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