OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Calling XRay from C++

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Fri Oct 29, 2004 7:41 am    Post subject: Calling XRay from C++ Reply with quote

1- easy method
I hope to construct at least two methods to call XRay from C++. This thread give the most simpler one. We only do it like described in : How to call a OOoBasic sub in C++
http://www.oooforum.org/forum/viewtopic.php?t=13712

First write this OOoBasic code :
Code:

Sub BernardXRay( x )
   oBJ = createUnoService(x)
   XRAY.XRAY oBJ
End Sub

in a module "Essai1"
The C++ code is then :
Code:

// Serge Moutou
int main( ) {
//retrieve an instance of the remote service manager
    Reference< XMultiServiceFactory > rOfficeServiceManager;
    rOfficeServiceManager = ooConnect();
    if( rOfficeServiceManager.is() ){
        printf( "Connected sucessfully to the office\n" );
    }

//get the desktop service using createInstance returns an XInterface type
    Reference< XInterface  > Desktop = rOfficeServiceManager->createInstance(
    OUString::createFromAscii( "com.sun.star.frame.Desktop" ));

//query for the XComponentLoader interface
    Reference< XComponentLoader > rComponentLoader (Desktop, UNO_QUERY);
    if( rComponentLoader.is() ){
           printf( "XComponentloader successfully instanciated\n" );
       }

   Reference< XDesktop > rDesktop(Desktop,UNO_QUERY);

// Don't forget to add : #include <com/sun/star/frame/XDispatchHelper.hpp>
// Don't forget to add "com.sun.star.frame.XDispatchHelper \" in the makefile
// Query the XDispatcher Interface
   Reference< XDispatchHelper > rDispatchHelper = Reference< XDispatchHelper >
            ( rOfficeServiceManager->createInstance(
                                        OUString( RTL_CONSTASCII_USTRINGPARAM(
                                        "com.sun.star.frame.DispatchHelper" ))), UNO_QUERY );


// Don't forget to add : #include <com/sun/star/frame/XDispatchProvider.hpp>
// Don't forget to add "com.sun.star.frame.XDispatchProvider \" in the makefile
// Query the XDispatchProvider Interface
   Reference< XDispatchProvider > rDispatchProvider(rDesktop,UNO_QUERY);

   Any any=rDispatchHelper->executeDispatch(rDispatchProvider,
         OUString::createFromAscii(
            "macro:///Standard.Essai1.BernardXRay(com.sun.star.frame.DispatchHelper)"),
         OUString::createFromAscii(""),
         0,
         Sequence < ::com::sun::star::beans::PropertyValue > ());


    return 0;
}


Its a begining but this method has a great drawback : there is no relation between the C++ code and the OOoBasic code. I mean you can see a variable in C++ "rDispatchHelper" and an other variable in OOoBasic which share only the same Object type but not the instantiation.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide


Last edited by SergeM on Fri Dec 02, 2005 11:04 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Fri Oct 29, 2004 7:55 am    Post subject: Reply with quote

2 - How to share an Object between C++ and OOoBasic ?

When you want to call an OOoBasic sub from C++ and sharing a variable you have to ask yourself how you can do that ? I though it like a procedure call in some language :
- put data on stack
- call the procedure
- the procedure retreive the data in the stack and proceed them
- terminate and puting the stack as befor
I can not do that in this case because the stack are not the same !
The idea is to use an add-on which put the object somewhere and retreive it with OOoBasic and XRay (new verb) it.
For the moment I encounter unexpected problem to do that but I hope to do that in a little.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Sat Oct 30, 2004 1:17 am    Post subject: Reply with quote

Quote:
How to share an Object between C++ and OOoBasic ?

I wonder if this is possible and in my opinion it should not. Because the C++ program (or any other program) and a running macro are two different and independent processes, event if C++ launches the macro (through a call to OpenOffice). The memory zones should be protected from one another.
You can only pass information between the two applications by way of a common file.
_________________
Bernard

OpenOffice.org 1.1.5 fr / Apache OpenOffice 4.0.1 / LibreOffice 4.1.0
MS-Windows 7 Home SP1
This forum is spammed, use instead Apache OpenOffice forums
Back to top
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Sat Oct 30, 2004 4:56 am    Post subject: Reply with quote

Yes the problem is more complicated that I though at the begining.
In fact this is a typical Remote Procedure Call because both computer executing the code could be different ! For that engeeners have hardly worked to pass from RPC to CORBA.

