トップ 一覧 検索 ヘルプ ログイン

wxTreeCtrl概要の変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
wxTreeCtrl overview
クラス: wxTreeCtrl, wxImageList

Classes: wxTreeCtrl, wxImageList
ツリーコントロールは、そのアイテムを木構造のように表示する。各アイテムはそれ自身の(オプションで)アイコンとラベルを持つ。1つのアイテムは、折りたたまれた状態(その子供が表示されていない)と、展開された状態(その子供が表示された状態)になり得る。ツリー内の各アイテムは、ぼかされたデータ型wxTreeItemId形のitemIdにより識別される。wxTreeItemId::IsOkを呼ぶことにより、アイテムが有効かどうか調べることができる。

The tree control displays its items in a tree like structure. Each item has its own (optional) icon and a label. An item may be either collapsed (meaning that its children are not visible) or expanded (meaning that its children are shown). Each item in the tree is identified by its itemId which is of opaque data type wxTreeItemId. You can test whether an item is valid by calling wxTreeItemId::IsOk.
アイテムのテキストと画像は、GetItemText/SetItemTextとGetItemImage/SetItemImageにより参照、変更することができる。事実、アイテムは2つの画像を持つことができる。SetItemSelectedImage/GetItemSelectedImage関数により設定、参照することができる状態により、標準の画像と、別の画像を持つことができる。しかし、この関数は幾つかのプラットフォームでは使用できない場合がある。

The items text and image may be retrieved and changed with GetItemText/SetItemText and GetItemImage/SetItemImage. In fact, an item may even have two images associated with it: the normal one and another one for selected state which is set/retrieved with SetItemSelectedImage/GetItemSelectedImage functions, but this functionality might be unavailable on some platforms.
ツリーアイテムは幾つかの属性を持っている。アイテムが選択されているかどうか、可視かどうか、ボールド状態かどうか、展開されているか折りたたまれているか。これら全ての属性は、関連する関数により参照することができる。IsSelected, IsVisible, IsBold, そしてIsExpandedである。1度に1つのアイテムだけが選択できる状態では、(SelectItemにより)他の1つのアイテムを選択すると、既に選択されていたアイテムは自動的に選択が解除される。

Tree items have several attributes: an item may be selected or not, visible or not, bold or not. It may also be expanded or collapsed. All these attributes may be retrieved with the corresponding functions: IsSelected, IsVisible, IsBold and IsExpanded. Only one item at a time may be selected, selecting another one (with SelectItem) automatically unselects the previously selected one.
アイコンとラベルに加えて、ユーザ固有のデータ構造を全てのツリー構造に関連付けることができる。そうしたい場合には、データに関連付けられているアイテムの識別子を返すGetId()というただ1つの関数を持つ単純なクラス、wxTreeItemDataクラスを派生させればよい。このデータは、関連付けられたアイテムが削除されるときにコントロール自身により開放される(コントロールが破棄される場合には、全てのアイテムが開放される)。このため、アプリケーション自身で削除する必要は無い(もしアプリケーションで削除する場合には、ツリーが2度ポインタを削除することを防ぐために、SetItemData(NULL)を呼ばなければならない)。関連付けられたデータは、GetItemData()関数により参照できる。

In addition to its icon and label, a user-specific data structure may be associated with all tree items. If you wish to do it, you should derive a class from wxTreeItemData which is a very simple class having only one function GetId() which returns the id of the item this data is associated with. This data 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 delete it yourself (if you do it, you should call SetItemData(NULL) to prevent the tree from deleting the pointer second time). The associated data may be retrieved with GetItemData() function.
ツリーが作成された瞬間において、全てのアイテムがツリーに追加される場合、ツリー上の作業は、相対的に一方方向に行われる。しかし、大きなツリーでは非常に効率が悪い。性能を上げるため、アイテムを含む枝が展開されるまで、アイテムのツリーへの追加を遅らせたいと考えるかもしれない。そのために、まずは(AddRootを使用して)、ルートアイテムだけを作成する。他のアイテムは、EVT_TREE_ITEM_EXPANDINGイベントを受信したときに追加する。そのとき、展開されたアイテムに じか につながる全てのアイテムを追加する。しかし、もちろん、このイベントはこのアイテムに対して始めの1回だけ受信される。そうでなければ、ユーザが枝の展開/折りたたみ/展開を行うと、2回追加されることになる。

Working with trees is relatively straightforward if all the items are added to the tree at the moment of its creation. However, for large trees it may be very inefficient. To improve the performance you may want to delay adding the items to the tree until the branch containing the items is expanded: so, in the beginning, only the root item is created (with AddRoot). Other items are added when EVT_TREE_ITEM_EXPANDING event is received: then all items lying immediately under the item being expanded should be added, but, of course, only when this event is received for the first time for this item - otherwise, the items would be added twice if the user expands/collapses/re-expands the branch.
ツリーコントロールは、そのアイテムを列挙するための関数を準備している。列挙用の関数として3種類ある。与えられたアイテムの子供に対するもの、与えられたアイテムの兄弟に対するもの、可視化されたアイテム(現在ユーザが見られるものであり、枝が折りたたまれた場合や、ビューでスクロール外にある場合がある)に対するものである。子供の列挙用の関数は、呼び出し元に1つの引数coockeを要求する。それは、呼び出し元に対してぼかしている数字であるが、ツリーコントロール自身が複数の列挙子に同じように実行できるようになっている(これは明示的に認められている)。忘れてはならないのは、GetFirstChildとGetNextChildに渡されたcookieは同じ変数であるべきである(and that nothing should be done with it by the user code)。

The tree control provides functions for enumerating its items. There are 3 groups of enumeration functions: for the children of a given item, for the sibling of the given item and for the visible items (those which are currently shown to the user: an item may be invisible either because its branch is collapsed or because it is scrolled out of view). Child enumeration functions require the caller to give them a cookie parameter: it is a number which is opaque to the caller but is used by the tree control itself to allow multiple enumerations to run simultaneously (this is explicitly allowed). The only thing to remember is that the cookie passed to GetFirstChild and to GetNextChild should be the same variable (and that nothing should be done with it by the user code).
ツリーコントロールには他の機能もある。ユーザ定義の比較関数OnCompareItems(デフォルトでは、ツリーラベルのアルファベット比較による比較)を使用したSortChildrenによるアイテムのソート、HitTestによる当たり判定(ポイントされたコントロールの位置を決定する)、ツリーアイテムラベルのインプレース編集(EditLabelを参照)である。

Among other features of the tree control are: item sorting with SortChildren which uses the user-defined comparison function OnCompareItems (by default the comparison is the alphabetic comparison of tree labels), hit testing (determining to which portion of the control the given point belongs, useful for implementing drag-and-drop in the tree) with HitTest and editing of the tree item labels in place (see EditLabel).

Finally, the tree control has a keyboard interface: the cursor navigation (arrow) keys may be used to change the current selection. <HOME> and <END> are used to go to the first/last sibling of the current item. '+', '-' and '*' expand, collapse and toggle the current branch. Note, however, that <DEL> and <INS> keys do nothing by default, but it is usual to associate them with deleting item from a tree and inserting a new one into it.
最後に、ツリーコントロールは、キーボードインタフェースを持っている。カーソル(方向)キーにより現在の選択を変更することができる。<HOME>と<END>は現在のアイテムの最初、または最後の兄弟に飛ぶことができる。'+'、'-'、'*'は、現在の枝の展開、折りたたみ、トグル(切り替え)に使用される。<DEL>と<INS>キーはデフォルトでは何もしないが、ツリーからのアイテムの削除や、新しいアイテムの挿入に関連付けることができる。