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