]>
Commit | Line | Data |
---|---|---|
f135ff73 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: treectrl.h | |
3 | // Purpose: wxTreeCtrl class | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1997,1998 Robert Roebling | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _GENERIC_TREECTRL_H_ | |
13 | #define _GENERIC_TREECTRL_H_ | |
c801d85f KB |
14 | |
15 | #ifdef __GNUG__ | |
f135ff73 | 16 | #pragma interface "treectrl.h" |
c801d85f KB |
17 | #endif |
18 | ||
62448488 JS |
19 | #ifdef __WXMSW__ |
20 | WXDLLEXPORT_DATA(extern const char*) wxTreeCtrlNameStr; | |
21 | #else | |
22 | #define wxTreeCtrlNameStr "wxTreeCtrl" | |
23 | #endif | |
24 | ||
c801d85f KB |
25 | #include "wx/defs.h" |
26 | #include "wx/string.h" | |
f135ff73 | 27 | #include "wx/object.h" |
c801d85f | 28 | #include "wx/event.h" |
c801d85f | 29 | #include "wx/scrolwin.h" |
f135ff73 | 30 | #include "wx/textctrl.h" |
ac57418f | 31 | #include "wx/pen.h" |
91b8de8d RR |
32 | #include "wx/dynarray.h" |
33 | ||
8506d95d SB |
34 | //those defines should only be done in generic/treectrl.h, |
35 | //because wxMSW doesn't allow mutiple selection | |
36 | ||
91b8de8d RR |
37 | #ifndef wxTR_SINGLE |
38 | #define wxTR_SINGLE 0x0000 | |
39 | #define wxTR_MULTIPLE 0x0020 | |
40 | #define wxTR_EXTENDED 0x0040 | |
41 | #define wxTR_HAS_VARIABLE_ROW_HIGHT 0x0080 | |
42 | #endif | |
c801d85f | 43 | |
4f22cf8d RR |
44 | // ----------------------------------------------------------------------------- |
45 | // constants | |
46 | // ----------------------------------------------------------------------------- | |
47 | ||
48 | // values for the `flags' parameter of wxTreeCtrl::HitTest() which determine | |
49 | // where exactly the specified point is situated: | |
91b8de8d RR |
50 | |
51 | static const int wxTREE_HITTEST_ABOVE = 0x0001; | |
52 | static const int wxTREE_HITTEST_BELOW = 0x0002; | |
4f22cf8d | 53 | static const int wxTREE_HITTEST_NOWHERE = 0x0004; |
91b8de8d RR |
54 | // on the button associated with an item. |
55 | static const int wxTREE_HITTEST_ONITEMBUTTON = 0x0008; | |
4f22cf8d | 56 | // on the bitmap associated with an item. |
91b8de8d RR |
57 | static const int wxTREE_HITTEST_ONITEMICON = 0x0010; |
58 | // on the ident associated with an item. | |
59 | static const int wxTREE_HITTEST_ONITEMIDENT = 0x0020; | |
60 | // on the label (string) associated with an item. | |
61 | static const int wxTREE_HITTEST_ONITEMLABEL = 0x0040; | |
62 | // on the right of the label associated with an item. | |
63 | static const int wxTREE_HITTEST_ONITEMRIGHT = 0x0080; | |
4f22cf8d | 64 | // on the label (string) associated with an item. |
91b8de8d RR |
65 | //static const int wxTREE_HITTEST_ONITEMSTATEICON = 0x0100; |
66 | // on the left of the wxTreeCtrl. | |
67 | static const int wxTREE_HITTEST_TOLEFT = 0x0200; | |
68 | // on the right of the wxTreeCtrl. | |
69 | static const int wxTREE_HITTEST_TORIGHT = 0x0400; | |
70 | // on the upper part (first half) of the item. | |
71 | static const int wxTREE_HITTEST_ONITEMUPPERPART = 0x0800; | |
72 | // on the lower part (second half) of the item. | |
73 | static const int wxTREE_HITTEST_ONITEMLOWERPART = 0x1000; | |
74 | ||
4f22cf8d RR |
75 | // anywhere on the item |
76 | static const int wxTREE_HITTEST_ONITEM = wxTREE_HITTEST_ONITEMICON | | |
77 | wxTREE_HITTEST_ONITEMLABEL; | |
fdd8d7b5 | 78 | |
f135ff73 VZ |
79 | // ----------------------------------------------------------------------------- |
80 | // forward declaration | |
81 | // ----------------------------------------------------------------------------- | |
c801d85f | 82 | |
f135ff73 | 83 | class wxImageList; |
c801d85f | 84 | class wxGenericTreeItem; |
c801d85f | 85 | |
f135ff73 | 86 | class wxTreeItemData; |
74bedbeb | 87 | |
f135ff73 VZ |
88 | // ----------------------------------------------------------------------------- |
89 | // wxTreeItemId - unique identifier of a tree element | |
90 | // ----------------------------------------------------------------------------- | |
c801d85f | 91 | |
f135ff73 VZ |
92 | class WXDLLEXPORT wxTreeItemId |
93 | { | |
94 | friend class wxTreeCtrl; | |
95 | friend class wxTreeEvent; | |
96 | public: | |
97 | // ctors | |
98 | // 0 is invalid value for HTREEITEM | |
99 | wxTreeItemId() { m_pItem = 0; } | |
100 | ||
101 | // default copy ctor/assignment operator are ok for us | |
102 | ||
103 | // accessors | |
104 | // is this a valid tree item? | |
105 | bool IsOk() const { return m_pItem != 0; } | |
c801d85f | 106 | |
f135ff73 VZ |
107 | // deprecated: only for compatibility |
108 | wxTreeItemId(long itemId) { m_pItem = (wxGenericTreeItem *)itemId; } | |
109 | operator long() const { return (long)m_pItem; } | |
110 | ||
6daa0637 | 111 | //protected: // not for gcc |
f135ff73 VZ |
112 | // for wxTreeCtrl usage only |
113 | wxTreeItemId(wxGenericTreeItem *pItem) { m_pItem = pItem; } | |
ef44a621 | 114 | |
f135ff73 | 115 | wxGenericTreeItem *m_pItem; |
c801d85f KB |
116 | }; |
117 | ||
91b8de8d RR |
118 | WX_DECLARE_OBJARRAY(wxTreeItemId, wxArrayTreeItemIds); |
119 | ||
f135ff73 VZ |
120 | // ---------------------------------------------------------------------------- |
121 | // wxTreeItemData is some (arbitrary) user class associated with some item. | |
122 | // | |
123 | // Because the objects of this class are deleted by the tree, they should | |
124 | // always be allocated on the heap! | |
125 | // ---------------------------------------------------------------------------- | |
fd0eed64 | 126 | class WXDLLEXPORT wxTreeItemData: public wxClientData |
c801d85f | 127 | { |
f135ff73 | 128 | friend class wxTreeCtrl; |
a32dd690 | 129 | public: |
f135ff73 VZ |
130 | // creation/destruction |
131 | // -------------------- | |
132 | // default ctor | |
133 | wxTreeItemData() { } | |
134 | ||
135 | // default copy ctor/assignment operator are ok | |
136 | ||
f135ff73 VZ |
137 | // accessor: get the item associated with us |
138 | const wxTreeItemId& GetId() const { return m_pItem; } | |
139 | void SetId(const wxTreeItemId& id) { m_pItem = id; } | |
c801d85f | 140 | |
f135ff73 VZ |
141 | protected: |
142 | wxTreeItemId m_pItem; | |
143 | }; | |
144 | ||
145 | // ----------------------------------------------------------------------------- | |
146 | // wxTreeEvent - the event generated by the tree control | |
147 | // ----------------------------------------------------------------------------- | |
92976ab6 | 148 | class WXDLLEXPORT wxTreeEvent : public wxNotifyEvent |
c801d85f | 149 | { |
f135ff73 VZ |
150 | friend class wxTreeCtrl; |
151 | public: | |
152 | wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); | |
153 | ||
154 | // accessors | |
155 | // get the item on which the operation was performed or the newly | |
156 | // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events | |
157 | wxTreeItemId GetItem() const { return m_item; } | |
c801d85f | 158 | |
f135ff73 VZ |
159 | // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously |
160 | // selected item | |
161 | wxTreeItemId GetOldItem() const { return m_itemOld; } | |
c801d85f | 162 | |
f135ff73 VZ |
163 | // the point where the mouse was when the drag operation started (for |
164 | // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) | |
165 | wxPoint GetPoint() const { return m_pointDrag; } | |
64693098 | 166 | |
f135ff73 VZ |
167 | // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only) |
168 | int GetCode() const { return m_code; } | |
169 | ||
170 | // set return code for wxEVT_COMMAND_TREE_ITEM_{EXPAND|COLLAPS}ING events | |
171 | // call this to forbid the change in item status | |
172 | void Veto() { m_code = TRUE; } | |
173 | ||
174 | // for implementation usage only | |
175 | bool WasVetoed() const { return m_code; } | |
176 | ||
177 | private: | |
178 | // @@ we could save some space by using union here | |
179 | int m_code; | |
180 | wxTreeItemId m_item, | |
181 | m_itemOld; | |
182 | wxPoint m_pointDrag; | |
183 | ||
184 | DECLARE_DYNAMIC_CLASS(wxTreeEvent) | |
c801d85f KB |
185 | }; |
186 | ||
187 | typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); | |
188 | ||
f135ff73 VZ |
189 | // ---------------------------------------------------------------------------- |
190 | // macros for handling tree control events | |
191 | // ---------------------------------------------------------------------------- | |
192 | ||
193 | // GetItem() returns the item being dragged, GetPoint() the mouse coords | |
c67daf87 UR |
194 | #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, |
195 | #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
f135ff73 VZ |
196 | |
197 | // GetItem() returns the itme whose label is being edited | |
c67daf87 UR |
198 | #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, |
199 | #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
f135ff73 VZ |
200 | |
201 | // provide/update information about GetItem() item | |
c67daf87 UR |
202 | #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, |
203 | #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
f135ff73 | 204 | |
ef44a621 | 205 | // GetItem() is the item being expanded/collapsed, the "ING" versions can use |
c67daf87 UR |
206 | #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, |
207 | #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
208 | #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
f135ff73 | 209 | #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, |
c801d85f | 210 | |
f135ff73 VZ |
211 | // GetOldItem() is the item which had the selection previously, GetItem() is |
212 | // the item which acquires selection | |
213 | #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
214 | #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
c801d85f | 215 | |
f135ff73 VZ |
216 | // GetCode() returns the key code |
217 | // NB: this is the only message for which GetItem() is invalid (you may get the | |
218 | // item from GetSelection()) | |
219 | #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
c801d85f | 220 | |
f135ff73 VZ |
221 | // GetItem() returns the item being deleted, the associated data (if any) will |
222 | // be deleted just after the return of this event handler (if any) | |
223 | #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, | |
224 | ||
435fe83e RR |
225 | // GetItem() returns the item that was activated (double click, enter, space) |
226 | #define EVT_TREE_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL }, | |
227 | ||
f135ff73 VZ |
228 | // ----------------------------------------------------------------------------- |
229 | // wxTreeCtrl - the tree control | |
230 | // ----------------------------------------------------------------------------- | |
c801d85f | 231 | |
f135ff73 | 232 | class WXDLLEXPORT wxTreeCtrl : public wxScrolledWindow |
c801d85f | 233 | { |
a32dd690 | 234 | public: |
f135ff73 VZ |
235 | // creation |
236 | // -------- | |
237 | wxTreeCtrl() { Init(); } | |
238 | ||
239 | wxTreeCtrl(wxWindow *parent, wxWindowID id = -1, | |
240 | const wxPoint& pos = wxDefaultPosition, | |
241 | const wxSize& size = wxDefaultSize, | |
242 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, | |
bfc6fde4 | 243 | const wxValidator &validator = wxDefaultValidator, |
62448488 | 244 | const wxString& name = wxTreeCtrlNameStr) |
f135ff73 | 245 | { |
4f22cf8d | 246 | Create(parent, id, pos, size, style, validator, name); |
f135ff73 VZ |
247 | } |
248 | ||
249 | virtual ~wxTreeCtrl(); | |
250 | ||
251 | bool Create(wxWindow *parent, wxWindowID id = -1, | |
252 | const wxPoint& pos = wxDefaultPosition, | |
253 | const wxSize& size = wxDefaultSize, | |
254 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, | |
bfc6fde4 | 255 | const wxValidator &validator = wxDefaultValidator, |
62448488 | 256 | const wxString& name = wxTreeCtrlNameStr); |
f135ff73 VZ |
257 | |
258 | // accessors | |
259 | // --------- | |
260 | ||
261 | // get the total number of items in the control | |
262 | size_t GetCount() const; | |
263 | ||
264 | // indent is the number of pixels the children are indented relative to | |
265 | // the parents position. SetIndent() also redraws the control | |
266 | // immediately. | |
267 | unsigned int GetIndent() const { return m_indent; } | |
268 | void SetIndent(unsigned int indent); | |
269 | ||
cf724bce RR |
270 | // spacing is the number of pixels between the start and the Text |
271 | unsigned int GetSpacing() const { return m_spacing; } | |
272 | void SetSpacing(unsigned int spacing); | |
273 | ||
f135ff73 VZ |
274 | // image list: these functions allow to associate an image list with |
275 | // the control and retrieve it. Note that the control does _not_ delete | |
276 | // the associated image list when it's deleted in order to allow image | |
277 | // lists to be shared between different controls. | |
278 | // | |
279 | // The normal image list is for the icons which correspond to the | |
280 | // normal tree item state (whether it is selected or not). | |
281 | // Additionally, the application might choose to show a state icon | |
282 | // which corresponds to an app-defined item state (for example, | |
283 | // checked/unchecked) which are taken from the state image list. | |
284 | wxImageList *GetImageList() const; | |
285 | wxImageList *GetStateImageList() const; | |
286 | ||
287 | void SetImageList(wxImageList *imageList); | |
288 | void SetStateImageList(wxImageList *imageList); | |
289 | ||
290 | // Functions to work with tree ctrl items. | |
291 | ||
292 | // accessors | |
293 | // --------- | |
294 | ||
295 | // retrieve items label | |
296 | wxString GetItemText(const wxTreeItemId& item) const; | |
297 | // get the normal item image | |
298 | int GetItemImage(const wxTreeItemId& item) const; | |
299 | // get the selected item image | |
300 | int GetItemSelectedImage(const wxTreeItemId& item) const; | |
301 | // get the data associated with the item | |
302 | wxTreeItemData *GetItemData(const wxTreeItemId& item) const; | |
303 | ||
304 | // modifiers | |
305 | // --------- | |
306 | ||
307 | // set items label | |
308 | void SetItemText(const wxTreeItemId& item, const wxString& text); | |
309 | // set the normal item image | |
310 | void SetItemImage(const wxTreeItemId& item, int image); | |
311 | // set the selected item image | |
312 | void SetItemSelectedImage(const wxTreeItemId& item, int image); | |
313 | // associate some data with the item | |
314 | void SetItemData(const wxTreeItemId& item, wxTreeItemData *data); | |
315 | ||
316 | // force appearance of [+] button near the item. This is useful to | |
317 | // allow the user to expand the items which don't have any children now | |
318 | // - but instead add them only when needed, thus minimizing memory | |
319 | // usage and loading time. | |
320 | void SetItemHasChildren(const wxTreeItemId& item, bool has = TRUE); | |
321 | ||
ef44a621 VZ |
322 | // the item will be shown in bold |
323 | void SetItemBold(const wxTreeItemId& item, bool bold = TRUE); | |
324 | ||
f135ff73 VZ |
325 | // item status inquiries |
326 | // --------------------- | |
327 | ||
328 | // is the item visible (it might be outside the view or not expanded)? | |
329 | bool IsVisible(const wxTreeItemId& item) const; | |
330 | // does the item has any children? | |
6daa0637 RR |
331 | bool HasChildren(const wxTreeItemId& item) const |
332 | { return ItemHasChildren(item); } | |
f135ff73 VZ |
333 | bool ItemHasChildren(const wxTreeItemId& item) const; |
334 | // is the item expanded (only makes sense if HasChildren())? | |
335 | bool IsExpanded(const wxTreeItemId& item) const; | |
336 | // is this item currently selected (the same as has focus)? | |
337 | bool IsSelected(const wxTreeItemId& item) const; | |
ef44a621 VZ |
338 | // is item text in bold font? |
339 | bool IsBold(const wxTreeItemId& item) const; | |
f135ff73 | 340 | |
4832f7c0 VZ |
341 | // number of children |
342 | // ------------------ | |
343 | ||
344 | // if 'recursively' is FALSE, only immediate children count, otherwise | |
345 | // the returned number is the number of all items in this branch | |
346 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); | |
347 | ||
f135ff73 VZ |
348 | // navigation |
349 | // ---------- | |
350 | ||
351 | // wxTreeItemId.IsOk() will return FALSE if there is no such item | |
352 | ||
353 | // get the root tree item | |
354 | wxTreeItemId GetRootItem() const { return m_anchor; } | |
355 | ||
356 | // get the item currently selected (may return NULL if no selection) | |
357 | wxTreeItemId GetSelection() const { return m_current; } | |
358 | ||
88ac883a | 359 | // get the items currently selected, return the number of such item |
91b8de8d | 360 | size_t GetSelections(wxArrayTreeItemIds&) const; |
88ac883a | 361 | |
f135ff73 VZ |
362 | // get the parent of this item (may return NULL if root) |
363 | wxTreeItemId GetParent(const wxTreeItemId& item) const; | |
364 | ||
365 | // for this enumeration function you must pass in a "cookie" parameter | |
366 | // which is opaque for the application but is necessary for the library | |
367 | // to make these functions reentrant (i.e. allow more than one | |
368 | // enumeration on one and the same object simultaneously). Of course, | |
369 | // the "cookie" passed to GetFirstChild() and GetNextChild() should be | |
370 | // the same! | |
371 | ||
372 | // get the first child of this item | |
373 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const; | |
374 | // get the next child | |
375 | wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const; | |
978f38c2 VZ |
376 | // get the last child of this item - this method doesn't use cookies |
377 | wxTreeItemId GetLastChild(const wxTreeItemId& item) const; | |
f135ff73 VZ |
378 | |
379 | // get the next sibling of this item | |
380 | wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; | |
381 | // get the previous sibling | |
382 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const; | |
383 | ||
384 | // get first visible item | |
385 | wxTreeItemId GetFirstVisibleItem() const; | |
386 | // get the next visible item: item must be visible itself! | |
387 | // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem() | |
388 | wxTreeItemId GetNextVisible(const wxTreeItemId& item) const; | |
389 | // get the previous visible item: item must be visible itself! | |
390 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; | |
391 | ||
392 | // operations | |
393 | // ---------- | |
394 | ||
395 | // add the root node to the tree | |
396 | wxTreeItemId AddRoot(const wxString& text, | |
397 | int image = -1, int selectedImage = -1, | |
398 | wxTreeItemData *data = NULL); | |
399 | ||
400 | // insert a new item in as the first child of the parent | |
401 | wxTreeItemId PrependItem(const wxTreeItemId& parent, | |
402 | const wxString& text, | |
403 | int image = -1, int selectedImage = -1, | |
404 | wxTreeItemData *data = NULL); | |
405 | ||
406 | // insert a new item after a given one | |
407 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
408 | const wxTreeItemId& idPrevious, | |
409 | const wxString& text, | |
410 | int image = -1, int selectedImage = -1, | |
411 | wxTreeItemData *data = NULL); | |
412 | ||
413 | // insert a new item in as the last child of the parent | |
414 | wxTreeItemId AppendItem(const wxTreeItemId& parent, | |
415 | const wxString& text, | |
416 | int image = -1, int selectedImage = -1, | |
417 | wxTreeItemData *data = NULL); | |
418 | ||
419 | // delete this item and associated data if any | |
420 | void Delete(const wxTreeItemId& item); | |
372edb9d VZ |
421 | // delete all children (but don't delete the item itself) |
422 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
423 | void DeleteChildren(const wxTreeItemId& item); | |
f135ff73 | 424 | // delete all items from the tree |
372edb9d | 425 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events |
f135ff73 VZ |
426 | void DeleteAllItems(); |
427 | ||
428 | // expand this item | |
429 | void Expand(const wxTreeItemId& item); | |
430 | // collapse the item without removing its children | |
431 | void Collapse(const wxTreeItemId& item); | |
432 | // collapse the item and remove all children | |
433 | void CollapseAndReset(const wxTreeItemId& item); | |
434 | // toggles the current state | |
435 | void Toggle(const wxTreeItemId& item); | |
436 | ||
437 | // remove the selection from currently selected item (if any) | |
438 | void Unselect(); | |
88ac883a | 439 | void UnselectAll(); |
f135ff73 | 440 | // select this item |
c0de7af4 | 441 | void SelectItem(const wxTreeItemId& item, bool unselect_others=TRUE, bool extended_select=FALSE); |
f135ff73 VZ |
442 | // make sure this item is visible (expanding the parent item and/or |
443 | // scrolling to this item if necessary) | |
444 | void EnsureVisible(const wxTreeItemId& item); | |
445 | // scroll to this item (but don't expand its parent) | |
446 | void ScrollTo(const wxTreeItemId& item); | |
447 | ||
4f22cf8d RR |
448 | // The first function is more portable (because easier to implement |
449 | // on other platforms), but the second one returns some extra info. | |
450 | wxTreeItemId HitTest(const wxPoint& point) | |
451 | { int dummy; return HitTest(point, dummy); } | |
452 | wxTreeItemId HitTest(const wxPoint& point, int& flags); | |
bfc6fde4 | 453 | |
f135ff73 VZ |
454 | // start editing the item label: this (temporarily) replaces the item |
455 | // with a one line edit control. The item will be selected if it hadn't | |
456 | // been before. textCtrlClass parameter allows you to create an edit | |
457 | // control of arbitrary user-defined class deriving from wxTextCtrl. | |
458 | wxTextCtrl* EditLabel(const wxTreeItemId& item, | |
459 | wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl)); | |
460 | // returns the same pointer as StartEdit() if the item is being edited, | |
461 | // NULL otherwise (it's assumed that no more than one item may be | |
462 | // edited simultaneously) | |
463 | wxTextCtrl* GetEditControl() const; | |
464 | // end editing and accept or discard the changes to item label | |
465 | void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE); | |
466 | ||
e1ee62bd VZ |
467 | // sorting |
468 | // this function is called to compare 2 items and should return -1, 0 | |
469 | // or +1 if the first item is less than, equal to or greater than the | |
470 | // second one. The base class version performs alphabetic comparaison | |
471 | // of item labels (GetText) | |
472 | virtual int OnCompareItems(const wxTreeItemId& item1, | |
473 | const wxTreeItemId& item2); | |
474 | // sort the children of this item using OnCompareItems | |
f135ff73 | 475 | // |
e1ee62bd VZ |
476 | // NB: this function is not reentrant and not MT-safe (FIXME)! |
477 | void SortChildren(const wxTreeItemId& item); | |
f135ff73 | 478 | |
a43a4f9d | 479 | // callbacks |
3db7be80 RR |
480 | void OnPaint( wxPaintEvent &event ); |
481 | void OnSetFocus( wxFocusEvent &event ); | |
482 | void OnKillFocus( wxFocusEvent &event ); | |
f135ff73 | 483 | void OnChar( wxKeyEvent &event ); |
3db7be80 RR |
484 | void OnMouse( wxMouseEvent &event ); |
485 | void OnIdle( wxIdleEvent &event ); | |
f135ff73 | 486 | |
a43a4f9d VZ |
487 | // implementation |
488 | void SendDeleteEvent(wxGenericTreeItem *itemBeingDeleted); | |
489 | ||
91b8de8d RR |
490 | // Draw Special Information |
491 | void DrawBorder(wxTreeItemId& item); | |
492 | void DrawLine(wxTreeItemId& item, bool below); | |
493 | ||
f135ff73 | 494 | protected: |
91b8de8d RR |
495 | friend class wxGenericTreeItem; |
496 | ||
f135ff73 | 497 | wxGenericTreeItem *m_anchor; |
91b8de8d | 498 | wxGenericTreeItem *m_current, *m_key_current; |
f135ff73 | 499 | bool m_hasFocus; |
3db7be80 | 500 | bool m_dirty; |
f135ff73 VZ |
501 | int m_xScroll,m_yScroll; |
502 | unsigned int m_indent; | |
cf724bce | 503 | unsigned int m_spacing; |
f135ff73 VZ |
504 | int m_lineHeight; |
505 | wxPen m_dottedPen; | |
506 | wxBrush *m_hilightBrush; | |
507 | wxImageList *m_imageListNormal, | |
508 | *m_imageListState; | |
bbe0af5b | 509 | int m_dragCount; |
f135ff73 VZ |
510 | |
511 | // the common part of all ctors | |
512 | void Init(); | |
513 | ||
514 | // misc helpers | |
515 | wxTreeItemId DoInsertItem(const wxTreeItemId& parent, | |
516 | size_t previous, | |
517 | const wxString& text, | |
518 | int image, int selectedImage, | |
519 | wxTreeItemData *data); | |
520 | ||
521 | void AdjustMyScrollbars(); | |
91b8de8d | 522 | int GetLineHeight(wxGenericTreeItem *item) const; |
ef44a621 VZ |
523 | void PaintLevel( wxGenericTreeItem *item, wxDC& dc, int level, int &y ); |
524 | void PaintItem( wxGenericTreeItem *item, wxDC& dc); | |
f135ff73 VZ |
525 | |
526 | void CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y ); | |
527 | void CalculatePositions(); | |
91b8de8d | 528 | void CalculateSize( wxGenericTreeItem *item, wxDC &dc ); |
f135ff73 VZ |
529 | |
530 | void RefreshSubtree( wxGenericTreeItem *item ); | |
531 | void RefreshLine( wxGenericTreeItem *item ); | |
43fa96a8 | 532 | |
91b8de8d | 533 | void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const; |
88ac883a VZ |
534 | void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 ); |
535 | bool TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select); | |
536 | bool TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select); | |
537 | void UnselectAllChildren( wxGenericTreeItem *item ); | |
538 | ||
a32dd690 | 539 | private: |
f135ff73 VZ |
540 | DECLARE_EVENT_TABLE() |
541 | DECLARE_DYNAMIC_CLASS(wxTreeCtrl) | |
c801d85f KB |
542 | }; |
543 | ||
f135ff73 VZ |
544 | #endif // _GENERIC_TREECTRL_H_ |
545 |