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