Bernard,
I think it would be better for me to write a XRay-like in C++. I then would be interested by some technical aspects of the reflection API if you can help me. I am not hurry I have to learn how to manipulate Dialog Box in C++. You can use my private Message Box and in French.
Thank you in advance'
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Sat Nov 06, 2004 2:41 pm    Post subject: Reply with quote

I begin to explore Core reflection in C++.
Here is a little piece of code :
Code:

// Serge Moutou
void LittleXRay(OUString OUStr,Reference< XMultiServiceFactory > rOServiceManager) {
// Don't forget to add : using namespace com::sun::star::reflection;
// Don't forget to add : #include <com/sun/star/reflection/XIdlReflection.hpp>
// Don't forget to add "com.sun.star.reflection.XIdlReflection \" in the makefile
   Reference< XIdlReflection >rIDLReflection = Reference< XIdlReflection >
               ( rOServiceManager->createInstance(
                                      OUString( RTL_CONSTASCII_USTRINGPARAM(
                                          "com.sun.star.reflection.CoreReflection" ))), UNO_QUERY );
   if (! rIDLReflection.is()) printf("Erreur XIDLRflection\n");
   Reference< XIdlClass > rIDLClass=rIDLReflection->forName(OUStr);
//         OUString::createFromAscii("com.sun.star.frame.XDesktop"));


   Sequence< Reference< XIdlMethod > > SeqIdlMethods = rIDLClass->getMethods();
   for (int i=0;i<SeqIdlMethods.getLength();i++){
      OString o = OUStringToOString( SeqIdlMethods[i]->getName(),RTL_TEXTENCODING_ASCII_US );
          printf("%s\n", o.pData->buffer );
   }
}


and a call of this sub :
Code:

main( ) {
//retrieve an instance of the remote service manager
    Reference< XMultiServiceFactory > rOfficeServiceManager;
    rOfficeServiceManager = ooConnect();
    if( rOfficeServiceManager.is() ){
        printf( "Connected sucessfully to the office\n" );
    }

//get the desktop service using createInstance returns an XInterface type
    Reference< XInterface  > Desktop = rOfficeServiceManager->createInstance(
    OUString::createFromAscii( "com.sun.star.frame.Desktop" ));

//query for the XComponentLoader interface
    Reference< XComponentLoader > rComponentLoader (Desktop, UNO_QUERY);
    if( rComponentLoader.is() ){
           printf( "XComponentloader successfully instanciated\n" );

       }

    Reference< XDesktop > rDesktop(Desktop,UNO_QUERY);
    Reference< XComponent > xcomponent = rComponentLoader->loadComponentFromURL(
   OUString::createFromAscii("private:factory/scalc"),
        OUString::createFromAscii("_blank"),
        0,
        Sequence < ::com::sun::star::beans::PropertyValue >());

    LitleXRay(OUString::createFromAscii("com.sun.star.frame.XDesktop"),rOfficeServiceManager);


    return 0;
}

_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide


Last edited by SergeM on Fri Dec 02, 2005 11:05 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Sat Nov 06, 2004 2:49 pm    Post subject: Reply with quote

A little fault in my previous main : (i have remove useless code)
Code:

main( ) {
//retrieve an instance of the remote service manager
    Reference< XMultiServiceFactory > rOfficeServiceManager;
    rOfficeServiceManager = ooConnect();
    if( rOfficeServiceManager.is() ){
        printf( "Connected sucessfully to the office\n" );
    }

//get the desktop service using createInstance returns an XInterface type
    Reference< XInterface  > Desktop = rOfficeServiceManager->createInstance(
    OUString::createFromAscii( "com.sun.star.frame.Desktop" ));

//query for the XComponentLoader interface
    Reference< XComponentLoader > rComponentLoader (Desktop, UNO_QUERY);
    if( rComponentLoader.is() ){
           printf( "XComponentloader successfully instanciated\n" );

       }

   Reference< XDesktop > rDesktop(Desktop,UNO_QUERY);
LittleXRay(OUString::createFromAscii("com.sun.star.frame.XDesktop"),rOfficeServiceManager);


    return 0;
}


Note that if I remove
Code:
 Reference< XDesktop > rDesktop(Desktop,UNO_QUERY);


I always obtain a 139 Error !
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Thu Nov 11, 2004 9:57 am    Post subject: Reply with quote

