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