]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/overviews/treectrl.h
Update OpenVMS compile support
[wxWidgets.git] / docs / doxygen / overviews / treectrl.h
CommitLineData
15b6757b 1/////////////////////////////////////////////////////////////////////////////
2cd3cc94 2// Name: treectrl.h
15b6757b
FM
3// Purpose: topic overview
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
880efa2a 9/**
36c9828f 10
2cd3cc94 11@page overview_treectrl wxTreeCtrl Overview
36c9828f 12
2cd3cc94 13Classes: wxTreeCtrl, wxImageList
7fa3c420 14
2cd3cc94
BP
15The tree control displays its items in a tree like structure. Each item has
16its own (optional) icon and a label. An item may be either collapsed (meaning
17that its children are not visible) or expanded (meaning that its children are
18shown). Each item in the tree is identified by its @c itemId which is of opaque
19data type wxTreeItemId. You can test whether an item is valid by calling
20wxTreeItemId::IsOk.
7fa3c420 21
2cd3cc94
BP
22The items text and image may be retrieved and changed with (Get|Set)ItemText
23and (Get|Set)ItemImage. In fact, an item may even have two images associated
24with it: the normal one and another one for selected state which is
25set/retrieved with (Get|Set)ItemSelectedImage functions, but this functionality
26might be unavailable on some platforms.
7fa3c420 27
2cd3cc94
BP
28Tree items have several attributes: an item may be selected or not, visible or
29not, bold or not. It may also be expanded or collapsed. All these attributes
30may be retrieved with the corresponding functions: IsSelected, IsVisible,
31IsBold and IsExpanded. Only one item at a time may be selected, selecting
32another one (with SelectItem) automatically unselects the previously selected
33one.
7fa3c420 34
2cd3cc94
BP
35In addition to its icon and label, a user-specific data structure may be
36associated with all tree items. If you wish to do it, you should derive a class
37from wxTreeItemData which is a very simple class having only one function
38GetId() which returns the id of the item this data is associated with. This
39data will be freed by the control itself when the associated item is deleted
40(all items are deleted when the control is destroyed), so you shouldn't delete
41it yourself (if you do it, you should call SetItemData(@NULL) to prevent the
42tree from deleting the pointer second time). The associated data may be
43retrieved with GetItemData() function.
7fa3c420 44
2cd3cc94
BP
45Working with trees is relatively straightforward if all the items are added to
46the tree at the moment of its creation. However, for large trees it may be
47very inefficient. To improve the performance you may want to delay adding the
48items to the tree until the branch containing the items is expanded: so, in the
49beginning, only the root item is created (with AddRoot). Other items are added
50when EVT_TREE_ITEM_EXPANDING event is received: then all items lying
51immediately under the item being expanded should be added, but, of course, only
52when this event is received for the first time for this item - otherwise, the
53items would be added twice if the user expands/collapses/re-expands the branch.
7fa3c420 54
2cd3cc94
BP
55The tree control provides functions for enumerating its items. There are 3
56groups of enumeration functions: for the children of a given item, for the
57sibling of the given item and for the visible items (those which are currently
58shown to the user: an item may be invisible either because its branch is
59collapsed or because it is scrolled out of view). Child enumeration functions
60require the caller to give them a @e cookie parameter: it is a number which
61is opaque to the caller but is used by the tree control itself to allow
62multiple enumerations to run simultaneously (this is explicitly allowed). The
63only thing to remember is that the @e cookie passed to GetFirstChild and to
64GetNextChild should be the same variable (and that nothing should be done with
65it by the user code).
7fa3c420 66
2cd3cc94
BP
67Among other features of the tree control are: item sorting with SortChildren
68which uses the user-defined comparison function OnCompareItems (by default the
69comparison is the alphabetic comparison of tree labels), hit testing
70(determining to which portion of the control the given point belongs, useful
71for implementing drag-and-drop in the tree) with HitTest and editing of the
72tree item labels in place (see EditLabel).
36c9828f 73
2cd3cc94
BP
74Finally, the tree control has a keyboard interface: the cursor navigation
75(arrow) keys may be used to change the current selection. HOME and END are used
76to go to the first/last sibling of the current item. '+', '-' and '*' expand,
77collapse and toggle the current branch. Note, however, that DEL and INS keys do
78nothing by default, but it is common to associate them with deleting an item
79from a tree and inserting a new one into it.
36c9828f 80
2cd3cc94 81*/
36c9828f 82