TreeView

A hierarchical tree of selectable, expandable nodes.

Constructors

this
this(Widget parent)

Create a tree view inside parent.

Members

Functions

addChild
TreeItem addChild(TreeItem parent, string text)

Add a node captioned text as the last child of parent.

addRoot
TreeItem addRoot(string text)

Add a top-level node captioned text.

clear
void clear()

Remove every node (and release any retained item data; see setItemData).

expandItem
void expandItem(TreeItem item)

Expand item to reveal its children.

getFirstRoot
TreeItem getFirstRoot()

Get the first top-level node (a null TreeItem if the tree is empty).

getItemData
void* getItemData(TreeItem item)

Retrieve the opaque pointer previously stored with setItemData.

getItemText
string getItemText(TreeItem item)

Get the caption text of item.

getPreferredSize
Size getPreferredSize()

Tree views prefer a generously sized box.

getSelectedItem
TreeItem getSelectedItem()

Get the currently selected node (a null TreeItem if none).

processNotify
bool processNotify(NMHDR* header)

Translate tree-view selection-change notifications into events.

processSubclassed
bool processSubclassed(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result)

Turn WM_CONTEXTMENU into onContextMenu. The message is raised by a right-click and by the keyboard (Apps key / Shift+F10); the latter arrives with a position of (-1, -1), in which case the menu is anchored at the selected node so a keyboard user gets the menu where focus is.

setItemData
void setItemData(TreeItem item, void* data)

Associate an opaque data pointer with item.

setSelectedItem
void setSelectedItem(TreeItem item)

Select item.

Variables

onContextMenu
Event!(TreeItem, MouseEventArgs) onContextMenu;

Fired when a context menu is requested, carrying the relevant item and the screen position to show the menu at. Raised both by a mouse right-click (item under the cursor) and by the keyboard — the Apps key or Shift+F10 — in which case the item is the selected node and the position is anchored to it. The screen coordinates can be passed straight to showPopupMenu.

onSelectionChanged
Event!(TreeItem) onSelectionChanged;

Fired when the selected node changes, carrying the newly selected item.

Inherited Members

From Control

controlId
int controlId()

The control's command identifier (the hMenu child id at creation).

setText
void setText(string text)

Set the control's text.

getText
string getText()

Get the control's text.

setFont
void setFont(HFONT font)

Assign a font to the control and request a repaint.

getPreferredSize
Size getPreferredSize()

A reasonable default preferred size; override per control type.

processCommand
bool processCommand(ushort notificationCode)

Handle a WM_COMMAND notification routed from the parent.

processNotify
bool processNotify(NMHDR* header)

Handle a WM_NOTIFY notification routed from the parent. Return true if it was handled. The default does nothing.

subclass
void subclass()

Install a subclass window procedure so the control can intercept its own messages (for example, swallowing the Enter key in a text field). Idempotent. Subclasses override processSubclassed to do the work.

processSubclassed
bool processSubclassed(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result)

Intercept a message while subclassed. Set result and return true to consume the message; return false to let default processing continue.

Meta