Page 1 of 1

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

Posted: Fri Jun 13, 2014 10:48 am
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.

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

Posted: Fri Jun 13, 2014 11:29 am
by Villeroy

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

Posted: Fri Jun 13, 2014 3:02 pm
by kikiz
This is an Office extension - useless for me.
I need pure code solution for external program.

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

Posted: Fri Jun 13, 2014 3:08 pm
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.

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

Posted: Fri Jun 13, 2014 11:30 pm
by kikiz
Still i'm not sure how to get type of current opened document.

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

Posted: Sat Jun 14, 2014 12:09 am
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());
    }
}