Platforms to show: All Mac Windows Linux Cross-Platform
/MacControls/Outline View Test
Required plugins for this example: MBS MacCocoa Plugin, MBS MacBase Plugin, MBS Main Plugin, MBS MacControls Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/Outline View Test
This example is the version from Mon, 5th Mar 2017.
Project "Outline View Test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control List Inherits NSOutlineControlMBS
ControlInstance List Inherits NSOutlineControlMBS
EventHandler Sub Open()
View = me.view
if View = nil then
Break // not initialized?
end if
// Add two columns
dim col1 as new NSTableColumnMBS("First")
dim col2 as new NSTableColumnMBS("Second")
col1.Width = 200
col2.Width = 120
columns.Append col1
columns.Append col2
me.View.addTableColumn col1
me.View.addTableColumn col2
// Set some options to make the list "prettier"
me.View.usesAlternatingRowBackgroundColors = true
me.View.gridStyleMask = NSTableViewMBS.NSTableViewSolidHorizontalGridLineMask + NSTableViewMBS.NSTableViewSolidVerticalGridLineMask
// Specify the column that contains the "expand" icons. If we don't set this, we effectively get a flat list instead
dim cols() as NSTableColumnMBS = me.View.tableColumns()
me.View.outlineTableColumn = col1 ' use the first column
// If we want to allow column resizing, this option should be set to avoid ugly visual effect while resizing
// (i.e. the vertical grid lines do not move nicely, then), or the gridlines should be not used.
me.View.autoresizesOutlineColumn = false
// Set up our hierarchical data, which is a tree structure
RootItem = new ListItem
dim d1 as new ListItem("People")
dim p1 as new ListItem("Antoine", 3453)
dim p2 as new ListItem("Bob", 53345)
dim p3 as new ListItem("Christoph", 457546)
dim p4 as new ListItem("Dagmar", 46575)
d1.Append p1
d1.Append p2
d1.Append p3
d1.Append p4
RootItem.Append d1
dim d2 as new ListItem("Cities")
dim c1 as new ListItem("London", 2435)
dim c2 as new ListItem("Munich", 436)
dim c3 as new ListItem("New York", 54325)
dim c4 as new ListItem("Oldenburg", 674756)
d2.Append c1
d2.Append c2
d2.Append c3
d2.Append c4
RootItem.Append d2
// this forces the listbox to update (by calling Events such as childOfItem etc.)
me.View.reloadData
End EventHandler
EventHandler Function childOfItem(index as Integer, item as NSOutlineViewItemMBS) As NSOutlineViewItemMBS
dim node as ListItem
if item = nil then
node = RootItem
else
node = ListItem(item)
end if
return node.children(index)
End EventHandler
EventHandler Function isItemExpandable(item as NSOutlineViewItemMBS) As Boolean
dim node as ListItem
if item = nil then
node = RootItem
else
node = ListItem(item)
end if
return node.children.Ubound >= 0
End EventHandler
EventHandler Function numberOfChildrenOfItem(item as NSOutlineViewItemMBS) As integer
dim node as ListItem
if item = nil then
node = RootItem
else
node = ListItem(item)
end if
if node <> nil then
return node.children.Ubound+1
end if
End EventHandler
EventHandler Function objectValue(tableColumn as NSTableColumnMBS, item as NSOutlineViewItemMBS) As Variant
dim node as ListItem
if item = nil then
node = RootItem
else
node = ListItem(item)
end if
dim colIndex as integer = Columns.IndexOf(tableColumn)
return node.Values(colIndex)
End EventHandler
End Control
Property Columns() As NSTableColumnMBS
Property RootItem As ListItem
Property View As NSOutlineViewMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class ListItem Inherits NSOutlineViewItemMBS
Sub Append(n as ListItem)
Children.Append n
End Sub
Sub Constructor(v1 as Variant = nil, v2 as Variant = nil)
super.Constructor
values.Append v1
values.Append v2
End Sub
Property Children() As Variant
Property Values() As Variant
End Class
End Project
The items on this page are in the following plugins: MBS MacControls Plugin.