The two previous post are interesting but don't make the future XRay I want (because the interface has no tie with an effective object).
Fortunately I find the Java Inspector code : this code save me probably few weeks. I have begun to navigate in the IDL files but I was very far of a result. I give now the code and its result (done in only one afternoon). What miss is of course a dialog Box. I work around this subject but without success for the moment. But I after forgeting it I discover in a recent post the Dany post arount windows awt toolkit.
Code:

// Don't forget to add : #include <com/sun/star/reflection/ParamMode.hpp>
// Don't forget to add "com.sun.star.reflection.ParamMode \" in the makefile
OString getParamMode(ParamMode paramMode) {
// comes from <OpenOffice1.1_SDK>/examples/java/Inspector
  OString toReturn;
  toReturn = "";
  if (paramMode == ParamMode_IN) toReturn = "IN"; else
    if (paramMode == ParamMode_OUT) toReturn = "OUT"; else
      if (paramMode == ParamMode_INOUT) toReturn = "INOUT";
  return toReturn;
}

void smallXRay(Any any,Reference< XMultiServiceFactory > rOServiceManager) {
// comes from <OpenOffice1.1_SDK>/examples/java/Inspector

// Don't forget to add : using namespace com::sun::star::beans;
// Don't forget to add : #include <com/sun/star/beans/XIntrospection.hpp>
// Don't forget to add "com.sun.star.beans.XIntrospection \" in the makefile
   Reference< XIntrospection >xIntrospection = Reference< XIntrospection >
               ( rOServiceManager->createInstance(
                                      OUString( RTL_CONSTASCII_USTRINGPARAM(
                                          "com.sun.star.beans.Introspection" ))), UNO_QUERY );

// ********* get all methods for the given object *********************

// Don't forget to add : #include <com/sun/star/lang/XServiceInfo.hpp>
// Don't forget to add "com.sun.star.lang.XServiceInfo \" in the makefile
   Reference< XServiceInfo > rServiceInfo(any,UNO_QUERY);

   Reference< XIntrospectionAccess > xIntrospec = xIntrospection->inspect(any);

// Don't forget to add : #include <com/sun/star/beans/MethodConcept.hpp>
// Don't forget to add "com.sun.star.beans.MethodConcept \" in the makefile
   Sequence< Reference < XIdlMethod > > mMethods = xIntrospec -> getMethods(MethodConcept::ALL);
   printf("******** methods : (%d)\n",mMethods.getLength());
   for (int i=0;i<mMethods.getLength();i++){
      OString params;
      params="";
      Sequence< ParamInfo > ParamInfos = mMethods[i]->getParameterInfos();
      if (ParamInfos.getLength() > 0) {
         for (int j=0;j<ParamInfos.getLength();j++){
            Reference< XIdlClass > xIdlClass = ParamInfos[j].aType;
            if (j == 0)
            // first parameter has no leading comma
            params += "[" + getParamMode(ParamInfos[j].aMode)+
            "]" + OUStringToOString(xIdlClass->getName(),RTL_TEXTENCODING_ASCII_US );
            else
            params += ",[" + getParamMode(ParamInfos[j].aMode)+
            "]"+OUStringToOString(xIdlClass->getName(),RTL_TEXTENCODING_ASCII_US );
         }
      }
      OString o = OUStringToOString( mMethods[i]->getName(),RTL_TEXTENCODING_ASCII_US )+"("+params+")";
          printf("%s\n", o.pData->buffer);
   }

// ********** get all Interfaces for the given object *********************

// Don't forget to add : #include <com/sun/star/lang/XTypeProvider.hpp>
// Don't forget to add "com.sun.star.lang.XTypeProvider \" in the makefile
   Reference< XTypeProvider > rTypeProvider(any,UNO_QUERY);
// Don't forget to add : #include <com/sun/star/uno/Type.hxx>
// But nothing in MakeFile : this hxx file is provided by SDK
   Sequence< Type > types = rTypeProvider->getTypes();
   printf("******** interfaces : (%d)\n",types.getLength());
   for (int i=0;i<types.getLength();i++){
      OString o = OUStringToOString( types[i].getTypeName(),RTL_TEXTENCODING_ASCII_US );
          printf("%s\n", o.pData->buffer );
   }

// ********** get all properties for the given object *********************

// Don't forget to add : #include <com/sun/star/beans/PropertyConcept.hpp>
// Don't forget to add "com.sun.star.beans.PropertyConcept \" in the makefile
// Don't forget to add : #include <com/sun/star/beans/Property.hpp>
// Don't forget to add "com.sun.star.beans.Property \" in the makefile
// Don't forget to add : #include <com/sun/star/beans/XPropertySet.hpp>
// Don't forget to add "com.sun.star.beans.XPropertySet \" in the makefile

   Sequence< Property > Properties = xIntrospec -> getProperties(PropertyConcept::ALL);
   printf("******** properties : (%d)\n",Properties.getLength());
   for (int i=0;i<Properties.getLength();i++){
      OString o = OUStringToOString( Properties[i].Name,RTL_TEXTENCODING_ASCII_US ) +
      " = (" + OUStringToOString(Properties[i].Type.getTypeName(),RTL_TEXTENCODING_ASCII_US ) + ") ";
   //   + OUStringToOString( ou,RTL_TEXTENCODING_ASCII_US );
          printf("%s\n", o.pData->buffer );
   }

}

