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>
23 #include <wx/dirctrl.h>
26 //----------------------------------------------------------------------
29 %include my_typemaps.i
31 // Import some definitions of other classes, etc.
39 %pragma(python) code = "import wx"
42 //----------------------------------------------------------------------
44 // Put some wx default wxChar* values into wxStrings.
45 const wxChar* wxListCtrlNameStr = _T("wxListCtrl");
46 DECLARE_DEF_STRING(ListCtrlNameStr);
48 const wxChar* wx_TreeCtrlNameStr = _T("wxTreeCtrl");
49 DECLARE_DEF_STRING(_TreeCtrlNameStr);
50 DECLARE_DEF_STRING(DirDialogDefaultFolderStr);
52 static const wxString wxPyEmptyString(wxT(""));
57 static const long longzero = 0;
60 //----------------------------------------------------------------------
63 /* List control event types */
64 wxEVT_COMMAND_LIST_BEGIN_DRAG,
65 wxEVT_COMMAND_LIST_BEGIN_RDRAG,
66 wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT,
67 wxEVT_COMMAND_LIST_END_LABEL_EDIT,
68 wxEVT_COMMAND_LIST_DELETE_ITEM,
69 wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS,
70 wxEVT_COMMAND_LIST_GET_INFO,
71 wxEVT_COMMAND_LIST_SET_INFO,
72 wxEVT_COMMAND_LIST_ITEM_SELECTED,
73 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
74 wxEVT_COMMAND_LIST_KEY_DOWN,
75 wxEVT_COMMAND_LIST_INSERT_ITEM,
76 wxEVT_COMMAND_LIST_COL_CLICK,
77 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
78 wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK,
79 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
80 wxEVT_COMMAND_LIST_CACHE_HINT,
81 wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
82 wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
83 wxEVT_COMMAND_LIST_COL_DRAGGING,
84 wxEVT_COMMAND_LIST_COL_END_DRAG,
85 wxEVT_COMMAND_LIST_ITEM_FOCUSED,
89 %pragma(python) code = "
90 def EVT_LIST_BEGIN_DRAG(win, id, func):
91 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func)
93 def EVT_LIST_BEGIN_RDRAG(win, id, func):
94 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func)
96 def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func):
97 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func)
99 def EVT_LIST_END_LABEL_EDIT(win, id, func):
100 win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func)
102 def EVT_LIST_DELETE_ITEM(win, id, func):
103 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func)
105 def EVT_LIST_DELETE_ALL_ITEMS(win, id, func):
106 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func)
108 def EVT_LIST_GET_INFO(win, id, func):
109 win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func)
111 def EVT_LIST_SET_INFO(win, id, func):
112 win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func)
114 def EVT_LIST_ITEM_SELECTED(win, id, func):
115 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func)
117 def EVT_LIST_ITEM_DESELECTED(win, id, func):
118 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func)
120 def EVT_LIST_KEY_DOWN(win, id, func):
121 win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func)
123 def EVT_LIST_INSERT_ITEM(win, id, func):
124 win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func)
126 def EVT_LIST_COL_CLICK(win, id, func):
127 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
129 def EVT_LIST_COL_RIGHT_CLICK(win, id, func):
130 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, func)
132 def EVT_LIST_COL_BEGIN_DRAG(win, id, func):
133 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, func)
135 def EVT_LIST_COL_DRAGGING(win, id, func):
136 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_DRAGGING, func)
138 def EVT_LIST_COL_END_DRAG(win, id, func):
139 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_END_DRAG, func)
141 def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
142 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
144 def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
145 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
147 def EVT_LIST_ITEM_ACTIVATED(win, id, func):
148 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func)
150 def EVT_LIST_CACHE_HINT(win, id, func):
151 win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func)
153 def EVT_LIST_ITEM_FOCUSED(win, id, func):
154 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_FOCUSED, func)
177 wxLC_SORT_DESCENDING,
198 wxLIST_STATE_DONTCARE,
199 wxLIST_STATE_DROPHILITED,
200 wxLIST_STATE_FOCUSED,
201 wxLIST_STATE_SELECTED,
205 wxLIST_HITTEST_ABOVE,
206 wxLIST_HITTEST_BELOW,
207 wxLIST_HITTEST_NOWHERE,
208 wxLIST_HITTEST_ONITEMICON,
209 wxLIST_HITTEST_ONITEMLABEL,
210 wxLIST_HITTEST_ONITEMRIGHT,
211 wxLIST_HITTEST_ONITEMSTATEICON,
212 wxLIST_HITTEST_TOLEFT,
213 wxLIST_HITTEST_TORIGHT,
214 wxLIST_HITTEST_ONITEM,
216 // Flags for GetNextItem
224 wxLIST_ALIGN_DEFAULT,
227 wxLIST_ALIGN_SNAP_TO_GRID,
229 // Autosize values for SetColumnWidth
230 wxLIST_AUTOSIZE = -1,
231 wxLIST_AUTOSIZE_USEHEADER = -2,
233 // Flag values for GetItemRect
238 // Flag values for FindItem (MSW only)
249 enum wxListColumnFormat
253 wxLIST_FORMAT_CENTRE,
254 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
265 wxListItemAttr(const wxColour& colText = wxNullColour,
266 const wxColour& colBack = wxNullColour,
267 const wxFont& font = wxNullFont);
271 void SetTextColour(const wxColour& colText);
272 void SetBackgroundColour(const wxColour& colBack);
273 void SetFont(const wxFont& font);
276 bool HasTextColour();
277 bool HasBackgroundColour();
280 wxColour GetTextColour();
281 wxColour GetBackgroundColour();
286 class wxListItem : public wxObject {
293 void ClearAttributes();
296 void SetMask(long mask);
298 void SetColumn(int col);
299 void SetState(long state);
300 void SetStateMask(long stateMask);
301 void SetText(const wxString& text);
302 void SetImage(int image);
303 void SetData(long data);
305 void SetWidth(int width);
306 void SetAlign(wxListColumnFormat align);
308 void SetTextColour(const wxColour& colText);
309 void SetBackgroundColour(const wxColour& colBack);
310 void SetFont(const wxFont& font);
317 const wxString& GetText();
322 wxListColumnFormat GetAlign();
324 wxListItemAttr *GetAttributes();
325 bool HasAttributes();
327 wxColour GetTextColour() const;
328 wxColour GetBackgroundColour() const;
329 wxFont GetFont() const;
331 // these members are public for compatibility
332 long m_mask; // Indicates what fields are valid
333 long m_itemId; // The zero-based item position
334 int m_col; // Zero-based column, if in report mode
335 long m_state; // The state of the item
336 long m_stateMask;// Which flags of m_state are valid (uses same flags)
337 wxString m_text; // The label/header text
338 int m_image; // The zero-based index into an image list
339 long m_data; // App-defined data
342 int m_format; // left, right, centre
343 int m_width; // width of column
348 class wxListEvent: public wxNotifyEvent {
350 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
365 const wxString& GetLabel();
366 const wxString& GetText();
370 const wxListItem& GetItem();
377 %{ // C++ Version of a Python aware class
378 class wxPyListCtrl : public wxListCtrl {
379 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
381 wxPyListCtrl() : wxListCtrl() {}
382 wxPyListCtrl(wxWindow* parent, wxWindowID id,
386 const wxValidator& validator,
387 const wxString& name) :
388 wxListCtrl(parent, id, pos, size, style, validator, name) {}
390 bool Create(wxWindow* parent, wxWindowID id,
394 const wxValidator& validator,
395 const wxString& name) {
396 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
399 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
400 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
401 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
406 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
408 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
409 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
410 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
415 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
417 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
418 const wxPoint& pos = wxDefaultPosition,
419 const wxSize& size = wxDefaultSize,
420 long style = wxLC_ICON,
421 const wxValidator& validator = wxDefaultValidator,
422 const wxString& name = wxPyListCtrlNameStr);
423 %name(wxPreListCtrl)wxPyListCtrl();
425 bool Create(wxWindow* parent, wxWindowID id = -1,
426 const wxPoint& pos = wxDefaultPosition,
427 const wxSize& size = wxDefaultSize,
428 long style = wxLC_ICON,
429 const wxValidator& validator = wxDefaultValidator,
430 const wxString& name = wxPyListCtrlNameStr);
432 void _setCallbackInfo(PyObject* self, PyObject* _class);
433 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxListCtrl)"
435 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
436 %pragma(python) addtomethod = "wxPreListCtrl:val._setOORInfo(val)"
438 // Set the control colours
439 bool SetForegroundColour(const wxColour& col);
440 bool SetBackgroundColour(const wxColour& col);
442 // Gets information about this column
443 // bool GetColumn(int col, wxListItem& item) const;
445 %new wxListItem* GetColumn(int col) {
447 if (self->GetColumn(col, item))
448 return new wxListItem(item);
452 } // The OOR typemaps don't know what to do with the %new, so fix it up.
453 %pragma(python) addtoclass = "
454 def GetItem(self, *_args, **_kwargs):
455 val = apply(controls2c.wxListCtrl_GetColumn,(self,) + _args, _kwargs)
456 if val is not None: val.thisown = 1
460 // Sets information about this column
461 bool SetColumn(int col, wxListItem& item) ;
463 // Gets the column width
464 int GetColumnWidth(int col) const;
466 // Sets the column width
467 bool SetColumnWidth(int col, int width) ;
469 // Gets the number of items that can fit vertically in the
470 // visible area of the list control (list or report view)
471 // or the total number of items in the list control (icon
472 // or small icon view)
473 int GetCountPerPage() const;
476 // Gets the edit control for editing labels.
477 wxTextCtrl* GetEditControl() const;
480 //bool GetItem(wxListItem& info) const ;
482 // Gets information about the item
483 %new wxListItem* GetItem(long itemId, int col=0) {
484 wxListItem* info = new wxListItem;
485 info->m_itemId = itemId;
487 info->m_mask = 0xFFFF;
488 self->GetItem(*info);
491 } // The OOR typemaps don't know what to do with the %new, so fix it up.
492 %pragma(python) addtoclass = "
493 def GetItem(self, *_args, **_kwargs):
494 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
500 // Sets information about the item
501 bool SetItem(wxListItem& info) ;
503 // Sets a string field at a particular column
504 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
506 // Gets the item state
507 int GetItemState(long item, long stateMask) const ;
509 // Sets the item state
510 bool SetItemState(long item, long state, long stateMask) ;
512 // Sets the item image
513 bool SetItemImage(long item, int image, int selImage) ;
515 // Gets the item text
516 wxString GetItemText(long item) const ;
518 // Sets the item text
519 void SetItemText(long item, const wxString& str) ;
521 // Gets the item data
522 long GetItemData(long item) const ;
524 // Sets the item data
525 bool SetItemData(long item, long data) ;
528 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
529 //bool GetItemPosition(long item, wxPoint& pos) const ;
531 // Gets the item position
533 %new wxPoint* GetItemPosition(long item) {
534 wxPoint* pos = new wxPoint;
535 self->GetItemPosition(item, *pos);
538 // Gets the item rectangle
539 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
540 wxRect* rect= new wxRect;
541 self->GetItemRect(item, *rect, code);
547 // Sets the item position
548 bool SetItemPosition(long item, const wxPoint& pos) ;
550 // Gets the number of items in the list control
551 int GetItemCount() const;
553 // Gets the number of columns in the list control
554 int GetColumnCount() const;
556 // Retrieves the spacing between icons in pixels.
557 // If small is TRUE, gets the spacing for the small icon
558 // view, otherwise the large icon view.
559 int GetItemSpacing(bool isSmall) const;
561 // Gets the number of selected items in the list control
562 int GetSelectedItemCount() const;
564 // Gets the text colour of the listview
565 wxColour GetTextColour() const;
567 // Sets the text colour of the listview
568 void SetTextColour(const wxColour& col);
570 // Gets the index of the topmost visible item when in
571 // list or report view
572 long GetTopItem() const ;
574 // Add or remove a single window style
575 void SetSingleStyle(long style, bool add = TRUE) ;
577 // Set the whole window style
578 void SetWindowStyleFlag(long style) ;
580 // Searches for an item, starting from 'item'.
581 // item can be -1 to find the first item that matches the
583 // Returns the item or -1 if unsuccessful.
584 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
586 // Gets one of the three image lists
587 wxImageList *GetImageList(int which) const ;
589 // Sets the image list
590 void SetImageList(wxImageList *imageList, int which) ;
591 void AssignImageList(wxImageList *imageList, int which) ;
592 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
594 // returns true if it is a virtual list control
595 bool IsVirtual() const;
597 // refresh items selectively (only useful for virtual list controls)
598 void RefreshItem(long item);
599 void RefreshItems(long itemFrom, long itemTo);
601 // Arranges the items
602 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
605 bool DeleteItem(long item);
608 bool DeleteAllItems() ;
611 bool DeleteColumn(int col);
613 // Deletes all columns
614 bool DeleteAllColumns();
616 // Clears items, and columns if there are any.
621 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
623 // End label editing, optionally cancelling the edit
624 bool EndEditLabel(bool cancel);
627 // Ensures this item is visible
628 bool EnsureVisible(long item) ;
630 // Find an item whose label matches this string, starting from the item after 'start'
631 // or the beginning if 'start' is -1.
632 long FindItem(long start, const wxString& str, bool partial = FALSE);
634 // Find an item whose data matches this data, starting from the item after 'start'
635 // or the beginning if 'start' is -1.
636 %name(FindItemData)long FindItem(long start, long data);
638 // Find an item nearest this position in the specified direction, starting from
639 // the item after 'start' or the beginning if 'start' is -1.
640 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
642 // Determines which item (if any) is at the specified point,
643 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
644 long HitTest(const wxPoint& point, int& OUTPUT);
646 // Inserts an item, returning the index of the new item if successful,
648 long InsertItem(wxListItem& info);
650 // Insert a string item
651 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
653 // Insert an image item
654 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
656 // Insert an image/string item
657 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
659 // For list view mode (only), inserts a column.
660 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
662 long InsertColumn(long col,
663 const wxString& heading,
664 int format = wxLIST_FORMAT_LEFT,
667 // set the number of items in a virtual list control
668 void SetItemCount(long count);
670 // Scrolls the list control. If in icon, small icon or report view mode,
671 // x specifies the number of pixels to scroll. If in list view mode, x
672 // specifies the number of columns to scroll.
673 // If in icon, small icon or list view mode, y specifies the number of pixels
674 // to scroll. If in report view mode, y specifies the number of lines to scroll.
675 bool ScrollList(int dx, int dy);
677 void SetItemTextColour( long item, const wxColour& col);
678 wxColour GetItemTextColour( long item ) const;
679 void SetItemBackgroundColour( long item, const wxColour &col);
680 wxColour GetItemBackgroundColour( long item ) const;
683 %pragma(python) addtoclass = "
686 def Select(self, idx, on=1):
687 '''[de]select an item'''
688 if on: state = wxLIST_STATE_SELECTED
690 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
692 def Focus(self, idx):
693 '''Focus and show the given item'''
694 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
695 self.EnsureVisible(idx)
697 def GetFocusedItem(self):
698 '''get the currently focused item or -1 if none'''
699 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
701 def IsSelected(self, idx):
702 '''return TRUE if the item is selected'''
703 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
705 def SetColumnImage(self, col, image):
707 item.SetMask(wxLIST_MASK_IMAGE)
709 self.SetColumn(col, item)
711 def ClearColumnImage(self, col):
712 self.SetColumnImage(col, -1)
714 def Append(self, entry):
715 '''Append an item to the list control. The entry parameter should be a
716 sequence with an item for each column'''
718 pos = self.GetItemCount()
719 self.InsertStringItem(pos, str(entry[0]))
720 for i in range(1, len(entry)):
721 self.SetStringItem(pos, i, str(entry[i]))
726 // bool SortItems(wxListCtrlCompare fn, long data);
729 // func is a function which takes 2 long arguments: item1, item2.
730 // item1 is the long data associated with a first item (NOT the index).
731 // item2 is the long data associated with a second item (NOT the index).
732 // The return value is a negative number if the first item should precede the second
733 // item, a positive number of the second item should precede the first,
734 // or zero if the two items are equivalent.
735 bool SortItems(PyObject* func) {
736 if (!PyCallable_Check(func))
738 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
745 %{ // Python aware sorting function for wxPyListCtrl
746 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
748 PyObject* func = (PyObject*)funcPtr;
749 wxPyBeginBlockThreads();
751 PyObject* args = Py_BuildValue("(ii)", item1, item2);
752 PyObject* result = PyEval_CallObject(func, args);
755 retval = PyInt_AsLong(result);
759 wxPyEndBlockThreads();
765 //----------------------------------------------------------------------
767 class wxListView : public wxPyListCtrl
770 wxListView( wxWindow *parent,
772 const wxPoint& pos = wxDefaultPosition,
773 const wxSize& size = wxDefaultSize,
774 long style = wxLC_REPORT,
775 const wxValidator& validator = wxDefaultValidator,
776 const wxString& name = wxPyListCtrlNameStr);
777 %name(wxPreListView)wxListView();
779 bool Create( wxWindow *parent,
781 const wxPoint& pos = wxDefaultPosition,
782 const wxSize& size = wxDefaultSize,
783 long style = wxLC_REPORT,
784 const wxValidator& validator = wxDefaultValidator,
785 const wxString& name = wxPyListCtrlNameStr);
787 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
788 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
790 // [de]select an item
791 void Select(long n, bool on = TRUE);
793 // focus and show the given item
794 void Focus(long index);
796 // get the currently focused item or -1 if none
797 long GetFocusedItem() const;
799 // get first and subsequent selected items, return -1 when no more
800 long GetNextSelected(long item) const;
801 long GetFirstSelected() const;
803 // return TRUE if the item is selected
804 bool IsSelected(long index);
806 void SetColumnImage(int col, int image);
807 void ClearColumnImage(int col);
811 //----------------------------------------------------------------------
825 wxTR_FULL_ROW_HIGHLIGHT,
831 wxTR_HAS_VARIABLE_ROW_HEIGHT,
838 wxTreeItemIcon_Normal, // not selected, not expanded
839 wxTreeItemIcon_Selected, // selected, not expanded
840 wxTreeItemIcon_Expanded, // not selected, expanded
841 wxTreeItemIcon_SelectedExpanded, // selected, expanded
846 // constants for HitTest
848 wxTREE_HITTEST_ABOVE,
849 wxTREE_HITTEST_BELOW,
850 wxTREE_HITTEST_NOWHERE,
851 wxTREE_HITTEST_ONITEMBUTTON,
852 wxTREE_HITTEST_ONITEMICON,
853 wxTREE_HITTEST_ONITEMINDENT,
854 wxTREE_HITTEST_ONITEMLABEL,
855 wxTREE_HITTEST_ONITEMRIGHT,
856 wxTREE_HITTEST_ONITEMSTATEICON,
857 wxTREE_HITTEST_TOLEFT,
858 wxTREE_HITTEST_TORIGHT,
859 wxTREE_HITTEST_ONITEMUPPERPART,
860 wxTREE_HITTEST_ONITEMLOWERPART,
861 wxTREE_HITTEST_ONITEM
866 /* Tree control event types */
867 wxEVT_COMMAND_TREE_BEGIN_DRAG,
868 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
869 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
870 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
871 wxEVT_COMMAND_TREE_DELETE_ITEM,
872 wxEVT_COMMAND_TREE_GET_INFO,
873 wxEVT_COMMAND_TREE_SET_INFO,
874 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
875 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
876 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
877 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
878 wxEVT_COMMAND_TREE_SEL_CHANGED,
879 wxEVT_COMMAND_TREE_SEL_CHANGING,
880 wxEVT_COMMAND_TREE_KEY_DOWN,
881 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
882 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
883 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
884 wxEVT_COMMAND_TREE_END_DRAG,
888 %pragma(python) code = "
890 def EVT_TREE_BEGIN_DRAG(win, id, func):
891 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
893 def EVT_TREE_BEGIN_RDRAG(win, id, func):
894 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
896 def EVT_TREE_END_DRAG(win, id, func):
897 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
899 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
900 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
902 def EVT_TREE_END_LABEL_EDIT(win, id, func):
903 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
905 def EVT_TREE_GET_INFO(win, id, func):
906 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
908 def EVT_TREE_SET_INFO(win, id, func):
909 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
911 def EVT_TREE_ITEM_EXPANDED(win, id, func):
912 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
914 def EVT_TREE_ITEM_EXPANDING(win, id, func):
915 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
917 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
918 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
920 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
921 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
923 def EVT_TREE_SEL_CHANGED(win, id, func):
924 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
926 def EVT_TREE_SEL_CHANGING(win, id, func):
927 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
929 def EVT_TREE_KEY_DOWN(win, id, func):
930 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
932 def EVT_TREE_DELETE_ITEM(win, id, func):
933 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
935 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
936 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
938 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
939 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
941 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
942 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
950 //wxTreeItemAttr() { }
951 wxTreeItemAttr(const wxColour& colText = wxNullColour,
952 const wxColour& colBack = wxNullColour,
953 const wxFont& font = wxNullFont);
956 void SetTextColour(const wxColour& colText);
957 void SetBackgroundColour(const wxColour& colBack);
958 void SetFont(const wxFont& font);
961 bool HasTextColour();
962 bool HasBackgroundColour();
965 wxColour GetTextColour();
966 wxColour GetBackgroundColour();
976 %pragma(python) addtoclass = "Ok = IsOk"
979 int __cmp__(wxTreeItemId* other) {
980 if (! other) return -1;
981 return *self != *other;
989 class wxPyTreeItemData : public wxTreeItemData {
991 wxPyTreeItemData(PyObject* obj = NULL) {
998 ~wxPyTreeItemData() {
999 wxPyBeginBlockThreads();
1001 wxPyEndBlockThreads();
1004 PyObject* GetData() {
1009 void SetData(PyObject* obj) {
1010 wxPyBeginBlockThreads();
1012 wxPyEndBlockThreads();
1023 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
1025 wxPyTreeItemData(PyObject* obj = NULL);
1027 PyObject* GetData();
1028 void SetData(PyObject* obj);
1030 const wxTreeItemId& GetId();
1031 void SetId(const wxTreeItemId& id);
1036 class wxTreeEvent : public wxNotifyEvent {
1038 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
1040 wxTreeItemId GetItem();
1041 wxTreeItemId GetOldItem();
1043 const wxKeyEvent& GetKeyEvent();
1045 const wxString& GetLabel();
1050 %{ // C++ version of Python aware wxTreeCtrl
1051 class wxPyTreeCtrl : public wxTreeCtrl {
1052 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
1054 wxPyTreeCtrl() : wxTreeCtrl() {}
1055 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1059 const wxValidator& validator,
1060 const wxString& name) :
1061 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1063 bool Create(wxWindow *parent, wxWindowID id,
1067 const wxValidator& validator,
1068 const wxString& name) {
1069 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1073 int OnCompareItems(const wxTreeItemId& item1,
1074 const wxTreeItemId& item2) {
1077 wxPyBeginBlockThreads();
1078 if ((found = m_myInst.findCallback("OnCompareItems")))
1079 rval = m_myInst.callCallback(Py_BuildValue(
1081 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
1082 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
1083 wxPyEndBlockThreads();
1085 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1091 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1095 // These are for the GetFirstChild/GetNextChild methods below
1096 %typemap(python, in) long& INOUT = long* INOUT;
1097 %typemap(python, argout) long& INOUT = long* INOUT;
1100 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1102 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1103 const wxPoint& pos = wxDefaultPosition,
1104 const wxSize& size = wxDefaultSize,
1105 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1106 const wxValidator& validator = wxDefaultValidator,
1107 const wxString& name = wxPy_TreeCtrlNameStr);
1108 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1110 bool Create(wxWindow *parent, wxWindowID id = -1,
1111 const wxPoint& pos = wxDefaultPosition,
1112 const wxSize& size = wxDefaultSize,
1113 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1114 const wxValidator& validator = wxDefaultValidator,
1115 const wxString& name = wxPy_TreeCtrlNameStr);
1117 void _setCallbackInfo(PyObject* self, PyObject* _class);
1118 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)"
1120 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1121 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
1124 unsigned int GetIndent();
1125 void SetIndent(unsigned int indent);
1126 wxImageList *GetImageList();
1127 wxImageList *GetStateImageList();
1128 void SetImageList(wxImageList *imageList);
1129 void SetStateImageList(wxImageList *imageList);
1130 void AssignImageList(wxImageList* imageList);
1131 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1132 void AssignStateImageList(wxImageList* imageList);
1133 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1135 unsigned int GetSpacing();
1136 void SetSpacing(unsigned int spacing);
1138 wxString GetItemText(const wxTreeItemId& item);
1139 int GetItemImage(const wxTreeItemId& item,
1140 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1141 int GetItemSelectedImage(const wxTreeItemId& item);
1143 void SetItemText(const wxTreeItemId& item, const wxString& text);
1144 void SetItemImage(const wxTreeItemId& item, int image,
1145 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1146 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1147 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1150 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1152 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1153 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1155 data = new wxPyTreeItemData();
1156 data->SetId(item); // set the id
1157 self->SetItemData(item, data);
1162 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1163 data->SetId(item); // set the id
1164 self->SetItemData(item, data);
1167 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1168 // automatically creating data classes.
1169 PyObject* GetPyData(const wxTreeItemId& item) {
1170 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1172 data = new wxPyTreeItemData();
1173 data->SetId(item); // set the id
1174 self->SetItemData(item, data);
1176 return data->GetData();
1179 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1180 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1182 data = new wxPyTreeItemData(obj);
1183 data->SetId(item); // set the id
1184 self->SetItemData(item, data);
1191 bool IsVisible(const wxTreeItemId& item);
1192 bool ItemHasChildren(const wxTreeItemId& item);
1193 bool IsExpanded(const wxTreeItemId& item);
1194 bool IsSelected(const wxTreeItemId& item);
1196 wxTreeItemId GetRootItem();
1197 wxTreeItemId GetSelection();
1198 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1199 //size_t GetSelections(wxArrayTreeItemIds& selection);
1201 PyObject* GetSelections() {
1202 wxPyBeginBlockThreads();
1203 PyObject* rval = PyList_New(0);
1204 wxArrayTreeItemIds array;
1206 num = self->GetSelections(array);
1207 for (x=0; x < num; x++) {
1208 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1209 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1210 PyList_Append(rval, item);
1212 wxPyEndBlockThreads();
1219 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1221 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT = longzero);
1222 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1223 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1224 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1225 wxTreeItemId GetFirstVisibleItem();
1226 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1227 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1228 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1232 wxTreeItemId AddRoot(const wxString& text,
1233 int image = -1, int selectedImage = -1,
1234 wxPyTreeItemData *data = NULL);
1235 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1236 const wxString& text,
1237 int image = -1, int selectedImage = -1,
1238 wxPyTreeItemData *data = NULL);
1239 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1240 const wxTreeItemId& idPrevious,
1241 const wxString& text,
1242 int image = -1, int selectedImage = -1,
1243 wxPyTreeItemData *data = NULL);
1244 %name(InsertItemBefore)
1245 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1247 const wxString& text,
1248 int image = -1, int selectedImage = -1,
1249 wxPyTreeItemData *data = NULL);
1250 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1251 const wxString& text,
1252 int image = -1, int selectedImage = -1,
1253 wxPyTreeItemData *data = NULL);
1255 void Delete(const wxTreeItemId& item);
1256 void DeleteChildren(const wxTreeItemId& item);
1257 void DeleteAllItems();
1259 void Expand(const wxTreeItemId& item);
1260 void Collapse(const wxTreeItemId& item);
1261 void CollapseAndReset(const wxTreeItemId& item);
1262 void Toggle(const wxTreeItemId& item);
1266 void SelectItem(const wxTreeItemId& item);
1267 void EnsureVisible(const wxTreeItemId& item);
1268 void ScrollTo(const wxTreeItemId& item);
1270 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1271 wxTextCtrl* GetEditControl();
1272 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1274 void EditLabel(const wxTreeItemId& item);
1277 void SortChildren(const wxTreeItemId& item);
1279 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1280 bool IsBold(const wxTreeItemId& item) const;
1281 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1285 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1286 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1287 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1290 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1293 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1295 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1297 if (self->GetBoundingRect(item, rect, textOnly)) {
1298 wxPyBeginBlockThreads();
1299 wxRect* r = new wxRect(rect);
1300 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1301 wxPyEndBlockThreads();
1312 %pragma(python) addtoclass = "
1313 # Redefine some methods that SWIG gets a bit confused on...
1314 def GetFirstChild(self, *_args, **_kwargs):
1315 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1316 val1 = wxTreeItemIdPtr(val1)
1319 def GetNextChild(self, *_args, **_kwargs):
1320 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1321 val1 = wxTreeItemIdPtr(val1)
1324 def HitTest(self, *_args, **_kwargs):
1325 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1326 val1 = wxTreeItemIdPtr(val1)
1334 //----------------------------------------------------------------------
1339 wxDIRCTRL_SELECT_FIRST,
1340 wxDIRCTRL_SHOW_FILTERS,
1341 wxDIRCTRL_3D_INTERNAL,
1342 wxDIRCTRL_EDIT_LABELS,
1345 wxID_FILTERLISTCTRL,
1349 class wxDirItemData : public wxObject // wxTreeItemData
1352 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
1353 // ~wxDirItemDataEx();
1354 void SetNewDirName( wxString path );
1355 wxString m_path, m_name;
1362 class wxGenericDirCtrl: public wxControl
1365 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
1366 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1367 const wxPoint& pos = wxDefaultPosition,
1368 const wxSize& size = wxDefaultSize,
1369 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1370 const wxString& filter = wxPyEmptyString,
1371 int defaultFilter = 0,
1372 const wxString& name = wxPy_TreeCtrlNameStr);
1373 %name(wxPreGenericDirCtrl)wxGenericDirCtrl();
1375 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1376 %pragma(python) addtomethod = "wxPreGenericDirCtrl:val._setOORInfo(val)"
1378 bool Create(wxWindow *parent, const wxWindowID id = -1,
1379 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1380 const wxPoint& pos = wxDefaultPosition,
1381 const wxSize& size = wxDefaultSize,
1382 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1383 const wxString& filter = wxPyEmptyString,
1384 int defaultFilter = 0,
1385 const wxString& name = wxPy_TreeCtrlNameStr);
1388 // Try to expand as much of the given path as possible.
1389 bool ExpandPath(const wxString& path);
1393 inline wxString GetDefaultPath() const;
1394 void SetDefaultPath(const wxString& path);
1396 // Get dir or filename
1397 wxString GetPath() const ;
1399 // Get selected filename path only (else empty string).
1400 // I.e. don't count a directory as a selection
1401 wxString GetFilePath() const ;
1402 void SetPath(const wxString& path) ;
1404 void ShowHidden( bool show );
1405 bool GetShowHidden();
1407 wxString GetFilter() const;
1408 void SetFilter(const wxString& filter);
1410 int GetFilterIndex() const;
1411 void SetFilterIndex(int n) ;
1413 wxTreeItemId GetRootId();
1415 wxTreeCtrl* GetTreeCtrl() const;
1416 wxDirFilterListCtrl* GetFilterListCtrl() const;
1419 // void SetupSections();
1420 // // Parse the filter into an array of filters and an array of descriptions
1421 // int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
1422 // // Find the child that matches the first part of 'path'.
1423 // // E.g. if a child path is "/usr" and 'path' is "/usr/include"
1424 // // then the child for /usr is returned.
1425 // // If the path string has been used (we're at the leaf), done is set to TRUE
1426 // wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
1430 class wxDirFilterListCtrl: public wxChoice
1433 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1434 const wxPoint& pos = wxDefaultPosition,
1435 const wxSize& size = wxDefaultSize,
1437 %name(wxPreDirFilterListCtrl)wxDirFilterListCtrl();
1439 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1440 %pragma(python) addtomethod = "wxPreDirFilterListCtrl:val._setOORInfo(val)"
1442 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1443 const wxPoint& pos = wxDefaultPosition,
1444 const wxSize& size = wxDefaultSize,
1448 void FillFilterList(const wxString& filter, int defaultFilter);
1452 //----------------------------------------------------------------------
1453 //----------------------------------------------------------------------
1456 // Map renamed classes back to their common name for OOR
1457 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1458 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1459 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1462 //----------------------------------------------------------------------