1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTreeItemData
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
12 A tree control presents information as a hierarchy, with items that may be
13 expanded to show further items. Items in a tree control are referenced by
14 wxTreeItemId handles, which may be tested for validity by calling
17 A similar control with a fully native implementation for GTK+ and OS X
18 as well is wxDataViewTreeCtrl.
20 To intercept events from a tree control, use the event table macros
21 described in wxTreeEvent.
24 @style{wxTR_EDIT_LABELS}
25 Use this style if you wish the user to be able to edit labels in the
27 @style{wxTR_NO_BUTTONS}
28 For convenience to document that no buttons are to be drawn.
29 @style{wxTR_HAS_BUTTONS}
30 Use this style to show + and - buttons to the left of parent items.
31 @style{wxTR_TWIST_BUTTONS}
32 Selects alternative style of @c +/@c - buttons and shows rotating
33 ("twisting") arrows instead. Currently this style is only implemented
34 under Microsoft Windows Vista and later Windows versions and is ignored
35 under the other platforms. Notice that under Vista this style results
36 in the same appearance as used by the tree control in Explorer and
37 other built-in programs and so using it may be preferable to the
40 Use this style to hide vertical level connectors.
41 @style{wxTR_FULL_ROW_HIGHLIGHT}
42 Use this style to have the background colour and the selection highlight
43 extend over the entire horizontal row of the tree control window. (This
44 flag is ignored under Windows unless you specify @c wxTR_NO_LINES as
46 @style{wxTR_LINES_AT_ROOT}
47 Use this style to show lines between root nodes. Only applicable if @c
48 wxTR_HIDE_ROOT is set and @c wxTR_NO_LINES is not set.
49 @style{wxTR_HIDE_ROOT}
50 Use this style to suppress the display of the root node, effectively
51 causing the first-level nodes to appear as a series of root nodes.
52 @style{wxTR_ROW_LINES}
53 Use this style to draw a contrasting border between displayed rows.
54 @style{wxTR_HAS_VARIABLE_ROW_HEIGHT}
55 Use this style to cause row heights to be just big enough to fit the
56 content. If not set, all rows use the largest row height. The default is
57 that this flag is unset. Generic only.
59 For convenience to document that only one item may be selected at a
60 time. Selecting another item causes the current selection, if any, to be
61 deselected. This is the default.
63 Use this style to allow a range of items to be selected. If a second
64 range is selected, the current range, if any, is deselected.
65 @style{wxTR_DEFAULT_STYLE}
66 The set of flags that are closest to the defaults for the native control
67 for a particular toolkit.
70 @beginEventEmissionTable{wxTreeEvent}
71 @event{EVT_TREE_BEGIN_DRAG(id, func)}
72 Begin dragging with the left mouse button.
73 If you want to enable left-dragging you need to intercept this event
74 and explicitly call wxTreeEvent::Allow(), as it's vetoed by default.
75 Processes a @c wxEVT_TREE_BEGIN_DRAG event type.
76 @event{EVT_TREE_BEGIN_RDRAG(id, func)}
77 Begin dragging with the right mouse button.
78 If you want to enable right-dragging you need to intercept this event
79 and explicitly call wxTreeEvent::Allow(), as it's vetoed by default.
80 Processes a @c wxEVT_TREE_BEGIN_RDRAG event type.
81 @event{EVT_TREE_END_DRAG(id, func)}
82 End dragging with the left or right mouse button.
83 Processes a @c wxEVT_TREE_END_DRAG event type.
84 @event{EVT_TREE_BEGIN_LABEL_EDIT(id, func)}
85 Begin editing a label. This can be prevented by calling Veto().
86 Processes a @c wxEVT_TREE_BEGIN_LABEL_EDIT event type.
87 @event{EVT_TREE_END_LABEL_EDIT(id, func)}
88 Finish editing a label. This can be prevented by calling Veto().
89 Processes a @c wxEVT_TREE_END_LABEL_EDIT event type.
90 @event{EVT_TREE_DELETE_ITEM(id, func)}
92 Processes a @c wxEVT_TREE_DELETE_ITEM event type.
93 @event{EVT_TREE_GET_INFO(id, func)}
94 Request information from the application.
95 Processes a @c wxEVT_TREE_GET_INFO event type.
96 @event{EVT_TREE_SET_INFO(id, func)}
97 Information is being supplied.
98 Processes a @c wxEVT_TREE_SET_INFO event type.
99 @event{EVT_TREE_ITEM_ACTIVATED(id, func)}
100 The item has been activated, i.e. chosen by double clicking it with
101 mouse or from keyboard.
102 Processes a @c wxEVT_TREE_ITEM_ACTIVATED event type.
103 @event{EVT_TREE_ITEM_COLLAPSED(id, func)}
104 The item has been collapsed.
105 Processes a @c wxEVT_TREE_ITEM_COLLAPSED event type.
106 @event{EVT_TREE_ITEM_COLLAPSING(id, func)}
107 The item is being collapsed. This can be prevented by calling Veto().
108 Processes a @c wxEVT_TREE_ITEM_COLLAPSING event type.
109 @event{EVT_TREE_ITEM_EXPANDED(id, func)}
110 The item has been expanded.
111 Processes a @c wxEVT_TREE_ITEM_EXPANDED event type.
112 @event{EVT_TREE_ITEM_EXPANDING(id, func)}
113 The item is being expanded. This can be prevented by calling Veto().
114 Processes a @c wxEVT_TREE_ITEM_EXPANDING event type.
115 @event{EVT_TREE_ITEM_RIGHT_CLICK(id, func)}
116 The user has clicked the item with the right mouse button.
117 Processes a @c wxEVT_TREE_ITEM_RIGHT_CLICK event type.
118 @event{EVT_TREE_ITEM_MIDDLE_CLICK(id, func)}
119 The user has clicked the item with the middle mouse button. This is
120 only supported by the generic control.
121 Processes a @c wxEVT_TREE_ITEM_MIDDLE_CLICK event type.
122 @event{EVT_TREE_SEL_CHANGED(id, func)}
123 Selection has changed.
124 Processes a @c wxEVT_TREE_SEL_CHANGED event type.
125 @event{EVT_TREE_SEL_CHANGING(id, func)}
126 Selection is changing. This can be prevented by calling Veto().
127 Processes a @c wxEVT_TREE_SEL_CHANGING event type.
128 @event{EVT_TREE_KEY_DOWN(id, func)}
129 A key has been pressed.
130 Processes a @c wxEVT_TREE_KEY_DOWN event type.
131 @event{EVT_TREE_ITEM_GETTOOLTIP(id, func)}
132 The opportunity to set the item tooltip is being given to the application
133 (call wxTreeEvent::SetToolTip). Windows only.
134 Processes a @c wxEVT_TREE_ITEM_GETTOOLTIP event type.
135 @event{EVT_TREE_ITEM_MENU(id, func)}
136 The context menu for the selected item has been requested, either by a
137 right click or by using the menu key.
138 Processes a @c wxEVT_TREE_ITEM_MENU event type.
139 @event{EVT_TREE_STATE_IMAGE_CLICK(id, func)}
140 The state image has been clicked.
141 Processes a @c wxEVT_TREE_STATE_IMAGE_CLICK event type.
145 See also @ref overview_windowstyles.
149 wxTreeCtrl class uses the standard common treeview control under Win32
150 implemented in the system library comctl32.dll. Some versions of this
151 library are known to have bugs with handling the tree control colours: the
152 usual symptom is that the expanded items leave black (or otherwise
153 incorrectly coloured) background behind them, especially for the controls
154 using non-default background colour. The recommended solution is to upgrade
155 the comctl32.dll to a newer version: see
156 http://www.microsoft.com/downloads/details.aspx?familyid=cb2cf3a2-8025-4e8f-8511-9b476a8d35d2
160 @appearance{treectrl}
162 @see wxDataViewTreeCtrl, wxTreeEvent, wxTreeItemData, @ref overview_treectrl,
163 wxListBox, wxListCtrl, wxImageList
165 class wxTreeCtrl
: public wxControl
174 Constructor, creating and showing a tree control.
177 Parent window. Must not be @NULL.
179 Window identifier. The value @c wxID_ANY indicates a default value.
182 If ::wxDefaultPosition is specified then a default position is chosen.
185 If ::wxDefaultSize is specified then the window is sized appropriately.
187 Window style. See wxTreeCtrl.
193 @see Create(), wxValidator
195 wxTreeCtrl(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
196 const wxPoint
& pos
= wxDefaultPosition
,
197 const wxSize
& size
= wxDefaultSize
,
198 long style
= wxTR_DEFAULT_STYLE
,
199 const wxValidator
& validator
= wxDefaultValidator
,
200 const wxString
& name
= wxTreeCtrlNameStr
);
204 Destructor, destroying the tree control.
206 virtual ~wxTreeCtrl();
209 Adds the root node to the tree, returning the new item.
211 The @a image and @a selImage parameters are an index within the normal
212 image list specifying the image to use for unselected and selected
213 items, respectively. If @a image -1 and @a selImage is -1, the same
214 image is used for both selected and unselected items.
216 virtual wxTreeItemId
AddRoot(const wxString
& text
, int image
= -1,
218 wxTreeItemData
* data
= NULL
);
221 Appends an item to the end of the branch identified by @a parent, return
224 The @a image and @a selImage parameters are an index within the normal
225 image list specifying the image to use for unselected and selected
226 items, respectively. If @a image -1 and @a selImage is -1, the same
227 image is used for both selected and unselected items.
229 wxTreeItemId
AppendItem(const wxTreeItemId
& parent
,
230 const wxString
& text
,
233 wxTreeItemData
* data
= NULL
);
236 Sets the buttons image list. The button images assigned with this method
237 will be automatically deleted by wxTreeCtrl as appropriate (i.e. it
238 takes ownership of the list).
240 Setting or assigning the button image list enables the display of image
241 buttons. Once enabled, the only way to disable the display of button
242 images is to set the button image list to @NULL.
244 This function is only available in the generic version.
246 @see SetButtonsImageList().
248 void AssignButtonsImageList(wxImageList
* imageList
);
251 Sets the normal image list. The image list assigned with this method
252 will be automatically deleted by wxTreeCtrl as appropriate (i.e. it
253 takes ownership of the list).
257 void AssignImageList(wxImageList
* imageList
);
260 Sets the state image list. Image list assigned with this method will be
261 automatically deleted by wxTreeCtrl as appropriate (i.e. it takes
262 ownership of the list).
264 @see SetStateImageList().
266 void AssignStateImageList(wxImageList
* imageList
);
269 Collapses the given item.
271 virtual void Collapse(const wxTreeItemId
& item
);
274 Collapses the root item.
281 Collapses this item and all of its children, recursively.
283 @see ExpandAllChildren()
285 void CollapseAllChildren(const wxTreeItemId
& item
);
288 Collapses the given item and removes all children.
290 virtual void CollapseAndReset(const wxTreeItemId
& item
);
293 Creates the tree control.
294 See wxTreeCtrl::wxTreeCtrl() for further details.
296 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
297 const wxPoint
& pos
= wxDefaultPosition
,
298 const wxSize
& size
= wxDefaultSize
,
299 long style
= wxTR_DEFAULT_STYLE
,
300 const wxValidator
& validator
= wxDefaultValidator
,
301 const wxString
& name
= wxTreeCtrlNameStr
);
304 Deletes the specified item. A @c EVT_TREE_DELETE_ITEM event will be
307 This function may cause a subsequent call to GetNextChild() to fail.
309 virtual void Delete(const wxTreeItemId
& item
);
312 Deletes all items in the control. Note that this may not generate
313 @c EVT_TREE_DELETE_ITEM events under some Windows versions although
314 normally such event is generated for each removed item.
316 virtual void DeleteAllItems();
319 Deletes all children of the given item (but not the item itself). Note
320 that this will @b not generate any events unlike Delete() method.
322 If you have called SetItemHasChildren(), you may need to call it again
323 since DeleteChildren() does not automatically clear the setting.
325 virtual void DeleteChildren(const wxTreeItemId
& item
);
328 Starts editing the label of the given @a item. This function generates a
329 @c EVT_TREE_BEGIN_LABEL_EDIT event which can be vetoed so that no text
330 control will appear for in-place editing.
332 If the user changed the label (i.e. s/he does not press ESC or leave the
333 text control without changes, a @c EVT_TREE_END_LABEL_EDIT event will be
334 sent which can be vetoed as well.
336 @see EndEditLabel(), wxTreeEvent
338 virtual wxTextCtrl
*EditLabel(const wxTreeItemId
& item
,
339 wxClassInfo
* textCtrlClass
= wxCLASSINFO(wxTextCtrl
));
342 Enable or disable a beep if there is no match for the currently
343 entered text when searching for the item from keyboard.
345 The default is to not beep in this case except in wxMSW where the
346 beep is always generated by the native control and cannot be disabled,
347 i.e. calls to this function do nothing there.
351 void EnableBellOnNoMatch(bool on
= true);
354 Ends label editing. If @a cancelEdit is @true, the edit will be
358 This function is currently supported under Windows only.
362 virtual void EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
= false);
365 Scrolls and/or expands items to ensure that the given item is visible.
367 virtual void EnsureVisible(const wxTreeItemId
& item
);
370 Expands the given item.
372 virtual void Expand(const wxTreeItemId
& item
);
375 Expands all items in the tree.
380 Expands the given item and all its children recursively.
382 void ExpandAllChildren(const wxTreeItemId
& item
);
385 Retrieves the rectangle bounding the @a item. If @a textOnly is @true,
386 only the rectangle around the item's label will be returned, otherwise
387 the item's image is also taken into account.
389 The return value is @true if the rectangle was successfully retrieved or
390 @c @false if it was not (in this case @a rect is not changed) -- for
391 example, if the item is currently invisible.
393 Notice that the rectangle coordinates are logical, not physical ones.
394 So, for example, the x coordinate may be negative if the tree has a
395 horizontal scrollbar and its position is not 0.
398 In wxPerl this method only takes the @a item and
399 @a textOnly parameters and returns a @c Wx::Rect (or @c undef).
402 virtual bool GetBoundingRect(const wxTreeItemId
& item
, wxRect
& rect
,
403 bool textOnly
= false) const;
406 Returns the buttons image list (from which application-defined button
409 This function is only available in the generic version.
411 wxImageList
* GetButtonsImageList() const;
414 Returns the number of items in the branch. If @a recursively is @true,
415 returns the total number of descendants, otherwise only one level of
418 virtual size_t GetChildrenCount(const wxTreeItemId
& item
,
419 bool recursively
= true) const;
422 Returns the number of items in the control.
424 virtual unsigned int GetCount() const;
427 Returns the edit control being currently used to edit a label. Returns
428 @NULL if no label is being edited.
430 @note This is currently only implemented for wxMSW.
432 virtual wxTextCtrl
* GetEditControl() const;
435 Returns the first child; call GetNextChild() for the next child.
437 For this enumeration function you must pass in a 'cookie' parameter
438 which is opaque for the application but is necessary for the library to
439 make these functions reentrant (i.e. allow more than one enumeration on
440 one and the same object simultaneously). The cookie passed to
441 GetFirstChild() and GetNextChild() should be the same variable.
443 Returns an invalid tree item (i.e. wxTreeItemId::IsOk() returns @false)
444 if there are no further children.
447 In wxPerl this method only takes the @a item parameter, and
448 returns a 2-element list (item, cookie).
451 @see GetNextChild(), GetNextSibling()
453 virtual wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
,
454 wxTreeItemIdValue
& cookie
) const;
457 Returns the first visible item.
459 virtual wxTreeItemId
GetFirstVisibleItem() const;
462 Returns the item last clicked or otherwise selected.
463 Unlike GetSelection(), it can be used whether or not
464 the control has the @c wxTR_MULTIPLE style.
468 virtual wxTreeItemId
GetFocusedItem() const;
472 Clears the currently focused item
476 virtual void ClearFocusedItem();
479 Sets the currently focused item.
482 The item to make the current one. It must be valid.
485 virtual void SetFocusedItem(const wxTreeItemId
& item
);
489 Returns the normal image list.
491 wxImageList
* GetImageList() const;
494 Returns the current tree control indentation.
496 virtual unsigned int GetIndent() const;
499 Returns the background colour of the item.
501 virtual wxColour
GetItemBackgroundColour(const wxTreeItemId
& item
) const;
504 Returns the tree item data associated with the item.
509 wxPerl provides the following shortcut method:
510 - GetPlData(item): returns the Perl data
511 associated with the Wx::TreeItemData. It is just the same as
512 tree->GetItemData(item)->GetData().
515 virtual wxTreeItemData
* GetItemData(const wxTreeItemId
& item
) const;
518 Returns the font of the item label.
520 virtual wxFont
GetItemFont(const wxTreeItemId
& item
) const;
523 Gets the specified item image. The value of @a which may be:
524 - ::wxTreeItemIcon_Normal: to get the normal item image.
525 - ::wxTreeItemIcon_Selected: to get the selected item image (i.e. the
526 image which is shown when the item is currently selected).
527 - ::wxTreeItemIcon_Expanded: to get the expanded image (this only makes
528 sense for items which have children - then this image is shown when
529 the item is expanded and the normal image is shown when it is
531 - ::wxTreeItemIcon_SelectedExpanded: to get the selected expanded image
532 (which is shown when an expanded item is currently selected).
534 virtual int GetItemImage(const wxTreeItemId
& item
,
535 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const;
538 Returns the item's parent.
540 virtual wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
543 Gets the specified item state.
545 int GetItemState(const wxTreeItemId
& item
) const;
548 Returns the item label.
550 virtual wxString
GetItemText(const wxTreeItemId
& item
) const;
553 Returns the colour of the item label.
555 virtual wxColour
GetItemTextColour(const wxTreeItemId
& item
) const;
558 Returns the last child of the item (or an invalid tree item if this item
561 @see GetFirstChild(), GetNextSibling(), GetLastChild()
563 virtual wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
566 Returns the next child; call GetFirstChild() for the first child. For
567 this enumeration function you must pass in a 'cookie' parameter which is
568 opaque for the application but is necessary for the library to make
569 these functions reentrant (i.e. allow more than one enumeration on one
570 and the same object simultaneously). The cookie passed to
571 GetFirstChild() and GetNextChild() should be the same.
573 Returns an invalid tree item if there are no further children.
576 In wxPerl this method returns a 2-element list
577 (item, cookie) instead of modifying its parameters.
582 virtual wxTreeItemId
GetNextChild(const wxTreeItemId
& item
,
583 wxTreeItemIdValue
& cookie
) const;
586 Returns the next sibling of the specified item; call GetPrevSibling()
587 for the previous sibling.
589 Returns an invalid tree item if there are no further siblings.
591 @see GetPrevSibling()
593 virtual wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
596 Returns the next visible item or an invalid item if this item is the
599 @note The @a item itself must be visible.
601 virtual wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
604 Returns the previous sibling of the specified item; call
605 GetNextSibling() for the next sibling.
607 Returns an invalid tree item if there are no further children.
609 @see GetNextSibling()
611 virtual wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
614 Returns the previous visible item or an invalid item if this item is the
617 @note The @a item itself must be visible.
619 virtual wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
622 Returns @true if the control will use a quick calculation for the best
623 size, looking only at the first and last items. The default is @false.
625 @see SetQuickBestSize()
627 bool GetQuickBestSize() const;
630 Returns the root item for the tree control.
632 virtual wxTreeItemId
GetRootItem() const;
635 Returns the selection, or an invalid item if there is no selection. This
636 function only works with the controls without @c wxTR_MULTIPLE style,
637 use GetSelections() for the controls which do have this style
638 or, if a single item is wanted, use GetFocusedItem().
640 virtual wxTreeItemId
GetSelection() const;
643 Fills the array of tree items passed in with the currently selected
644 items. This function can be called only if the control has the @c
647 Returns the number of selected items.
650 In wxPerl this method takes no parameters and returns a list of
654 virtual size_t GetSelections(wxArrayTreeItemIds
& selection
) const;
657 Returns the state image list (from which application-defined state
660 wxImageList
* GetStateImageList() const;
663 Calculates which (if any) item is under the given @a point, returning
664 the tree item id at this point plus extra information @a flags. @a flags
665 is a bitlist of the following:
667 - @c wxTREE_HITTEST_ABOVE: Above the client area.
668 - @c wxTREE_HITTEST_BELOW: Below the client area.
669 - @c wxTREE_HITTEST_NOWHERE: In the client area but below the last item.
670 - @c wxTREE_HITTEST_ONITEMBUTTON: On the button associated with an item.
671 - @c wxTREE_HITTEST_ONITEMICON: On the bitmap associated with an item.
672 - @c wxTREE_HITTEST_ONITEMINDENT: In the indentation associated with an item.
673 - @c wxTREE_HITTEST_ONITEMLABEL: On the label (string) associated with an item.
674 - @c wxTREE_HITTEST_ONITEMRIGHT: In the area to the right of an item.
675 - @c wxTREE_HITTEST_ONITEMSTATEICON: On the state icon for a tree view
676 item that is in a user-defined state.
677 - @c wxTREE_HITTEST_TOLEFT: To the right of the client area.
678 - @c wxTREE_HITTEST_TORIGHT: To the left of the client area.
681 In wxPerl this method only takes the @a point parameter
682 and returns a 2-element list (item, flags).
685 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
) const;
689 Inserts an item after a given one (@a previous).
691 The @a image and @a selImage parameters are an index within the normal
692 image list specifying the image to use for unselected and selected
693 items, respectively. If @a image -1 and @a selImage is -1, the same
694 image is used for both selected and unselected items.
696 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
697 const wxTreeItemId
& previous
,
698 const wxString
& text
,
701 wxTreeItemData
* data
= NULL
);
704 Inserts an item before one identified
705 by its position (@a pos). @a pos must be less than or equal to
706 the number of children.
708 The @a image and @a selImage parameters are an index within the normal
709 image list specifying the image to use for unselected and selected
710 items, respectively. If @a image -1 and @a selImage is -1, the same
711 image is used for both selected and unselected items.
713 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
715 const wxString
& text
,
718 wxTreeItemData
* data
= NULL
);
721 Returns @true if the given item is in bold state.
725 virtual bool IsBold(const wxTreeItemId
& item
) const;
728 Returns @true if the control is empty (i.e.\ has no items, even no root
731 bool IsEmpty() const;
734 Returns @true if the item is expanded (only makes sense if it has
737 virtual bool IsExpanded(const wxTreeItemId
& item
) const;
740 Returns @true if the item is selected.
742 virtual bool IsSelected(const wxTreeItemId
& item
) const;
745 Returns @true if the item is visible on the screen.
747 virtual bool IsVisible(const wxTreeItemId
& item
) const;
750 Returns @true if the item has children.
752 virtual bool ItemHasChildren(const wxTreeItemId
& item
) const;
755 Override this function in the derived class to change the sort order of
756 the items in the tree control. The function should return a negative,
757 zero or positive value if the first item is less than, equal to or
758 greater than the second one.
760 Please note that you @b must use wxRTTI macros wxDECLARE_DYNAMIC_CLASS()
761 and wxIMPLEMENT_DYNAMIC_CLASS() if you override this function because
762 otherwise the base class considers that it is not overridden and uses
763 the default comparison, i.e. sorts the items alphabetically, which
764 allows it optimize away the calls to the virtual function completely.
768 virtual int OnCompareItems(const wxTreeItemId
& item1
,
769 const wxTreeItemId
& item2
);
772 Appends an item as the first child of @a parent, return a new item id.
774 The @a image and @a selImage parameters are an index within the normal
775 image list specifying the image to use for unselected and selected
776 items, respectively. If @a image -1 and @a selImage is -1, the same
777 image is used for both selected and unselected items.
779 wxTreeItemId
PrependItem(const wxTreeItemId
& parent
,
780 const wxString
& text
,
783 wxTreeItemData
* data
= NULL
);
786 Scrolls the specified item into view.
788 virtual void ScrollTo(const wxTreeItemId
& item
);
791 Selects the given item.
793 In multiple selection controls, can be also used to deselect a
794 currently selected item if the value of @a select is @false.
796 Notice that calling this method will generate
797 @c wxEVT_TREE_SEL_CHANGING and @c wxEVT_TREE_SEL_CHANGED
798 events and that the change could be vetoed by the former event handler.
800 virtual void SelectItem(const wxTreeItemId
& item
, bool select
= true);
803 Sets the buttons image list (from which application-defined button
806 The button images assigned with this method will @b not be deleted by
807 @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it yourself.
808 Setting or assigning the button image list enables the display of image
809 buttons. Once enabled, the only way to disable the display of button
810 images is to set the button image list to @NULL.
812 @note This function is only available in the generic version.
814 @see AssignButtonsImageList().
816 void SetButtonsImageList(wxImageList
* imageList
);
819 Sets the normal image list. The image list assigned with this method
820 will @b not be deleted by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you
821 must delete it yourself.
823 @see AssignImageList().
825 virtual void SetImageList(wxImageList
* imageList
);
828 Sets the indentation for the tree control.
830 virtual void SetIndent(unsigned int indent
);
833 Sets the colour of the item's background.
835 virtual void SetItemBackgroundColour(const wxTreeItemId
& item
,
836 const wxColour
& col
);
839 Makes item appear in bold font if @a bold parameter is @true or resets
840 it to the normal state.
844 virtual void SetItemBold(const wxTreeItemId
& item
, bool bold
= true);
847 Sets the item client data.
849 Notice that the client data previously associated with the @a item (if
850 any) is @em not freed by this function and so calling this function
851 multiple times for the same item will result in memory leaks unless you
852 delete the old item data pointer yourself.
855 wxPerl provides the following shortcut method:
856 - SetPlData(item, data): sets the Perl data
857 associated with the @c Wx::TreeItemData. It is just the same as
858 tree->GetItemData(item)->SetData(data).
861 virtual void SetItemData(const wxTreeItemId
& item
, wxTreeItemData
* data
);
865 Gives the item the visual feedback for Drag'n'Drop actions, which is
866 useful if something is dragged from the outside onto the tree control
867 (as opposed to a DnD operation within the tree control, which already
868 is implemented internally).
870 virtual void SetItemDropHighlight(const wxTreeItemId
& item
,
871 bool highlight
= true);
874 Sets the item's font. All items in the tree should have the same height
875 to avoid text clipping, so the fonts height should be the same for all
876 of them, although font attributes may vary.
880 virtual void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
);
883 Force appearance of the button next to the item. This is useful to
884 allow the user to expand the items which don't have any children now,
885 but instead adding them only when needed, thus minimizing memory
886 usage and loading time.
888 virtual void SetItemHasChildren(const wxTreeItemId
& item
,
889 bool hasChildren
= true);
892 Sets the specified item's image. See GetItemImage() for the description
893 of the @a which parameter.
895 virtual void SetItemImage(const wxTreeItemId
& item
, int image
,
896 wxTreeItemIcon which
= wxTreeItemIcon_Normal
);
899 Sets the specified item state. The value of @a state may be:
900 - @c wxTREE_ITEMSTATE_NONE: to disable the item state (the state image will
902 - @c wxTREE_ITEMSTATE_NEXT: to set the next item state.
903 - @c wxTREE_ITEMSTATE_PREV: to set the previous item state.
905 void SetItemState(const wxTreeItemId
& item
, int state
);
910 virtual void SetItemText(const wxTreeItemId
& item
, const wxString
& text
);
913 Sets the colour of the item's text.
915 virtual void SetItemTextColour(const wxTreeItemId
& item
,
916 const wxColour
& col
);
919 If @true is passed, specifies that the control will use a quick
920 calculation for the best size, looking only at the first and last items.
921 Otherwise, it will look at all items. The default is @false.
923 @see GetQuickBestSize()
925 void SetQuickBestSize(bool quickBestSize
);
928 Sets the state image list (from which application-defined state images
929 are taken). Image list assigned with this method will @b not be deleted
930 by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it
933 @see AssignStateImageList().
935 virtual void SetStateImageList(wxImageList
* imageList
);
938 Sets the mode flags associated with the display of the tree control. The
939 new mode takes effect immediately.
941 @note Generic only; MSW ignores changes.
943 void SetWindowStyle(long styles
);
946 Sorts the children of the given item using OnCompareItems().
947 You should override that method to change the sort order (the default is
948 ascending case-sensitive alphabetical order).
950 @see wxTreeItemData, OnCompareItems()
952 virtual void SortChildren(const wxTreeItemId
& item
);
955 Toggles the given item between collapsed and expanded states.
957 virtual void Toggle(const wxTreeItemId
& item
);
960 Toggles the given item between selected and unselected states. For
961 multiselection controls only.
963 void ToggleItemSelection(const wxTreeItemId
& item
);
966 Removes the selection from the currently selected item (if any).
968 virtual void Unselect();
971 This function either behaves the same as Unselect() if the control
972 doesn't have @c wxTR_MULTIPLE style, or removes the selection from all
973 items if it does have this style.
975 virtual void UnselectAll();
978 Unselects the given item. This works in multiselection controls only.
980 void UnselectItem(const wxTreeItemId
& item
);
983 Select all the immediate children of the given parent.
985 This function can be used with multiselection controls only.
989 virtual void SelectChildren(const wxTreeItemId
& parent
);
997 A tree event holds information about events associated with wxTreeCtrl
1000 To process input from a tree control, use these event handler macros to
1001 direct input to member functions that take a wxTreeEvent argument.
1003 @beginEventTable{wxTreeEvent}
1004 @event{EVT_TREE_BEGIN_DRAG(id, func)}
1005 Begin dragging with the left mouse button. If you want to enable
1006 left-dragging you need to intercept this event and explicitly call
1007 wxTreeEvent::Allow(), as it's vetoed by default. Also notice that the
1008 control must have an associated image list (see SetImageList()) to
1009 drag its items under MSW.
1010 @event{EVT_TREE_BEGIN_RDRAG(id, func)}
1011 Begin dragging with the right mouse button. If you want to enable
1012 right-dragging you need to intercept this event and explicitly call
1013 wxTreeEvent::Allow(), as it's vetoed by default.
1014 @event{EVT_TREE_END_DRAG(id, func)}
1015 End dragging with the left or right mouse button.
1016 @event{EVT_TREE_BEGIN_LABEL_EDIT(id, func)}
1017 Begin editing a label. This can be prevented by calling Veto().
1018 @event{EVT_TREE_END_LABEL_EDIT(id, func)}
1019 Finish editing a label. This can be prevented by calling Veto().
1020 @event{EVT_TREE_DELETE_ITEM(id, func)}
1022 @event{EVT_TREE_GET_INFO(id, func)}
1023 Request information from the application.
1024 @event{EVT_TREE_SET_INFO(id, func)}
1025 Information is being supplied.
1026 @event{EVT_TREE_ITEM_ACTIVATED(id, func)}
1027 The item has been activated, i.e. chosen by double clicking it with
1028 mouse or from keyboard.
1029 @event{EVT_TREE_ITEM_COLLAPSED(id, func)}
1030 The item has been collapsed.
1031 @event{EVT_TREE_ITEM_COLLAPSING(id, func)}
1032 The item is being collapsed. This can be prevented by calling Veto().
1033 @event{EVT_TREE_ITEM_EXPANDED(id, func)}
1034 The item has been expanded.
1035 @event{EVT_TREE_ITEM_EXPANDING(id, func)}
1036 The item is being expanded. This can be prevented by calling Veto().
1037 @event{EVT_TREE_ITEM_RIGHT_CLICK(id, func)}
1038 The user has clicked the item with the right mouse button.
1039 @event{EVT_TREE_ITEM_MIDDLE_CLICK(id, func)}
1040 The user has clicked the item with the middle mouse button.
1041 @event{EVT_TREE_SEL_CHANGED(id, func)}
1042 Selection has changed.
1043 @event{EVT_TREE_SEL_CHANGING(id, func)}
1044 Selection is changing. This can be prevented by calling Veto().
1045 @event{EVT_TREE_KEY_DOWN(id, func)}
1046 A key has been pressed.
1047 @event{EVT_TREE_ITEM_GETTOOLTIP(id, func)}
1048 The opportunity to set the item tooltip is being given to the
1049 application (call SetToolTip()). Windows only.
1050 @event{EVT_TREE_ITEM_MENU(id, func)}
1051 The context menu for the selected item has been requested, either by a
1052 right click or by using the menu key.
1053 @event{EVT_TREE_STATE_IMAGE_CLICK(id, func)}
1054 The state image has been clicked.
1062 class wxTreeEvent
: public wxNotifyEvent
1066 Constructor, used by wxWidgets itself only.
1068 wxTreeEvent(wxEventType commandType
, wxTreeCtrl
* tree
,
1069 const wxTreeItemId
& item
= wxTreeItemId());
1072 Returns the item (valid for all events).
1074 wxTreeItemId
GetItem() const;
1077 Returns the key code if the event is a key event. Use GetKeyEvent() to
1078 get the values of the modifier keys for this event (i.e. Shift or Ctrl).
1080 int GetKeyCode() const;
1083 Returns the key event for @c EVT_TREE_KEY_DOWN events.
1085 const wxKeyEvent
& GetKeyEvent() const;
1088 Returns the label if the event is a begin or end edit label event.
1090 const wxString
& GetLabel() const;
1093 Returns the old item index (valid for @c EVT_TREE_ITEM_CHANGING and
1094 @c EVT_TREE_ITEM_CHANGED events).
1096 wxTreeItemId
GetOldItem() const;
1099 Returns the position of the mouse pointer if the event is a drag or
1102 In both cases the position is in client coordinates - i.e. relative to
1103 the wxTreeCtrl window (so that you can pass it directly to e.g.
1104 wxWindow::PopupMenu()).
1106 wxPoint
GetPoint() const;
1109 Returns @true if the label edit was cancelled. This should be called
1110 from within an @c EVT_TREE_END_LABEL_EDIT handler.
1112 bool IsEditCancelled() const;
1115 Set the tooltip for the item (valid for @c EVT_TREE_ITEM_GETTOOLTIP
1116 events). Windows only.
1118 void SetToolTip(const wxString
& tooltip
);
1122 wxEventType wxEVT_TREE_BEGIN_DRAG
;
1123 wxEventType wxEVT_TREE_BEGIN_RDRAG
;
1124 wxEventType wxEVT_TREE_BEGIN_LABEL_EDIT
;
1125 wxEventType wxEVT_TREE_END_LABEL_EDIT
;
1126 wxEventType wxEVT_TREE_DELETE_ITEM
;
1127 wxEventType wxEVT_TREE_GET_INFO
;
1128 wxEventType wxEVT_TREE_SET_INFO
;
1129 wxEventType wxEVT_TREE_ITEM_EXPANDED
;
1130 wxEventType wxEVT_TREE_ITEM_EXPANDING
;
1131 wxEventType wxEVT_TREE_ITEM_COLLAPSED
;
1132 wxEventType wxEVT_TREE_ITEM_COLLAPSING
;
1133 wxEventType wxEVT_TREE_SEL_CHANGED
;
1134 wxEventType wxEVT_TREE_SEL_CHANGING
;
1135 wxEventType wxEVT_TREE_KEY_DOWN
;
1136 wxEventType wxEVT_TREE_ITEM_ACTIVATED
;
1137 wxEventType wxEVT_TREE_ITEM_RIGHT_CLICK
;
1138 wxEventType wxEVT_TREE_ITEM_MIDDLE_CLICK
;
1139 wxEventType wxEVT_TREE_END_DRAG
;
1140 wxEventType wxEVT_TREE_STATE_IMAGE_CLICK
;
1141 wxEventType wxEVT_TREE_ITEM_GETTOOLTIP
;
1142 wxEventType wxEVT_TREE_ITEM_MENU
;