wxTreeCtrl
Module
Module Summary
Description
A tree control presents information as a hierarchy, with items that may be expanded to show further items. Items in a tree control are referenced by wxTreeItemId (not implemented in wx) handles, which may be tested for validity by calling wxTreeItemId::IsOk() (not implemented in wx).
A similar control with a fully native implementation for GTK+ and macOS as well is wxDataViewTreeCtrl (not implemented in wx).
To intercept events from a tree control, use the event table macros described in wxTreeEvent.
Styles
This class supports the following styles:
See also overview_windowstyles.
Win32 notes:
wxTreeCtrl class uses the standard common treeview control under Win32 implemented in the system library comctl32.dll. Some versions of this library are known to have bugs with handling the tree control colours: the usual symptom is that the expanded items leave black (or otherwise incorrectly coloured) background behind them, especially for the controls using non-default background colour. The recommended solution is to upgrade the comctl32.dll to a newer version: see http://www.microsoft.com/downloads/details.aspx?familyid=cb2cf3a2-8025-4e8f-8511-9b476a8d35d2
See: wxDataViewTreeCtrl (not implemented in wx), wxTreeEvent, wxTreeItemData (not implemented in wx), Overview treectrl, wxListBox, wxListCtrl, wxImageList
This class is derived (and can use functions) from: wxControl wxWindow wxEvtHandler
wxWidgets docs: wxTreeCtrl
Events
Event types emitted from this class: command_tree_begin_drag, command_tree_begin_rdrag, command_tree_end_drag, command_tree_begin_label_edit, command_tree_end_label_edit, command_tree_delete_item, command_tree_get_info, command_tree_set_info, command_tree_item_activated, command_tree_item_collapsed, command_tree_item_collapsing, command_tree_item_expanded, command_tree_item_expanding, command_tree_item_right_click, command_tree_item_middle_click, command_tree_sel_changed, command_tree_sel_changing, command_tree_key_down, command_tree_item_gettooltip, command_tree_item_menu, command_tree_state_image_click
new() -> wxTreeCtrl()
|
Default Constructor.
new(Parent) -> wxTreeCtrl()
|
Types
new(Parent, Options :: [Option]) -> wxTreeCtrl()
|
Types
{id, integer()} |
{pos, {X :: integer(), Y :: integer()}} |
{size, {W :: integer(), H :: integer()}} |
{style, integer()} |
{validator, wx:wx_object()}
Constructor, creating and showing a tree control.
See: create/3, wxValidator (not implemented in wx)
destroy(This :: wxTreeCtrl()) -> ok |
Destructor, destroying the tree control.
Types
{image, integer()} |
{selectedImage, integer()} |
{data, term()}
Adds the root node to the tree, returning the new item.
The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image > -1 and selImage is -1, the same image is used for both selected and unselected items.
Types
{image, integer()} |
{selectedImage, integer()} |
{data, term()}
Appends an item to the end of the branch identified by parent, return a new item id.
The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image > -1 and selImage is -1, the same image is used for both selected and unselected items.
Sets the normal image list.
The image list assigned with this method will be automatically deleted by wxTreeCtrl as appropriate (i.e. it takes ownership of the list).
See: setImageList/2
Sets the state image list.
Image list assigned with this method will be automatically deleted by wxTreeCtrl as appropriate (i.e. it takes ownership of the list).
See: setStateImageList/2
Collapses the given item.
Collapses the given item and removes all children.
Types
{id, integer()} |
{pos, {X :: integer(), Y :: integer()}} |
{size, {W :: integer(), H :: integer()}} |
{style, integer()} |
{validator, wx:wx_object()}
Creates the tree control.
See new/2 for further details.
Deletes the specified item.
A EVT_TREE_DELETE_ITEM event will be generated.
This function may cause a subsequent call to getNextChild/3 to fail.
Types
Deletes all items in the control.
This function generates wxEVT_TREE_DELETE_ITEM events for each item being deleted, including the root one if it is shown, i.e. unless wxTR_HIDE_ROOT style is used.
Deletes all children of the given item (but not the item itself).
A wxEVT_TREE_DELETE_ITEM event will be generated for every item being deleted.
If you have called setItemHasChildren/3, you may need to call it again since deleteChildren/2 does not automatically clear the setting.
editLabel(This, Item) -> wxTextCtrl:wxTextCtrl()
|
Starts editing the label of the given item.
This function generates a EVT_TREE_BEGIN_LABEL_EDIT event which can be vetoed so that no text control will appear for in-place editing.
If the user changed the label (i.e. s/he does not press ESC or leave the text control without changes, a EVT_TREE_END_LABEL_EDIT event will be sent which can be vetoed as well.
See: EndEditLabel() (not implemented in wx), wxTreeEvent
Scrolls and/or expands items to ensure that the given item is visible.
This method can be used, and will work, even while the window is frozen (see wxWindow:freeze/1).
Expands the given item.
Types
{Res :: boolean(),
Rect ::
{X :: integer(),
Y :: integer(),
W :: integer(),
H :: integer()}}
Types
{Res :: boolean(),
Rect ::
{X :: integer(),
Y :: integer(),
W :: integer(),
H :: integer()}}
Retrieves the rectangle bounding the item.
If textOnly is true, only the rectangle around the item's label will be returned, otherwise the item's image is also taken into account.
The return value is true if the rectangle was successfully retrieved or false if it was not (in this case rect is not changed) - for example, if the item is currently invisible.
Notice that the rectangle coordinates are logical, not physical ones. So, for example, the x coordinate may be negative if the tree has a horizontal scrollbar and its position is not 0.
Returns the number of items in the branch.
If recursively is true, returns the total number of descendants, otherwise only one level of children is counted.
Types
Returns the number of items in the control.
getEditControl(This) -> wxTextCtrl:wxTextCtrl()
|
Types
Returns the edit control being currently used to edit a label.
Returns NULL if no label is being edited.
Note: This is currently only implemented for wxMSW.
Returns the first child; call getNextChild/3 for the next child.
For this enumeration function you must pass in a 'cookie' parameter which is opaque for the application but is necessary for the library to make these functions reentrant (i.e. allow more than one enumeration on one and the same object simultaneously). The cookie passed to getFirstChild/2 and getNextChild/3 should be the same variable.
Returns an invalid tree item (i.e. wxTreeItemId::IsOk() (not implemented in wx) returns false) if there are no further children.
Types
Returns the next child; call getFirstChild/2 for the first child.
For this enumeration function you must pass in a 'cookie' parameter which is opaque for the application but is necessary for the library to make these functions reentrant (i.e. allow more than one enumeration on one and the same object simultaneously). The cookie passed to getFirstChild/2 and getNextChild/3 should be the same.
Returns an invalid tree item if there are no further children.
See: getFirstChild/2
Types
Returns the first visible item.
getImageList(This) -> wxImageList:wxImageList()
|
Types
Returns the normal image list.
Types
Returns the current tree control indentation.
getItemBackgroundColour(This, Item) -> wx:wx_colour4()
|
Returns the background colour of the item.
Returns the tree item data associated with the item.
See: wxTreeItemData (not implemented in wx)
getItemFont(This, Item) -> wxFont:wxFont()
|
Returns the font of the item label.
If the font hadn't been explicitly set for the specified item with setItemFont/3, returns an invalid ?wxNullFont font. wxWindow:getFont/1 can be used to retrieve the global tree control font used for the items without any specific font.
Gets the specified item image.
The value of which may be:
getItemText(This, Item) -> unicode:charlist()
|
Returns the item label.
getItemTextColour(This, Item) -> wx:wx_colour4()
|
Returns the colour of the item label.
Returns the last child of the item (or an invalid tree item if this item has no children).
Returns the next sibling of the specified item; call getPrevSibling/2 for the previous sibling.
Returns an invalid tree item if there are no further siblings.
See: getPrevSibling/2
Returns the next visible item or an invalid item if this item is the last visible one.
Note: The item itself must be visible.
Returns the item's parent.
Returns the previous sibling of the specified item; call getNextSibling/2 for the next sibling.
Returns an invalid tree item if there are no further children.
See: getNextSibling/2
Returns the previous visible item or an invalid item if this item is the first visible one.
Note: The item itself must be visible.
Types
Returns the root item for the tree control.
Types
Returns the selection, or an invalid item if there is no selection.
This function only works with the controls without wxTR_MULTIPLE style, use getSelections/1 for the controls which do have this style or, if a single item is wanted, use GetFocusedItem() (not implemented in wx).
Fills the array of tree items passed in with the currently selected items.
This function can be called only if the control has the wxTR_MULTIPLE style.
Returns the number of selected items.
getStateImageList(This) -> wxImageList:wxImageList()
|
Types
Returns the state image list (from which application-defined state images are taken).
Types
Calculates which (if any) item is under the given point, returning the tree item id at this point plus extra information flags.
flags is a bitlist of the following:
Types
{image, integer()} | {selImage, integer()} | {data, term()}
Inserts an item after a given one (previous).
The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image > -1 and selImage is -1, the same image is used for both selected and unselected items.
Returns true if the given item is in bold state.
See: setItemBold/3
Returns true if the item is expanded (only makes sense if it has children).
Returns true if the item is selected.
Returns true if the item is visible on the screen.
Returns true if the item has children.
Types
Returns true if the item is valid.
Types
{image, integer()} |
{selectedImage, integer()} |
{data, term()}
Appends an item as the first child of parent, return a new item id.
The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image > -1 and selImage is -1, the same image is used for both selected and unselected items.
Scrolls the specified item into view.
Note that this method doesn't work while the window is frozen (See wxWindow:freeze/1), at least under MSW.
See: ensureVisible/2
Selects the given item.
In multiple selection controls, can be also used to deselect a currently selected item if the value of select is false.
Notice that calling this method will generate wxEVT_TREE_SEL_CHANGING and wxEVT_TREE_SEL_CHANGED events and that the change could be vetoed by the former event handler.
Sets the indentation for the tree control.
Sets the normal image list.
The image list assigned with this method will not be deleted by wxTreeCtrl's destructor, you must delete it yourself.
See: assignImageList/2
Sets the colour of the item's background.
Makes item appear in bold font if bold parameter is true or resets it to the normal state.
See: isBold/2
Sets the item client data.
Notice that the client data previously associated with the item (if any) is not freed by this function and so calling this function multiple times for the same item will result in memory leaks unless you delete the old item data pointer yourself.
Gives the item the visual feedback for Drag'n'Drop actions, which is useful if something is dragged from the outside onto the tree control (as opposed to a DnD operation within the tree control, which already is implemented internally).
Sets the item's font.
All items in the tree should have the same height to avoid text clipping, so the fonts height should be the same for all of them, although font attributes may vary.
See: setItemBold/3
Force appearance of the button next to the item.
This is useful to allow the user to expand the items which don't have any children now, but instead adding them only when needed, thus minimizing memory usage and loading time.
Sets the specified item's image.
See getItemImage/3 for the description of the which parameter.
Sets the item label.
Sets the colour of the item's text.
Sets the state image list (from which application-defined state images are taken).
Image list assigned with this method will not be deleted by wxTreeCtrl's destructor, you must delete it yourself.
Sets the mode flags associated with the display of the tree control.
The new mode takes effect immediately.
Note: Generic only; MSW ignores changes.
Sorts the children of the given item using OnCompareItems() (not implemented in wx).
You should override that method to change the sort order (the default is ascending case-sensitive alphabetical order).
See: wxTreeItemData (not implemented in wx), OnCompareItems() (not implemented in wx)
Toggles the given item between collapsed and expanded states.
Toggles the given item between selected and unselected states.
For multiselection controls only.
Types
Removes the selection from the currently selected item (if any).
Types
This function either behaves the same as unselect/1 if the control doesn't have wxTR_MULTIPLE style, or removes the selection from all items if it does have this style.
Unselects the given item.
This works in multiselection controls only.