]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_treectrl.i
Reworked how stock objects are initialized. They now have an
[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 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP;
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 EVT_TREE_ITEM_GETTOOLTIP = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, 1)
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 // Set the tooltip for the item (for EVT_TREE_ITEM_GETTOOLTIP events)
265 void SetToolTip(const wxString& toolTip);
266 };
267
268 //---------------------------------------------------------------------------
269 %newgroup
270
271 %{ // C++ version of Python aware wxTreeCtrl
272 class wxPyTreeCtrl : public wxTreeCtrl {
273 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
274 public:
275 wxPyTreeCtrl() : wxTreeCtrl() {}
276 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
277 const wxPoint& pos,
278 const wxSize& size,
279 long style,
280 const wxValidator& validator,
281 const wxString& name) :
282 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
283
284 bool Create(wxWindow *parent, wxWindowID id,
285 const wxPoint& pos,
286 const wxSize& size,
287 long style,
288 const wxValidator& validator,
289 const wxString& name) {
290 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
291 }
292
293
294 int OnCompareItems(const wxTreeItemId& item1,
295 const wxTreeItemId& item2) {
296 int rval = 0;
297 bool found;
298 wxPyBeginBlockThreads();
299 if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) {
300 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), False);
301 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), False);
302 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2));
303 Py_DECREF(o1);
304 Py_DECREF(o2);
305 }
306 wxPyEndBlockThreads();
307 if (! found)
308 rval = wxTreeCtrl::OnCompareItems(item1, item2);
309 return rval;
310 }
311 PYPRIVATE;
312 };
313
314 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
315
316 %}
317
318
319
320
321 %name(TreeCtrl)class wxPyTreeCtrl : public wxControl {
322 public:
323 %addtofunc wxPyTreeCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeCtrl)"
324 %addtofunc wxPyTreeCtrl() ""
325
326 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
327 const wxPoint& pos = wxDefaultPosition,
328 const wxSize& size = wxDefaultSize,
329 long style = wxTR_DEFAULT_STYLE,
330 const wxValidator& validator = wxDefaultValidator,
331 const wxString& name = wxPy_TreeCtrlNameStr);
332 %name(PreTreeCtrl)wxPyTreeCtrl();
333
334 bool Create(wxWindow *parent, wxWindowID id = -1,
335 const wxPoint& pos = wxDefaultPosition,
336 const wxSize& size = wxDefaultSize,
337 long style = wxTR_DEFAULT_STYLE,
338 const wxValidator& validator = wxDefaultValidator,
339 const wxString& name = wxPy_TreeCtrlNameStr);
340
341 void _setCallbackInfo(PyObject* self, PyObject* _class);
342
343
344 // get the total number of items in the control
345 size_t GetCount() const;
346
347 // indent is the number of pixels the children are indented relative to
348 // the parents position. SetIndent() also redraws the control
349 // immediately.
350 unsigned int GetIndent() const;
351 void SetIndent(unsigned int indent);
352
353 // spacing is the number of pixels between the start and the Text
354 // not implemented under wxMSW
355 unsigned int GetSpacing() const;
356 void SetSpacing(unsigned int spacing);
357
358
359 // image list: these functions allow to associate an image list with
360 // the control and retrieve it. Note that the control does _not_ delete
361 // the associated image list when it's deleted in order to allow image
362 // lists to be shared between different controls.
363 //
364 // The normal image list is for the icons which correspond to the
365 // normal tree item state (whether it is selected or not).
366 // Additionally, the application might choose to show a state icon
367 // which corresponds to an app-defined item state (for example,
368 // checked/unchecked) which are taken from the state image list.
369 wxImageList *GetImageList() const;
370 wxImageList *GetStateImageList() const;
371
372 void SetImageList(wxImageList *imageList);
373 void SetStateImageList(wxImageList *imageList);
374
375 %addtofunc AssignImageList "args[1].thisown = 0";
376 %addtofunc AssignStateImageList "args[1].thisown = 0";
377 void AssignImageList(wxImageList *imageList);
378 void AssignStateImageList(wxImageList *imageList);
379
380
381 // retrieve items label
382 wxString GetItemText(const wxTreeItemId& item) const;
383
384 // get one of the images associated with the item (normal by default)
385 int GetItemImage(const wxTreeItemId& item,
386 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
387
388 %extend {
389 // get the wxPyTreeItemData associated with the tree item
390 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
391 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
392 if (data == NULL) {
393 data = new wxPyTreeItemData();
394 data->SetId(item); // set the id
395 self->SetItemData(item, data);
396 }
397 return data;
398 }
399 // Get the Python object associated with the tree item
400 PyObject* GetItemPyData(const wxTreeItemId& item) {
401 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
402 if (data == NULL) {
403 data = new wxPyTreeItemData();
404 data->SetId(item); // set the id
405 self->SetItemData(item, data);
406 }
407 return data->GetData();
408 }
409 }
410 %pythoncode { GetPyData = GetItemPyData }
411
412
413 // get the item's text colour
414 wxColour GetItemTextColour(const wxTreeItemId& item) const;
415
416 // get the item's background colour
417 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
418
419 // get the item's font
420 wxFont GetItemFont(const wxTreeItemId& item) const;
421
422
423
424 // set items label
425 void SetItemText(const wxTreeItemId& item, const wxString& text);
426
427 // get one of the images associated with the item (normal by default)
428 void SetItemImage(const wxTreeItemId& item, int image,
429 wxTreeItemIcon which = wxTreeItemIcon_Normal);
430
431 %extend {
432 // associate a wxPyTreeItemData with the tree item
433 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
434 data->SetId(item); // set the id
435 self->SetItemData(item, data);
436 }
437
438 // associate a Python object with the tree item
439 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
440 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
441 if (data == NULL) {
442 data = new wxPyTreeItemData(obj);
443 data->SetId(item); // set the id
444 self->SetItemData(item, data);
445 } else
446 data->SetData(obj);
447 }
448 }
449 %pythoncode { SetPyData = SetItemPyData }
450
451
452 // force appearance of [+] button near the item. This is useful to
453 // allow the user to expand the items which don't have any children now
454 // - but instead add them only when needed, thus minimizing memory
455 // usage and loading time.
456 void SetItemHasChildren(const wxTreeItemId& item, bool has = True);
457
458 // the item will be shown in bold
459 void SetItemBold(const wxTreeItemId& item, bool bold = True);
460
461 #ifdef __WXMSW__
462 // the item will be shown with a drop highlight
463 void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = True);
464 #endif
465
466 // set the items text colour
467 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
468
469 // set the items background colour
470 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
471
472 // set the items font (should be of the same height for all items)
473 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
474
475
476 // is the item visible (it might be outside the view or not expanded)?
477 bool IsVisible(const wxTreeItemId& item) const;
478
479 // does the item has any children?
480 bool ItemHasChildren(const wxTreeItemId& item) const;
481
482 // is the item expanded (only makes sense if HasChildren())?
483 bool IsExpanded(const wxTreeItemId& item) const;
484
485 // is this item currently selected (the same as has focus)?
486 bool IsSelected(const wxTreeItemId& item) const;
487
488 // is item text in bold font?
489 bool IsBold(const wxTreeItemId& item) const;
490
491
492 // if 'recursively' is False, only immediate children count, otherwise
493 // the returned number is the number of all items in this branch
494 size_t GetChildrenCount(const wxTreeItemId& item,
495 bool recursively = True) /*const*/;
496
497
498
499 // get the root tree item
500 // wxTreeItemId.IsOk() will return False if there is no such item
501 wxTreeItemId GetRootItem() const;
502
503 // get the item currently selected
504 // wxTreeItemId.IsOk() will return False if there is no such item
505 wxTreeItemId GetSelection() const;
506
507 %extend {
508 // get the items currently selected, return the number of such item
509 //
510 // NB: this operation is expensive and can take a long time for a
511 // control with a lot of items (~ O(number of items)).
512 PyObject* GetSelections() {
513 wxPyBeginBlockThreads();
514 PyObject* rval = PyList_New(0);
515 wxArrayTreeItemIds array;
516 size_t num, x;
517 num = self->GetSelections(array);
518 for (x=0; x < num; x++) {
519 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
520 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True);
521 PyList_Append(rval, item);
522 }
523 wxPyEndBlockThreads();
524 return rval;
525 }
526 }
527
528 // get the parent of this item
529 // wxTreeItemId.IsOk() will return False if there is no such item
530 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
531
532
533 %extend {
534 // Get the first child of this item. Returns a wxTreeItemId and an
535 // opaque "cookie" value that should be passed to GetNextChild in
536 // order to continue the search.
537 PyObject* GetFirstChild(const wxTreeItemId& item) {
538 wxTreeItemIdValue cookie = 0;
539 wxTreeItemId ritem = self->GetFirstChild(item, cookie);
540 wxPyBeginBlockThreads();
541 PyObject* tup = PyTuple_New(2);
542 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), True));
543 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(cookie, wxT("wxTreeItemIdValue"), True));
544 wxPyEndBlockThreads();
545 return tup;
546 }
547
548
549 // Get the next child of this item. The cookie parameter is the 2nd
550 // value returned from GetFirstChild or the previous GetNextChild.
551 // Returns a wxTreeItemId and an opaque "cookie" value that should be
552 // passed to GetNextChild in order to continue the search.
553 PyObject* GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) {
554 wxTreeItemId ritem = self->GetNextChild(item, cookie);
555 wxPyBeginBlockThreads();
556 PyObject* tup = PyTuple_New(2);
557 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), True));
558 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(cookie, wxT("wxTreeItemIdValue"), True));
559 wxPyEndBlockThreads();
560 return tup;
561 }
562 }
563
564 // get the last child of this item
565 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
566
567 // get the next sibling of this item
568 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
569
570 // get the previous sibling
571 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
572
573 // get first visible item
574 wxTreeItemId GetFirstVisibleItem() const;
575
576 // get the next visible item: item must be visible itself!
577 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
578 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
579
580 // get the previous visible item: item must be visible itself!
581 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
582
583
584
585 // add the root node to the tree
586 wxTreeItemId AddRoot(const wxString& text,
587 int image = -1, int selectedImage = -1,
588 wxPyTreeItemData *data = NULL);
589
590 // insert a new item in as the first child of the parent
591 wxTreeItemId PrependItem(const wxTreeItemId& parent,
592 const wxString& text,
593 int image = -1, int selectedImage = -1,
594 wxPyTreeItemData *data = NULL);
595
596 // insert a new item after a given one
597 wxTreeItemId InsertItem(const wxTreeItemId& parent,
598 const wxTreeItemId& idPrevious,
599 const wxString& text,
600 int image = -1, int selectedImage = -1,
601 wxPyTreeItemData *data = NULL);
602
603 // insert a new item before the one with the given index
604 %name(InsertItemBefore)
605 wxTreeItemId InsertItem(const wxTreeItemId& parent,
606 size_t index,
607 const wxString& text,
608 int image = -1, int selectedImage = -1,
609 wxPyTreeItemData *data = NULL);
610
611 // insert a new item in as the last child of the parent
612 wxTreeItemId AppendItem(const wxTreeItemId& parent,
613 const wxString& text,
614 int image = -1, int selectedImage = -1,
615 wxPyTreeItemData *data = NULL);
616
617
618
619 // delete this item and associated data if any
620 void Delete(const wxTreeItemId& item);
621
622 // delete all children (but don't delete the item itself)
623 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
624 void DeleteChildren(const wxTreeItemId& item);
625
626 // delete all items from the tree
627 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
628 void DeleteAllItems();
629
630
631 // expand this item
632 void Expand(const wxTreeItemId& item);
633
634 // collapse the item without removing its children
635 void Collapse(const wxTreeItemId& item);
636
637 // collapse the item and remove all children
638 void CollapseAndReset(const wxTreeItemId& item);
639
640 // toggles the current state
641 void Toggle(const wxTreeItemId& item);
642
643
644 // remove the selection from currently selected item (if any)
645 void Unselect();
646
647 // unselect all items (only makes sense for multiple selection control)
648 void UnselectAll();
649
650 // select this item
651 void SelectItem(const wxTreeItemId& item);
652
653 // make sure this item is visible (expanding the parent item and/or
654 // scrolling to this item if necessary)
655 void EnsureVisible(const wxTreeItemId& item);
656
657 // scroll to this item (but don't expand its parent)
658 void ScrollTo(const wxTreeItemId& item);
659
660
661
662 // start editing the item label: this (temporarily) replaces the item
663 // with a one line edit control. The item will be selected if it hadn't
664 // been before.
665 /**wxTextCtrl* */ void EditLabel(const wxTreeItemId& item);
666
667 // returns the same pointer as StartEdit() if the item is being edited,
668 // NULL otherwise (it's assumed that no more than one item may be
669 // edited simultaneously)
670 wxTextCtrl* GetEditControl() const;
671
672 #ifdef __WXMSW__
673 // end editing and accept or discard the changes to item label
674 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = False);
675 #endif
676
677
678 // Sort the children of this item using OnCompareItems, a member function
679 // that is called to compare 2 items and should return -1, 0 or +1 if the
680 // first item is less than, equal to or greater than the second one. The
681 // base class version performs alphabetic comparaison of item labels
682 // (GetText)
683 void SortChildren(const wxTreeItemId& item);
684
685
686
687 DocDeclAStr(
688 wxTreeItemId, HitTest(const wxPoint& point, int& OUTPUT),
689 "HitTest(Point point) -> (item, where)",
690 "Determine which item (if any) belongs the given point. The\n"
691 "coordinates specified are relative to the client area of tree ctrl\n"
692 "and the where return value is set to a bitmask of wxTREE_HITTEST_xxx\n"
693 "constants.\n");
694
695
696 %extend {
697 // get the bounding rectangle of the item (or of its label only)
698 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
699 wxRect rect;
700 if (self->GetBoundingRect(item, rect, textOnly)) {
701 wxPyBeginBlockThreads();
702 wxRect* r = new wxRect(rect);
703 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), True);
704 wxPyEndBlockThreads();
705 return val;
706 }
707 else
708 RETURN_NONE();
709 }
710 }
711
712
713 };
714
715
716 //---------------------------------------------------------------------------
717 %init %{
718 // Map renamed classes back to their common name for OOR
719 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
720 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
721 %}
722 //---------------------------------------------------------------------------