]>
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> | |
9416aa89 | 22 | #include <wx/imaglist.h> |
7bf85405 RD |
23 | %} |
24 | ||
25 | //---------------------------------------------------------------------- | |
26 | ||
27 | %include typemaps.i | |
28 | %include my_typemaps.i | |
29 | ||
30 | // Import some definitions of other classes, etc. | |
31 | %import _defs.i | |
32 | %import misc.i | |
33 | %import windows.i | |
34 | %import gdi.i | |
35 | %import events.i | |
36 | %import controls.i | |
37 | ||
b8b8dda7 | 38 | %pragma(python) code = "import wx" |
9c039d08 | 39 | |
c7e7022c RD |
40 | |
41 | //---------------------------------------------------------------------- | |
7bf85405 RD |
42 | //---------------------------------------------------------------------- |
43 | ||
c7e7022c RD |
44 | enum { |
45 | /* List control event types */ | |
46 | wxEVT_COMMAND_LIST_BEGIN_DRAG, | |
47 | wxEVT_COMMAND_LIST_BEGIN_RDRAG, | |
48 | wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, | |
49 | wxEVT_COMMAND_LIST_END_LABEL_EDIT, | |
50 | wxEVT_COMMAND_LIST_DELETE_ITEM, | |
51 | wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, | |
52 | wxEVT_COMMAND_LIST_GET_INFO, | |
53 | wxEVT_COMMAND_LIST_SET_INFO, | |
54 | wxEVT_COMMAND_LIST_ITEM_SELECTED, | |
55 | wxEVT_COMMAND_LIST_ITEM_DESELECTED, | |
56 | wxEVT_COMMAND_LIST_KEY_DOWN, | |
57 | wxEVT_COMMAND_LIST_INSERT_ITEM, | |
58 | wxEVT_COMMAND_LIST_COL_CLICK, | |
59 | wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, | |
60 | wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, | |
61 | wxEVT_COMMAND_LIST_ITEM_ACTIVATED, | |
62 | wxEVT_COMMAND_LIST_CACHE_HINT, | |
6d19860f RD |
63 | wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, |
64 | wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, | |
65 | wxEVT_COMMAND_LIST_COL_DRAGGING, | |
66 | wxEVT_COMMAND_LIST_COL_END_DRAG, | |
d8200036 | 67 | wxEVT_COMMAND_LIST_ITEM_FOCUSED, |
c7e7022c RD |
68 | }; |
69 | ||
70 | ||
71 | %pragma(python) code = " | |
72 | def EVT_LIST_BEGIN_DRAG(win, id, func): | |
73 | win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func) | |
74 | ||
75 | def EVT_LIST_BEGIN_RDRAG(win, id, func): | |
76 | win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func) | |
77 | ||
78 | def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func): | |
79 | win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func) | |
80 | ||
81 | def EVT_LIST_END_LABEL_EDIT(win, id, func): | |
82 | win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func) | |
83 | ||
84 | def EVT_LIST_DELETE_ITEM(win, id, func): | |
85 | win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func) | |
86 | ||
87 | def EVT_LIST_DELETE_ALL_ITEMS(win, id, func): | |
88 | win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func) | |
89 | ||
90 | def EVT_LIST_GET_INFO(win, id, func): | |
91 | win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func) | |
92 | ||
93 | def EVT_LIST_SET_INFO(win, id, func): | |
94 | win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func) | |
95 | ||
96 | def EVT_LIST_ITEM_SELECTED(win, id, func): | |
97 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func) | |
98 | ||
99 | def EVT_LIST_ITEM_DESELECTED(win, id, func): | |
100 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func) | |
101 | ||
102 | def EVT_LIST_KEY_DOWN(win, id, func): | |
103 | win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func) | |
104 | ||
105 | def EVT_LIST_INSERT_ITEM(win, id, func): | |
106 | win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func) | |
107 | ||
108 | def EVT_LIST_COL_CLICK(win, id, func): | |
109 | win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func) | |
110 | ||
6d19860f RD |
111 | def EVT_LIST_COL_RIGHT_CLICK(win, id, func): |
112 | win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, func) | |
113 | ||
114 | def EVT_LIST_COL_BEGIN_DRAG(win, id, func): | |
115 | win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, func) | |
116 | ||
117 | def EVT_LIST_COL_DRAGGING(win, id, func): | |
118 | win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_DRAGGING, func) | |
119 | ||
120 | def EVT_LIST_COL_END_DRAG(win, id, func): | |
121 | win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_END_DRAG, func) | |
122 | ||
c7e7022c RD |
123 | def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func): |
124 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func) | |
125 | ||
126 | def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func): | |
127 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func) | |
128 | ||
129 | def EVT_LIST_ITEM_ACTIVATED(win, id, func): | |
130 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func) | |
131 | ||
132 | def EVT_LIST_CACHE_HINT(win, id, func): | |
133 | win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func) | |
d8200036 RD |
134 | |
135 | def EVT_LIST_ITEM_FOCUSED(win, id, func): | |
136 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_FOCUSED, func) | |
c7e7022c RD |
137 | " |
138 | ||
7bf85405 | 139 | |
af309447 | 140 | enum { |
c7e7022c RD |
141 | /* Style flags */ |
142 | wxLC_VRULES, | |
143 | wxLC_HRULES, | |
144 | ||
145 | wxLC_ICON, | |
146 | wxLC_SMALL_ICON, | |
147 | wxLC_LIST, | |
148 | wxLC_REPORT, | |
149 | ||
150 | wxLC_ALIGN_TOP, | |
151 | wxLC_ALIGN_LEFT, | |
152 | wxLC_AUTOARRANGE, | |
153 | wxLC_VIRTUAL, | |
154 | wxLC_EDIT_LABELS, | |
155 | wxLC_NO_HEADER, | |
156 | wxLC_NO_SORT_HEADER, | |
157 | wxLC_SINGLE_SEL, | |
158 | wxLC_SORT_ASCENDING, | |
159 | wxLC_SORT_DESCENDING, | |
160 | ||
161 | wxLC_MASK_TYPE, | |
162 | wxLC_MASK_ALIGN, | |
163 | wxLC_MASK_SORT, | |
164 | ||
6d19860f | 165 | wxLC_USER_TEXT, |
c7e7022c RD |
166 | }; |
167 | ||
168 | ||
169 | enum { | |
170 | // Mask flags | |
171 | wxLIST_MASK_STATE, | |
af309447 RD |
172 | wxLIST_MASK_TEXT, |
173 | wxLIST_MASK_IMAGE, | |
174 | wxLIST_MASK_DATA, | |
c7e7022c | 175 | wxLIST_SET_ITEM, |
af309447 RD |
176 | wxLIST_MASK_WIDTH, |
177 | wxLIST_MASK_FORMAT, | |
c7e7022c RD |
178 | |
179 | // State flags | |
af309447 RD |
180 | wxLIST_STATE_DONTCARE, |
181 | wxLIST_STATE_DROPHILITED, | |
182 | wxLIST_STATE_FOCUSED, | |
183 | wxLIST_STATE_SELECTED, | |
184 | wxLIST_STATE_CUT, | |
c7e7022c RD |
185 | |
186 | // Hit test flags | |
af309447 RD |
187 | wxLIST_HITTEST_ABOVE, |
188 | wxLIST_HITTEST_BELOW, | |
189 | wxLIST_HITTEST_NOWHERE, | |
190 | wxLIST_HITTEST_ONITEMICON, | |
191 | wxLIST_HITTEST_ONITEMLABEL, | |
192 | wxLIST_HITTEST_ONITEMRIGHT, | |
193 | wxLIST_HITTEST_ONITEMSTATEICON, | |
194 | wxLIST_HITTEST_TOLEFT, | |
195 | wxLIST_HITTEST_TORIGHT, | |
196 | wxLIST_HITTEST_ONITEM, | |
c7e7022c RD |
197 | |
198 | // Flags for GetNextItem | |
af309447 RD |
199 | wxLIST_NEXT_ABOVE, |
200 | wxLIST_NEXT_ALL, | |
201 | wxLIST_NEXT_BELOW, | |
202 | wxLIST_NEXT_LEFT, | |
203 | wxLIST_NEXT_RIGHT, | |
c7e7022c RD |
204 | |
205 | // Alignment flags | |
af309447 RD |
206 | wxLIST_ALIGN_DEFAULT, |
207 | wxLIST_ALIGN_LEFT, | |
208 | wxLIST_ALIGN_TOP, | |
209 | wxLIST_ALIGN_SNAP_TO_GRID, | |
c7e7022c RD |
210 | |
211 | // Autosize values for SetColumnWidth | |
212 | wxLIST_AUTOSIZE = -1, | |
213 | wxLIST_AUTOSIZE_USEHEADER = -2, | |
214 | ||
215 | // Flag values for GetItemRect | |
af309447 RD |
216 | wxLIST_RECT_BOUNDS, |
217 | wxLIST_RECT_ICON, | |
218 | wxLIST_RECT_LABEL, | |
c7e7022c RD |
219 | |
220 | // Flag values for FindItem (MSW only) | |
af309447 RD |
221 | wxLIST_FIND_UP, |
222 | wxLIST_FIND_DOWN, | |
223 | wxLIST_FIND_LEFT, | |
224 | wxLIST_FIND_RIGHT, | |
c7e7022c RD |
225 | |
226 | ||
af309447 RD |
227 | }; |
228 | ||
229 | ||
c7e7022c | 230 | |
f6bcfd97 BP |
231 | enum wxListColumnFormat |
232 | { | |
233 | wxLIST_FORMAT_LEFT, | |
234 | wxLIST_FORMAT_RIGHT, | |
235 | wxLIST_FORMAT_CENTRE, | |
236 | wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE | |
237 | }; | |
238 | ||
239 | ||
1b62f00d RD |
240 | |
241 | ||
f6bcfd97 BP |
242 | class wxListItemAttr |
243 | { | |
244 | public: | |
245 | // ctors | |
c7e7022c RD |
246 | //wxListItemAttr(); |
247 | wxListItemAttr(const wxColour& colText = wxNullColour, | |
248 | const wxColour& colBack = wxNullColour, | |
249 | const wxFont& font = wxNullFont); | |
250 | ||
f6bcfd97 BP |
251 | |
252 | // setters | |
253 | void SetTextColour(const wxColour& colText); | |
254 | void SetBackgroundColour(const wxColour& colBack); | |
255 | void SetFont(const wxFont& font); | |
256 | ||
257 | // accessors | |
258 | bool HasTextColour(); | |
259 | bool HasBackgroundColour(); | |
260 | bool HasFont(); | |
261 | ||
c5943253 RD |
262 | wxColour GetTextColour(); |
263 | wxColour GetBackgroundColour(); | |
264 | wxFont GetFont(); | |
f6bcfd97 BP |
265 | }; |
266 | ||
267 | ||
9416aa89 | 268 | class wxListItem : public wxObject { |
7bf85405 | 269 | public: |
f6bcfd97 BP |
270 | wxListItem(); |
271 | ~wxListItem(); | |
272 | ||
273 | // resetting | |
274 | void Clear(); | |
275 | void ClearAttributes(); | |
276 | ||
277 | // setters | |
278 | void SetMask(long mask); | |
279 | void SetId(long id); | |
280 | void SetColumn(int col); | |
281 | void SetState(long state); | |
282 | void SetStateMask(long stateMask); | |
283 | void SetText(const wxString& text); | |
284 | void SetImage(int image); | |
285 | void SetData(long data); | |
286 | ||
287 | void SetWidth(int width); | |
288 | void SetAlign(wxListColumnFormat align); | |
289 | ||
290 | void SetTextColour(const wxColour& colText); | |
291 | void SetBackgroundColour(const wxColour& colBack); | |
292 | void SetFont(const wxFont& font); | |
293 | ||
294 | // accessors | |
295 | long GetMask(); | |
296 | long GetId(); | |
297 | int GetColumn(); | |
298 | long GetState(); | |
299 | const wxString& GetText(); | |
300 | int GetImage(); | |
301 | long GetData(); | |
302 | ||
303 | int GetWidth(); | |
304 | wxListColumnFormat GetAlign(); | |
305 | ||
306 | wxListItemAttr *GetAttributes(); | |
307 | bool HasAttributes(); | |
308 | ||
309 | wxColour GetTextColour() const; | |
310 | wxColour GetBackgroundColour() const; | |
311 | wxFont GetFont() const; | |
312 | ||
313 | // these members are public for compatibility | |
7bf85405 RD |
314 | long m_mask; // Indicates what fields are valid |
315 | long m_itemId; // The zero-based item position | |
316 | int m_col; // Zero-based column, if in report mode | |
317 | long m_state; // The state of the item | |
f6bcfd97 | 318 | long m_stateMask;// Which flags of m_state are valid (uses same flags) |
7bf85405 RD |
319 | wxString m_text; // The label/header text |
320 | int m_image; // The zero-based index into an image list | |
321 | long m_data; // App-defined data | |
7bf85405 RD |
322 | |
323 | // For columns only | |
324 | int m_format; // left, right, centre | |
325 | int m_width; // width of column | |
326 | ||
7bf85405 RD |
327 | }; |
328 | ||
f6bcfd97 | 329 | |
c368d904 | 330 | class wxListEvent: public wxNotifyEvent { |
7bf85405 | 331 | public: |
6d19860f RD |
332 | wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0); |
333 | ||
7bf85405 | 334 | int m_code; |
ebf4302c | 335 | long m_oldItemIndex; |
7bf85405 | 336 | long m_itemIndex; |
7bf85405 | 337 | int m_col; |
7bf85405 RD |
338 | wxPoint m_pointDrag; |
339 | wxListItem m_item; | |
7bf85405 | 340 | |
f6bcfd97 BP |
341 | int GetCode(); |
342 | long GetIndex(); | |
f6bcfd97 | 343 | int GetColumn(); |
f6bcfd97 BP |
344 | wxPoint GetPoint(); |
345 | const wxString& GetLabel(); | |
346 | const wxString& GetText(); | |
347 | int GetImage(); | |
348 | long GetData(); | |
349 | long GetMask(); | |
350 | const wxListItem& GetItem(); | |
6d19860f RD |
351 | |
352 | long GetCacheFrom(); | |
353 | long GetCacheTo(); | |
f6bcfd97 | 354 | }; |
7bf85405 RD |
355 | |
356 | ||
09f3d4e6 | 357 | %{ // C++ Version of a Python aware class |
c7e7022c RD |
358 | class wxPyListCtrl : public wxListCtrl { |
359 | DECLARE_ABSTRACT_CLASS(wxPyListCtrl); | |
7bf85405 | 360 | public: |
09f3d4e6 | 361 | wxPyListCtrl() : wxListCtrl() {} |
c7e7022c RD |
362 | wxPyListCtrl(wxWindow* parent, wxWindowID id, |
363 | const wxPoint& pos, | |
364 | const wxSize& size, | |
365 | long style, | |
366 | const wxValidator& validator, | |
367 | char* name) : | |
368 | wxListCtrl(parent, id, pos, size, style, validator, name) {} | |
369 | ||
09f3d4e6 RD |
370 | bool Create(wxWindow* parent, wxWindowID id, |
371 | const wxPoint& pos, | |
372 | const wxSize& size, | |
373 | long style, | |
374 | const wxValidator& validator, | |
375 | char* name) { | |
376 | return wxListCtrl::Create(parent, id, pos, size, style, validator, name); | |
377 | } | |
378 | ||
c7e7022c RD |
379 | DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText); |
380 | DEC_PYCALLBACK_INT_LONG(OnGetItemImage); | |
381 | DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr); | |
382 | ||
383 | PYPRIVATE; | |
384 | }; | |
385 | ||
386 | IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl); | |
7bf85405 | 387 | |
c7e7022c RD |
388 | IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText); |
389 | IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage); | |
390 | IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr); | |
391 | %} | |
392 | ||
393 | ||
cdf14688 | 394 | |
c7e7022c RD |
395 | %name(wxListCtrl)class wxPyListCtrl : public wxControl { |
396 | public: | |
397 | wxPyListCtrl(wxWindow* parent, wxWindowID id = -1, | |
398 | const wxPoint& pos = wxDefaultPosition, | |
399 | const wxSize& size = wxDefaultSize, | |
400 | long style = wxLC_ICON, | |
401 | const wxValidator& validator = wxDefaultValidator, | |
402 | char* name = "listCtrl"); | |
09f3d4e6 RD |
403 | %name(wxPreListCtrl)wxPyListCtrl(); |
404 | ||
405 | bool Create(wxWindow* parent, wxWindowID id = -1, | |
406 | const wxPoint& pos = wxDefaultPosition, | |
407 | const wxSize& size = wxDefaultSize, | |
408 | long style = wxLC_ICON, | |
409 | const wxValidator& validator = wxDefaultValidator, | |
410 | char* name = "listCtrl"); | |
c7e7022c | 411 | |
0122b7e3 RD |
412 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
413 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxListCtrl)" | |
9c039d08 | 414 | |
0122b7e3 | 415 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" |
17c0e08c | 416 | %pragma(python) addtomethod = "wxPreListCtrl:val._setOORInfo(val)" |
7bf85405 | 417 | |
c7e7022c RD |
418 | // Set the control colours |
419 | bool SetForegroundColour(const wxColour& col); | |
420 | bool SetBackgroundColour(const wxColour& col); | |
421 | ||
422 | // Gets information about this column | |
423 | bool GetColumn(int col, wxListItem& item) const; | |
424 | ||
425 | // Sets information about this column | |
426 | bool SetColumn(int col, wxListItem& item) ; | |
427 | ||
428 | // Gets the column width | |
429 | int GetColumnWidth(int col) const; | |
430 | ||
431 | // Sets the column width | |
432 | bool SetColumnWidth(int col, int width) ; | |
433 | ||
434 | // Gets the number of items that can fit vertically in the | |
435 | // visible area of the list control (list or report view) | |
436 | // or the total number of items in the list control (icon | |
437 | // or small icon view) | |
438 | int GetCountPerPage() const; | |
439 | ||
cd096152 | 440 | #ifdef __WXMSW__ |
c7e7022c RD |
441 | // Gets the edit control for editing labels. |
442 | wxTextCtrl* GetEditControl() const; | |
cd096152 | 443 | #endif |
c7e7022c RD |
444 | |
445 | //bool GetItem(wxListItem& info) const ; | |
7bf85405 | 446 | %addmethods { |
c7e7022c | 447 | // Gets information about the item |
e166644c | 448 | %new wxListItem* GetItem(long itemId, int col=0) { |
7bf85405 | 449 | wxListItem* info = new wxListItem; |
0699c864 | 450 | info->m_itemId = itemId; |
e166644c | 451 | info->m_col = col; |
f17fee68 | 452 | info->m_mask = 0xFFFF; |
7bf85405 RD |
453 | self->GetItem(*info); |
454 | return info; | |
455 | } | |
5597b61e RD |
456 | } // The OOR typemaps don't know what to do with the %new, so fix it up. |
457 | %pragma(python) addtoclass = " | |
458 | def GetItem(self, *_args, **_kwargs): | |
459 | val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs) | |
460 | val.thisown = 1 | |
461 | return val | |
462 | " | |
463 | ||
c7e7022c RD |
464 | |
465 | // Sets information about the item | |
466 | bool SetItem(wxListItem& info) ; | |
467 | ||
468 | // Sets a string field at a particular column | |
469 | %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1); | |
470 | ||
471 | // Gets the item state | |
472 | int GetItemState(long item, long stateMask) const ; | |
473 | ||
474 | // Sets the item state | |
475 | bool SetItemState(long item, long state, long stateMask) ; | |
476 | ||
477 | // Sets the item image | |
478 | bool SetItemImage(long item, int image, int selImage) ; | |
479 | ||
480 | // Gets the item text | |
481 | wxString GetItemText(long item) const ; | |
482 | ||
483 | // Sets the item text | |
484 | void SetItemText(long item, const wxString& str) ; | |
485 | ||
486 | // Gets the item data | |
487 | long GetItemData(long item) const ; | |
488 | ||
489 | // Sets the item data | |
490 | bool SetItemData(long item, long data) ; | |
491 | ||
492 | ||
493 | //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ; | |
494 | //bool GetItemPosition(long item, wxPoint& pos) const ; | |
00b6c4e3 RD |
495 | |
496 | // Gets the item position | |
5597b61e | 497 | %addmethods { |
7bf85405 RD |
498 | %new wxPoint* GetItemPosition(long item) { |
499 | wxPoint* pos = new wxPoint; | |
500 | self->GetItemPosition(item, *pos); | |
501 | return pos; | |
502 | } | |
c7e7022c | 503 | // Gets the item rectangle |
7bf85405 RD |
504 | %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) { |
505 | wxRect* rect= new wxRect; | |
506 | self->GetItemRect(item, *rect, code); | |
507 | return rect; | |
508 | } | |
509 | } | |
510 | ||
c7e7022c RD |
511 | |
512 | // Sets the item position | |
513 | bool SetItemPosition(long item, const wxPoint& pos) ; | |
514 | ||
515 | // Gets the number of items in the list control | |
516 | int GetItemCount() const; | |
517 | ||
518 | // Gets the number of columns in the list control | |
9d37f964 | 519 | int GetColumnCount() const; |
c7e7022c RD |
520 | |
521 | // Retrieves the spacing between icons in pixels. | |
522 | // If small is TRUE, gets the spacing for the small icon | |
523 | // view, otherwise the large icon view. | |
524 | int GetItemSpacing(bool isSmall) const; | |
525 | ||
526 | // Gets the number of selected items in the list control | |
527 | int GetSelectedItemCount() const; | |
528 | ||
529 | // Gets the text colour of the listview | |
530 | wxColour GetTextColour() const; | |
531 | ||
532 | // Sets the text colour of the listview | |
4f22cf8d | 533 | void SetTextColour(const wxColour& col); |
c7e7022c RD |
534 | |
535 | // Gets the index of the topmost visible item when in | |
536 | // list or report view | |
537 | long GetTopItem() const ; | |
538 | ||
539 | // Add or remove a single window style | |
540 | void SetSingleStyle(long style, bool add = TRUE) ; | |
541 | ||
542 | // Set the whole window style | |
543 | void SetWindowStyleFlag(long style) ; | |
544 | ||
545 | // Searches for an item, starting from 'item'. | |
546 | // item can be -1 to find the first item that matches the | |
547 | // specified flags. | |
548 | // Returns the item or -1 if unsuccessful. | |
549 | long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ; | |
550 | ||
551 | // Gets one of the three image lists | |
552 | wxImageList *GetImageList(int which) const ; | |
553 | ||
554 | // Sets the image list | |
555 | void SetImageList(wxImageList *imageList, int which) ; | |
556 | void AssignImageList(wxImageList *imageList, int which) ; | |
557 | %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0" | |
558 | ||
559 | // returns true if it is a virtual list control | |
560 | bool IsVirtual() const; | |
561 | ||
562 | // refresh items selectively (only useful for virtual list controls) | |
563 | void RefreshItem(long item); | |
564 | void RefreshItems(long itemFrom, long itemTo); | |
565 | ||
c7e7022c RD |
566 | // Arranges the items |
567 | bool Arrange(int flag = wxLIST_ALIGN_DEFAULT); | |
568 | ||
569 | // Deletes an item | |
570 | bool DeleteItem(long item); | |
571 | ||
572 | // Deletes all items | |
573 | bool DeleteAllItems() ; | |
574 | ||
575 | // Deletes a column | |
576 | bool DeleteColumn(int col); | |
577 | ||
578 | // Deletes all columns | |
579 | bool DeleteAllColumns(); | |
580 | ||
581 | // Clears items, and columns if there are any. | |
582 | void ClearAll(); | |
583 | ||
cd096152 | 584 | #ifdef __WXMSW__ |
c7e7022c RD |
585 | // Edit the label |
586 | wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/); | |
587 | ||
588 | // End label editing, optionally cancelling the edit | |
589 | bool EndEditLabel(bool cancel); | |
cd096152 | 590 | #endif |
c7e7022c RD |
591 | |
592 | // Ensures this item is visible | |
593 | bool EnsureVisible(long item) ; | |
594 | ||
595 | // Find an item whose label matches this string, starting from the item after 'start' | |
596 | // or the beginning if 'start' is -1. | |
597 | long FindItem(long start, const wxString& str, bool partial = FALSE); | |
598 | ||
599 | // Find an item whose data matches this data, starting from the item after 'start' | |
600 | // or the beginning if 'start' is -1. | |
601 | %name(FindItemData)long FindItem(long start, long data); | |
602 | ||
603 | // Find an item nearest this position in the specified direction, starting from | |
604 | // the item after 'start' or the beginning if 'start' is -1. | |
605 | %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction); | |
606 | ||
607 | // Determines which item (if any) is at the specified point, | |
608 | // giving details in the second return value (see wxLIST_HITTEST_... flags above) | |
7bf85405 | 609 | long HitTest(const wxPoint& point, int& OUTPUT); |
c7e7022c RD |
610 | |
611 | // Inserts an item, returning the index of the new item if successful, | |
612 | // -1 otherwise. | |
613 | long InsertItem(wxListItem& info); | |
614 | ||
615 | // Insert a string item | |
616 | %name(InsertStringItem)long InsertItem(long index, const wxString& label); | |
617 | ||
618 | // Insert an image item | |
619 | %name(InsertImageItem)long InsertItem(long index, int imageIndex); | |
620 | ||
621 | // Insert an image/string item | |
622 | %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex); | |
623 | ||
624 | // For list view mode (only), inserts a column. | |
c368d904 | 625 | %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info); |
c7e7022c RD |
626 | |
627 | long InsertColumn(long col, | |
628 | const wxString& heading, | |
7bf85405 RD |
629 | int format = wxLIST_FORMAT_LEFT, |
630 | int width = -1); | |
631 | ||
c7e7022c RD |
632 | // set the number of items in a virtual list control |
633 | void SetItemCount(long count); | |
7bf85405 | 634 | |
c7e7022c RD |
635 | // Scrolls the list control. If in icon, small icon or report view mode, |
636 | // x specifies the number of pixels to scroll. If in list view mode, x | |
637 | // specifies the number of columns to scroll. | |
638 | // If in icon, small icon or list view mode, y specifies the number of pixels | |
639 | // to scroll. If in report view mode, y specifies the number of lines to scroll. | |
7bf85405 | 640 | bool ScrollList(int dx, int dy); |
dcd38683 RD |
641 | |
642 | // bool SortItems(wxListCtrlCompare fn, long data); | |
643 | %addmethods { | |
c7e7022c RD |
644 | // Sort items. |
645 | // func is a function which takes 2 long arguments: item1, item2. | |
646 | // item1 is the long data associated with a first item (NOT the index). | |
647 | // item2 is the long data associated with a second item (NOT the index). | |
648 | // The return value is a negative number if the first item should precede the second | |
649 | // item, a positive number of the second item should precede the first, | |
650 | // or zero if the two items are equivalent. | |
dcd38683 RD |
651 | bool SortItems(PyObject* func) { |
652 | if (!PyCallable_Check(func)) | |
653 | return FALSE; | |
f6bcfd97 | 654 | return self->SortItems(wxPyListCtrl_SortItems, (long)func); |
dcd38683 RD |
655 | } |
656 | } | |
c7e7022c | 657 | |
6d19860f RD |
658 | %pragma(python) addtoclass = " |
659 | # Some helpers... | |
660 | ||
43097598 | 661 | def Select(self, idx, on=1): |
6d19860f RD |
662 | '''[de]select an item''' |
663 | if on: state = wxLIST_STATE_SELECTED | |
664 | else: state = 0 | |
665 | self.SetItemState(idx, state, wxLIST_STATE_SELECTED) | |
666 | ||
667 | def Focus(self, idx): | |
668 | '''Focus and show the given item''' | |
669 | self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED) | |
670 | self.EnsureVisible(idx) | |
671 | ||
672 | def GetFocusedItem(self): | |
673 | '''get the currently focused item or -1 if none''' | |
674 | return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED) | |
675 | ||
676 | def IsSelected(self, idx): | |
677 | '''return TRUE if the item is selected''' | |
678 | return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0 | |
679 | ||
680 | def SetColumnImage(self, col, image): | |
681 | item = wxListItem() | |
682 | item.SetMask(wxLIST_MASK_IMAGE) | |
683 | item.SetImage(image) | |
684 | self.SetColumn(col, item) | |
685 | ||
686 | def ClearColumnImage(self, col): | |
687 | self.SetColumnImage(col, -1) | |
688 | " | |
7bf85405 RD |
689 | }; |
690 | ||
c7e7022c RD |
691 | |
692 | ||
6d19860f | 693 | %{ // Python aware sorting function for wxPyListCtrl |
f6bcfd97 | 694 | int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) { |
dcd38683 RD |
695 | int retval = 0; |
696 | PyObject* func = (PyObject*)funcPtr; | |
4268f798 | 697 | wxPyBeginBlockThreads(); |
7bf85405 | 698 | |
dcd38683 RD |
699 | PyObject* args = Py_BuildValue("(ii)", item1, item2); |
700 | PyObject* result = PyEval_CallObject(func, args); | |
701 | Py_DECREF(args); | |
702 | if (result) { | |
703 | retval = PyInt_AsLong(result); | |
704 | Py_DECREF(result); | |
705 | } | |
706 | ||
4268f798 | 707 | wxPyEndBlockThreads(); |
dcd38683 RD |
708 | return retval; |
709 | } | |
710 | ||
711 | %} | |
7bf85405 | 712 | |
6d19860f RD |
713 | //---------------------------------------------------------------------- |
714 | ||
715 | class wxListView : public wxPyListCtrl | |
716 | { | |
717 | public: | |
718 | wxListView( wxWindow *parent, | |
719 | wxWindowID id = -1, | |
720 | const wxPoint& pos = wxDefaultPosition, | |
721 | const wxSize& size = wxDefaultSize, | |
722 | long style = wxLC_REPORT, | |
723 | const wxValidator& validator = wxDefaultValidator, | |
724 | const wxString &name = "listctrl" ); | |
725 | %name(wxPreListView)wxListView(); | |
726 | ||
727 | bool Create( wxWindow *parent, | |
728 | wxWindowID id = -1, | |
729 | const wxPoint& pos = wxDefaultPosition, | |
730 | const wxSize& size = wxDefaultSize, | |
731 | long style = wxLC_REPORT, | |
732 | const wxValidator& validator = wxDefaultValidator, | |
733 | const wxString &name = "listctrl" ); | |
734 | ||
0122b7e3 | 735 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" |
17c0e08c | 736 | %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)" |
6d19860f RD |
737 | |
738 | // [de]select an item | |
739 | void Select(long n, bool on = TRUE); | |
740 | ||
741 | // focus and show the given item | |
742 | void Focus(long index); | |
743 | ||
744 | // get the currently focused item or -1 if none | |
745 | long GetFocusedItem() const; | |
746 | ||
747 | // get first and subsequent selected items, return -1 when no more | |
748 | long GetNextSelected(long item) const; | |
749 | long GetFirstSelected() const; | |
750 | ||
751 | // return TRUE if the item is selected | |
752 | bool IsSelected(long index); | |
753 | ||
754 | void SetColumnImage(int col, int image); | |
755 | void ClearColumnImage(int col); | |
756 | }; | |
757 | ||
758 | ||
7bf85405 RD |
759 | //---------------------------------------------------------------------- |
760 | ||
00b6c4e3 RD |
761 | // wxTreeCtrl flags |
762 | enum { | |
763 | wxTR_NO_BUTTONS, | |
764 | wxTR_HAS_BUTTONS, | |
765 | wxTR_TWIST_BUTTONS, | |
766 | wxTR_NO_LINES, | |
767 | wxTR_MAC_BUTTONS, | |
b5a5d647 | 768 | wxTR_AQUA_BUTTONS, |
00b6c4e3 RD |
769 | |
770 | wxTR_SINGLE, | |
771 | wxTR_MULTIPLE, | |
772 | wxTR_EXTENDED, | |
b5a5d647 | 773 | wxTR_FULL_ROW_HIGHLIGHT, |
00b6c4e3 RD |
774 | |
775 | wxTR_EDIT_LABELS, | |
776 | wxTR_LINES_AT_ROOT, | |
777 | wxTR_HIDE_ROOT, | |
778 | wxTR_ROW_LINES, | |
779 | wxTR_HAS_VARIABLE_ROW_HEIGHT, | |
780 | ||
781 | wxTR_DEFAULT_STYLE, | |
782 | }; | |
783 | ||
694759cf RD |
784 | enum wxTreeItemIcon |
785 | { | |
786 | wxTreeItemIcon_Normal, // not selected, not expanded | |
787 | wxTreeItemIcon_Selected, // selected, not expanded | |
788 | wxTreeItemIcon_Expanded, // not selected, expanded | |
789 | wxTreeItemIcon_SelectedExpanded, // selected, expanded | |
790 | wxTreeItemIcon_Max | |
791 | }; | |
792 | ||
7bf85405 | 793 | |
164b735b RD |
794 | // constants for HitTest |
795 | enum { | |
796 | wxTREE_HITTEST_ABOVE, | |
797 | wxTREE_HITTEST_BELOW, | |
798 | wxTREE_HITTEST_NOWHERE, | |
799 | wxTREE_HITTEST_ONITEMBUTTON, | |
800 | wxTREE_HITTEST_ONITEMICON, | |
801 | wxTREE_HITTEST_ONITEMINDENT, | |
802 | wxTREE_HITTEST_ONITEMLABEL, | |
803 | wxTREE_HITTEST_ONITEMRIGHT, | |
804 | wxTREE_HITTEST_ONITEMSTATEICON, | |
805 | wxTREE_HITTEST_TOLEFT, | |
806 | wxTREE_HITTEST_TORIGHT, | |
807 | wxTREE_HITTEST_ONITEMUPPERPART, | |
808 | wxTREE_HITTEST_ONITEMLOWERPART, | |
809 | wxTREE_HITTEST_ONITEM | |
810 | }; | |
811 | ||
812 | ||
1b62f00d RD |
813 | enum { |
814 | /* Tree control event types */ | |
815 | wxEVT_COMMAND_TREE_BEGIN_DRAG, | |
816 | wxEVT_COMMAND_TREE_BEGIN_RDRAG, | |
817 | wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, | |
818 | wxEVT_COMMAND_TREE_END_LABEL_EDIT, | |
819 | wxEVT_COMMAND_TREE_DELETE_ITEM, | |
820 | wxEVT_COMMAND_TREE_GET_INFO, | |
821 | wxEVT_COMMAND_TREE_SET_INFO, | |
822 | wxEVT_COMMAND_TREE_ITEM_EXPANDED, | |
823 | wxEVT_COMMAND_TREE_ITEM_EXPANDING, | |
824 | wxEVT_COMMAND_TREE_ITEM_COLLAPSED, | |
825 | wxEVT_COMMAND_TREE_ITEM_COLLAPSING, | |
826 | wxEVT_COMMAND_TREE_SEL_CHANGED, | |
827 | wxEVT_COMMAND_TREE_SEL_CHANGING, | |
828 | wxEVT_COMMAND_TREE_KEY_DOWN, | |
829 | wxEVT_COMMAND_TREE_ITEM_ACTIVATED, | |
830 | wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, | |
831 | wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, | |
d1679124 | 832 | wxEVT_COMMAND_TREE_END_DRAG, |
1b62f00d RD |
833 | }; |
834 | ||
835 | ||
00b6c4e3 RD |
836 | %pragma(python) code = " |
837 | # wxTreeCtrl events | |
838 | def EVT_TREE_BEGIN_DRAG(win, id, func): | |
839 | win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func) | |
840 | ||
841 | def EVT_TREE_BEGIN_RDRAG(win, id, func): | |
842 | win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func) | |
843 | ||
844 | def EVT_TREE_END_DRAG(win, id, func): | |
845 | win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func) | |
846 | ||
847 | def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func): | |
848 | win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func) | |
849 | ||
850 | def EVT_TREE_END_LABEL_EDIT(win, id, func): | |
851 | win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func) | |
852 | ||
853 | def EVT_TREE_GET_INFO(win, id, func): | |
854 | win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func) | |
855 | ||
856 | def EVT_TREE_SET_INFO(win, id, func): | |
857 | win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func) | |
858 | ||
859 | def EVT_TREE_ITEM_EXPANDED(win, id, func): | |
860 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func) | |
861 | ||
862 | def EVT_TREE_ITEM_EXPANDING(win, id, func): | |
863 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func) | |
864 | ||
865 | def EVT_TREE_ITEM_COLLAPSED(win, id, func): | |
866 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func) | |
867 | ||
868 | def EVT_TREE_ITEM_COLLAPSING(win, id, func): | |
869 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func) | |
870 | ||
871 | def EVT_TREE_SEL_CHANGED(win, id, func): | |
872 | win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func) | |
873 | ||
874 | def EVT_TREE_SEL_CHANGING(win, id, func): | |
875 | win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func) | |
876 | ||
877 | def EVT_TREE_KEY_DOWN(win, id, func): | |
878 | win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func) | |
879 | ||
880 | def EVT_TREE_DELETE_ITEM(win, id, func): | |
881 | win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func) | |
882 | ||
883 | def EVT_TREE_ITEM_ACTIVATED(win, id, func): | |
884 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func) | |
885 | ||
886 | def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func): | |
887 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func) | |
888 | ||
889 | def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func): | |
890 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func) | |
891 | " | |
892 | ||
893 | ||
894 | class wxTreeItemAttr | |
895 | { | |
896 | public: | |
897 | // ctors | |
898 | //wxTreeItemAttr() { } | |
899 | wxTreeItemAttr(const wxColour& colText = wxNullColour, | |
900 | const wxColour& colBack = wxNullColour, | |
901 | const wxFont& font = wxNullFont); | |
902 | ||
903 | // setters | |
904 | void SetTextColour(const wxColour& colText); | |
905 | void SetBackgroundColour(const wxColour& colBack); | |
906 | void SetFont(const wxFont& font); | |
907 | ||
908 | // accessors | |
909 | bool HasTextColour(); | |
910 | bool HasBackgroundColour(); | |
911 | bool HasFont(); | |
912 | ||
c5943253 RD |
913 | wxColour GetTextColour(); |
914 | wxColour GetBackgroundColour(); | |
915 | wxFont GetFont(); | |
00b6c4e3 RD |
916 | }; |
917 | ||
918 | ||
d5c9047a RD |
919 | class wxTreeItemId { |
920 | public: | |
921 | wxTreeItemId(); | |
922 | ~wxTreeItemId(); | |
bb0054cd | 923 | bool IsOk(); |
78e8819c | 924 | %pragma(python) addtoclass = "Ok = IsOk" |
d5c9047a | 925 | |
f6bcfd97 BP |
926 | %addmethods { |
927 | int __cmp__(wxTreeItemId* other) { | |
c368d904 | 928 | if (! other) return -1; |
f6bcfd97 BP |
929 | return *self != *other; |
930 | } | |
931 | } | |
d5c9047a RD |
932 | }; |
933 | ||
934 | ||
935 | ||
cf694132 RD |
936 | %{ |
937 | class wxPyTreeItemData : public wxTreeItemData { | |
d5c9047a | 938 | public: |
cf694132 | 939 | wxPyTreeItemData(PyObject* obj = NULL) { |
c368d904 | 940 | if (obj == NULL) |
cf694132 | 941 | obj = Py_None; |
c368d904 RD |
942 | Py_INCREF(obj); |
943 | m_obj = obj; | |
cf694132 | 944 | } |
d5c9047a | 945 | |
cf694132 | 946 | ~wxPyTreeItemData() { |
4268f798 | 947 | wxPyBeginBlockThreads(); |
c368d904 | 948 | Py_DECREF(m_obj); |
4268f798 | 949 | wxPyEndBlockThreads(); |
cf694132 RD |
950 | } |
951 | ||
952 | PyObject* GetData() { | |
953 | Py_INCREF(m_obj); | |
954 | return m_obj; | |
955 | } | |
956 | ||
957 | void SetData(PyObject* obj) { | |
4268f798 | 958 | wxPyBeginBlockThreads(); |
cf694132 | 959 | Py_DECREF(m_obj); |
4268f798 | 960 | wxPyEndBlockThreads(); |
cf694132 RD |
961 | m_obj = obj; |
962 | Py_INCREF(obj); | |
963 | } | |
964 | ||
965 | PyObject* m_obj; | |
d5c9047a | 966 | }; |
cf694132 | 967 | %} |
d5c9047a RD |
968 | |
969 | ||
970 | ||
9416aa89 | 971 | %name(wxTreeItemData) class wxPyTreeItemData : public wxObject { |
cf694132 RD |
972 | public: |
973 | wxPyTreeItemData(PyObject* obj = NULL); | |
974 | ||
975 | PyObject* GetData(); | |
976 | void SetData(PyObject* obj); | |
977 | ||
978 | const wxTreeItemId& GetId(); | |
979 | void SetId(const wxTreeItemId& id); | |
980 | }; | |
981 | ||
982 | ||
d5c9047a | 983 | |
8bf5d46e | 984 | class wxTreeEvent : public wxNotifyEvent { |
d5c9047a | 985 | public: |
00b6c4e3 RD |
986 | wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); |
987 | ||
d5c9047a RD |
988 | wxTreeItemId GetItem(); |
989 | wxTreeItemId GetOldItem(); | |
990 | wxPoint GetPoint(); | |
ecc08ead | 991 | const wxKeyEvent& GetKeyEvent(); |
d5c9047a | 992 | int GetCode(); |
8bf5d46e | 993 | const wxString& GetLabel(); |
d5c9047a RD |
994 | }; |
995 | ||
996 | ||
f6bcfd97 | 997 | |
09f3d4e6 | 998 | %{ // C++ version of Python aware wxTreeCtrl |
f6bcfd97 | 999 | class wxPyTreeCtrl : public wxTreeCtrl { |
3b36695d | 1000 | DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl); |
f6bcfd97 | 1001 | public: |
09f3d4e6 | 1002 | wxPyTreeCtrl() : wxTreeCtrl() {} |
f6bcfd97 BP |
1003 | wxPyTreeCtrl(wxWindow *parent, wxWindowID id, |
1004 | const wxPoint& pos, | |
1005 | const wxSize& size, | |
1006 | long style, | |
1007 | const wxValidator& validator, | |
1008 | char* name) : | |
1009 | wxTreeCtrl(parent, id, pos, size, style, validator, name) {} | |
1010 | ||
09f3d4e6 RD |
1011 | bool Create(wxWindow *parent, wxWindowID id, |
1012 | const wxPoint& pos, | |
1013 | const wxSize& size, | |
1014 | long style, | |
1015 | const wxValidator& validator, | |
1016 | char* name) { | |
1017 | return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name); | |
1018 | } | |
1019 | ||
1020 | ||
f6bcfd97 BP |
1021 | int OnCompareItems(const wxTreeItemId& item1, |
1022 | const wxTreeItemId& item2) { | |
1023 | int rval = 0; | |
19a97bd6 | 1024 | bool found; |
4268f798 | 1025 | wxPyBeginBlockThreads(); |
19a97bd6 | 1026 | if ((found = m_myInst.findCallback("OnCompareItems"))) |
f6bcfd97 BP |
1027 | rval = m_myInst.callCallback(Py_BuildValue( |
1028 | "(OO)", | |
1029 | wxPyConstructObject((void*)&item1, "wxTreeItemId"), | |
1030 | wxPyConstructObject((void*)&item2, "wxTreeItemId"))); | |
4268f798 | 1031 | wxPyEndBlockThreads(); |
19a97bd6 | 1032 | if (! found) |
f6bcfd97 | 1033 | rval = wxTreeCtrl::OnCompareItems(item1, item2); |
f6bcfd97 BP |
1034 | return rval; |
1035 | } | |
1036 | PYPRIVATE; | |
1037 | }; | |
1038 | ||
3b36695d RD |
1039 | IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl); |
1040 | ||
f6bcfd97 BP |
1041 | %} |
1042 | ||
d5c9047a RD |
1043 | // These are for the GetFirstChild/GetNextChild methods below |
1044 | %typemap(python, in) long& INOUT = long* INOUT; | |
1045 | %typemap(python, argout) long& INOUT = long* INOUT; | |
1046 | ||
1047 | ||
f6bcfd97 | 1048 | %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl { |
d5c9047a | 1049 | public: |
f6bcfd97 | 1050 | wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1, |
b68dc582 RD |
1051 | const wxPoint& pos = wxDefaultPosition, |
1052 | const wxSize& size = wxDefaultSize, | |
d5c9047a | 1053 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, |
b68dc582 | 1054 | const wxValidator& validator = wxDefaultValidator, |
d5c9047a | 1055 | char* name = "wxTreeCtrl"); |
09f3d4e6 RD |
1056 | %name(wxPreTreeCtrl)wxPyTreeCtrl(); |
1057 | ||
1058 | bool Create(wxWindow *parent, wxWindowID id = -1, | |
1059 | const wxPoint& pos = wxDefaultPosition, | |
1060 | const wxSize& size = wxDefaultSize, | |
1061 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, | |
1062 | const wxValidator& validator = wxDefaultValidator, | |
1063 | char* name = "wxTreeCtrl"); | |
d5c9047a | 1064 | |
0122b7e3 RD |
1065 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
1066 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)" | |
1067 | ||
1068 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" | |
17c0e08c | 1069 | %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)" |
d5c9047a RD |
1070 | |
1071 | size_t GetCount(); | |
1072 | unsigned int GetIndent(); | |
1073 | void SetIndent(unsigned int indent); | |
1074 | wxImageList *GetImageList(); | |
1075 | wxImageList *GetStateImageList(); | |
1b62f00d | 1076 | void SetImageList(wxImageList *imageList); |
d5c9047a | 1077 | void SetStateImageList(wxImageList *imageList); |
00b6c4e3 RD |
1078 | void AssignImageList(wxImageList* imageList); |
1079 | %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0" | |
1080 | void AssignStateImageList(wxImageList* imageList); | |
1081 | %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0" | |
d5c9047a | 1082 | |
b1462dfa RD |
1083 | unsigned int GetSpacing(); |
1084 | void SetSpacing(unsigned int spacing); | |
1085 | ||
d5c9047a | 1086 | wxString GetItemText(const wxTreeItemId& item); |
694759cf RD |
1087 | int GetItemImage(const wxTreeItemId& item, |
1088 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
d5c9047a | 1089 | int GetItemSelectedImage(const wxTreeItemId& item); |
d5c9047a RD |
1090 | |
1091 | void SetItemText(const wxTreeItemId& item, const wxString& text); | |
694759cf RD |
1092 | void SetItemImage(const wxTreeItemId& item, int image, |
1093 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
d5c9047a | 1094 | void SetItemSelectedImage(const wxTreeItemId& item, int image); |
08127323 | 1095 | void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE); |
d5c9047a | 1096 | |
cf694132 | 1097 | %addmethods { |
c368d904 RD |
1098 | // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData |
1099 | // if needed. | |
cf694132 RD |
1100 | wxPyTreeItemData* GetItemData(const wxTreeItemId& item) { |
1101 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
1102 | if (data == NULL) { | |
1103 | data = new wxPyTreeItemData(); | |
f6bcfd97 | 1104 | data->SetId(item); // set the id |
cf694132 RD |
1105 | self->SetItemData(item, data); |
1106 | } | |
1107 | return data; | |
1108 | } | |
1109 | ||
1110 | void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { | |
f6bcfd97 BP |
1111 | data->SetId(item); // set the id |
1112 | self->SetItemData(item, data); | |
c368d904 | 1113 | } |
cf694132 | 1114 | |
c368d904 RD |
1115 | // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by |
1116 | // automatically creating data classes. | |
1117 | PyObject* GetPyData(const wxTreeItemId& item) { | |
cf694132 RD |
1118 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); |
1119 | if (data == NULL) { | |
1120 | data = new wxPyTreeItemData(); | |
f6bcfd97 | 1121 | data->SetId(item); // set the id |
cf694132 RD |
1122 | self->SetItemData(item, data); |
1123 | } | |
1124 | return data->GetData(); | |
c368d904 | 1125 | } |
cf694132 RD |
1126 | |
1127 | void SetPyData(const wxTreeItemId& item, PyObject* obj) { | |
1128 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
1129 | if (data == NULL) { | |
1130 | data = new wxPyTreeItemData(obj); | |
f6bcfd97 | 1131 | data->SetId(item); // set the id |
cf694132 RD |
1132 | self->SetItemData(item, data); |
1133 | } else | |
1134 | data->SetData(obj); | |
c368d904 | 1135 | } |
cf694132 RD |
1136 | } |
1137 | ||
1138 | ||
d5c9047a RD |
1139 | bool IsVisible(const wxTreeItemId& item); |
1140 | bool ItemHasChildren(const wxTreeItemId& item); | |
1141 | bool IsExpanded(const wxTreeItemId& item); | |
1142 | bool IsSelected(const wxTreeItemId& item); | |
1143 | ||
1144 | wxTreeItemId GetRootItem(); | |
1145 | wxTreeItemId GetSelection(); | |
eb715945 | 1146 | %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item); |
d426c97e RD |
1147 | //size_t GetSelections(wxArrayTreeItemIds& selection); |
1148 | %addmethods { | |
1149 | PyObject* GetSelections() { | |
4268f798 | 1150 | wxPyBeginBlockThreads(); |
d426c97e RD |
1151 | PyObject* rval = PyList_New(0); |
1152 | wxArrayTreeItemIds array; | |
1153 | size_t num, x; | |
1154 | num = self->GetSelections(array); | |
1155 | for (x=0; x < num; x++) { | |
c368d904 RD |
1156 | wxTreeItemId *tii = new wxTreeItemId(array.Item(x)); |
1157 | PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE); | |
d426c97e RD |
1158 | PyList_Append(rval, item); |
1159 | } | |
4268f798 | 1160 | wxPyEndBlockThreads(); |
d426c97e RD |
1161 | return rval; |
1162 | } | |
1163 | } | |
1164 | ||
1165 | ||
d5c9047a | 1166 | |
bb0054cd RD |
1167 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); |
1168 | ||
d5c9047a RD |
1169 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT); |
1170 | wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT); | |
1171 | wxTreeItemId GetNextSibling(const wxTreeItemId& item); | |
1172 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item); | |
1173 | wxTreeItemId GetFirstVisibleItem(); | |
1174 | wxTreeItemId GetNextVisible(const wxTreeItemId& item); | |
1175 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item); | |
d426c97e RD |
1176 | wxTreeItemId GetLastChild(const wxTreeItemId& item); |
1177 | ||
d5c9047a RD |
1178 | |
1179 | ||
1180 | wxTreeItemId AddRoot(const wxString& text, | |
1181 | int image = -1, int selectedImage = -1, | |
cf694132 | 1182 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
1183 | wxTreeItemId PrependItem(const wxTreeItemId& parent, |
1184 | const wxString& text, | |
1185 | int image = -1, int selectedImage = -1, | |
cf694132 | 1186 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
1187 | wxTreeItemId InsertItem(const wxTreeItemId& parent, |
1188 | const wxTreeItemId& idPrevious, | |
1189 | const wxString& text, | |
1190 | int image = -1, int selectedImage = -1, | |
cf694132 | 1191 | wxPyTreeItemData *data = NULL); |
f6bcfd97 BP |
1192 | %name(InsertItemBefore) |
1193 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
1194 | size_t before, | |
1195 | const wxString& text, | |
1196 | int image = -1, int selectedImage = -1, | |
1197 | wxTreeItemData *data = NULL); | |
d5c9047a RD |
1198 | wxTreeItemId AppendItem(const wxTreeItemId& parent, |
1199 | const wxString& text, | |
1200 | int image = -1, int selectedImage = -1, | |
cf694132 | 1201 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
1202 | |
1203 | void Delete(const wxTreeItemId& item); | |
08127323 | 1204 | void DeleteChildren(const wxTreeItemId& item); |
d5c9047a RD |
1205 | void DeleteAllItems(); |
1206 | ||
1207 | void Expand(const wxTreeItemId& item); | |
1208 | void Collapse(const wxTreeItemId& item); | |
1209 | void CollapseAndReset(const wxTreeItemId& item); | |
1210 | void Toggle(const wxTreeItemId& item); | |
1211 | ||
1212 | void Unselect(); | |
8bf5d46e | 1213 | void UnselectAll(); |
d5c9047a RD |
1214 | void SelectItem(const wxTreeItemId& item); |
1215 | void EnsureVisible(const wxTreeItemId& item); | |
1216 | void ScrollTo(const wxTreeItemId& item); | |
8bf5d46e | 1217 | #ifdef __WXMSW__ |
d5c9047a | 1218 | wxTextCtrl* EditLabel(const wxTreeItemId& item); |
d5c9047a | 1219 | wxTextCtrl* GetEditControl(); |
b1462dfa | 1220 | void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE); |
8bf5d46e RD |
1221 | #else |
1222 | void EditLabel(const wxTreeItemId& item); | |
1223 | #endif | |
d5c9047a | 1224 | |
d426c97e | 1225 | void SortChildren(const wxTreeItemId& item); |
d5c9047a | 1226 | |
b1462dfa | 1227 | void SetItemBold(const wxTreeItemId& item, int bold = TRUE); |
b8b8dda7 | 1228 | bool IsBold(const wxTreeItemId& item) const; |
164b735b | 1229 | wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT); |
c127177f | 1230 | |
f6bcfd97 BP |
1231 | |
1232 | ||
b7e72427 RD |
1233 | void SetItemTextColour(const wxTreeItemId& item, const wxColour& col); |
1234 | void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col); | |
1235 | void SetItemFont(const wxTreeItemId& item, const wxFont& font); | |
1236 | ||
4120ef2b | 1237 | #ifdef __WXMSW__ |
b1462dfa | 1238 | void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE); |
74bcba0e | 1239 | #endif |
b1462dfa | 1240 | |
d426c97e RD |
1241 | //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE) |
1242 | %addmethods { | |
1243 | PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) { | |
1244 | wxRect rect; | |
164b735b | 1245 | if (self->GetBoundingRect(item, rect, textOnly)) { |
4268f798 | 1246 | wxPyBeginBlockThreads(); |
164b735b RD |
1247 | wxRect* r = new wxRect(rect); |
1248 | PyObject* val = wxPyConstructObject((void*)r, "wxRect"); | |
4268f798 | 1249 | wxPyEndBlockThreads(); |
164b735b RD |
1250 | return val; |
1251 | } | |
d426c97e RD |
1252 | else { |
1253 | Py_INCREF(Py_None); | |
1254 | return Py_None; | |
1255 | } | |
1256 | } | |
1257 | } | |
74bcba0e | 1258 | |
d426c97e | 1259 | |
c127177f | 1260 | %pragma(python) addtoclass = " |
f6bcfd97 BP |
1261 | # Redefine some methods that SWIG gets a bit confused on... |
1262 | def GetFirstChild(self, *_args, **_kwargs): | |
1263 | val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs) | |
1264 | val1 = wxTreeItemIdPtr(val1) | |
1265 | val1.thisown = 1 | |
1266 | return (val1,val2) | |
1267 | def GetNextChild(self, *_args, **_kwargs): | |
1268 | val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs) | |
c127177f RD |
1269 | val1 = wxTreeItemIdPtr(val1) |
1270 | val1.thisown = 1 | |
1271 | return (val1,val2) | |
f6bcfd97 BP |
1272 | def HitTest(self, *_args, **_kwargs): |
1273 | val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs) | |
c127177f RD |
1274 | val1 = wxTreeItemIdPtr(val1) |
1275 | val1.thisown = 1 | |
1276 | return (val1,val2) | |
1277 | " | |
74bcba0e | 1278 | |
d5c9047a RD |
1279 | }; |
1280 | ||
d5c9047a | 1281 | |
7bf85405 RD |
1282 | //---------------------------------------------------------------------- |
1283 | ||
9416aa89 | 1284 | %init %{ |
a3fbed81 | 1285 | // Map renamed classes back to their common name for OOR |
9416aa89 RD |
1286 | wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData"); |
1287 | wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl"); | |
a3fbed81 | 1288 | wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl"); |
9416aa89 RD |
1289 | %} |
1290 | ||
1291 | //---------------------------------------------------------------------- | |
1292 | ||
7bf85405 | 1293 |