]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_treectrl.i
Cosmetic cleanup (-1 -> wxID_ANY, TRUE->true).
[wxWidgets.git] / wxPython / src / _treectrl.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _treectrl.i
3 // Purpose: SWIG interface file for wxTreeCtrl and related classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 10-June-1998
8 // RCS-ID: $Id$
9 // Copyright: (c) 2002 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include <wx/treectrl.h>
20 #include "wx/wxPython/pytree.h"
21
22 const wxChar* wx_TreeCtrlNameStr = _T("wxTreeCtrl");
23 DECLARE_DEF_STRING(_TreeCtrlNameStr);
24 %}
25
26 //---------------------------------------------------------------------------
27 %newgroup
28
29
30 // wxTreeCtrl flags
31 enum {
32 wxTR_NO_BUTTONS,
33 wxTR_HAS_BUTTONS,
34 wxTR_NO_LINES,
35 wxTR_LINES_AT_ROOT,
36
37 wxTR_SINGLE,
38 wxTR_MULTIPLE,
39 wxTR_EXTENDED,
40 wxTR_HAS_VARIABLE_ROW_HEIGHT,
41
42 wxTR_EDIT_LABELS,
43 wxTR_HIDE_ROOT,
44 wxTR_ROW_LINES,
45
46 wxTR_FULL_ROW_HIGHLIGHT,
47 wxTR_DEFAULT_STYLE,
48
49 wxTR_TWIST_BUTTONS,
50 wxTR_MAC_BUTTONS,
51 wxTR_AQUA_BUTTONS,
52 };
53
54
55 enum wxTreeItemIcon
56 {
57 wxTreeItemIcon_Normal, // not selected, not expanded
58 wxTreeItemIcon_Selected, // selected, not expanded
59 wxTreeItemIcon_Expanded, // not selected, expanded
60 wxTreeItemIcon_SelectedExpanded, // selected, expanded
61 wxTreeItemIcon_Max
62 };
63
64
65 // constants for HitTest
66 enum {
67 wxTREE_HITTEST_ABOVE,
68 wxTREE_HITTEST_BELOW,
69 wxTREE_HITTEST_NOWHERE,
70 wxTREE_HITTEST_ONITEMBUTTON,
71 wxTREE_HITTEST_ONITEMICON,
72 wxTREE_HITTEST_ONITEMINDENT,
73 wxTREE_HITTEST_ONITEMLABEL,
74 wxTREE_HITTEST_ONITEMRIGHT,
75 wxTREE_HITTEST_ONITEMSTATEICON,
76 wxTREE_HITTEST_TOLEFT,
77 wxTREE_HITTEST_TORIGHT,
78 wxTREE_HITTEST_ONITEMUPPERPART,
79 wxTREE_HITTEST_ONITEMLOWERPART,
80 wxTREE_HITTEST_ONITEM
81 };
82
83 //---------------------------------------------------------------------------
84 %newgroup
85
86 typedef void *wxTreeItemIdValue;
87
88 // wxTreeItemId identifies an element of the tree. In this implementation, it's
89 // just a trivial wrapper around Win32 HTREEITEM or a pointer to some private
90 // data structure in the generic version. It's opaque for the application and
91 // the only method which can be used by user code is IsOk().
92 class wxTreeItemId {
93 public:
94 wxTreeItemId();
95 ~wxTreeItemId();
96
97 // is this a valid tree item?
98 bool IsOk() const;
99
100 %extend {
101 bool operator==(const wxTreeItemId* other) {
102 if (!other) return False;
103 return *self == *other;
104 }
105
106 bool operator!=(const wxTreeItemId* other) {
107 if (!other) return True;
108 return *self != *other;
109 }
110 }
111
112 wxTreeItemIdValue m_pItem;
113
114
115 %pythoncode {
116 Ok = IsOk
117 def __nonzero__(self): return self.IsOk() }
118 };
119
120
121
122
123 // wxTreeItemData is some (arbitrary) user data associated with some tree
124 // item. The Python version is just a simple wrapper around a Python object
125 // that knows how to handle references properly. Using this class directly in
126 // Python code should rarely be neccessary. Just use the GetItemPyData and
127 // SetItemPyData tree methods instead of the GetItemData and SetItemData
128 // methods.
129 %name(TreeItemData) class wxPyTreeItemData {
130 public:
131 wxPyTreeItemData(PyObject* obj = NULL);
132
133 PyObject* GetData();
134 void SetData(PyObject* obj);
135
136 const wxTreeItemId& GetId();
137 void SetId(const wxTreeItemId& id);
138
139 %extend { void Destroy() { delete self; } }
140 };
141
142
143
144 #if 0 // it's not currently used anywhere...
145
146 // wxTreeItemAttr: a structure containing the visual attributes of an item
147 class wxTreeItemAttr
148 {
149 public:
150 // ctors
151 //wxTreeItemAttr() { }
152 wxTreeItemAttr(const wxColour& colText = wxNullColour,
153 const wxColour& colBack = wxNullColour,
154 const wxFont& font = wxNullFont);
155
156 // setters
157 void SetTextColour(const wxColour& colText);
158 void SetBackgroundColour(const wxColour& colBack);
159 void SetFont(const wxFont& font);
160
161 // accessors
162 bool HasTextColour();
163 bool HasBackgroundColour();
164 bool HasFont();
165
166 wxColour GetTextColour();
167 wxColour GetBackgroundColour();
168 wxFont GetFont();
169
170 %extend { void Destroy() { delete self; } }
171 };
172
173 #endif
174
175
176 //---------------------------------------------------------------------------
177 %newgroup
178
179 /* Tree control event types */
180 %constant wxEventType wxEVT_COMMAND_TREE_BEGIN_DRAG;
181 %constant wxEventType wxEVT_COMMAND_TREE_BEGIN_RDRAG;
182 %constant wxEventType wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT;
183 %constant wxEventType wxEVT_COMMAND_TREE_END_LABEL_EDIT;
184 %constant wxEventType wxEVT_COMMAND_TREE_DELETE_ITEM;
185 %constant wxEventType wxEVT_COMMAND_TREE_GET_INFO;
186 %constant wxEventType wxEVT_COMMAND_TREE_SET_INFO;
187 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDED;
188 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDING;
189 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSED;
190 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING;
191 %constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED;
192 %constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING;
193 %constant wxEventType wxEVT_COMMAND_TREE_KEY_DOWN;
194 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED;
195 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK;
196 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK;
197 %constant wxEventType wxEVT_COMMAND_TREE_END_DRAG;
198 %constant wxEventType wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK;
199
200
201
202 %pythoncode {
203
204 EVT_TREE_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_DRAG , 1)
205 EVT_TREE_BEGIN_RDRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_RDRAG , 1)
206 EVT_TREE_BEGIN_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT , 1)
207 EVT_TREE_END_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_LABEL_EDIT , 1)
208 EVT_TREE_DELETE_ITEM = wx.PyEventBinder(wxEVT_COMMAND_TREE_DELETE_ITEM , 1)
209 EVT_TREE_GET_INFO = wx.PyEventBinder(wxEVT_COMMAND_TREE_GET_INFO , 1)
210 EVT_TREE_SET_INFO = wx.PyEventBinder(wxEVT_COMMAND_TREE_SET_INFO , 1)
211 EVT_TREE_ITEM_EXPANDED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDED , 1)
212 EVT_TREE_ITEM_EXPANDING = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDING , 1)
213 EVT_TREE_ITEM_COLLAPSED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSED , 1)
214 EVT_TREE_ITEM_COLLAPSING = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSING , 1)
215 EVT_TREE_SEL_CHANGED = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGED , 1)
216 EVT_TREE_SEL_CHANGING = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGING , 1)
217 EVT_TREE_KEY_DOWN = wx.PyEventBinder(wxEVT_COMMAND_TREE_KEY_DOWN , 1)
218 EVT_TREE_ITEM_ACTIVATED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_ACTIVATED , 1)
219 EVT_TREE_ITEM_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK , 1)
220 EVT_TREE_ITEM_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, 1)
221 EVT_TREE_END_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_DRAG , 1)
222 EVT_TREE_STATE_IMAGE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, 1)
223
224 }
225
226
227
228 // wxTreeEvent is a special class for all events associated with tree controls
229 //
230 // NB: note that not all accessors make sense for all events, see the event
231 // descriptions below
232 class wxTreeEvent : public wxNotifyEvent {
233 public:
234 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
235
236 // get the item on which the operation was performed or the newly
237 // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events
238 wxTreeItemId GetItem() const;
239 void SetItem(const wxTreeItemId& item);
240
241 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
242 // selected item
243 wxTreeItemId GetOldItem() const;
244 void SetOldItem(const wxTreeItemId& item);
245
246 // the point where the mouse was when the drag operation started (for
247 // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) or click position
248 wxPoint GetPoint() const;
249 void SetPoint(const wxPoint& pt);
250
251 // keyboard data (for wxEVT_COMMAND_TREE_KEY_DOWN only)
252 const wxKeyEvent& GetKeyEvent() const;
253 int GetKeyCode() const;
254 void SetKeyEvent(const wxKeyEvent& evt);
255
256 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
257 const wxString& GetLabel() const;
258 void SetLabel(const wxString& label);
259
260 // edit cancel flag (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
261 bool IsEditCancelled() const;
262 void SetEditCanceled(bool editCancelled);
263
264 };
265
266 //---------------------------------------------------------------------------
267 %newgroup
268
269 %{ // C++ version of Python aware wxTreeCtrl
270 class wxPyTreeCtrl : public wxTreeCtrl {
271 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
272 public:
273 wxPyTreeCtrl() : wxTreeCtrl() {}
274 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
275 const wxPoint& pos,
276 const wxSize& size,
277 long style,
278 const wxValidator& validator,
279 const wxString& name) :
280 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
281
282 bool Create(wxWindow *parent, wxWindowID id,
283 const wxPoint& pos,
284 const wxSize& size,
285 long style,
286 const wxValidator& validator,
287 const wxString& name) {
288 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
289 }
290
291
292 int OnCompareItems(const wxTreeItemId& item1,
293 const wxTreeItemId& item2) {
294 int rval = 0;
295 bool found;
296 wxPyBeginBlockThreads();
297 if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) {
298 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), False);
299 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), False);
300 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2));
301 Py_DECREF(o1);
302 Py_DECREF(o2);
303 }
304 wxPyEndBlockThreads();
305 if (! found)
306 rval = wxTreeCtrl::OnCompareItems(item1, item2);
307 return rval;
308 }
309 PYPRIVATE;
310 };
311
312 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
313
314 %}
315
316
317
318
319 %name(TreeCtrl)class wxPyTreeCtrl : public wxControl {
320 public:
321 %addtofunc wxPyTreeCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeCtrl)"
322 %addtofunc wxPyTreeCtrl() ""
323
324 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
325 const wxPoint& pos = wxDefaultPosition,
326 const wxSize& size = wxDefaultSize,
327 long style = wxTR_DEFAULT_STYLE,
328 const wxValidator& validator = wxDefaultValidator,
329 const wxString& name = wxPy_TreeCtrlNameStr);
330 %name(PreTreeCtrl)wxPyTreeCtrl();
331
332 bool Create(wxWindow *parent, wxWindowID id = -1,
333 const wxPoint& pos = wxDefaultPosition,
334 const wxSize& size = wxDefaultSize,
335 long style = wxTR_DEFAULT_STYLE,
336 const wxValidator& validator = wxDefaultValidator,
337 const wxString& name = wxPy_TreeCtrlNameStr);
338
339 void _setCallbackInfo(PyObject* self, PyObject* _class);
340
341
342 // get the total number of items in the control
343 size_t GetCount() const;
344
345 // indent is the number of pixels the children are indented relative to
346 // the parents position. SetIndent() also redraws the control
347 // immediately.
348 unsigned int GetIndent() const;
349 void SetIndent(unsigned int indent);
350
351 // spacing is the number of pixels between the start and the Text
352 // not implemented under wxMSW
353 unsigned int GetSpacing() const;
354 void SetSpacing(unsigned int spacing);
355
356
357 // image list: these functions allow to associate an image list with
358 // the control and retrieve it. Note that the control does _not_ delete
359 // the associated image list when it's deleted in order to allow image
360 // lists to be shared between different controls.
361 //
362 // The normal image list is for the icons which correspond to the
363 // normal tree item state (whether it is selected or not).
364 // Additionally, the application might choose to show a state icon
365 // which corresponds to an app-defined item state (for example,
366 // checked/unchecked) which are taken from the state image list.
367 wxImageList *GetImageList() const;
368 wxImageList *GetStateImageList() const;
369
370 void SetImageList(wxImageList *imageList);
371 void SetStateImageList(wxImageList *imageList);
372
373 %addtofunc AssignImageList "args[1].thisown = 0";
374 %addtofunc AssignStateImageList "args[1].thisown = 0";
375 void AssignImageList(wxImageList *imageList);
376 void AssignStateImageList(wxImageList *imageList);
377
378
379 // retrieve items label
380 wxString GetItemText(const wxTreeItemId& item) const;
381
382 // get one of the images associated with the item (normal by default)
383 int GetItemImage(const wxTreeItemId& item,
384 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
385
386 %extend {
387 // get the wxPyTreeItemData associated with the tree item
388 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
389 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
390 if (data == NULL) {
391 data = new wxPyTreeItemData();
392 data->SetId(item); // set the id
393 self->SetItemData(item, data);
394 }
395 return data;
396 }
397 // Get the Python object associated with the tree item
398 PyObject* GetItemPyData(const wxTreeItemId& item) {
399 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
400 if (data == NULL) {
401 data = new wxPyTreeItemData();
402 data->SetId(item); // set the id
403 self->SetItemData(item, data);
404 }
405 return data->GetData();
406 }
407 }
408 %pythoncode { GetPyData = GetItemPyData }
409
410
411 // get the item's text colour
412 wxColour GetItemTextColour(const wxTreeItemId& item) const;
413
414 // get the item's background colour
415 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
416
417 // get the item's font
418 wxFont GetItemFont(const wxTreeItemId& item) const;
419
420
421
422 // set items label
423 void SetItemText(const wxTreeItemId& item, const wxString& text);
424
425 // get one of the images associated with the item (normal by default)
426 void SetItemImage(const wxTreeItemId& item, int image,
427 wxTreeItemIcon which = wxTreeItemIcon_Normal);
428
429 %extend {
430 // associate a wxPyTreeItemData with the tree item
431 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
432 data->SetId(item); // set the id
433 self->SetItemData(item, data);
434 }
435
436 // associate a Python object with the tree item
437 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
438 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
439 if (data == NULL) {
440 data = new wxPyTreeItemData(obj);
441 data->SetId(item); // set the id
442 self->SetItemData(item, data);
443 } else
444 data->SetData(obj);
445 }
446 }
447 %pythoncode { SetPyData = SetItemPyData }
448
449
450 // force appearance of [+] button near the item. This is useful to
451 // allow the user to expand the items which don't have any children now
452 // - but instead add them only when needed, thus minimizing memory
453 // usage and loading time.
454 void SetItemHasChildren(const wxTreeItemId& item, bool has = True);
455
456 // the item will be shown in bold
457 void SetItemBold(const wxTreeItemId& item, bool bold = True);
458
459 #ifdef __WXMSW__
460 // the item will be shown with a drop highlight
461 void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = True);
462 #endif
463
464 // set the items text colour
465 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
466
467 // set the items background colour
468 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
469
470 // set the items font (should be of the same height for all items)
471 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
472
473
474 // is the item visible (it might be outside the view or not expanded)?
475 bool IsVisible(const wxTreeItemId& item) const;
476
477 // does the item has any children?
478 bool ItemHasChildren(const wxTreeItemId& item) const;
479
480 // is the item expanded (only makes sense if HasChildren())?
481 bool IsExpanded(const wxTreeItemId& item) const;
482
483 // is this item currently selected (the same as has focus)?
484 bool IsSelected(const wxTreeItemId& item) const;
485
486 // is item text in bold font?
487 bool IsBold(const wxTreeItemId& item) const;
488
489
490 // if 'recursively' is False, only immediate children count, otherwise
491 // the returned number is the number of all items in this branch
492 size_t GetChildrenCount(const wxTreeItemId& item,
493 bool recursively = True) /*const*/;
494
495
496
497 // get the root tree item
498 // wxTreeItemId.IsOk() will return False if there is no such item
499 wxTreeItemId GetRootItem() const;
500
501 // get the item currently selected
502 // wxTreeItemId.IsOk() will return False if there is no such item
503 wxTreeItemId GetSelection() const;
504
505 %extend {
506 // get the items currently selected, return the number of such item
507 //
508 // NB: this operation is expensive and can take a long time for a
509 // control with a lot of items (~ O(number of items)).
510 PyObject* GetSelections() {
511 wxPyBeginBlockThreads();
512 PyObject* rval = PyList_New(0);
513 wxArrayTreeItemIds array;
514 size_t num, x;
515 num = self->GetSelections(array);
516 for (x=0; x < num; x++) {
517 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
518 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True);
519 PyList_Append(rval, item);
520 }
521 wxPyEndBlockThreads();
522 return rval;
523 }
524 }
525
526 // get the parent of this item
527 // wxTreeItemId.IsOk() will return False if there is no such item
528 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
529
530
531 %extend {
532 // Get the first child of this item. Returns a wxTreeItemId and an
533 // opaque "cookie" value that should be passed to GetNextChild in
534 // order to continue the search.
535 PyObject* GetFirstChild(const wxTreeItemId& item) {
536 wxTreeItemIdValue cookie = 0;
537 wxTreeItemId ritem = self->GetFirstChild(item, cookie);
538 wxPyBeginBlockThreads();
539 PyObject* tup = PyTuple_New(2);
540 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), True));
541 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(cookie, wxT("wxTreeItemIdValue"), True));
542 wxPyEndBlockThreads();
543 return tup;
544 }
545
546
547 // Get the next child of this item. The cookie parameter is the 2nd
548 // value returned from GetFirstChild or the previous GetNextChild.
549 // Returns a wxTreeItemId and an opaque "cookie" value that should be
550 // passed to GetNextChild in order to continue the search.
551 PyObject* GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) {
552 wxTreeItemId ritem = self->GetNextChild(item, cookie);
553 wxPyBeginBlockThreads();
554 PyObject* tup = PyTuple_New(2);
555 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), True));
556 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(cookie, wxT("wxTreeItemIdValue"), True));
557 wxPyEndBlockThreads();
558 return tup;
559 }
560 }
561
562 // get the last child of this item
563 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
564
565 // get the next sibling of this item
566 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
567
568 // get the previous sibling
569 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
570
571 // get first visible item
572 wxTreeItemId GetFirstVisibleItem() const;
573
574 // get the next visible item: item must be visible itself!
575 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
576 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
577
578 // get the previous visible item: item must be visible itself!
579 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
580
581
582
583 // add the root node to the tree
584 wxTreeItemId AddRoot(const wxString& text,
585 int image = -1, int selectedImage = -1,
586 wxPyTreeItemData *data = NULL);
587
588 // insert a new item in as the first child of the parent
589 wxTreeItemId PrependItem(const wxTreeItemId& parent,
590 const wxString& text,
591 int image = -1, int selectedImage = -1,
592 wxPyTreeItemData *data = NULL);
593
594 // insert a new item after a given one
595 wxTreeItemId InsertItem(const wxTreeItemId& parent,
596 const wxTreeItemId& idPrevious,
597 const wxString& text,
598 int image = -1, int selectedImage = -1,
599 wxPyTreeItemData *data = NULL);
600
601 // insert a new item before the one with the given index
602 %name(InsertItemBefore)
603 wxTreeItemId InsertItem(const wxTreeItemId& parent,
604 size_t index,
605 const wxString& text,
606 int image = -1, int selectedImage = -1,
607 wxPyTreeItemData *data = NULL);
608
609 // insert a new item in as the last child of the parent
610 wxTreeItemId AppendItem(const wxTreeItemId& parent,
611 const wxString& text,
612 int image = -1, int selectedImage = -1,
613 wxPyTreeItemData *data = NULL);
614
615
616
617 // delete this item and associated data if any
618 void Delete(const wxTreeItemId& item);
619
620 // delete all children (but don't delete the item itself)
621 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
622 void DeleteChildren(const wxTreeItemId& item);
623
624 // delete all items from the tree
625 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
626 void DeleteAllItems();
627
628
629 // expand this item
630 void Expand(const wxTreeItemId& item);
631
632 // collapse the item without removing its children
633 void Collapse(const wxTreeItemId& item);
634
635 // collapse the item and remove all children
636 void CollapseAndReset(const wxTreeItemId& item);
637
638 // toggles the current state
639 void Toggle(const wxTreeItemId& item);
640
641
642 // remove the selection from currently selected item (if any)
643 void Unselect();
644
645 // unselect all items (only makes sense for multiple selection control)
646 void UnselectAll();
647
648 // select this item
649 void SelectItem(const wxTreeItemId& item);
650
651 // make sure this item is visible (expanding the parent item and/or
652 // scrolling to this item if necessary)
653 void EnsureVisible(const wxTreeItemId& item);
654
655 // scroll to this item (but don't expand its parent)
656 void ScrollTo(const wxTreeItemId& item);
657
658
659
660 // start editing the item label: this (temporarily) replaces the item
661 // with a one line edit control. The item will be selected if it hadn't
662 // been before.
663 /**wxTextCtrl* */ void EditLabel(const wxTreeItemId& item);
664
665 // returns the same pointer as StartEdit() if the item is being edited,
666 // NULL otherwise (it's assumed that no more than one item may be
667 // edited simultaneously)
668 wxTextCtrl* GetEditControl() const;
669
670 #ifdef __WXMSW__
671 // end editing and accept or discard the changes to item label
672 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = False);
673 #endif
674
675
676 // Sort the children of this item using OnCompareItems, a member function
677 // that is called to compare 2 items and should return -1, 0 or +1 if the
678 // first item is less than, equal to or greater than the second one. The
679 // base class version performs alphabetic comparaison of item labels
680 // (GetText)
681 void SortChildren(const wxTreeItemId& item);
682
683
684
685 DocDeclAStr(
686 wxTreeItemId, HitTest(const wxPoint& point, int& OUTPUT),
687 "HitTest(Point point) -> (item, where)",
688 "Determine which item (if any) belongs the given point. The\n"
689 "coordinates specified are relative to the client area of tree ctrl\n"
690 "and the where return value is set to a bitmask of wxTREE_HITTEST_xxx\n"
691 "constants.\n");
692
693
694 %extend {
695 // get the bounding rectangle of the item (or of its label only)
696 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
697 wxRect rect;
698 if (self->GetBoundingRect(item, rect, textOnly)) {
699 wxPyBeginBlockThreads();
700 wxRect* r = new wxRect(rect);
701 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), True);
702 wxPyEndBlockThreads();
703 return val;
704 }
705 else
706 RETURN_NONE();
707 }
708 }
709
710
711 };
712
713
714 //---------------------------------------------------------------------------
715 %init %{
716 // Map renamed classes back to their common name for OOR
717 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
718 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
719 %}
720 //---------------------------------------------------------------------------