Matthias Benkmann wrote:
I've managed to create my own toolbar with the following code

layout = thisComponent.CurrentController.Frame.LayoutManager
layout.createElement( "private:resource/toolbar/UITest" )
layout.showElement( "private:resource/toolbar/UITest" )

but I can't seem to find a way to add a button to it. Could someone please give me a pointer in the right direction. Thanks.

Hi Matthias,

please have a look at the following Basic example. It creates a transient toolbar (non-persistent) and inserts a toolbar button.

Sub Main
        REM *** Initialize strings
        sToolbar = "private:resource/toolbar/mytoolbar"
        sMyToolbarCmdId = "vnd.openoffice.org:MyFunction"
        
        REM *** Retrieve the desktop service
        oDesktop = createUnoService("com.sun.star.frame.Desktop")

        REM *** Retrieve the current frame and layout manager
        oCurrFrame = oDesktop.getCurrentFrame()
        oLayoutManager = oCurrFrame.LayoutManager

        REM *** Create a new transient toolbar ***
        REM *** A transient toolbar will be automatically created whenever
        REM *** createElement is called and no configuration data can be found
        REM *** for it. By default a new toolbar is visible.
        REM *** Attention:
        REM *** Running this macro more than once on the same frame will
        REM *** add the same button again and again.
        oLayoutManager.createElement( sToolbar )
        oLayoutManager.hideElement( sToolbar )
        oToolbar = oLayoutManager.getElement( sToolbar )
        
        REM *** Retrieve settings from toolbar ***
        oToolbarSettings = oToolbar.getSettings( true )
        
        REM *** Create a toolbar button ***
oToolbarItem = CreateToolbarItem( "macro:///Standard.Module1.Test()", "Standard.Module1.Test" )
        
        REM *** Insert button into our settings
        oToolbarSettings.insertByIndex( 0, oToolbarItem )

        REM *** Set title of our new toolbar
        oToolbarSettings.setPropertyValue( "UIName", "My new toolbar" )
        
        REM *** Set new settings at our toolbar
        oToolbar.setSettings( oToolbarSettings )
        oLayoutManager.showElement( sToolbar )
End Sub

Function CreateToolbarItem( Command as String, Label as String ) as Variant
        Dim aToolbarItem(3) 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
        aToolbarItem(3).Name = "IsVisible"
        aToolbarItem(3).Value = TRUE

        CreateToolbarItem = aToolbarItem()
End Function

Sub Test
        MsgBox "Test"
End Sub

Regards,
Carsten

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

Reply via email to