As Wilbert correctly describes it, it's really a bit complicated because of PureBasic's internal toolbar implementation. PureBasic always adds a flexible space, a space and a separator (on Snow Leopard but not on Mavericks!) behind the last visible toolbar button. You may inspect this by executing the following code which enables you to customize your toolbar and by the way see all visible and invisible items which PureBasic always adds to your toolbar:
Code: Select all
#SilkThemePath = #PB_Compiler_Home + "Themes/"
#IconNameList = "disk.png+delete.png+arrow_left.png+arrow_right.png"
UsePNGImageDecoder()
UseZipPacker()
OpenWindow(0, 270, 100, 290, 50, "Customizable toolbar")
CreateToolBar(0, WindowID(0))
If OpenPack(0, #SilkThemePath + "SilkTheme.zip")
*ImageBuffer = AllocateMemory(1024)
If ExaminePack(0)
For i = 0 To CountString(#IconNameList, "+")
ImageSize = UncompressPackMemory(0, *ImageBuffer, MemorySize(*ImageBuffer),
StringField(#IconNameList, i + 1, "+"))
If ImageSize > 0
If CatchImage(i, *ImageBuffer, ImageSize)
ToolBarImageButton(i, ImageID(i))
If i = 2
ToolBarSeparator()
EndIf
EndIf
EndIf
Next i
EndIf
FreeMemory(*ImageBuffer)
EndIf
; ----- Display dialog to customize toolbar
CocoaMessage(0, ToolBarID(0), "runCustomizationPalette:", ToolBarID(0))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Also keep in mind that these PureBasic internals may change with new releases, so please use the following hackish solution with care:
Code: Select all
#NSToolbarSizeModeRegular = 1
OpenWindow(0, 270, 100, 350, 200, "ToolBar with button at right end")
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()
CreateToolBar(0, WindowID(0))
CocoaMessage(0, ToolBarID(0), "setSizeMode:", #NSToolbarSizeModeRegular)
ToolBarImageButton(0, ImageID(0))
ToolBarImageButton(1, ImageID(1))
; ----- 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)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow