]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/treectrl.h
document wxFSVolume (fixes #3977)
[wxWidgets.git] / interface / wx / treectrl.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: treectrl.h
e54c96f1 3// Purpose: interface of wxTreeItemData
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
e54c96f1 9
23324ae1
FM
10/**
11 @class wxTreeCtrl
7c913512 12
23324ae1 13 A tree control presents information as a hierarchy, with items that may be
7977b62a
BP
14 expanded to show further items. Items in a tree control are referenced by
15 wxTreeItemId handles, which may be tested for validity by calling
16 wxTreeItemId::IsOk().
03966fcb 17
f0871806
RR
18 A similar control with a fully native implemtation for GTK+ and OS X
19 as well is wxDataViewTreeCtrl.
7c913512 20
7977b62a
BP
21 To intercept events from a tree control, use the event table macros
22 described in wxTreeEvent.
7c913512 23
23324ae1 24 @beginStyleTable
8c6791e4 25 @style{wxTR_EDIT_LABELS}
7977b62a
BP
26 Use this style if you wish the user to be able to edit labels in the
27 tree control.
8c6791e4 28 @style{wxTR_NO_BUTTONS}
7977b62a 29 For convenience to document that no buttons are to be drawn.
8c6791e4 30 @style{wxTR_HAS_BUTTONS}
7977b62a 31 Use this style to show + and - buttons to the left of parent items.
8c6791e4 32 @style{wxTR_NO_LINES}
7977b62a 33 Use this style to hide vertical level connectors.
8c6791e4 34 @style{wxTR_FULL_ROW_HIGHLIGHT}
7977b62a
BP
35 Use this style to have the background colour and the selection highlight
36 extend over the entire horizontal row of the tree control window. (This
37 flag is ignored under Windows unless you specify @c wxTR_NO_LINES as
38 well.)
8c6791e4 39 @style{wxTR_LINES_AT_ROOT}
7977b62a
BP
40 Use this style to show lines between root nodes. Only applicable if @c
41 wxTR_HIDE_ROOT is set and @c wxTR_NO_LINES is not set.
8c6791e4 42 @style{wxTR_HIDE_ROOT}
7977b62a
BP
43 Use this style to suppress the display of the root node, effectively
44 causing the first-level nodes to appear as a series of root nodes.
8c6791e4 45 @style{wxTR_ROW_LINES}
7977b62a 46 Use this style to draw a contrasting border between displayed rows.
8c6791e4 47 @style{wxTR_HAS_VARIABLE_ROW_HEIGHT}
7977b62a
BP
48 Use this style to cause row heights to be just big enough to fit the
49 content. If not set, all rows use the largest row height. The default is
50 that this flag is unset. Generic only.
8c6791e4 51 @style{wxTR_SINGLE}
7977b62a
BP
52 For convenience to document that only one item may be selected at a
53 time. Selecting another item causes the current selection, if any, to be
54 deselected. This is the default.
8c6791e4 55 @style{wxTR_MULTIPLE}
7977b62a
BP
56 Use this style to allow a range of items to be selected. If a second
57 range is selected, the current range, if any, is deselected.
8c6791e4 58 @style{wxTR_DEFAULT_STYLE}
7977b62a
BP
59 The set of flags that are closest to the defaults for the native control
60 for a particular toolkit.
23324ae1 61 @endStyleTable
7c913512 62
98d45c55
RR
63 @beginEventTable{wxTreeEvent}
64 @event{EVT_TREE_BEGIN_DRAG(id, func)}
65 Begin dragging with the left mouse button.
66 @event{EVT_TREE_BEGIN_RDRAG(id, func)}
67 Begin dragging with the right mouse button.
68 @event{EVT_TREE_END_DRAG(id, func)}
69 End dragging with the left or right mouse button.
70 @event{EVT_TREE_BEGIN_LABEL_EDIT(id, func)}
71 Begin editing a label. This can be prevented by calling Veto().
72 @event{EVT_TREE_END_LABEL_EDIT(id, func)}
73 Finish editing a label. This can be prevented by calling Veto().
74 @event{EVT_TREE_DELETE_ITEM(id, func)}
75 An item was deleted.
76 @event{EVT_TREE_GET_INFO(id, func)}
77 Request information from the application.
78 @event{EVT_TREE_SET_INFO(id, func)}
79 Information is being supplied.
80 @event{EVT_TREE_ITEM_ACTIVATED(id, func)}
6873eb5b
FM
81 The item has been activated, i.e. chosen by double clicking it with
82 mouse or from keyboard.
98d45c55
RR
83 @event{EVT_TREE_ITEM_COLLAPSED(id, func)}
84 The item has been collapsed.
85 @event{EVT_TREE_ITEM_COLLAPSING(id, func)}
86 The item is being collapsed. This can be prevented by calling Veto().
87 @event{EVT_TREE_ITEM_EXPANDED(id, func)}
88 The item has been expanded.
89 @event{EVT_TREE_ITEM_EXPANDING(id, func)}
90 The item is being expanded. This can be prevented by calling Veto().
91 @event{EVT_TREE_ITEM_RIGHT_CLICK(id, func)}
92 The user has clicked the item with the right mouse button.
93 @event{EVT_TREE_ITEM_MIDDLE_CLICK(id, func)}
94 The user has clicked the item with the middle mouse button.
95 @event{EVT_TREE_SEL_CHANGED(id, func)}
96 Selection has changed.
97 @event{EVT_TREE_SEL_CHANGING(id, func)}
98 Selection is changing. This can be prevented by calling Veto().
99 @event{EVT_TREE_KEY_DOWN(id, func)}
100 A key has been pressed.
101 @event{EVT_TREE_ITEM_GETTOOLTIP(id, func)}
6873eb5b
FM
102 The opportunity to set the item tooltip is being given to the application
103 (call wxTreeEvent::SetToolTip). Windows only.
98d45c55 104 @event{EVT_TREE_ITEM_MENU(id, func)}
6873eb5b
FM
105 The context menu for the selected item has been requested, either by a
106 right click or by using the menu key.
98d45c55
RR
107 @event{EVT_TREE_STATE_IMAGE_CLICK(id, func)}
108 The state image has been clicked. Windows only.
109 @endEventTable
110
111
7977b62a 112 See also @ref overview_windowstyles.
03966fcb 113
7977b62a
BP
114 @b Win32 @b notes:
115
116 wxTreeCtrl class uses the standard common treeview control under Win32
117 implemented in the system library comctl32.dll. Some versions of this
118 library are known to have bugs with handling the tree control colours: the
119 usual symptom is that the expanded items leave black (or otherwise
120 incorrectly coloured) background behind them, especially for the controls
121 using non-default background colour. The recommended solution is to upgrade
122 the comctl32.dll to a newer version: see
123 http://www.microsoft.com/downloads/details.aspx?familyid=cb2cf3a2-8025-4e8f-8511-9b476a8d35d2
124
23324ae1
FM
125 @library{wxcore}
126 @category{ctrl}
7e59b885 127 @appearance{treectrl.png}
7c913512 128
6873eb5b
FM
129 @see wxDataViewTreeCtrl, wxTreeEvent, wxTreeItemData, @ref overview_treectrl,
130 wxListBox, wxListCtrl, wxImageList
23324ae1
FM
131*/
132class wxTreeCtrl : public wxControl
133{
134public:
7977b62a
BP
135 /**
136 Default Constructor.
137 */
138 wxTreeCtrl();
139
23324ae1
FM
140 /**
141 Constructor, creating and showing a tree control.
3c4f71cc 142
7c913512 143 @param parent
4cc4bfaf 144 Parent window. Must not be @NULL.
7c913512 145 @param id
7977b62a 146 Window identifier. The value @c wxID_ANY indicates a default value.
7c913512 147 @param pos
4cc4bfaf 148 Window position.
7c913512 149 @param size
7977b62a 150 Window size. If wxDefaultSize is specified then the window is sized
4cc4bfaf 151 appropriately.
7c913512 152 @param style
4cc4bfaf 153 Window style. See wxTreeCtrl.
7c913512 154 @param validator
4cc4bfaf 155 Window validator.
7c913512 156 @param name
4cc4bfaf 157 Window name.
3c4f71cc 158
4cc4bfaf 159 @see Create(), wxValidator
23324ae1 160 */
cfbe5614 161 wxTreeCtrl(wxWindow* parent, wxWindowID id = wxID_ANY,
7c913512
FM
162 const wxPoint& pos = wxDefaultPosition,
163 const wxSize& size = wxDefaultSize,
cfbe5614 164 long style = wxTR_DEFAULT_STYLE,
7c913512 165 const wxValidator& validator = wxDefaultValidator,
cfbe5614 166 const wxString& name = wxTreeCtrlNameStr);
03966fcb 167
23324ae1
FM
168
169 /**
170 Destructor, destroying the tree control.
171 */
adaaa686 172 virtual ~wxTreeCtrl();
23324ae1
FM
173
174 /**
175 Adds the root node to the tree, returning the new item.
7977b62a
BP
176
177 The @a image and @a selImage parameters are an index within the normal
178 image list specifying the image to use for unselected and selected
179 items, respectively. If @a image -1 and @a selImage is -1, the same
180 image is used for both selected and unselected items.
23324ae1 181 */
adaaa686
FM
182 virtual wxTreeItemId AddRoot(const wxString& text, int image = -1,
183 int selImage = -1,
184 wxTreeItemData* data = NULL);
23324ae1
FM
185
186 /**
7977b62a
BP
187 Appends an item to the end of the branch identified by @a parent, return
188 a new item id.
03966fcb 189
7977b62a
BP
190 The @a image and @a selImage parameters are an index within the normal
191 image list specifying the image to use for unselected and selected
192 items, respectively. If @a image -1 and @a selImage is -1, the same
193 image is used for both selected and unselected items.
23324ae1
FM
194 */
195 wxTreeItemId AppendItem(const wxTreeItemId& parent,
196 const wxString& text,
197 int image = -1,
198 int selImage = -1,
4cc4bfaf 199 wxTreeItemData* data = NULL);
23324ae1
FM
200
201 /**
7977b62a
BP
202 Sets the buttons image list. The button images assigned with this method
203 will be automatically deleted by wxTreeCtrl as appropriate (i.e. it
204 takes ownership of the list).
205
206 Setting or assigning the button image list enables the display of image
207 buttons. Once enabled, the only way to disable the display of button
208 images is to set the button image list to @NULL.
209
23324ae1 210 This function is only available in the generic version.
7977b62a
BP
211
212 @see SetButtonsImageList().
23324ae1
FM
213 */
214 void AssignButtonsImageList(wxImageList* imageList);
215
216 /**
7977b62a
BP
217 Sets the normal image list. The image list assigned with this method
218 will be automatically deleted by wxTreeCtrl as appropriate (i.e. it
219 takes ownership of the list).
220
221 @see SetImageList().
23324ae1
FM
222 */
223 void AssignImageList(wxImageList* imageList);
224
225 /**
7977b62a
BP
226 Sets the state image list. Image list assigned with this method will be
227 automatically deleted by wxTreeCtrl as appropriate (i.e. it takes
228 ownership of the list).
229
230 @see SetStateImageList().
23324ae1
FM
231 */
232 void AssignStateImageList(wxImageList* imageList);
233
234 /**
235 Collapses the given item.
236 */
adaaa686 237 virtual void Collapse(const wxTreeItemId& item);
23324ae1
FM
238
239 /**
240 Collapses the root item.
3c4f71cc 241
4cc4bfaf 242 @see ExpandAll()
23324ae1
FM
243 */
244 void CollapseAll();
245
246 /**
247 Collapses this item and all of its children, recursively.
3c4f71cc 248
4cc4bfaf 249 @see ExpandAllChildren()
23324ae1
FM
250 */
251 void CollapseAllChildren(const wxTreeItemId& item);
252
253 /**
254 Collapses the given item and removes all children.
255 */
adaaa686 256 virtual void CollapseAndReset(const wxTreeItemId& item);
23324ae1
FM
257
258 /**
cfbe5614
FM
259 Creates the tree control.
260 See wxTreeCtrl::wxTreeCtrl() for further details.
23324ae1 261 */
cfbe5614 262 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
7977b62a
BP
263 const wxPoint& pos = wxDefaultPosition,
264 const wxSize& size = wxDefaultSize,
cfbe5614 265 long style = wxTR_DEFAULT_STYLE,
7977b62a 266 const wxValidator& validator = wxDefaultValidator,
cfbe5614 267 const wxString& name = wxTreeCtrlNameStr);
23324ae1
FM
268
269 /**
6873eb5b 270 Deletes the specified item. A @c EVT_TREE_DELETE_ITEM event will be
23324ae1 271 generated.
7977b62a
BP
272
273 This function may cause a subsequent call to GetNextChild() to fail.
23324ae1 274 */
adaaa686 275 virtual void Delete(const wxTreeItemId& item);
23324ae1
FM
276
277 /**
278 Deletes all items in the control. Note that this may not generate
6873eb5b 279 @c EVT_TREE_DELETE_ITEM events under some Windows versions although
23324ae1
FM
280 normally such event is generated for each removed item.
281 */
adaaa686 282 virtual void DeleteAllItems();
23324ae1
FM
283
284 /**
7977b62a
BP
285 Deletes all children of the given item (but not the item itself). Note
286 that this will @b not generate any events unlike Delete() method.
287
288 If you have called SetItemHasChildren(), you may need to call it again
289 since DeleteChildren() does not automatically clear the setting.
23324ae1 290 */
adaaa686 291 virtual void DeleteChildren(const wxTreeItemId& item);
23324ae1
FM
292
293 /**
7977b62a 294 Starts editing the label of the given @a item. This function generates a
6873eb5b 295 @c EVT_TREE_BEGIN_LABEL_EDIT event which can be vetoed so that no text
7977b62a
BP
296 control will appear for in-place editing.
297
298 If the user changed the label (i.e. s/he does not press ESC or leave the
6873eb5b 299 text control without changes, a @c EVT_TREE_END_LABEL_EDIT event will be
7977b62a 300 sent which can be vetoed as well.
3c4f71cc 301
4cc4bfaf 302 @see EndEditLabel(), wxTreeEvent
23324ae1 303 */
cfbe5614
FM
304 virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
305 wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
23324ae1
FM
306
307 /**
7977b62a
BP
308 Ends label editing. If @a cancelEdit is @true, the edit will be
309 cancelled.
310
311 @note
312 This function is currently supported under Windows only.
3c4f71cc 313
4cc4bfaf 314 @see EditLabel()
23324ae1 315 */
cfbe5614 316 virtual void EndEditLabel(const wxTreeItemId& item, bool discardChanges = false);
23324ae1
FM
317
318 /**
319 Scrolls and/or expands items to ensure that the given item is visible.
320 */
adaaa686 321 virtual void EnsureVisible(const wxTreeItemId& item);
23324ae1
FM
322
323 /**
324 Expands the given item.
325 */
adaaa686 326 virtual void Expand(const wxTreeItemId& item);
23324ae1
FM
327
328 /**
329 Expands all items in the tree.
330 */
331 void ExpandAll();
332
333 /**
334 Expands the given item and all its children recursively.
335 */
336 void ExpandAllChildren(const wxTreeItemId& item);
337
338 /**
7977b62a
BP
339 Retrieves the rectangle bounding the @a item. If @a textOnly is @true,
340 only the rectangle around the item's label will be returned, otherwise
341 the item's image is also taken into account.
342
343 The return value is @true if the rectangle was successfully retrieved or
344 @c @false if it was not (in this case @a rect is not changed) -- for
345 example, if the item is currently invisible.
346
347 Notice that the rectangle coordinates are logical, not physical ones.
348 So, for example, the x coordinate may be negative if the tree has a
349 horizontal scrollbar and its position is not 0.
350
351 @beginWxPythonOnly
352 The wxPython version of this method requires only the @a item and @a
353 textOnly parameters. The return value is either a wxRect object or @c
354 None.
355 @endWxPythonOnly
23324ae1 356 */
fadc2df6
FM
357 virtual bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect,
358 bool textOnly = false) const;
23324ae1
FM
359
360 /**
7977b62a
BP
361 Returns the buttons image list (from which application-defined button
362 images are taken).
363
23324ae1
FM
364 This function is only available in the generic version.
365 */
328f5751 366 wxImageList* GetButtonsImageList() const;
23324ae1
FM
367
368 /**
4cc4bfaf 369 Returns the number of items in the branch. If @a recursively is @true,
7977b62a
BP
370 returns the total number of descendants, otherwise only one level of
371 children is counted.
23324ae1 372 */
cfbe5614
FM
373 virtual size_t GetChildrenCount(const wxTreeItemId& item,
374 bool recursively = true) const;
23324ae1
FM
375
376 /**
377 Returns the number of items in the control.
378 */
adaaa686 379 virtual unsigned int GetCount() const;
23324ae1
FM
380
381 /**
7977b62a
BP
382 Returns the edit control being currently used to edit a label. Returns
383 @NULL if no label is being edited.
384
385 @note This is currently only implemented for wxMSW.
23324ae1 386 */
adaaa686 387 virtual wxTextCtrl* GetEditControl() const;
23324ae1
FM
388
389 /**
390 Returns the first child; call GetNextChild() for the next child.
7977b62a 391
23324ae1 392 For this enumeration function you must pass in a 'cookie' parameter
7977b62a
BP
393 which is opaque for the application but is necessary for the library to
394 make these functions reentrant (i.e. allow more than one enumeration on
395 one and the same object simultaneously). The cookie passed to
396 GetFirstChild() and GetNextChild() should be the same variable.
397
398 Returns an invalid tree item (i.e. wxTreeItemId::IsOk() returns @false)
399 if there are no further children.
400
401 @beginWxPythonOnly
402 In wxPython the returned wxTreeItemId and the new cookie value are both
403 returned as a tuple containing the two values.
404 @endWxPythonOnly
3c4f71cc 405
4cc4bfaf 406 @see GetNextChild(), GetNextSibling()
23324ae1 407 */
fadc2df6
FM
408 virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
409 wxTreeItemIdValue& cookie) const;
23324ae1
FM
410
411 /**
412 Returns the first visible item.
413 */
adaaa686 414 virtual wxTreeItemId GetFirstVisibleItem() const;
23324ae1
FM
415
416 /**
417 Returns the normal image list.
418 */
328f5751 419 wxImageList* GetImageList() const;
23324ae1
FM
420
421 /**
422 Returns the current tree control indentation.
423 */
cfbe5614 424 virtual unsigned int GetIndent() const;
23324ae1
FM
425
426 /**
427 Returns the background colour of the item.
428 */
adaaa686 429 virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
23324ae1 430
23324ae1 431 /**
7977b62a 432 Returns the tree item data associated with the item.
23324ae1 433
483724a1 434 @see wxTreeItemData
23324ae1 435
483724a1
FM
436 @beginWxPythonOnly
437 wxPython provides the following shortcut method:
438 @li GetPyData(item): Returns the Python Object associated with the
439 wxTreeItemData for the given item Id.
440 @endWxPythonOnly
441 */
adaaa686 442 virtual wxTreeItemData* GetItemData(const wxTreeItemId& item) const;
7977b62a
BP
443
444 /**
445 Returns the font of the item label.
446 */
adaaa686 447 virtual wxFont GetItemFont(const wxTreeItemId& item) const;
23324ae1
FM
448
449 /**
4cc4bfaf 450 Gets the specified item image. The value of @a which may be:
7977b62a
BP
451 - ::wxTreeItemIcon_Normal: to get the normal item image.
452 - ::wxTreeItemIcon_Selected: to get the selected item image (i.e. the
453 image which is shown when the item is currently selected).
454 - ::wxTreeItemIcon_Expanded: to get the expanded image (this only makes
455 sense for items which have children - then this image is shown when
456 the item is expanded and the normal image is shown when it is
457 collapsed).
458 - ::wxTreeItemIcon_SelectedExpanded: to get the selected expanded image
459 (which is shown when an expanded item is currently selected).
23324ae1 460 */
fadc2df6
FM
461 virtual int GetItemImage(const wxTreeItemId& item,
462 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
23324ae1
FM
463
464 /**
465 Returns the item's parent.
466 */
adaaa686 467 virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
23324ae1 468
03966fcb
RR
469 /**
470 Gets the specified item state.
471 */
472 int GetItemState(const wxTreeItemId& item) const;
473
23324ae1
FM
474 /**
475 Returns the item label.
476 */
adaaa686 477 virtual wxString GetItemText(const wxTreeItemId& item) const;
23324ae1
FM
478
479 /**
480 Returns the colour of the item label.
481 */
adaaa686 482 virtual wxColour GetItemTextColour(const wxTreeItemId& item) const;
23324ae1
FM
483
484 /**
7977b62a
BP
485 Returns the last child of the item (or an invalid tree item if this item
486 has no children).
3c4f71cc 487
7977b62a 488 @see GetFirstChild(), GetNextSibling(), GetLastChild()
23324ae1 489 */
adaaa686 490 virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
23324ae1
FM
491
492 /**
7977b62a
BP
493 Returns the next child; call GetFirstChild() for the first child. For
494 this enumeration function you must pass in a 'cookie' parameter which is
495 opaque for the application but is necessary for the library to make
496 these functions reentrant (i.e. allow more than one enumeration on one
497 and the same object simultaneously). The cookie passed to
498 GetFirstChild() and GetNextChild() should be the same.
499
23324ae1 500 Returns an invalid tree item if there are no further children.
3c4f71cc 501
7977b62a
BP
502 @beginWxPythonOnly
503 In wxPython the returned wxTreeItemId and the new cookie value are both
504 returned as a tuple containing the two values.
505 @endWxPythonOnly
506
4cc4bfaf 507 @see GetFirstChild()
23324ae1 508 */
fadc2df6
FM
509 virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
510 wxTreeItemIdValue& cookie) const;
23324ae1
FM
511
512 /**
7977b62a
BP
513 Returns the next sibling of the specified item; call GetPrevSibling()
514 for the previous sibling.
515
23324ae1 516 Returns an invalid tree item if there are no further siblings.
3c4f71cc 517
4cc4bfaf 518 @see GetPrevSibling()
23324ae1 519 */
adaaa686 520 virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
23324ae1
FM
521
522 /**
7977b62a
BP
523 Returns the next visible item or an invalid item if this item is the
524 last visible one.
525
526 @note The @a item itself must be visible.
23324ae1 527 */
adaaa686 528 virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
23324ae1
FM
529
530 /**
7977b62a
BP
531 Returns the previous sibling of the specified item; call
532 GetNextSibling() for the next sibling.
533
23324ae1 534 Returns an invalid tree item if there are no further children.
3c4f71cc 535
4cc4bfaf 536 @see GetNextSibling()
23324ae1 537 */
adaaa686 538 virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
23324ae1
FM
539
540 /**
7977b62a
BP
541 Returns the previous visible item or an invalid item if this item is the
542 first visible one.
543
544 @note The @a item itself must be visible.
23324ae1 545 */
adaaa686 546 virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
23324ae1
FM
547
548 /**
7977b62a
BP
549 Returns @true if the control will use a quick calculation for the best
550 size, looking only at the first and last items. The default is @false.
3c4f71cc 551
4cc4bfaf 552 @see SetQuickBestSize()
23324ae1 553 */
328f5751 554 bool GetQuickBestSize() const;
23324ae1
FM
555
556 /**
557 Returns the root item for the tree control.
558 */
adaaa686 559 virtual wxTreeItemId GetRootItem() const;
23324ae1
FM
560
561 /**
7977b62a
BP
562 Returns the selection, or an invalid item if there is no selection. This
563 function only works with the controls without @c wxTR_MULTIPLE style,
564 use GetSelections() for the controls which do have this style.
23324ae1 565 */
adaaa686 566 virtual wxTreeItemId GetSelection() const;
23324ae1
FM
567
568 /**
7977b62a
BP
569 Fills the array of tree items passed in with the currently selected
570 items. This function can be called only if the control has the @c
571 wxTR_MULTIPLE style.
572
23324ae1 573 Returns the number of selected items.
03966fcb 574
7977b62a
BP
575 @beginWxPythonOnly
576 The wxPython version of this method accepts no parameters and returns a
577 Python list of @ref wxTreeItemId "wxTreeItemId"s.
578 @endWxPythonOnly
23324ae1 579 */
cfbe5614 580 virtual size_t GetSelections(wxArrayTreeItemIds& selection) const;
23324ae1
FM
581
582 /**
7977b62a
BP
583 Returns the state image list (from which application-defined state
584 images are taken).
23324ae1 585 */
328f5751 586 wxImageList* GetStateImageList() const;
23324ae1
FM
587
588 /**
7977b62a
BP
589 Calculates which (if any) item is under the given @a point, returning
590 the tree item id at this point plus extra information @a flags. @a flags
591 is a bitlist of the following:
592
593 - @c wxTREE_HITTEST_ABOVE: Above the client area.
594 - @c wxTREE_HITTEST_BELOW: Below the client area.
595 - @c wxTREE_HITTEST_NOWHERE: In the client area but below the last item.
596 - @c wxTREE_HITTEST_ONITEMBUTTON: On the button associated with an item.
597 - @c wxTREE_HITTEST_ONITEMICON: On the bitmap associated with an item.
6873eb5b
FM
598 - @c wxTREE_HITTEST_ONITEMINDENT: In the indentation associated with an item.
599 - @c wxTREE_HITTEST_ONITEMLABEL: On the label (string) associated with an item.
7977b62a
BP
600 - @c wxTREE_HITTEST_ONITEMRIGHT: In the area to the right of an item.
601 - @c wxTREE_HITTEST_ONITEMSTATEICON: On the state icon for a tree view
6873eb5b 602 item that is in a user-defined state.
7977b62a
BP
603 - @c wxTREE_HITTEST_TOLEFT: To the right of the client area.
604 - @c wxTREE_HITTEST_TORIGHT: To the left of the client area.
03966fcb 605
7977b62a
BP
606 @beginWxPythonOnly
607 In wxPython both the wxTreeItemId and the flags are returned as a tuple.
608 @endWxPythonOnly
23324ae1 609 */
328f5751 610 wxTreeItemId HitTest(const wxPoint& point, int& flags) const;
23324ae1 611
7977b62a 612
23324ae1 613 /**
7977b62a
BP
614 Inserts an item after a given one (@a previous).
615
616 The @a image and @a selImage parameters are an index within the normal
617 image list specifying the image to use for unselected and selected
618 items, respectively. If @a image -1 and @a selImage is -1, the same
619 image is used for both selected and unselected items.
23324ae1
FM
620 */
621 wxTreeItemId InsertItem(const wxTreeItemId& parent,
622 const wxTreeItemId& previous,
623 const wxString& text,
624 int image = -1,
625 int selImage = -1,
4cc4bfaf 626 wxTreeItemData* data = NULL);
7977b62a
BP
627
628 /**
629 Inserts an item before one identified
630 by its position (@a before). @a before must be less than the number of
631 children.
632
633 The @a image and @a selImage parameters are an index within the normal
634 image list specifying the image to use for unselected and selected
635 items, respectively. If @a image -1 and @a selImage is -1, the same
636 image is used for both selected and unselected items.
637
638 @beginWxPythonOnly
639 In wxPython, this form of this method is called @c InsertItemBefore().
640 @endWxPythonOnly
641 */
7c913512
FM
642 wxTreeItemId InsertItem(const wxTreeItemId& parent,
643 size_t before,
644 const wxString& text,
645 int image = -1,
646 int selImage = -1,
4cc4bfaf 647 wxTreeItemData* data = NULL);
23324ae1
FM
648
649 /**
650 Returns @true if the given item is in bold state.
7977b62a
BP
651
652 @see SetItemBold()
23324ae1 653 */
adaaa686 654 virtual bool IsBold(const wxTreeItemId& item) const;
23324ae1
FM
655
656 /**
7977b62a
BP
657 Returns @true if the control is empty (i.e. has no items, even no root
658 one).
23324ae1 659 */
328f5751 660 bool IsEmpty() const;
23324ae1
FM
661
662 /**
7977b62a
BP
663 Returns @true if the item is expanded (only makes sense if it has
664 children).
23324ae1 665 */
adaaa686 666 virtual bool IsExpanded(const wxTreeItemId& item) const;
23324ae1
FM
667
668 /**
669 Returns @true if the item is selected.
670 */
adaaa686 671 virtual bool IsSelected(const wxTreeItemId& item) const;
23324ae1
FM
672
673 /**
674 Returns @true if the item is visible on the screen.
675 */
adaaa686 676 virtual bool IsVisible(const wxTreeItemId& item) const;
23324ae1
FM
677
678 /**
679 Returns @true if the item has children.
680 */
adaaa686 681 virtual bool ItemHasChildren(const wxTreeItemId& item) const;
23324ae1
FM
682
683 /**
7977b62a
BP
684 Override this function in the derived class to change the sort order of
685 the items in the tree control. The function should return a negative,
686 zero or positive value if the first item is less than, equal to or
687 greater than the second one.
688
689 Please note that you @b must use wxRTTI macros DECLARE_DYNAMIC_CLASS()
690 and IMPLEMENT_DYNAMIC_CLASS() if you override this function because
691 otherwise the base class considers that it is not overridden and uses
692 the default comparison, i.e. sorts the items alphabetically, which
23324ae1 693 allows it optimize away the calls to the virtual function completely.
7977b62a
BP
694
695 @see SortChildren()
23324ae1 696 */
fadc2df6
FM
697 virtual int OnCompareItems(const wxTreeItemId& item1,
698 const wxTreeItemId& item2);
23324ae1
FM
699
700 /**
7977b62a
BP
701 Appends an item as the first child of @a parent, return a new item id.
702
703 The @a image and @a selImage parameters are an index within the normal
704 image list specifying the image to use for unselected and selected
705 items, respectively. If @a image -1 and @a selImage is -1, the same
706 image is used for both selected and unselected items.
23324ae1
FM
707 */
708 wxTreeItemId PrependItem(const wxTreeItemId& parent,
709 const wxString& text,
710 int image = -1,
711 int selImage = -1,
4cc4bfaf 712 wxTreeItemData* data = NULL);
23324ae1
FM
713
714 /**
715 Scrolls the specified item into view.
716 */
adaaa686 717 virtual void ScrollTo(const wxTreeItemId& item);
23324ae1
FM
718
719 /**
7977b62a
BP
720 Selects the given item. In multiple selection controls, can be also used
721 to deselect a currently selected item if the value of @a select is
722 @false.
23324ae1 723 */
adaaa686 724 virtual void SelectItem(const wxTreeItemId& item, bool select = true);
23324ae1
FM
725
726 /**
7977b62a
BP
727 Sets the buttons image list (from which application-defined button
728 images are taken).
729
730 The button images assigned with this method will @b not be deleted by
731 @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it yourself.
732 Setting or assigning the button image list enables the display of image
733 buttons. Once enabled, the only way to disable the display of button
734 images is to set the button image list to @NULL.
735
736 @note This function is only available in the generic version.
737
738 @see AssignButtonsImageList().
23324ae1
FM
739 */
740 void SetButtonsImageList(wxImageList* imageList);
741
742 /**
7977b62a
BP
743 Sets the normal image list. The image list assigned with this method
744 will @b not be deleted by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you
745 must delete it yourself.
746
747 @see AssignImageList().
23324ae1 748 */
adaaa686 749 virtual void SetImageList(wxImageList* imageList);
23324ae1
FM
750
751 /**
752 Sets the indentation for the tree control.
753 */
cfbe5614 754 virtual void SetIndent(unsigned int indent);
23324ae1
FM
755
756 /**
757 Sets the colour of the item's background.
758 */
fadc2df6
FM
759 virtual void SetItemBackgroundColour(const wxTreeItemId& item,
760 const wxColour& col);
23324ae1
FM
761
762 /**
7977b62a
BP
763 Makes item appear in bold font if @a bold parameter is @true or resets
764 it to the normal state.
765
766 @see IsBold()
23324ae1 767 */
adaaa686 768 virtual void SetItemBold(const wxTreeItemId& item, bool bold = true);
23324ae1 769
7977b62a
BP
770 /**
771 Sets the item client data.
772
773 @beginWxPythonOnly
774 - @b SetPyData( @a item, @c obj): Associate the given Python Object with
775 the wxTreeItemData for the given item Id.
776 @endWxPythonOnly
777
778 */
adaaa686 779 virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData* data);
7977b62a
BP
780
781
23324ae1
FM
782 /**
783 Gives the item the visual feedback for Drag'n'Drop actions, which is
784 useful if something is dragged from the outside onto the tree control
785 (as opposed to a DnD operation within the tree control, which already
786 is implemented internally).
787 */
fadc2df6
FM
788 virtual void SetItemDropHighlight(const wxTreeItemId& item,
789 bool highlight = true);
23324ae1
FM
790
791 /**
7977b62a
BP
792 Sets the item's font. All items in the tree should have the same height
793 to avoid text clipping, so the fonts height should be the same for all
794 of them, although font attributes may vary.
3c4f71cc 795
4cc4bfaf 796 @see SetItemBold()
23324ae1 797 */
adaaa686 798 virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font);
23324ae1
FM
799
800 /**
801 Force appearance of the button next to the item. This is useful to
802 allow the user to expand the items which don't have any children now,
803 but instead adding them only when needed, thus minimizing memory
804 usage and loading time.
805 */
fadc2df6
FM
806 virtual void SetItemHasChildren(const wxTreeItemId& item,
807 bool hasChildren = true);
23324ae1
FM
808
809 /**
7977b62a
BP
810 Sets the specified item's image. See GetItemImage() for the description
811 of the @a which parameter.
23324ae1 812 */
fadc2df6
FM
813 virtual void SetItemImage(const wxTreeItemId& item, int image,
814 wxTreeItemIcon which = wxTreeItemIcon_Normal);
23324ae1 815
03966fcb
RR
816 /**
817 Sets the specified item state. The value of @a state may be:
809ca837
RR
818 - @c wxTREE_ITEMSTATE_NONE: to disable the item state (the state image will
819 be not displayed).
820 - @c wxTREE_ITEMSTATE_NEXT: to set the next item state.
821 - @c wxTREE_ITEMSTATE_PREV: to set the previous item state.
03966fcb
RR
822 */
823 void SetItemState(const wxTreeItemId& item, int state);
824
23324ae1
FM
825 /**
826 Sets the item label.
827 */
adaaa686 828 virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
23324ae1
FM
829
830 /**
831 Sets the colour of the item's text.
832 */
fadc2df6
FM
833 virtual void SetItemTextColour(const wxTreeItemId& item,
834 const wxColour& col);
23324ae1
FM
835
836 /**
7977b62a
BP
837 If @true is passed, specifies that the control will use a quick
838 calculation for the best size, looking only at the first and last items.
839 Otherwise, it will look at all items. The default is @false.
3c4f71cc 840
4cc4bfaf 841 @see GetQuickBestSize()
23324ae1
FM
842 */
843 void SetQuickBestSize(bool quickBestSize);
844
845 /**
7977b62a
BP
846 Sets the state image list (from which application-defined state images
847 are taken). Image list assigned with this method will @b not be deleted
848 by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it
849 yourself.
850
851 @see AssignStateImageList().
23324ae1 852 */
adaaa686 853 virtual void SetStateImageList(wxImageList* imageList);
23324ae1
FM
854
855 /**
7977b62a
BP
856 Sets the mode flags associated with the display of the tree control. The
857 new mode takes effect immediately.
858
859 @note Generic only; MSW ignores changes.
23324ae1
FM
860 */
861 void SetWindowStyle(long styles);
862
863 /**
7977b62a
BP
864 Sorts the children of the given item using OnCompareItems().
865 You should override that method to change the sort order (the default is
866 ascending case-sensitive alphabetical order).
3c4f71cc 867
4cc4bfaf 868 @see wxTreeItemData, OnCompareItems()
23324ae1 869 */
adaaa686 870 virtual void SortChildren(const wxTreeItemId& item);
23324ae1
FM
871
872 /**
873 Toggles the given item between collapsed and expanded states.
874 */
adaaa686 875 virtual void Toggle(const wxTreeItemId& item);
23324ae1
FM
876
877 /**
878 Toggles the given item between selected and unselected states. For
879 multiselection controls only.
880 */
881 void ToggleItemSelection(const wxTreeItemId& item);
882
883 /**
884 Removes the selection from the currently selected item (if any).
885 */
adaaa686 886 virtual void Unselect();
23324ae1
FM
887
888 /**
7977b62a
BP
889 This function either behaves the same as Unselect() if the control
890 doesn't have @c wxTR_MULTIPLE style, or removes the selection from all
891 items if it does have this style.
23324ae1 892 */
adaaa686 893 virtual void UnselectAll();
23324ae1
FM
894
895 /**
896 Unselects the given item. This works in multiselection controls only.
897 */
898 void UnselectItem(const wxTreeItemId& item);
899};
900
901
e54c96f1 902
23324ae1
FM
903/**
904 @class wxTreeEvent
7c913512 905
7977b62a
BP
906 A tree event holds information about events associated with wxTreeCtrl
907 objects.
908
909 To process input from a tree control, use these event handler macros to
910 direct input to member functions that take a wxTreeEvent argument.
911
912 @beginEventTable{wxTreeEvent}
913 @event{EVT_TREE_BEGIN_DRAG(id, func)}
914 Begin dragging with the left mouse button.
915 @event{EVT_TREE_BEGIN_RDRAG(id, func)}
916 Begin dragging with the right mouse button.
917 @event{EVT_TREE_END_DRAG(id, func)}
918 End dragging with the left or right mouse button.
919 @event{EVT_TREE_BEGIN_LABEL_EDIT(id, func)}
920 Begin editing a label. This can be prevented by calling Veto().
921 @event{EVT_TREE_END_LABEL_EDIT(id, func)}
922 Finish editing a label. This can be prevented by calling Veto().
923 @event{EVT_TREE_DELETE_ITEM(id, func)}
924 Delete an item.
925 @event{EVT_TREE_GET_INFO(id, func)}
926 Request information from the application.
927 @event{EVT_TREE_SET_INFO(id, func)}
928 Information is being supplied.
929 @event{EVT_TREE_ITEM_ACTIVATED(id, func)}
930 The item has been activated, i.e. chosen by double clicking it with
931 mouse or from keyboard.
932 @event{EVT_TREE_ITEM_COLLAPSED(id, func)}
933 The item has been collapsed.
934 @event{EVT_TREE_ITEM_COLLAPSING(id, func)}
935 The item is being collapsed. This can be prevented by calling Veto().
936 @event{EVT_TREE_ITEM_EXPANDED(id, func)}
937 The item has been expanded.
938 @event{EVT_TREE_ITEM_EXPANDING(id, func)}
939 The item is being expanded. This can be prevented by calling Veto().
940 @event{EVT_TREE_ITEM_RIGHT_CLICK(id, func)}
941 The user has clicked the item with the right mouse button.
942 @event{EVT_TREE_ITEM_MIDDLE_CLICK(id, func)}
943 The user has clicked the item with the middle mouse button.
944 @event{EVT_TREE_SEL_CHANGED(id, func)}
945 Selection has changed.
946 @event{EVT_TREE_SEL_CHANGING(id, func)}
947 Selection is changing. This can be prevented by calling Veto().
948 @event{EVT_TREE_KEY_DOWN(id, func)}
949 A key has been pressed.
950 @event{EVT_TREE_ITEM_GETTOOLTIP(id, func)}
951 The opportunity to set the item tooltip is being given to the
952 application (call SetToolTip()). Windows only.
953 @event{EVT_TREE_ITEM_MENU(id, func)}
954 The context menu for the selected item has been requested, either by a
955 right click or by using the menu key.
956 @event{EVT_TREE_STATE_IMAGE_CLICK(id, func)}
809ca837 957 The state image has been clicked.
7977b62a 958 @endEventTable
7c913512 959
23324ae1
FM
960 @library{wxbase}
961 @category{events}
7c913512 962
e54c96f1 963 @see wxTreeCtrl
23324ae1
FM
964*/
965class wxTreeEvent : public wxNotifyEvent
966{
967public:
968 /**
23324ae1
FM
969 Constructor, used by wxWidgets itself only.
970 */
cfbe5614
FM
971 wxTreeEvent(wxEventType commandType, wxTreeCtrl* tree,
972 const wxTreeItemId& item = wxTreeItemId());
23324ae1
FM
973
974 /**
975 Returns the item (valid for all events).
976 */
328f5751 977 wxTreeItemId GetItem() const;
23324ae1
FM
978
979 /**
7977b62a
BP
980 Returns the key code if the event is a key event. Use GetKeyEvent() to
981 get the values of the modifier keys for this event (i.e. Shift or Ctrl).
23324ae1 982 */
328f5751 983 int GetKeyCode() const;
23324ae1
FM
984
985 /**
6873eb5b 986 Returns the key event for @c EVT_TREE_KEY_DOWN events.
23324ae1 987 */
cfbe5614 988 const wxKeyEvent& GetKeyEvent() const;
23324ae1
FM
989
990 /**
991 Returns the label if the event is a begin or end edit label event.
992 */
cfbe5614 993 const wxString& GetLabel() const;
23324ae1
FM
994
995 /**
6873eb5b
FM
996 Returns the old item index (valid for @c EVT_TREE_ITEM_CHANGING and
997 @c EVT_TREE_ITEM_CHANGED events).
23324ae1 998 */
328f5751 999 wxTreeItemId GetOldItem() const;
23324ae1
FM
1000
1001 /**
1002 Returns the position of the mouse pointer if the event is a drag or
1003 menu-context event.
7977b62a
BP
1004
1005 In both cases the position is in client coordinates - i.e. relative to
1006 the wxTreeCtrl window (so that you can pass it directly to e.g.
1007 wxWindow::PopupMenu()).
23324ae1 1008 */
328f5751 1009 wxPoint GetPoint() const;
23324ae1
FM
1010
1011 /**
7977b62a 1012 Returns @true if the label edit was cancelled. This should be called
6873eb5b 1013 from within an @c EVT_TREE_END_LABEL_EDIT handler.
23324ae1 1014 */
328f5751 1015 bool IsEditCancelled() const;
23324ae1
FM
1016
1017 /**
6873eb5b 1018 Set the tooltip for the item (valid for @c EVT_TREE_ITEM_GETTOOLTIP
7977b62a 1019 events). Windows only.
23324ae1
FM
1020 */
1021 void SetToolTip(const wxString& tooltip);
1022};