⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttreectl.tex

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 TEX
字号:
\section{wxTreeCtrl overview}\label{wxtreectrloverview}Classes: \helpref{wxTreeCtrl}{wxtreectrl}, \helpref{wxImageList}{wximagelist}The tree control displays its items in a tree like structure. Each item has itsown (optional) icon and a label. An item may be either collapsed (meaning thatits children are not visible) or expanded (meaning that its children areshown). Each item in the tree is identified by its {\it itemId} which is ofopaque data type {\it wxTreeItemId}. You can test whether an item is validby calling wxTreeItemId::IsOk.The items text and image may be retrieved and changed with \helpref{GetItemText}{wxtreectrlgetitemtext}/\helpref{SetItemText}{wxtreectrlsetitemtext} and \helpref{GetItemImage}{wxtreectrlgetitemimage}/\helpref{SetItemImage}{wxtreectrlsetitemimage}.In fact, an item may even have two images associated with it: the normal oneand another one for selected state which is set/retrieved with \helpref{SetItemSelectedImage}{wxtreectrlsetitemselectedimage}/\helpref{GetItemSelectedImage}{wxtreectrlgetitemselectedimage} functions, but this functionality might be unavailable on some platforms.Tree items have several attributes: an item may be selected or not, visible ornot, bold or not. It may also be expanded or collapsed. All these attributesmay be retrieved with the corresponding functions: \helpref{IsSelected}{wxtreectrlisselected}, \helpref{IsVisible}{wxtreectrlisvisible}, \helpref{IsBold}{wxtreectrlisbold} and \helpref{IsExpanded}{wxtreectrlisexpanded}. Only one item at a time may beselected, selecting another one (with \helpref{SelectItem}{wxtreectrlselectitem}) automatically unselects thepreviously selected one.In addition to its icon and label, a user-specific data structure may be associatedwith all tree items. If you wish to do it, you should derive a class from {\itwxTreeItemData} which is a very simple class having only one function {\itGetId()} which returns the id of the item this data is associated with. Thisdata will be freed by the control itself when the associated item is deleted(all items are deleted when the control is destroyed), so you shouldn't deleteit yourself (if you do it, you should call \helpref{SetItemData(NULL)}{wxtreectrlsetitemdata} to prevent the tree fromdeleting the pointer second time). The associated data may be retrieved with \helpref{GetItemData()}{wxtreectrlgetitemdata} function.Working with trees is relatively straightforward if all the items are added tothe tree at the moment of its creation. However, for large trees it may bevery inefficient. To improve the performance you may want to delay adding theitems to the tree until the branch containing the items is expanded: so, in thebeginning, only the root item is created (with \helpref{AddRoot}{wxtreectrladdroot}). Other items are added whenEVT\_TREE\_ITEM\_EXPANDING event is received: then all items lying immediatelyunder the item being expanded should be added, but, of course, only when thisevent is received for the first time for this item - otherwise, the items wouldbe added twice if the user expands/collapses/re-expands the branch.The tree control provides functions for enumerating its items. There are 3groups of enumeration functions: for the children of a given item, for thesibling of the given item and for the visible items (those which are currentlyshown to the user: an item may be invisible either because its branch iscollapsed or because it is scrolled out of view). Child enumeration functionsrequire the caller to give them a {\it cookie} parameter: it is a number whichis opaque to the caller but is used by the tree control itself to allowmultiple enumerations to run simultaneously (this is explicitly allowed). Theonly thing to remember is that the {\it cookie} passed to \helpref{GetFirstChild}{wxtreectrlgetfirstchild} and to \helpref{GetNextChild}{wxtreectrlgetnextchild} should be the same variable (andthat nothing should be done with it by the user code).Among other features of the tree control are: item sorting with \helpref{SortChildren}{wxtreectrlsortchildren} which uses the user-defined comparisonfunction \helpref{OnCompareItems}{wxtreectrloncompareitems} (by default thecomparison is the alphabetic comparison of tree labels), hit testing(determining to which portion of the control the given point belongs, usefulfor implementing drag-and-drop in the tree) with \helpref{HitTest}{wxtreectrlhittest} and editing of the tree item labels inplace (see \helpref{EditLabel}{wxtreectrleditlabel}).Finally, the tree control has a keyboard interface: the cursor navigation (arrow) keysmay be used to change the current selection. <HOME> and <END> are used to go tothe first/last sibling of the current item. '+', '-' and '*' expand, collapseand toggle the current branch. Note, however, that <DEL> and <INS> keys donothing by default, but it is common to associate them with deleting an item froma tree and inserting a new one into it.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -