]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_treectrl.i
added more properties
[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 %property(Data, GetData, SetData, doc="See `GetData` and `SetData`");
139 %property(Id, GetId, SetId, doc="See `GetId` and `SetId`");
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 ~wxTreeItemAttr();
156
157 // setters
158 void SetTextColour(const wxColour& colText);
159 void SetBackgroundColour(const wxColour& colBack);
160 void SetFont(const wxFont& font);
161
162 // accessors
163 bool HasTextColour();
164 bool HasBackgroundColour();
165 bool HasFont();
166
167 wxColour GetTextColour();
168 wxColour GetBackgroundColour();
169 wxFont GetFont();
170
171 %pythonAppend Destroy "args[0].thisown = 0"
172 %extend { void Destroy() { delete self; } }
173 };
174
175 #endif
176
177
178 //---------------------------------------------------------------------------
179 %newgroup
180
181 /* Tree control event types */
182 %constant wxEventType wxEVT_COMMAND_TREE_BEGIN_DRAG;
183 %constant wxEventType wxEVT_COMMAND_TREE_BEGIN_RDRAG;
184 %constant wxEventType wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT;
185 %constant wxEventType wxEVT_COMMAND_TREE_END_LABEL_EDIT;
186 %constant wxEventType wxEVT_COMMAND_TREE_DELETE_ITEM;
187 %constant wxEventType wxEVT_COMMAND_TREE_GET_INFO;
188 %constant wxEventType wxEVT_COMMAND_TREE_SET_INFO;
189 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDED;
190 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDING;
191 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSED;
192 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING;
193 %constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED;
194 %constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING;
195 %constant wxEventType wxEVT_COMMAND_TREE_KEY_DOWN;
196 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED;
197 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK;
198 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK;
199 %constant wxEventType wxEVT_COMMAND_TREE_END_DRAG;
200 %constant wxEventType wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK;
201 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP;
202 %constant wxEventType wxEVT_COMMAND_TREE_ITEM_MENU;
203
204 %pythoncode {
205 EVT_TREE_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_DRAG , 1)
206 EVT_TREE_BEGIN_RDRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_RDRAG , 1)
207 EVT_TREE_BEGIN_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT , 1)
208 EVT_TREE_END_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_LABEL_EDIT , 1)
209 EVT_TREE_DELETE_ITEM = wx.PyEventBinder(wxEVT_COMMAND_TREE_DELETE_ITEM , 1)
210 EVT_TREE_GET_INFO = wx.PyEventBinder(wxEVT_COMMAND_TREE_GET_INFO , 1)
211 EVT_TREE_SET_INFO = wx.PyEventBinder(wxEVT_COMMAND_TREE_SET_INFO , 1)
212 EVT_TREE_ITEM_EXPANDED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDED , 1)
213 EVT_TREE_ITEM_EXPANDING = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDING , 1)
214 EVT_TREE_ITEM_COLLAPSED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSED , 1)
215 EVT_TREE_ITEM_COLLAPSING = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSING , 1)
216 EVT_TREE_SEL_CHANGED = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGED , 1)
217 EVT_TREE_SEL_CHANGING = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGING , 1)
218 EVT_TREE_KEY_DOWN = wx.PyEventBinder(wxEVT_COMMAND_TREE_KEY_DOWN , 1)
219 EVT_TREE_ITEM_ACTIVATED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_ACTIVATED , 1)
220 EVT_TREE_ITEM_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK , 1)
221 EVT_TREE_ITEM_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, 1)
222 EVT_TREE_END_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_DRAG , 1)
223 EVT_TREE_STATE_IMAGE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, 1)
224 EVT_TREE_ITEM_GETTOOLTIP = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, 1)
225 EVT_TREE_ITEM_MENU = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_MENU, 1)
226 }
227
228
229 %{
230 static wxTreeItemId wxNullTreeItemId;
231 %}
232 wxTreeItemId wxNullTreeItemId;
233
234
235 // wxTreeEvent is a special class for all events associated with tree controls
236 //
237 // NB: note that not all accessors make sense for all events, see the event
238 // descriptions below
239 class wxTreeEvent : public wxNotifyEvent {
240 public:
241 %nokwargs wxTreeEvent;
242 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
243 wxTreeEvent(wxEventType commandType,
244 wxPyTreeCtrl* tree,
245 wxTreeItemId& item = wxNullTreeItemId);
246
247 // get the item on which the operation was performed or the newly
248 // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events
249 wxTreeItemId GetItem() const;
250 void SetItem(const wxTreeItemId& item);
251
252 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
253 // selected item
254 wxTreeItemId GetOldItem() const;
255 void SetOldItem(const wxTreeItemId& item);
256
257 // the point where the mouse was when the drag operation started (for
258 // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) or click position
259 wxPoint GetPoint() const;
260 void SetPoint(const wxPoint& pt);
261
262 // keyboard data (for wxEVT_COMMAND_TREE_KEY_DOWN only)
263 const wxKeyEvent& GetKeyEvent() const;
264 int GetKeyCode() const;
265 void SetKeyEvent(const wxKeyEvent& evt);
266
267 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
268 const wxString& GetLabel() const;
269 void SetLabel(const wxString& label);
270
271 // edit cancel flag (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
272 bool IsEditCancelled() const;
273 void SetEditCanceled(bool editCancelled);
274
275 // Set the tooltip for the item (for EVT_TREE_ITEM_GETTOOLTIP events)
276 void SetToolTip(const wxString& toolTip);
277 wxString GetToolTip();
278
279 %property(Item, GetItem, SetItem, doc="See `GetItem` and `SetItem`");
280 %property(KeyCode, GetKeyCode, doc="See `GetKeyCode`");
281 %property(KeyEvent, GetKeyEvent, SetKeyEvent, doc="See `GetKeyEvent` and `SetKeyEvent`");
282 %property(Label, GetLabel, SetLabel, doc="See `GetLabel` and `SetLabel`");
283 %property(OldItem, GetOldItem, SetOldItem, doc="See `GetOldItem` and `SetOldItem`");
284 %property(Point, GetPoint, SetPoint, doc="See `GetPoint` and `SetPoint`");
285 %property(ToolTip, GetToolTip, SetToolTip, doc="See `GetToolTip` and `SetToolTip`");
286 %property(EditCancelled, IsEditCancelled, SetEditCanceled, doc="See `IsEditCancelled` and `SetEditCanceled`");
287 };
288
289 //---------------------------------------------------------------------------
290 %newgroup
291
292 %{ // C++ version of Python aware wxTreeCtrl
293 class wxPyTreeCtrl : public wxTreeCtrl {
294 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl)
295 public:
296 wxPyTreeCtrl() : wxTreeCtrl() {}
297 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
298 const wxPoint& pos,
299 const wxSize& size,
300 long style,
301 const wxValidator& validator,
302 const wxString& name) :
303 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
304
305 bool Create(wxWindow *parent, wxWindowID id,
306 const wxPoint& pos,
307 const wxSize& size,
308 long style,
309 const wxValidator& validator,
310 const wxString& name) {
311 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
312 }
313
314
315 int OnCompareItems(const wxTreeItemId& item1,
316 const wxTreeItemId& item2) {
317 int rval = 0;
318 bool found;
319 wxPyBlock_t blocked = wxPyBeginBlockThreads();
320 if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) {
321 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), false);
322 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), false);
323 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2));
324 Py_DECREF(o1);
325 Py_DECREF(o2);
326 }
327 wxPyEndBlockThreads(blocked);
328 if (! found)
329 rval = wxTreeCtrl::OnCompareItems(item1, item2);
330 return rval;
331 }
332 PYPRIVATE;
333 };
334
335 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
336
337 %}
338
339
340
341
342 MustHaveApp(wxPyTreeCtrl);
343
344 %rename(TreeCtrl) wxPyTreeCtrl;
345 class wxPyTreeCtrl : public wxControl {
346 public:
347 %pythonAppend wxPyTreeCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeCtrl)"
348 %pythonAppend wxPyTreeCtrl() ""
349 %typemap(out) wxPyTreeCtrl*; // turn off this typemap
350
351 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
352 const wxPoint& pos = wxDefaultPosition,
353 const wxSize& size = wxDefaultSize,
354 long style = wxTR_DEFAULT_STYLE,
355 const wxValidator& validator = wxDefaultValidator,
356 const wxString& name = wxPyTreeCtrlNameStr);
357 %RenameCtor(PreTreeCtrl, wxPyTreeCtrl());
358
359 // Turn it back on again
360 %typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1, $owner); }
361
362 bool Create(wxWindow *parent, wxWindowID id = -1,
363 const wxPoint& pos = wxDefaultPosition,
364 const wxSize& size = wxDefaultSize,
365 long style = wxTR_DEFAULT_STYLE,
366 const wxValidator& validator = wxDefaultValidator,
367 const wxString& name = wxPyTreeCtrlNameStr);
368
369 void _setCallbackInfo(PyObject* self, PyObject* _class);
370
371
372 // get the total number of items in the control
373 unsigned int GetCount() const;
374
375 // indent is the number of pixels the children are indented relative to
376 // the parents position. SetIndent() also redraws the control
377 // immediately.
378 unsigned int GetIndent() const;
379 void SetIndent(unsigned int indent);
380
381 // spacing is the number of pixels between the start and the Text
382 // not implemented under wxMSW
383 unsigned int GetSpacing() const;
384 void SetSpacing(unsigned int spacing);
385
386
387 // image list: these functions allow to associate an image list with
388 // the control and retrieve it. Note that the control does _not_ delete
389 // the associated image list when it's deleted in order to allow image
390 // lists to be shared between different controls.
391 //
392 // The normal image list is for the icons which correspond to the
393 // normal tree item state (whether it is selected or not).
394 // Additionally, the application might choose to show a state icon
395 // which corresponds to an app-defined item state (for example,
396 // checked/unchecked) which are taken from the state image list.
397 wxImageList *GetImageList() const;
398 wxImageList *GetStateImageList() const;
399
400 void SetImageList(wxImageList *imageList);
401 void SetStateImageList(wxImageList *imageList);
402
403 %disownarg( wxImageList *imageList );
404 void AssignImageList(wxImageList *imageList);
405 void AssignStateImageList(wxImageList *imageList);
406 %cleardisown( wxImageList *imageList );
407
408
409 // retrieve items label
410 wxString GetItemText(const wxTreeItemId& item) const;
411
412 // get one of the images associated with the item (normal by default)
413 int GetItemImage(const wxTreeItemId& item,
414 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
415
416 %extend {
417 // get the wxPyTreeItemData associated with the tree item
418 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
419 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
420 if (data == NULL) {
421 data = new wxPyTreeItemData();
422 data->SetId(item); // set the id
423 self->SetItemData(item, data);
424 }
425 return data;
426 }
427 // Get the Python object associated with the tree item
428 PyObject* GetItemPyData(const wxTreeItemId& item) {
429 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
430 if (data == NULL) {
431 data = new wxPyTreeItemData();
432 data->SetId(item); // set the id
433 self->SetItemData(item, data);
434 }
435 return data->GetData();
436 }
437 }
438 %pythoncode { GetPyData = GetItemPyData }
439
440
441 // get the item's text colour
442 wxColour GetItemTextColour(const wxTreeItemId& item) const;
443
444 // get the item's background colour
445 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
446
447 // get the item's font
448 wxFont GetItemFont(const wxTreeItemId& item) const;
449
450
451
452 // set items label
453 void SetItemText(const wxTreeItemId& item, const wxString& text);
454
455 // get one of the images associated with the item (normal by default)
456 void SetItemImage(const wxTreeItemId& item, int image,
457 wxTreeItemIcon which = wxTreeItemIcon_Normal);
458
459 %extend {
460 // associate a wxPyTreeItemData with the tree item
461 %disownarg( wxPyTreeItemData* data );
462 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
463 data->SetId(item); // set the id
464 self->SetItemData(item, data);
465 }
466 %cleardisown( wxPyTreeItemData* data );
467
468 // associate a Python object with the tree item
469 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
470 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
471 if (data == NULL) {
472 data = new wxPyTreeItemData(obj);
473 data->SetId(item); // set the id
474 self->SetItemData(item, data);
475 } else
476 data->SetData(obj);
477 }
478 }
479 %pythoncode { SetPyData = SetItemPyData }
480
481
482 // force appearance of [+] button near the item. This is useful to
483 // allow the user to expand the items which don't have any children now
484 // - but instead add them only when needed, thus minimizing memory
485 // usage and loading time.
486 void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
487
488 // the item will be shown in bold
489 void SetItemBold(const wxTreeItemId& item, bool bold = true);
490
491 // the item will be shown with a drop highlight
492 void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true);
493
494 // set the items text colour
495 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
496
497 // set the items background colour
498 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
499
500 // set the items font (should be of the same height for all items)
501 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
502
503
504 // is the item visible (it might be outside the view or not expanded)?
505 bool IsVisible(const wxTreeItemId& item) const;
506
507 // does the item has any children?
508 bool ItemHasChildren(const wxTreeItemId& item) const;
509
510 // is the item expanded (only makes sense if HasChildren())?
511 bool IsExpanded(const wxTreeItemId& item) const;
512
513 // is this item currently selected (the same as has focus)?
514 bool IsSelected(const wxTreeItemId& item) const;
515
516 // is item text in bold font?
517 bool IsBold(const wxTreeItemId& item) const;
518
519
520 // if 'recursively' is False, only immediate children count, otherwise
521 // the returned number is the number of all items in this branch
522 size_t GetChildrenCount(const wxTreeItemId& item,
523 bool recursively = true) /*const*/;
524
525
526
527 // get the root tree item
528 // wxTreeItemId.IsOk() will return False if there is no such item
529 wxTreeItemId GetRootItem() const;
530
531 // get the item currently selected
532 // wxTreeItemId.IsOk() will return False if there is no such item
533 wxTreeItemId GetSelection() const;
534
535 %extend {
536 // get the items currently selected, return the number of such item
537 //
538 // NB: this operation is expensive and can take a long time for a
539 // control with a lot of items (~ O(number of items)).
540 PyObject* GetSelections() {
541 wxPyBlock_t blocked = wxPyBeginBlockThreads();
542 PyObject* rval = PyList_New(0);
543 wxArrayTreeItemIds array;
544 size_t num, x;
545 num = self->GetSelections(array);
546 for (x=0; x < num; x++) {
547 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
548 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), true);
549 PyList_Append(rval, item);
550 Py_DECREF(item);
551 }
552 wxPyEndBlockThreads(blocked);
553 return rval;
554 }
555 }
556
557 // get the parent of this item
558 // wxTreeItemId.IsOk() will return False if there is no such item
559 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
560
561
562 // NOTE: These are a copy of the same methods in gizmos.i, be sure to
563 // update both at the same time. (Or find a good way to refactor!)
564 %extend {
565 // Get the first child of this item. Returns a wxTreeItemId and an
566 // opaque "cookie" value that should be passed to GetNextChild in
567 // order to continue the search.
568 PyObject* GetFirstChild(const wxTreeItemId& item) {
569 void* cookie = 0;
570 wxTreeItemId* ritem = new wxTreeItemId(self->GetFirstChild(item, cookie));
571 wxPyBlock_t blocked = wxPyBeginBlockThreads();
572 PyObject* tup = PyTuple_New(2);
573 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
574 PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void")));
575 wxPyEndBlockThreads(blocked);
576 return tup;
577 }
578
579
580 // Get the next child of this item. The cookie parameter is the 2nd
581 // value returned from GetFirstChild or the previous GetNextChild.
582 // Returns a wxTreeItemId and an opaque "cookie" value that should be
583 // passed to GetNextChild in order to continue the search.
584 PyObject* GetNextChild(const wxTreeItemId& item, void* cookie) {
585 wxTreeItemId* ritem = new wxTreeItemId(self->GetNextChild(item, cookie));
586 wxPyBlock_t blocked = wxPyBeginBlockThreads();
587 PyObject* tup = PyTuple_New(2);
588 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
589 PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void")));
590 wxPyEndBlockThreads(blocked);
591 return tup;
592 }
593 }
594
595 // get the last child of this item
596 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
597
598 // get the next sibling of this item
599 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
600
601 // get the previous sibling
602 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
603
604 // get first visible item
605 wxTreeItemId GetFirstVisibleItem() const;
606
607 // get the next visible item: item must be visible itself!
608 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
609 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
610
611 // get the previous visible item: item must be visible itself!
612 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
613
614
615 %disownarg( wxPyTreeItemData* data );
616
617 // add the root node to the tree
618 wxTreeItemId AddRoot(const wxString& text,
619 int image = -1, int selectedImage = -1,
620 wxPyTreeItemData *data = NULL);
621
622 // insert a new item in as the first child of the parent
623 wxTreeItemId PrependItem(const wxTreeItemId& parent,
624 const wxString& text,
625 int image = -1, int selectedImage = -1,
626 wxPyTreeItemData *data = NULL);
627
628 // insert a new item after a given one
629 wxTreeItemId InsertItem(const wxTreeItemId& parent,
630 const wxTreeItemId& idPrevious,
631 const wxString& text,
632 int image = -1, int selectedImage = -1,
633 wxPyTreeItemData *data = NULL);
634
635 // insert a new item before the one with the given index
636 %Rename(InsertItemBefore,
637 wxTreeItemId, InsertItem(const wxTreeItemId& parent,
638 size_t index,
639 const wxString& text,
640 int image = -1, int selectedImage = -1,
641 wxPyTreeItemData *data = NULL));
642
643 // insert a new item in as the last child of the parent
644 wxTreeItemId AppendItem(const wxTreeItemId& parent,
645 const wxString& text,
646 int image = -1, int selectedImage = -1,
647 wxPyTreeItemData *data = NULL);
648
649
650 %cleardisown( wxPyTreeItemData* data );
651
652 // delete this item and associated data if any
653 void Delete(const wxTreeItemId& item);
654
655 // delete all children (but don't delete the item itself)
656 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
657 void DeleteChildren(const wxTreeItemId& item);
658
659 // delete all items from the tree
660 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
661 void DeleteAllItems();
662
663
664 // expand this item
665 void Expand(const wxTreeItemId& item);
666
667 // expand the item and all its childs and thats childs
668 void ExpandAllChildren(const wxTreeItemId& item);
669
670 // expand all items
671 void ExpandAll();
672
673 // collapse the item without removing its children
674 void Collapse(const wxTreeItemId& item);
675
676 // collapse the item and remove all children
677 void CollapseAndReset(const wxTreeItemId& item);
678
679 // toggles the current state
680 void Toggle(const wxTreeItemId& item);
681
682
683 // remove the selection from currently selected item (if any)
684 void Unselect();
685
686 // remove the selection from the given one (multiselect mode only)
687 void UnselectItem(const wxTreeItemId& item);
688
689 // unselect all items (only makes sense for multiple selection control)
690 void UnselectAll();
691
692 // select this item
693 void SelectItem(const wxTreeItemId& item, bool select = true);
694
695 // toggle the item selection
696 void ToggleItemSelection(const wxTreeItemId& item);
697
698
699 // make sure this item is visible (expanding the parent item and/or
700 // scrolling to this item if necessary)
701 void EnsureVisible(const wxTreeItemId& item);
702
703 // scroll to this item (but don't expand its parent)
704 void ScrollTo(const wxTreeItemId& item);
705
706
707
708 // start editing the item label: this (temporarily) replaces the item
709 // with a one line edit control. The item will be selected if it hadn't
710 // been before.
711 /**wxTextCtrl* */ void EditLabel(const wxTreeItemId& item);
712
713 // returns the same pointer as StartEdit() if the item is being edited,
714 // NULL otherwise (it's assumed that no more than one item may be
715 // edited simultaneously)
716 wxTextCtrl* GetEditControl() const;
717
718 #ifdef __WXMSW__
719 // end editing and accept or discard the changes to item label
720 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = false);
721 #endif
722
723
724 // Sort the children of this item using OnCompareItems, a member function
725 // that is called to compare 2 items and should return -1, 0 or +1 if the
726 // first item is less than, equal to or greater than the second one. The
727 // base class version performs alphabetic comparaison of item labels
728 // (GetText)
729 void SortChildren(const wxTreeItemId& item);
730
731
732
733 DocDeclAStr(
734 wxTreeItemId, HitTest(const wxPoint& point, int& OUTPUT),
735 "HitTest(Point point) -> (item, where)",
736 "Determine which item (if any) belongs the given point. The coordinates
737 specified are relative to the client area of tree ctrl and the where return
738 value is set to a bitmask of wxTREE_HITTEST_xxx constants.
739 ", "");
740
741
742 %extend {
743 // get the bounding rectangle of the item (or of its label only)
744 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = false) {
745 wxRect rect;
746 if (self->GetBoundingRect(item, rect, textOnly)) {
747 wxPyBlock_t blocked = wxPyBeginBlockThreads();
748 wxRect* r = new wxRect(rect);
749 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), true);
750 wxPyEndBlockThreads(blocked);
751 return val;
752 }
753 else
754 RETURN_NONE();
755 }
756 }
757
758 #ifdef __WXMSW__
759 // set/get the item state.image (state == -1 means cycle to the next one)
760 void SetState(const wxTreeItemId& node, int state);
761 int GetState(const wxTreeItemId& node);
762 #endif
763
764 static wxVisualAttributes
765 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
766
767 void SetQuickBestSize(bool q);
768 bool GetQuickBestSize() const;
769
770 %property(Count, GetCount, doc="See `GetCount`");
771 %property(EditControl, GetEditControl, doc="See `GetEditControl`");
772 %property(FirstVisibleItem, GetFirstVisibleItem, doc="See `GetFirstVisibleItem`");
773 %property(ImageList, GetImageList, SetImageList, doc="See `GetImageList` and `SetImageList`");
774 %property(Indent, GetIndent, SetIndent, doc="See `GetIndent` and `SetIndent`");
775 %property(QuickBestSize, GetQuickBestSize, SetQuickBestSize, doc="See `GetQuickBestSize` and `SetQuickBestSize`");
776 %property(RootItem, GetRootItem, doc="See `GetRootItem`");
777 %property(Selection, GetSelection, doc="See `GetSelection`");
778 %property(Selections, GetSelections, doc="See `GetSelections`");
779 %property(Spacing, GetSpacing, SetSpacing, doc="See `GetSpacing` and `SetSpacing`");
780 %property(StateImageList, GetStateImageList, SetStateImageList, doc="See `GetStateImageList` and `SetStateImageList`");
781 };
782
783
784 //---------------------------------------------------------------------------
785 %init %{
786 // Map renamed classes back to their common name for OOR
787 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
788 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
789 %}
790 //---------------------------------------------------------------------------