Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/Listbox and TableView Demos/NSOutlineView/OutlineControl


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/Listbox and TableView Demos/NSOutlineView/OutlineControl

This example is the version from Mon, 5th Mar 2017.

Project "OutlineControl.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control MyTableControl Inherits HierarchicalMacListBox
ControlInstance MyTableControl Inherits HierarchicalMacListBox
EventHandler Sub Open() // Add two columns dim col as new NSTableColumnMBS("First") col.Width = 200 me.AddColumn col col = new NSTableColumnMBS("Second") col.Width = 120 me.AddColumn col // 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 = cols(0) ' 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 mRootItem = new DataNode ("root") for level1 as Integer = 1 to 30 dim node as new DataNode (Str(level1)) mRootItem.children.Append node ' let's give each node a few children for level2 as Integer = 1 to level1 dim node2 as new DataNode (node.text + " - " + Str(level2)) node.children.Append node2 ' let's give each of these nodes a few children as well for level3 as Integer = 1 to 3 'Rnd*5 dim node3 as new DataNode (node.text + " - " + Str(level3)) node2.children.Append node3 next next next me.Reload ' this forces the listbox to update (by calling Events such as childOfItem etc.) End EventHandler
EventHandler Function childOfItem(index as Integer, item as NSOutlineViewItemMBS) As NSOutlineViewItemMBS #pragma DisableBoundsChecking #pragma DisableBackgroundTasks #pragma StackOverflowChecking false 'mCallCount = mCallCount + 1 dim node as DataNode if item = nil then node = mRootItem else node = DataNode(item) end if return node.children(index) End EventHandler
EventHandler Function isItemExpandable(item as NSOutlineViewItemMBS) As Boolean #pragma DisableBoundsChecking #pragma DisableBackgroundTasks #pragma StackOverflowChecking false mCallCount = mCallCount + 1 dim node as DataNode if item = nil then node = mRootItem else node = DataNode(item) end if return node.children.Ubound >= 0 End EventHandler
EventHandler Function numberOfChildrenOfItem(item as NSOutlineViewItemMBS) As integer #pragma DisableBoundsChecking #pragma DisableBackgroundTasks #pragma StackOverflowChecking false 'mCallCount = mCallCount + 1 dim node as DataNode if item = nil then node = mRootItem else node = DataNode(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 #pragma DisableBoundsChecking #pragma DisableBackgroundTasks #pragma StackOverflowChecking false 'mCallCount = mCallCount + 1 dim node as DataNode if item = nil then node = mRootItem else node = DataNode(item) end if return node.text End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Label1.Text = Str (mCallCount) + " (" + Str(MyTableControl.View.numberOfRows) + " rows)" mCallCount = 0 End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Property Private mCallCount As Integer
Property Private mRootItem As DataNode
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class HierarchicalMacListBox Inherits NSOutlineControlMBS
Sub AddColumn(col as NSTableColumnMBS) mRetainedCols.Append col me.View.addTableColumn col End Sub
Sub Reload() me.View.reloadData End Sub
Property Private mRetainedCols() As NSTableColumnMBS
End Class
Class DataNode Inherits NSOutlineViewItemMBS
Sub Constructor(text as String) me.text = text super.Constructor End Sub
Property children() As NSOutlineViewItemMBS
Property text As String
End Class
End Project

See also:

The items on this page are in the following plugins: MBS MacControls Plugin.


The biggest plugin in space...