]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: _treectrl.i | |
3 | // Purpose: SWIG interface file for wxTreeCtrl and related classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 10-June-1998 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2002 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | ||
18 | %{ | |
19 | #include <wx/treectrl.h> | |
20 | #include "wx/wxPython/pytree.h" | |
21 | %} | |
22 | ||
23 | MAKE_CONST_WXSTRING2(TreeCtrlNameStr, _T("wxTreeCtrl")); | |
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 | ||
85 | typedef void *wxTreeItemIdValue; | |
86 | ||
87 | // wxTreeItemId identifies an element of the tree. In this implementation, it's | |
88 | // just a trivial wrapper around Win32 HTREEITEM or a pointer to some private | |
89 | // data structure in the generic version. It's opaque for the application and | |
90 | // the only method which can be used by user code is IsOk(). | |
91 | class wxTreeItemId { | |
92 | public: | |
93 | wxTreeItemId(); | |
94 | ~wxTreeItemId(); | |
95 | ||
96 | // is this a valid tree item? | |
97 | bool IsOk() const; | |
98 | ||
99 | %extend { | |
100 | bool operator==(const wxTreeItemId* other) { | |
101 | if (!other) return False; | |
102 | return *self == *other; | |
103 | } | |
104 | ||
105 | bool operator!=(const wxTreeItemId* other) { | |
106 | if (!other) return True; | |
107 | return *self != *other; | |
108 | } | |
109 | } | |
110 | ||
111 | wxTreeItemIdValue m_pItem; | |
112 | ||
113 | ||
114 | %pythoncode { | |
115 | Ok = IsOk | |
116 | def __nonzero__(self): return self.IsOk() } | |
117 | }; | |
118 | ||
119 | ||
120 | ||
121 | ||
122 | // wxTreeItemData is some (arbitrary) user data associated with some tree | |
123 | // item. The Python version is just a simple wrapper around a Python object | |
124 | // that knows how to handle references properly. Using this class directly in | |
125 | // Python code should rarely be neccessary. Just use the GetItemPyData and | |
126 | // SetItemPyData tree methods instead of the GetItemData and SetItemData | |
127 | // methods. | |
128 | %name(TreeItemData) class wxPyTreeItemData { | |
129 | public: | |
130 | wxPyTreeItemData(PyObject* obj = NULL); | |
131 | ||
132 | PyObject* GetData(); | |
133 | void SetData(PyObject* obj); | |
134 | ||
135 | const wxTreeItemId& GetId(); | |
136 | void SetId(const wxTreeItemId& id); | |
137 | ||
138 | %extend { void Destroy() { delete self; } } | |
139 | }; | |
140 | ||
141 | ||
142 | ||
143 | #if 0 // it's not currently used anywhere... | |
144 | ||
145 | // wxTreeItemAttr: a structure containing the visual attributes of an item | |
146 | class wxTreeItemAttr | |
147 | { | |
148 | public: | |
149 | // ctors | |
150 | //wxTreeItemAttr() { } | |
151 | wxTreeItemAttr(const wxColour& colText = wxNullColour, | |
152 | const wxColour& colBack = wxNullColour, | |
153 | const wxFont& font = wxNullFont); | |
154 | ||
155 | // setters | |
156 | void SetTextColour(const wxColour& colText); | |
157 | void SetBackgroundColour(const wxColour& colBack); | |
158 | void SetFont(const wxFont& font); | |
159 | ||
160 | // accessors | |
161 | bool HasTextColour(); | |
162 | bool HasBackgroundColour(); | |
163 | bool HasFont(); | |
164 | ||
165 | wxColour GetTextColour(); | |
166 | wxColour GetBackgroundColour(); | |
167 | wxFont GetFont(); | |
168 | ||
169 | %extend { void Destroy() { delete self; } } | |
170 | }; | |
171 | ||
172 | #endif | |
173 | ||
174 | ||
175 | //--------------------------------------------------------------------------- | |
176 | %newgroup | |
177 | ||
178 | /* Tree control event types */ | |
179 | %constant wxEventType wxEVT_COMMAND_TREE_BEGIN_DRAG; | |
180 | %constant wxEventType wxEVT_COMMAND_TREE_BEGIN_RDRAG; | |
181 | %constant wxEventType wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT; | |
182 | %constant wxEventType wxEVT_COMMAND_TREE_END_LABEL_EDIT; | |
183 | %constant wxEventType wxEVT_COMMAND_TREE_DELETE_ITEM; | |
184 | %constant wxEventType wxEVT_COMMAND_TREE_GET_INFO; | |
185 | %constant wxEventType wxEVT_COMMAND_TREE_SET_INFO; | |
186 | %constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDED; | |
187 | %constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDING; | |
188 | %constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSED; | |
189 | %constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING; | |
190 | %constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED; | |
191 | %constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING; | |
192 | %constant wxEventType wxEVT_COMMAND_TREE_KEY_DOWN; | |
193 | %constant wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED; | |
194 | %constant wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK; | |
195 | %constant wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK; | |
196 | %constant wxEventType wxEVT_COMMAND_TREE_END_DRAG; | |
197 | %constant wxEventType wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK; | |
198 | %constant wxEventType wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP; | |
199 | ||
200 | ||
201 | %pythoncode { | |
202 | ||
203 | EVT_TREE_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_DRAG , 1) | |
204 | EVT_TREE_BEGIN_RDRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_RDRAG , 1) | |
205 | EVT_TREE_BEGIN_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT , 1) | |
206 | EVT_TREE_END_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_LABEL_EDIT , 1) | |
207 | EVT_TREE_DELETE_ITEM = wx.PyEventBinder(wxEVT_COMMAND_TREE_DELETE_ITEM , 1) | |
208 | EVT_TREE_GET_INFO = wx.PyEventBinder(wxEVT_COMMAND_TREE_GET_INFO , 1) | |
209 | EVT_TREE_SET_INFO = wx.PyEventBinder(wxEVT_COMMAND_TREE_SET_INFO , 1) | |
210 | EVT_TREE_ITEM_EXPANDED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDED , 1) | |
211 | EVT_TREE_ITEM_EXPANDING = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDING , 1) | |
212 | EVT_TREE_ITEM_COLLAPSED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSED , 1) | |
213 | EVT_TREE_ITEM_COLLAPSING = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSING , 1) | |
214 | EVT_TREE_SEL_CHANGED = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGED , 1) | |
215 | EVT_TREE_SEL_CHANGING = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGING , 1) | |
216 | EVT_TREE_KEY_DOWN = wx.PyEventBinder(wxEVT_COMMAND_TREE_KEY_DOWN , 1) | |
217 | EVT_TREE_ITEM_ACTIVATED = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_ACTIVATED , 1) | |
218 | EVT_TREE_ITEM_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK , 1) | |
219 | EVT_TREE_ITEM_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, 1) | |
220 | EVT_TREE_END_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_DRAG , 1) | |
221 | EVT_TREE_STATE_IMAGE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, 1) | |
222 | EVT_TREE_ITEM_GETTOOLTIP = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, 1) | |
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 | |
231 | class wxTreeEvent : public wxNotifyEvent { | |
232 | public: | |
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 | ||
263 | // Set the tooltip for the item (for EVT_TREE_ITEM_GETTOOLTIP events) | |
264 | void SetToolTip(const wxString& toolTip); | |
265 | }; | |
266 | ||
267 | //--------------------------------------------------------------------------- | |
268 | %newgroup | |
269 | ||
270 | %{ // C++ version of Python aware wxTreeCtrl | |
271 | class wxPyTreeCtrl : public wxTreeCtrl { | |
272 | DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl); | |
273 | public: | |
274 | wxPyTreeCtrl() : wxTreeCtrl() {} | |
275 | wxPyTreeCtrl(wxWindow *parent, wxWindowID id, | |
276 | const wxPoint& pos, | |
277 | const wxSize& size, | |
278 | long style, | |
279 | const wxValidator& validator, | |
280 | const wxString& name) : | |
281 | wxTreeCtrl(parent, id, pos, size, style, validator, name) {} | |
282 | ||
283 | bool Create(wxWindow *parent, wxWindowID id, | |
284 | const wxPoint& pos, | |
285 | const wxSize& size, | |
286 | long style, | |
287 | const wxValidator& validator, | |
288 | const wxString& name) { | |
289 | return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name); | |
290 | } | |
291 | ||
292 | ||
293 | int OnCompareItems(const wxTreeItemId& item1, | |
294 | const wxTreeItemId& item2) { | |
295 | int rval = 0; | |
296 | bool found; | |
297 | wxPyBeginBlockThreads(); | |
298 | if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) { | |
299 | PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), False); | |
300 | PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), False); | |
301 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2)); | |
302 | Py_DECREF(o1); | |
303 | Py_DECREF(o2); | |
304 | } | |
305 | wxPyEndBlockThreads(); | |
306 | if (! found) | |
307 | rval = wxTreeCtrl::OnCompareItems(item1, item2); | |
308 | return rval; | |
309 | } | |
310 | PYPRIVATE; | |
311 | }; | |
312 | ||
313 | IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl); | |
314 | ||
315 | %} | |
316 | ||
317 | ||
318 | ||
319 | ||
320 | %name(TreeCtrl)class wxPyTreeCtrl : public wxControl { | |
321 | public: | |
322 | %addtofunc wxPyTreeCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeCtrl)" | |
323 | %addtofunc wxPyTreeCtrl() "" | |
324 | ||
325 | wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1, | |
326 | const wxPoint& pos = wxDefaultPosition, | |
327 | const wxSize& size = wxDefaultSize, | |
328 | long style = wxTR_DEFAULT_STYLE, | |
329 | const wxValidator& validator = wxDefaultValidator, | |
330 | const wxString& name = wxPyTreeCtrlNameStr); | |
331 | %name(PreTreeCtrl)wxPyTreeCtrl(); | |
332 | ||
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, | |
338 | const wxString& name = wxPyTreeCtrlNameStr); | |
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 | ||
374 | %addtofunc AssignImageList "args[1].thisown = 0"; | |
375 | %addtofunc AssignStateImageList "args[1].thisown = 0"; | |
376 | void AssignImageList(wxImageList *imageList); | |
377 | void AssignStateImageList(wxImageList *imageList); | |
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. | |
455 | void SetItemHasChildren(const wxTreeItemId& item, bool has = True); | |
456 | ||
457 | // the item will be shown in bold | |
458 | void SetItemBold(const wxTreeItemId& item, bool bold = True); | |
459 | ||
460 | #ifdef __WXMSW__ | |
461 | // the item will be shown with a drop highlight | |
462 | void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = True); | |
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 | ||
491 | // if 'recursively' is False, only immediate children count, otherwise | |
492 | // the returned number is the number of all items in this branch | |
493 | size_t GetChildrenCount(const wxTreeItemId& item, | |
494 | bool recursively = True) /*const*/; | |
495 | ||
496 | ||
497 | ||
498 | // get the root tree item | |
499 | // wxTreeItemId.IsOk() will return False if there is no such item | |
500 | wxTreeItemId GetRootItem() const; | |
501 | ||
502 | // get the item currently selected | |
503 | // wxTreeItemId.IsOk() will return False if there is no such item | |
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() { | |
512 | wxPyBeginBlockThreads(); | |
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)); | |
519 | PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True); | |
520 | PyList_Append(rval, item); | |
521 | } | |
522 | wxPyEndBlockThreads(); | |
523 | return rval; | |
524 | } | |
525 | } | |
526 | ||
527 | // get the parent of this item | |
528 | // wxTreeItemId.IsOk() will return False if there is no such item | |
529 | wxTreeItemId GetItemParent(const wxTreeItemId& item) const; | |
530 | ||
531 | ||
532 | %extend { | |
533 | // Get the first child of this item. Returns a wxTreeItemId and an | |
534 | // opaque "cookie" value that should be passed to GetNextChild in | |
535 | // order to continue the search. | |
536 | PyObject* GetFirstChild(const wxTreeItemId& item) { | |
537 | wxTreeItemIdValue cookie = 0; | |
538 | wxTreeItemId ritem = self->GetFirstChild(item, cookie); | |
539 | wxPyBeginBlockThreads(); | |
540 | PyObject* tup = PyTuple_New(2); | |
541 | PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), True)); | |
542 | PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(cookie, wxT("wxTreeItemIdValue"), True)); | |
543 | wxPyEndBlockThreads(); | |
544 | return tup; | |
545 | } | |
546 | ||
547 | ||
548 | // Get the next child of this item. The cookie parameter is the 2nd | |
549 | // value returned from GetFirstChild or the previous GetNextChild. | |
550 | // Returns a wxTreeItemId and an opaque "cookie" value that should be | |
551 | // passed to GetNextChild in order to continue the search. | |
552 | PyObject* GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) { | |
553 | wxTreeItemId ritem = self->GetNextChild(item, cookie); | |
554 | wxPyBeginBlockThreads(); | |
555 | PyObject* tup = PyTuple_New(2); | |
556 | PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), True)); | |
557 | PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(cookie, wxT("wxTreeItemIdValue"), True)); | |
558 | wxPyEndBlockThreads(); | |
559 | return tup; | |
560 | } | |
561 | } | |
562 | ||
563 | // get the last child of this item | |
564 | wxTreeItemId GetLastChild(const wxTreeItemId& item) const; | |
565 | ||
566 | // get the next sibling of this item | |
567 | wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; | |
568 | ||
569 | // get the previous sibling | |
570 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const; | |
571 | ||
572 | // get first visible item | |
573 | wxTreeItemId GetFirstVisibleItem() const; | |
574 | ||
575 | // get the next visible item: item must be visible itself! | |
576 | // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem() | |
577 | wxTreeItemId GetNextVisible(const wxTreeItemId& item) const; | |
578 | ||
579 | // get the previous visible item: item must be visible itself! | |
580 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; | |
581 | ||
582 | ||
583 | ||
584 | // add the root node to the tree | |
585 | wxTreeItemId AddRoot(const wxString& text, | |
586 | int image = -1, int selectedImage = -1, | |
587 | wxPyTreeItemData *data = NULL); | |
588 | ||
589 | // insert a new item in as the first child of the parent | |
590 | wxTreeItemId PrependItem(const wxTreeItemId& parent, | |
591 | const wxString& text, | |
592 | int image = -1, int selectedImage = -1, | |
593 | wxPyTreeItemData *data = NULL); | |
594 | ||
595 | // insert a new item after a given one | |
596 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
597 | const wxTreeItemId& idPrevious, | |
598 | const wxString& text, | |
599 | int image = -1, int selectedImage = -1, | |
600 | wxPyTreeItemData *data = NULL); | |
601 | ||
602 | // insert a new item before the one with the given index | |
603 | %name(InsertItemBefore) | |
604 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
605 | size_t index, | |
606 | const wxString& text, | |
607 | int image = -1, int selectedImage = -1, | |
608 | wxPyTreeItemData *data = NULL); | |
609 | ||
610 | // insert a new item in as the last child of the parent | |
611 | wxTreeItemId AppendItem(const wxTreeItemId& parent, | |
612 | const wxString& text, | |
613 | int image = -1, int selectedImage = -1, | |
614 | wxPyTreeItemData *data = NULL); | |
615 | ||
616 | ||
617 | ||
618 | // delete this item and associated data if any | |
619 | void Delete(const wxTreeItemId& item); | |
620 | ||
621 | // delete all children (but don't delete the item itself) | |
622 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
623 | void DeleteChildren(const wxTreeItemId& item); | |
624 | ||
625 | // delete all items from the tree | |
626 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
627 | void DeleteAllItems(); | |
628 | ||
629 | ||
630 | // expand this item | |
631 | void Expand(const wxTreeItemId& item); | |
632 | ||
633 | // collapse the item without removing its children | |
634 | void Collapse(const wxTreeItemId& item); | |
635 | ||
636 | // collapse the item and remove all children | |
637 | void CollapseAndReset(const wxTreeItemId& item); | |
638 | ||
639 | // toggles the current state | |
640 | void Toggle(const wxTreeItemId& item); | |
641 | ||
642 | ||
643 | // remove the selection from currently selected item (if any) | |
644 | void Unselect(); | |
645 | ||
646 | // unselect all items (only makes sense for multiple selection control) | |
647 | void UnselectAll(); | |
648 | ||
649 | // select this item | |
650 | void SelectItem(const wxTreeItemId& item); | |
651 | ||
652 | // make sure this item is visible (expanding the parent item and/or | |
653 | // scrolling to this item if necessary) | |
654 | void EnsureVisible(const wxTreeItemId& item); | |
655 | ||
656 | // scroll to this item (but don't expand its parent) | |
657 | void ScrollTo(const wxTreeItemId& item); | |
658 | ||
659 | ||
660 | ||
661 | // start editing the item label: this (temporarily) replaces the item | |
662 | // with a one line edit control. The item will be selected if it hadn't | |
663 | // been before. | |
664 | /**wxTextCtrl* */ void EditLabel(const wxTreeItemId& item); | |
665 | ||
666 | // returns the same pointer as StartEdit() if the item is being edited, | |
667 | // NULL otherwise (it's assumed that no more than one item may be | |
668 | // edited simultaneously) | |
669 | wxTextCtrl* GetEditControl() const; | |
670 | ||
671 | #ifdef __WXMSW__ | |
672 | // end editing and accept or discard the changes to item label | |
673 | void EndEditLabel(const wxTreeItemId& item, bool discardChanges = False); | |
674 | #endif | |
675 | ||
676 | ||
677 | // Sort the children of this item using OnCompareItems, a member function | |
678 | // that is called to compare 2 items and should return -1, 0 or +1 if the | |
679 | // first item is less than, equal to or greater than the second one. The | |
680 | // base class version performs alphabetic comparaison of item labels | |
681 | // (GetText) | |
682 | void SortChildren(const wxTreeItemId& item); | |
683 | ||
684 | ||
685 | ||
686 | DocDeclAStr( | |
687 | wxTreeItemId, HitTest(const wxPoint& point, int& OUTPUT), | |
688 | "HitTest(Point point) -> (item, where)", | |
689 | "Determine which item (if any) belongs the given point. The\n" | |
690 | "coordinates specified are relative to the client area of tree ctrl\n" | |
691 | "and the where return value is set to a bitmask of wxTREE_HITTEST_xxx\n" | |
692 | "constants.\n"); | |
693 | ||
694 | ||
695 | %extend { | |
696 | // get the bounding rectangle of the item (or of its label only) | |
697 | PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) { | |
698 | wxRect rect; | |
699 | if (self->GetBoundingRect(item, rect, textOnly)) { | |
700 | wxPyBeginBlockThreads(); | |
701 | wxRect* r = new wxRect(rect); | |
702 | PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), True); | |
703 | wxPyEndBlockThreads(); | |
704 | return val; | |
705 | } | |
706 | else | |
707 | RETURN_NONE(); | |
708 | } | |
709 | } | |
710 | ||
711 | ||
712 | }; | |
713 | ||
714 | ||
715 | //--------------------------------------------------------------------------- | |
716 | %init %{ | |
717 | // Map renamed classes back to their common name for OOR | |
718 | wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData"); | |
719 | wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl"); | |
720 | %} | |
721 | //--------------------------------------------------------------------------- |