Oh! I thought you were making a UNO Component. You are doing a Macro.

On 10/24/06, Knut Olav Bøhmer <[EMAIL PROTECTED]> wrote:

On 10/24/06, Tabish F. Mufti <[EMAIL PROTECTED]> wrote:
>
> Hi Knut
>
> If you have made a toolbar please send me the code snippet and the
> procedures towards its integration. I'll be highly Thankful.



'MakeToolbar.main( sToolBar, "Save", "
vnd.sun.star.script:App.Arkiver.Main?language=Basic&location=application",
"Arkiver", "MY ToolBar", oDoc)


Sub Main (sToolBar as String, Button as String, Macro as String, Label as
String, Title as String, optional Dok, optional save)
    Dim oCurrFrame
    Dim oLayoutManager
    Dim oToolbar
    Dim oToolbarSettings
    Dim oToolbarItem
    Dim oUICfgMgr
    Dim BarExsist

    on Error goto AnError
    BarExsist = false

    if isMissing(Dok) Then
        Dok = ThisComponent
    End if

    if isMissing(save) Then
        save = true
    End if

    oUICfgMgr = Dok.getUIConfigurationManager()

    oCurrFrame       = Dok.currentController.Frame
    oLayoutManager   = oCurrFrame.LayoutManager

    if oUICfgMgr.hasSettings( sToolBar ) then
        'oUICfgMgr.replaceSettings( sToolBar, oToolbarSettings )
        oToolbarSettings         = oUICfgMgr.getSettings( sToolBar, True )
        oToolbar = oLayoutManager.getElement( sToolbar )
        BarExsist = True

    else
        oLayoutManager.createElement( sToolbar )
        oLayoutManager.hideElement( sToolbar )
        oToolbar = oLayoutManager.getElement( sToolbar )
        oToolbarSettings = oToolbar.getSettings( true )
    End If

    'oToolbar = oLayoutManager.getElement( sToolbar )
    oToolbarItem = CreateToolbarItem( Macro, Label )
    oToolbarSettings.insertByIndex( 0, oToolbarItem )
    oToolbarSettings.setPropertyValue( "UIName", Title )

    oToolbar.setSettings( oToolbarSettings )
    If BarExsist Then
        oUICfgMgr.replaceSettings( sToolBar, oToolbarSettings )
    Else
        oUICfgMgr.insertSettings( sToolBar, oToolbarSettings )
        oLayoutManager.showElement( sToolbar )
    End if

    if save then
        oUICfgMgr.store()
    end if
    Goto Done
AnError:
    MsgBox "Feil under laging av knapp [linje:" + erl + "]" + Chr(13) +
Err() + ": " + Error()

Done:

End Sub

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

    aToolbarItem(0) = MakePropertyValue("CommandURL", Command)
    aToolbarItem(1) = MakePropertyValue("Label", Label)
    aToolbarItem(2) = MakePropertyValue("Type", 0)
    aToolbarItem(3) = MakePropertyValue("IsVisible", True)

       CreateToolbarItem = aToolbarItem()
End Function

Function MakePropertyValue( Optional cName As String, Optional uValue ) As
com.sun.star.beans.PropertyValue
   Dim oPropertyValue As New com.sun.star.beans.PropertyValue
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function


Sub remove (sToolBar as String, optional Dok)
        REM *** Initialize strings
    Dim oCurrFrame
    Dim oLayoutManager
    Dim oToolbar
    Dim oToolbarSettings
    Dim oToolbarItem
    Dim oUICfgMgr

    on Error goto AnError
    if isMissing(Dok) Then
        Dok = ThisComponent
    End if

    oUICfgMgr = Dok.getUIConfigurationManager()

    if oUICfgMgr.hasSettings( sToolBar ) then
        oUICfgMgr.removeSettings( sToolBar ,True )
        oUICfgMgr.store()
    end If
    Goto Done
AnError:
    MsgBox "Feil under fjerning av knapp [linje:" + erl + "]" + Chr(13) +
Err() + ": " + Error()

Done:

End Sub



--
Knut Olav Bøhmer


Reply via email to