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