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