]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/treectrl.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTreeItemData
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
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
18 A similar control with a fully native implemtation for GTK+ and OS X
19 as well is wxDataViewTreeCtrl.
21 To intercept events from a tree control, use the event table macros
22 described in wxTreeEvent.
25 @style{wxTR_EDIT_LABELS}
26 Use this style if you wish the user to be able to edit labels in the
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.
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
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.
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.
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.
63 @beginEventEmissionTable{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)}
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.
116 See also @ref overview_windowstyles.
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
131 @appearance{treectrl.png}
133 @see wxDataViewTreeCtrl, wxTreeEvent, wxTreeItemData, @ref overview_treectrl,
134 wxListBox, wxListCtrl, wxImageList
136 class wxTreeCtrl
: public wxControl
145 Constructor, creating and showing a tree control.
148 Parent window. Must not be @NULL.
150 Window identifier. The value @c wxID_ANY indicates a default value.
153 If ::wxDefaultPosition is specified then a default position is chosen.
156 If ::wxDefaultSize is specified then the window is sized appropriately.
158 Window style. See wxTreeCtrl.
164 @see Create(), wxValidator
166 wxTreeCtrl(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
167 const wxPoint
& pos
= wxDefaultPosition
,
168 const wxSize
& size
= wxDefaultSize
,
169 long style
= wxTR_DEFAULT_STYLE
,
170 const wxValidator
& validator
= wxDefaultValidator
,
171 const wxString
& name
= wxTreeCtrlNameStr
);
175 Destructor, destroying the tree control.
177 virtual ~wxTreeCtrl();
180 Adds the root node to the tree, returning the new item.
182 The @a image and @a selImage parameters are an index within the normal
183 image list specifying the image to use for unselected and selected
184 items, respectively. If @a image -1 and @a selImage is -1, the same
185 image is used for both selected and unselected items.
187 virtual wxTreeItemId
AddRoot(const wxString
& text
, int image
= -1,
189 wxTreeItemData
* data
= NULL
);
192 Appends an item to the end of the branch identified by @a parent, return
195 The @a image and @a selImage parameters are an index within the normal
196 image list specifying the image to use for unselected and selected
197 items, respectively. If @a image -1 and @a selImage is -1, the same
198 image is used for both selected and unselected items.
200 wxTreeItemId
AppendItem(const wxTreeItemId
& parent
,
201 const wxString
& text
,
204 wxTreeItemData
* data
= NULL
);
207 Sets the buttons image list. The button images assigned with this method
208 will be automatically deleted by wxTreeCtrl as appropriate (i.e. it
209 takes ownership of the list).
211 Setting or assigning the button image list enables the display of image
212 buttons. Once enabled, the only way to disable the display of button
213 images is to set the button image list to @NULL.
215 This function is only available in the generic version.
217 @see SetButtonsImageList().
219 void AssignButtonsImageList(wxImageList
* imageList
);
222 Sets the normal image list. The image list assigned with this method
223 will be automatically deleted by wxTreeCtrl as appropriate (i.e. it
224 takes ownership of the list).
228 void AssignImageList(wxImageList
* imageList
);
231 Sets the state image list. Image list assigned with this method will be
232 automatically deleted by wxTreeCtrl as appropriate (i.e. it takes
233 ownership of the list).
235 @see SetStateImageList().
237 void AssignStateImageList(wxImageList
* imageList
);
240 Collapses the given item.
242 virtual void Collapse(const wxTreeItemId
& item
);
245 Collapses the root item.
252 Collapses this item and all of its children, recursively.
254 @see ExpandAllChildren()
256 void CollapseAllChildren(const wxTreeItemId
& item
);
259 Collapses the given item and removes all children.
261 virtual void CollapseAndReset(const wxTreeItemId
& item
);
264 Creates the tree control.
265 See wxTreeCtrl::wxTreeCtrl() for further details.
267 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
268 const wxPoint
& pos
= wxDefaultPosition
,
269 const wxSize
& size
= wxDefaultSize
,
270 long style
= wxTR_DEFAULT_STYLE
,
271 const wxValidator
& validator
= wxDefaultValidator
,
272 const wxString
& name
= wxTreeCtrlNameStr
);
275 Deletes the specified item. A @c EVT_TREE_DELETE_ITEM event will be
278 This function may cause a subsequent call to GetNextChild() to fail.
280 virtual void Delete(const wxTreeItemId
& item
);
283 Deletes all items in the control. Note that this may not generate
284 @c EVT_TREE_DELETE_ITEM events under some Windows versions although
285 normally such event is generated for each removed item.
287 virtual void DeleteAllItems();
290 Deletes all children of the given item (but not the item itself). Note
291 that this will @b not generate any events unlike Delete() method.
293 If you have called SetItemHasChildren(), you may need to call it again
294 since DeleteChildren() does not automatically clear the setting.
296 virtual void DeleteChildren(const wxTreeItemId
& item
);
299 Starts editing the label of the given @a item. This function generates a
300 @c EVT_TREE_BEGIN_LABEL_EDIT event which can be vetoed so that no text
301 control will appear for in-place editing.
303 If the user changed the label (i.e. s/he does not press ESC or leave the
304 text control without changes, a @c EVT_TREE_END_LABEL_EDIT event will be
305 sent which can be vetoed as well.
307 @see EndEditLabel(), wxTreeEvent
309 virtual wxTextCtrl
*EditLabel(const wxTreeItemId
& item
,
310 wxClassInfo
* textCtrlClass
= CLASSINFO(wxTextCtrl
));
313 Ends label editing. If @a cancelEdit is @true, the edit will be
317 This function is currently supported under Windows only.
321 virtual void EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
= false);
324 Scrolls and/or expands items to ensure that the given item is visible.
326 virtual void EnsureVisible(const wxTreeItemId
& item
);
329 Expands the given item.
331 virtual void Expand(const wxTreeItemId
& item
);
334 Expands all items in the tree.
339 Expands the given item and all its children recursively.
341 void ExpandAllChildren(const wxTreeItemId
& item
);
344 Retrieves the rectangle bounding the @a item. If @a textOnly is @true,
345 only the rectangle around the item's label will be returned, otherwise
346 the item's image is also taken into account.
348 The return value is @true if the rectangle was successfully retrieved or
349 @c @false if it was not (in this case @a rect is not changed) -- for
350 example, if the item is currently invisible.
352 Notice that the rectangle coordinates are logical, not physical ones.
353 So, for example, the x coordinate may be negative if the tree has a
354 horizontal scrollbar and its position is not 0.
357 The wxPython version of this method requires only the @a item and @a
358 textOnly parameters. The return value is either a wxRect object or @c
362 virtual bool GetBoundingRect(const wxTreeItemId
& item
, wxRect
& rect
,
363 bool textOnly
= false) const;
366 Returns the buttons image list (from which application-defined button
369 This function is only available in the generic version.
371 wxImageList
* GetButtonsImageList() const;
374 Returns the number of items in the branch. If @a recursively is @true,
375 returns the total number of descendants, otherwise only one level of
378 virtual size_t GetChildrenCount(const wxTreeItemId
& item
,
379 bool recursively
= true) const;
382 Returns the number of items in the control.
384 virtual unsigned int GetCount() const;
387 Returns the edit control being currently used to edit a label. Returns
388 @NULL if no label is being edited.
390 @note This is currently only implemented for wxMSW.
392 virtual wxTextCtrl
* GetEditControl() const;
395 Returns the first child; call GetNextChild() for the next child.
397 For this enumeration function you must pass in a 'cookie' parameter
398 which is opaque for the application but is necessary for the library to
399 make these functions reentrant (i.e. allow more than one enumeration on
400 one and the same object simultaneously). The cookie passed to
401 GetFirstChild() and GetNextChild() should be the same variable.
403 Returns an invalid tree item (i.e. wxTreeItemId::IsOk() returns @false)
404 if there are no further children.
407 In wxPython the returned wxTreeItemId and the new cookie value are both
408 returned as a tuple containing the two values.
411 @see GetNextChild(), GetNextSibling()
413 virtual wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
,
414 wxTreeItemIdValue
& cookie
) const;
417 Returns the first visible item.
419 virtual wxTreeItemId
GetFirstVisibleItem() const;
422 Returns the item last clicked or otherwise selected.
423 Unlike GetSelection(), it can be used whether or not
424 the control has the @c wxTR_MULTIPLE style.
428 virtual wxTreeItemId
GetFocusedItem() const;
431 Returns the normal image list.
433 wxImageList
* GetImageList() const;
436 Returns the current tree control indentation.
438 virtual unsigned int GetIndent() const;
441 Returns the background colour of the item.
443 virtual wxColour
GetItemBackgroundColour(const wxTreeItemId
& item
) const;
446 Returns the tree item data associated with the item.
451 wxPython provides the following shortcut method:
452 @li GetPyData(item): Returns the Python Object associated with the
453 wxTreeItemData for the given item Id.
456 virtual wxTreeItemData
* GetItemData(const wxTreeItemId
& item
) const;
459 Returns the font of the item label.
461 virtual wxFont
GetItemFont(const wxTreeItemId
& item
) const;
464 Gets the specified item image. The value of @a which may be:
465 - ::wxTreeItemIcon_Normal: to get the normal item image.
466 - ::wxTreeItemIcon_Selected: to get the selected item image (i.e. the
467 image which is shown when the item is currently selected).
468 - ::wxTreeItemIcon_Expanded: to get the expanded image (this only makes
469 sense for items which have children - then this image is shown when
470 the item is expanded and the normal image is shown when it is
472 - ::wxTreeItemIcon_SelectedExpanded: to get the selected expanded image
473 (which is shown when an expanded item is currently selected).
475 virtual int GetItemImage(const wxTreeItemId
& item
,
476 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const;
479 Returns the item's parent.
481 virtual wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
484 Gets the specified item state.
486 int GetItemState(const wxTreeItemId
& item
) const;
489 Returns the item label.
491 virtual wxString
GetItemText(const wxTreeItemId
& item
) const;
494 Returns the colour of the item label.
496 virtual wxColour
GetItemTextColour(const wxTreeItemId
& item
) const;
499 Returns the last child of the item (or an invalid tree item if this item
502 @see GetFirstChild(), GetNextSibling(), GetLastChild()
504 virtual wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
507 Returns the next child; call GetFirstChild() for the first child. For
508 this enumeration function you must pass in a 'cookie' parameter which is
509 opaque for the application but is necessary for the library to make
510 these functions reentrant (i.e. allow more than one enumeration on one
511 and the same object simultaneously). The cookie passed to
512 GetFirstChild() and GetNextChild() should be the same.
514 Returns an invalid tree item if there are no further children.
517 In wxPython the returned wxTreeItemId and the new cookie value are both
518 returned as a tuple containing the two values.
523 virtual wxTreeItemId
GetNextChild(const wxTreeItemId
& item
,
524 wxTreeItemIdValue
& cookie
) const;
527 Returns the next sibling of the specified item; call GetPrevSibling()
528 for the previous sibling.
530 Returns an invalid tree item if there are no further siblings.
532 @see GetPrevSibling()
534 virtual wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
537 Returns the next visible item or an invalid item if this item is the
540 @note The @a item itself must be visible.
542 virtual wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
545 Returns the previous sibling of the specified item; call
546 GetNextSibling() for the next sibling.
548 Returns an invalid tree item if there are no further children.
550 @see GetNextSibling()
552 virtual wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
555 Returns the previous visible item or an invalid item if this item is the
558 @note The @a item itself must be visible.
560 virtual wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
563 Returns @true if the control will use a quick calculation for the best
564 size, looking only at the first and last items. The default is @false.
566 @see SetQuickBestSize()
568 bool GetQuickBestSize() const;
571 Returns the root item for the tree control.
573 virtual wxTreeItemId
GetRootItem() const;
576 Returns the selection, or an invalid item if there is no selection. This
577 function only works with the controls without @c wxTR_MULTIPLE style,
578 use GetSelections() for the controls which do have this style
579 or, if a single item is wanted, use GetFocusedItem().
581 virtual wxTreeItemId
GetSelection() const;
584 Fills the array of tree items passed in with the currently selected
585 items. This function can be called only if the control has the @c
588 Returns the number of selected items.
591 The wxPython version of this method accepts no parameters and returns a
592 Python list of @ref wxTreeItemId "wxTreeItemId"s.
595 virtual size_t GetSelections(wxArrayTreeItemIds
& selection
) const;
598 Returns the state image list (from which application-defined state
601 wxImageList
* GetStateImageList() const;
604 Calculates which (if any) item is under the given @a point, returning
605 the tree item id at this point plus extra information @a flags. @a flags
606 is a bitlist of the following:
608 - @c wxTREE_HITTEST_ABOVE: Above the client area.
609 - @c wxTREE_HITTEST_BELOW: Below the client area.
610 - @c wxTREE_HITTEST_NOWHERE: In the client area but below the last item.
611 - @c wxTREE_HITTEST_ONITEMBUTTON: On the button associated with an item.
612 - @c wxTREE_HITTEST_ONITEMICON: On the bitmap associated with an item.
613 - @c wxTREE_HITTEST_ONITEMINDENT: In the indentation associated with an item.
614 - @c wxTREE_HITTEST_ONITEMLABEL: On the label (string) associated with an item.
615 - @c wxTREE_HITTEST_ONITEMRIGHT: In the area to the right of an item.
616 - @c wxTREE_HITTEST_ONITEMSTATEICON: On the state icon for a tree view
617 item that is in a user-defined state.
618 - @c wxTREE_HITTEST_TOLEFT: To the right of the client area.
619 - @c wxTREE_HITTEST_TORIGHT: To the left of the client area.
622 In wxPython both the wxTreeItemId and the flags are returned as a tuple.
625 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
) const;
629 Inserts an item after a given one (@a previous).
631 The @a image and @a selImage parameters are an index within the normal
632 image list specifying the image to use for unselected and selected
633 items, respectively. If @a image -1 and @a selImage is -1, the same
634 image is used for both selected and unselected items.
636 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
637 const wxTreeItemId
& previous
,
638 const wxString
& text
,
641 wxTreeItemData
* data
= NULL
);
644 Inserts an item before one identified
645 by its position (@a before). @a before must be less than the number of
648 The @a image and @a selImage parameters are an index within the normal
649 image list specifying the image to use for unselected and selected
650 items, respectively. If @a image -1 and @a selImage is -1, the same
651 image is used for both selected and unselected items.
654 In wxPython, this form of this method is called @c InsertItemBefore().
657 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
659 const wxString
& text
,
662 wxTreeItemData
* data
= NULL
);
665 Returns @true if the given item is in bold state.
669 virtual bool IsBold(const wxTreeItemId
& item
) const;
672 Returns @true if the control is empty (i.e. has no items, even no root
675 bool IsEmpty() const;
678 Returns @true if the item is expanded (only makes sense if it has
681 virtual bool IsExpanded(const wxTreeItemId
& item
) const;
684 Returns @true if the item is selected.
686 virtual bool IsSelected(const wxTreeItemId
& item
) const;
689 Returns @true if the item is visible on the screen.
691 virtual bool IsVisible(const wxTreeItemId
& item
) const;
694 Returns @true if the item has children.
696 virtual bool ItemHasChildren(const wxTreeItemId
& item
) const;
699 Override this function in the derived class to change the sort order of
700 the items in the tree control. The function should return a negative,
701 zero or positive value if the first item is less than, equal to or
702 greater than the second one.
704 Please note that you @b must use wxRTTI macros DECLARE_DYNAMIC_CLASS()
705 and IMPLEMENT_DYNAMIC_CLASS() if you override this function because
706 otherwise the base class considers that it is not overridden and uses
707 the default comparison, i.e. sorts the items alphabetically, which
708 allows it optimize away the calls to the virtual function completely.
712 virtual int OnCompareItems(const wxTreeItemId
& item1
,
713 const wxTreeItemId
& item2
);
716 Appends an item as the first child of @a parent, return a new item id.
718 The @a image and @a selImage parameters are an index within the normal
719 image list specifying the image to use for unselected and selected
720 items, respectively. If @a image -1 and @a selImage is -1, the same
721 image is used for both selected and unselected items.
723 wxTreeItemId
PrependItem(const wxTreeItemId
& parent
,
724 const wxString
& text
,
727 wxTreeItemData
* data
= NULL
);
730 Scrolls the specified item into view.
732 virtual void ScrollTo(const wxTreeItemId
& item
);
735 Selects the given item. In multiple selection controls, can be also used
736 to deselect a currently selected item if the value of @a select is
739 virtual void SelectItem(const wxTreeItemId
& item
, bool select
= true);
742 Sets the buttons image list (from which application-defined button
745 The button images assigned with this method will @b not be deleted by
746 @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it yourself.
747 Setting or assigning the button image list enables the display of image
748 buttons. Once enabled, the only way to disable the display of button
749 images is to set the button image list to @NULL.
751 @note This function is only available in the generic version.
753 @see AssignButtonsImageList().
755 void SetButtonsImageList(wxImageList
* imageList
);
758 Sets the normal image list. The image list assigned with this method
759 will @b not be deleted by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you
760 must delete it yourself.
762 @see AssignImageList().
764 virtual void SetImageList(wxImageList
* imageList
);
767 Sets the indentation for the tree control.
769 virtual void SetIndent(unsigned int indent
);
772 Sets the colour of the item's background.
774 virtual void SetItemBackgroundColour(const wxTreeItemId
& item
,
775 const wxColour
& col
);
778 Makes item appear in bold font if @a bold parameter is @true or resets
779 it to the normal state.
783 virtual void SetItemBold(const wxTreeItemId
& item
, bool bold
= true);
786 Sets the item client data.
788 Notice that the client data previously associated with the @a item (if
789 any) is @em not freed by this function and so calling this function
790 multiple times for the same item will result in memory leaks unless you
791 delete the old item data pointer yourself.
794 - @b SetPyData( @a item, @c obj): Associate the given Python Object with
795 the wxTreeItemData for the given item Id.
799 virtual void SetItemData(const wxTreeItemId
& item
, wxTreeItemData
* data
);
803 Gives the item the visual feedback for Drag'n'Drop actions, which is
804 useful if something is dragged from the outside onto the tree control
805 (as opposed to a DnD operation within the tree control, which already
806 is implemented internally).
808 virtual void SetItemDropHighlight(const wxTreeItemId
& item
,
809 bool highlight
= true);
812 Sets the item's font. All items in the tree should have the same height
813 to avoid text clipping, so the fonts height should be the same for all
814 of them, although font attributes may vary.
818 virtual void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
);
821 Force appearance of the button next to the item. This is useful to
822 allow the user to expand the items which don't have any children now,
823 but instead adding them only when needed, thus minimizing memory
824 usage and loading time.
826 virtual void SetItemHasChildren(const wxTreeItemId
& item
,
827 bool hasChildren
= true);
830 Sets the specified item's image. See GetItemImage() for the description
831 of the @a which parameter.
833 virtual void SetItemImage(const wxTreeItemId
& item
, int image
,
834 wxTreeItemIcon which
= wxTreeItemIcon_Normal
);
837 Sets the specified item state. The value of @a state may be:
838 - @c wxTREE_ITEMSTATE_NONE: to disable the item state (the state image will
840 - @c wxTREE_ITEMSTATE_NEXT: to set the next item state.
841 - @c wxTREE_ITEMSTATE_PREV: to set the previous item state.
843 void SetItemState(const wxTreeItemId
& item
, int state
);
848 virtual void SetItemText(const wxTreeItemId
& item
, const wxString
& text
);
851 Sets the colour of the item's text.
853 virtual void SetItemTextColour(const wxTreeItemId
& item
,
854 const wxColour
& col
);
857 If @true is passed, specifies that the control will use a quick
858 calculation for the best size, looking only at the first and last items.
859 Otherwise, it will look at all items. The default is @false.
861 @see GetQuickBestSize()
863 void SetQuickBestSize(bool quickBestSize
);
866 Sets the state image list (from which application-defined state images
867 are taken). Image list assigned with this method will @b not be deleted
868 by @ref wxTreeCtrl "wxTreeCtrl"'s destructor, you must delete it
871 @see AssignStateImageList().
873 virtual void SetStateImageList(wxImageList
* imageList
);
876 Sets the mode flags associated with the display of the tree control. The
877 new mode takes effect immediately.
879 @note Generic only; MSW ignores changes.
881 void SetWindowStyle(long styles
);
884 Sorts the children of the given item using OnCompareItems().
885 You should override that method to change the sort order (the default is
886 ascending case-sensitive alphabetical order).
888 @see wxTreeItemData, OnCompareItems()
890 virtual void SortChildren(const wxTreeItemId
& item
);
893 Toggles the given item between collapsed and expanded states.
895 virtual void Toggle(const wxTreeItemId
& item
);
898 Toggles the given item between selected and unselected states. For
899 multiselection controls only.
901 void ToggleItemSelection(const wxTreeItemId
& item
);
904 Removes the selection from the currently selected item (if any).
906 virtual void Unselect();
909 This function either behaves the same as Unselect() if the control
910 doesn't have @c wxTR_MULTIPLE style, or removes the selection from all
911 items if it does have this style.
913 virtual void UnselectAll();
916 Unselects the given item. This works in multiselection controls only.
918 void UnselectItem(const wxTreeItemId
& item
);
926 A tree event holds information about events associated with wxTreeCtrl
929 To process input from a tree control, use these event handler macros to
930 direct input to member functions that take a wxTreeEvent argument.
932 @beginEventTable{wxTreeEvent}
933 @event{EVT_TREE_BEGIN_DRAG(id, func)}
934 Begin dragging with the left mouse button. If you want to enable
935 left-dragging you need to intercept this event and explicitely call
936 wxTreeEvent::Allow(), as it's vetoed by default. Also notice that the
937 control must have an associated image list (see SetImageList()) to
938 drag its items under MSW.
939 @event{EVT_TREE_BEGIN_RDRAG(id, func)}
940 Begin dragging with the right mouse button. If you want to enable
941 right-dragging you need to intercept this event and explicitely call
942 wxTreeEvent::Allow(), as it's vetoed by default.
943 @event{EVT_TREE_END_DRAG(id, func)}
944 End dragging with the left or right mouse button.
945 @event{EVT_TREE_BEGIN_LABEL_EDIT(id, func)}
946 Begin editing a label. This can be prevented by calling Veto().
947 @event{EVT_TREE_END_LABEL_EDIT(id, func)}
948 Finish editing a label. This can be prevented by calling Veto().
949 @event{EVT_TREE_DELETE_ITEM(id, func)}
951 @event{EVT_TREE_GET_INFO(id, func)}
952 Request information from the application.
953 @event{EVT_TREE_SET_INFO(id, func)}
954 Information is being supplied.
955 @event{EVT_TREE_ITEM_ACTIVATED(id, func)}
956 The item has been activated, i.e. chosen by double clicking it with
957 mouse or from keyboard.
958 @event{EVT_TREE_ITEM_COLLAPSED(id, func)}
959 The item has been collapsed.
960 @event{EVT_TREE_ITEM_COLLAPSING(id, func)}
961 The item is being collapsed. This can be prevented by calling Veto().
962 @event{EVT_TREE_ITEM_EXPANDED(id, func)}
963 The item has been expanded.
964 @event{EVT_TREE_ITEM_EXPANDING(id, func)}
965 The item is being expanded. This can be prevented by calling Veto().
966 @event{EVT_TREE_ITEM_RIGHT_CLICK(id, func)}
967 The user has clicked the item with the right mouse button.
968 @event{EVT_TREE_ITEM_MIDDLE_CLICK(id, func)}
969 The user has clicked the item with the middle mouse button.
970 @event{EVT_TREE_SEL_CHANGED(id, func)}
971 Selection has changed.
972 @event{EVT_TREE_SEL_CHANGING(id, func)}
973 Selection is changing. This can be prevented by calling Veto().
974 @event{EVT_TREE_KEY_DOWN(id, func)}
975 A key has been pressed.
976 @event{EVT_TREE_ITEM_GETTOOLTIP(id, func)}
977 The opportunity to set the item tooltip is being given to the
978 application (call SetToolTip()). Windows only.
979 @event{EVT_TREE_ITEM_MENU(id, func)}
980 The context menu for the selected item has been requested, either by a
981 right click or by using the menu key.
982 @event{EVT_TREE_STATE_IMAGE_CLICK(id, func)}
983 The state image has been clicked.
991 class wxTreeEvent
: public wxNotifyEvent
995 Constructor, used by wxWidgets itself only.
997 wxTreeEvent(wxEventType commandType
, wxTreeCtrl
* tree
,
998 const wxTreeItemId
& item
= wxTreeItemId());
1001 Returns the item (valid for all events).
1003 wxTreeItemId
GetItem() const;
1006 Returns the key code if the event is a key event. Use GetKeyEvent() to
1007 get the values of the modifier keys for this event (i.e. Shift or Ctrl).
1009 int GetKeyCode() const;
1012 Returns the key event for @c EVT_TREE_KEY_DOWN events.
1014 const wxKeyEvent
& GetKeyEvent() const;
1017 Returns the label if the event is a begin or end edit label event.
1019 const wxString
& GetLabel() const;
1022 Returns the old item index (valid for @c EVT_TREE_ITEM_CHANGING and
1023 @c EVT_TREE_ITEM_CHANGED events).
1025 wxTreeItemId
GetOldItem() const;
1028 Returns the position of the mouse pointer if the event is a drag or
1031 In both cases the position is in client coordinates - i.e. relative to
1032 the wxTreeCtrl window (so that you can pass it directly to e.g.
1033 wxWindow::PopupMenu()).
1035 wxPoint
GetPoint() const;
1038 Returns @true if the label edit was cancelled. This should be called
1039 from within an @c EVT_TREE_END_LABEL_EDIT handler.
1041 bool IsEditCancelled() const;
1044 Set the tooltip for the item (valid for @c EVT_TREE_ITEM_GETTOOLTIP
1045 events). Windows only.
1047 void SetToolTip(const wxString
& tooltip
);