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