main( ) {
//retrieve an instance of the remote service manager
    Reference< XMultiServiceFactory > rOfficeServiceManager;
    rOfficeServiceManager = ooConnect();
    if( rOfficeServiceManager.is() ){
        printf( "Connected sucessfully to the office\n" );
    }

//get the desktop service using createInstance returns an XInterface type
    Reference< XInterface  > Desktop = rOfficeServiceManager->createInstance(
    OUString::createFromAscii( "com.sun.star.frame.Desktop" ));

//query for the XComponentLoader interface
    Reference< XComponentLoader > rComponentLoader (Desktop, UNO_QUERY);
    if( rComponentLoader.is() ){
           printf( "XComponentloader successfully instanciated\n" );

       }

   Reference< XDesktop > rDesktop(Desktop,UNO_QUERY);

   Any toInspect;
   toInspect <<= rDesktop;
   smallXRay(toInspect,rOfficeServiceManager);
    return 0;
}

This coded gives me a text :
Code:

******** methods : (52)
queryInterface([IN]type)
acquire()
release()
getTypes()
getImplementationId()
getImplementationName()
supportsService([IN]string)
getSupportedServiceNames()
terminate()
addTerminateListener([IN]com.sun.star.frame.XTerminateListener)
removeTerminateListener([IN]com.sun.star.frame.XTerminateListener)
getComponents()
getCurrentComponent()
getCurrentFrame()
loadComponentFromURL([IN]string,[IN]string,[IN]long,[IN][]com.sun.star.beans.PropertyValue)
getTasks()
getActiveTask()
queryDispatch([IN]com.sun.star.util.URL,[IN]string,[IN]long)
queryDispatches([IN][]com.sun.star.frame.DispatchDescriptor)
dispose()
addEventListener([IN]com.sun.star.lang.XEventListener)
removeEventListener([IN]com.sun.star.lang.XEventListener)
initialize([IN]com.sun.star.awt.XWindow)
getContainerWindow()
setCreator([IN]com.sun.star.frame.XFramesSupplier)
getCreator()
getName()
setName([IN]string)
findFrame([IN]string,[IN]long)
isTop()
activate()
deactivate()
isActive()
setComponent([IN]com.sun.star.awt.XWindow,[IN]com.sun.star.frame.XController)
getComponentWindow()
getController()
contextChanged()
addFrameActionListener([IN]com.sun.star.frame.XFrameActionListener)
removeFrameActionListener([IN]com.sun.star.frame.XFrameActionListener)
getFrames()
getActiveFrame()
setActiveFrame([IN]com.sun.star.frame.XFrame)
disposing([IN]com.sun.star.lang.EventObject)
dispatchFinished([IN]com.sun.star.frame.DispatchResultEvent)
handle([IN]com.sun.star.task.XInteractionRequest)
getPropertySetInfo()
setPropertyValue([IN]string,[IN]any)
getPropertyValue([IN]string)
addPropertyChangeListener([IN]string,[IN]com.sun.star.beans.XPropertyChangeListener)
removePropertyChangeListener([IN]string,[IN]com.sun.star.beans.XPropertyChangeListener)
addVetoableChangeListener([IN]string,[IN]com.sun.star.beans.XVetoableChangeListener)
removeVetoableChangeListener([IN]string,[IN]com.sun.star.beans.XVetoableChangeListener)
******** interfaces : (13)
com.sun.star.lang.XTypeProvider
com.sun.star.lang.XServiceInfo
com.sun.star.frame.XDesktop
com.sun.star.frame.XComponentLoader
com.sun.star.frame.XTasksSupplier
com.sun.star.frame.XDispatchProvider
com.sun.star.frame.XFramesSupplier
com.sun.star.frame.XFrame
com.sun.star.lang.XComponent
com.sun.star.frame.XDispatchResultListener
com.sun.star.lang.XEventListener
com.sun.star.task.XInteractionHandler
com.sun.star.beans.XPropertySet
******** properties : (21)
ActiveFrame = (com.sun.star.lang.XComponent)
DispatchRecorderSupplier = (com.sun.star.frame.XDispatchRecorderSupplier)
IsPlugged = (boolean)
SuspendQuickstartVeto = (boolean)
Title = (string)
Types = ([]type)
ImplementationId = ([]byte)
ImplementationName = (string)
SupportedServiceNames = ([]string)
Components = (com.sun.star.container.XEnumerationAccess)
CurrentComponent = (com.sun.star.lang.XComponent)
CurrentFrame = (com.sun.star.frame.XFrame)
Tasks = (com.sun.star.container.XEnumerationAccess)
ActiveTask = (com.sun.star.frame.XTask)
ContainerWindow = (com.sun.star.awt.XWindow)
Creator = (com.sun.star.frame.XFramesSupplier)
Name = (string)
ComponentWindow = (com.sun.star.awt.XWindow)
Controller = (com.sun.star.frame.XController)
Frames = (com.sun.star.frame.XFrames)
PropertySetInfo = (com.sun.star.beans.XPropertySetInfo)


