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