wxtreectrla 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. derived from
wxcontrol include files <wx/treectrl.h> window styles
see also window styles overview. event handling to process input from a tree control, use these event handler macros to direct input to member functions that take a wxtreeevent argument.
see also wxtreeitemdata, wxtreectrl overview, wxlistbox, wxlistctrl, wximagelist, wxtreeevent win32 notes 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. members
wxtreectrl::wxtreectrl
wxtreectrl::wxtreectrlwxtreectrl() default constructor. wxtreectrl(wxwindow* parent, wxwindowid id, const wxpoint& pos = wxdefaultposition, const wxsize& size = wxdefaultsize, long style = wxtr_has_buttons, const wxvalidator& validator = wxdefaultvalidator, const wxstring& name = "treectrl") constructor, creating and showing a tree control. parameters parent
id
pos
size
style
validator
name
see also wxtreectrl::create, wxvalidator
wxtreectrl::~wxtreectrlvoid ~wxtreectrl() destructor, destroying the tree control.
wxtreectrl::addrootwxtreeitemid addroot(const wxstring& text, int image = -1, int selimage = -1, wxtreeitemdata* 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.
wxtreectrl::appenditemwxtreeitemid appenditem(const wxtreeitemid& parent, const wxstring& text, int image = -1, int selimage = -1, wxtreeitemdata* 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.
wxtreectrl::assignbuttonsimagelistvoid 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.
wxtreectrl::assignimagelistvoid 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.
wxtreectrl::assignstateimagelistvoid 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.
wxtreectrl::collapsevoid collapse(const wxtreeitemid& item) collapses the given item.
wxtreectrl::collapseallvoid collapseall() collapses the root item. see also
wxtreectrl::collapseallchildrenvoid collapseallchildren(const wxtreeitemid& item) collapses this item and all of its children, recursively. see also
wxtreectrl::collapseandresetvoid collapseandreset(const wxtreeitemid& item) collapses the given item and removes all children.
wxtreectrl::createbool wxtreectrl(wxwindow* parent, wxwindowid id, const wxpoint& pos = wxdefaultposition, const wxsize& size = wxdefaultsize, long style = wxtr_has_buttons, const wxvalidator& validator = wxdefaultvalidator, const wxstring& name = "treectrl") creates the tree control. see wxtreectrl::wxtreectrl for further details.
wxtreectrl::deletevoid 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.
wxtreectrl::deleteallitemsvoid deleteallitems() deletes all 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.
wxtreectrl::deletechildrenvoid 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.
wxtreectrl::editlabelvoid 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. see also wxtreectrl::endeditlabel, wxtreeevent
wxtreectrl::endeditlabelvoid endeditlabel(bool canceledit) ends label editing. if canceledit is true, the edit will be cancelled. this function is currently supported under windows only. see also
wxtreectrl::ensurevisiblevoid ensurevisible(const wxtreeitemid& item) scrolls and/or expands items to ensure that the given item is visible.
wxtreectrl::expandvoid expand(const wxtreeitemid& item) expands the given item.
wxtreectrl::expandallvoid expandall() expands all items in the tree.
wxtreectrl::expandallchildrenvoid expandallchildren(const wxtreeitemid& item) expands the given item and all its children recursively.
wxtreectrl::getboundingrectbool getboundingrect(const wxtreeitemid& item, wxrect& rect, bool textonly = false) const 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. notice that the rectangle coordinates are logical, not physical ones. so, for example, the x coordinate may be negative if the tree has a horizontal scrollbar and its position is not 0. wxpython note: the wxpython version of this method requires only the item and textonly parameters. the return value is either a wxrect object or none. wxperl note: in wxperl this method only takes the parameters item and textonly, and returns a wx::rect ( or undef ).
wxtreectrl::getbuttonsimagelistwximagelist* getbuttonsimagelist() const returns the buttons image list (from which application-defined button images are taken). this function is only available in the generic version.
wxtreectrl::getchildrencountunsigned int getchildrencount(const wxtreeitemid& item, bool recursively = true) const 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.
wxtreectrl::getcountunsigned int getcount() const returns the number of items in the control.
wxtreectrl::geteditcontrolwxtextctrl * geteditcontrol() const 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.
wxtreectrl::getfirstchildwxtreeitemid getfirstchild(const wxtreeitemid& item, wxtreeitemidvalue & cookie) const 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. see also wxtreectrl::getnextchild, wxtreectrl::getnextsibling wxpython note: in wxpython the returned wxtreeitemid and the new cookie value are both returned as a tuple containing the two values. wxperl note: in wxperl this method only takes the item parameter, and returns a 2-element list ( item, cookie ).
wxtreectrl::getfirstvisibleitemwxtreeitemid getfirstvisibleitem() const returns the first visible item.
wxtreectrl::getimagelistwximagelist* getimagelist() const returns the normal image list.
wxtreectrl::getindentint getindent() const returns the current tree control indentation.
wxtreectrl::getitembackgroundcolourwxcolour getitembackgroundcolour(const wxtreeitemid& item) const returns the background colour of the item.
wxtreectrl::getitemdatawxtreeitemdata* getitemdata(const wxtreeitemid& item) const returns the tree item data associated with the item. see also wxpython note: wxpython provides the following shortcut method:
wxtreectrl::getitemfontwxfont getitemfont(const wxtreeitemid& item) const returns the font of the item label.
wxtreectrl::getitemimageint getitemimage(const wxtreeitemid& item, wxtreeitemicon which = wxtreeitemicon_normal) const gets the specified item image. the value of which may be:
wxtreectrl::getitemtextwxstring getitemtext(const wxtreeitemid& item) const returns the item label.
wxtreectrl::getitemtextcolourwxcolour getitemtextcolour(const wxtreeitemid& item) const returns the colour of the item label.
wxtreectrl::getlastchildwxtreeitemid getlastchild(const wxtreeitemid& item) const returns the last child of the item (or an invalid tree item if this item has no children). see also getfirstchild, wxtreectrl::getnextsibling, getlastchild
wxtreectrl::getnextchildwxtreeitemid getnextchild(const wxtreeitemid& item, wxtreeitemidvalue & cookie) const 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. see also wxpython note: in wxpython the returned wxtreeitemid and the new cookie value are both returned as a tuple containing the two values. wxperl note: in wxperl this method returns a 2-element list ( item, cookie ), instead of modifying its parameters.
wxtreectrl::getnextsiblingwxtreeitemid getnextsibling(const wxtreeitemid& item) const 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. see also
wxtreectrl::getnextvisiblewxtreeitemid getnextvisible(const wxtreeitemid& item) const returns the next visible item.
wxtreectrl::getitemparentwxtreeitemid getitemparent(const wxtreeitemid& item) const returns the item's parent.
wxtreectrl::getprevsiblingwxtreeitemid getprevsibling(const wxtreeitemid& item) const 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. see also
wxtreectrl::getprevvisiblewxtreeitemid getprevvisible(const wxtreeitemid& item) const returns the previous visible item.
wxtreectrl::getquickbestsizebool getquickbestsize() const returns true if the control will use a quick calculation for the best size, looking only at the first and last items. the default is false. see also
wxtreectrl::getrootitemwxtreeitemid getrootitem() const returns the root item for the tree control.
wxtreectrl::getitemselectedimageint getitemselectedimage(const wxtreeitemid& item) const gets the selected item image (this function is obsolete, use getitemimage(item, wxtreeitemicon_selected) instead).
wxtreectrl::getselectionwxtreeitemid getselection() const 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.
wxtreectrl::getselectionsunsigned int getselections(wxarraytreeitemids& selection) const 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. wxpython note: the wxpython version of this method accepts no parameters and returns a python list of wxtreeitemids. wxperl note: in wxperl this method takes no parameters and returns a list of wx::treeitemids.
wxtreectrl::getstateimagelistwximagelist* getstateimagelist() const returns the state image list (from which application-defined state images are taken).
wxtreectrl::hittestwxtreeitemid hittest(const wxpoint& point, int& flags) const 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:
wxpython note: in wxpython both the wxtreeitemid and the flags are returned as a tuple. wxperl note: in wxperl this method only takes the point parameter and returns a 2-element list ( item, flags ).
wxtreectrl::insertitemwxtreeitemid insertitem(const wxtreeitemid& parent, const wxtreeitemid& previous, const wxstring& text, int image = -1, int selimage = -1, wxtreeitemdata* data = null) wxtreeitemid insertitem(const wxtreeitemid& parent, size_t before, const wxstring& text, int image = -1, int selimage = -1, wxtreeitemdata* 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. wxpython note: the second form of this method is called insertitembefore in wxpython.
wxtreectrl::isboldbool isbold(const wxtreeitemid& item) const returns true if the given item is in bold state. see also: setitembold
wxtreectrl::isemptybool isempty() const returns true if the control is empty (i.e. has no items, even no root one).
wxtreectrl::isexpandedbool isexpanded(const wxtreeitemid& item) const returns true if the item is expanded (only makes sense if it has children).
wxtreectrl::isselectedbool isselected(const wxtreeitemid& item) const returns true if the item is selected.
wxtreectrl::isvisiblebool isvisible(const wxtreeitemid& item) const returns true if the item is visible (it might be outside the view, or not expanded).
wxtreectrl::itemhaschildrenbool itemhaschildren(const wxtreeitemid& item) const returns true if the item has children.
wxtreectrl::oncompareitemsint oncompareitems(const wxtreeitemid& item1, const 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. please note that you must use wxrtti macros declare_dynamic_class and implement_dynamic_class if you override this function because otherwise the base class considers that it is not overridden and uses the default comparison, i.e. sorts the items alphabetically, which allows it optimize away the calls to the virtual function completely. see also: sortchildren
wxtreectrl::prependitemwxtreeitemid prependitem(const wxtreeitemid& parent, const wxstring& text, int image = -1, int selimage = -1, wxtreeitemdata* 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.
wxtreectrl::scrolltovoid scrollto(const wxtreeitemid& item) scrolls the specified item into view.
wxtreectrl::selectitemvoid selectitem(const wxtreeitemid& item, bool 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.
wxtreectrl::setbuttonsimagelistvoid 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.
wxtreectrl::setindentvoid setindent(int indent) sets the indentation for the tree control.
wxtreectrl::setimagelistvoid 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.
wxtreectrl::setitembackgroundcolourvoid setitembackgroundcolour(const wxtreeitemid& item, const wxcolour& col) sets the colour of the item's background.
wxtreectrl::setitemboldvoid setitembold(const wxtreeitemid& item, bool bold = true) makes item appear in bold font if bold parameter is true or resets it to the normal state. see also: isbold
wxtreectrl::setitemdatavoid setitemdata(const wxtreeitemid& item, wxtreeitemdata* data) sets the item client data. wxpython note: wxpython provides the following shortcut method:
wxtreectrl::setitemdrophighlightvoid setitemdrophighlight(const wxtreeitemid& item, boolhighlight = 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).
wxtreectrl::setitemfontvoid setitemfont(const wxtreeitemid& item, const 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. see also
wxtreectrl::setitemhaschildrenvoid setitemhaschildren(const wxtreeitemid& item, bool 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.
wxtreectrl::setitemimagevoid setitemimage(const wxtreeitemid& item, int image, wxtreeitemicon which = wxtreeitemicon_normal) sets the specified item image. see getitemimage for the description of the which parameter.
wxtreectrl::setitemselectedimagevoid setitemselectedimage(const wxtreeitemid& item, int selimage) sets the selected item image (this function is obsolete, use setitemimage(item, wxtreeitemicon_selected) instead).
wxtreectrl::setitemtextvoid setitemtext(const wxtreeitemid& item, const wxstring& text) sets the item label.
wxtreectrl::setitemtextcolourvoid setitemtextcolour(const wxtreeitemid& item, const wxcolour& col) sets the colour of the item's text.
wxtreectrl::setquickbestsizevoid setquickbestsize(bool quickbestsize) if true is passed, specifies that the control will use a quick calculation for the best size, looking only at the first and last items. otherwise, it will look at all items. the default is false. see also
wxtreectrl::setstateimagelistvoid 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.
wxtreectrl::setwindowstylevoid 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.)
wxtreectrl::sortchildrenvoid sortchildren(const wxtreeitemid& item) sorts the children of the given item using oncompareitems method of wxtreectrl. you should override that method to change the sort order (the default is ascending case-sensitive alphabetical order). see also wxtreeitemdata, oncompareitems
wxtreectrl::togglevoid toggle(const wxtreeitemid& item) toggles the given item between collapsed and expanded states.
wxtreectrl::toggleitemselectionvoid toggleitemselection(const wxtreeitemid& item) toggles the given item between selected and unselected states. for multiselection controls only.
wxtreectrl::unselectvoid unselect() removes the selection from the currently selected item (if any).
wxtreectrl::unselectallvoid 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.
wxtreectrl::unselectitemvoid unselectitem(const wxtreeitemid& item) unselects the given item. this works in multiselection controls only.
|