Code: Select all
EnableExplicit
#NSTableViewStylePlain = 4
Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "delegate")
Define DelegateClass.I = CocoaMessage(0, AppDelegate, "class")
ProcedureC WillDisplayCell(Object.I, Selector.I, TableView.I, Cell.I,
*Column, Row.I)
Protected Column.I
Protected CellFrame.NSRect
Protected CellText.S
Protected GadgetID.I
Protected LineFrame.NSRect
Protected RowFrame.NSRect
Protected TextSize.NSSize
GadgetID = CocoaMessage(0, TableView, "tag")
Column = CocoaMessage(0, CocoaMessage(0, TableView, "tableColumns"),
"indexOfObject:", *Column)
CellText = GetGadgetItemText(CocoaMessage(0, TableView, "tag"), Row, Column)
CocoaMessage(0, Cell, "setStringValue:$", @CellText)
If GetGadgetItemData(GadgetID, Row) = #True
CocoaMessage(0, Cell, "_setVerticallyCentered:", #YES)
If Column = 0
CocoaMessage(@CellFrame, TableView,
"frameOfCellAtColumn:", Column,
"row:", Row)
CocoaMessage(@TextSize, Cell, "cellSize")
CocoaMessage(@RowFrame, GadgetID(GadgetID), "rectOfRow:", Row)
; ----- Draw line from end of text in column 0 to end of row
LineFrame\origin\x = CellFrame\origin\x + TextSize\width + 10
LineFrame\origin\y = CellFrame\origin\y + CellFrame\size\height / 2 + 1
LineFrame\size\height = 1
LineFrame\size\width = RowFrame\size\width - TextSize\width - 20
CocoaMessage(0, CocoaMessage(0, 0, "NSColor textColor"), "setFill")
CocoaMessage(0, 0, "NSBezierPath fillRect:@", @LineFrame)
CocoaMessage(0, Cell,
"drawInteriorWithFrame:@", @LineFrame,
"inView:", TableView)
CocoaMessage(0, Cell,
"setTextColor:", CocoaMessage(0, 0, "NSColor textColor"))
EndIf
Else
CocoaMessage(0, Cell,
"setTextColor:", CocoaMessage(0, 0, "NSColor textColor"))
EndIf
EndProcedure
ProcedureC IsGroupRowCallback(Object.I, Selector.I, TableView.I, Row.I)
Protected IsGroupRow.I
IsGroupRow = GetGadgetItemData(CocoaMessage(0, TableView, "tag"), Row)
ProcedureReturn IsGroupRow
EndProcedure
OpenWindow(0, 200, 100, 202, 270, "Group demo")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20,
"Fruit", 90)
AddGadgetColumn(0, 1, "Euro/kg", 60)
AddGadgetItem(0, 0, "Stone fruits")
SetGadgetItemData(0, 0, #True)
AddGadgetItem(0, 1, "Apricots" + #LF$ + "2,99")
AddGadgetItem(0, 2, "Peaches" + #LF$ + "2,69")
AddGadgetItem(0, 3, "Plums" + #LF$ + "1,60")
AddGadgetItem(0, 4, "Berries")
SetGadgetItemData(0, 4, #True)
AddGadgetItem(0, 5, "Grapes" + #LF$ + "1,78")
AddGadgetItem(0, 6, "Raspberries" + #LF$ + "2,99")
AddGadgetItem(0, 7, "Strawberries" + #LF$ + "3,56")
CocoaMessage(0, GadgetID(0), "setUsesAlternatingRowBackgroundColors:", #YES)
CocoaMessage(0, CocoaMessage(0, GadgetID(0), "enclosingScrollView"),
"setHasHorizontalScroller:", #False)
class_addMethod_(DelegateClass,
sel_registerName_("tableView:isGroupRow:"),
@IsGroupRowCallback(), "v@:@@")
class_addMethod_(DelegateClass,
sel_registerName_("tableView:willDisplayCell:forTableColumn:row:"),
@WillDisplayCell(), "v@:@@@@")
CocoaMessage(0, GadgetID(0), "setDelegate:", AppDelegate)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow