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