The only problem I encounter is to find the values of properties.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Wed Dec 22, 2004 7:03 am    Post subject: Reply with quote

First use of Reflection Helper :
I want to gives informations on methods, interfaces, services properties. For that I use the reflection Helper and then construct draw pages ... see Some Introspection techniques (various languages)
http://www.oooforum.org/forum/viewtopic.php?t=7068
The helper simplify the code :
Code:

// Christian Junker code
void MakePosition(sal_Int32 x, sal_Int32 y, ::com::sun::star::awt::Point *Pos)
{

   Pos->X = x;
   Pos->Y = y;
}

void MakeSize(sal_Int32 width, sal_Int32 height, ::com::sun::star::awt::Size *Size)
{
   Size->Width = width;
   Size->Height = height;
}

void DrawMe(Reference< XShape > &Shape, Reference< XDrawPage > &page, const OUString shapename)
{
   Reference< XShapes > Shapes(page, UNO_QUERY);
   Shapes->add(Shape);
   Reference< XPropertySet > shapeprops(Shape, UNO_QUERY);
   shapeprops->setPropertyValue(OUString::createFromAscii("Name"),
               makeAny(shapename));
}

void smallXRay(Any any,Reference< XMultiServiceFactory > rOServiceManager,Reference< XDesktop > theDesktop) {
// here we use the helper
   ReflectionHelper *Reflect = new (ReflectionHelper)(any,rOServiceManager);

   // create a drawing document : goal : use the navigator to see the results

   //query for the XComponentLoader interface
   Reference< XComponentLoader > rComponentLoader (theDesktop, UNO_QUERY);

   Reference< XComponent > xcomponent = rComponentLoader->loadComponentFromURL(
      OUString::createFromAscii("private:factory/sdraw"),
           OUString::createFromAscii("_blank"),
           0,
           Sequence < ::com::sun::star::beans::PropertyValue >());

// Don't forget to add : using namespace com::sun::star::drawing;
// Don't forget to add : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
// Don't forget to add "com.sun.star.drawing.XDrawPagesSupplier \" in the makefile
   Reference< XDrawPagesSupplier > rDrawDoc(xcomponent, UNO_QUERY);

// query the XDrawPages Interface
   Reference< XDrawPages > rDrawPages = rDrawDoc->getDrawPages();

// Don't forget to add : using namespace com::sun::star::container;
// Don't forget to add : #include <com/sun/star/container/XIndexAccess.hpp>
// Don't forget to add "com.sun.star.container.XIndexAccess \" in the makefile
// query the XIndexAccess Interface
   Reference< XIndexAccess > rPageIndexAccess(rDrawPages, UNO_QUERY);

   Any DrawPage = rPageIndexAccess->getByIndex(0);

// Don't forget to add : #include <com/sun/star/drawing/XDrawPage.hpp>
// Don't forget to add "com.sun.star.drawing.XDrawPage \" in the makefile
// Query the XDrawPage Interface
   Reference< XDrawPage > rDrawPage(DrawPage, UNO_QUERY);

// Don't forget to add : #include <com/sun/star/container/XNamed.hpp>
// Don't forget to add "com.sun.star.container.XNamed \" in the makefile
// query for the XNamed Interface
   Reference< XNamed > rNamed(rDrawPage, UNO_QUERY);
   rNamed->setName(OUString::createFromAscii("Methods"));

   Reference< XMultiServiceFactory > DocFactory(xcomponent, UNO_QUERY);

// ******** we have now our first Page

   Sequence< OUString > mMethods = Reflect -> getMethods();
   printf("******** methods : (%d)\n",mMethods.getLength());
   for (int i=0;i<mMethods.getLength();i++){

      Point *Pos = new (Point);
      Size *TheSize = new ( Size );

      Reference< XInterface > RectangleShape = DocFactory->createInstance(
                  OUString::createFromAscii("com.sun.star.drawing.RectangleShape") );
      Reference< XShape > rRectShape(RectangleShape, UNO_QUERY);
      MakePosition(0, 0, Pos);
      MakeSize(0, 0, TheSize);
      rRectShape->setPosition(*Pos);
      rRectShape->setSize(*TheSize);
      DrawMe(rRectShape, rDrawPage, mMethods[i]);

   }

// Insert a new Page with name "Interfaces"
   // query for the XDrawPage Inteface
   rDrawPage = rDrawPages->insertNewByIndex(1);
// query for the XNamed Interface
   Reference< XNamed > rNamed2(rDrawPage, UNO_QUERY);
   rNamed2->setName(OUString::createFromAscii("Interfaces"));


// ********** get all Interfaces for the given object *********************


   Sequence< OUString > types = Reflect->getTypes();
   printf("******** interfaces : (%d)\n",types.getLength());
   for (int i=0;i<types.getLength();i++){
//      OString o = OUStringToOString( types[i].getTypeName(), RTL_TEXTENCODING_ASCII_US );
//          printf("%s\n", o.pData->buffer );
      Point *Pos = new (Point);
      Size *TheSize = new ( Size );

      Reference< XInterface > RectangleShape = DocFactory->createInstance(
                  OUString::createFromAscii("com.sun.star.drawing.RectangleShape") );
      Reference< XShape > rRectShape(RectangleShape, UNO_QUERY);
      MakePosition(0, 0, Pos);
      MakeSize(0, 0, TheSize);
      rRectShape->setPosition(*Pos);
      rRectShape->setSize(*TheSize);
      DrawMe(rRectShape, rDrawPage, types[i]);
   }

// Insert a new Page with name "Services"
   // query for the XDrawPage Inteface
   rDrawPage = rDrawPages->insertNewByIndex(2);
// query for the XNamed Interface
   Reference< XNamed > rNamed3(rDrawPage, UNO_QUERY);
   rNamed3->setName(OUString::createFromAscii("Services"));

// ********** get all services for the given object *********************

   Sequence< OUString > services = Reflect->getServices();
   printf("******** services : (%d)\n",services.getLength());
   for (int i=0;i<services.getLength();i++){
      Point *Pos = new (Point);
      Size *TheSize = new ( Size );

      Reference< XInterface > RectangleShape = DocFactory->createInstance(
                  OUString::createFromAscii("com.sun.star.drawing.RectangleShape") );
      Reference< XShape > rRectShape(RectangleShape, UNO_QUERY);
      MakePosition(0, 0, Pos);
      MakeSize(0, 0, TheSize);
      rRectShape->setPosition(*Pos);
      rRectShape->setSize(*TheSize);
      DrawMe(rRectShape, rDrawPage, services[i]);
   }

// Insert a new Page with name "Properties"
   // query for the XDrawPage Inteface
   rDrawPage = rDrawPages->insertNewByIndex(3);
// query for the XNamed Interface
   Reference< XNamed > rNamed4(rDrawPage, UNO_QUERY);
   rNamed4->setName(OUString::createFromAscii("Properties"));


// ********** get all properties for the given object *********************
   Sequence< OUString > properties = Reflect->getPropertiesWithoutValues();
   printf("******** properties : (%d)\n",properties.getLength());
   for (int i=0;i<properties.getLength();i++){
      Point *Pos = new (Point);
      Size *TheSize = new ( Size );
      Reference< XInterface > RectangleShape = DocFactory->createInstance(
              OUString::createFromAscii("com.sun.star.drawing.RectangleShape") );
      Reference< XShape > rRectShape(RectangleShape, UNO_QUERY);
      MakePosition(0, 0, Pos);
      MakeSize(0, 0, TheSize);
      rRectShape->setPosition(*Pos);
      rRectShape->setSize(*TheSize);
      DrawMe(rRectShape, rDrawPage, properties[i]);
   }
}

