1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: More control (widget) classes for wxPython
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
20 #include <wx/listctrl.h>
21 #include <wx/treectrl.h>
22 #include <wx/imaglist.h>
25 //----------------------------------------------------------------------
28 %include my_typemaps.i
30 // Import some definitions of other classes, etc.
38 %pragma(python) code = "import wx"
41 //----------------------------------------------------------------------
42 //----------------------------------------------------------------------
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 wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
64 wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
65 wxEVT_COMMAND_LIST_COL_DRAGGING,
66 wxEVT_COMMAND_LIST_COL_END_DRAG,
71 %pragma(python) code = "
72 def EVT_LIST_BEGIN_DRAG(win, id, func):
73 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func)
75 def EVT_LIST_BEGIN_RDRAG(win, id, func):
76 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func)
78 def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func):
79 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func)
81 def EVT_LIST_END_LABEL_EDIT(win, id, func):
82 win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func)
84 def EVT_LIST_DELETE_ITEM(win, id, func):
85 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func)
87 def EVT_LIST_DELETE_ALL_ITEMS(win, id, func):
88 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func)
90 def EVT_LIST_GET_INFO(win, id, func):
91 win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func)
93 def EVT_LIST_SET_INFO(win, id, func):
94 win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func)
96 def EVT_LIST_ITEM_SELECTED(win, id, func):
97 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func)
99 def EVT_LIST_ITEM_DESELECTED(win, id, func):
100 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func)
102 def EVT_LIST_KEY_DOWN(win, id, func):
103 win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func)
105 def EVT_LIST_INSERT_ITEM(win, id, func):
106 win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func)
108 def EVT_LIST_COL_CLICK(win, id, func):
109 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
111 def EVT_LIST_COL_RIGHT_CLICK(win, id, func):
112 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, func)
114 def EVT_LIST_COL_BEGIN_DRAG(win, id, func):
115 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, func)
117 def EVT_LIST_COL_DRAGGING(win, id, func):
118 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_DRAGGING, func)
120 def EVT_LIST_COL_END_DRAG(win, id, func):
121 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_END_DRAG, func)
123 def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
124 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
126 def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
127 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
129 def EVT_LIST_ITEM_ACTIVATED(win, id, func):
130 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func)
132 def EVT_LIST_CACHE_HINT(win, id, func):
133 win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func)
156 wxLC_SORT_DESCENDING,
177 wxLIST_STATE_DONTCARE,
178 wxLIST_STATE_DROPHILITED,
179 wxLIST_STATE_FOCUSED,
180 wxLIST_STATE_SELECTED,
184 wxLIST_HITTEST_ABOVE,
185 wxLIST_HITTEST_BELOW,
186 wxLIST_HITTEST_NOWHERE,
187 wxLIST_HITTEST_ONITEMICON,
188 wxLIST_HITTEST_ONITEMLABEL,
189 wxLIST_HITTEST_ONITEMRIGHT,
190 wxLIST_HITTEST_ONITEMSTATEICON,
191 wxLIST_HITTEST_TOLEFT,
192 wxLIST_HITTEST_TORIGHT,
193 wxLIST_HITTEST_ONITEM,
195 // Flags for GetNextItem
203 wxLIST_ALIGN_DEFAULT,
206 wxLIST_ALIGN_SNAP_TO_GRID,
208 // Autosize values for SetColumnWidth
209 wxLIST_AUTOSIZE = -1,
210 wxLIST_AUTOSIZE_USEHEADER = -2,
212 // Flag values for GetItemRect
217 // Flag values for FindItem (MSW only)
228 enum wxListColumnFormat
232 wxLIST_FORMAT_CENTRE,
233 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
244 wxListItemAttr(const wxColour& colText = wxNullColour,
245 const wxColour& colBack = wxNullColour,
246 const wxFont& font = wxNullFont);
250 void SetTextColour(const wxColour& colText);
251 void SetBackgroundColour(const wxColour& colBack);
252 void SetFont(const wxFont& font);
255 bool HasTextColour();
256 bool HasBackgroundColour();
259 const wxColour& GetTextColour();
260 const wxColour& GetBackgroundColour();
261 const wxFont& GetFont();
265 class wxListItem : public wxObject {
272 void ClearAttributes();
275 void SetMask(long mask);
277 void SetColumn(int col);
278 void SetState(long state);
279 void SetStateMask(long stateMask);
280 void SetText(const wxString& text);
281 void SetImage(int image);
282 void SetData(long data);
284 void SetWidth(int width);
285 void SetAlign(wxListColumnFormat align);
287 void SetTextColour(const wxColour& colText);
288 void SetBackgroundColour(const wxColour& colBack);
289 void SetFont(const wxFont& font);
296 const wxString& GetText();
301 wxListColumnFormat GetAlign();
303 wxListItemAttr *GetAttributes();
304 bool HasAttributes();
306 wxColour GetTextColour() const;
307 wxColour GetBackgroundColour() const;
308 wxFont GetFont() const;
310 // these members are public for compatibility
311 long m_mask; // Indicates what fields are valid
312 long m_itemId; // The zero-based item position
313 int m_col; // Zero-based column, if in report mode
314 long m_state; // The state of the item
315 long m_stateMask;// Which flags of m_state are valid (uses same flags)
316 wxString m_text; // The label/header text
317 int m_image; // The zero-based index into an image list
318 long m_data; // App-defined data
321 int m_format; // left, right, centre
322 int m_width; // width of column
327 class wxListEvent: public wxNotifyEvent {
329 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
346 const wxString& GetLabel();
347 const wxString& GetText();
351 const wxListItem& GetItem();
358 %{ // C++ Version of a Python aware class
359 class wxPyListCtrl : public wxListCtrl {
360 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
362 wxPyListCtrl() : wxListCtrl() {}
363 wxPyListCtrl(wxWindow* parent, wxWindowID id,
367 const wxValidator& validator,
369 wxListCtrl(parent, id, pos, size, style, validator, name) {}
371 bool Create(wxWindow* parent, wxWindowID id,
375 const wxValidator& validator,
377 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
380 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
381 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
382 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
387 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
389 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
390 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
391 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
396 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
398 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
399 const wxPoint& pos = wxDefaultPosition,
400 const wxSize& size = wxDefaultSize,
401 long style = wxLC_ICON,
402 const wxValidator& validator = wxDefaultValidator,
403 char* name = "listCtrl");
404 %name(wxPreListCtrl)wxPyListCtrl();
406 bool Create(wxWindow* parent, wxWindowID id = -1,
407 const wxPoint& pos = wxDefaultPosition,
408 const wxSize& size = wxDefaultSize,
409 long style = wxLC_ICON,
410 const wxValidator& validator = wxDefaultValidator,
411 char* name = "listCtrl");
413 void _setSelf(PyObject* self, PyObject* _class);
414 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxListCtrl)"
417 // Set the control colours
418 bool SetForegroundColour(const wxColour& col);
419 bool SetBackgroundColour(const wxColour& col);
421 // Gets information about this column
422 bool GetColumn(int col, wxListItem& item) const;
424 // Sets information about this column
425 bool SetColumn(int col, wxListItem& item) ;
427 // Gets the column width
428 int GetColumnWidth(int col) const;
430 // Sets the column width
431 bool SetColumnWidth(int col, int width) ;
433 // Gets the number of items that can fit vertically in the
434 // visible area of the list control (list or report view)
435 // or the total number of items in the list control (icon
436 // or small icon view)
437 int GetCountPerPage() const;
440 // Gets the edit control for editing labels.
441 wxTextCtrl* GetEditControl() const;
444 //bool GetItem(wxListItem& info) const ;
446 // Gets information about the item
447 %new wxListItem* GetItem(long itemId, int col=0) {
448 wxListItem* info = new wxListItem;
449 info->m_itemId = itemId;
451 info->m_mask = 0xFFFF;
452 self->GetItem(*info);
455 } // The OOR typemaps don't know what to do with the %new, so fix it up.
456 %pragma(python) addtoclass = "
457 def GetItem(self, *_args, **_kwargs):
458 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
464 // Sets information about the item
465 bool SetItem(wxListItem& info) ;
467 // Sets a string field at a particular column
468 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
470 // Gets the item state
471 int GetItemState(long item, long stateMask) const ;
473 // Sets the item state
474 bool SetItemState(long item, long state, long stateMask) ;
476 // Sets the item image
477 bool SetItemImage(long item, int image, int selImage) ;
479 // Gets the item text
480 wxString GetItemText(long item) const ;
482 // Sets the item text
483 void SetItemText(long item, const wxString& str) ;
485 // Gets the item data
486 long GetItemData(long item) const ;
488 // Sets the item data
489 bool SetItemData(long item, long data) ;
492 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
493 //bool GetItemPosition(long item, wxPoint& pos) const ;
495 // Gets the item position
497 %new wxPoint* GetItemPosition(long item) {
498 wxPoint* pos = new wxPoint;
499 self->GetItemPosition(item, *pos);
502 // Gets the item rectangle
503 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
504 wxRect* rect= new wxRect;
505 self->GetItemRect(item, *rect, code);
511 // Sets the item position
512 bool SetItemPosition(long item, const wxPoint& pos) ;
514 // Gets the number of items in the list control
515 int GetItemCount() const;
517 // Gets the number of columns in the list control
518 int GetColumnCount() const { return m_colCount; }
520 // Retrieves the spacing between icons in pixels.
521 // If small is TRUE, gets the spacing for the small icon
522 // view, otherwise the large icon view.
523 int GetItemSpacing(bool isSmall) const;
525 // Gets the number of selected items in the list control
526 int GetSelectedItemCount() const;
528 // Gets the text colour of the listview
529 wxColour GetTextColour() const;
531 // Sets the text colour of the listview
532 void SetTextColour(const wxColour& col);
534 // Gets the index of the topmost visible item when in
535 // list or report view
536 long GetTopItem() const ;
538 // Add or remove a single window style
539 void SetSingleStyle(long style, bool add = TRUE) ;
541 // Set the whole window style
542 void SetWindowStyleFlag(long style) ;
544 // Searches for an item, starting from 'item'.
545 // item can be -1 to find the first item that matches the
547 // Returns the item or -1 if unsuccessful.
548 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
550 // Gets one of the three image lists
551 wxImageList *GetImageList(int which) const ;
553 // Sets the image list
554 void SetImageList(wxImageList *imageList, int which) ;
555 void AssignImageList(wxImageList *imageList, int which) ;
556 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
558 // returns true if it is a virtual list control
559 bool IsVirtual() const;
561 // refresh items selectively (only useful for virtual list controls)
562 void RefreshItem(long item);
563 void RefreshItems(long itemFrom, long itemTo);
568 // Arranges the items
569 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
572 bool DeleteItem(long item);
575 bool DeleteAllItems() ;
578 bool DeleteColumn(int col);
580 // Deletes all columns
581 bool DeleteAllColumns();
583 // Clears items, and columns if there are any.
588 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
590 // End label editing, optionally cancelling the edit
591 bool EndEditLabel(bool cancel);
594 // Ensures this item is visible
595 bool EnsureVisible(long item) ;
597 // Find an item whose label matches this string, starting from the item after 'start'
598 // or the beginning if 'start' is -1.
599 long FindItem(long start, const wxString& str, bool partial = FALSE);
601 // Find an item whose data matches this data, starting from the item after 'start'
602 // or the beginning if 'start' is -1.
603 %name(FindItemData)long FindItem(long start, long data);
605 // Find an item nearest this position in the specified direction, starting from
606 // the item after 'start' or the beginning if 'start' is -1.
607 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
609 // Determines which item (if any) is at the specified point,
610 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
611 long HitTest(const wxPoint& point, int& OUTPUT);
613 // Inserts an item, returning the index of the new item if successful,
615 long InsertItem(wxListItem& info);
617 // Insert a string item
618 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
620 // Insert an image item
621 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
623 // Insert an image/string item
624 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
626 // For list view mode (only), inserts a column.
627 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
629 long InsertColumn(long col,
630 const wxString& heading,
631 int format = wxLIST_FORMAT_LEFT,
634 // set the number of items in a virtual list control
635 void SetItemCount(long count);
637 // Scrolls the list control. If in icon, small icon or report view mode,
638 // x specifies the number of pixels to scroll. If in list view mode, x
639 // specifies the number of columns to scroll.
640 // If in icon, small icon or list view mode, y specifies the number of pixels
641 // to scroll. If in report view mode, y specifies the number of lines to scroll.
642 bool ScrollList(int dx, int dy);
644 // bool SortItems(wxListCtrlCompare fn, long data);
647 // func is a function which takes 2 long arguments: item1, item2.
648 // item1 is the long data associated with a first item (NOT the index).
649 // item2 is the long data associated with a second item (NOT the index).
650 // The return value is a negative number if the first item should precede the second
651 // item, a positive number of the second item should precede the first,
652 // or zero if the two items are equivalent.
653 bool SortItems(PyObject* func) {
654 if (!PyCallable_Check(func))
656 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
660 %pragma(python) addtoclass = "
663 def Select(self, idx, on=1):
664 '''[de]select an item'''
665 if on: state = wxLIST_STATE_SELECTED
667 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
669 def Focus(self, idx):
670 '''Focus and show the given item'''
671 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
672 self.EnsureVisible(idx)
674 def GetFocusedItem(self):
675 '''get the currently focused item or -1 if none'''
676 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
678 def IsSelected(self, idx):
679 '''return TRUE if the item is selected'''
680 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
682 def SetColumnImage(self, col, image):
684 item.SetMask(wxLIST_MASK_IMAGE)
686 self.SetColumn(col, item)
688 def ClearColumnImage(self, col):
689 self.SetColumnImage(col, -1)
695 %{ // Python aware sorting function for wxPyListCtrl
696 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
698 PyObject* func = (PyObject*)funcPtr;
699 wxPyTState* state = wxPyBeginBlockThreads();
701 PyObject* args = Py_BuildValue("(ii)", item1, item2);
702 PyObject* result = PyEval_CallObject(func, args);
705 retval = PyInt_AsLong(result);
709 wxPyEndBlockThreads(state);
715 //----------------------------------------------------------------------
717 class wxListView : public wxPyListCtrl
720 wxListView( wxWindow *parent,
722 const wxPoint& pos = wxDefaultPosition,
723 const wxSize& size = wxDefaultSize,
724 long style = wxLC_REPORT,
725 const wxValidator& validator = wxDefaultValidator,
726 const wxString &name = "listctrl" );
727 %name(wxPreListView)wxListView();
729 bool Create( wxWindow *parent,
731 const wxPoint& pos = wxDefaultPosition,
732 const wxSize& size = wxDefaultSize,
733 long style = wxLC_REPORT,
734 const wxValidator& validator = wxDefaultValidator,
735 const wxString &name = "listctrl" );
738 // [de]select an item
739 void Select(long n, bool on = TRUE);
741 // focus and show the given item
742 void Focus(long index);
744 // get the currently focused item or -1 if none
745 long GetFocusedItem() const;
747 // get first and subsequent selected items, return -1 when no more
748 long GetNextSelected(long item) const;
749 long GetFirstSelected() const;
751 // return TRUE if the item is selected
752 bool IsSelected(long index);
754 void SetColumnImage(int col, int image);
755 void ClearColumnImage(int col);
759 //----------------------------------------------------------------------
777 wxTR_HAS_VARIABLE_ROW_HEIGHT,
784 wxTreeItemIcon_Normal, // not selected, not expanded
785 wxTreeItemIcon_Selected, // selected, not expanded
786 wxTreeItemIcon_Expanded, // not selected, expanded
787 wxTreeItemIcon_SelectedExpanded, // selected, expanded
792 // constants for HitTest
794 wxTREE_HITTEST_ABOVE,
795 wxTREE_HITTEST_BELOW,
796 wxTREE_HITTEST_NOWHERE,
797 wxTREE_HITTEST_ONITEMBUTTON,
798 wxTREE_HITTEST_ONITEMICON,
799 wxTREE_HITTEST_ONITEMINDENT,
800 wxTREE_HITTEST_ONITEMLABEL,
801 wxTREE_HITTEST_ONITEMRIGHT,
802 wxTREE_HITTEST_ONITEMSTATEICON,
803 wxTREE_HITTEST_TOLEFT,
804 wxTREE_HITTEST_TORIGHT,
805 wxTREE_HITTEST_ONITEMUPPERPART,
806 wxTREE_HITTEST_ONITEMLOWERPART,
807 wxTREE_HITTEST_ONITEM
812 /* Tree control event types */
813 wxEVT_COMMAND_TREE_BEGIN_DRAG,
814 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
815 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
816 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
817 wxEVT_COMMAND_TREE_DELETE_ITEM,
818 wxEVT_COMMAND_TREE_GET_INFO,
819 wxEVT_COMMAND_TREE_SET_INFO,
820 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
821 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
822 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
823 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
824 wxEVT_COMMAND_TREE_SEL_CHANGED,
825 wxEVT_COMMAND_TREE_SEL_CHANGING,
826 wxEVT_COMMAND_TREE_KEY_DOWN,
827 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
828 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
829 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
830 wxEVT_COMMAND_TREE_END_DRAG,
834 %pragma(python) code = "
836 def EVT_TREE_BEGIN_DRAG(win, id, func):
837 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
839 def EVT_TREE_BEGIN_RDRAG(win, id, func):
840 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
842 def EVT_TREE_END_DRAG(win, id, func):
843 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
845 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
846 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
848 def EVT_TREE_END_LABEL_EDIT(win, id, func):
849 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
851 def EVT_TREE_GET_INFO(win, id, func):
852 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
854 def EVT_TREE_SET_INFO(win, id, func):
855 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
857 def EVT_TREE_ITEM_EXPANDED(win, id, func):
858 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
860 def EVT_TREE_ITEM_EXPANDING(win, id, func):
861 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
863 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
864 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
866 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
867 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
869 def EVT_TREE_SEL_CHANGED(win, id, func):
870 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
872 def EVT_TREE_SEL_CHANGING(win, id, func):
873 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
875 def EVT_TREE_KEY_DOWN(win, id, func):
876 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
878 def EVT_TREE_DELETE_ITEM(win, id, func):
879 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
881 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
882 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
884 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
885 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
887 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
888 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
896 //wxTreeItemAttr() { }
897 wxTreeItemAttr(const wxColour& colText = wxNullColour,
898 const wxColour& colBack = wxNullColour,
899 const wxFont& font = wxNullFont);
902 void SetTextColour(const wxColour& colText);
903 void SetBackgroundColour(const wxColour& colBack);
904 void SetFont(const wxFont& font);
907 bool HasTextColour();
908 bool HasBackgroundColour();
911 const wxColour& GetTextColour();
912 const wxColour& GetBackgroundColour();
913 const wxFont& GetFont();
924 int __cmp__(wxTreeItemId* other) {
925 if (! other) return -1;
926 return *self != *other;
934 class wxPyTreeItemData : public wxTreeItemData {
936 wxPyTreeItemData(PyObject* obj = NULL) {
943 ~wxPyTreeItemData() {
944 wxPyTState* state = wxPyBeginBlockThreads();
946 wxPyEndBlockThreads(state);
949 PyObject* GetData() {
954 void SetData(PyObject* obj) {
955 wxPyTState* state = wxPyBeginBlockThreads();
957 wxPyEndBlockThreads(state);
968 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
970 wxPyTreeItemData(PyObject* obj = NULL);
973 void SetData(PyObject* obj);
975 const wxTreeItemId& GetId();
976 void SetId(const wxTreeItemId& id);
981 class wxTreeEvent : public wxNotifyEvent {
983 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
985 wxTreeItemId GetItem();
986 wxTreeItemId GetOldItem();
988 const wxKeyEvent& GetKeyEvent();
990 const wxString& GetLabel();
995 %{ // C++ version of Python aware wxTreeCtrl
996 class wxPyTreeCtrl : public wxTreeCtrl {
997 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
999 wxPyTreeCtrl() : wxTreeCtrl() {}
1000 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1004 const wxValidator& validator,
1006 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1008 bool Create(wxWindow *parent, wxWindowID id,
1012 const wxValidator& validator,
1014 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1018 int OnCompareItems(const wxTreeItemId& item1,
1019 const wxTreeItemId& item2) {
1022 wxPyTState* state = wxPyBeginBlockThreads();
1023 if ((found = m_myInst.findCallback("OnCompareItems")))
1024 rval = m_myInst.callCallback(Py_BuildValue(
1026 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
1027 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
1028 wxPyEndBlockThreads(state);
1030 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1036 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1040 // These are for the GetFirstChild/GetNextChild methods below
1041 %typemap(python, in) long& INOUT = long* INOUT;
1042 %typemap(python, argout) long& INOUT = long* INOUT;
1045 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1047 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1048 const wxPoint& pos = wxDefaultPosition,
1049 const wxSize& size = wxDefaultSize,
1050 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1051 const wxValidator& validator = wxDefaultValidator,
1052 char* name = "wxTreeCtrl");
1053 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1055 bool Create(wxWindow *parent, wxWindowID id = -1,
1056 const wxPoint& pos = wxDefaultPosition,
1057 const wxSize& size = wxDefaultSize,
1058 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1059 const wxValidator& validator = wxDefaultValidator,
1060 char* name = "wxTreeCtrl");
1062 void _setSelf(PyObject* self, PyObject* _class);
1063 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTreeCtrl)"
1066 unsigned int GetIndent();
1067 void SetIndent(unsigned int indent);
1068 wxImageList *GetImageList();
1069 wxImageList *GetStateImageList();
1070 void SetImageList(wxImageList *imageList);
1071 void SetStateImageList(wxImageList *imageList);
1072 void AssignImageList(wxImageList* imageList);
1073 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1074 void AssignStateImageList(wxImageList* imageList);
1075 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1077 unsigned int GetSpacing();
1078 void SetSpacing(unsigned int spacing);
1080 wxString GetItemText(const wxTreeItemId& item);
1081 int GetItemImage(const wxTreeItemId& item,
1082 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1083 int GetItemSelectedImage(const wxTreeItemId& item);
1085 void SetItemText(const wxTreeItemId& item, const wxString& text);
1086 void SetItemImage(const wxTreeItemId& item, int image,
1087 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1088 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1089 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1092 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1094 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1095 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1097 data = new wxPyTreeItemData();
1098 data->SetId(item); // set the id
1099 self->SetItemData(item, data);
1104 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1105 data->SetId(item); // set the id
1106 self->SetItemData(item, data);
1109 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1110 // automatically creating data classes.
1111 PyObject* GetPyData(const wxTreeItemId& item) {
1112 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1114 data = new wxPyTreeItemData();
1115 data->SetId(item); // set the id
1116 self->SetItemData(item, data);
1118 return data->GetData();
1121 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1122 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1124 data = new wxPyTreeItemData(obj);
1125 data->SetId(item); // set the id
1126 self->SetItemData(item, data);
1133 bool IsVisible(const wxTreeItemId& item);
1134 bool ItemHasChildren(const wxTreeItemId& item);
1135 bool IsExpanded(const wxTreeItemId& item);
1136 bool IsSelected(const wxTreeItemId& item);
1138 wxTreeItemId GetRootItem();
1139 wxTreeItemId GetSelection();
1140 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1141 //size_t GetSelections(wxArrayTreeItemIds& selection);
1143 PyObject* GetSelections() {
1144 wxPyTState* state = wxPyBeginBlockThreads();
1145 PyObject* rval = PyList_New(0);
1146 wxArrayTreeItemIds array;
1148 num = self->GetSelections(array);
1149 for (x=0; x < num; x++) {
1150 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1151 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1152 PyList_Append(rval, item);
1154 wxPyEndBlockThreads(state);
1161 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1163 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
1164 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1165 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1166 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1167 wxTreeItemId GetFirstVisibleItem();
1168 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1169 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1170 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1174 wxTreeItemId AddRoot(const wxString& text,
1175 int image = -1, int selectedImage = -1,
1176 wxPyTreeItemData *data = NULL);
1177 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1178 const wxString& text,
1179 int image = -1, int selectedImage = -1,
1180 wxPyTreeItemData *data = NULL);
1181 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1182 const wxTreeItemId& idPrevious,
1183 const wxString& text,
1184 int image = -1, int selectedImage = -1,
1185 wxPyTreeItemData *data = NULL);
1186 %name(InsertItemBefore)
1187 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1189 const wxString& text,
1190 int image = -1, int selectedImage = -1,
1191 wxTreeItemData *data = NULL);
1192 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1193 const wxString& text,
1194 int image = -1, int selectedImage = -1,
1195 wxPyTreeItemData *data = NULL);
1197 void Delete(const wxTreeItemId& item);
1198 void DeleteChildren(const wxTreeItemId& item);
1199 void DeleteAllItems();
1201 void Expand(const wxTreeItemId& item);
1202 void Collapse(const wxTreeItemId& item);
1203 void CollapseAndReset(const wxTreeItemId& item);
1204 void Toggle(const wxTreeItemId& item);
1208 void SelectItem(const wxTreeItemId& item);
1209 void EnsureVisible(const wxTreeItemId& item);
1210 void ScrollTo(const wxTreeItemId& item);
1212 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1213 wxTextCtrl* GetEditControl();
1214 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1216 void EditLabel(const wxTreeItemId& item);
1219 void SortChildren(const wxTreeItemId& item);
1221 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1222 bool IsBold(const wxTreeItemId& item) const;
1223 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1227 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1228 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1229 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1232 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1234 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1236 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1238 if (self->GetBoundingRect(item, rect, textOnly)) {
1239 wxPyTState* state = wxPyBeginBlockThreads();
1240 wxRect* r = new wxRect(rect);
1241 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1242 wxPyEndBlockThreads(state);
1253 %pragma(python) addtoclass = "
1254 # Redefine some methods that SWIG gets a bit confused on...
1255 def GetFirstChild(self, *_args, **_kwargs):
1256 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1257 val1 = wxTreeItemIdPtr(val1)
1260 def GetNextChild(self, *_args, **_kwargs):
1261 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1262 val1 = wxTreeItemIdPtr(val1)
1265 def HitTest(self, *_args, **_kwargs):
1266 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1267 val1 = wxTreeItemIdPtr(val1)
1274 //----------------------------------------------------------------------
1277 // Map renamed classes back to their common name for OOR
1278 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1279 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1280 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1283 //----------------------------------------------------------------------