[C++][Java] Getting information about document

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
kikiz
Posts: 6
Joined: Fri May 23, 2014 12:13 pm

[C++][Java] Getting information about document

Post by kikiz »

HI,

I need help in getting information about current opened document.
Sample code looks like:

Code: Select all

		Reference< XInterface  > Desktop = xServiceManager->createInstanceWithContext(
		OUString::createFromAscii("com.sun.star.frame.Desktop"), xContext);
		Reference< XDesktop > xDesktop(Desktop, UNO_QUERY);
		Reference< XComponent > xcomponent = xDesktop->getCurrentComponent();
And now i wish to know what kind of document was opened (calc, writer, etc.).
I've tried with this: https://wiki.openoffice.org/wiki/Docume ... _Documents
However i have problem to get any property value (to be honest I'm not sure how to do this).

Thanks for help.
OpenOffice 4 on Windows 8.1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [C++][Java] Getting information about document

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
kikiz
Posts: 6
Joined: Fri May 23, 2014 12:13 pm

Re: [C++][Java] Getting information about document

Post by kikiz »

This is an Office extension - useless for me.
I need pure code solution for external program.
OpenOffice 4 on Windows 8.1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [C++][Java] Getting information about document

Post by Villeroy »

It is the solution to your problem because it reveals each and every property, interface, service for any UNO object you throw at it. While using it, it produces some C++ code snippet on the fly.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
kikiz
Posts: 6
Joined: Fri May 23, 2014 12:13 pm

Re: [C++][Java] Getting information about document

Post by kikiz »

Still i'm not sure how to get type of current opened document.
OpenOffice 4 on Windows 8.1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [C++][Java] Getting information about document

Post by Villeroy »

Code recorded by MRI with a text document as variable oInitialTarget

Code: Select all

#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/uno/XInterface.hpp>

using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
using namespace ::rtl;

void snippet(const Reference< XComponentContext > &xContext, const Reference< XInterface > &oInitialTarget)
{
    try
    {
        Reference< XServiceInfo > xServiceInfo(oInitialTarget, UNO_QUERY);
        sal_Bool bsupportsService = xServiceInfo->supportsService(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument")));
        
    }
    catch (RuntimeException &e)
    {
        // supportsService
        //printf(OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
    }
}
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply