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