Do you want to display left aligned, centered and right aligned buttons in the toolbar? I have already demonstrated how to display a right aligned button in the toolbar
here (2nd code example).
For your conveniance I have extended that example to display a left aligned, centered and right aligned button. The trick is to insert a flexible space item (NSToolbarFlexibleSpaceItem) between two toolbar buttons:
Code:
#NSToolbarSizeModeRegular = 1
OpenWindow(0, 270, 100, 450, 100,
"ToolBar with left aligned, centered and right aligned button")
CreateImage(0, 24, 24)
StartDrawing(ImageOutput(0))
Box(0, 0, 24, 24, $FF0000)
Box(4, 4, 16, 16, $FFFF)
StopDrawing()
CreateImage(1, 24, 24)
StartDrawing(ImageOutput(1))
Box(0, 0, 24, 24, $FF)
Box(4, 4, 16, 16, $FFFF)
StopDrawing()
CreateImage(2, 24, 24)
StartDrawing(ImageOutput(2))
Box(0, 0, 24, 24, $32CD32)
Box(4, 4, 16, 16, $FFFF)
StopDrawing()
CreateToolBar(0, WindowID(0))
CocoaMessage(0, ToolBarID(0), "setSizeMode:", #NSToolbarSizeModeRegular)
ToolBarImageButton(0, ImageID(0))
ToolBarImageButton(1, ImageID(1))
ToolBarImageButton(2, ImageID(2))
; ----- Count visible and invisible toolbar items
ItemCount = CocoaMessage(0, CocoaMessage(0, ToolBarID(0), "items"), "count")
If OSVersion() <= #PB_OS_MacOSX_10_6
; ----- Remove rightmost separator
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1
EndIf
; ----- Remove rightmost space
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1
; ----- Remove rightmost flexible space
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1
; ----- Insert flexible space between 1st and 2nd button
CocoaMessage(0, ToolBarID(0),
"insertItemWithItemIdentifier:$", @"NSToolbarFlexibleSpaceItem",
"atIndex:", 1)
; ----- Insert flexible space between 2nd and 3rd button
CocoaMessage(0, ToolBarID(0),
"insertItemWithItemIdentifier:$", @"NSToolbarFlexibleSpaceItem",
"atIndex:", 3)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow