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