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