Hi all,
I had some problems with manipulating toolbars through OLE Automation
Bridge, but Carsten and his OLE automation expert found the solution of
the problem. I attached the useful mail sent by Carsten explaining the
problem and the workarround to avoid it.
I posted this "bug" at OOo issuezilla as Carsten suggest me. You can
find it at:
http://qa.openoffice.org/issues/show_bug.cgi?id=55913

Best regards,
Jordi
--- Begin Message ---
Jordi Sanchez Lara wrote:

Hi Carsten,

Ok, I read the thread, I will try to follow your (fisrt draft)
instructions about how to add a combo box to a toolbar for achieving my
goal. It's not imperative to create this toolbars through OLE Automation
Bridge, actually, the real requirement is that the "creation"** of this
toolbar must be in execution time in a dynamic way.
Hi Jordi,

I asked again our OLE automation expert and he checked your code again and found the problem. It's a bug in the OLE automation bridge which doesn't convert the array of com.sun.star.lang.PropertyValue correctly. It would be nice if you could create a task on issuezilla and he will try to fix it in one of the next updates of OOo 2.0. See the following adapted code which should work now as he tried it by himself. If you have questions regarding your work with the toolbar controller and additional sub menu, please ask in the openoffice.dev mailing list (so other people can also participate and learn).

--------------
Hi,

This is the changed code:
Module Module1

  Sub Main()
      Dim objSM As Object = CreateObject("com.sun.star.ServiceManager")
Dim CoreRef As Object = objSM.CreateInstance("com.sun.star.reflection.CoreReflection") Dim classPV As Object = CoreRef.forName("com.sun.star.beans.PropertyValue")
      Dim aToolbarItemProp1 As Object
      classPV.CreateObject(aToolbarItemProp1)
      Dim aToolbarItemProp2 As Object
      classPV.CreateObject(aToolbarItemProp2)
      Dim aToolbarItemProp3 As Object
      classPV.CreateObject(aToolbarItemProp3)
      Dim properties As System.Array
properties = System.Array.CreateInstance(aToolbarItemProp1.GetType, 3)


      aToolbarItemProp1.Name = "CommandURL"
      aToolbarItemProp1.Value = "macro:///standard.module1.TestIt"
      aToolbarItemProp2.Name = "Label"
      aToolbarItemProp2.Value = "Test"
      aToolbarItemProp3.Name = "Type"
      aToolbarItemProp3.Value = 0

      properties(0) = aToolbarItemProp1
      properties(1) = aToolbarItemProp2
      properties(2) = aToolbarItemProp3

      Dim Doc As Object
      Dim dummy As System.Array
      Dim objDummy As Object = New Object
      dummy = System.Array.CreateInstance(objDummy.GetType, 0)
Doc = objSM.createInstance("com.sun.star.frame.Desktop").loadComponentFromURL("private:factory/swriter", "_blank", 2, dummy) Dim LayoutManager As Object = Doc.currentController.Frame.LayoutManager LayoutManager.createElement("private:resource/toolbar/user_toolbar1")
      LayoutManager.showElement("private:resource/toolbar/user_toolbar1")
Dim ToolBar As Object = LayoutManager.getElement("private:resource/toolbar/user_toolbar1")
      Dim settings As Object = ToolBar.getSettings(True)

'the changes are here:
      Dim any As Object = objSM.Bridge_GetValueObject()
      any.Set("[]com.sun.star.beans.PropertyValue", properties)
      settings.insertByIndex(0, any)
      ToolBar.setSettings(settings)
  End Sub


Explanation: The function insertByIndex expects an any as second argument. The bridge does not have the information what must be contained in the any, that is, what the implementation expects. The bridge then uses some default conversion rules, which are not appropriate here. A "Value Object" (see Developer's Guide, chapter 3.4.4) can be used as Any in this case. Because it contains the type, the bridge can convert the object accordingly.

Jochen
--------

Regards,
Carsten


--- End Message ---
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to