Christoph Lutz wrote:
Hi Carsten,
Is it the XSingleComponentFactory I have to use to create the sub
containers? Just to write a quick test-example in basic: How can I
create a instance using basic? settings.createInstance() didn't work
and I don't know how to get the required XComponentContext in Basic to
call the settings.createInstanceWithContext()-Method.
Hi Christoph,
Please look at the following example in Basic. It uses the function
CreatePopupMenu to create a new popup menu. The line of interest uses
the factory (the container) to create a sub container with
createInstanceWithContext().
Factory.createInstanceWithContext( GetDefaultContext() )
Example:
--------
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 which call the Basic
macro test.
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("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
REM *** Retrieve the module configuration manager with module identifier
REM *** See 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
MsgBox bHasAlreadyPopupMenu
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
Regards,
Carsten
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]