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