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