.\" This is a wxWidgets manpage page generated from the XML docs .TH wxTreeCtrl 3wx 2005-02-15 "wxWidgets" "wxWidgets class documentation" .SH NAME wxTreeCtrl \- Tree (hierarchy) control .SH DESCRIPTION A tree control presents information as a hierarchy, with items that may be expanded to show further items. Items in a tree control are referenced by wxTreeItemId handles, which may be tested for validity by calling wxTreeItemId::IsOk. To intercept events from a tree control, use the event table macros described in wxTreeEvent . .SH NOTE wxTreeCtrl class uses the standard common treeview control under Win32 implemented in the system library comctl32.dll . Some versions of this library are known to have bugs with handling the tree control colours: the usual symptom is that the expanded items leave black (or otherwise incorrectly coloured) background behind them, especially for the controls using non default background colour. The recommended solution is to upgrade the comctl32.dll to a newer version: see http://www.microsoft.com/downloads/release.asp?ReleaseID=11916 . .SH "PARENTS" wxControl wxWindow wxEvtHandler wxObject .SH "INCLUDE FILES" wx/treectrl.h .SH MEMBERS .SS wxTreeCtrl () Default constructor. .SS wxTreeCtrl (wxWindow* parentwxWindowID idconst wxPoint& pos = wxDefaultPositionconst wxSize& size = wxDefaultSizelong style = wxTR_HAS_BUTTONSconst wxValidator& validator = wxDefaultValidatorconst wxString& name = ``listCtrl") .SS void ~wxTreeCtrl () Destructor, destroying the list control. .SS wxTreeItemId AddRoot (const wxString& textint image = -1int selImage = -1wxTreeItemData* data = NULL) Adds the root node to the tree, returning the new item. The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image > -1 and selImage is -1, the same image is used for both selected and unselected items. .SS wxTreeItemId AppendItem (const wxTreeItemId& parentconst wxString& textint image = -1int selImage = -1wxTreeItemData* data = NULL) Appends an item to the end of the branch identified by parent , return a new item id. The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image > -1 and selImage is -1, the same image is used for both selected and unselected items. .SS void AssignButtonsImageList (wxImageList* imageList) Sets the buttons image list. The button images assigned with this method will be automatically deleted by wxTreeCtrl as appropriate (i.e. it takes ownership of the list). Setting or assigning the button image list enables the display of image buttons. Once enabled, the only way to disable the display of button images is to set the button image list to NULL . This function is only available in the generic version. See also SetButtonsImageList . .SS void AssignImageList (wxImageList* imageList) Sets the normal image list. Image list assigned with this method will be automatically deleted by wxTreeCtrl as appropriate (i.e. it takes ownership of the list). See also SetImageList . .SS void AssignStateImageList (wxImageList* imageList) Sets the state image list. Image list assigned with this method will be automatically deleted by wxTreeCtrl as appropriate (i.e. it takes ownership of the list). See also SetStateImageList . .SS void Collapse (const wxTreeItemId& item) Collapses the given item. .SS void CollapseAndReset (const wxTreeItemId& item) Collapses the given item and removes all children. .SS bool wxTreeCtrl (wxWindow* parentwxWindowID idconst wxPoint& pos = wxDefaultPositionconst wxSize& size = wxDefaultSizelong style = wxTR_HAS_BUTTONSconst wxValidator& validator = wxDefaultValidatorconst wxString& name = ``listCtrl") Creates the tree control. See wxTreeCtrl::wxTreeCtrl for further details. .SS void Delete (const wxTreeItemId& item) Deletes the specified item. A EVT_TREE_DELETE_ITEM event will be generated. This function may cause a subsequent call to GetNextChild to fail. .SS void DeleteAllItems () Deletes all the items in the control. Note that this may not generate EVT_TREE_DELETE_ITEM events under some Windows versions although normally such event is generated for each removed item. .SS void DeleteChildren (const wxTreeItemId& item) Deletes all children of the given item (but not the item itself). Note that this will not generate any events unlike Delete method. If you have called wxTreeCtrl::SetItemHasChildren , you may need to call it again since DeleteChildren does not automatically clear the setting. .SS void EditLabel (const wxTreeItemId& item) Starts editing the label of the given item. This function generates a EVT_TREE_BEGIN_LABEL_EDIT event which can be vetoed so that no text control will appear for in-place editing. If the user changed the label (i.e. s/he does not press ESC or leave the text control without changes, a EVT_TREE_END_LABEL_EDIT event will be sent which can be vetoed as well. .SS void EndEditLabel (bool cancelEdit) Ends label editing. If cancelEdit is true , the edit will be cancelled. This function is currently supported under Windows only. .SS void EnsureVisible (const wxTreeItemId& item) Scrolls and/or expands items to ensure that the given item is visible. .SS void Expand (const wxTreeItemId& item) Expands the given item. .SS bool GetBoundingRect (const wxTreeItemId& itemwxRect& rectbool textOnly = false) Retrieves the rectangle bounding the item . If textOnly is true , only the rectangle around the item's label will be returned, otherwise the item's image is also taken into account. The return value is true if the rectangle was successfully retrieved or false if it was not (in this case rect is not changed) - for example, if the item is currently invisible. .SS wxImageList* GetButtonsImageList () Returns the buttons image list (from which application-defined button images are taken). This function is only available in the generic version. .SS size_t GetChildrenCount (const wxTreeItemId& itembool recursively = true) Returns the number of items in the branch. If recursively is true , returns the total number of descendants, otherwise only one level of children is counted. .SS int GetCount () Returns the number of items in the control. .SS wxTextCtrl * GetEditControl () Returns the edit control being currently used to edit a label. Returns NULL if no label is being edited. NB: It is currently only implemented for wxMSW. .SS wxTreeItemId GetFirstChild (const wxTreeItemId& itemwxTreeItemIdValue & cookie) Returns the first child; call wxTreeCtrl::GetNextChild for the next child. For this enumeration function you must pass in a `cookie' parameter which is opaque for the application but is necessary for the library to make these functions reentrant (i.e. allow more than one enumeration on one and the same object simultaneously). The cookie passed to GetFirstChild and GetNextChild should be the same variable. Returns an invalid tree item (i.e. IsOk() returns false ) if there are no further children. .SS wxTreeItemId GetFirstVisibleItem () Returns the first visible item. .SS wxImageList* GetImageList () Returns the normal image list. .SS int GetIndent () Returns the current tree control indentation. .SS wxColour GetItemBackgroundColour (const wxTreeItemId& item) Returns the background colour of the item. .SS wxTreeItemData* GetItemData (const wxTreeItemId& item) Returns the tree item data associated with the item. .SS wxFont GetItemFont (const wxTreeItemId& item) Returns the font of the item label. .SS int GetItemImage (const wxTreeItemId& itemwxTreeItemIcon which = wxTreeItemIcon_Normal) Gets the specified item image. The value of which may be: {wxTreeItemIcon_Normal} to get the normal item image {wxTreeItemIcon_Selected} to get the selected item image (i.e. the image which is shown when the item is currently selected) {wxTreeItemIcon_Expanded} to get the expanded image (this only makes sense for items which have children - then this image is shown when the item is expanded and the normal image is shown when it is collapsed) {wxTreeItemIcon_SelectedExpanded} to get the selected expanded image (which is shown when an expanded item is currently selected) .SS wxString GetItemText (const wxTreeItemId& item) Returns the item label. .SS wxColour GetItemTextColour (const wxTreeItemId& item) Returns the colour of the item label. .SS wxTreeItemId GetLastChild (const wxTreeItemId& item) Returns the last child of the item (or an invalid tree item if this item has no children). .SS wxTreeItemId GetNextChild (const wxTreeItemId& itemwxTreeItemIdValue & cookie) Returns the next child; call wxTreeCtrl::GetFirstChild for the first child. For this enumeration function you must pass in a `cookie' parameter which is opaque for the application but is necessary for the library to make these functions reentrant (i.e. allow more than one enumeration on one and the same object simultaneously). The cookie passed to GetFirstChild and GetNextChild should be the same. Returns an invalid tree item if there are no further children. .SS wxTreeItemId GetNextSibling (const wxTreeItemId& item) Returns the next sibling of the specified item; call wxTreeCtrl::GetPrevSibling for the previous sibling. Returns an invalid tree item if there are no further siblings. .SS wxTreeItemId GetNextVisible (const wxTreeItemId& item) Returns the next visible item. .SS wxTreeItemId GetItemParent (const wxTreeItemId& item) Returns the item's parent. .SS wxTreeItemId GetParent (const wxTreeItemId& item) NOTE: This function is deprecated and will only work if WXWIN_COMPATIBILITY_2_2 is defined. Use wxTreeCtrl::GetItemParent instead. Returns the item's parent. .SS wxTreeItemId GetPrevSibling (const wxTreeItemId& item) Returns the previous sibling of the specified item; call wxTreeCtrl::GetNextSibling for the next sibling. Returns an invalid tree item if there are no further children. .SS wxTreeItemId GetPrevVisible (const wxTreeItemId& item) Returns the previous visible item. .SS wxTreeItemId GetRootItem () Returns the root item for the tree control. .SS int GetItemSelectedImage (const wxTreeItemId& item) Gets the selected item image (this function is obsolete, use GetItemImage(item, wxTreeItemIcon_Selected ) instead). .SS wxTreeItemId GetSelection () Returns the selection, or an invalid item if there is no selection. This function only works with the controls without wxTR_MULTIPLE style, use GetSelections for the controls which do have this style. .SS size_t GetSelections (wxArrayTreeItemIds& selection) Fills the array of tree items passed in with the currently selected items. This function can be called only if the control has the wxTR_MULTIPLE style. Returns the number of selected items. .SS wxImageList* GetStateImageList () Returns the state image list (from which application-defined state images are taken). .SS wxTreeItemId HitTest (const wxPoint& pointint& flags) Calculates which (if any) item is under the given point, returning the tree item id at this point plus extra information flags . flags is a bitlist of the following: wxTREE_HITTEST_ABOVE Above the client area. wxTREE_HITTEST_BELOW Below the client area. wxTREE_HITTEST_NOWHERE In the client area but below the last item. wxTREE_HITTEST_ONITEMBUTTON On the button associated with an item. wxTREE_HITTEST_ONITEMICON On the bitmap associated with an item. wxTREE_HITTEST_ONITEMINDENT In the indentation associated with an item. wxTREE_HITTEST_ONITEMLABEL On the label (string) associated with an item. wxTREE_HITTEST_ONITEMRIGHT In the area to the right of an item. wxTREE_HITTEST_ONITEMSTATEICON On the state icon for a tree view item that is in a user-defined state. wxTREE_HITTEST_TOLEFT To the right of the client area. wxTREE_HITTEST_TORIGHT To the left of the client area. .SS wxTreeItemId InsertItem (const wxTreeItemId& parentconst wxTreeItemId& previousconst wxString& textint image = -1int selImage = -1wxTreeItemData* data = NULL) .SS wxTreeItemId InsertItem (const wxTreeItemId& parentsize_t beforeconst wxString& textint image = -1int selImage = -1wxTreeItemData* data = NULL) Inserts an item after a given one ( previous ) or before one identified by its position ( before ). before must be less than the number of children. The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image > -1 and selImage is -1, the same image is used for both selected and unselected items. .SS bool IsBold (const wxTreeItemId& item) Returns true if the given item is in bold state. See also SetItemBold .SS bool IsExpanded (const wxTreeItemId& item) Returns true if the item is expanded (only makes sense if it has children). .SS bool IsSelected (const wxTreeItemId& item) Returns true if the item is selected. .SS bool IsVisible (const wxTreeItemId& item) Returns true if the item is visible (it might be outside the view, or not expanded). .SS bool ItemHasChildren (const wxTreeItemId& item) Returns true if the item has children. .SS int OnCompareItems (const wxTreeItemId& item1const wxTreeItemId& item2) Override this function in the derived class to change the sort order of the items in the tree control. The function should return a negative, zero or positive value if the first item is less than, equal to or greater than the second one. The base class version compares items alphabetically. See also SortChildren .SS wxTreeItemId PrependItem (const wxTreeItemId& parentconst wxString& textint image = -1int selImage = -1wxTreeItemData* data = NULL) Appends an item as the first child of parent , return a new item id. The image and selImage parameters are an index within the normal image list specifying the image to use for unselected and selected items, respectively. If image > -1 and selImage is -1, the same image is used for both selected and unselected items. .SS void ScrollTo (const wxTreeItemId& item) Scrolls the specified item into view. .SS bool SelectItem (const wxTreeItemId& itembool select = true) Selects the given item. In multiple selection controls, can be also used to deselect a currently selected item if the value of select is false. .SS void SetButtonsImageList (wxImageList* imageList) Sets the buttons image list (from which application-defined button images are taken). The button images assigned with this method will not be deleted by wxTreeCtrl's destructor, you must delete it yourself. Setting or assigning the button image list enables the display of image buttons. Once enabled, the only way to disable the display of button images is to set the button image list to NULL . This function is only available in the generic version. See also AssignButtonsImageList . .SS void SetIndent (int indent) Sets the indentation for the tree control. .SS void SetImageList (wxImageList* imageList) Sets the normal image list. Image list assigned with this method will not be deleted by wxTreeCtrl's destructor, you must delete it yourself. See also AssignImageList . .SS void SetItemBackgroundColour (const wxTreeItemId& itemconst wxColour& col) Sets the colour of the item's background. .SS void SetItemBold (const wxTreeItemId& itembool bold = true) Makes item appear in bold font if bold parameter is true or resets it to the normal state. See also IsBold .SS void SetItemData (const wxTreeItemId& itemwxTreeItemData* data) Sets the item client data. .SS void SetItemDropHighlight (const wxTreeItemId& itemboolhighlight = true) Gives the item the visual feedback for Drag'n'Drop actions, which is useful if something is dragged from the outside onto the tree control (as opposed to a DnD operation within the tree control, which already is implemented internally). .SS void SetItemFont (const wxTreeItemId& itemconst wxFont& font) Sets the item's font. All items in the tree should have the same height to avoid text clipping, so the fonts height should be the same for all of them, although font attributes may vary. .SS void SetItemHasChildren (const wxTreeItemId& itembool hasChildren = true) Force appearance of the button next to the item. This is useful to allow the user to expand the items which don't have any children now, but instead adding them only when needed, thus minimizing memory usage and loading time. .SS void SetItemImage (const wxTreeItemId& itemint imagewxTreeItemIcon which = wxTreeItemIcon_Normal) Sets the specified item image. See GetItemImage for the description of the which parameter. .SS void SetItemSelectedImage (const wxTreeItemId& itemint selImage) Sets the selected item image (this function is obsolete, use SetItemImage(item, wxTreeItemIcon_Selected ) instead). .SS void SetItemText (const wxTreeItemId& itemconst wxString& text) Sets the item label. .SS void SetItemTextColour (const wxTreeItemId& itemconst wxColour& col) Sets the colour of the item's text. .SS void SetStateImageList (wxImageList* imageList) Sets the state image list (from which application-defined state images are taken). Image list assigned with this method will not be deleted by wxTreeCtrl's destructor, you must delete it yourself. See also AssignStateImageList . .SS void SetWindowStyle (longstyles) Sets the mode flags associated with the display of the tree control. The new mode takes effect immediately. (Generic only; MSW ignores changes.) .SS void SortChildren (const wxTreeItemId& item) .SS void Toggle (const wxTreeItemId& item) Toggles the given item between collapsed and expanded states. .SS void ToggleItemSelection (const wxTreeItemId& item) Toggles the given item between selected and unselected states. For multiselection controls only. .SS void Unselect () Removes the selection from the currently selected item (if any). .SS void UnselectAll () This function either behaves the same as Unselect if the control doesn't have wxTR_MULTIPLE style, or removes the selection from all items if it does have this style. .SS void UnselectItem (const wxTreeItemId& item) Unselects the given item. This works in multiselection controls only. .SH "WINDOW STYLES" .SS wxTR_EDIT_LABELS wxTR_EDIT_LABELS .SS wxTR_NO_BUTTONS wxTR_NO_BUTTONS .SS wxTR_HAS_BUTTONS wxTR_HAS_BUTTONS .SS wxTR_NO_LINES wxTR_NO_LINES .SS wxTR_FULL_ROW_HIGHLIGHT wxTR_FULL_ROW_HIGHLIGHT .SS wxTR_LINES_AT_ROOT wxTR_LINES_AT_ROOT .SS wxTR_HIDE_ROOT wxTR_HIDE_ROOT .SS wxTR_ROW_LINES wxTR_ROW_LINES .SS wxTR_HAS_VARIABLE_ROW_HEIGHT wxTR_HAS_VARIABLE_ROW_HEIGHT .SS wxTR_SINGLE wxTR_SINGLE .SS wxTR_MULTIPLE wxTR_MULTIPLE .SS wxTR_EXTENDED wxTR_EXTENDED .SS wxTR_DEFAULT_STYLE wxTR_DEFAULT_STYLE .SH EVENTS .SS EVT_TREE_BEGIN_DRAG(id, func) Begin dragging with the left mouse button. .SS EVT_TREE_BEGIN_RDRAG(id, func) Begin dragging with the right mouse button. .SS EVT_TREE_END_DRAG(id, func) End dragging with the left or right mouse button. .SS EVT_TREE_BEGIN_LABEL_EDIT(id, func) Begin editing a label. This can be prevented by calling Veto() . .SS EVT_TREE_END_LABEL_EDIT(id, func) Finish editing a label. This can be prevented by calling Veto() . .SS EVT_TREE_DELETE_ITEM(id, func) Delete an item. .SS EVT_TREE_GET_INFO(id, func) Request information from the application. .SS EVT_TREE_SET_INFO(id, func) Information is being supplied. .SS EVT_TREE_ITEM_ACTIVATED(id, func) The item has been activated, i.e. chosen by double clicking it with mouse or from keyboard .SS EVT_TREE_ITEM_COLLAPSED(id, func) The item has been collapsed. .SS EVT_TREE_ITEM_COLLAPSING(id, func) The item is being collapsed. This can be prevented by calling Veto() . .SS EVT_TREE_ITEM_EXPANDED(id, func) The item has been expanded. .SS EVT_TREE_ITEM_EXPANDING(id, func) The item is being expanded. This can be prevented by calling Veto() . .SS EVT_TREE_ITEM_RIGHT_CLICK(id, func) The user has clicked the item with the right mouse button. .SS EVT_TREE_ITEM_MIDDLE_CLICK(id, func) The user has clicked the item with the middle mouse button. .SS EVT_TREE_SEL_CHANGED(id, func) Selection has changed. .SS EVT_TREE_SEL_CHANGING(id, func) Selection is changing. This can be prevented by calling Veto() . .SS EVT_TREE_KEY_DOWN(id, func) A key has been pressed. .SS EVT_TREE_ITEM_GETTOOLTIP(id, func) The opportunity to set the item tooltip is being given to the application (call wxTreeEvent::SetToolTip). Windows only. .SS EVT_TREE_ITEM_MENU(id, func) The context menu for the selected item has been requested, either by a right click or by using the menu key. .SS EVT_TREE_STATE_IMAGE_CLICK(id, func) The state image has been clicked. Windows only. .SH "SEE ALSO" wxControl wxWindow wxEvtHandler wxObject wxTreeItemData wxTreeCtrl overview wxListBox wxListCtrl , wxImageList wxTreeEvent .SH "AUTHORS" Documentation content by Julian Smart, Robert Roebling, Vadim Zeitlin, Robin Dunn, et al Conversion to manpage format by Arnout Engelen (http://bzzt.net), bugreports welcome.