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