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 If the font hadn't been explicitly set for the specified @a item with
521 SetItemFont(), returns an invalid ::wxNullFont font. GetFont() can be
522 used to retrieve the global tree control font used for the items
523 without any specific font.
525 virtual wxFont
GetItemFont(const wxTreeItemId
& item
) const;
528 Gets the specified item image. The value of @a which may be:
529 - ::wxTreeItemIcon_Normal: to get the normal item image.
530 - ::wxTreeItemIcon_Selected: to get the selected item image (i.e. the
531 image which is shown when the item is currently selected).
532 - ::wxTreeItemIcon_Expanded: to get the expanded image (this only makes
533 sense for items which have children - then this image is shown when
534 the item is expanded and the normal image is shown when it is
536 - ::wxTreeItemIcon_SelectedExpanded: to get the selected expanded image
537 (which is shown when an expanded item is currently selected).
539 virtual int GetItemImage(const wxTreeItemId
& item
,
540 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const;
543 Returns the item's parent.
545 virtual wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
548 Gets the specified item state.
550 int GetItemState(const wxTreeItemId
& item
) const;
553 Returns the item label.
555 virtual wxString
GetItemText(const wxTreeItemId
& item
) const;
558 Returns the colour of the item label.
560 virtual wxColour
GetItemTextColour(const wxTreeItemId
& item
) const;
563 Returns the last child of the item (or an invalid tree item if this item
566 @see GetFirstChild(), GetNextSibling(), GetLastChild()
568 virtual wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
571 Returns the next child; call GetFirstChild() for the first child. For
572 this enumeration function you must pass in a 'cookie' parameter which is
573 opaque for the application but is necessary for the library to make
574 these functions reentrant (i.e. allow more than one enumeration on one
575 and the same object simultaneously). The cookie passed to
576 GetFirstChild() and GetNextChild() should be the same.
578 Returns an invalid tree item if there are no further children.
581 In wxPerl this method returns a 2-element list
582 (item, cookie) instead of modifying its parameters.
587 virtual wxTreeItemId
GetNextChild(const wxTreeItemId
& item
,
588 wxTreeItemIdValue
& cookie
) const;
591 Returns the next sibling of the specified item; call GetPrevSibling()
592 for the previous sibling.
594 Returns an invalid tree item if there are no further siblings.
596 @see GetPrevSibling()
598 virtual wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
601 Returns the next visible item or an invalid item if this item is the
604 @note The @a item itself must be visible.
606 virtual wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
609 Returns the previous sibling of the specified item; call
610 GetNextSibling() for the next sibling.
612 Returns an invalid tree item if there are no further children.
614 @see GetNextSibling()
616 virtual wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
619 Returns the previous visible item or an invalid item if this item is the
622 @note The @a item itself must be visible.
624 virtual wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
627 Returns @true if the control will use a quick calculation for the best
628 size, looking only at the first and last items. The default is @false.
630 @see SetQuickBestSize()
632 bool GetQuickBestSize() const;
635 Returns the root item for the tree control.
637 virtual wxTreeItemId
GetRootItem() const;
640 Returns the selection, or an invalid item if there is no selection. This
641 function only works with the controls without @c wxTR_MULTIPLE style,
642 use GetSelections() for the controls which do have this style
643 or, if a single item is wanted, use GetFocusedItem().
645 virtual wxTreeItemId
GetSelection() const;
648 Fills the array of tree items passed in with the currently selected
649 items. This function can be called only if the control has the @c
652 Returns the number of selected items.
655 In wxPerl this method takes no parameters and returns a list of
659 virtual size_t GetSelections(wxArrayTreeItemIds
& selection
) const;
662 Returns the state image list (from which application-defined state
665 wxImageList
* GetStateImageList() const;
668 Calculates which (if any) item is under the given @a point, returning
669 the tree item id at this point plus extra information @a flags. @a flags
670 is a bitlist of the following:
672 - @c wxTREE_HITTEST_ABOVE: Above the client area.
673 - @c wxTREE_HITTEST_BELOW: Below the client area.
674 - @c wxTREE_HITTEST_NOWHERE: In the client area but below the last item.
675 - @c wxTREE_HITTEST_ONITEMBUTTON: On the button associated with an item.
676 - @c wxTREE_HITTEST_ONITEMICON: On the bitmap associated with an item.
677 - @c wxTREE_HITTEST_ONITEMINDENT: In the indentation associated with an item.
678 - @c wxTREE_HITTEST_ONITEMLABEL: On the label (string) associated with an item.
679 - @c wxTREE_HITTEST_ONITEMRIGHT: In the area to the right of an item.
680 - @c wxTREE_HITTEST_ONITEMSTATEICON: On the state icon for a tree view
681 item that is in a user-defined state.
682 - @c wxTREE_HITTEST_TOLEFT: To the right of the client area.
683 - @c wxTREE_HITTEST_TORIGHT: To the left of the client area.
686 In wxPerl this method only takes the @a point parameter
687 and returns a 2-element list (item, flags).
690 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
) const;
694 Inserts an item after a given one (@a previous).
696 The @a image and @a selImage parameters are an index within the normal
697 image list specifying the image to use for unselected and selected
698 items, respectively. If @a image -1 and @a selImage is -1, the same
699 image is used for both selected and unselected items.
701 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
702 const wxTreeItemId
& previous
,
703 const wxString
& text
,
706 wxTreeItemData
* data
= NULL
);
709 Inserts an item before one identified
710 by its position (@a pos). @a pos must be less than or equal to
711 the number of children.
713 The @a image and @a selImage parameters are an index within the normal
714 image list specifying the image to use for unselected and selected
715 items, respectively. If @a image -1 and @a selImage is -1, the same
716 image is used for both selected and unselected items.
718 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
720 const wxString
& text
,
723 wxTreeItemData
* data
= NULL
);
726 Returns @true if the given item is in bold state.
730 virtual bool IsBold(const wxTreeItemId
& item
) const;
733 Returns @true if the control is empty (i.e.\ has no items, even no root
736 bool IsEmpty() const;
739 Returns @true if the item is expanded (only makes sense if it has
742 virtual bool IsExpanded(const wxTreeItemId
& item
) const;
745 Returns @true if the item is selected.
747 virtual bool IsSelected(const wxTreeItemId
& item
) const;
750 Returns @true if the item is visible on the screen.
752 virtual bool IsVisible(const wxTreeItemId
& item
) const;
755 Returns @true if the item has children.
757 virtual bool ItemHasChildren(const wxTreeItemId
& item
) const;
760 Override this function in the derived class to change the sort order of
761 the items in the tree control. The function should return a negative,
762 zero or positive value if the first item is less than, equal to or
763 greater than the second one.
765 Please note that you @b must use wxRTTI macros wxDECLARE_DYNAMIC_CLASS()
766 and wxIMPLEMENT_DYNAMIC_CLASS() if you override this function because
767 otherwise the base class considers that it is not overridden and uses
768 the default comparison, i.e. sorts the items alphabetically, which
769 allows it optimize away the calls to the virtual function completely.
773 virtual int OnCompareItems(const wxTreeItemId
& item1
,
774 const wxTreeItemId
& item2
);
777 Appends an item as the first child of @a parent, return a new item id.
779 The @a image and @a selImage parameters are an index within the normal
780 image list specifying the image to use for unselected and selected
781 items, respectively. If @a image -1 and @a selImage is -1, the same
782 image is used for both selected and unselected items.
784 wxTreeItemId
PrependItem(const wxTreeItemId
& parent
,
785 const wxString
& text
,
788 wxTreeItemData
* data
= NULL
);
791 Scrolls the specified item into view.
793 virtual void ScrollTo(const wxTreeItemId
& item
);
796 Selects the given item.
798 In multiple selection controls, can be also used to deselect a
799 currently selected item if the value of @a select is @false.
801 Notice that calling this method will generate
802 @c wxEVT_TREE_SEL_CHANGING and @c wxEVT_TREE_SEL_CHANGED
803 events and that the change could be vetoed by the former event handler.
805 virtual void SelectItem(const wxTreeItemId
& item
, bool select
= true);
808 Sets the buttons image list (from which application-defined button
811 The button images assigned with this method will @b not be deleted by
812 @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it yourself.
813 Setting or assigning the button image list enables the display of image
814 buttons. Once enabled, the only way to disable the display of button
815 images is to set the button image list to @NULL.
817 @note This function is only available in the generic version.
819 @see AssignButtonsImageList().
821 void SetButtonsImageList(wxImageList
* imageList
);
824 Sets the normal image list. The image list assigned with this method
825 will @b not be deleted by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you
826 must delete it yourself.
828 @see AssignImageList().
830 virtual void SetImageList(wxImageList
* imageList
);
833 Sets the indentation for the tree control.
835 virtual void SetIndent(unsigned int indent
);
838 Sets the colour of the item's background.
840 virtual void SetItemBackgroundColour(const wxTreeItemId
& item
,
841 const wxColour
& col
);
844 Makes item appear in bold font if @a bold parameter is @true or resets
845 it to the normal state.
849 virtual void SetItemBold(const wxTreeItemId
& item
, bool bold
= true);
852 Sets the item client data.
854 Notice that the client data previously associated with the @a item (if
855 any) is @em not freed by this function and so calling this function
856 multiple times for the same item will result in memory leaks unless you
857 delete the old item data pointer yourself.
860 wxPerl provides the following shortcut method:
861 - SetPlData(item, data): sets the Perl data
862 associated with the @c Wx::TreeItemData. It is just the same as
863 tree->GetItemData(item)->SetData(data).
866 virtual void SetItemData(const wxTreeItemId
& item
, wxTreeItemData
* data
);
870 Gives the item the visual feedback for Drag'n'Drop actions, which is
871 useful if something is dragged from the outside onto the tree control
872 (as opposed to a DnD operation within the tree control, which already
873 is implemented internally).
875 virtual void SetItemDropHighlight(const wxTreeItemId
& item
,
876 bool highlight
= true);
879 Sets the item's font. All items in the tree should have the same height
880 to avoid text clipping, so the fonts height should be the same for all
881 of them, although font attributes may vary.
885 virtual void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
);
888 Force appearance of the button next to the item. This is useful to
889 allow the user to expand the items which don't have any children now,
890 but instead adding them only when needed, thus minimizing memory
891 usage and loading time.
893 virtual void SetItemHasChildren(const wxTreeItemId
& item
,
894 bool hasChildren
= true);
897 Sets the specified item's image. See GetItemImage() for the description
898 of the @a which parameter.
900 virtual void SetItemImage(const wxTreeItemId
& item
, int image
,
901 wxTreeItemIcon which
= wxTreeItemIcon_Normal
);
904 Sets the specified item state. The value of @a state may be:
905 - @c wxTREE_ITEMSTATE_NONE: to disable the item state (the state image will
907 - @c wxTREE_ITEMSTATE_NEXT: to set the next item state.
908 - @c wxTREE_ITEMSTATE_PREV: to set the previous item state.
910 void SetItemState(const wxTreeItemId
& item
, int state
);
915 virtual void SetItemText(const wxTreeItemId
& item
, const wxString
& text
);
918 Sets the colour of the item's text.
920 virtual void SetItemTextColour(const wxTreeItemId
& item
,
921 const wxColour
& col
);
924 If @true is passed, specifies that the control will use a quick
925 calculation for the best size, looking only at the first and last items.
926 Otherwise, it will look at all items. The default is @false.
928 @see GetQuickBestSize()
930 void SetQuickBestSize(bool quickBestSize
);
933 Sets the state image list (from which application-defined state images
934 are taken). Image list assigned with this method will @b not be deleted
935 by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it
938 @see AssignStateImageList().
940 virtual void SetStateImageList(wxImageList
* imageList
);
943 Sets the mode flags associated with the display of the tree control. The
944 new mode takes effect immediately.
946 @note Generic only; MSW ignores changes.
948 void SetWindowStyle(long styles
);
951 Sorts the children of the given item using OnCompareItems().
952 You should override that method to change the sort order (the default is
953 ascending case-sensitive alphabetical order).
955 @see wxTreeItemData, OnCompareItems()
957 virtual void SortChildren(const wxTreeItemId
& item
);
960 Toggles the given item between collapsed and expanded states.
962 virtual void Toggle(const wxTreeItemId
& item
);
965 Toggles the given item between selected and unselected states. For
966 multiselection controls only.
968 void ToggleItemSelection(const wxTreeItemId
& item
);
971 Removes the selection from the currently selected item (if any).
973 virtual void Unselect();
976 This function either behaves the same as Unselect() if the control
977 doesn't have @c wxTR_MULTIPLE style, or removes the selection from all
978 items if it does have this style.
980 virtual void UnselectAll();
983 Unselects the given item. This works in multiselection controls only.
985 void UnselectItem(const wxTreeItemId
& item
);
988 Select all the immediate children of the given parent.
990 This function can be used with multiselection controls only.
994 virtual void SelectChildren(const wxTreeItemId
& parent
);
1002 A tree event holds information about events associated with wxTreeCtrl
1005 To process input from a tree control, use these event handler macros to
1006 direct input to member functions that take a wxTreeEvent argument.
1008 @beginEventTable{wxTreeEvent}
1009 @event{EVT_TREE_BEGIN_DRAG(id, func)}
1010 Begin dragging with the left mouse button. If you want to enable
1011 left-dragging you need to intercept this event and explicitly call
1012 wxTreeEvent::Allow(), as it's vetoed by default. Also notice that the
1013 control must have an associated image list (see SetImageList()) to
1014 drag its items under MSW.
1015 @event{EVT_TREE_BEGIN_RDRAG(id, func)}
1016 Begin dragging with the right mouse button. If you want to enable
1017 right-dragging you need to intercept this event and explicitly call
1018 wxTreeEvent::Allow(), as it's vetoed by default.
1019 @event{EVT_TREE_END_DRAG(id, func)}
1020 End dragging with the left or right mouse button.
1021 @event{EVT_TREE_BEGIN_LABEL_EDIT(id, func)}
1022 Begin editing a label. This can be prevented by calling Veto().
1023 @event{EVT_TREE_END_LABEL_EDIT(id, func)}
1024 Finish editing a label. This can be prevented by calling Veto().
1025 @event{EVT_TREE_DELETE_ITEM(id, func)}
1027 @event{EVT_TREE_GET_INFO(id, func)}
1028 Request information from the application.
1029 @event{EVT_TREE_SET_INFO(id, func)}
1030 Information is being supplied.
1031 @event{EVT_TREE_ITEM_ACTIVATED(id, func)}
1032 The item has been activated, i.e. chosen by double clicking it with
1033 mouse or from keyboard.
1034 @event{EVT_TREE_ITEM_COLLAPSED(id, func)}
1035 The item has been collapsed.
1036 @event{EVT_TREE_ITEM_COLLAPSING(id, func)}
1037 The item is being collapsed. This can be prevented by calling Veto().
1038 @event{EVT_TREE_ITEM_EXPANDED(id, func)}
1039 The item has been expanded.
1040 @event{EVT_TREE_ITEM_EXPANDING(id, func)}
1041 The item is being expanded. This can be prevented by calling Veto().
1042 @event{EVT_TREE_ITEM_RIGHT_CLICK(id, func)}
1043 The user has clicked the item with the right mouse button.
1044 @event{EVT_TREE_ITEM_MIDDLE_CLICK(id, func)}
1045 The user has clicked the item with the middle mouse button.
1046 @event{EVT_TREE_SEL_CHANGED(id, func)}
1047 Selection has changed.
1048 @event{EVT_TREE_SEL_CHANGING(id, func)}
1049 Selection is changing. This can be prevented by calling Veto().
1050 @event{EVT_TREE_KEY_DOWN(id, func)}
1051 A key has been pressed.
1052 @event{EVT_TREE_ITEM_GETTOOLTIP(id, func)}
1053 The opportunity to set the item tooltip is being given to the
1054 application (call SetToolTip()). Windows only.
1055 @event{EVT_TREE_ITEM_MENU(id, func)}
1056 The context menu for the selected item has been requested, either by a
1057 right click or by using the menu key.
1058 @event{EVT_TREE_STATE_IMAGE_CLICK(id, func)}
1059 The state image has been clicked.
1067 class wxTreeEvent
: public wxNotifyEvent
1071 Constructor, used by wxWidgets itself only.
1073 wxTreeEvent(wxEventType commandType
, wxTreeCtrl
* tree
,
1074 const wxTreeItemId
& item
= wxTreeItemId());
1077 Returns the item (valid for all events).
1079 wxTreeItemId
GetItem() const;
1082 Returns the key code if the event is a key event. Use GetKeyEvent() to
1083 get the values of the modifier keys for this event (i.e. Shift or Ctrl).
1085 int GetKeyCode() const;
1088 Returns the key event for @c EVT_TREE_KEY_DOWN events.
1090 const wxKeyEvent
& GetKeyEvent() const;
1093 Returns the label if the event is a begin or end edit label event.
1095 const wxString
& GetLabel() const;
1098 Returns the old item index (valid for @c EVT_TREE_ITEM_CHANGING and
1099 @c EVT_TREE_ITEM_CHANGED events).
1101 wxTreeItemId
GetOldItem() const;
1104 Returns the position of the mouse pointer if the event is a drag or
1107 In both cases the position is in client coordinates - i.e. relative to
1108 the wxTreeCtrl window (so that you can pass it directly to e.g.
1109 wxWindow::PopupMenu()).
1111 wxPoint
GetPoint() const;
1114 Returns @true if the label edit was cancelled. This should be called
1115 from within an @c EVT_TREE_END_LABEL_EDIT handler.
1117 bool IsEditCancelled() const;
1120 Set the tooltip for the item (valid for @c EVT_TREE_ITEM_GETTOOLTIP
1121 events). Windows only.
1123 void SetToolTip(const wxString
& tooltip
);
1127 wxEventType wxEVT_TREE_BEGIN_DRAG
;
1128 wxEventType wxEVT_TREE_BEGIN_RDRAG
;
1129 wxEventType wxEVT_TREE_BEGIN_LABEL_EDIT
;
1130 wxEventType wxEVT_TREE_END_LABEL_EDIT
;
1131 wxEventType wxEVT_TREE_DELETE_ITEM
;
1132 wxEventType wxEVT_TREE_GET_INFO
;
1133 wxEventType wxEVT_TREE_SET_INFO
;
1134 wxEventType wxEVT_TREE_ITEM_EXPANDED
;
1135 wxEventType wxEVT_TREE_ITEM_EXPANDING
;
1136 wxEventType wxEVT_TREE_ITEM_COLLAPSED
;
1137 wxEventType wxEVT_TREE_ITEM_COLLAPSING
;
1138 wxEventType wxEVT_TREE_SEL_CHANGED
;
1139 wxEventType wxEVT_TREE_SEL_CHANGING
;
1140 wxEventType wxEVT_TREE_KEY_DOWN
;
1141 wxEventType wxEVT_TREE_ITEM_ACTIVATED
;
1142 wxEventType wxEVT_TREE_ITEM_RIGHT_CLICK
;
1143 wxEventType wxEVT_TREE_ITEM_MIDDLE_CLICK
;
1144 wxEventType wxEVT_TREE_END_DRAG
;
1145 wxEventType wxEVT_TREE_STATE_IMAGE_CLICK
;
1146 wxEventType wxEVT_TREE_ITEM_GETTOOLTIP
;
1147 wxEventType wxEVT_TREE_ITEM_MENU
;