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,
67 wxEVT_COMMAND_LIST_ITEM_FOCUSED,
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)
135 def EVT_LIST_ITEM_FOCUSED(win, id, func):
136 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_FOCUSED, func)
159 wxLC_SORT_DESCENDING,
180 wxLIST_STATE_DONTCARE,
181 wxLIST_STATE_DROPHILITED,
182 wxLIST_STATE_FOCUSED,
183 wxLIST_STATE_SELECTED,
187 wxLIST_HITTEST_ABOVE,
188 wxLIST_HITTEST_BELOW,
189 wxLIST_HITTEST_NOWHERE,
190 wxLIST_HITTEST_ONITEMICON,
191 wxLIST_HITTEST_ONITEMLABEL,
192 wxLIST_HITTEST_ONITEMRIGHT,
193 wxLIST_HITTEST_ONITEMSTATEICON,
194 wxLIST_HITTEST_TOLEFT,
195 wxLIST_HITTEST_TORIGHT,
196 wxLIST_HITTEST_ONITEM,
198 // Flags for GetNextItem
206 wxLIST_ALIGN_DEFAULT,
209 wxLIST_ALIGN_SNAP_TO_GRID,
211 // Autosize values for SetColumnWidth
212 wxLIST_AUTOSIZE = -1,
213 wxLIST_AUTOSIZE_USEHEADER = -2,
215 // Flag values for GetItemRect
220 // Flag values for FindItem (MSW only)
231 enum wxListColumnFormat
235 wxLIST_FORMAT_CENTRE,
236 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
247 wxListItemAttr(const wxColour& colText = wxNullColour,
248 const wxColour& colBack = wxNullColour,
249 const wxFont& font = wxNullFont);
253 void SetTextColour(const wxColour& colText);
254 void SetBackgroundColour(const wxColour& colBack);
255 void SetFont(const wxFont& font);
258 bool HasTextColour();
259 bool HasBackgroundColour();
262 wxColour GetTextColour();
263 wxColour GetBackgroundColour();
268 class wxListItem : public wxObject {
275 void ClearAttributes();
278 void SetMask(long mask);
280 void SetColumn(int col);
281 void SetState(long state);
282 void SetStateMask(long stateMask);
283 void SetText(const wxString& text);
284 void SetImage(int image);
285 void SetData(long data);
287 void SetWidth(int width);
288 void SetAlign(wxListColumnFormat align);
290 void SetTextColour(const wxColour& colText);
291 void SetBackgroundColour(const wxColour& colBack);
292 void SetFont(const wxFont& font);
299 const wxString& GetText();
304 wxListColumnFormat GetAlign();
306 wxListItemAttr *GetAttributes();
307 bool HasAttributes();
309 wxColour GetTextColour() const;
310 wxColour GetBackgroundColour() const;
311 wxFont GetFont() const;
313 // these members are public for compatibility
314 long m_mask; // Indicates what fields are valid
315 long m_itemId; // The zero-based item position
316 int m_col; // Zero-based column, if in report mode
317 long m_state; // The state of the item
318 long m_stateMask;// Which flags of m_state are valid (uses same flags)
319 wxString m_text; // The label/header text
320 int m_image; // The zero-based index into an image list
321 long m_data; // App-defined data
324 int m_format; // left, right, centre
325 int m_width; // width of column
330 class wxListEvent: public wxNotifyEvent {
332 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
345 const wxString& GetLabel();
346 const wxString& GetText();
350 const wxListItem& GetItem();
357 %{ // C++ Version of a Python aware class
358 class wxPyListCtrl : public wxListCtrl {
359 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
361 wxPyListCtrl() : wxListCtrl() {}
362 wxPyListCtrl(wxWindow* parent, wxWindowID id,
366 const wxValidator& validator,
368 wxListCtrl(parent, id, pos, size, style, validator, name) {}
370 bool Create(wxWindow* parent, wxWindowID id,
374 const wxValidator& validator,
376 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
379 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
380 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
381 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
386 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
388 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
389 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
390 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
395 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
397 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
398 const wxPoint& pos = wxDefaultPosition,
399 const wxSize& size = wxDefaultSize,
400 long style = wxLC_ICON,
401 const wxValidator& validator = wxDefaultValidator,
402 char* name = "listCtrl");
403 %name(wxPreListCtrl)wxPyListCtrl();
405 bool Create(wxWindow* parent, wxWindowID id = -1,
406 const wxPoint& pos = wxDefaultPosition,
407 const wxSize& size = wxDefaultSize,
408 long style = wxLC_ICON,
409 const wxValidator& validator = wxDefaultValidator,
410 char* name = "listCtrl");
412 void _setCallbackInfo(PyObject* self, PyObject* _class);
413 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxListCtrl)"
415 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
416 %pragma(python) addtomethod = "wxPreListCtrl:val._setOORInfo(val)"
418 // Set the control colours
419 bool SetForegroundColour(const wxColour& col);
420 bool SetBackgroundColour(const wxColour& col);
422 // Gets information about this column
423 bool GetColumn(int col, wxListItem& item) const;
425 // Sets information about this column
426 bool SetColumn(int col, wxListItem& item) ;
428 // Gets the column width
429 int GetColumnWidth(int col) const;
431 // Sets the column width
432 bool SetColumnWidth(int col, int width) ;
434 // Gets the number of items that can fit vertically in the
435 // visible area of the list control (list or report view)
436 // or the total number of items in the list control (icon
437 // or small icon view)
438 int GetCountPerPage() const;
441 // Gets the edit control for editing labels.
442 wxTextCtrl* GetEditControl() const;
445 //bool GetItem(wxListItem& info) const ;
447 // Gets information about the item
448 %new wxListItem* GetItem(long itemId, int col=0) {
449 wxListItem* info = new wxListItem;
450 info->m_itemId = itemId;
452 info->m_mask = 0xFFFF;
453 self->GetItem(*info);
456 } // The OOR typemaps don't know what to do with the %new, so fix it up.
457 %pragma(python) addtoclass = "
458 def GetItem(self, *_args, **_kwargs):
459 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
465 // Sets information about the item
466 bool SetItem(wxListItem& info) ;
468 // Sets a string field at a particular column
469 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
471 // Gets the item state
472 int GetItemState(long item, long stateMask) const ;
474 // Sets the item state
475 bool SetItemState(long item, long state, long stateMask) ;
477 // Sets the item image
478 bool SetItemImage(long item, int image, int selImage) ;
480 // Gets the item text
481 wxString GetItemText(long item) const ;
483 // Sets the item text
484 void SetItemText(long item, const wxString& str) ;
486 // Gets the item data
487 long GetItemData(long item) const ;
489 // Sets the item data
490 bool SetItemData(long item, long data) ;
493 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
494 //bool GetItemPosition(long item, wxPoint& pos) const ;
496 // Gets the item position
498 %new wxPoint* GetItemPosition(long item) {
499 wxPoint* pos = new wxPoint;
500 self->GetItemPosition(item, *pos);
503 // Gets the item rectangle
504 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
505 wxRect* rect= new wxRect;
506 self->GetItemRect(item, *rect, code);
512 // Sets the item position
513 bool SetItemPosition(long item, const wxPoint& pos) ;
515 // Gets the number of items in the list control
516 int GetItemCount() const;
518 // Gets the number of columns in the list control
519 int GetColumnCount() const;
521 // Retrieves the spacing between icons in pixels.
522 // If small is TRUE, gets the spacing for the small icon
523 // view, otherwise the large icon view.
524 int GetItemSpacing(bool isSmall) const;
526 // Gets the number of selected items in the list control
527 int GetSelectedItemCount() const;
529 // Gets the text colour of the listview
530 wxColour GetTextColour() const;
532 // Sets the text colour of the listview
533 void SetTextColour(const wxColour& col);
535 // Gets the index of the topmost visible item when in
536 // list or report view
537 long GetTopItem() const ;
539 // Add or remove a single window style
540 void SetSingleStyle(long style, bool add = TRUE) ;
542 // Set the whole window style
543 void SetWindowStyleFlag(long style) ;
545 // Searches for an item, starting from 'item'.
546 // item can be -1 to find the first item that matches the
548 // Returns the item or -1 if unsuccessful.
549 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
551 // Gets one of the three image lists
552 wxImageList *GetImageList(int which) const ;
554 // Sets the image list
555 void SetImageList(wxImageList *imageList, int which) ;
556 void AssignImageList(wxImageList *imageList, int which) ;
557 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
559 // returns true if it is a virtual list control
560 bool IsVirtual() const;
562 // refresh items selectively (only useful for virtual list controls)
563 void RefreshItem(long item);
564 void RefreshItems(long itemFrom, long itemTo);
566 // Arranges the items
567 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
570 bool DeleteItem(long item);
573 bool DeleteAllItems() ;
576 bool DeleteColumn(int col);
578 // Deletes all columns
579 bool DeleteAllColumns();
581 // Clears items, and columns if there are any.
586 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
588 // End label editing, optionally cancelling the edit
589 bool EndEditLabel(bool cancel);
592 // Ensures this item is visible
593 bool EnsureVisible(long item) ;
595 // Find an item whose label matches this string, starting from the item after 'start'
596 // or the beginning if 'start' is -1.
597 long FindItem(long start, const wxString& str, bool partial = FALSE);
599 // Find an item whose data matches this data, starting from the item after 'start'
600 // or the beginning if 'start' is -1.
601 %name(FindItemData)long FindItem(long start, long data);
603 // Find an item nearest this position in the specified direction, starting from
604 // the item after 'start' or the beginning if 'start' is -1.
605 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
607 // Determines which item (if any) is at the specified point,
608 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
609 long HitTest(const wxPoint& point, int& OUTPUT);
611 // Inserts an item, returning the index of the new item if successful,
613 long InsertItem(wxListItem& info);
615 // Insert a string item
616 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
618 // Insert an image item
619 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
621 // Insert an image/string item
622 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
624 // For list view mode (only), inserts a column.
625 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
627 long InsertColumn(long col,
628 const wxString& heading,
629 int format = wxLIST_FORMAT_LEFT,
632 // set the number of items in a virtual list control
633 void SetItemCount(long count);
635 // Scrolls the list control. If in icon, small icon or report view mode,
636 // x specifies the number of pixels to scroll. If in list view mode, x
637 // specifies the number of columns to scroll.
638 // If in icon, small icon or list view mode, y specifies the number of pixels
639 // to scroll. If in report view mode, y specifies the number of lines to scroll.
640 bool ScrollList(int dx, int dy);
642 // bool SortItems(wxListCtrlCompare fn, long data);
645 // func is a function which takes 2 long arguments: item1, item2.
646 // item1 is the long data associated with a first item (NOT the index).
647 // item2 is the long data associated with a second item (NOT the index).
648 // The return value is a negative number if the first item should precede the second
649 // item, a positive number of the second item should precede the first,
650 // or zero if the two items are equivalent.
651 bool SortItems(PyObject* func) {
652 if (!PyCallable_Check(func))
654 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
658 %pragma(python) addtoclass = "
661 def Select(self, idx, on=1):
662 '''[de]select an item'''
663 if on: state = wxLIST_STATE_SELECTED
665 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
667 def Focus(self, idx):
668 '''Focus and show the given item'''
669 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
670 self.EnsureVisible(idx)
672 def GetFocusedItem(self):
673 '''get the currently focused item or -1 if none'''
674 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
676 def IsSelected(self, idx):
677 '''return TRUE if the item is selected'''
678 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
680 def SetColumnImage(self, col, image):
682 item.SetMask(wxLIST_MASK_IMAGE)
684 self.SetColumn(col, item)
686 def ClearColumnImage(self, col):
687 self.SetColumnImage(col, -1)
693 %{ // Python aware sorting function for wxPyListCtrl
694 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
696 PyObject* func = (PyObject*)funcPtr;
697 wxPyBeginBlockThreads();
699 PyObject* args = Py_BuildValue("(ii)", item1, item2);
700 PyObject* result = PyEval_CallObject(func, args);
703 retval = PyInt_AsLong(result);
707 wxPyEndBlockThreads();
713 //----------------------------------------------------------------------
715 class wxListView : public wxPyListCtrl
718 wxListView( wxWindow *parent,
720 const wxPoint& pos = wxDefaultPosition,
721 const wxSize& size = wxDefaultSize,
722 long style = wxLC_REPORT,
723 const wxValidator& validator = wxDefaultValidator,
724 const wxString &name = "listctrl" );
725 %name(wxPreListView)wxListView();
727 bool Create( wxWindow *parent,
729 const wxPoint& pos = wxDefaultPosition,
730 const wxSize& size = wxDefaultSize,
731 long style = wxLC_REPORT,
732 const wxValidator& validator = wxDefaultValidator,
733 const wxString &name = "listctrl" );
735 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
736 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
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 wxColour GetTextColour();
912 wxColour GetBackgroundColour();
922 %pragma(python) addtoclass = "Ok = IsOk"
925 int __cmp__(wxTreeItemId* other) {
926 if (! other) return -1;
927 return *self != *other;
935 class wxPyTreeItemData : public wxTreeItemData {
937 wxPyTreeItemData(PyObject* obj = NULL) {
944 ~wxPyTreeItemData() {
945 wxPyBeginBlockThreads();
947 wxPyEndBlockThreads();
950 PyObject* GetData() {
955 void SetData(PyObject* obj) {
956 wxPyBeginBlockThreads();
958 wxPyEndBlockThreads();
969 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
971 wxPyTreeItemData(PyObject* obj = NULL);
974 void SetData(PyObject* obj);
976 const wxTreeItemId& GetId();
977 void SetId(const wxTreeItemId& id);
982 class wxTreeEvent : public wxNotifyEvent {
984 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
986 wxTreeItemId GetItem();
987 wxTreeItemId GetOldItem();
989 const wxKeyEvent& GetKeyEvent();
991 const wxString& GetLabel();
996 %{ // C++ version of Python aware wxTreeCtrl
997 class wxPyTreeCtrl : public wxTreeCtrl {
998 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
1000 wxPyTreeCtrl() : wxTreeCtrl() {}
1001 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1005 const wxValidator& validator,
1007 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1009 bool Create(wxWindow *parent, wxWindowID id,
1013 const wxValidator& validator,
1015 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1019 int OnCompareItems(const wxTreeItemId& item1,
1020 const wxTreeItemId& item2) {
1023 wxPyBeginBlockThreads();
1024 if ((found = m_myInst.findCallback("OnCompareItems")))
1025 rval = m_myInst.callCallback(Py_BuildValue(
1027 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
1028 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
1029 wxPyEndBlockThreads();
1031 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1037 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1041 // These are for the GetFirstChild/GetNextChild methods below
1042 %typemap(python, in) long& INOUT = long* INOUT;
1043 %typemap(python, argout) long& INOUT = long* INOUT;
1046 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1048 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1049 const wxPoint& pos = wxDefaultPosition,
1050 const wxSize& size = wxDefaultSize,
1051 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1052 const wxValidator& validator = wxDefaultValidator,
1053 char* name = "wxTreeCtrl");
1054 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1056 bool Create(wxWindow *parent, wxWindowID id = -1,
1057 const wxPoint& pos = wxDefaultPosition,
1058 const wxSize& size = wxDefaultSize,
1059 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1060 const wxValidator& validator = wxDefaultValidator,
1061 char* name = "wxTreeCtrl");
1063 void _setCallbackInfo(PyObject* self, PyObject* _class);
1064 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)"
1066 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1067 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
1070 unsigned int GetIndent();
1071 void SetIndent(unsigned int indent);
1072 wxImageList *GetImageList();
1073 wxImageList *GetStateImageList();
1074 void SetImageList(wxImageList *imageList);
1075 void SetStateImageList(wxImageList *imageList);
1076 void AssignImageList(wxImageList* imageList);
1077 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1078 void AssignStateImageList(wxImageList* imageList);
1079 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1081 unsigned int GetSpacing();
1082 void SetSpacing(unsigned int spacing);
1084 wxString GetItemText(const wxTreeItemId& item);
1085 int GetItemImage(const wxTreeItemId& item,
1086 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1087 int GetItemSelectedImage(const wxTreeItemId& item);
1089 void SetItemText(const wxTreeItemId& item, const wxString& text);
1090 void SetItemImage(const wxTreeItemId& item, int image,
1091 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1092 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1093 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1096 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1098 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1099 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1101 data = new wxPyTreeItemData();
1102 data->SetId(item); // set the id
1103 self->SetItemData(item, data);
1108 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1109 data->SetId(item); // set the id
1110 self->SetItemData(item, data);
1113 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1114 // automatically creating data classes.
1115 PyObject* GetPyData(const wxTreeItemId& item) {
1116 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1118 data = new wxPyTreeItemData();
1119 data->SetId(item); // set the id
1120 self->SetItemData(item, data);
1122 return data->GetData();
1125 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1126 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1128 data = new wxPyTreeItemData(obj);
1129 data->SetId(item); // set the id
1130 self->SetItemData(item, data);
1137 bool IsVisible(const wxTreeItemId& item);
1138 bool ItemHasChildren(const wxTreeItemId& item);
1139 bool IsExpanded(const wxTreeItemId& item);
1140 bool IsSelected(const wxTreeItemId& item);
1142 wxTreeItemId GetRootItem();
1143 wxTreeItemId GetSelection();
1144 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1145 //size_t GetSelections(wxArrayTreeItemIds& selection);
1147 PyObject* GetSelections() {
1148 wxPyBeginBlockThreads();
1149 PyObject* rval = PyList_New(0);
1150 wxArrayTreeItemIds array;
1152 num = self->GetSelections(array);
1153 for (x=0; x < num; x++) {
1154 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1155 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1156 PyList_Append(rval, item);
1158 wxPyEndBlockThreads();
1165 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1167 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
1168 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1169 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1170 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1171 wxTreeItemId GetFirstVisibleItem();
1172 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1173 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1174 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1178 wxTreeItemId AddRoot(const wxString& text,
1179 int image = -1, int selectedImage = -1,
1180 wxPyTreeItemData *data = NULL);
1181 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1182 const wxString& text,
1183 int image = -1, int selectedImage = -1,
1184 wxPyTreeItemData *data = NULL);
1185 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1186 const wxTreeItemId& idPrevious,
1187 const wxString& text,
1188 int image = -1, int selectedImage = -1,
1189 wxPyTreeItemData *data = NULL);
1190 %name(InsertItemBefore)
1191 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1193 const wxString& text,
1194 int image = -1, int selectedImage = -1,
1195 wxTreeItemData *data = NULL);
1196 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1197 const wxString& text,
1198 int image = -1, int selectedImage = -1,
1199 wxPyTreeItemData *data = NULL);
1201 void Delete(const wxTreeItemId& item);
1202 void DeleteChildren(const wxTreeItemId& item);
1203 void DeleteAllItems();
1205 void Expand(const wxTreeItemId& item);
1206 void Collapse(const wxTreeItemId& item);
1207 void CollapseAndReset(const wxTreeItemId& item);
1208 void Toggle(const wxTreeItemId& item);
1212 void SelectItem(const wxTreeItemId& item);
1213 void EnsureVisible(const wxTreeItemId& item);
1214 void ScrollTo(const wxTreeItemId& item);
1216 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1217 wxTextCtrl* GetEditControl();
1218 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1220 void EditLabel(const wxTreeItemId& item);
1223 void SortChildren(const wxTreeItemId& item);
1225 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1226 bool IsBold(const wxTreeItemId& item) const;
1227 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1231 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1232 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1233 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1236 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1239 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1241 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1243 if (self->GetBoundingRect(item, rect, textOnly)) {
1244 wxPyBeginBlockThreads();
1245 wxRect* r = new wxRect(rect);
1246 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1247 wxPyEndBlockThreads();
1258 %pragma(python) addtoclass = "
1259 # Redefine some methods that SWIG gets a bit confused on...
1260 def GetFirstChild(self, *_args, **_kwargs):
1261 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1262 val1 = wxTreeItemIdPtr(val1)
1265 def GetNextChild(self, *_args, **_kwargs):
1266 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1267 val1 = wxTreeItemIdPtr(val1)
1270 def HitTest(self, *_args, **_kwargs):
1271 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1272 val1 = wxTreeItemIdPtr(val1)
1280 //----------------------------------------------------------------------
1283 // Map renamed classes back to their common name for OOR
1284 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1285 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1286 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1289 //----------------------------------------------------------------------