Christian Junker wrote:
I remember some time ago,
that it had been discussed that OOo 2.0 will provide functional interfaces that haven't been functional yet in any way (XMenu, XMenuListener) and probably add some more interfaces that make menus accessible via API.
Now that the first beta candidate has been released, I would like to know if that is possible yet. I tried putting information together and working it out for 1.9.m79 but I did not succeed. I think that there is a lot of request in this area, since it would improve customization of OOo's GUI a lot and make it possible for developers around the world to create their own OOo looks (of course there are tight boundaries, but as of yet it is not even possible to disable certain menu entries in the main menu as far as I know) without having to hack portions of the huge source code and repackaging their own oo distributions.



Hi Christian,

there is an API to configure your menu (toolbars), but it's not a low-level API like XMenu/XMenuListener. For example, it's not possible to disable certain menu item with it. The Office UI is highly dynamic and therefor there is no easy way to force menu item to be disabled/enabled. You can use DispatchInterceptors or the "disable commands" feature (both are documented in the DevelopersGuide for OOo 1.1.x).

Currently the developer documentation which describes the new APIs is not ready yet. A first introduction to our new API can be found here:
http://specs.openoffice.org/ui_in_general/api/ProgrammaticControlOfMenuAndToolbarItems.sxw


I attached some examples which work on the Beta. Please keep in mind that the namespace drafts will removed on a later version, I think 1.9.83. The real namespaces will be "com.sun.star.ui" and "com.sun.star.frame".

Regards,
Carsten

----------

REM  *****  BASIC  *****
Sub Main
        REM *** Creates a top-level popup menu on the Writer menu bar 
persistently.
        REM *** It checks if its popup menu has already been added to the menu 
bar
        REM *** and does nothing.
        REM *** The popup menu contains one menu item with a

REM *** Initialize strings
sMenuBar = "private:resource/menubar/menubar"
sMyPopupMenuCmdId = "vnd.openoffice.org:MyMenu"

REM *** Retrieve the module configuration manager from central module configuration manager supplier
oModuleCfgMgrSupplier = createUnoService("drafts.com.sun.star.ui.ModuleUIConfigurationManagerSupplier")


REM *** Retrieve the module configuration manager with module identifier
REM *** See drafts.com.sun.star.frame.ModuleManager for more information
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager( "com.sun.star.text.TextDocument" )
oMenuBarSettings = oModuleCfgMgr.getSettings( sMenuBar, true )

REM *** Look for our top-level popup menu. Can be identified by the CommandURL property.
bHasAlreadyPopupMenu = false
nCount = oMenuBarSettings.getCount()
for i = 0 to nCount-1
oPopupMenu() = oMenuBarSettings.getByIndex( i )
nPopupMenuCount = ubound(oPopupMenu())
for j = 0 to nPopupMenuCount
if oPopupMenu(j).Name = "CommandURL" then
if oPopupMenu(j).Value = sMyPopupMenuCmdId then
bHasAlreadyPopupMenu = true
end if
endif
next j
next i

if not bHasAlreadyPopupMenu then
sString = "My Macro's"
oPopupMenu = CreatePopupMenu( sMyPopupMenuCmdId, sString, oMenuBarSettings )
oPopupMenuContainer = oPopupMenu(3).Value
oMenuItem = CreateMenuItem( "macro:///Standard.Module1.Test()", "Standard.Module1.Test" )
oPopupMenuContainer.insertByIndex( 0, oMenuItem )
oMenuBarSettings.insertByIndex( nCount, oPopupMenu )
oModuleCfgMgr.replaceSettings( sMenuBar, oMenuBarSettings )
end if
End Sub


Function CreatePopupMenu( CommandId, Label, Factory ) as Variant
        Dim aPopupMenu(3) as new com.sun.star.beans.PropertyValue

aPopupMenu(0).Name = "CommandURL"
aPopupMenu(0).Value = CommandId
aPopupMenu(1).Name = "Label"
aPopupMenu(1).Value = Label
aPopupMenu(2).Name = "Type"
aPopupMenu(2).Value = 0
aPopupMenu(3).Name = "ItemDescriptorContainer"
aPopupMenu(3).Value = Factory.createInstanceWithContext( GetDefaultContext() )


        CreatePopupMenu = aPopupMenu()
End Function

Function CreateMenuItem( Command as String, Label as String ) as Variant
        Dim aMenuItem(2) as new com.sun.star.beans.PropertyValue

        aMenuItem(0).Name = "CommandURL"
        aMenuItem(0).Value = Command
        aMenuItem(1).Name = "Label"
        aMenuItem(1).Value = Label
        aMenuItem(2).Name = "Type"
        aMenuItem(2).Value = 0

        CreateMenuItem = aMenuItem()
End Function


Sub Test MsgBox "Test" End Sub

--------------

REM  *****  BASIC  *****

Sub Main
REM *** Modifies the standard bar of the BasicIDE module
REM *** Initialize strings
sToolbar = "private:resource/toolbar/standardbar"
sMyToolbarCmdId = "vnd.openoffice.org:MyFunction"

REM *** Retrieve the module configuration manager from central module configuration manager supplier
oModuleCfgMgrSupplier = createUnoService("drafts.com.sun.star.ui.ModuleUIConfigurationManagerSupplier")


REM *** Retrieve the module configuration manager with module identifier
REM *** See drafts.com.sun.star.frame.ModuleManager for more information
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager( "com.sun.star.script.BasicIDE" )

oToolbarSettings = oModuleCfgMgr.createSettings()

REM *** Create a button
sString = "My Macro's"
oToolbarItem = CreateToolbarItem( "macro:///Standard.Module1.Test()", "Standard.Module1.Test" )
oToolbarSettings.insertByIndex( nCount, oToolbarItem )

oModuleCfgMgr.insertSettings( sToolbar, oToolbarSettings )
End Sub


Function CreateToolbarItem( Command as String, Label as String ) as Variant
        Dim aToolbarItem(2) as new com.sun.star.beans.PropertyValue

        aToolbarItem(0).Name = "CommandURL"
        aToolbarItem(0).Value = Command
        aToolbarItem(1).Name = "Label"
        aToolbarItem(1).Value = Label
        aToolbarItem(2).Name = "Type"
        aToolbarItem(2).Value = 0

        CreateToolbarItem = aToolbarItem()
End Function

Sub Test
        MsgBox "Test"
End Sub

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



Reply via email to