]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: treectrl.h | |
3 | // Purpose: wxTreeCtrl class | |
4 | // Author: Julian Smart | |
08b7c251 | 5 | // Modified by: Vadim Zeitlin to be less MSW-specific on 10/10/98 |
2bda0e17 KB |
6 | // Created: 01/02/97 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
08b7c251 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_TREECTRL_H_ |
13 | #define _WX_TREECTRL_H_ | |
2bda0e17 | 14 | |
08b7c251 VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 18 | #ifdef __GNUG__ |
08b7c251 | 19 | #pragma interface "treectrl.h" |
2bda0e17 KB |
20 | #endif |
21 | ||
22 | #include "wx/control.h" | |
23 | #include "wx/event.h" | |
2bda0e17 | 24 | |
16553659 JS |
25 | #ifdef __GNUWIN32__ |
26 | # ifdef GetFirstChild | |
27 | # undef GetFirstChild | |
28 | # endif | |
29 | ||
30 | # ifdef GetNextSibling | |
31 | # undef GetNextSibling | |
32 | # endif | |
16e93305 JS |
33 | #endif |
34 | ||
08b7c251 VZ |
35 | // the type for "untyped" data |
36 | typedef long wxDataType; | |
37 | ||
38 | // fwd decl | |
06e38c8e JS |
39 | class WXDLLEXPORT wxImageList; |
40 | struct WXDLLEXPORT wxTreeViewItem; | |
08b7c251 VZ |
41 | |
42 | // a callback function used for sorting tree items, it should return -1 if the | |
43 | // first item precedes the second, +1 if the second precedes the first or 0 if | |
44 | // they're equivalent | |
45 | class wxTreeItemData; | |
08b7c251 VZ |
46 | |
47 | // ---------------------------------------------------------------------------- | |
48 | // constants | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | // values for the `flags' parameter of wxTreeCtrl::HitTest() which determine | |
52 | // where exactly the specified point is situated: | |
53 | // above the client area. | |
54 | static const int wxTREE_HITTEST_ABOVE = 0x0001; | |
55 | // below the client area. | |
56 | static const int wxTREE_HITTEST_BELOW = 0x0002; | |
57 | // in the client area but below the last item. | |
58 | static const int wxTREE_HITTEST_NOWHERE = 0x0004; | |
59 | // on the button associated with an item. | |
60 | static const int wxTREE_HITTEST_ONITEMBUTTON = 0x0010; | |
61 | // on the bitmap associated with an item. | |
62 | static const int wxTREE_HITTEST_ONITEMICON = 0x0020; | |
63 | // in the indentation associated with an item. | |
64 | static const int wxTREE_HITTEST_ONITEMINDENT = 0x0040; | |
65 | // on the label (string) associated with an item. | |
66 | static const int wxTREE_HITTEST_ONITEMLABEL = 0x0080; | |
67 | // in the area to the right of an item. | |
68 | static const int wxTREE_HITTEST_ONITEMRIGHT = 0x0100; | |
69 | // on the state icon for a tree view item that is in a user-defined state. | |
70 | static const int wxTREE_HITTEST_ONITEMSTATEICON = 0x0200; | |
71 | // to the right of the client area. | |
72 | static const int wxTREE_HITTEST_TOLEFT = 0x0400; | |
73 | // to the left of the client area. | |
74 | static const int wxTREE_HITTEST_TORIGHT = 0x0800; | |
75 | // anywhere on the item | |
76 | static const int wxTREE_HITTEST_ONITEM = wxTREE_HITTEST_ONITEMICON | | |
77 | wxTREE_HITTEST_ONITEMLABEL | | |
78 | wxTREE_HITTEST_ONITEMSTATEICON; | |
79 | ||
80 | // NB: all the following flags are for compatbility only and will be removed in the | |
81 | // next versions | |
82 | ||
83 | // flags for deprecated `Expand(int action)' | |
84 | enum | |
85 | { | |
2bda0e17 KB |
86 | wxTREE_EXPAND_EXPAND, |
87 | wxTREE_EXPAND_COLLAPSE, | |
88 | wxTREE_EXPAND_COLLAPSE_RESET, | |
89 | wxTREE_EXPAND_TOGGLE | |
90 | }; | |
91 | ||
08b7c251 | 92 | // flags for deprecated InsertItem() variant |
3197ed26 VZ |
93 | #define wxTREE_INSERT_FIRST 0xFFFF0001 |
94 | #define wxTREE_INSERT_LAST 0xFFFF0002 | |
2bda0e17 | 95 | |
08b7c251 VZ |
96 | // ---------------------------------------------------------------------------- |
97 | // wxTreeItemId identifies an element of the tree. In this implementation, it's | |
98 | // just a trivial wrapper around Win32 HTREEITEM. It's opaque for the | |
99 | // application. | |
100 | // ---------------------------------------------------------------------------- | |
101 | class WXDLLEXPORT wxTreeItemId | |
2bda0e17 | 102 | { |
2bda0e17 | 103 | public: |
08b7c251 VZ |
104 | // ctors |
105 | // 0 is invalid value for HTREEITEM | |
106 | wxTreeItemId() { m_itemId = 0; } | |
107 | ||
108 | // default copy ctor/assignment operator are ok for us | |
109 | ||
110 | // accessors | |
111 | // is this a valid tree item? | |
112 | bool IsOk() const { return m_itemId != 0; } | |
113 | ||
114 | // conversion to/from either real (system-dependent) tree item id or | |
115 | // to "long" which used to be the type for tree item ids in previous | |
116 | // versions of wxWindows | |
117 | ||
08b7c251 | 118 | // for wxTreeCtrl usage only |
06e38c8e JS |
119 | wxTreeItemId(WXHTREEITEM itemId) { m_itemId = (long)itemId; } |
120 | operator WXHTREEITEM() const { return (WXHTREEITEM)m_itemId; } | |
121 | ||
add28c55 | 122 | void operator=(WXHTREEITEM item) { m_itemId = (long) item; } |
08b7c251 VZ |
123 | |
124 | protected: | |
125 | long m_itemId; | |
2bda0e17 KB |
126 | }; |
127 | ||
08b7c251 VZ |
128 | // ---------------------------------------------------------------------------- |
129 | // wxTreeItemData is some (arbitrary) user class associated with some item. The | |
130 | // main advantage of having this class (compared to old untyped interface) is | |
131 | // that wxTreeItemData's are destroyed automatically by the tree and, as this | |
132 | // class has virtual dtor, it means that the memory will be automatically | |
133 | // freed. OTOH, we don't just use wxObject instead of wxTreeItemData because | |
134 | // the size of this class is critical: in any real application, each tree leaf | |
135 | // will have wxTreeItemData associated with it and number of leaves may be | |
136 | // quite big. | |
137 | // | |
138 | // Because the objects of this class are deleted by the tree, they should | |
139 | // always be allocated on the heap! | |
140 | // ---------------------------------------------------------------------------- | |
3a5a2f56 | 141 | class WXDLLEXPORT wxTreeItemData : private wxTreeItemId |
08b7c251 | 142 | { |
08b7c251 | 143 | public: |
3a5a2f56 | 144 | // default ctor/copy ctor/assignment operator are ok |
08b7c251 | 145 | |
3a5a2f56 VZ |
146 | // dtor is virtual and all the items are deleted by the tree control when |
147 | // it's deleted, so you normally don't have to care about freeing memory | |
148 | // allocated in your wxTreeItemData-derived class | |
08b7c251 VZ |
149 | virtual ~wxTreeItemData() { } |
150 | ||
3a5a2f56 VZ |
151 | // accessors: set/get the item associated with this node |
152 | void SetId(const wxTreeItemId& id) { m_itemId = id; } | |
a7e594b2 | 153 | const wxTreeItemId& GetId() const { return (wxTreeItemId&) m_itemId; } |
08b7c251 VZ |
154 | }; |
155 | ||
156 | // ---------------------------------------------------------------------------- | |
157 | // wxTreeCtrl | |
158 | // ---------------------------------------------------------------------------- | |
159 | class WXDLLEXPORT wxTreeCtrl : public wxControl | |
2bda0e17 | 160 | { |
092bddef | 161 | public: |
092bddef VZ |
162 | // creation |
163 | // -------- | |
08b7c251 VZ |
164 | wxTreeCtrl() { Init(); } |
165 | ||
166 | wxTreeCtrl(wxWindow *parent, wxWindowID id = -1, | |
167 | const wxPoint& pos = wxDefaultPosition, | |
168 | const wxSize& size = wxDefaultSize, | |
169 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, | |
170 | const wxValidator& validator = wxDefaultValidator, | |
171 | const wxString& name = "wxTreeCtrl") | |
092bddef VZ |
172 | { |
173 | Create(parent, id, pos, size, style, validator, name); | |
174 | } | |
08b7c251 VZ |
175 | |
176 | virtual ~wxTreeCtrl(); | |
177 | ||
092bddef VZ |
178 | bool Create(wxWindow *parent, wxWindowID id = -1, |
179 | const wxPoint& pos = wxDefaultPosition, | |
180 | const wxSize& size = wxDefaultSize, | |
08b7c251 | 181 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, |
092bddef VZ |
182 | const wxValidator& validator = wxDefaultValidator, |
183 | const wxString& name = "wxTreeCtrl"); | |
08b7c251 | 184 | |
092bddef VZ |
185 | // accessors |
186 | // --------- | |
092bddef | 187 | |
08b7c251 VZ |
188 | // get the total number of items in the control |
189 | size_t GetCount() const; | |
190 | ||
191 | // indent is the number of pixels the children are indented relative to | |
192 | // the parents position. SetIndent() also redraws the control | |
193 | // immediately. | |
194 | unsigned int GetIndent() const; | |
195 | void SetIndent(unsigned int indent); | |
196 | ||
197 | // image list: these functions allow to associate an image list with | |
198 | // the control and retrieve it. Note that the control does _not_ delete | |
199 | // the associated image list when it's deleted in order to allow image | |
200 | // lists to be shared between different controls. | |
201 | // | |
202 | // The normal image list is for the icons which correspond to the | |
203 | // normal tree item state (whether it is selected or not). | |
204 | // Additionally, the application might choose to show a state icon | |
205 | // which corresponds to an app-defined item state (for example, | |
206 | // checked/unchecked) which are taken from the state image list. | |
207 | wxImageList *GetImageList() const; | |
208 | wxImageList *GetStateImageList() const; | |
209 | ||
210 | void SetImageList(wxImageList *imageList); | |
211 | void SetStateImageList(wxImageList *imageList); | |
212 | ||
213 | // Functions to work with tree ctrl items. Unfortunately, they can _not_ be | |
214 | // member functions of wxTreeItem because they must know the tree the item | |
215 | // belongs to for Windows implementation and storing the pointer to | |
216 | // wxTreeCtrl in each wxTreeItem is just too much waste. | |
217 | ||
218 | // accessors | |
219 | // --------- | |
220 | ||
221 | // retrieve items label | |
222 | wxString GetItemText(const wxTreeItemId& item) const; | |
223 | // get the normal item image | |
224 | int GetItemImage(const wxTreeItemId& item) const; | |
225 | // get the selected item image | |
226 | int GetItemSelectedImage(const wxTreeItemId& item) const; | |
227 | // get the data associated with the item | |
228 | wxTreeItemData *GetItemData(const wxTreeItemId& item) const; | |
229 | ||
230 | // modifiers | |
231 | // --------- | |
232 | ||
233 | // set items label | |
234 | void SetItemText(const wxTreeItemId& item, const wxString& text); | |
235 | // set the normal item image | |
236 | void SetItemImage(const wxTreeItemId& item, int image); | |
237 | // set the selected item image | |
238 | void SetItemSelectedImage(const wxTreeItemId& item, int image); | |
239 | // associate some data with the item | |
240 | void SetItemData(const wxTreeItemId& item, wxTreeItemData *data); | |
241 | ||
3a5a2f56 VZ |
242 | // force appearance of [+] button near the item. This is useful to |
243 | // allow the user to expand the items which don't have any children now | |
244 | // - but instead add them only when needed, thus minimizing memory | |
245 | // usage and loading time. | |
246 | void SetItemHasChildren(const wxTreeItemId& item, bool has = TRUE); | |
247 | ||
add28c55 VZ |
248 | // the item will be shown in bold |
249 | void SetItemBold(const wxTreeItemId& item, bool bold = TRUE); | |
250 | ||
08b7c251 VZ |
251 | // item status inquiries |
252 | // --------------------- | |
253 | ||
254 | // is the item visible (it might be outside the view or not expanded)? | |
255 | bool IsVisible(const wxTreeItemId& item) const; | |
256 | // does the item has any children? | |
257 | bool ItemHasChildren(const wxTreeItemId& item) const; | |
258 | // is the item expanded (only makes sense if HasChildren())? | |
259 | bool IsExpanded(const wxTreeItemId& item) const; | |
260 | // is this item currently selected (the same as has focus)? | |
261 | bool IsSelected(const wxTreeItemId& item) const; | |
add28c55 VZ |
262 | // is item text in bold font? |
263 | bool IsBold(const wxTreeItemId& item) const; | |
08b7c251 | 264 | |
4832f7c0 VZ |
265 | // number of children |
266 | // ------------------ | |
267 | ||
268 | // if 'recursively' is FALSE, only immediate children count, otherwise | |
269 | // the returned number is the number of all items in this branch | |
270 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); | |
271 | ||
08b7c251 VZ |
272 | // navigation |
273 | // ---------- | |
274 | ||
275 | // wxTreeItemId.IsOk() will return FALSE if there is no such item | |
276 | ||
277 | // get the root tree item | |
278 | wxTreeItemId GetRootItem() const; | |
279 | ||
280 | // get the item currently selected (may return NULL if no selection) | |
281 | wxTreeItemId GetSelection() const; | |
282 | ||
283 | // get the parent of this item (may return NULL if root) | |
284 | wxTreeItemId GetParent(const wxTreeItemId& item) const; | |
285 | ||
286 | // for this enumeration function you must pass in a "cookie" parameter | |
287 | // which is opaque for the application but is necessary for the library | |
288 | // to make these functions reentrant (i.e. allow more than one | |
289 | // enumeration on one and the same object simultaneously). Of course, | |
290 | // the "cookie" passed to GetFirstChild() and GetNextChild() should be | |
291 | // the same! | |
292 | ||
293 | // get the first child of this item | |
06e38c8e | 294 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& _cookie) const; |
08b7c251 | 295 | // get the next child |
06e38c8e | 296 | wxTreeItemId GetNextChild(const wxTreeItemId& item, long& _cookie) const; |
08b7c251 VZ |
297 | |
298 | // get the next sibling of this item | |
299 | wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; | |
300 | // get the previous sibling | |
301 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const; | |
302 | ||
303 | // get first visible item | |
304 | wxTreeItemId GetFirstVisibleItem() const; | |
305 | // get the next visible item: item must be visible itself! | |
306 | // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem() | |
307 | wxTreeItemId GetNextVisible(const wxTreeItemId& item) const; | |
308 | // get the previous visible item: item must be visible itself! | |
309 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; | |
310 | ||
092bddef VZ |
311 | // operations |
312 | // ---------- | |
08b7c251 VZ |
313 | |
314 | // add the root node to the tree | |
315 | wxTreeItemId AddRoot(const wxString& text, | |
316 | int image = -1, int selectedImage = -1, | |
317 | wxTreeItemData *data = NULL); | |
318 | ||
319 | // insert a new item in as the first child of the parent | |
320 | wxTreeItemId PrependItem(const wxTreeItemId& parent, | |
321 | const wxString& text, | |
322 | int image = -1, int selectedImage = -1, | |
323 | wxTreeItemData *data = NULL); | |
324 | ||
325 | // insert a new item after a given one | |
326 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
327 | const wxTreeItemId& idPrevious, | |
328 | const wxString& text, | |
329 | int image = -1, int selectedImage = -1, | |
330 | wxTreeItemData *data = NULL); | |
331 | ||
332 | // insert a new item in as the last child of the parent | |
333 | wxTreeItemId AppendItem(const wxTreeItemId& parent, | |
334 | const wxString& text, | |
335 | int image = -1, int selectedImage = -1, | |
336 | wxTreeItemData *data = NULL); | |
337 | ||
338 | // delete this item and associated data if any | |
339 | void Delete(const wxTreeItemId& item); | |
372edb9d VZ |
340 | // delete all children (but don't delete the item itself) |
341 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
342 | void DeleteChildren(const wxTreeItemId& item); | |
08b7c251 | 343 | // delete all items from the tree |
372edb9d | 344 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events |
08b7c251 VZ |
345 | void DeleteAllItems(); |
346 | ||
347 | // expand this item | |
348 | void Expand(const wxTreeItemId& item); | |
349 | // collapse the item without removing its children | |
350 | void Collapse(const wxTreeItemId& item); | |
351 | // collapse the item and remove all children | |
352 | void CollapseAndReset(const wxTreeItemId& item); | |
353 | // toggles the current state | |
354 | void Toggle(const wxTreeItemId& item); | |
355 | ||
356 | // remove the selection from currently selected item (if any) | |
357 | void Unselect(); | |
358 | // select this item | |
359 | void SelectItem(const wxTreeItemId& item); | |
360 | // make sure this item is visible (expanding the parent item and/or | |
361 | // scrolling to this item if necessary) | |
362 | void EnsureVisible(const wxTreeItemId& item); | |
363 | // scroll to this item (but don't expand its parent) | |
364 | void ScrollTo(const wxTreeItemId& item); | |
365 | ||
366 | // start editing the item label: this (temporarily) replaces the item | |
367 | // with a one line edit control. The item will be selected if it hadn't | |
368 | // been before. textCtrlClass parameter allows you to create an edit | |
369 | // control of arbitrary user-defined class deriving from wxTextCtrl. | |
370 | wxTextCtrl* EditLabel(const wxTreeItemId& item, | |
371 | wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl)); | |
372 | // returns the same pointer as StartEdit() if the item is being edited, | |
373 | // NULL otherwise (it's assumed that no more than one item may be | |
374 | // edited simultaneously) | |
375 | wxTextCtrl* GetEditControl() const; | |
376 | // end editing and accept or discard the changes to item label | |
377 | void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE); | |
378 | ||
95aabccc VZ |
379 | // sorting |
380 | // this function is called to compare 2 items and should return -1, 0 | |
381 | // or +1 if the first item is less than, equal to or greater than the | |
382 | // second one. The base class version performs alphabetic comparaison | |
383 | // of item labels (GetText) | |
384 | virtual int OnCompareItems(const wxTreeItemId& item1, | |
385 | const wxTreeItemId& item2); | |
386 | // sort the children of this item using OnCompareItems | |
08b7c251 | 387 | // |
95aabccc VZ |
388 | // NB: this function is not reentrant and not MT-safe (FIXME)! |
389 | void SortChildren(const wxTreeItemId& item); | |
08b7c251 VZ |
390 | |
391 | // helpers | |
392 | // ------- | |
393 | ||
add28c55 VZ |
394 | // determine to which item (if any) belongs the given point (the |
395 | // coordinates specified are relative to the client area of tree ctrl) | |
396 | // and fill the flags parameter with a bitmask of wxTREE_HITTEST_xxx | |
397 | // constants. | |
398 | // | |
399 | // The first function is more portable (because easier to implement | |
400 | // on other platforms), but the second one returns some extra info. | |
401 | wxTreeItemId HitTest(const wxPoint& point) | |
402 | { int dummy; return HitTest(point, dummy); } | |
403 | wxTreeItemId HitTest(const wxPoint& point, int& flags); | |
08b7c251 VZ |
404 | |
405 | // get the bounding rectangle of the item (or of its label only) | |
add28c55 | 406 | // @@@ do we really need to expose this functions to the application? |
08b7c251 | 407 | void GetBoundingRect(const wxTreeItemId& item, |
16e93305 | 408 | wxRect& rect, |
08b7c251 VZ |
409 | bool textOnly = FALSE) const; |
410 | ||
08b7c251 VZ |
411 | // deprecated |
412 | // ---------- | |
413 | ||
414 | // these methods are deprecated and will be removed in future versions of | |
415 | // wxWindows, they're here for compatibility only, don't use them in new | |
416 | // code (the comments indicate why these methods are now useless and how to | |
417 | // replace them) | |
418 | ||
419 | // use Expand, Collapse, CollapseAndReset or Toggle | |
420 | void ExpandItem(const wxTreeItemId& item, int action); | |
421 | ||
422 | // use AddRoot, PrependItem or AppendItem | |
423 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
424 | const wxString& text, | |
425 | int image = -1, int selImage = -1, | |
426 | long insertAfter = wxTREE_INSERT_LAST); | |
427 | ||
428 | // use Set/GetImageList and Set/GetStateImageList | |
429 | wxImageList *GetImageList(int) const | |
430 | { return GetImageList(); } | |
431 | void SetImageList(wxImageList *imageList, int) | |
432 | { SetImageList(imageList); } | |
433 | ||
434 | // implementation | |
435 | // -------------- | |
092bddef | 436 | void Command(wxCommandEvent& event) { ProcessCommand(event); }; |
fd3f686c VZ |
437 | virtual bool MSWCommand(WXUINT param, WXWORD id); |
438 | virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result); | |
08b7c251 | 439 | |
2bda0e17 | 440 | protected: |
08b7c251 VZ |
441 | // SetImageList helper |
442 | void SetAnyImageList(wxImageList *imageList, int which); | |
443 | ||
444 | wxTextCtrl* m_textCtrl; // used while editing the item label | |
445 | wxImageList *m_imageListNormal, // images for tree elements | |
446 | *m_imageListState; // special images for app defined states | |
447 | ||
448 | private: | |
449 | // the common part of all ctors | |
450 | void Init(); | |
451 | ||
452 | // helper functions | |
453 | inline bool DoGetItem(wxTreeViewItem *tvItem) const; | |
454 | inline void DoSetItem(wxTreeViewItem *tvItem); | |
455 | ||
456 | inline void DoExpand(const wxTreeItemId& item, int flag); | |
457 | ||
458 | wxTreeItemId DoInsertItem(const wxTreeItemId& parent, | |
459 | wxTreeItemId hInsertAfter, | |
460 | const wxString& text, | |
461 | int image, int selectedImage, | |
462 | wxTreeItemData *data); | |
463 | ||
464 | void DeleteTextCtrl(); | |
092bddef VZ |
465 | |
466 | DECLARE_DYNAMIC_CLASS(wxTreeCtrl) | |
2bda0e17 KB |
467 | }; |
468 | ||
08b7c251 VZ |
469 | // ---------------------------------------------------------------------------- |
470 | // wxTreeEvent is a special class for all events associated with tree controls | |
471 | // | |
472 | // NB: note that not all accessors make sense for all events, see the event | |
473 | // descriptions below | |
474 | // ---------------------------------------------------------------------------- | |
fd3f686c | 475 | class WXDLLEXPORT wxTreeEvent : public wxNotifyEvent |
2bda0e17 | 476 | { |
08b7c251 VZ |
477 | friend wxTreeCtrl; |
478 | public: | |
479 | wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); | |
480 | ||
481 | // accessors | |
482 | // get the item on which the operation was performed or the newly | |
483 | // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events | |
484 | wxTreeItemId GetItem() const { return m_item; } | |
2bda0e17 | 485 | |
08b7c251 VZ |
486 | // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously |
487 | // selected item | |
488 | wxTreeItemId GetOldItem() const { return m_itemOld; } | |
2bda0e17 | 489 | |
08b7c251 VZ |
490 | // the point where the mouse was when the drag operation started (for |
491 | // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) | |
492 | wxPoint GetPoint() const { return m_pointDrag; } | |
64693098 | 493 | |
08b7c251 VZ |
494 | // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only) |
495 | int GetCode() const { return m_code; } | |
496 | ||
08b7c251 VZ |
497 | private: |
498 | // @@ we could save some space by using union here | |
499 | int m_code; | |
500 | wxTreeItemId m_item, | |
501 | m_itemOld; | |
502 | wxPoint m_pointDrag; | |
503 | ||
504 | DECLARE_DYNAMIC_CLASS(wxTreeEvent) | |
2bda0e17 KB |
505 | }; |
506 | ||
507 | typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); | |
508 | ||
08b7c251 VZ |
509 | // ---------------------------------------------------------------------------- |
510 | // macros for handling tree control events | |
511 | // ---------------------------------------------------------------------------- | |
512 | ||
513 | // GetItem() returns the item being dragged, GetPoint() the mouse coords | |
c67daf87 UR |
514 | #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, |
515 | #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
08b7c251 VZ |
516 | |
517 | // GetItem() returns the itme whose label is being edited | |
c67daf87 UR |
518 | #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, |
519 | #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
08b7c251 VZ |
520 | |
521 | // provide/update information about GetItem() item | |
c67daf87 UR |
522 | #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, |
523 | #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
08b7c251 VZ |
524 | |
525 | // GetItem() is the item being expanded/collapsed, the "ING" versions can use | |
c67daf87 UR |
526 | #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, |
527 | #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
528 | #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
092bddef | 529 | #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, |
08b7c251 VZ |
530 | |
531 | // GetOldItem() is the item which had the selection previously, GetItem() is | |
532 | // the item which acquires selection | |
fe71f65c RR |
533 | #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, |
534 | #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
08b7c251 VZ |
535 | |
536 | // GetCode() returns the key code | |
537 | // NB: this is the only message for which GetItem() is invalid (you may get the | |
538 | // item from GetSelection()) | |
fe71f65c | 539 | #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, |
2bda0e17 | 540 | |
08b7c251 VZ |
541 | // GetItem() returns the item being deleted, the associated data (if any) will |
542 | // be deleted just after the return of this event handler (if any) | |
543 | #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
544 | ||
435fe83e RR |
545 | // GetItem() returns the item that was activated (double click, enter, space) |
546 | #define EVT_TREE_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
547 | ||
2bda0e17 | 548 | #endif |
bbcdf8bc | 549 | // _WX_TREECTRL_H_ |