main( ) {
//retrieve an instance of the remote service manager
    Reference< XMultiServiceFactory > rOfficeServiceManager;
    rOfficeServiceManager = ooConnect();
    if( rOfficeServiceManager.is() ){
        printf( "Connected sucessfully to the office\n" );
    }

//get the desktop service using createInstance returns an XInterface type
    Reference< XInterface  > Desktop = rOfficeServiceManager->createInstance(
    OUString::createFromAscii( "com.sun.star.frame.Desktop" ));

//query for the XComponentLoader interface
    Reference< XComponentLoader > rComponentLoader (Desktop, UNO_QUERY);
    if( rComponentLoader.is() ){
           printf( "XComponentloader successfully instanciated\n" );

       }

   Reference< XDesktop > rDesktop(Desktop,UNO_QUERY);

   Any toInspect;
   toInspect <<= rDesktop;

   smallXRay(toInspect,rOfficeServiceManager,rDesktop);
    return 0;
}


_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Fri Dec 24, 2004 5:11 am    Post subject: Reply with quote

Three helpers use

I want to use in this post three helpers :

Desktop Helper in C++http://www.oooforum.org/forum/viewtopic.php?t=15437

DrawDocument Helper in C++http://www.oooforum.org/forum/viewtopic.php?t=15438

