]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/ttreectl.tex
fixed nonsenses in tnoneng.tex
[wxWidgets.git] / docs / latex / wx / ttreectl.tex
CommitLineData
a660d684
KB
1\section{wxTreeCtrl overview}\label{wxtreectrloverview}
2
3Classes: \helpref{wxTreeCtrl}{wxtreectrl}, \helpref{wxImageList}{wximagelist}
4
ed93168b
VZ
5The tree control displays its items in a tree like structure. Each item has its
6own (optional) icon and a label. An item may be either collapsed (meaning that
7its children are not visible) or expanded (meaning that its children are
8shown). Each item in the tree is identified by its {\it itemId} which is of
9opaque data type {\it wxTreeItemId}.
a660d684 10
ed93168b
VZ
11The items text and image may be retrieved and changed with
12\helpref{GetItemText}{wxtreectrlgetitemtext}/\helpref{SetItemText}{wxtreectrlsetitemtext}
13and
14\helpref{GetItemImage}{wxtreectrlgetitemimage}/\helpref{SetItemImage}{wxtreectrlsetitemimage}.
15In fact, an item may even have two images associated with it: the normal one
16and another one for selected state which is set/retrieved with
17\helpref{SetItemSelectedImage}{wxtreectrlsetitemselectedimage}/\helpref{GetItemSelectedImage}{wxtreectrlgetitemselectedimage}
18functions, but this functionality might be unavailable on some platforms.
19
20Tree items have several attributes: an item may be selected or not, visible or
21not, bold or not. It may also be expanded or collapsed. All these attributes
22may be retrieved with the corresponding functions:
23\helpref{IsSelected}{wxtreectrlisselected},
24\helpref{IsVisible}{wxtreectrlisvisible}, \helpref{IsBold}{wxtreectrlisbold}
25and \helpref{IsExpanded}{wxtreectrlisexpanded}. Only one item at a time may be
f6bcfd97 26selected, selecting another one (with
ed93168b
VZ
27\helpref{SelectItem}{wxtreectrlselectitem}) automatically unselects the
28previously selected one.
29
30In addition to its icon and label, a user-specific data structure may be associated
31with all tree items. If you wish to do it, you should derive a class from {\it
32wxTreeItemData} which is a very simple class having only one function {\it
33GetId()} which returns the id of the item this data is associated with. This
34data will be freed by the control itself when the associated item is deleted
35(all items are deleted when the control is destroyed), so you shouldn't delete
36it yourself (if you do it, you should call
37\helpref{SetItemData(NULL)}{wxtreectrlsetitemdata} to prevent the tree from
38deleting the pointer second time). The associated data may be retrieved with
39\helpref{GetItemData()}{wxtreectrlgetitemdata} function.
40
41Working with trees is relatively straightforward if all the items are added to
42the tree at the moment of its creation. However, for large trees it may be
43very inefficient. To improve the performance you may want to delay adding the
44items to the tree until the branch containing the items is expanded: so, in the
45beginning, only the root item is created (with
46\helpref{AddRoot}{wxtreectrladdroot}). Other items are added when
47EVT\_TREE\_ITEM\_EXPANDING event is received: then all items lying immediately
48under the item being expanded should be added, but, of course, only when this
49event is received for the first time for this item - otherwise, the items would
f6bcfd97 50be added twice if the user expands/collapses/re-expands the branch.
ed93168b
VZ
51
52The tree control provides functions for enumerating its items. There are 3
53groups of enumeration functions: for the children of a given item, for the
54sibling of the given item and for the visible items (those which are currently
55shown to the user: an item may be invisible either because its branch is
56collapsed or because it is scrolled out of view). Child enumeration functions
57require the caller to give them a {\it cookie} parameter: it is a number which
58is opaque to the caller but is used by the tree control itself to allow
59multiple enumerations to run simultaneously (this is explicitly allowed). The
60only thing to remember is that the {\it cookie} passed to
61\helpref{GetFirstChild}{wxtreectrlgetfirstchild} and to
62\helpref{GetNextChild}{wxtreectrlgetnextchild} should be the same variable (and
63that nothing should be done with it by the user code).
64
2a47d3c1 65Among other features of the tree control are: item sorting with
ed93168b
VZ
66\helpref{SortChildren}{wxtreectrlsortchildren} which uses the user-defined comparison
67function \helpref{OnCompareItems}{wxtreectrloncompareitems} (by default the
68comparison is the alphabetic comparison of tree labels), hit testing
69(determining to which portion of the control the given point belongs, useful
70for implementing drag-and-drop in the tree) with
71\helpref{HitTest}{wxtreectrlhittest} and editing of the tree item labels in
72place (see \helpref{EditLabel}{wxtreectrleditlabel}).
73
74Finally, the tree control has a keyboard interface: the cursor navigation (arrow) keys
75may be used to change the current selection. <HOME> and <END> are used to go to
76the first/last sibling of the current item. '+', '-' and '*' expand, collapse
77and toggle the current branch. Note, however, that <DEL> and <INS> keys do
2a47d3c1
JS
78nothing by default, but it is usual to associate them with deleting item from
79a tree and inserting a new one into it.
80