]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/_treectrl.i
Fixed typo causing multiple file selections to always return the same single name.
[wxWidgets.git] / wxPython / src / _treectrl.i
... / ...
CommitLineData
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
23MAKE_CONST_WXSTRING2(TreeCtrlNameStr, _T("wxTreeCtrl"));
24
25//---------------------------------------------------------------------------
26%newgroup
27
28
29// wxTreeCtrl flags
30enum {
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 wxTR_MAC_BUTTONS,
50 wxTR_AQUA_BUTTONS,
51};
52
53
54enum wxTreeItemIcon
55{
56 wxTreeItemIcon_Normal, // not selected, not expanded
57 wxTreeItemIcon_Selected, // selected, not expanded
58 wxTreeItemIcon_Expanded, // not selected, expanded
59 wxTreeItemIcon_SelectedExpanded, // selected, expanded
60 wxTreeItemIcon_Max
61};
62
63
64// constants for HitTest
65enum {
66 wxTREE_HITTEST_ABOVE,
67 wxTREE_HITTEST_BELOW,
68 wxTREE_HITTEST_NOWHERE,
69 wxTREE_HITTEST_ONITEMBUTTON,
70 wxTREE_HITTEST_ONITEMICON,
71 wxTREE_HITTEST_ONITEMINDENT,
72 wxTREE_HITTEST_ONITEMLABEL,
73 wxTREE_HITTEST_ONITEMRIGHT,
74 wxTREE_HITTEST_ONITEMSTATEICON,
75 wxTREE_HITTEST_TOLEFT,
76 wxTREE_HITTEST_TORIGHT,
77 wxTREE_HITTEST_ONITEMUPPERPART,
78 wxTREE_HITTEST_ONITEMLOWERPART,
79 wxTREE_HITTEST_ONITEM
80};
81
82//---------------------------------------------------------------------------
83%newgroup
84
85
86// wxTreeItemId identifies an element of the tree. In this implementation, it's
87// just a trivial wrapper around Win32 HTREEITEM or a pointer to some private
88// data structure in the generic version. It's opaque for the application and
89// the only method which can be used by user code is IsOk().
90class wxTreeItemId {
91public:
92 wxTreeItemId();
93 ~wxTreeItemId();
94
95 // is this a valid tree item?
96 bool IsOk() const;
97
98 %extend {
99 bool operator==(const wxTreeItemId* other) {
100 if (!other) return False;
101 return *self == *other;
102 }
103
104 bool operator!=(const wxTreeItemId* other) {
105 if (!other) return True;
106 return *self != *other;
107 }
108 }
109
110 void* m_pItem;
111
112
113 %pythoncode {
114 Ok = IsOk
115 def __nonzero__(self): return self.IsOk() }
116};
117
118
119
120
121// wxTreeItemData is some (arbitrary) user data associated with some tree
122// item. The Python version is just a simple wrapper around a Python object
123// that knows how to handle references properly. Using this class directly in
124// Python code should rarely be neccessary. Just use the GetItemPyData and
125// SetItemPyData tree methods instead of the GetItemData and SetItemData
126// methods.
127%name(TreeItemData) class wxPyTreeItemData {
128public:
129 wxPyTreeItemData(PyObject* obj = NULL);
130
131 PyObject* GetData();
132 void SetData(PyObject* obj);
133
134 const wxTreeItemId& GetId();
135 void SetId(const wxTreeItemId& id);
136
137 %extend { void Destroy() { delete self; } }
138};
139
140
141
142#if 0 // it's not currently used anywhere...
143
144// wxTreeItemAttr: a structure containing the visual attributes of an item
145class wxTreeItemAttr
146{
147public:
148 // ctors
149 //wxTreeItemAttr() { }
150 wxTreeItemAttr(const wxColour& colText = wxNullColour,
151 const wxColour& colBack = wxNullColour,
152 const wxFont& font = wxNullFont);
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 %extend { void Destroy() { delete self; } }
169};
170
171#endif
172
173
174//---------------------------------------------------------------------------
175%newgroup
176
177/* Tree control event types */
178%constant wxEventType wxEVT_COMMAND_TREE_BEGIN_DRAG;
179%constant wxEventType wxEVT_COMMAND_TREE_BEGIN_RDRAG;
180%constant wxEventType wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT;
181%constant wxEventType wxEVT_COMMAND_TREE_END_LABEL_EDIT;
182%constant wxEventType wxEVT_COMMAND_TREE_DELETE_ITEM;
183%constant wxEventType wxEVT_COMMAND_TREE_GET_INFO;
184%constant wxEventType wxEVT_COMMAND_TREE_SET_INFO;
185%constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDED;
186%constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDING;
187%constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSED;
188%constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING;
189%constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED;
190%constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING;
191%constant wxEventType wxEVT_COMMAND_TREE_KEY_DOWN;
192%constant wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED;
193%constant wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK;
194%constant wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK;
195%constant wxEventType wxEVT_COMMAND_TREE_END_DRAG;
196%constant wxEventType wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK;
197%constant wxEventType wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP;
198
199
200%pythoncode {
201
202EVT_TREE_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_DRAG , 1)
203EVT_TREE_BEGIN_RDRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_RDRAG , 1)
204EVT_TREE_BEGIN_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT , 1)
205EVT_TREE_END_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_LABEL_EDIT , 1)
206EVT_TREE_DELETE_ITEM = wx.PyEventBinder(wxEVT_COMMAND_TREE_DELETE_ITEM , 1)
207EVT_TREE_GET_INFO = wx.PyEventBinder(wxEVT_COMMAND_TREE_GET_INFO , 1)
208EVT_TREE_SET_INFO = wx.PyEventBinder(wxEVT_COMMAND_TREE_SET_INFO , 1)
209EVT_TREE_ITEM_EXPANDED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDED , 1)
210EVT_TREE_ITEM_EXPANDING = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDING , 1)
211EVT_TREE_ITEM_COLLAPSED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSED , 1)
212EVT_TREE_ITEM_COLLAPSING = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSING , 1)
213EVT_TREE_SEL_CHANGED = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGED , 1)
214EVT_TREE_SEL_CHANGING = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGING , 1)
215EVT_TREE_KEY_DOWN = wx.PyEventBinder(wxEVT_COMMAND_TREE_KEY_DOWN , 1)
216EVT_TREE_ITEM_ACTIVATED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_ACTIVATED , 1)
217EVT_TREE_ITEM_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK , 1)
218EVT_TREE_ITEM_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, 1)
219EVT_TREE_END_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_DRAG , 1)
220EVT_TREE_STATE_IMAGE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, 1)
221EVT_TREE_ITEM_GETTOOLTIP = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, 1)
222}
223
224
225
226// wxTreeEvent is a special class for all events associated with tree controls
227//
228// NB: note that not all accessors make sense for all events, see the event
229// descriptions below
230class wxTreeEvent : public wxNotifyEvent {
231public:
232 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
233
234 // get the item on which the operation was performed or the newly
235 // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events
236 wxTreeItemId GetItem() const;
237 void SetItem(const wxTreeItemId& item);
238
239 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
240 // selected item
241 wxTreeItemId GetOldItem() const;
242 void SetOldItem(const wxTreeItemId& item);
243
244 // the point where the mouse was when the drag operation started (for
245 // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) or click position
246 wxPoint GetPoint() const;
247 void SetPoint(const wxPoint& pt);
248
249 // keyboard data (for wxEVT_COMMAND_TREE_KEY_DOWN only)
250 const wxKeyEvent& GetKeyEvent() const;
251 int GetKeyCode() const;
252 void SetKeyEvent(const wxKeyEvent& evt);
253
254 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
255 const wxString& GetLabel() const;
256 void SetLabel(const wxString& label);
257
258 // edit cancel flag (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
259 bool IsEditCancelled() const;
260 void SetEditCanceled(bool editCancelled);
261
262 // Set the tooltip for the item (for EVT_TREE_ITEM_GETTOOLTIP events)
263 void SetToolTip(const wxString& toolTip);
264};
265
266//---------------------------------------------------------------------------
267%newgroup
268
269%{ // C++ version of Python aware wxTreeCtrl
270class wxPyTreeCtrl : public wxTreeCtrl {
271 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
272public:
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
312IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
313
314%}
315
316
317
318
319%name(TreeCtrl)class wxPyTreeCtrl : public wxControl {
320public:
321 %pythonAppend wxPyTreeCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeCtrl)"
322 %pythonAppend 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 = wxPyTreeCtrlNameStr);
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 = wxPyTreeCtrlNameStr);
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 %apply SWIGTYPE *DISOWN { wxImageList *imageList };
374 void AssignImageList(wxImageList *imageList);
375 void AssignStateImageList(wxImageList *imageList);
376 %clear 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 void* cookie = 0;
537 wxTreeItemId* ritem = new wxTreeItemId(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, wxPyMakeSwigPtr(cookie, wxT("void")));
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, void* cookie) {
552 wxTreeItemId* ritem = new wxTreeItemId(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, wxPyMakeSwigPtr(cookie, wxT("void")));
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 // remove the selection from the given one (multiselect mode only)
646 void UnselectItem(const wxTreeItemId& item);
647
648 // unselect all items (only makes sense for multiple selection control)
649 void UnselectAll();
650
651 // select this item
652 void SelectItem(const wxTreeItemId& item, bool select = True);
653
654 // toggle the item selection
655 void ToggleItemSelection(const wxTreeItemId& item);
656
657
658 // make sure this item is visible (expanding the parent item and/or
659 // scrolling to this item if necessary)
660 void EnsureVisible(const wxTreeItemId& item);
661
662 // scroll to this item (but don't expand its parent)
663 void ScrollTo(const wxTreeItemId& item);
664
665
666
667 // start editing the item label: this (temporarily) replaces the item
668 // with a one line edit control. The item will be selected if it hadn't
669 // been before.
670 /**wxTextCtrl* */ void EditLabel(const wxTreeItemId& item);
671
672 // returns the same pointer as StartEdit() if the item is being edited,
673 // NULL otherwise (it's assumed that no more than one item may be
674 // edited simultaneously)
675 wxTextCtrl* GetEditControl() const;
676
677#ifdef __WXMSW__
678 // end editing and accept or discard the changes to item label
679 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = False);
680#endif
681
682
683 // Sort the children of this item using OnCompareItems, a member function
684 // that is called to compare 2 items and should return -1, 0 or +1 if the
685 // first item is less than, equal to or greater than the second one. The
686 // base class version performs alphabetic comparaison of item labels
687 // (GetText)
688 void SortChildren(const wxTreeItemId& item);
689
690
691
692 DocDeclAStr(
693 wxTreeItemId, HitTest(const wxPoint& point, int& OUTPUT),
694 "HitTest(Point point) -> (item, where)",
695 "Determine which item (if any) belongs the given point. The\n"
696 "coordinates specified are relative to the client area of tree ctrl\n"
697 "and the where return value is set to a bitmask of wxTREE_HITTEST_xxx\n"
698 "constants.\n");
699
700
701 %extend {
702 // get the bounding rectangle of the item (or of its label only)
703 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
704 wxRect rect;
705 if (self->GetBoundingRect(item, rect, textOnly)) {
706 wxPyBeginBlockThreads();
707 wxRect* r = new wxRect(rect);
708 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), True);
709 wxPyEndBlockThreads();
710 return val;
711 }
712 else
713 RETURN_NONE();
714 }
715 }
716
717
718};
719
720
721//---------------------------------------------------------------------------
722%init %{
723 // Map renamed classes back to their common name for OOR
724 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
725 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
726%}
727//---------------------------------------------------------------------------