Desktop Helper in C++http://www.oooforum.org/forum/viewtopic.php?t=15437

The goal is al to do the same of previous post but using three helpers then simplifying greatly the code : First function :
Code:

void smallXRay(Any any,Reference< XMultiServiceFactory > rOServiceManager,Reference< XDesktop > theDesktop) {
// using the Reflection Helper
   ReflectionHelper *Reflect = new (ReflectionHelper)(any,rOServiceManager);
// using the DrawDocument helper
   DrawDocument *theDoc = new (DrawDocument) (theDesktop);

   theDoc->getPageByIndexAndRenameIt(0,OUString::createFromAscii("Methods"));
// ******** we have now our first Page entitled "Methods"

   Sequence< OUString > mMethods = Reflect -> getMethods();
   printf("******** methods : (%d)\n",mMethods.getLength());
   for (int i=0;i<mMethods.getLength();i++){
      theDoc->DrawRectangle(0,0,0,0, mMethods[i]);
   }

// Insert a new Page with name "Interfaces"
   theDoc->addPageByIndexAndRenameIt(1,OUString::createFromAscii("Interfaces"));

// ********** get all Interfaces for the given object *********************

   Sequence< OUString > types = Reflect->getTypes();
   printf("******** interfaces : (%d)\n",types.getLength());
   for (int i=0;i<types.getLength();i++){
       theDoc->DrawRectangle(0,0,0,0,types[i]);
   }

// Insert a new Page with name "Services"
   theDoc->addPageByIndexAndRenameIt(2,OUString::createFromAscii("Services"));

// ********** get all services for the given object *********************

   Sequence< OUString > services = Reflect->getServices();
   printf("******** services : (%d)\n",services.getLength());
   for (int i=0;i<services.getLength();i++){
       theDoc->DrawRectangle(0,0,0,0,services[i]);
   }

// Insert a new Page with name "Properties"
   theDoc->addPageByIndexAndRenameIt(3,OUString::createFromAscii("Properties"));

// ********** get all properties for the given object *********************

   Sequence< OUString > properties = Reflect->getPropertiesWithValues();
   printf("******** properties : (%d)\n",properties.getLength());
   for (int i=0;i<properties.getLength();i++){
       theDoc->DrawRectangle(0,0,0,0,properties[i]);
   }
}


And the main :
Code:

main( ) {
   DesktopHelper *theDesktop = new (DesktopHelper);

   Any toInspect;
   toInspect <<= theDesktop->xDesktop;
   
   smallXRay(toInspect,theDesktop->xSVMG,theDesktop->xDesktop);
    return 0;
}

This gives :
[/quote]
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group