]>
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 RD |
412 | |
413 | void _setSelf(PyObject* self, PyObject* _class); | |
c7e7022c | 414 | %pragma(python) addtomethod = "__init__:self._setSelf(self, wxListCtrl)" |
9c039d08 | 415 | |
7bf85405 | 416 | |
c7e7022c RD |
417 | // Set the control colours |
418 | bool SetForegroundColour(const wxColour& col); | |
419 | bool SetBackgroundColour(const wxColour& col); | |
420 | ||
421 | // Gets information about this column | |
422 | bool GetColumn(int col, wxListItem& item) const; | |
423 | ||
424 | // Sets information about this column | |
425 | bool SetColumn(int col, wxListItem& item) ; | |
426 | ||
427 | // Gets the column width | |
428 | int GetColumnWidth(int col) const; | |
429 | ||
430 | // Sets the column width | |
431 | bool SetColumnWidth(int col, int width) ; | |
432 | ||
433 | // Gets the number of items that can fit vertically in the | |
434 | // visible area of the list control (list or report view) | |
435 | // or the total number of items in the list control (icon | |
436 | // or small icon view) | |
437 | int GetCountPerPage() const; | |
438 | ||
cd096152 | 439 | #ifdef __WXMSW__ |
c7e7022c RD |
440 | // Gets the edit control for editing labels. |
441 | wxTextCtrl* GetEditControl() const; | |
cd096152 | 442 | #endif |
c7e7022c RD |
443 | |
444 | //bool GetItem(wxListItem& info) const ; | |
7bf85405 | 445 | %addmethods { |
c7e7022c | 446 | // Gets information about the item |
e166644c | 447 | %new wxListItem* GetItem(long itemId, int col=0) { |
7bf85405 | 448 | wxListItem* info = new wxListItem; |
0699c864 | 449 | info->m_itemId = itemId; |
e166644c | 450 | info->m_col = col; |
f17fee68 | 451 | info->m_mask = 0xFFFF; |
7bf85405 RD |
452 | self->GetItem(*info); |
453 | return info; | |
454 | } | |
5597b61e RD |
455 | } // The OOR typemaps don't know what to do with the %new, so fix it up. |
456 | %pragma(python) addtoclass = " | |
457 | def GetItem(self, *_args, **_kwargs): | |
458 | val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs) | |
459 | val.thisown = 1 | |
460 | return val | |
461 | " | |
462 | ||
c7e7022c RD |
463 | |
464 | // Sets information about the item | |
465 | bool SetItem(wxListItem& info) ; | |
466 | ||
467 | // Sets a string field at a particular column | |
468 | %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1); | |
469 | ||
470 | // Gets the item state | |
471 | int GetItemState(long item, long stateMask) const ; | |
472 | ||
473 | // Sets the item state | |
474 | bool SetItemState(long item, long state, long stateMask) ; | |
475 | ||
476 | // Sets the item image | |
477 | bool SetItemImage(long item, int image, int selImage) ; | |
478 | ||
479 | // Gets the item text | |
480 | wxString GetItemText(long item) const ; | |
481 | ||
482 | // Sets the item text | |
483 | void SetItemText(long item, const wxString& str) ; | |
484 | ||
485 | // Gets the item data | |
486 | long GetItemData(long item) const ; | |
487 | ||
488 | // Sets the item data | |
489 | bool SetItemData(long item, long data) ; | |
490 | ||
491 | ||
492 | //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ; | |
493 | //bool GetItemPosition(long item, wxPoint& pos) const ; | |
00b6c4e3 RD |
494 | |
495 | // Gets the item position | |
5597b61e | 496 | %addmethods { |
7bf85405 RD |
497 | %new wxPoint* GetItemPosition(long item) { |
498 | wxPoint* pos = new wxPoint; | |
499 | self->GetItemPosition(item, *pos); | |
500 | return pos; | |
501 | } | |
c7e7022c | 502 | // Gets the item rectangle |
7bf85405 RD |
503 | %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) { |
504 | wxRect* rect= new wxRect; | |
505 | self->GetItemRect(item, *rect, code); | |
506 | return rect; | |
507 | } | |
508 | } | |
509 | ||
c7e7022c RD |
510 | |
511 | // Sets the item position | |
512 | bool SetItemPosition(long item, const wxPoint& pos) ; | |
513 | ||
514 | // Gets the number of items in the list control | |
515 | int GetItemCount() const; | |
516 | ||
517 | // Gets the number of columns in the list control | |
518 | int GetColumnCount() const { return m_colCount; } | |
519 | ||
520 | // Retrieves the spacing between icons in pixels. | |
521 | // If small is TRUE, gets the spacing for the small icon | |
522 | // view, otherwise the large icon view. | |
523 | int GetItemSpacing(bool isSmall) const; | |
524 | ||
525 | // Gets the number of selected items in the list control | |
526 | int GetSelectedItemCount() const; | |
527 | ||
528 | // Gets the text colour of the listview | |
529 | wxColour GetTextColour() const; | |
530 | ||
531 | // Sets the text colour of the listview | |
4f22cf8d | 532 | void SetTextColour(const wxColour& col); |
c7e7022c RD |
533 | |
534 | // Gets the index of the topmost visible item when in | |
535 | // list or report view | |
536 | long GetTopItem() const ; | |
537 | ||
538 | // Add or remove a single window style | |
539 | void SetSingleStyle(long style, bool add = TRUE) ; | |
540 | ||
541 | // Set the whole window style | |
542 | void SetWindowStyleFlag(long style) ; | |
543 | ||
544 | // Searches for an item, starting from 'item'. | |
545 | // item can be -1 to find the first item that matches the | |
546 | // specified flags. | |
547 | // Returns the item or -1 if unsuccessful. | |
548 | long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ; | |
549 | ||
550 | // Gets one of the three image lists | |
551 | wxImageList *GetImageList(int which) const ; | |
552 | ||
553 | // Sets the image list | |
554 | void SetImageList(wxImageList *imageList, int which) ; | |
555 | void AssignImageList(wxImageList *imageList, int which) ; | |
556 | %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0" | |
557 | ||
558 | // returns true if it is a virtual list control | |
559 | bool IsVirtual() const; | |
560 | ||
561 | // refresh items selectively (only useful for virtual list controls) | |
562 | void RefreshItem(long item); | |
563 | void RefreshItems(long itemFrom, long itemTo); | |
564 | ||
565 | ||
566 | ||
567 | ||
568 | // Arranges the items | |
569 | bool Arrange(int flag = wxLIST_ALIGN_DEFAULT); | |
570 | ||
571 | // Deletes an item | |
572 | bool DeleteItem(long item); | |
573 | ||
574 | // Deletes all items | |
575 | bool DeleteAllItems() ; | |
576 | ||
577 | // Deletes a column | |
578 | bool DeleteColumn(int col); | |
579 | ||
580 | // Deletes all columns | |
581 | bool DeleteAllColumns(); | |
582 | ||
583 | // Clears items, and columns if there are any. | |
584 | void ClearAll(); | |
585 | ||
cd096152 | 586 | #ifdef __WXMSW__ |
c7e7022c RD |
587 | // Edit the label |
588 | wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/); | |
589 | ||
590 | // End label editing, optionally cancelling the edit | |
591 | bool EndEditLabel(bool cancel); | |
cd096152 | 592 | #endif |
c7e7022c RD |
593 | |
594 | // Ensures this item is visible | |
595 | bool EnsureVisible(long item) ; | |
596 | ||
597 | // Find an item whose label matches this string, starting from the item after 'start' | |
598 | // or the beginning if 'start' is -1. | |
599 | long FindItem(long start, const wxString& str, bool partial = FALSE); | |
600 | ||
601 | // Find an item whose data matches this data, starting from the item after 'start' | |
602 | // or the beginning if 'start' is -1. | |
603 | %name(FindItemData)long FindItem(long start, long data); | |
604 | ||
605 | // Find an item nearest this position in the specified direction, starting from | |
606 | // the item after 'start' or the beginning if 'start' is -1. | |
607 | %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction); | |
608 | ||
609 | // Determines which item (if any) is at the specified point, | |
610 | // giving details in the second return value (see wxLIST_HITTEST_... flags above) | |
7bf85405 | 611 | long HitTest(const wxPoint& point, int& OUTPUT); |
c7e7022c RD |
612 | |
613 | // Inserts an item, returning the index of the new item if successful, | |
614 | // -1 otherwise. | |
615 | long InsertItem(wxListItem& info); | |
616 | ||
617 | // Insert a string item | |
618 | %name(InsertStringItem)long InsertItem(long index, const wxString& label); | |
619 | ||
620 | // Insert an image item | |
621 | %name(InsertImageItem)long InsertItem(long index, int imageIndex); | |
622 | ||
623 | // Insert an image/string item | |
624 | %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex); | |
625 | ||
626 | // For list view mode (only), inserts a column. | |
c368d904 | 627 | %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info); |
c7e7022c RD |
628 | |
629 | long InsertColumn(long col, | |
630 | const wxString& heading, | |
7bf85405 RD |
631 | int format = wxLIST_FORMAT_LEFT, |
632 | int width = -1); | |
633 | ||
c7e7022c RD |
634 | // set the number of items in a virtual list control |
635 | void SetItemCount(long count); | |
7bf85405 | 636 | |
c7e7022c RD |
637 | // Scrolls the list control. If in icon, small icon or report view mode, |
638 | // x specifies the number of pixels to scroll. If in list view mode, x | |
639 | // specifies the number of columns to scroll. | |
640 | // If in icon, small icon or list view mode, y specifies the number of pixels | |
641 | // to scroll. If in report view mode, y specifies the number of lines to scroll. | |
7bf85405 | 642 | bool ScrollList(int dx, int dy); |
dcd38683 RD |
643 | |
644 | // bool SortItems(wxListCtrlCompare fn, long data); | |
645 | %addmethods { | |
c7e7022c RD |
646 | // Sort items. |
647 | // func is a function which takes 2 long arguments: item1, item2. | |
648 | // item1 is the long data associated with a first item (NOT the index). | |
649 | // item2 is the long data associated with a second item (NOT the index). | |
650 | // The return value is a negative number if the first item should precede the second | |
651 | // item, a positive number of the second item should precede the first, | |
652 | // or zero if the two items are equivalent. | |
dcd38683 RD |
653 | bool SortItems(PyObject* func) { |
654 | if (!PyCallable_Check(func)) | |
655 | return FALSE; | |
f6bcfd97 | 656 | return self->SortItems(wxPyListCtrl_SortItems, (long)func); |
dcd38683 RD |
657 | } |
658 | } | |
c7e7022c | 659 | |
6d19860f RD |
660 | %pragma(python) addtoclass = " |
661 | # Some helpers... | |
662 | ||
43097598 | 663 | def Select(self, idx, on=1): |
6d19860f RD |
664 | '''[de]select an item''' |
665 | if on: state = wxLIST_STATE_SELECTED | |
666 | else: state = 0 | |
667 | self.SetItemState(idx, state, wxLIST_STATE_SELECTED) | |
668 | ||
669 | def Focus(self, idx): | |
670 | '''Focus and show the given item''' | |
671 | self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED) | |
672 | self.EnsureVisible(idx) | |
673 | ||
674 | def GetFocusedItem(self): | |
675 | '''get the currently focused item or -1 if none''' | |
676 | return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED) | |
677 | ||
678 | def IsSelected(self, idx): | |
679 | '''return TRUE if the item is selected''' | |
680 | return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0 | |
681 | ||
682 | def SetColumnImage(self, col, image): | |
683 | item = wxListItem() | |
684 | item.SetMask(wxLIST_MASK_IMAGE) | |
685 | item.SetImage(image) | |
686 | self.SetColumn(col, item) | |
687 | ||
688 | def ClearColumnImage(self, col): | |
689 | self.SetColumnImage(col, -1) | |
690 | " | |
7bf85405 RD |
691 | }; |
692 | ||
c7e7022c RD |
693 | |
694 | ||
6d19860f | 695 | %{ // Python aware sorting function for wxPyListCtrl |
f6bcfd97 | 696 | int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) { |
dcd38683 RD |
697 | int retval = 0; |
698 | PyObject* func = (PyObject*)funcPtr; | |
19a97bd6 | 699 | wxPyTState* state = wxPyBeginBlockThreads(); |
7bf85405 | 700 | |
dcd38683 RD |
701 | PyObject* args = Py_BuildValue("(ii)", item1, item2); |
702 | PyObject* result = PyEval_CallObject(func, args); | |
703 | Py_DECREF(args); | |
704 | if (result) { | |
705 | retval = PyInt_AsLong(result); | |
706 | Py_DECREF(result); | |
707 | } | |
708 | ||
19a97bd6 | 709 | wxPyEndBlockThreads(state); |
dcd38683 RD |
710 | return retval; |
711 | } | |
712 | ||
713 | %} | |
7bf85405 | 714 | |
6d19860f RD |
715 | //---------------------------------------------------------------------- |
716 | ||
717 | class wxListView : public wxPyListCtrl | |
718 | { | |
719 | public: | |
720 | wxListView( wxWindow *parent, | |
721 | wxWindowID id = -1, | |
722 | const wxPoint& pos = wxDefaultPosition, | |
723 | const wxSize& size = wxDefaultSize, | |
724 | long style = wxLC_REPORT, | |
725 | const wxValidator& validator = wxDefaultValidator, | |
726 | const wxString &name = "listctrl" ); | |
727 | %name(wxPreListView)wxListView(); | |
728 | ||
729 | bool Create( wxWindow *parent, | |
730 | wxWindowID id = -1, | |
731 | const wxPoint& pos = wxDefaultPosition, | |
732 | const wxSize& size = wxDefaultSize, | |
733 | long style = wxLC_REPORT, | |
734 | const wxValidator& validator = wxDefaultValidator, | |
735 | const wxString &name = "listctrl" ); | |
736 | ||
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, | |
768 | ||
769 | wxTR_SINGLE, | |
770 | wxTR_MULTIPLE, | |
771 | wxTR_EXTENDED, | |
772 | ||
773 | wxTR_EDIT_LABELS, | |
774 | wxTR_LINES_AT_ROOT, | |
775 | wxTR_HIDE_ROOT, | |
776 | wxTR_ROW_LINES, | |
777 | wxTR_HAS_VARIABLE_ROW_HEIGHT, | |
778 | ||
779 | wxTR_DEFAULT_STYLE, | |
780 | }; | |
781 | ||
694759cf RD |
782 | enum wxTreeItemIcon |
783 | { | |
784 | wxTreeItemIcon_Normal, // not selected, not expanded | |
785 | wxTreeItemIcon_Selected, // selected, not expanded | |
786 | wxTreeItemIcon_Expanded, // not selected, expanded | |
787 | wxTreeItemIcon_SelectedExpanded, // selected, expanded | |
788 | wxTreeItemIcon_Max | |
789 | }; | |
790 | ||
7bf85405 | 791 | |
164b735b RD |
792 | // constants for HitTest |
793 | enum { | |
794 | wxTREE_HITTEST_ABOVE, | |
795 | wxTREE_HITTEST_BELOW, | |
796 | wxTREE_HITTEST_NOWHERE, | |
797 | wxTREE_HITTEST_ONITEMBUTTON, | |
798 | wxTREE_HITTEST_ONITEMICON, | |
799 | wxTREE_HITTEST_ONITEMINDENT, | |
800 | wxTREE_HITTEST_ONITEMLABEL, | |
801 | wxTREE_HITTEST_ONITEMRIGHT, | |
802 | wxTREE_HITTEST_ONITEMSTATEICON, | |
803 | wxTREE_HITTEST_TOLEFT, | |
804 | wxTREE_HITTEST_TORIGHT, | |
805 | wxTREE_HITTEST_ONITEMUPPERPART, | |
806 | wxTREE_HITTEST_ONITEMLOWERPART, | |
807 | wxTREE_HITTEST_ONITEM | |
808 | }; | |
809 | ||
810 | ||
1b62f00d RD |
811 | enum { |
812 | /* Tree control event types */ | |
813 | wxEVT_COMMAND_TREE_BEGIN_DRAG, | |
814 | wxEVT_COMMAND_TREE_BEGIN_RDRAG, | |
815 | wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, | |
816 | wxEVT_COMMAND_TREE_END_LABEL_EDIT, | |
817 | wxEVT_COMMAND_TREE_DELETE_ITEM, | |
818 | wxEVT_COMMAND_TREE_GET_INFO, | |
819 | wxEVT_COMMAND_TREE_SET_INFO, | |
820 | wxEVT_COMMAND_TREE_ITEM_EXPANDED, | |
821 | wxEVT_COMMAND_TREE_ITEM_EXPANDING, | |
822 | wxEVT_COMMAND_TREE_ITEM_COLLAPSED, | |
823 | wxEVT_COMMAND_TREE_ITEM_COLLAPSING, | |
824 | wxEVT_COMMAND_TREE_SEL_CHANGED, | |
825 | wxEVT_COMMAND_TREE_SEL_CHANGING, | |
826 | wxEVT_COMMAND_TREE_KEY_DOWN, | |
827 | wxEVT_COMMAND_TREE_ITEM_ACTIVATED, | |
828 | wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, | |
829 | wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, | |
d1679124 | 830 | wxEVT_COMMAND_TREE_END_DRAG, |
1b62f00d RD |
831 | }; |
832 | ||
833 | ||
00b6c4e3 RD |
834 | %pragma(python) code = " |
835 | # wxTreeCtrl events | |
836 | def EVT_TREE_BEGIN_DRAG(win, id, func): | |
837 | win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func) | |
838 | ||
839 | def EVT_TREE_BEGIN_RDRAG(win, id, func): | |
840 | win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func) | |
841 | ||
842 | def EVT_TREE_END_DRAG(win, id, func): | |
843 | win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func) | |
844 | ||
845 | def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func): | |
846 | win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func) | |
847 | ||
848 | def EVT_TREE_END_LABEL_EDIT(win, id, func): | |
849 | win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func) | |
850 | ||
851 | def EVT_TREE_GET_INFO(win, id, func): | |
852 | win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func) | |
853 | ||
854 | def EVT_TREE_SET_INFO(win, id, func): | |
855 | win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func) | |
856 | ||
857 | def EVT_TREE_ITEM_EXPANDED(win, id, func): | |
858 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func) | |
859 | ||
860 | def EVT_TREE_ITEM_EXPANDING(win, id, func): | |
861 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func) | |
862 | ||
863 | def EVT_TREE_ITEM_COLLAPSED(win, id, func): | |
864 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func) | |
865 | ||
866 | def EVT_TREE_ITEM_COLLAPSING(win, id, func): | |
867 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func) | |
868 | ||
869 | def EVT_TREE_SEL_CHANGED(win, id, func): | |
870 | win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func) | |
871 | ||
872 | def EVT_TREE_SEL_CHANGING(win, id, func): | |
873 | win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func) | |
874 | ||
875 | def EVT_TREE_KEY_DOWN(win, id, func): | |
876 | win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func) | |
877 | ||
878 | def EVT_TREE_DELETE_ITEM(win, id, func): | |
879 | win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func) | |
880 | ||
881 | def EVT_TREE_ITEM_ACTIVATED(win, id, func): | |
882 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func) | |
883 | ||
884 | def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func): | |
885 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func) | |
886 | ||
887 | def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func): | |
888 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func) | |
889 | " | |
890 | ||
891 | ||
892 | class wxTreeItemAttr | |
893 | { | |
894 | public: | |
895 | // ctors | |
896 | //wxTreeItemAttr() { } | |
897 | wxTreeItemAttr(const wxColour& colText = wxNullColour, | |
898 | const wxColour& colBack = wxNullColour, | |
899 | const wxFont& font = wxNullFont); | |
900 | ||
901 | // setters | |
902 | void SetTextColour(const wxColour& colText); | |
903 | void SetBackgroundColour(const wxColour& colBack); | |
904 | void SetFont(const wxFont& font); | |
905 | ||
906 | // accessors | |
907 | bool HasTextColour(); | |
908 | bool HasBackgroundColour(); | |
909 | bool HasFont(); | |
910 | ||
911 | const wxColour& GetTextColour(); | |
912 | const wxColour& GetBackgroundColour(); | |
913 | const wxFont& GetFont(); | |
914 | }; | |
915 | ||
916 | ||
d5c9047a RD |
917 | class wxTreeItemId { |
918 | public: | |
919 | wxTreeItemId(); | |
920 | ~wxTreeItemId(); | |
bb0054cd | 921 | bool IsOk(); |
d5c9047a | 922 | |
f6bcfd97 BP |
923 | %addmethods { |
924 | int __cmp__(wxTreeItemId* other) { | |
c368d904 | 925 | if (! other) return -1; |
f6bcfd97 BP |
926 | return *self != *other; |
927 | } | |
928 | } | |
d5c9047a RD |
929 | }; |
930 | ||
931 | ||
932 | ||
cf694132 RD |
933 | %{ |
934 | class wxPyTreeItemData : public wxTreeItemData { | |
d5c9047a | 935 | public: |
cf694132 | 936 | wxPyTreeItemData(PyObject* obj = NULL) { |
c368d904 | 937 | if (obj == NULL) |
cf694132 | 938 | obj = Py_None; |
c368d904 RD |
939 | Py_INCREF(obj); |
940 | m_obj = obj; | |
cf694132 | 941 | } |
d5c9047a | 942 | |
cf694132 | 943 | ~wxPyTreeItemData() { |
19a97bd6 | 944 | wxPyTState* state = wxPyBeginBlockThreads(); |
c368d904 | 945 | Py_DECREF(m_obj); |
19a97bd6 | 946 | wxPyEndBlockThreads(state); |
cf694132 RD |
947 | } |
948 | ||
949 | PyObject* GetData() { | |
950 | Py_INCREF(m_obj); | |
951 | return m_obj; | |
952 | } | |
953 | ||
954 | void SetData(PyObject* obj) { | |
19a97bd6 | 955 | wxPyTState* state = wxPyBeginBlockThreads(); |
cf694132 | 956 | Py_DECREF(m_obj); |
19a97bd6 | 957 | wxPyEndBlockThreads(state); |
cf694132 RD |
958 | m_obj = obj; |
959 | Py_INCREF(obj); | |
960 | } | |
961 | ||
962 | PyObject* m_obj; | |
d5c9047a | 963 | }; |
cf694132 | 964 | %} |
d5c9047a RD |
965 | |
966 | ||
967 | ||
9416aa89 | 968 | %name(wxTreeItemData) class wxPyTreeItemData : public wxObject { |
cf694132 RD |
969 | public: |
970 | wxPyTreeItemData(PyObject* obj = NULL); | |
971 | ||
972 | PyObject* GetData(); | |
973 | void SetData(PyObject* obj); | |
974 | ||
975 | const wxTreeItemId& GetId(); | |
976 | void SetId(const wxTreeItemId& id); | |
977 | }; | |
978 | ||
979 | ||
d5c9047a | 980 | |
8bf5d46e | 981 | class wxTreeEvent : public wxNotifyEvent { |
d5c9047a | 982 | public: |
00b6c4e3 RD |
983 | wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0); |
984 | ||
d5c9047a RD |
985 | wxTreeItemId GetItem(); |
986 | wxTreeItemId GetOldItem(); | |
987 | wxPoint GetPoint(); | |
988 | int GetCode(); | |
8bf5d46e | 989 | const wxString& GetLabel(); |
d5c9047a RD |
990 | }; |
991 | ||
992 | ||
f6bcfd97 | 993 | |
09f3d4e6 | 994 | %{ // C++ version of Python aware wxTreeCtrl |
f6bcfd97 | 995 | class wxPyTreeCtrl : public wxTreeCtrl { |
3b36695d | 996 | DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl); |
f6bcfd97 | 997 | public: |
09f3d4e6 | 998 | wxPyTreeCtrl() : wxTreeCtrl() {} |
f6bcfd97 BP |
999 | wxPyTreeCtrl(wxWindow *parent, wxWindowID id, |
1000 | const wxPoint& pos, | |
1001 | const wxSize& size, | |
1002 | long style, | |
1003 | const wxValidator& validator, | |
1004 | char* name) : | |
1005 | wxTreeCtrl(parent, id, pos, size, style, validator, name) {} | |
1006 | ||
09f3d4e6 RD |
1007 | bool Create(wxWindow *parent, wxWindowID id, |
1008 | const wxPoint& pos, | |
1009 | const wxSize& size, | |
1010 | long style, | |
1011 | const wxValidator& validator, | |
1012 | char* name) { | |
1013 | return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name); | |
1014 | } | |
1015 | ||
1016 | ||
f6bcfd97 BP |
1017 | int OnCompareItems(const wxTreeItemId& item1, |
1018 | const wxTreeItemId& item2) { | |
1019 | int rval = 0; | |
19a97bd6 RD |
1020 | bool found; |
1021 | wxPyTState* state = wxPyBeginBlockThreads(); | |
1022 | if ((found = m_myInst.findCallback("OnCompareItems"))) | |
f6bcfd97 BP |
1023 | rval = m_myInst.callCallback(Py_BuildValue( |
1024 | "(OO)", | |
1025 | wxPyConstructObject((void*)&item1, "wxTreeItemId"), | |
1026 | wxPyConstructObject((void*)&item2, "wxTreeItemId"))); | |
19a97bd6 RD |
1027 | wxPyEndBlockThreads(state); |
1028 | if (! found) | |
f6bcfd97 | 1029 | rval = wxTreeCtrl::OnCompareItems(item1, item2); |
f6bcfd97 BP |
1030 | return rval; |
1031 | } | |
1032 | PYPRIVATE; | |
1033 | }; | |
1034 | ||
3b36695d RD |
1035 | IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl); |
1036 | ||
f6bcfd97 BP |
1037 | %} |
1038 | ||
d5c9047a RD |
1039 | // These are for the GetFirstChild/GetNextChild methods below |
1040 | %typemap(python, in) long& INOUT = long* INOUT; | |
1041 | %typemap(python, argout) long& INOUT = long* INOUT; | |
1042 | ||
1043 | ||
f6bcfd97 | 1044 | %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl { |
d5c9047a | 1045 | public: |
f6bcfd97 | 1046 | wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1, |
b68dc582 RD |
1047 | const wxPoint& pos = wxDefaultPosition, |
1048 | const wxSize& size = wxDefaultSize, | |
d5c9047a | 1049 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, |
b68dc582 | 1050 | const wxValidator& validator = wxDefaultValidator, |
d5c9047a | 1051 | char* name = "wxTreeCtrl"); |
09f3d4e6 RD |
1052 | %name(wxPreTreeCtrl)wxPyTreeCtrl(); |
1053 | ||
1054 | bool Create(wxWindow *parent, wxWindowID id = -1, | |
1055 | const wxPoint& pos = wxDefaultPosition, | |
1056 | const wxSize& size = wxDefaultSize, | |
1057 | long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, | |
1058 | const wxValidator& validator = wxDefaultValidator, | |
1059 | char* name = "wxTreeCtrl"); | |
d5c9047a | 1060 | |
f6bcfd97 | 1061 | void _setSelf(PyObject* self, PyObject* _class); |
f6bcfd97 | 1062 | %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTreeCtrl)" |
d5c9047a RD |
1063 | |
1064 | size_t GetCount(); | |
1065 | unsigned int GetIndent(); | |
1066 | void SetIndent(unsigned int indent); | |
1067 | wxImageList *GetImageList(); | |
1068 | wxImageList *GetStateImageList(); | |
1b62f00d | 1069 | void SetImageList(wxImageList *imageList); |
d5c9047a | 1070 | void SetStateImageList(wxImageList *imageList); |
00b6c4e3 RD |
1071 | void AssignImageList(wxImageList* imageList); |
1072 | %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0" | |
1073 | void AssignStateImageList(wxImageList* imageList); | |
1074 | %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0" | |
d5c9047a | 1075 | |
b1462dfa RD |
1076 | unsigned int GetSpacing(); |
1077 | void SetSpacing(unsigned int spacing); | |
1078 | ||
d5c9047a | 1079 | wxString GetItemText(const wxTreeItemId& item); |
694759cf RD |
1080 | int GetItemImage(const wxTreeItemId& item, |
1081 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
d5c9047a | 1082 | int GetItemSelectedImage(const wxTreeItemId& item); |
d5c9047a RD |
1083 | |
1084 | void SetItemText(const wxTreeItemId& item, const wxString& text); | |
694759cf RD |
1085 | void SetItemImage(const wxTreeItemId& item, int image, |
1086 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
d5c9047a | 1087 | void SetItemSelectedImage(const wxTreeItemId& item, int image); |
08127323 | 1088 | void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE); |
d5c9047a | 1089 | |
cf694132 | 1090 | %addmethods { |
c368d904 RD |
1091 | // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData |
1092 | // if needed. | |
cf694132 RD |
1093 | wxPyTreeItemData* GetItemData(const wxTreeItemId& item) { |
1094 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
1095 | if (data == NULL) { | |
1096 | data = new wxPyTreeItemData(); | |
f6bcfd97 | 1097 | data->SetId(item); // set the id |
cf694132 RD |
1098 | self->SetItemData(item, data); |
1099 | } | |
1100 | return data; | |
1101 | } | |
1102 | ||
1103 | void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { | |
f6bcfd97 BP |
1104 | data->SetId(item); // set the id |
1105 | self->SetItemData(item, data); | |
c368d904 | 1106 | } |
cf694132 | 1107 | |
c368d904 RD |
1108 | // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by |
1109 | // automatically creating data classes. | |
1110 | PyObject* GetPyData(const wxTreeItemId& item) { | |
cf694132 RD |
1111 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); |
1112 | if (data == NULL) { | |
1113 | data = new wxPyTreeItemData(); | |
f6bcfd97 | 1114 | data->SetId(item); // set the id |
cf694132 RD |
1115 | self->SetItemData(item, data); |
1116 | } | |
1117 | return data->GetData(); | |
c368d904 | 1118 | } |
cf694132 RD |
1119 | |
1120 | void SetPyData(const wxTreeItemId& item, PyObject* obj) { | |
1121 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
1122 | if (data == NULL) { | |
1123 | data = new wxPyTreeItemData(obj); | |
f6bcfd97 | 1124 | data->SetId(item); // set the id |
cf694132 RD |
1125 | self->SetItemData(item, data); |
1126 | } else | |
1127 | data->SetData(obj); | |
c368d904 | 1128 | } |
cf694132 RD |
1129 | } |
1130 | ||
1131 | ||
d5c9047a RD |
1132 | bool IsVisible(const wxTreeItemId& item); |
1133 | bool ItemHasChildren(const wxTreeItemId& item); | |
1134 | bool IsExpanded(const wxTreeItemId& item); | |
1135 | bool IsSelected(const wxTreeItemId& item); | |
1136 | ||
1137 | wxTreeItemId GetRootItem(); | |
1138 | wxTreeItemId GetSelection(); | |
eb715945 | 1139 | %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item); |
d426c97e RD |
1140 | //size_t GetSelections(wxArrayTreeItemIds& selection); |
1141 | %addmethods { | |
1142 | PyObject* GetSelections() { | |
19a97bd6 | 1143 | wxPyTState* state = wxPyBeginBlockThreads(); |
d426c97e RD |
1144 | PyObject* rval = PyList_New(0); |
1145 | wxArrayTreeItemIds array; | |
1146 | size_t num, x; | |
1147 | num = self->GetSelections(array); | |
1148 | for (x=0; x < num; x++) { | |
c368d904 RD |
1149 | wxTreeItemId *tii = new wxTreeItemId(array.Item(x)); |
1150 | PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE); | |
d426c97e RD |
1151 | PyList_Append(rval, item); |
1152 | } | |
19a97bd6 | 1153 | wxPyEndBlockThreads(state); |
d426c97e RD |
1154 | return rval; |
1155 | } | |
1156 | } | |
1157 | ||
1158 | ||
d5c9047a | 1159 | |
bb0054cd RD |
1160 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); |
1161 | ||
d5c9047a RD |
1162 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT); |
1163 | wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT); | |
1164 | wxTreeItemId GetNextSibling(const wxTreeItemId& item); | |
1165 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item); | |
1166 | wxTreeItemId GetFirstVisibleItem(); | |
1167 | wxTreeItemId GetNextVisible(const wxTreeItemId& item); | |
1168 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item); | |
d426c97e RD |
1169 | wxTreeItemId GetLastChild(const wxTreeItemId& item); |
1170 | ||
d5c9047a RD |
1171 | |
1172 | ||
1173 | wxTreeItemId AddRoot(const wxString& text, | |
1174 | int image = -1, int selectedImage = -1, | |
cf694132 | 1175 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
1176 | wxTreeItemId PrependItem(const wxTreeItemId& parent, |
1177 | const wxString& text, | |
1178 | int image = -1, int selectedImage = -1, | |
cf694132 | 1179 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
1180 | wxTreeItemId InsertItem(const wxTreeItemId& parent, |
1181 | const wxTreeItemId& idPrevious, | |
1182 | const wxString& text, | |
1183 | int image = -1, int selectedImage = -1, | |
cf694132 | 1184 | wxPyTreeItemData *data = NULL); |
f6bcfd97 BP |
1185 | %name(InsertItemBefore) |
1186 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
1187 | size_t before, | |
1188 | const wxString& text, | |
1189 | int image = -1, int selectedImage = -1, | |
1190 | wxTreeItemData *data = NULL); | |
d5c9047a RD |
1191 | wxTreeItemId AppendItem(const wxTreeItemId& parent, |
1192 | const wxString& text, | |
1193 | int image = -1, int selectedImage = -1, | |
cf694132 | 1194 | wxPyTreeItemData *data = NULL); |
d5c9047a RD |
1195 | |
1196 | void Delete(const wxTreeItemId& item); | |
08127323 | 1197 | void DeleteChildren(const wxTreeItemId& item); |
d5c9047a RD |
1198 | void DeleteAllItems(); |
1199 | ||
1200 | void Expand(const wxTreeItemId& item); | |
1201 | void Collapse(const wxTreeItemId& item); | |
1202 | void CollapseAndReset(const wxTreeItemId& item); | |
1203 | void Toggle(const wxTreeItemId& item); | |
1204 | ||
1205 | void Unselect(); | |
8bf5d46e | 1206 | void UnselectAll(); |
d5c9047a RD |
1207 | void SelectItem(const wxTreeItemId& item); |
1208 | void EnsureVisible(const wxTreeItemId& item); | |
1209 | void ScrollTo(const wxTreeItemId& item); | |
8bf5d46e | 1210 | #ifdef __WXMSW__ |
d5c9047a | 1211 | wxTextCtrl* EditLabel(const wxTreeItemId& item); |
d5c9047a | 1212 | wxTextCtrl* GetEditControl(); |
b1462dfa | 1213 | void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE); |
8bf5d46e RD |
1214 | #else |
1215 | void EditLabel(const wxTreeItemId& item); | |
1216 | #endif | |
d5c9047a | 1217 | |
d426c97e | 1218 | void SortChildren(const wxTreeItemId& item); |
d5c9047a | 1219 | |
b1462dfa | 1220 | void SetItemBold(const wxTreeItemId& item, int bold = TRUE); |
b8b8dda7 | 1221 | bool IsBold(const wxTreeItemId& item) const; |
164b735b | 1222 | wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT); |
c127177f | 1223 | |
f6bcfd97 BP |
1224 | |
1225 | ||
b7e72427 RD |
1226 | void SetItemTextColour(const wxTreeItemId& item, const wxColour& col); |
1227 | void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col); | |
1228 | void SetItemFont(const wxTreeItemId& item, const wxFont& font); | |
1229 | ||
4120ef2b | 1230 | #ifdef __WXMSW__ |
b1462dfa RD |
1231 | void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE); |
1232 | ||
d426c97e RD |
1233 | //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE) |
1234 | %addmethods { | |
1235 | PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) { | |
1236 | wxRect rect; | |
164b735b | 1237 | if (self->GetBoundingRect(item, rect, textOnly)) { |
19a97bd6 | 1238 | wxPyTState* state = wxPyBeginBlockThreads(); |
164b735b RD |
1239 | wxRect* r = new wxRect(rect); |
1240 | PyObject* val = wxPyConstructObject((void*)r, "wxRect"); | |
19a97bd6 | 1241 | wxPyEndBlockThreads(state); |
164b735b RD |
1242 | return val; |
1243 | } | |
d426c97e RD |
1244 | else { |
1245 | Py_INCREF(Py_None); | |
1246 | return Py_None; | |
1247 | } | |
1248 | } | |
1249 | } | |
761a9d2b | 1250 | #endif |
d426c97e | 1251 | |
c127177f | 1252 | %pragma(python) addtoclass = " |
f6bcfd97 BP |
1253 | # Redefine some methods that SWIG gets a bit confused on... |
1254 | def GetFirstChild(self, *_args, **_kwargs): | |
1255 | val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs) | |
1256 | val1 = wxTreeItemIdPtr(val1) | |
1257 | val1.thisown = 1 | |
1258 | return (val1,val2) | |
1259 | def GetNextChild(self, *_args, **_kwargs): | |
1260 | val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs) | |
c127177f RD |
1261 | val1 = wxTreeItemIdPtr(val1) |
1262 | val1.thisown = 1 | |
1263 | return (val1,val2) | |
f6bcfd97 BP |
1264 | def HitTest(self, *_args, **_kwargs): |
1265 | val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs) | |
c127177f RD |
1266 | val1 = wxTreeItemIdPtr(val1) |
1267 | val1.thisown = 1 | |
1268 | return (val1,val2) | |
1269 | " | |
d5c9047a RD |
1270 | }; |
1271 | ||
d5c9047a | 1272 | |
7bf85405 RD |
1273 | //---------------------------------------------------------------------- |
1274 | ||
9416aa89 | 1275 | %init %{ |
a3fbed81 | 1276 | // Map renamed classes back to their common name for OOR |
9416aa89 RD |
1277 | wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData"); |
1278 | wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl"); | |
a3fbed81 | 1279 | wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl"); |
9416aa89 RD |
1280 | %} |
1281 | ||
1282 | //---------------------------------------------------------------------- | |
1283 | ||
7bf85405 | 1284 |