]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: controls2.i | |
3 | // Purpose: More control (widget) classes for wxPython | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 6/10/98 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
03e9bead | 13 | %module controls2 |
7bf85405 | 14 | |
03e9bead | 15 | %{ |
7bf85405 | 16 | #include "helpers.h" |
2f90df85 RD |
17 | #ifdef __WXMSW__ |
18 | #include <windows.h> | |
19 | #endif | |
7bf85405 RD |
20 | #include <wx/listctrl.h> |
21 | #include <wx/treectrl.h> | |
7bf85405 RD |
22 | %} |
23 | ||
24 | //---------------------------------------------------------------------- | |
25 | ||
26 | %include typemaps.i | |
27 | %include my_typemaps.i | |
28 | ||
29 | // Import some definitions of other classes, etc. | |
30 | %import _defs.i | |
31 | %import misc.i | |
32 | %import windows.i | |
33 | %import gdi.i | |
34 | %import events.i | |
35 | %import controls.i | |
36 | ||
b8b8dda7 | 37 | %pragma(python) code = "import wx" |
9c039d08 | 38 | |
7bf85405 RD |
39 | //---------------------------------------------------------------------- |
40 | ||
7bf85405 | 41 | |
af309447 RD |
42 | enum { |
43 | wxLIST_MASK_TEXT, | |
44 | wxLIST_MASK_IMAGE, | |
45 | wxLIST_MASK_DATA, | |
46 | wxLIST_MASK_WIDTH, | |
47 | wxLIST_MASK_FORMAT, | |
bb0054cd | 48 | wxLIST_MASK_STATE, |
af309447 RD |
49 | wxLIST_STATE_DONTCARE, |
50 | wxLIST_STATE_DROPHILITED, | |
51 | wxLIST_STATE_FOCUSED, | |
52 | wxLIST_STATE_SELECTED, | |
53 | wxLIST_STATE_CUT, | |
54 | wxLIST_HITTEST_ABOVE, | |
55 | wxLIST_HITTEST_BELOW, | |
56 | wxLIST_HITTEST_NOWHERE, | |
57 | wxLIST_HITTEST_ONITEMICON, | |
58 | wxLIST_HITTEST_ONITEMLABEL, | |
59 | wxLIST_HITTEST_ONITEMRIGHT, | |
60 | wxLIST_HITTEST_ONITEMSTATEICON, | |
61 | wxLIST_HITTEST_TOLEFT, | |
62 | wxLIST_HITTEST_TORIGHT, | |
63 | wxLIST_HITTEST_ONITEM, | |
64 | wxLIST_NEXT_ABOVE, | |
65 | wxLIST_NEXT_ALL, | |
66 | wxLIST_NEXT_BELOW, | |
67 | wxLIST_NEXT_LEFT, | |
68 | wxLIST_NEXT_RIGHT, | |
69 | wxLIST_ALIGN_DEFAULT, | |
70 | wxLIST_ALIGN_LEFT, | |
71 | wxLIST_ALIGN_TOP, | |
72 | wxLIST_ALIGN_SNAP_TO_GRID, | |
af309447 RD |
73 | wxLIST_AUTOSIZE, |
74 | wxLIST_AUTOSIZE_USEHEADER, | |
75 | wxLIST_RECT_BOUNDS, | |
76 | wxLIST_RECT_ICON, | |
77 | wxLIST_RECT_LABEL, | |
78 | wxLIST_FIND_UP, | |
79 | wxLIST_FIND_DOWN, | |
80 | wxLIST_FIND_LEFT, | |
81 | wxLIST_FIND_RIGHT, | |
82 | }; | |
83 | ||
84 | ||
f6bcfd97 BP |
85 | enum wxListColumnFormat |
86 | { | |
87 | wxLIST_FORMAT_LEFT, | |
88 | wxLIST_FORMAT_RIGHT, | |
89 | wxLIST_FORMAT_CENTRE, | |
90 | wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE | |
91 | }; | |
92 | ||
93 | ||
1b62f00d RD |
94 | enum { |
95 | /* List control event types */ | |
96 | wxEVT_COMMAND_LIST_BEGIN_DRAG, | |
97 | wxEVT_COMMAND_LIST_BEGIN_RDRAG, | |
98 | wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, | |
99 | wxEVT_COMMAND_LIST_END_LABEL_EDIT, | |
100 | wxEVT_COMMAND_LIST_DELETE_ITEM, | |
101 | wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, | |
102 | wxEVT_COMMAND_LIST_GET_INFO, | |
103 | wxEVT_COMMAND_LIST_SET_INFO, | |
104 | wxEVT_COMMAND_LIST_ITEM_SELECTED, | |
105 | wxEVT_COMMAND_LIST_ITEM_DESELECTED, | |
106 | wxEVT_COMMAND_LIST_KEY_DOWN, | |
107 | wxEVT_COMMAND_LIST_INSERT_ITEM, | |
108 | wxEVT_COMMAND_LIST_COL_CLICK, | |
109 | wxEVT_COMMAND_LIST_ITEM_ACTIVATED, | |
110 | wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, | |
111 | wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, | |
112 | }; | |
113 | ||
114 | ||
115 | ||
f6bcfd97 BP |
116 | class wxListItemAttr |
117 | { | |
118 | public: | |
119 | // ctors | |
120 | wxListItemAttr(); | |
121 | //wxListItemAttr(const wxColour& colText, | |
122 | // const wxColour& colBack, | |
123 | // const wxFont& font) | |
124 | // : m_colText(colText), m_colBack(colBack), m_font(font) { } | |
125 | ||
126 | // setters | |
127 | void SetTextColour(const wxColour& colText); | |
128 | void SetBackgroundColour(const wxColour& colBack); | |
129 | void SetFont(const wxFont& font); | |
130 | ||
131 | // accessors | |
132 | bool HasTextColour(); | |
133 | bool HasBackgroundColour(); | |
134 | bool HasFont(); | |
135 | ||
136 | const wxColour& GetTextColour(); | |
137 | const wxColour& GetBackgroundColour(); | |
138 | const wxFont& GetFont(); | |
139 | }; | |
140 | ||
141 | ||
7bf85405 RD |
142 | class wxListItem { |
143 | public: | |
f6bcfd97 BP |
144 | wxListItem(); |
145 | ~wxListItem(); | |
146 | ||
147 | // resetting | |
148 | void Clear(); | |
149 | void ClearAttributes(); | |
150 | ||
151 | // setters | |
152 | void SetMask(long mask); | |
153 | void SetId(long id); | |
154 | void SetColumn(int col); | |
155 | void SetState(long state); | |
156 | void SetStateMask(long stateMask); | |
157 | void SetText(const wxString& text); | |
158 | void SetImage(int image); | |
159 | void SetData(long data); | |
160 | ||
161 | void SetWidth(int width); | |
162 | void SetAlign(wxListColumnFormat align); | |
163 | ||
164 | void SetTextColour(const wxColour& colText); | |
165 | void SetBackgroundColour(const wxColour& colBack); | |
166 | void SetFont(const wxFont& font); | |
167 | ||
168 | // accessors | |
169 | long GetMask(); | |
170 | long GetId(); | |
171 | int GetColumn(); | |
172 | long GetState(); | |
173 | const wxString& GetText(); | |
174 | int GetImage(); | |
175 | long GetData(); | |
176 | ||
177 | int GetWidth(); | |
178 | wxListColumnFormat GetAlign(); | |
179 | ||
180 | wxListItemAttr *GetAttributes(); | |
181 | bool HasAttributes(); | |
182 | ||
183 | wxColour GetTextColour() const; | |
184 | wxColour GetBackgroundColour() const; | |
185 | wxFont GetFont() const; | |
186 | ||
187 | // these members are public for compatibility | |
7bf85405 RD |
188 | long m_mask; // Indicates what fields are valid |
189 | long m_itemId; // The zero-based item position | |
190 | int m_col; // Zero-based column, if in report mode | |
191 | long m_state; // The state of the item | |
f6bcfd97 | 192 | long m_stateMask;// Which flags of m_state are valid (uses same flags) |
7bf85405 RD |
193 | wxString m_text; // The label/header text |
194 | int m_image; // The zero-based index into an image list | |
195 | long m_data; // App-defined data | |
7bf85405 RD |
196 | |
197 | // For columns only | |
198 | int m_format; // left, right, centre | |
199 | int m_width; // width of column | |
200 | ||
7bf85405 RD |
201 | }; |
202 | ||
f6bcfd97 | 203 | |
c368d904 | 204 | class wxListEvent: public wxNotifyEvent { |
7bf85405 RD |
205 | public: |
206 | int m_code; | |
207 | long m_itemIndex; | |
208 | long m_oldItemIndex; | |
209 | int m_col; | |
210 | bool m_cancelled; | |
211 | wxPoint m_pointDrag; | |
212 | wxListItem m_item; | |
7bf85405 | 213 | |
f6bcfd97 BP |
214 | int GetCode(); |
215 | long GetIndex(); | |
216 | long GetOldIndex(); | |
217 | long GetOldItem(); | |
218 | int GetColumn(); | |
219 | bool Cancelled(); | |
220 | wxPoint GetPoint(); | |
221 | const wxString& GetLabel(); | |
222 | const wxString& GetText(); | |
223 | int GetImage(); | |
224 | long GetData(); | |
225 | long GetMask(); | |
226 | const wxListItem& GetItem(); | |
227 | }; | |
7bf85405 RD |
228 | |
229 | ||
230 | ||
231 | class wxListCtrl : public wxControl { | |
232 | public: | |
233 | wxListCtrl(wxWindow* parent, wxWindowID id, | |
b68dc582 RD |
234 | const wxPoint& pos = wxDefaultPosition, |
235 | const wxSize& size = wxDefaultSize, | |
7bf85405 | 236 | long style = wxLC_ICON, |
b68dc582 | 237 | const wxValidator& validator = wxDefaultValidator, |
7bf85405 RD |
238 | char* name = "listCtrl"); |
239 | ||
f6bcfd97 | 240 | %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)" |
9c039d08 | 241 | |
7bf85405 | 242 | bool Arrange(int flag = wxLIST_ALIGN_DEFAULT); |
1b62f00d | 243 | void AssignImageList(wxImageList* imageList, int which); |
7bf85405 RD |
244 | bool DeleteItem(long item); |
245 | bool DeleteAllItems(); | |
246 | bool DeleteColumn(int col); | |
247 | bool DeleteAllColumns(void); | |
248 | void ClearAll(void); | |
4f22cf8d | 249 | #ifdef __WXMSW__ |
7bf85405 RD |
250 | wxTextCtrl* EditLabel(long item); |
251 | bool EndEditLabel(bool cancel); | |
4f22cf8d | 252 | wxTextCtrl* GetEditControl(); |
8bf5d46e RD |
253 | #else |
254 | void EditLabel(long item); | |
fb5e0af0 | 255 | #endif |
7bf85405 RD |
256 | bool EnsureVisible(long item); |
257 | long FindItem(long start, const wxString& str, bool partial = FALSE); | |
258 | %name(FindItemData)long FindItem(long start, long data); | |
259 | %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, | |
260 | int direction); | |
261 | bool GetColumn(int col, wxListItem& item); | |
262 | int GetColumnWidth(int col); | |
263 | int GetCountPerPage(); | |
7bf85405 RD |
264 | wxImageList* GetImageList(int which); |
265 | long GetItemData(long item); | |
266 | ||
267 | %addmethods { | |
e166644c | 268 | %new wxListItem* GetItem(long itemId, int col=0) { |
7bf85405 | 269 | wxListItem* info = new wxListItem; |
0699c864 | 270 | info->m_itemId = itemId; |
e166644c | 271 | info->m_col = col; |
f17fee68 | 272 | info->m_mask = 0xFFFF; |
7bf85405 RD |
273 | self->GetItem(*info); |
274 | return info; | |
275 | } | |
276 | %new wxPoint* GetItemPosition(long item) { | |
277 | wxPoint* pos = new wxPoint; | |
278 | self->GetItemPosition(item, *pos); | |
279 | return pos; | |
280 | } | |
281 | %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) { | |
282 | wxRect* rect= new wxRect; | |
283 | self->GetItemRect(item, *rect, code); | |
284 | return rect; | |
285 | } | |
286 | } | |
287 | ||
288 | int GetItemState(long item, long stateMask); | |
289 | int GetItemCount(); | |
290 | int GetItemSpacing(bool isSmall); | |
291 | wxString GetItemText(long item); | |
292 | long GetNextItem(long item, | |
293 | int geometry = wxLIST_NEXT_ALL, | |
294 | int state = wxLIST_STATE_DONTCARE); | |
295 | int GetSelectedItemCount(); | |
fb5e0af0 | 296 | #ifdef __WXMSW__ |
7bf85405 | 297 | wxColour GetTextColour(); |
4f22cf8d | 298 | void SetTextColour(const wxColour& col); |
fb5e0af0 | 299 | #endif |
7bf85405 RD |
300 | long GetTopItem(); |
301 | long HitTest(const wxPoint& point, int& OUTPUT); | |
c368d904 | 302 | %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info); |
7bf85405 RD |
303 | long InsertColumn(long col, const wxString& heading, |
304 | int format = wxLIST_FORMAT_LEFT, | |
305 | int width = -1); | |
306 | ||
307 | long InsertItem(wxListItem& info); | |
308 | %name(InsertStringItem) long InsertItem(long index, const wxString& label); | |
309 | %name(InsertImageItem) long InsertItem(long index, int imageIndex); | |
310 | %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, | |
311 | int imageIndex); | |
312 | ||
313 | bool ScrollList(int dx, int dy); | |
314 | void SetBackgroundColour(const wxColour& col); | |
315 | bool SetColumn(int col, wxListItem& item); | |
316 | bool SetColumnWidth(int col, int width); | |
317 | void SetImageList(wxImageList* imageList, int which); | |
af309447 | 318 | |
7bf85405 | 319 | bool SetItem(wxListItem& info); |
af309447 | 320 | %name(SetStringItem)long SetItem(long index, int col, const wxString& label, |
7bf85405 | 321 | int imageId = -1); |
af309447 | 322 | |
7bf85405 RD |
323 | bool SetItemData(long item, long data); |
324 | bool SetItemImage(long item, int image, int selImage); | |
325 | bool SetItemPosition(long item, const wxPoint& pos); | |
326 | bool SetItemState(long item, long state, long stateMask); | |
327 | void SetItemText(long item, const wxString& text); | |
328 | void SetSingleStyle(long style, bool add = TRUE); | |
7bf85405 | 329 | void SetWindowStyleFlag(long style); |
dcd38683 RD |
330 | |
331 | // bool SortItems(wxListCtrlCompare fn, long data); | |
332 | %addmethods { | |
333 | bool SortItems(PyObject* func) { | |
334 | if (!PyCallable_Check(func)) | |
335 | return FALSE; | |
336 | ||
f6bcfd97 | 337 | return self->SortItems(wxPyListCtrl_SortItems, (long)func); |
dcd38683 RD |
338 | } |
339 | } | |
7bf85405 RD |
340 | }; |
341 | ||
dcd38683 | 342 | %{ |
f6bcfd97 | 343 | int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) { |
dcd38683 RD |
344 | int retval = 0; |
345 | PyObject* func = (PyObject*)funcPtr; | |
346 | bool doSave = wxPyRestoreThread(); | |
7bf85405 | 347 | |
dcd38683 RD |
348 | PyObject* args = Py_BuildValue("(ii)", item1, item2); |
349 | PyObject* result = PyEval_CallObject(func, args); | |
350 | Py_DECREF(args); | |
351 | if (result) { | |
352 | retval = PyInt_AsLong(result); | |
353 | Py_DECREF(result); | |
354 | } | |
355 | ||
356 | wxPySaveThread(doSave); | |
357 | return retval; | |
358 | } | |
359 | ||
360 | %} | |
7bf85405 RD |
361 | |
362 | //---------------------------------------------------------------------- | |
363 | ||
694759cf RD |
364 | enum wxTreeItemIcon |
365 | { | |
366 | wxTreeItemIcon_Normal, // not selected, not expanded | |
367 | wxTreeItemIcon_Selected, // selected, not expanded | |
368 | wxTreeItemIcon_Expanded, // not selected, expanded | |
369 | wxTreeItemIcon_SelectedExpanded, // selected, expanded | |
370 | wxTreeItemIcon_Max | |
371 | }; | |
372 | ||
7bf85405 | 373 | |
164b735b RD |
374 | // constants for HitTest |
375 | enum { | |
376 | wxTREE_HITTEST_ABOVE, | |
377 | wxTREE_HITTEST_BELOW, | |
378 | wxTREE_HITTEST_NOWHERE, | |
379 | wxTREE_HITTEST_ONITEMBUTTON, | |
380 | wxTREE_HITTEST_ONITEMICON, | |
381 | wxTREE_HITTEST_ONITEMINDENT, | |
382 | wxTREE_HITTEST_ONITEMLABEL, | |
383 | wxTREE_HITTEST_ONITEMRIGHT, | |
384 | wxTREE_HITTEST_ONITEMSTATEICON, | |
385 | wxTREE_HITTEST_TOLEFT, | |
386 | wxTREE_HITTEST_TORIGHT, | |
387 | wxTREE_HITTEST_ONITEMUPPERPART, | |
388 | wxTREE_HITTEST_ONITEMLOWERPART, | |
389 | wxTREE_HITTEST_ONITEM | |
390 | }; | |
391 | ||
392 | ||
1b62f00d RD |
393 | enum { |
394 | /* Tree control event types */ | |
395 | wxEVT_COMMAND_TREE_BEGIN_DRAG, | |
396 | wxEVT_COMMAND_TREE_BEGIN_RDRAG, | |
397 | wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, | |
398 | wxEVT_COMMAND_TREE_END_LABEL_EDIT, | |
399 | wxEVT_COMMAND_TREE_DELETE_ITEM, | |
400 | wxEVT_COMMAND_TREE_GET_INFO, | |
401 | wxEVT_COMMAND_TREE_SET_INFO, | |
402 | wxEVT_COMMAND_TREE_ITEM_EXPANDED, | |
403 | wxEVT_COMMAND_TREE_ITEM_EXPANDING, | |
404 | wxEVT_COMMAND_TREE_ITEM_COLLAPSED, | |
405 | wxEVT_COMMAND_TREE_ITEM_COLLAPSING, | |
406 | wxEVT_COMMAND_TREE_SEL_CHANGED, | |
407 | wxEVT_COMMAND_TREE_SEL_CHANGING, | |
408 | wxEVT_COMMAND_TREE_KEY_DOWN, | |
409 | wxEVT_COMMAND_TREE_ITEM_ACTIVATED, | |
410 | wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, | |
411 | wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, | |
d1679124 | 412 | wxEVT_COMMAND_TREE_END_DRAG, |
1b62f00d RD |
413 | }; |
414 | ||
415 | ||
d5c9047a RD |
416 | class wxTreeItemId { |
417 | public: | |
418 | wxTreeItemId(); | |
419 | ~wxTreeItemId(); | |
bb0054cd | 420 | bool IsOk(); |
d5c9047a | 421 | |
f6bcfd97 BP |
422 | %addmethods { |
423 | int __cmp__(wxTreeItemId* other) { | |
c368d904 | 424 | if (! other) return -1; |
f6bcfd97 BP |
425 | return *self != *other; |
426 | } | |
427 | } | |
d5c9047a RD |
428 | }; |
429 | ||
430 | ||
431 | ||
cf694132 RD |
432 | %{ |
433 | class wxPyTreeItemData : public wxTreeItemData { | |
d5c9047a | 434 | public: |
cf694132 | 435 | wxPyTreeItemData(PyObject* obj = NULL) { |
c368d904 | 436 | if (obj == NULL) |
cf694132 | 437 | obj = Py_None; |
c368d904 RD |
438 | Py_INCREF(obj); |
439 | m_obj = obj; | |
cf694132 | 440 | } |
d5c9047a | 441 | |
cf694132 | 442 | ~wxPyTreeItemData() { |
1afc06c2 | 443 | bool doSave = wxPyRestoreThread(); |
c368d904 | 444 | Py_DECREF(m_obj); |
1afc06c2 | 445 | wxPySaveThread(doSave); |
cf694132 RD |
446 | } |
447 | ||
448 | PyObject* GetData() { | |
449 | Py_INCREF(m_obj); | |
450 | return m_obj; | |
451 | } | |
452 | ||
453 | void SetData(PyObject* obj) { | |
c368d904 | 454 | bool doSave = wxPyRestoreThread(); |
cf694132 | 455 | Py_DECREF(m_obj); |
c368d904 | 456 | wxPySaveThread(doSave); |
cf694132 RD |
457 | m_obj = obj; |
458 | Py_INCREF(obj); | |
459 | } | |
460 | ||
461 | PyObject* m_obj; | |
d5c9047a | 462 | }; |
cf694132 | 463 | %} |
d5c9047a RD |
464 | |
465 | ||
466 | ||
cf694132 RD |
467 | %name(wxTreeItemData) class wxPyTreeItemData { |
468 | public: | |
469 | wxPyTreeItemData(PyObject* obj = NULL); | |
470 | ||
471 | PyObject* GetData(); | |
472 | void SetData(PyObject* obj); | |
473 | ||
474 | const wxTreeItemId& GetId(); | |
475 | void SetId(const wxTreeItemId& id); | |
476 | }; | |
477 | ||
478 | ||
d5c9047a | 479 | |
8bf5d46e | 480 | class wxTreeEvent : public wxNotifyEvent { |
d5c9047a RD |
481 | public: |
482 | wxTreeItemId GetItem(); | |
483 | wxTreeItemId GetOldItem(); | |
484 | wxPoint GetPoint(); | |
485 | int GetCode(); | |
8bf5d46e | 486 | const wxString& GetLabel(); |
d5c9047a RD |
487 | }; |
488 | ||
489 | ||
f6bcfd97 BP |
490 | |
491 | %{ | |
492 | class wxPyTreeCtrl : public wxTreeCtrl { | |
3b36695d | 493 | DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl); |
f6bcfd97 BP |
494 | public: |
495 | wxPyTreeCtrl(wxWindow *parent, wxWindowID id, | |
496 | const wxPoint& pos, | |
497 | const wxSize& size, | |
498 | long style, | |
499 | const wxValidator& validator, | |
500 | char* name) : | |
501 | wxTreeCtrl(parent, id, pos, size, style, validator, name) {} | |
502 | ||
f6bcfd97 BP |
503 | int OnCompareItems(const wxTreeItemId& item1, |
504 | const wxTreeItemId& item2) { | |
505 | int rval = 0; | |
506 | bool doSave = wxPyRestoreThread(); | |
507 | if (m_myInst.findCallback("OnCompareItems")) | |
508 | rval = m_myInst.callCallback(Py_BuildValue( | |
509 | "(OO)", | |
510 | wxPyConstructObject((void*)&item1, "wxTreeItemId"), | |
511 | wxPyConstructObject((void*)&item2, "wxTreeItemId"))); | |
512 | else | |
513 | rval = wxTreeCtrl::OnCompareItems(item1, item2); | |
514 | wxPySaveThread(doSave); | |
515 | return rval; | |
516 | } | |
517 | PYPRIVATE; | |
518 | }; | |
519 | ||
3b36695d RD |
520 | IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl); |
521 | ||
f6bcfd97 BP |
522 | %} |
523 | ||
d5c9047a RD |
524 | // These are for the GetFirstChild/GetNextChild methods below |
525 | %typemap(python, in) long& INOUT = long* INOUT; | |
526 | %typemap(python, argout) long& INOUT = long* INOUT; | |
527 | ||
528 | ||
f6bcfd97 | 529 | %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl { |
d5c9047a | 530 | public: |
f6bcfd97 | 531 | wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1, |
b68dc582 RD |
532 | const wxPoint& pos = wxDefaultPosition, |
533 | const wxSize& size = wxDefaultSize, | |
d5c9047a | 534 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, |
b68dc582 | 535 | const wxValidator& validator = wxDefaultValidator, |
d5c9047a RD |
536 | char* name = "wxTreeCtrl"); |
537 | ||
f6bcfd97 BP |
538 | void _setSelf(PyObject* self, PyObject* _class); |
539 | %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)" | |
540 | %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTreeCtrl)" | |
d5c9047a | 541 | |
1b62f00d | 542 | void AssignImageList(wxImageList* imageList); |
d5c9047a RD |
543 | size_t GetCount(); |
544 | unsigned int GetIndent(); | |
545 | void SetIndent(unsigned int indent); | |
546 | wxImageList *GetImageList(); | |
547 | wxImageList *GetStateImageList(); | |
1b62f00d | 548 | void SetImageList(wxImageList *imageList); |
d5c9047a RD |
549 | void SetStateImageList(wxImageList *imageList); |
550 | ||
b1462dfa RD |
551 | unsigned int GetSpacing(); |
552 | void SetSpacing(unsigned int spacing); | |
553 | ||
d5c9047a | 554 | wxString GetItemText(const wxTreeItemId& item); |
694759cf RD |
555 | int GetItemImage(const wxTreeItemId& item, |
556 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
d5c9047a | 557 | int GetItemSelectedImage(const wxTreeItemId& item); |
d5c9047a RD |
558 | |
559 | void SetItemText(const wxTreeItemId& item, const wxString& text); | |
694759cf RD |
560 | void SetItemImage(const wxTreeItemId& item, int image, |
561 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
d5c9047a | 562 | void SetItemSelectedImage(const wxTreeItemId& item, int image); |
08127323 | 563 | void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE); |
d5c9047a | 564 | |
cf694132 | 565 | %addmethods { |
c368d904 RD |
566 | // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData |
567 | // if needed. | |
cf694132 RD |
568 | wxPyTreeItemData* GetItemData(const wxTreeItemId& item) { |
569 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
570 | if (data == NULL) { | |
571 | data = new wxPyTreeItemData(); | |
f6bcfd97 | 572 | data->SetId(item); // set the id |
cf694132 RD |
573 | self->SetItemData(item, data); |
574 | } | |
575 | return data; | |
576 | } | |
577 | ||
578 | void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { | |
f6bcfd97 BP |
579 | data->SetId(item); // set the id |
580 | self->SetItemData(item, data); | |
c368d904 | 581 | } |
cf694132 | 582 | |
c368d904 RD |
583 | // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by |
584 | // automatically creating data classes. | |
585 | PyObject* GetPyData(const wxTreeItemId& item) { | |
cf694132 RD |
586 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); |
587 | if (data == NULL) { | |
588 | data = new wxPyTreeItemData(); | |
f6bcfd97 | 589 | data->SetId(item); // set the id |
cf694132 RD |
590 | self->SetItemData(item, data); |
591 | } | |
592 | return data->GetData(); | |
c368d904 | 593 | } |
cf694132 RD |
594 | |
595 | void SetPyData(const wxTreeItemId& item, PyObject* obj) { | |
596 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
597 | if (data == NULL) { | |
598 | data = new wxPyTreeItemData(obj); | |
f6bcfd97 | 599 | data->SetId(item); // set the id |
cf694132 RD |
600 | self->SetItemData(item, data); |
601 | } else | |
602 | data->SetData(obj); | |
c368d904 | 603 | } |
cf694132 RD |
604 | } |
605 | ||
606 | ||
d5c9047a RD |
607 | bool IsVisible(const wxTreeItemId& item); |
608 | bool ItemHasChildren(const wxTreeItemId& item); | |
609 | bool IsExpanded(const wxTreeItemId& item); | |
610 | bool IsSelected(const wxTreeItemId& item); | |
611 | ||
612 | wxTreeItemId GetRootItem(); | |
613 | wxTreeItemId GetSelection(); | |
eb715945 | 614 | %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item); |
d426c97e RD |
615 | //size_t GetSelections(wxArrayTreeItemIds& selection); |
616 | %addmethods { | |
617 | PyObject* GetSelections() { | |
26b9cf27 | 618 | bool doSave = wxPyRestoreThread(); |
d426c97e RD |
619 | PyObject* rval = PyList_New(0); |
620 | wxArrayTreeItemIds array; | |
621 | size_t num, x; | |
622 | num = self->GetSelections(array); | |
623 | for (x=0; x < num; x++) { | |
c368d904 RD |
624 | wxTreeItemId *tii = new wxTreeItemId(array.Item(x)); |
625 | PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE); | |
d426c97e RD |
626 | PyList_Append(rval, item); |
627 | } | |
26b9cf27 | 628 | wxPySaveThread(doSave); |
d426c97e RD |
629 | return rval; |
630 | } | |
631 | } | |
632 | ||
633 | ||
d5c9047a | 634 | |
bb0054cd RD |
635 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); |
636 | ||
d5c9047a RD |
637 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT); |
638 | wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT); | |
639 | wxTreeItemId GetNextSibling(const wxTreeItemId& item); | |
640 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item); | |
641 | wxTreeItemId GetFirstVisibleItem(); | |
642 | wxTreeItemId GetNextVisible(const wxTreeItemId& item); | |
643 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item); | |
d426c97e RD |
644 | wxTreeItemId GetLastChild(const wxTreeItemId& item); |
645 | ||
d5c9047a RD |
646 | |
647 | ||
648 | wxTreeItemId AddRoot(const wxString& text, | |
649 | int image = -1, int selectedImage = -1, | |
cf694132 | 650 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
651 | wxTreeItemId PrependItem(const wxTreeItemId& parent, |
652 | const wxString& text, | |
653 | int image = -1, int selectedImage = -1, | |
cf694132 | 654 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
655 | wxTreeItemId InsertItem(const wxTreeItemId& parent, |
656 | const wxTreeItemId& idPrevious, | |
657 | const wxString& text, | |
658 | int image = -1, int selectedImage = -1, | |
cf694132 | 659 | wxPyTreeItemData *data = NULL); |
f6bcfd97 BP |
660 | %name(InsertItemBefore) |
661 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
662 | size_t before, | |
663 | const wxString& text, | |
664 | int image = -1, int selectedImage = -1, | |
665 | wxTreeItemData *data = NULL); | |
d5c9047a RD |
666 | wxTreeItemId AppendItem(const wxTreeItemId& parent, |
667 | const wxString& text, | |
668 | int image = -1, int selectedImage = -1, | |
cf694132 | 669 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
670 | |
671 | void Delete(const wxTreeItemId& item); | |
08127323 | 672 | void DeleteChildren(const wxTreeItemId& item); |
d5c9047a RD |
673 | void DeleteAllItems(); |
674 | ||
675 | void Expand(const wxTreeItemId& item); | |
676 | void Collapse(const wxTreeItemId& item); | |
677 | void CollapseAndReset(const wxTreeItemId& item); | |
678 | void Toggle(const wxTreeItemId& item); | |
679 | ||
680 | void Unselect(); | |
8bf5d46e | 681 | void UnselectAll(); |
d5c9047a RD |
682 | void SelectItem(const wxTreeItemId& item); |
683 | void EnsureVisible(const wxTreeItemId& item); | |
684 | void ScrollTo(const wxTreeItemId& item); | |
8bf5d46e | 685 | #ifdef __WXMSW__ |
d5c9047a | 686 | wxTextCtrl* EditLabel(const wxTreeItemId& item); |
d5c9047a | 687 | wxTextCtrl* GetEditControl(); |
b1462dfa | 688 | void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE); |
8bf5d46e RD |
689 | #else |
690 | void EditLabel(const wxTreeItemId& item); | |
691 | #endif | |
d5c9047a | 692 | |
d426c97e | 693 | void SortChildren(const wxTreeItemId& item); |
d5c9047a | 694 | |
b1462dfa | 695 | void SetItemBold(const wxTreeItemId& item, int bold = TRUE); |
b8b8dda7 | 696 | bool IsBold(const wxTreeItemId& item) const; |
164b735b | 697 | wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT); |
c127177f | 698 | |
f6bcfd97 BP |
699 | |
700 | ||
b7e72427 RD |
701 | void SetItemTextColour(const wxTreeItemId& item, const wxColour& col); |
702 | void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col); | |
703 | void SetItemFont(const wxTreeItemId& item, const wxFont& font); | |
704 | ||
4120ef2b | 705 | #ifdef __WXMSW__ |
b1462dfa RD |
706 | void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE); |
707 | ||
d426c97e RD |
708 | //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE) |
709 | %addmethods { | |
710 | PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) { | |
711 | wxRect rect; | |
164b735b RD |
712 | if (self->GetBoundingRect(item, rect, textOnly)) { |
713 | bool doSave = wxPyRestoreThread(); | |
714 | wxRect* r = new wxRect(rect); | |
715 | PyObject* val = wxPyConstructObject((void*)r, "wxRect"); | |
716 | wxPySaveThread(doSave); | |
717 | return val; | |
718 | } | |
d426c97e RD |
719 | else { |
720 | Py_INCREF(Py_None); | |
721 | return Py_None; | |
722 | } | |
723 | } | |
724 | } | |
761a9d2b | 725 | #endif |
d426c97e | 726 | |
c127177f | 727 | %pragma(python) addtoclass = " |
f6bcfd97 BP |
728 | # Redefine some methods that SWIG gets a bit confused on... |
729 | def GetFirstChild(self, *_args, **_kwargs): | |
730 | val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs) | |
731 | val1 = wxTreeItemIdPtr(val1) | |
732 | val1.thisown = 1 | |
733 | return (val1,val2) | |
734 | def GetNextChild(self, *_args, **_kwargs): | |
735 | val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs) | |
c127177f RD |
736 | val1 = wxTreeItemIdPtr(val1) |
737 | val1.thisown = 1 | |
738 | return (val1,val2) | |
f6bcfd97 BP |
739 | def HitTest(self, *_args, **_kwargs): |
740 | val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs) | |
c127177f RD |
741 | val1 = wxTreeItemIdPtr(val1) |
742 | val1.thisown = 1 | |
743 | return (val1,val2) | |
744 | " | |
d5c9047a RD |
745 | }; |
746 | ||
d5c9047a | 747 | |
7bf85405 RD |
748 | //---------------------------------------------------------------------- |
749 | ||
9c039d08 | 750 | #ifdef SKIPTHIS |
fb5e0af0 | 751 | #ifdef __WXMSW__ |
1b62f00d RD |
752 | |
753 | ||
754 | enum { | |
755 | /* tab control event types */ | |
756 | wxEVT_COMMAND_TAB_SEL_CHANGED, | |
757 | wxEVT_COMMAND_TAB_SEL_CHANGING, | |
758 | }; | |
759 | ||
760 | ||
7bf85405 RD |
761 | class wxTabEvent : public wxCommandEvent { |
762 | public: | |
763 | }; | |
764 | ||
765 | ||
766 | ||
767 | class wxTabCtrl : public wxControl { | |
768 | public: | |
769 | wxTabCtrl(wxWindow* parent, wxWindowID id, | |
b68dc582 RD |
770 | const wxPoint& pos = wxDefaultPosition, |
771 | const wxSize& size = wxDefaultSize, | |
7bf85405 RD |
772 | long style = 0, |
773 | char* name = "tabCtrl"); | |
774 | ||
f6bcfd97 | 775 | %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)" |
9c039d08 | 776 | |
7bf85405 RD |
777 | bool DeleteAllItems(); |
778 | bool DeleteItem(int item); | |
779 | wxImageList* GetImageList(); | |
780 | int GetItemCount(); | |
781 | // TODO: void* GetItemData(); | |
782 | int GetItemImage(int item); | |
783 | ||
784 | %addmethods { | |
785 | %new wxRect* GetItemRect(int item) { | |
786 | wxRect* rect = new wxRect; | |
787 | self->GetItemRect(item, *rect); | |
788 | return rect; | |
789 | } | |
790 | } | |
791 | ||
792 | wxString GetItemText(int item); | |
793 | bool GetRowCount(); | |
794 | int GetSelection(); | |
795 | int HitTest(const wxPoint& pt, long& OUTPUT); | |
796 | void InsertItem(int item, const wxString& text, | |
797 | int imageId = -1, void* clientData = NULL); | |
798 | // TODO: bool SetItemData(int item, void* data); | |
799 | bool SetItemImage(int item, int image); | |
800 | void SetImageList(wxImageList* imageList); | |
801 | void SetItemSize(const wxSize& size); | |
802 | bool SetItemText(int item, const wxString& text); | |
803 | void SetPadding(const wxSize& padding); | |
804 | int SetSelection(int item); | |
805 | ||
806 | }; | |
807 | ||
9c039d08 | 808 | #endif |
fb5e0af0 RD |
809 | #endif |
810 | ||
7bf85405 RD |
811 | //---------------------------------------------------------------------- |
812 | ||
813 |