
Thanks.
Code: Select all
If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(0, 10, 10, 160, 160) ; TreeGadget standard
TreeGadget(1, 180, 10, 160, 160, #PB_Tree_CheckBoxes | #PB_Tree_NoLines) ; TreeGadget with Checkboxes + NoLines
For ID = 0 To 1
For a = 0 To 10
AddGadgetItem (ID, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use
AddGadgetItem (ID, -1, "Node "+Str(a), 0, 0) ; ImageID(x) as 4th parameter
AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1) ; These are on the 1st sublevel
AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1)
AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1)
AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1)
AddGadgetItem (ID, -1, "File "+Str(a), 0, 0) ; sublevel 0 again
Next
Next
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
No, it doesn't look fine. The checkboxes should indent with the gadget's levels. If the same type of control looks different in other applications then perhaps you need to report a bug. If the same type of control exhibits the same behaviour in other applications then it's probably the Mac way of drawing the gadget, though I'm dubious on that latter point.wombats wrote:...it looks fine:
With my workaround below you can obtain this result:wombats wrote:Is it possible to change the TreeGadget so the icons are indented as in the one on the right in the image below?
Code: Select all
EnableExplicit
#NSSwitchButton = 3
ImportC ""
sel_registerName(MethodName.P-ASCII)
class_addMethod(Class.I, Selector.I, Implementation.I, Types.P-ASCII)
EndImport
Dim ButtonCell.I(0)
Define i.I
ProcedureC CellDisplayCallback(Object.I, Selector.I, OutlineView.I,
TableColumn.I, Item.I)
Shared ButtonCell.I()
Protected Row.I = CocoaMessage(0, GadgetID(0), "rowForItem:", Item)
If ButtonCell(Row) <> 0
ProcedureReturn ButtonCell(Row)
EndIf
EndProcedure
Procedure SetGadgetCallback(GadgetID.I, GadgetCallback.I, Method.S)
Protected AppDelegate.I
Protected DelegateClass.I
Protected PlaceholderList.S
PlaceholderList = LSet("@:", CountString(Method, ":"), "@")
AppDelegate = CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "delegate")
DelegateClass = CocoaMessage(0, AppDelegate, "class")
class_addMethod(DelegateClass, sel_registerName(Method), GadgetCallback,
PlaceholderList)
CocoaMessage(0, GadgetID(GadgetID), "setDelegate:", AppDelegate)
EndProcedure
Procedure AddImageToTreeRow(ImageID.I, Row.I)
Shared ButtonCell.I()
Protected ItemText.S
Protected TableColumn.I
TableColumn = CocoaMessage(0, CocoaMessage(0, GadgetID(0), "tableColumns"),
"objectAtIndex:", 0)
ButtonCell(Row) = CocoaMessage(0, 0, "NSButtonCell new")
CocoaMessage(0, ButtonCell(Row), "setButtonType:", #NSSwitchButton)
CocoaMessage(0, ButtonCell(Row), "setImage:", ImageID(ImageID))
ItemText = GetGadgetItemText(0, Row)
CocoaMessage(0, ButtonCell(Row), "setTitle:$", @ItemText)
EndProcedure
Procedure LoadIcons(IconNameList.S)
Protected i.I
Protected *ImageBuffer
Protected ImageSize.I
If OpenPack(0, #PB_Compiler_Home + "Themes/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
CatchImage(i, *ImageBuffer, ImageSize)
EndIf
Next i
EndIf
FreeMemory(*ImageBuffer)
EndIf
EndProcedure
UsePNGImageDecoder()
UseZipPacker()
LoadIcons("folder.png+page_white.png")
OpenWindow(0, 270, 100, 140, 110, "Tree")
TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
AddGadgetItem (0, -1, "Parent")
For i = 1 To 3
AddGadgetItem (0, -1, "Child" + Str(i), 0, 1)
Next i
SetGadgetItemState(0, 0, #PB_Tree_Expanded)
; ----- Setup callback for TreeGadget
SetGadgetCallback(0, @CellDisplayCallback(),
"outlineView:dataCellForTableColumn:item:")
; ----- Add images to specified rows
ReDim ButtonCell(CountGadgetItems(0) - 1)
AddImageToTreeRow(0, 0)
AddImageToTreeRow(1, 1)
AddImageToTreeRow(1, 2)
AddImageToTreeRow(1, 3)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
; ----- Release NSButtonCell objects
For i = 0 To CountGadgetItems(0) - 1
If ButtonCell(i) <> 0
CocoaMessage(0, ButtonCell(i), "release")
EndIf
Next i