Thank you for your kind words...
I was even able to add other gadgets to the ToolBar which are all fully functional. The only drawback is that you have to define all dummy buttons to be replaced with gadgets in the ToolBar in advance because an error will be displayed when you try to add additional buttons to the ToolBar dynamically:
Code: Select all
#NSToolbarSizeModeRegular = 1
Procedure AddGadgetToToolBar(GadgetID.I, ButtonID.I)
Protected Item.I
Protected ItemArray.I
Protected Size.NSSize
; ----- Get item object of ToolBar button
ItemArray = CocoaMessage(0, ToolBarID(0), "items")
Item = CocoaMessage(0, ItemArray, "objectAtIndex:", ButtonID)
; ----- Get width and height of gadget
Size\width = GadgetWidth(GadgetID)
Size\height = GadgetHeight(GadgetID)
; ----- Replace ToolBar button by gadget
CocoaMessage(0, Item, "setView:", GadgetID(GadgetID))
; ----- Change ToolBar button size to that of gadget
CocoaMessage(0, Item, "setMaxSize:@", @Size)
CocoaMessage(0, Item, "setMinSize:@", @Size)
EndProcedure
OpenWindow(0, 270, 100, 350, 50, "ToolBar with different gadgets",
#PB_Window_SystemMenu | #PB_Window_Invisible)
ComboBoxGadget(0, 0, 0, 100, 22)
AddGadgetItem(0, 0, "MacOS X")
AddGadgetItem(0, 1, "Linux")
AddGadgetItem(0, 2, "Windows")
SetGadgetState(0, 0)
ProgressBarGadget(1, 10, 10, 100, 16, 0, 100)
SetGadgetState(1, 0)
TrackBarGadget(2, 0, 0, 100, 20, 0, 100)
SetGadgetState(2, 50)
; ----- Create standard ToolBar
CreateToolBar(0, WindowID(0))
; ----- Change size of ToolBar to larger icons
CocoaMessage(0, ToolBarID(0), "setSizeMode:", #NSToolbarSizeModeRegular)
; ----- Create empty dummy image
CreateImage(0, 24, 24)
; ----- Add buttons with dummy image to ToolBar
ToolBarImageButton(0, ImageID(0))
ToolBarImageButton(1, ImageID(0))
ToolBarImageButton(2, ImageID(0))
; ----- Free empty dummy image
FreeImage(0)
; ----- Add gadgets to ToolBar
AddGadgetToToolBar(0, 0)
AddGadgetToToolBar(1, 1)
AddGadgetToToolBar(2, 2)
; ----- Make window visible now in order to hide previous ToolBar modifications
HideWindow(0, #False)
AddWindowTimer(0, 0, 50)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Timer
If EventTimer() = 0
CurrentState = GetGadgetState(1) + 1
If CurrentState > 100
CurrentState = 0
EndIf
SetGadgetState(1, CurrentState)
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case 0
If EventType() = #PB_EventType_Change
Debug "ComboBox selection changed to " + GetGadgetText(0)
EndIf
Case 2
Debug "Trackbar position changed to " + GetGadgetState(2)
EndSelect
EndSelect
ForEver