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