1 \section{\class{wxTreeCtrl
}}\label{wxtreectrl
}
3 A tree control presents information as a hierarchy, with items that may be expanded
4 to show further items. Items in a tree control are referenced by long integer handles.
6 To intercept events from a tree control, use the event table macros described in
\helpref{wxTreeEvent
}{wxtreeevent
}.
8 \wxheading{Derived from
}
10 \helpref{wxControl
}{wxcontrol
}\\
11 \helpref{wxWindow
}{wxwindow
}\\
12 \helpref{wxEvtHandler
}{wxevthandler
}\\
13 \helpref{wxObject
}{wxobject
}
15 \wxheading{Window styles
}
18 \begin{twocollist
}\itemsep=
0pt
19 \twocolitem{\windowstyle{wxTR
\_HAS\_BUTTONS}}{Use this style to show + and - buttons to the
20 left of parent items.
}
21 \twocolitem{\windowstyle{wxTR
\_EDIT\_LABELS}}{Use this style if you wish the user to be
22 able to edit labels in the tree control.
}
25 See also
\helpref{window styles overview
}{windowstyles
}.
27 \wxheading{Event handling
}
29 To process input from a tree control, use these event handler macros to direct input to member
30 functions that take a
\helpref{wxTreeEvent
}{wxtreeevent
} argument.
33 \begin{twocollist
}\itemsep=
0pt
34 \twocolitem{{\bf EVT
\_TREE\_BEGIN\_DRAG(id, func)
}}{Begin dragging with the left mouse button.
}
35 \twocolitem{{\bf EVT
\_TREE\_BEGIN\_RDRAG(id, func)
}}{Begin dragging with the right mouse button.
}
36 \twocolitem{{\bf EVT
\_TREE\_BEGIN\_LABEL\_EDIT(id, func)
}}{Begin editing a label.
}
37 \twocolitem{{\bf EVT
\_TREE\_END\_LABEL\_EDIT(id, func)
}}{Finish editing a label.
}
38 \twocolitem{{\bf EVT
\_TREE\_DELETE\_ITEM(id, func)
}}{Delete an item.
}
39 \twocolitem{{\bf EVT
\_TREE\_GET\_INFO(id, func)
}}{Request information from the application.
}
40 \twocolitem{{\bf EVT
\_TREE\_SET\_INFO(id, func)
}}{Information is being supplied.
}
41 \twocolitem{{\bf EVT
\_TREE\_ITEM\_EXPANDED(id, func)
}}{Parent has been expanded.
}
42 \twocolitem{{\bf EVT
\_TREE\_ITEM\_EXPANDING(id, func)
}}{Parent is being expanded.
}
43 \twocolitem{{\bf EVT
\_TREE\_SEL\_CHANGED(id, func)
}}{Selection has changed.
}
44 \twocolitem{{\bf EVT
\_TREE\_SEL\_CHANGING(id, func)
}}{Selection is changing.
}
45 \twocolitem{{\bf EVT
\_TREE\_KEY\_DOWN(id, func)
}}{A key has been pressed.
}
50 \helpref{wxTreeCtrl overview
}{wxtreectrloverview
},
\helpref{wxListBox
}{wxlistbox
},
\helpref{wxListCtrl
}{wxlistctrl
},
\rtfsp
51 \helpref{wxImageList
}{wximagelist
},
\helpref{wxTreeEvent
}{wxtreeevent
}
53 \latexignore{\rtfignore{\wxheading{Members
}}}
55 \membersection{wxTreeCtrl::wxTreeCtrl
}\label{wxtreectrlconstr
}
57 \func{}{wxTreeCtrl
}{\void}
61 \func{}{wxTreeCtrl
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
62 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
63 \param{long
}{ style = wxTR
\_HAS\_BUTTONS},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listCtrl"
}}
65 Constructor, creating and showing a tree control.
67 \wxheading{Parameters
}
69 \docparam{parent
}{Parent window. Must not be NULL.
}
71 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
73 \docparam{pos
}{Window position.
}
75 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
78 \docparam{style
}{Window style. See
\helpref{wxTreeCtrl
}{wxtreectrl
}.
}
80 \docparam{validator
}{Window validator.
}
82 \docparam{name
}{Window name.
}
86 \helpref{wxTreeCtrl::Create
}{wxtreectrlcreate
},
\helpref{wxValidator
}{wxvalidator
}
88 \membersection{wxTreeCtrl::
\destruct{wxTreeCtrl
}}
90 \func{void
}{\destruct{wxTreeCtrl
}}{\void}
92 Destructor, destroying the list control.
94 \membersection{wxTreeCtrl::Create
}\label{wxtreectrlcreate
}
96 \func{bool
}{wxTreeCtrl
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
97 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
98 \param{long
}{ style = wxTR
\_HAS\_BUTTONS},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listCtrl"
}}
100 Creates the tree control. See
\helpref{wxTreeCtrl::wxTreeCtrl
}{wxtreectrlconstr
} for further details.
102 \membersection{wxTreeCtrl::DeleteAllItems
}\label{wxtreectrldeleteallitems
}
104 \func{bool
}{DeleteAllItems
}{\void}
106 Deletes all the items in the control.
108 \membersection{wxTreeCtrl::DeleteItem
}\label{wxtreectrldeleteitem
}
110 \func{bool
}{DeleteItem
}{\param{long
}{item
}}
112 Deletes the specified item.
114 \membersection{wxTreeCtrl::EditLabel
}\label{wxtreectrleditlabel
}
116 \func{wxTextCtrl*
}{EditLabel
}{\param{long
}{item
},
\param{wxClassInfo*
}{ textControlClass = CLASSINFO(wxTextCtrl)
}}
118 Starts editing the label of the given item, returning the text control that the tree control uses for editing.
120 Pass another
{\it textControlClass
} if a derived class is required. It usually will be, in order for
121 the application to detect when editing has finished and to call
\helpref{wxTreeCtrl::EndEditLabel
}{wxtreectrlendeditlabel
}.
123 Do not delete the text control yourself.
125 This function is currently supported under Windows only.
129 \helpref{wxTreeCtrl::EndEditLabel
}{wxtreectrlendeditlabel
}
131 \membersection{wxTreeCtrl::EndEditLabel
}\label{wxtreectrlendeditlabel
}
133 \func{bool
}{EndEditLabel
}{\param{bool
}{cancelEdit
}}
135 Ends label editing. If
{\it cancelEdit
} is TRUE, the edit will be cancelled.
137 This function is currently supported under Windows only.
141 \helpref{wxTreeCtrl::EditLabel
}{wxtreectrleditlabel
}
143 \membersection{wxTreeCtrl::EnsureVisible
}\label{wxtreectrlensurevisible
}
145 \func{bool
}{EnsureVisible
}{\param{long
}{item
}}
147 Scrolls and/or expands items to ensure that the given item is visible.
149 \membersection{wxTreeCtrl::ExpandItem
}\label{wxtreectrlexpanditem
}
151 \func{bool
}{ExpandItem
}{\param{long
}{item
},
\param{int
}{action
}}
153 Expands the given item.
155 {\it action
} may be one of:
158 \begin{twocollist
}\itemsep=
0pt
159 \twocolitem{\windowstyle{wxTREE
\_EXPAND\_EXPAND}}{Expands the item.
}
160 \twocolitem{\windowstyle{wxTREE
\_EXPAND\_COLLAPSE}}{Collapses the item.
}
161 \twocolitem{\windowstyle{wxTREE
\_EXPAND\_COLLAPSE\_RESET}}{Collapses the item and removes the child items.
}
162 \twocolitem{\windowstyle{wxTREE
\_EXPAND\_TOGGLE}}{Expands if the item is collapsed, collapses if the item is expanded.
}
165 \membersection{wxTreeCtrl::GetChild
}\label{wxtreectrlgetchild
}
167 \constfunc{long
}{GetChild
}{\param{long
}{item
}}
169 Call this function to retrieve the tree view item that is the first child of the item specified by
{\it item
}.
171 \membersection{wxTreeCtrl::GetCount
}\label{wxtreectrlgetcount
}
173 \constfunc{int
}{GetCount
}{\void}
175 Returns the number of items in the control.
177 \membersection{wxTreeCtrl::GetEditControl
}\label{wxtreectrlgeteditcontrol
}
179 \constfunc{wxTextCtrl\&
}{GetEditControl
}{\void}
181 Returns the edit control used to edit a label.
183 \membersection{wxTreeCtrl::GetFirstVisibleItem
}\label{wxtreectrlgetfirstvisibleitem
}
185 \constfunc{long
}{GetFirstVisibleItem
}{\void}
187 Returns the first visible item.
189 \membersection{wxTreeCtrl::GetImageList
}\label{wxtreectrlgetimagelist
}
191 \constfunc{wxImageList*
}{GetImageList
}{\param{int
}{which = wxIMAGE
\_LIST\_NORMAL}}
193 Returns the specified image list.
{\it which
} may be one of:
196 \begin{twocollist
}\itemsep=
0pt
197 \twocolitem{\windowstyle{wxIMAGE
\_LIST\_NORMAL}}{The normal (large icon) image list.
}
198 \twocolitem{\windowstyle{wxIMAGE
\_LIST\_SMALL}}{The small icon image list.
}
199 \twocolitem{\windowstyle{wxIMAGE
\_LIST\_STATE}}{The user-defined state image list (unimplemented).
}
202 \membersection{wxTreeCtrl::GetIndent
}\label{wxtreectrlgetindent
}
204 \constfunc{int
}{GetIndent
}{\void}
206 Returns the current tree control indentation.
208 \membersection{wxTreeCtrl::GetItem
}\label{wxtreectrlgetitem
}
210 \constfunc{bool
}{GetItem
}{\param{wxTreeItem\&
}{info
}}
212 Gets information about the item. See
\helpref{wxTreeCtrl::SetItem
}{wxtreectrlsetitem
} for more
215 \membersection{wxTreeCtrl::GetItemData
}\label{wxtreectrlgetitemdata
}
217 \constfunc{long
}{GetItemData
}{\param{long
}{item
}}
219 Returns the client data associated with the item, if any.
221 \membersection{wxTreeCtrl::GetItemRect
}\label{wxtreectrlgetitemrect
}
223 \constfunc{bool
}{GetItemRect
}{\param{long
}{item
},
\param{wxRect\&
}{rect
},
\param{bool
}{textOnly = FALSE
}}
225 Returns the position and size of the rectangle bounding the item.
227 \membersection{wxTreeCtrl::GetItemState
}\label{wxtreectrlgetitemstate
}
229 \constfunc{int
}{GetItemState
}{\param{long
}{item
},
\param{long
}{stateMask
}}
231 Gets the item state. For a list of state flags, see
\helpref{wxTreeCtrl::SetItem
}{wxtreectrlsetitem
}.
233 \membersection{wxTreeCtrl::GetItemText
}\label{wxtreectrlgetitemtext
}
235 \constfunc{wxString
}{GetItemText
}{\param{long
}{item
}}
237 Returns the item label.
239 \membersection{wxTreeCtrl::GetNextItem
}\label{wxtreectrlgetnextitem
}
241 \constfunc{long
}{GetNextItem
}{\param{long
}{item
},
\param{int
}{code
}}
243 Searches for an item using the given criterion, starting from
{\it item
}.
245 Returns the item or
0 if unsuccessful.
247 {\it code
} can be one of:
250 \begin{twocollist
}\itemsep=
0pt
251 \twocolitem{wxTREE
\_NEXT\_CARET}{Retrieves the currently selected item.
}
252 \twocolitem{wxTREE
\_NEXT\_CHILD}{Retrieves the first child item. The hItem parameter must be NULL.
}
253 \twocolitem{wxTREE
\_NEXT\_DROPHILITE}{Retrieves the item that is the target of a drag-and-drop operation.
}
254 \twocolitem{wxTREE
\_NEXT\_FIRSTVISIBLE}{Retrieves the first visible item.
}
255 \twocolitem{wxTREE
\_NEXT\_NEXT}{Retrieves the next sibling item.
}
256 \twocolitem{wxTREE
\_NEXT\_NEXTVISIBLE}{Retrieves the next visible item that follows the specified item.
}
257 \twocolitem{wxTREE
\_NEXT\_PARENT}{Retrieves the parent of the specified item.
}
258 \twocolitem{wxTREE
\_NEXT\_PREVIOUS}{Retrieves the previous sibling item.
}
259 \twocolitem{wxTREE
\_NEXT\_PREVIOUSVISIBLE}{Retrieves the first visible item that precedes the specified item.
}
260 \twocolitem{wxTREE
\_NEXT\_ROOT}{Retrieves the first child item of the root item of which the specified item is a part.
}
263 \membersection{wxTreeCtrl::GetNextVisibleItem
}\label{wxtreectrlgetnextvisibleitem
}
265 \constfunc{long
}{GetNextVisibleItem
}{\param{long
}{item
}}
267 Returns the next visible item.
269 \membersection{wxTreeCtrl::GetParent
}\label{wxtreectrlgetparent
}
271 \constfunc{long
}{GetParent
}{\param{long
}{item
}}
273 Returns the item's parent.
275 \membersection{wxTreeCtrl::GetRootItem
}\label{wxtreectrlgetrootitem
}
277 \constfunc{long
}{GetRootItem
}{\void}
279 Returns the root item for the tree control.
281 \membersection{wxTreeCtrl::GetSelection
}\label{wxtreectrlgetselection
}
283 \constfunc{long
}{GetSelection
}{\void}
285 Returns the selection, or
0 if there is no selection.
287 \membersection{wxTreeCtrl::HitTest
}\label{wxtreectrlhittest
}
289 \func{long
}{HitTest
}{\param{const wxPoint\&
}{point
},
\param{int\&
}{flags
}}
291 Calculates which (if any) item is under the given point, returning extra information
292 in
{\it flags
}.
{\it flags
} is a bitlist of the following:
295 \begin{twocollist
}\itemsep=
0pt
296 \twocolitem{wxTREE
\_HITTEST\_ABOVE}{Above the client area.
}
297 \twocolitem{wxTREE
\_HITTEST\_BELOW}{Below the client area.
}
298 \twocolitem{wxTREE
\_HITTEST\_NOWHERE}{In the client area but below the last item.
}
299 \twocolitem{wxTREE
\_HITTEST\_ONITEMBUTTON}{On the button associated with an item.
}
300 \twocolitem{wxTREE
\_HITTEST\_ONITEMICON}{On the bitmap associated with an item.
}
301 \twocolitem{wxTREE
\_HITTEST\_ONITEMINDENT}{In the indentation associated with an item.
}
302 \twocolitem{wxTREE
\_HITTEST\_ONITEMLABEL}{On the label (string) associated with an item.
}
303 \twocolitem{wxTREE
\_HITTEST\_ONITEMRIGHT}{In the area to the right of an item.
}
304 \twocolitem{wxTREE
\_HITTEST\_ONITEMSTATEICON}{On the state icon for a tree view item that is in a user-defined state.
}
305 \twocolitem{wxTREE
\_HITTEST\_TOLEFT}{To the right of the client area.
}
306 \twocolitem{wxTREE
\_HITTEST\_TORIGHT}{To the left of the client area.
}
309 \membersection{wxTreeCtrl::InsertItem
}\label{wxtreectrlinsertitem
}
311 \func{long
}{InsertItem
}{\param{long
}{parent
},
\param{wxTreeItem\&
}{info
},
\param{long
}{insertAfter = wxTREE
\_INSERT\_LAST}}
313 Inserts an item. For more information on
{\it info
}, see
\helpref{wxTreeCtrl::SetItem
}{wxtreectrlsetitem
}.
315 \func{long
}{InsertItem
}{\param{long
}{parent
},
\param{const wxString\&
}{label
},
\param{int
}{image = -
1},
\param{int
}{selImage = -
1},
\param{long
}{insertAfter = wxTREE
\_INSERT\_LAST}}
319 If
{\it image
} > -
1 and
{\it selImage
} is -
1, the same image is used for
320 both selected and unselected items.
322 \membersection{wxTreeCtrl::ItemHasChildren
}\label{wxtreectrlitemhaschildren
}
324 \constfunc{bool
}{ItemHasChildren
}{\param{long
}{item
}}
326 Returns TRUE if the item has children.
328 \membersection{wxTreeCtrl::ScrollTo
}\label{wxtreectrlscrollto
}
330 \func{bool
}{ScrollTo
}{\param{long
}{item
}}
332 selects the specified item and scrolls the item into view,
334 \membersection{wxTreeCtrl::SelectItem
}\label{wxtreectrlselectitem
}
336 \func{bool
}{SelectItem
}{\param{long
}{item
}}
338 Selects the given item.
340 \membersection{wxTreeCtrl::SetIndent
}\label{wxtreectrlsetindent
}
342 \func{void
}{SetIndent
}{\param{int
}{indent
}}
344 Sets the indentation for the tree control.
346 \membersection{wxTreeCtrl::SetImageList
}\label{wxtreectrlsetimagelist
}
348 \func{void
}{SetImageList
}{\param{wxImageList*
}{ imageList
},
\param{int
}{which = wxIMAGE
\_LIST\_NORMAL}}
350 Sets the image list.
{\it which
} should be one of wxIMAGE
\_LIST\_NORMAL, wxIMAGE
\_LIST\_SMALL and
351 wxIMAGE
\_LIST\_STATE.
353 \membersection{wxTreeCtrl::SetItem
}\label{wxtreectrlsetitem
}
355 \func{bool
}{SetItem
}{\param{wxTreeItem\&
}{info
}}
357 Sets the properties of the item.
359 The members of wxTreeItem are as follows:
362 \begin{twocollist
}\itemsep=
0pt
363 \twocolitem{m
\_mask}{A bitlist specifying the valid members. See below for mask flags.
}
364 \twocolitem{m
\_itemId}{The item identifier.
}
365 \twocolitem{m
\_state}{The item state. See below for state flags.
}
366 \twocolitem{m
\_stateMask}{A bitlist specifying the valid contents of
{\it m
\_state}. These flags
367 are taken from the same set of symbols as
{\it m
\_state}.
}
368 \twocolitem{m
\_text}{The item label.
}
369 \twocolitem{m
\_image}{The item image index (an index into the appropriate image list).
}
370 \twocolitem{m
\_selectedImage}{The item selected index (an index into the appropriate image list).
}
371 \twocolitem{m
\_children}{The number of child items that this item has.
}
372 \twocolitem{m
\_data}{The application-defined data associated with this item.
}
375 Valid mask flags are:
378 \begin{twocollist
}\itemsep=
0pt
379 \twocolitem{wxTREE
\_MASK\_HANDLE}{The
{\it m
\_itemId} member is valid.
}
380 \twocolitem{wxTREE
\_MASK\_STATE}{The
{\it m
\_state} member is valid.
}
381 \twocolitem{wxTREE
\_MASK\_TEXT}{The
{\it m
\_text} member is valid.
}
382 \twocolitem{wxTREE
\_MASK\_IMAGE}{The
{\it m
\_image} member is valid.
}
383 \twocolitem{wxTREE
\_MASK\_SELECTED\_IMAGE}{The
{\it m
\_selectedImage} member is valid.
}
384 \twocolitem{wxTREE
\_MASK\_CHILDREN}{The
{\it m
\_children} member is valid.
}
385 \twocolitem{wxTREE
\_MASK\_DATA}{The
{\it m
\_data} member is valid.
}
388 Valid state and state mask flags are:
391 \begin{twocollist
}\itemsep=
0pt
392 \twocolitem{wxTREE
\_STATE\_BOLD}{The label is emboldened.
}
393 \twocolitem{wxTREE
\_STATE\_DROPHILITED}{The item indicates it is a drop target.
}
394 \twocolitem{wxTREE
\_STATE\_EXPANDED}{The item is expanded.
}
395 \twocolitem{wxTREE
\_STATE\_EXPANDEDONCE}{The item's list of child items has been expanded at least once.
}
396 \twocolitem{wxTREE
\_STATE\_FOCUSED}{The item has the focus, so it is surrounded by a standard focus rectangle.
397 Only one item can have the focus.
}
398 \twocolitem{wxTREE
\_STATE\_SELECTED}{The item is selected.
}
399 \twocolitem{wxTREE
\_STATE\_CUT}{The item is selected as part of a cut and paste operation.
}
402 \membersection{wxTreeCtrl::SetItemImage
}\label{wxtreectrlsetitemimage
}
404 \func{bool
}{SetItemImage
}{\param{long
}{item
},
\param{int
}{image
},
\param{int
}{selImage
}}
406 Sets the item image and selected image. These are indices into the assciated image list.
408 \membersection{wxTreeCtrl::SetItemState
}\label{wxtreectrlsetitemstate
}
410 \func{bool
}{SetItemState
}{\param{long
}{item
},
\param{long
}{state
},
\param{long
}{stateMask
}}
412 Sets the item state. See
\helpref{wxTreeCtrl::SetItem
}{wxtreectrlsetitem
} for valid state and state mask flags.
414 \membersection{wxTreeCtrl::SetItemText
}\label{wxtreectrlsetitemtext
}
416 \func{void
}{SetItemText
}{\param{long
}{item
},
\param{const wxString\&
}{text
}}
420 \membersection{wxTreeCtrl::SetItemData
}\label{wxtreectrlsetitemdata
}
422 \func{bool
}{SetItemData
}{\param{long
}{item
},
\param{long
}{data
}}
424 Sets the item client data.
426 \membersection{wxTreeCtrl::SortChildren
}\label{wxtreectrlsortchildren
}
428 \func{bool
}{SortChildren
}{\param{long
}{item
}}
430 Sorts the children of the given item in ascending alphabetical order.