]>
Commit | Line | Data |
---|---|---|
33328cd8 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _treelist.i | |
3 | // Purpose: wxTreeListCtrl and helpers | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 12-Sept-2006 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2006 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | ||
18 | %{ | |
19 | #include "wx/treelistctrl.h" | |
20 | #include "wx/wxPython/pytree.h" | |
21 | ||
22 | %} | |
23 | ||
24 | //--------------------------------------------------------------------------- | |
25 | %newgroup | |
26 | ||
27 | ||
28 | MAKE_CONST_WXSTRING2(TreeListCtrlNameStr, wxT("treelistctrl")); | |
29 | ||
30 | ||
31 | //---------------------------------------------------------------------------- | |
32 | // wxTreeListCtrl - the multicolumn tree control | |
33 | //---------------------------------------------------------------------------- | |
34 | ||
35 | ||
36 | ||
37 | enum { | |
38 | DEFAULT_COL_WIDTH = 100 | |
39 | }; | |
40 | ||
41 | // modes for navigation | |
42 | enum { | |
43 | wxTL_MODE_NAV_FULLTREE, | |
44 | wxTL_MODE_NAV_EXPANDED, | |
45 | wxTL_MODE_NAV_VISIBLE, | |
46 | wxTL_MODE_NAV_LEVEL | |
47 | }; | |
48 | ||
49 | // modes for FindItem | |
50 | enum { | |
51 | wxTL_MODE_FIND_EXACT, | |
52 | wxTL_MODE_FIND_PARTIAL, | |
53 | wxTL_MODE_FIND_NOCASE | |
54 | }; | |
55 | ||
56 | // additional flag for HitTest | |
57 | enum { | |
58 | wxTREE_HITTEST_ONITEMCOLUMN | |
59 | }; | |
60 | %pythoncode { wx.TREE_HITTEST_ONITEMCOLUMN = TREE_HITTEST_ONITEMCOLUMN } | |
61 | ||
62 | ||
63 | // additional style flags | |
64 | enum { | |
65 | wxTR_COLUMN_LINES, // put border around items | |
66 | wxTR_VIRTUAL // The application provides items text on demand. | |
67 | }; | |
68 | %pythoncode { | |
69 | wx.TR_COLUMN_LINES = TR_COLUMN_LINES | |
70 | wxTR_VIRTUAL = TR_VIRTUAL | |
71 | } | |
72 | ||
73 | ||
74 | %pythoncode { | |
75 | %#// Compatibility aliases for old names/values | |
76 | TL_ALIGN_LEFT = wx.ALIGN_LEFT | |
77 | TL_ALIGN_RIGHT = wx.ALIGN_RIGHT | |
78 | TL_ALIGN_CENTER = wx.ALIGN_CENTER | |
79 | ||
80 | TL_SEARCH_VISIBLE = TL_MODE_NAV_VISIBLE | |
81 | TL_SEARCH_LEVEL = TL_MODE_NAV_LEVEL | |
82 | TL_SEARCH_FULL = TL_MODE_FIND_EXACT | |
83 | TL_SEARCH_PARTIAL = TL_MODE_FIND_PARTIAL | |
84 | TL_SEARCH_NOCASE = TL_MODE_FIND_NOCASE | |
85 | ||
86 | TR_DONT_ADJUST_MAC = 0 | |
87 | wx.TR_DONT_ADJUST_MAC = TR_DONT_ADJUST_MAC | |
88 | } | |
89 | ||
90 | ||
91 | ||
92 | ||
93 | class wxTreeListColumnInfo: public wxObject { | |
94 | public: | |
95 | wxTreeListColumnInfo(const wxString& text = wxPyEmptyString, | |
96 | int width = DEFAULT_COL_WIDTH, | |
97 | int flag = wxALIGN_LEFT, | |
98 | int image = -1, | |
99 | bool shown = true, | |
100 | bool edit = false); | |
101 | ||
102 | ~wxTreeListColumnInfo(); | |
103 | ||
104 | int GetAlignment() const; | |
105 | wxString GetText() const; | |
106 | int GetImage() const; | |
107 | int GetSelectedImage() const; | |
108 | size_t GetWidth() const; | |
109 | bool IsEditable() const { return m_edit; } | |
110 | bool IsShown() const { return m_shown; } | |
111 | ||
112 | // TODO: These all actually return wxTreeListColumnInfo&, any problem with doing it for Python too? | |
113 | void SetAlignment(int alignment); | |
114 | void SetText(const wxString& text); | |
115 | void SetImage(int image); | |
116 | void SetSelectedImage(int image); | |
117 | void SetWidth(size_t with); | |
118 | void SetEditable (bool edit); | |
119 | void SetShown(bool shown); | |
120 | ||
121 | }; | |
122 | ||
123 | ||
124 | ||
125 | ||
126 | %{ // C++ version of Python aware control | |
127 | class wxPyTreeListCtrl : public wxTreeListCtrl { | |
128 | DECLARE_ABSTRACT_CLASS(wxPyTreeListCtrl); | |
129 | public: | |
130 | wxPyTreeListCtrl() : wxTreeListCtrl() {} | |
131 | wxPyTreeListCtrl(wxWindow *parent, wxWindowID id, | |
132 | const wxPoint& pos, | |
133 | const wxSize& size, | |
134 | long style, | |
135 | const wxValidator &validator, | |
136 | const wxString& name) : | |
137 | wxTreeListCtrl(parent, id, pos, size, style, validator, name) {} | |
138 | ||
139 | virtual int OnCompareItems(const wxTreeItemId& item1, | |
140 | const wxTreeItemId& item2) { | |
141 | int rval = 0; | |
142 | bool found; | |
143 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
144 | if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) { | |
145 | PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), 0); | |
146 | PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), 0); | |
147 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2)); | |
148 | Py_DECREF(o1); | |
149 | Py_DECREF(o2); | |
150 | } | |
151 | wxPyEndBlockThreads(blocked); | |
152 | if (! found) | |
153 | rval = wxTreeListCtrl::OnCompareItems(item1, item2); | |
154 | return rval; | |
155 | } | |
156 | ||
157 | virtual wxString OnGetItemText( wxTreeItemData* item, long column ) const { | |
158 | wxString rval; | |
159 | bool found; | |
160 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
161 | if ((found = wxPyCBH_findCallback(m_myInst, "OnGetItemText"))) { | |
162 | PyObject* ro; | |
163 | PyObject* itemo = wxPyConstructObject((void*)&item, wxT("wxTreeItemId"), 0); | |
164 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Oi)", itemo, column)); | |
165 | Py_DECREF(itemo); | |
166 | if (ro) { | |
167 | rval = Py2wxString(ro); | |
168 | Py_DECREF(ro); | |
169 | } | |
170 | } | |
171 | wxPyEndBlockThreads(blocked); | |
172 | if (! found) | |
173 | rval = wxTreeListCtrl::OnGetItemText(item, column); | |
174 | return rval; | |
175 | } | |
176 | ||
177 | PYPRIVATE; | |
178 | }; | |
179 | ||
180 | IMPLEMENT_ABSTRACT_CLASS(wxPyTreeListCtrl, wxTreeListCtrl) | |
181 | ||
182 | %} | |
183 | ||
184 | ||
185 | ||
186 | ||
187 | ||
188 | ||
189 | MustHaveApp(wxPyTreeListCtrl); | |
190 | ||
191 | %rename(TreeListCtrl) wxPyTreeListCtrl; | |
192 | class wxPyTreeListCtrl : public wxControl | |
193 | { | |
194 | public: | |
195 | %pythonAppend wxPyTreeListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeListCtrl)" | |
196 | %pythonAppend wxPyTreeListCtrl() "" | |
197 | ||
198 | wxPyTreeListCtrl(wxWindow *parent, wxWindowID id = -1, | |
199 | const wxPoint& pos = wxDefaultPosition, | |
200 | const wxSize& size = wxDefaultSize, | |
201 | long style = wxTR_DEFAULT_STYLE, | |
202 | const wxValidator &validator = wxDefaultValidator, | |
203 | const wxString& name = wxPyTreeListCtrlNameStr ); | |
204 | %RenameCtor(PreTreeListCtrl, wxPyTreeListCtrl()); | |
205 | ||
206 | bool Create(wxWindow *parent, wxWindowID id = -1, | |
207 | const wxPoint& pos = wxDefaultPosition, | |
208 | const wxSize& size = wxDefaultSize, | |
209 | long style = wxTR_DEFAULT_STYLE, | |
210 | const wxValidator &validator = wxDefaultValidator, | |
211 | const wxString& name = wxPyTreeListCtrlNameStr ); | |
212 | ||
213 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
214 | ||
215 | ||
216 | // get the total number of items in the control | |
217 | size_t GetCount() const; | |
218 | ||
219 | // indent is the number of pixels the children are indented relative to | |
220 | // the parents position. SetIndent() also redraws the control | |
221 | // immediately. | |
222 | unsigned int GetIndent() const; | |
223 | void SetIndent(unsigned int indent); | |
224 | ||
225 | // line spacing is the space above and below the text on each line | |
226 | unsigned int GetLineSpacing() const; | |
227 | void SetLineSpacing(unsigned int spacing); | |
228 | ||
229 | // image list: these functions allow to associate an image list with | |
230 | // the control and retrieve it. Note that when assigned with | |
231 | // SetImageList, the control does _not_ delete | |
232 | // the associated image list when it's deleted in order to allow image | |
233 | // lists to be shared between different controls. If you use | |
234 | // AssignImageList, the control _does_ delete the image list. | |
235 | // | |
236 | // The normal image list is for the icons which correspond to the | |
237 | // normal tree item state (whether it is selected or not). | |
238 | // Additionally, the application might choose to show a state icon | |
239 | // which corresponds to an app-defined item state (for example, | |
240 | // checked/unchecked) which are taken from the state image list. | |
241 | wxImageList *GetImageList() const; | |
242 | wxImageList *GetStateImageList() const; | |
243 | wxImageList *GetButtonsImageList() const; | |
244 | ||
245 | void SetImageList(wxImageList *imageList); | |
246 | void SetStateImageList(wxImageList *imageList); | |
247 | void SetButtonsImageList(wxImageList *imageList); | |
248 | ||
249 | %disownarg( wxImageList *imageList ); | |
250 | void AssignImageList(wxImageList *imageList); | |
251 | void AssignStateImageList(wxImageList *imageList); | |
252 | void AssignButtonsImageList(wxImageList *imageList); | |
253 | %cleardisown( wxImageList *imageList ); | |
254 | ||
255 | ||
256 | // adds a column | |
257 | void AddColumn (const wxString& text, | |
258 | int width = DEFAULT_COL_WIDTH, | |
259 | int flag = wxALIGN_LEFT, | |
260 | int image = -1, | |
261 | bool shown = true, | |
262 | bool edit = false); | |
263 | %Rename(AddColumnInfo, void, AddColumn(const wxTreeListColumnInfo& col)); | |
264 | ||
265 | // inserts a column before the given one | |
266 | void InsertColumn (int before, | |
267 | const wxString& text, | |
268 | int width = DEFAULT_COL_WIDTH, | |
269 | int flag = wxALIGN_LEFT, | |
270 | int image = -1, | |
271 | bool shown = true, | |
272 | bool edit = false); | |
273 | %Rename(InsertColumnInfo, void, InsertColumn(size_t before, const wxTreeListColumnInfo& col)); | |
274 | ||
275 | // deletes the given column - does not delete the corresponding column | |
276 | // of each item | |
277 | void RemoveColumn(size_t column); | |
278 | ||
279 | // returns the number of columns in the ctrl | |
280 | size_t GetColumnCount() const; | |
281 | ||
282 | // tells which column is the "main" one, i.e. the "threaded" one | |
283 | void SetMainColumn(size_t column); | |
284 | size_t GetMainColumn() const; | |
285 | ||
286 | void SetColumn (int column, const wxTreeListColumnInfo& colInfo); | |
287 | wxTreeListColumnInfo& GetColumn (int column); | |
288 | ||
289 | void SetColumnText (int column, const wxString& text); | |
290 | wxString GetColumnText (int column) const; | |
291 | ||
292 | void SetColumnWidth (int column, int width); | |
293 | int GetColumnWidth (int column) const; | |
294 | ||
295 | void SetColumnAlignment (int column, int flag); | |
296 | int GetColumnAlignment (int column) const; | |
297 | ||
298 | void SetColumnImage (int column, int image); | |
299 | int GetColumnImage (int column) const; | |
300 | ||
301 | void SetColumnShown (int column, bool shown = true); | |
302 | bool IsColumnShown (int column) const; | |
303 | %pythoncode { ShowColumn = SetColumnShown } | |
304 | ||
305 | void SetColumnEditable (int column, bool edit = true); | |
306 | bool IsColumnEditable (int column) const; | |
307 | ||
308 | ||
309 | ||
310 | ||
311 | %extend { | |
312 | // retrieves item's label of the given column (main column by default) | |
313 | wxString GetItemText(const wxTreeItemId& item, int column = -1) { | |
314 | if (column < 0) column = self->GetMainColumn(); | |
315 | return self->GetItemText(item, column); | |
316 | } | |
317 | ||
318 | // get one of the images associated with the item (normal by default) | |
319 | int GetItemImage(const wxTreeItemId& item, int column = -1, | |
320 | wxTreeItemIcon which = wxTreeItemIcon_Normal) { | |
321 | if (column < 0) column = self->GetMainColumn(); | |
322 | return self->GetItemImage(item, column, which); | |
323 | } | |
324 | ||
325 | // set item's label (main column by default) | |
326 | void SetItemText(const wxTreeItemId& item, const wxString& text, int column = -1) { | |
327 | if (column < 0) column = self->GetMainColumn(); | |
328 | self->SetItemText(item, column, text); | |
329 | } | |
330 | ||
331 | // set one of the images associated with the item (normal by default) | |
332 | // the which parameter is ignored for all columns but the main one | |
333 | void SetItemImage(const wxTreeItemId& item, int image, int column = -1, | |
334 | wxTreeItemIcon which = wxTreeItemIcon_Normal) { | |
335 | if (column < 0) column = self->GetMainColumn(); | |
336 | self->SetItemImage(item, column, image, which); | |
337 | } | |
338 | ||
339 | ||
340 | // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData | |
341 | // if needed. | |
342 | wxPyTreeItemData* GetItemData(const wxTreeItemId& item) { | |
343 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
344 | if (data == NULL) { | |
345 | data = new wxPyTreeItemData(); | |
346 | data->SetId(item); // set the id | |
347 | self->SetItemData(item, data); | |
348 | } | |
349 | return data; | |
350 | } | |
351 | ||
352 | %disownarg( wxPyTreeItemData* data ); | |
353 | void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { | |
354 | data->SetId(item); // set the id | |
355 | self->SetItemData(item, data); | |
356 | } | |
357 | %cleardisown(wxPyTreeItemData* data ); | |
358 | ||
359 | // [Get|Set]ItemPyData are short-cuts. Also made somewhat crash-proof by | |
360 | // automatically creating data classes. | |
361 | PyObject* GetItemPyData(const wxTreeItemId& item) { | |
362 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
363 | if (data == NULL) { | |
364 | data = new wxPyTreeItemData(); | |
365 | data->SetId(item); // set the id | |
366 | self->SetItemData(item, data); | |
367 | } | |
368 | return data->GetData(); | |
369 | } | |
370 | ||
371 | void SetItemPyData(const wxTreeItemId& item, PyObject* obj) { | |
372 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
373 | if (data == NULL) { | |
374 | data = new wxPyTreeItemData(obj); | |
375 | data->SetId(item); // set the id | |
376 | self->SetItemData(item, data); | |
377 | } else | |
378 | data->SetData(obj); | |
379 | } | |
380 | } | |
381 | %pythoncode { GetPyData = GetItemPyData } | |
382 | %pythoncode { SetPyData = SetItemPyData } | |
383 | ||
384 | ||
385 | bool GetItemBold(const wxTreeItemId& item) const; | |
386 | wxColour GetItemTextColour(const wxTreeItemId& item) const; | |
387 | wxColour GetItemBackgroundColour(const wxTreeItemId& item) const; | |
388 | wxFont GetItemFont(const wxTreeItemId& item) const; | |
389 | ||
390 | ||
391 | // force appearance of [+] button near the item. This is useful to | |
392 | // allow the user to expand the items which don't have any children now | |
393 | // - but instead add them only when needed, thus minimizing memory | |
394 | // usage and loading time. | |
395 | void SetItemHasChildren(const wxTreeItemId& item, bool has = true); | |
396 | ||
397 | // the item will be shown in bold | |
398 | void SetItemBold(const wxTreeItemId& item, bool bold = true); | |
399 | ||
400 | // set the item's text colour | |
401 | void SetItemTextColour(const wxTreeItemId& item, const wxColour& colour); | |
402 | ||
403 | // set the item's background colour | |
404 | void SetItemBackgroundColour(const wxTreeItemId& item, | |
405 | const wxColour& colour); | |
406 | ||
407 | // set the item's font (should be of the same height for all items) | |
408 | void SetItemFont(const wxTreeItemId& item, const wxFont& font); | |
409 | ||
410 | ||
411 | ||
412 | // is the item visible (it might be outside the view or not expanded)? | |
413 | bool IsVisible(const wxTreeItemId& item) const; | |
414 | ||
415 | // does the item has any children? | |
416 | bool HasChildren(const wxTreeItemId& item) const; | |
417 | %pythoncode { ItemHasChildren = HasChildren } | |
418 | ||
419 | // is the item expanded (only makes sense if HasChildren())? | |
420 | bool IsExpanded(const wxTreeItemId& item) const; | |
421 | ||
422 | // is this item currently selected (the same as has focus)? | |
423 | bool IsSelected(const wxTreeItemId& item) const; | |
424 | ||
425 | // is item text in bold font? | |
426 | bool IsBold(const wxTreeItemId& item) const; | |
427 | ||
428 | ||
429 | // if 'recursively' is False, only immediate children count, otherwise | |
430 | // the returned number is the number of all items in this branch | |
431 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = true); | |
432 | ||
433 | ||
434 | // wxTreeItemId.IsOk() will return False if there is no such item | |
435 | ||
436 | // get the root tree item | |
437 | wxTreeItemId GetRootItem() const; | |
438 | ||
439 | // get the item currently selected (may return NULL if no selection) | |
440 | wxTreeItemId GetSelection() const; | |
441 | ||
442 | // get the items currently selected, return the number of such item | |
443 | //size_t GetSelections(wxArrayTreeItemIds&) const; | |
444 | %extend { | |
445 | PyObject* GetSelections() { | |
446 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
447 | PyObject* rval = PyList_New(0); | |
448 | wxArrayTreeItemIds array; | |
449 | size_t num, x; | |
450 | num = self->GetSelections(array); | |
451 | for (x=0; x < num; x++) { | |
452 | wxTreeItemId *tii = new wxTreeItemId(array.Item(x)); | |
453 | PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), true); | |
454 | PyList_Append(rval, item); | |
455 | Py_DECREF(item); | |
456 | } | |
457 | wxPyEndBlockThreads(blocked); | |
458 | return rval; | |
459 | } | |
460 | } | |
461 | ||
462 | ||
463 | // get the parent of this item (may return NULL if root) | |
464 | wxTreeItemId GetItemParent(const wxTreeItemId& item) const; | |
465 | ||
466 | // for this enumeration function you must pass in a "cookie" parameter | |
467 | // which is opaque for the application but is necessary for the library | |
468 | // to make these functions reentrant (i.e. allow more than one | |
469 | // enumeration on one and the same object simultaneously). Of course, | |
470 | // the "cookie" passed to GetFirstChild() and GetNextChild() should be | |
471 | // the same! | |
472 | ||
473 | ||
474 | // NOTE: These are a copy of the same methods in _treectrl.i, be sure to | |
475 | // update both at the same time. (Or find a good way to refactor!) | |
476 | %extend { | |
477 | // Get the first child of this item. Returns a wxTreeItemId and an | |
478 | // opaque "cookie" value that should be passed to GetNextChild in | |
479 | // order to continue the search. | |
480 | PyObject* GetFirstChild(const wxTreeItemId& item) { | |
481 | void* cookie = 0; | |
482 | wxTreeItemId* ritem = new wxTreeItemId(self->GetFirstChild(item, cookie)); | |
483 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
484 | PyObject* tup = PyTuple_New(2); | |
485 | PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true)); | |
486 | PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void"))); | |
487 | wxPyEndBlockThreads(blocked); | |
488 | return tup; | |
489 | } | |
490 | ||
491 | ||
492 | // Get the next child of this item. The cookie parameter is the 2nd | |
493 | // value returned from GetFirstChild or the previous GetNextChild. | |
494 | // Returns a wxTreeItemId and an opaque "cookie" value that should be | |
495 | // passed to GetNextChild in order to continue the search. | |
496 | PyObject* GetNextChild(const wxTreeItemId& item, void* cookie) { | |
497 | wxTreeItemId* ritem = new wxTreeItemId(self->GetNextChild(item, cookie)); | |
498 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
499 | PyObject* tup = PyTuple_New(2); | |
500 | PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true)); | |
501 | PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void"))); | |
502 | wxPyEndBlockThreads(blocked); | |
503 | return tup; | |
504 | } | |
505 | ||
506 | ||
507 | PyObject* GetLastChild(const wxTreeItemId& item) { | |
508 | void* cookie = 0; | |
509 | wxTreeItemId* ritem = new wxTreeItemId(self->GetLastChild(item, cookie)); | |
510 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
511 | PyObject* tup = PyTuple_New(2); | |
512 | PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true)); | |
513 | PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void"))); | |
514 | wxPyEndBlockThreads(blocked); | |
515 | return tup; | |
516 | } | |
517 | ||
518 | ||
519 | PyObject* GetPrevChild(const wxTreeItemId& item, void* cookie) { | |
520 | wxTreeItemId* ritem = new wxTreeItemId(self->GetPrevChild(item, cookie)); | |
521 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
522 | PyObject* tup = PyTuple_New(2); | |
523 | PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true)); | |
524 | PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void"))); | |
525 | wxPyEndBlockThreads(blocked); | |
526 | return tup; | |
527 | } | |
528 | } | |
529 | ||
530 | ||
531 | // get the next sibling of this item | |
532 | wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; | |
533 | ||
534 | // get the previous sibling | |
535 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const; | |
536 | ||
537 | ||
538 | // get item in the full tree (currently only for internal use) | |
539 | wxTreeItemId GetNext(const wxTreeItemId& item) const; | |
540 | wxTreeItemId GetPrev(const wxTreeItemId& item) const; | |
541 | ||
542 | // get expanded item, see IsExpanded() | |
543 | wxTreeItemId GetFirstExpandedItem() const; | |
544 | wxTreeItemId GetNextExpanded(const wxTreeItemId& item) const; | |
545 | wxTreeItemId GetPrevExpanded(const wxTreeItemId& item) const; | |
546 | ||
547 | // get visible item, see IsVisible() | |
548 | wxTreeItemId GetFirstVisibleItem(bool fullRow = false) const; | |
549 | wxTreeItemId GetNextVisible(const wxTreeItemId& item, bool fullRow = false) const; | |
550 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item, bool fullRow = false) const; | |
551 | ||
552 | ||
553 | ||
554 | %disownarg( wxPyTreeItemData* data ); | |
555 | ||
556 | // add the root node to the tree | |
557 | wxTreeItemId AddRoot(const wxString& text, | |
558 | int image = -1, int selectedImage = -1, | |
559 | wxPyTreeItemData *data = NULL); | |
560 | ||
561 | // insert a new item in as the first child of the parent | |
562 | wxTreeItemId PrependItem(const wxTreeItemId& parent, | |
563 | const wxString& text, | |
564 | int image = -1, int selectedImage = -1, | |
565 | wxPyTreeItemData *data = NULL); | |
566 | ||
567 | // insert a new item after a given one | |
568 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
569 | const wxTreeItemId& idPrevious, | |
570 | const wxString& text, | |
571 | int image = -1, int selectedImage = -1, | |
572 | wxPyTreeItemData *data = NULL); | |
573 | ||
574 | // insert a new item before the one with the given index | |
575 | %Rename(InsertItemBefore, | |
576 | wxTreeItemId, InsertItem(const wxTreeItemId& parent, | |
577 | size_t index, | |
578 | const wxString& text, | |
579 | int image = -1, int selectedImage = -1, | |
580 | wxPyTreeItemData *data = NULL)); | |
581 | ||
582 | // insert a new item in as the last child of the parent | |
583 | wxTreeItemId AppendItem(const wxTreeItemId& parent, | |
584 | const wxString& text, | |
585 | int image = -1, int selectedImage = -1, | |
586 | wxPyTreeItemData *data = NULL); | |
587 | ||
588 | %cleardisown(wxPyTreeItemData* data ); | |
589 | ||
590 | // delete this item and associated data if any | |
591 | void Delete(const wxTreeItemId& item); | |
592 | ||
593 | // delete all children (but don't delete the item itself) | |
594 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
595 | void DeleteChildren(const wxTreeItemId& item); | |
596 | ||
597 | // delete all items from the tree | |
598 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
599 | void DeleteRoot(); | |
600 | %pythoncode { DeleteAllItems = DeleteRoot } | |
601 | ||
602 | ||
603 | ||
604 | // expand this item | |
605 | void Expand(const wxTreeItemId& item); | |
606 | ||
607 | // expand this item and all subitems recursively | |
608 | void ExpandAll(const wxTreeItemId& item); | |
609 | ||
610 | // collapse the item without removing its children | |
611 | void Collapse(const wxTreeItemId& item); | |
612 | ||
613 | // collapse the item and remove all children | |
614 | void CollapseAndReset(const wxTreeItemId& item); | |
615 | ||
616 | // toggles the current state | |
617 | void Toggle(const wxTreeItemId& item); | |
618 | ||
619 | // remove the selection from currently selected item (if any) | |
620 | void Unselect(); | |
621 | void UnselectAll(); | |
622 | ||
623 | // select this item | |
624 | void SelectItem(const wxTreeItemId& item, | |
625 | const wxTreeItemId& last = (wxTreeItemId*)NULL, | |
626 | bool unselect_others=true); | |
627 | ||
628 | void SelectAll(); | |
629 | ||
630 | // make sure this item is visible (expanding the parent item and/or | |
631 | // scrolling to this item if necessary) | |
632 | void EnsureVisible(const wxTreeItemId& item); | |
633 | ||
634 | // scroll to this item (but don't expand its parent) | |
635 | void ScrollTo(const wxTreeItemId& item); | |
636 | ||
637 | // Returns wxTreeItemId, flags, and column | |
638 | wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT, int& OUTPUT); | |
639 | ||
640 | %extend { | |
641 | // get the bounding rectangle of the item (or of its label only) | |
642 | PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = false) { | |
643 | wxRect rect; | |
644 | if (self->GetBoundingRect(item, rect, textOnly)) { | |
645 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
646 | wxRect* r = new wxRect(rect); | |
647 | PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1); | |
648 | wxPyEndBlockThreads(blocked); | |
649 | return val; | |
650 | } | |
651 | else { | |
652 | RETURN_NONE(); | |
653 | } | |
654 | } | |
655 | } | |
656 | ||
657 | ||
658 | %extend { | |
659 | // Start editing the item label: this (temporarily) replaces the item | |
660 | // with a one line edit control. The item will be selected if it hadn't | |
661 | // been before. | |
662 | void EditLabel(const wxTreeItemId& item, int column = -1) { | |
663 | if (column < 0) column = self->GetMainColumn(); | |
664 | self->EditLabel(item, column); | |
665 | } | |
666 | } | |
667 | %pythoncode { Edit = EditLabel } | |
668 | ||
669 | // sort the children of this item using OnCompareItems | |
670 | void SortChildren(const wxTreeItemId& item); | |
671 | ||
672 | // searching | |
673 | wxTreeItemId FindItem (const wxTreeItemId& item, const wxString& str, int flags = 0); | |
674 | ||
675 | // drop over item | |
676 | void SetDragItem (const wxTreeItemId& item = (wxTreeItemId*)NULL); | |
677 | ||
678 | wxWindow* GetHeaderWindow() const; | |
679 | wxScrolledWindow* GetMainWindow() const; | |
680 | ||
681 | }; | |
682 | ||
683 | //---------------------------------------------------------------------- | |
684 | ||
685 | %init %{ | |
686 | wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl"); | |
687 | %} | |
688 | ||
689 | //---------------------------------------------------------------------- |