Hi all.
I am trying to emulate a togglebutton/checkbox in a custom toolbar.
Right now I have settled for having two toolbar buttons with different
icons. Only one of them is visible and when it's pressed it toggles the
visibility of both buttons using the code below (which sets visibility
of a single button with a given label).
It works OK but only as long as the user doesn't fiddle with button
visibility :-). Is there a way of changing a toolbar button's icon
directly from Basic code ? I could not figure out how to do it.
Kind regards
-- Jan Holst Jensen
Sub SetToolbarButtonVisible(ToolbarURL as String, ButtonLabel as String,
Visibility as Boolean)
Dim LayoutMgr as Variant
Dim Toolbar as Variant
Dim ToolbarSettings as Variant
LayoutMgr = ThisComponent.GetCurrentController().GetFrame().LayoutManager
Toolbar = LayoutMgr.GetElement(ToolbarURL)
Toolbar.Persistent = False
ToolbarSettings = Toolbar.GetSettings(True)
Dim I, J as Integer
Dim ButtonCount as Integer
Dim ButtonFound as Boolean
ButtonCount = ToolbarSettings.GetCount()
For I = 0 To ButtonCount - 1
ButtonFound = False
Dim ToolbarButtonProps()
ToolbarButtonProps() = ToolbarSettings.GetByIndex(I)
For J = 0 To UBound(ToolbarButtonProps())
If ToolbarButtonProps(J).Name = "Label" and
ToolbarButtonProps(J).Value = ButtonLabel Then
ButtonFound = True
End If
Next
If ButtonFound Then
For J = 0 To UBound(ToolbarButtonProps())
If ToolbarButtonProps(J).Name = "IsVisible" Then
ToolbarButtonProps(J).Value = Visibility
End If
Next
' Write properties back - ToolbarButtonProps() is a local copy(!).
ToolbarSettings.ReplaceByIndex(I, ToolbarButtonProps)
End If
Next
Toolbar.SetSettings( ToolbarSettings )
End Sub