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