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