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>
28 //----------------------------------------------------------------------
31 %include my_typemaps.i
33 // Import some definitions of other classes, etc.
41 %pragma(python) code = "import wx"
44 //----------------------------------------------------------------------
46 // Put some wx default wxChar* values into wxStrings.
47 const wxChar* wxListCtrlNameStr = _T("wxListCtrl");
48 DECLARE_DEF_STRING(ListCtrlNameStr);
50 const wxChar* wx_TreeCtrlNameStr = _T("wxTreeCtrl");
51 DECLARE_DEF_STRING(_TreeCtrlNameStr);
52 DECLARE_DEF_STRING(DirDialogDefaultFolderStr);
54 static const wxString wxPyEmptyString(wxT(""));
59 static const long longzero = 0;
62 //----------------------------------------------------------------------
65 /* List control event types */
66 wxEVT_COMMAND_LIST_BEGIN_DRAG,
67 wxEVT_COMMAND_LIST_BEGIN_RDRAG,
68 wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT,
69 wxEVT_COMMAND_LIST_END_LABEL_EDIT,
70 wxEVT_COMMAND_LIST_DELETE_ITEM,
71 wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS,
72 wxEVT_COMMAND_LIST_GET_INFO,
73 wxEVT_COMMAND_LIST_SET_INFO,
74 wxEVT_COMMAND_LIST_ITEM_SELECTED,
75 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
76 wxEVT_COMMAND_LIST_KEY_DOWN,
77 wxEVT_COMMAND_LIST_INSERT_ITEM,
78 wxEVT_COMMAND_LIST_COL_CLICK,
79 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
80 wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK,
81 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
82 wxEVT_COMMAND_LIST_CACHE_HINT,
83 wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
84 wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
85 wxEVT_COMMAND_LIST_COL_DRAGGING,
86 wxEVT_COMMAND_LIST_COL_END_DRAG,
87 wxEVT_COMMAND_LIST_ITEM_FOCUSED,
91 %pragma(python) code = "
92 def EVT_LIST_BEGIN_DRAG(win, id, func):
93 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func)
95 def EVT_LIST_BEGIN_RDRAG(win, id, func):
96 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func)
98 def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func):
99 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func)
101 def EVT_LIST_END_LABEL_EDIT(win, id, func):
102 win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func)
104 def EVT_LIST_DELETE_ITEM(win, id, func):
105 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func)
107 def EVT_LIST_DELETE_ALL_ITEMS(win, id, func):
108 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func)
110 def EVT_LIST_GET_INFO(win, id, func):
111 win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func)
113 def EVT_LIST_SET_INFO(win, id, func):
114 win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func)
116 def EVT_LIST_ITEM_SELECTED(win, id, func):
117 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func)
119 def EVT_LIST_ITEM_DESELECTED(win, id, func):
120 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func)
122 def EVT_LIST_KEY_DOWN(win, id, func):
123 win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func)
125 def EVT_LIST_INSERT_ITEM(win, id, func):
126 win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func)
128 def EVT_LIST_COL_CLICK(win, id, func):
129 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
131 def EVT_LIST_COL_RIGHT_CLICK(win, id, func):
132 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, func)
134 def EVT_LIST_COL_BEGIN_DRAG(win, id, func):
135 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, func)
137 def EVT_LIST_COL_DRAGGING(win, id, func):
138 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_DRAGGING, func)
140 def EVT_LIST_COL_END_DRAG(win, id, func):
141 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_END_DRAG, func)
143 def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
144 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
146 def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
147 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
149 def EVT_LIST_ITEM_ACTIVATED(win, id, func):
150 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func)
152 def EVT_LIST_CACHE_HINT(win, id, func):
153 win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func)
155 def EVT_LIST_ITEM_FOCUSED(win, id, func):
156 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_FOCUSED, func)
179 wxLC_SORT_DESCENDING,
200 wxLIST_STATE_DONTCARE,
201 wxLIST_STATE_DROPHILITED,
202 wxLIST_STATE_FOCUSED,
203 wxLIST_STATE_SELECTED,
207 wxLIST_HITTEST_ABOVE,
208 wxLIST_HITTEST_BELOW,
209 wxLIST_HITTEST_NOWHERE,
210 wxLIST_HITTEST_ONITEMICON,
211 wxLIST_HITTEST_ONITEMLABEL,
212 wxLIST_HITTEST_ONITEMRIGHT,
213 wxLIST_HITTEST_ONITEMSTATEICON,
214 wxLIST_HITTEST_TOLEFT,
215 wxLIST_HITTEST_TORIGHT,
216 wxLIST_HITTEST_ONITEM,
218 // Flags for GetNextItem
226 wxLIST_ALIGN_DEFAULT,
229 wxLIST_ALIGN_SNAP_TO_GRID,
231 // Autosize values for SetColumnWidth
232 wxLIST_AUTOSIZE = -1,
233 wxLIST_AUTOSIZE_USEHEADER = -2,
235 // Flag values for GetItemRect
240 // Flag values for FindItem (MSW only)
251 enum wxListColumnFormat
255 wxLIST_FORMAT_CENTRE,
256 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
267 wxListItemAttr(const wxColour& colText = wxNullColour,
268 const wxColour& colBack = wxNullColour,
269 const wxFont& font = wxNullFont);
273 void SetTextColour(const wxColour& colText);
274 void SetBackgroundColour(const wxColour& colBack);
275 void SetFont(const wxFont& font);
278 bool HasTextColour();
279 bool HasBackgroundColour();
282 wxColour GetTextColour();
283 wxColour GetBackgroundColour();
288 class wxListItem : public wxObject {
295 void ClearAttributes();
298 void SetMask(long mask);
300 void SetColumn(int col);
301 void SetState(long state);
302 void SetStateMask(long stateMask);
303 void SetText(const wxString& text);
304 void SetImage(int image);
305 void SetData(long data);
307 void SetWidth(int width);
308 void SetAlign(wxListColumnFormat align);
310 void SetTextColour(const wxColour& colText);
311 void SetBackgroundColour(const wxColour& colBack);
312 void SetFont(const wxFont& font);
319 const wxString& GetText();
324 wxListColumnFormat GetAlign();
326 wxListItemAttr *GetAttributes();
327 bool HasAttributes();
329 wxColour GetTextColour() const;
330 wxColour GetBackgroundColour() const;
331 wxFont GetFont() const;
333 // these members are public for compatibility
334 long m_mask; // Indicates what fields are valid
335 long m_itemId; // The zero-based item position
336 int m_col; // Zero-based column, if in report mode
337 long m_state; // The state of the item
338 long m_stateMask;// Which flags of m_state are valid (uses same flags)
339 wxString m_text; // The label/header text
340 int m_image; // The zero-based index into an image list
341 long m_data; // App-defined data
344 int m_format; // left, right, centre
345 int m_width; // width of column
350 class wxListEvent: public wxNotifyEvent {
352 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
364 %pragma(python) addtoclass = "GetCode = GetKeyCode"
368 const wxString& GetLabel();
369 const wxString& GetText();
373 const wxListItem& GetItem();
380 %{ // C++ Version of a Python aware class
381 class wxPyListCtrl : public wxListCtrl {
382 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
384 wxPyListCtrl() : wxListCtrl() {}
385 wxPyListCtrl(wxWindow* parent, wxWindowID id,
389 const wxValidator& validator,
390 const wxString& name) :
391 wxListCtrl(parent, id, pos, size, style, validator, name) {}
393 bool Create(wxWindow* parent, wxWindowID id,
397 const wxValidator& validator,
398 const wxString& name) {
399 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
402 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
403 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
404 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
409 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
411 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
412 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
413 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
418 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
420 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
421 const wxPoint& pos = wxDefaultPosition,
422 const wxSize& size = wxDefaultSize,
423 long style = wxLC_ICON,
424 const wxValidator& validator = wxDefaultValidator,
425 const wxString& name = wxPyListCtrlNameStr);
426 %name(wxPreListCtrl)wxPyListCtrl();
428 bool Create(wxWindow* parent, wxWindowID id = -1,
429 const wxPoint& pos = wxDefaultPosition,
430 const wxSize& size = wxDefaultSize,
431 long style = wxLC_ICON,
432 const wxValidator& validator = wxDefaultValidator,
433 const wxString& name = wxPyListCtrlNameStr);
435 void _setCallbackInfo(PyObject* self, PyObject* _class);
436 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxListCtrl)"
438 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
439 %pragma(python) addtomethod = "wxPreListCtrl:val._setOORInfo(val)"
441 // Set the control colours
442 bool SetForegroundColour(const wxColour& col);
443 bool SetBackgroundColour(const wxColour& col);
445 // Gets information about this column
446 // bool GetColumn(int col, wxListItem& item) const;
448 %new wxListItem* GetColumn(int col) {
450 item.SetMask(0xFFFF);
451 if (self->GetColumn(col, item))
452 return new wxListItem(item);
456 } // The OOR typemaps don't know what to do with the %new, so fix it up.
457 %pragma(python) addtoclass = "
458 def GetColumn(self, *_args, **_kwargs):
459 val = controls2c.wxListCtrl_GetColumn(self, *_args, **_kwargs)
460 if val is not None: val.thisown = 1
464 // Sets information about this column
465 bool SetColumn(int col, wxListItem& item) ;
467 // Gets the column width
468 int GetColumnWidth(int col) const;
470 // Sets the column width
471 bool SetColumnWidth(int col, int width) ;
473 // Gets the number of items that can fit vertically in the
474 // visible area of the list control (list or report view)
475 // or the total number of items in the list control (icon
476 // or small icon view)
477 int GetCountPerPage() const;
480 // Gets the edit control for editing labels.
481 wxTextCtrl* GetEditControl() const;
484 //bool GetItem(wxListItem& info) const ;
486 // Gets information about the item
487 %new wxListItem* GetItem(long itemId, int col=0) {
488 wxListItem* info = new wxListItem;
489 info->m_itemId = itemId;
491 info->m_mask = 0xFFFF;
492 self->GetItem(*info);
495 } // The OOR typemaps don't know what to do with the %new, so fix it up.
496 %pragma(python) addtoclass = "
497 def GetItem(self, *_args, **_kwargs):
498 val = controls2c.wxListCtrl_GetItem(self, *_args, **_kwargs)
499 if val is not None: val.thisown = 1
503 // Sets information about the item
504 bool SetItem(wxListItem& info) ;
506 // Sets a string field at a particular column
507 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
509 // Gets the item state
510 int GetItemState(long item, long stateMask) const ;
512 // Sets the item state
513 bool SetItemState(long item, long state, long stateMask) ;
515 // Sets the item image
516 bool SetItemImage(long item, int image, int selImage) ;
518 // Gets the item text
519 wxString GetItemText(long item) const ;
521 // Sets the item text
522 void SetItemText(long item, const wxString& str) ;
524 // Gets the item data
525 long GetItemData(long item) const ;
527 // Sets the item data
528 bool SetItemData(long item, long data) ;
531 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
532 //bool GetItemPosition(long item, wxPoint& pos) const ;
534 // Gets the item position
536 %new wxPoint* GetItemPosition(long item) {
537 wxPoint* pos = new wxPoint;
538 self->GetItemPosition(item, *pos);
541 // Gets the item rectangle
542 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
543 wxRect* rect= new wxRect;
544 self->GetItemRect(item, *rect, code);
550 // Sets the item position
551 bool SetItemPosition(long item, const wxPoint& pos) ;
553 // Gets the number of items in the list control
554 int GetItemCount() const;
556 // Gets the number of columns in the list control
557 int GetColumnCount() const;
559 // Retrieves the spacing between icons in pixels.
560 // If small is TRUE, gets the spacing for the small icon
561 // view, otherwise the large icon view.
562 int GetItemSpacing(bool isSmall) const;
565 void SetItemSpacing( int spacing, bool isSmall = FALSE );
568 // Gets the number of selected items in the list control
569 int GetSelectedItemCount() const;
571 // Gets the text colour of the listview
572 wxColour GetTextColour() const;
574 // Sets the text colour of the listview
575 void SetTextColour(const wxColour& col);
577 // Gets the index of the topmost visible item when in
578 // list or report view
579 long GetTopItem() const ;
581 // Add or remove a single window style
582 void SetSingleStyle(long style, bool add = TRUE) ;
584 // Set the whole window style
585 void SetWindowStyleFlag(long style) ;
587 // Searches for an item, starting from 'item'.
588 // item can be -1 to find the first item that matches the
590 // Returns the item or -1 if unsuccessful.
591 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
593 // Gets one of the three image lists
594 wxImageList *GetImageList(int which) const ;
596 // Sets the image list
597 void SetImageList(wxImageList *imageList, int which) ;
598 void AssignImageList(wxImageList *imageList, int which) ;
599 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
601 // returns true if it is a virtual list control
602 bool IsVirtual() const;
604 // refresh items selectively (only useful for virtual list controls)
605 void RefreshItem(long item);
606 void RefreshItems(long itemFrom, long itemTo);
608 // Arranges the items
609 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
612 bool DeleteItem(long item);
615 bool DeleteAllItems() ;
618 bool DeleteColumn(int col);
620 // Deletes all columns
621 bool DeleteAllColumns();
623 // Clears items, and columns if there are any.
628 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
630 // End label editing, optionally cancelling the edit
631 bool EndEditLabel(bool cancel);
633 void EditLabel(long item);
636 // Ensures this item is visible
637 bool EnsureVisible(long item) ;
639 // Find an item whose label matches this string, starting from the item after 'start'
640 // or the beginning if 'start' is -1.
641 long FindItem(long start, const wxString& str, bool partial = FALSE);
643 // Find an item whose data matches this data, starting from the item after 'start'
644 // or the beginning if 'start' is -1.
645 %name(FindItemData)long FindItem(long start, long data);
647 // Find an item nearest this position in the specified direction, starting from
648 // the item after 'start' or the beginning if 'start' is -1.
649 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
651 // Determines which item (if any) is at the specified point,
652 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
653 long HitTest(const wxPoint& point, int& OUTPUT);
655 // Inserts an item, returning the index of the new item if successful,
657 long InsertItem(wxListItem& info);
659 // Insert a string item
660 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
662 // Insert an image item
663 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
665 // Insert an image/string item
666 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
668 // For list view mode (only), inserts a column.
669 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
671 long InsertColumn(long col,
672 const wxString& heading,
673 int format = wxLIST_FORMAT_LEFT,
676 // set the number of items in a virtual list control
677 void SetItemCount(long count);
679 // Scrolls the list control. If in icon, small icon or report view mode,
680 // x specifies the number of pixels to scroll. If in list view mode, x
681 // specifies the number of columns to scroll.
682 // If in icon, small icon or list view mode, y specifies the number of pixels
683 // to scroll. If in report view mode, y specifies the number of lines to scroll.
684 bool ScrollList(int dx, int dy);
686 void SetItemTextColour( long item, const wxColour& col);
687 wxColour GetItemTextColour( long item ) const;
688 void SetItemBackgroundColour( long item, const wxColour &col);
689 wxColour GetItemBackgroundColour( long item ) const;
692 %pragma(python) addtoclass = "
695 def Select(self, idx, on=1):
696 '''[de]select an item'''
697 if on: state = wxLIST_STATE_SELECTED
699 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
701 def Focus(self, idx):
702 '''Focus and show the given item'''
703 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
704 self.EnsureVisible(idx)
706 def GetFocusedItem(self):
707 '''get the currently focused item or -1 if none'''
708 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
710 def GetFirstSelected(self, *args):
711 '''return first selected item, or -1 when none'''
712 return self.GetNextSelected(-1)
714 def GetNextSelected(self, item):
715 '''return subsequent selected items, or -1 when no more'''
716 return self.GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)
718 def IsSelected(self, idx):
719 '''return TRUE if the item is selected'''
720 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
722 def SetColumnImage(self, col, image):
724 item.SetMask(wxLIST_MASK_IMAGE)
726 self.SetColumn(col, item)
728 def ClearColumnImage(self, col):
729 self.SetColumnImage(col, -1)
731 def Append(self, entry):
732 '''Append an item to the list control. The entry parameter should be a
733 sequence with an item for each column'''
739 pos = self.GetItemCount()
740 self.InsertStringItem(pos, cvtfunc(entry[0]))
741 for i in range(1, len(entry)):
742 self.SetStringItem(pos, i, cvtfunc(entry[i]))
747 // bool SortItems(wxListCtrlCompare fn, long data);
750 // func is a function which takes 2 long arguments: item1, item2.
751 // item1 is the long data associated with a first item (NOT the index).
752 // item2 is the long data associated with a second item (NOT the index).
753 // The return value is a negative number if the first item should precede the second
754 // item, a positive number of the second item should precede the first,
755 // or zero if the two items are equivalent.
756 bool SortItems(PyObject* func) {
757 if (!PyCallable_Check(func))
759 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
765 wxWindow* GetMainWindow() {
769 return (wxWindow*)self->m_mainWin;
777 %{ // Python aware sorting function for wxPyListCtrl
778 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
780 PyObject* func = (PyObject*)funcPtr;
781 wxPyBeginBlockThreads();
783 PyObject* args = Py_BuildValue("(ii)", item1, item2);
784 PyObject* result = PyEval_CallObject(func, args);
787 retval = PyInt_AsLong(result);
791 wxPyEndBlockThreads();
797 //----------------------------------------------------------------------
799 class wxListView : public wxPyListCtrl
802 wxListView( wxWindow *parent,
804 const wxPoint& pos = wxDefaultPosition,
805 const wxSize& size = wxDefaultSize,
806 long style = wxLC_REPORT,
807 const wxValidator& validator = wxDefaultValidator,
808 const wxString& name = wxPyListCtrlNameStr);
809 %name(wxPreListView)wxListView();
811 bool Create( wxWindow *parent,
813 const wxPoint& pos = wxDefaultPosition,
814 const wxSize& size = wxDefaultSize,
815 long style = wxLC_REPORT,
816 const wxValidator& validator = wxDefaultValidator,
817 const wxString& name = wxPyListCtrlNameStr);
819 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
820 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
822 // [de]select an item
823 void Select(long n, bool on = TRUE);
825 // focus and show the given item
826 void Focus(long index);
828 // get the currently focused item or -1 if none
829 long GetFocusedItem() const;
831 // get first and subsequent selected items, return -1 when no more
832 long GetNextSelected(long item) const;
833 long GetFirstSelected() const;
835 // return TRUE if the item is selected
836 bool IsSelected(long index);
838 void SetColumnImage(int col, int image);
839 void ClearColumnImage(int col);
843 //----------------------------------------------------------------------
857 wxTR_FULL_ROW_HIGHLIGHT,
863 wxTR_HAS_VARIABLE_ROW_HEIGHT,
870 wxTreeItemIcon_Normal, // not selected, not expanded
871 wxTreeItemIcon_Selected, // selected, not expanded
872 wxTreeItemIcon_Expanded, // not selected, expanded
873 wxTreeItemIcon_SelectedExpanded, // selected, expanded
878 // constants for HitTest
880 wxTREE_HITTEST_ABOVE,
881 wxTREE_HITTEST_BELOW,
882 wxTREE_HITTEST_NOWHERE,
883 wxTREE_HITTEST_ONITEMBUTTON,
884 wxTREE_HITTEST_ONITEMICON,
885 wxTREE_HITTEST_ONITEMINDENT,
886 wxTREE_HITTEST_ONITEMLABEL,
887 wxTREE_HITTEST_ONITEMRIGHT,
888 wxTREE_HITTEST_ONITEMSTATEICON,
889 wxTREE_HITTEST_TOLEFT,
890 wxTREE_HITTEST_TORIGHT,
891 wxTREE_HITTEST_ONITEMUPPERPART,
892 wxTREE_HITTEST_ONITEMLOWERPART,
893 wxTREE_HITTEST_ONITEM
898 /* Tree control event types */
899 wxEVT_COMMAND_TREE_BEGIN_DRAG,
900 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
901 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
902 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
903 wxEVT_COMMAND_TREE_DELETE_ITEM,
904 wxEVT_COMMAND_TREE_GET_INFO,
905 wxEVT_COMMAND_TREE_SET_INFO,
906 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
907 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
908 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
909 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
910 wxEVT_COMMAND_TREE_SEL_CHANGED,
911 wxEVT_COMMAND_TREE_SEL_CHANGING,
912 wxEVT_COMMAND_TREE_KEY_DOWN,
913 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
914 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
915 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
916 wxEVT_COMMAND_TREE_END_DRAG,
920 %pragma(python) code = "
922 def EVT_TREE_BEGIN_DRAG(win, id, func):
923 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
925 def EVT_TREE_BEGIN_RDRAG(win, id, func):
926 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
928 def EVT_TREE_END_DRAG(win, id, func):
929 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
931 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
932 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
934 def EVT_TREE_END_LABEL_EDIT(win, id, func):
935 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
937 def EVT_TREE_GET_INFO(win, id, func):
938 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
940 def EVT_TREE_SET_INFO(win, id, func):
941 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
943 def EVT_TREE_ITEM_EXPANDED(win, id, func):
944 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
946 def EVT_TREE_ITEM_EXPANDING(win, id, func):
947 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
949 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
950 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
952 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
953 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
955 def EVT_TREE_SEL_CHANGED(win, id, func):
956 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
958 def EVT_TREE_SEL_CHANGING(win, id, func):
959 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
961 def EVT_TREE_KEY_DOWN(win, id, func):
962 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
964 def EVT_TREE_DELETE_ITEM(win, id, func):
965 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
967 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
968 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
970 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
971 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
973 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
974 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
982 //wxTreeItemAttr() { }
983 wxTreeItemAttr(const wxColour& colText = wxNullColour,
984 const wxColour& colBack = wxNullColour,
985 const wxFont& font = wxNullFont);
988 void SetTextColour(const wxColour& colText);
989 void SetBackgroundColour(const wxColour& colBack);
990 void SetFont(const wxFont& font);
993 bool HasTextColour();
994 bool HasBackgroundColour();
997 wxColour GetTextColour();
998 wxColour GetBackgroundColour();
1003 class wxTreeItemId {
1008 %pragma(python) addtoclass = "
1010 def __nonzero__(self):
1015 int __cmp__(wxTreeItemId* other) {
1016 if (! other) return -1;
1017 return *self != *other;
1025 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
1027 wxPyTreeItemData(PyObject* obj = NULL);
1029 PyObject* GetData();
1030 void SetData(PyObject* obj);
1032 const wxTreeItemId& GetId();
1033 void SetId(const wxTreeItemId& id);
1038 class wxTreeEvent : public wxNotifyEvent {
1040 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
1042 wxTreeItemId GetItem();
1043 wxTreeItemId GetOldItem();
1045 const wxKeyEvent& GetKeyEvent();
1047 %pragma(python) addtoclass = "GetCode = GetKeyCode"
1048 const wxString& GetLabel();
1049 bool IsEditCancelled() const;
1050 void SetItem(const wxTreeItemId& item);
1051 void SetOldItem(const wxTreeItemId& item);
1052 void SetPoint(const wxPoint& pt);
1053 void SetKeyEvent(const wxKeyEvent& evt);
1054 void SetLabel(const wxString& label);
1055 void SetEditCanceled(bool editCancelled);
1060 %{ // C++ version of Python aware wxTreeCtrl
1061 class wxPyTreeCtrl : public wxTreeCtrl {
1062 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
1064 wxPyTreeCtrl() : wxTreeCtrl() {}
1065 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1069 const wxValidator& validator,
1070 const wxString& name) :
1071 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1073 bool Create(wxWindow *parent, wxWindowID id,
1077 const wxValidator& validator,
1078 const wxString& name) {
1079 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1083 int OnCompareItems(const wxTreeItemId& item1,
1084 const wxTreeItemId& item2) {
1087 wxPyBeginBlockThreads();
1088 if ((found = m_myInst.findCallback("OnCompareItems"))) {
1089 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"));
1090 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"));
1091 rval = m_myInst.callCallback(Py_BuildValue("(OO)",o1,o2));
1095 wxPyEndBlockThreads();
1097 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1103 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1107 // These are for the GetFirstChild/GetNextChild methods below
1108 %typemap(python, in) long& INOUT = long* INOUT;
1109 %typemap(python, argout) long& INOUT = long* INOUT;
1112 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1114 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1115 const wxPoint& pos = wxDefaultPosition,
1116 const wxSize& size = wxDefaultSize,
1117 long style = wxTR_DEFAULT_STYLE,
1118 const wxValidator& validator = wxDefaultValidator,
1119 const wxString& name = wxPy_TreeCtrlNameStr);
1120 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1122 bool Create(wxWindow *parent, wxWindowID id = -1,
1123 const wxPoint& pos = wxDefaultPosition,
1124 const wxSize& size = wxDefaultSize,
1125 long style = wxTR_DEFAULT_STYLE,
1126 const wxValidator& validator = wxDefaultValidator,
1127 const wxString& name = wxPy_TreeCtrlNameStr);
1129 void _setCallbackInfo(PyObject* self, PyObject* _class);
1130 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)"
1132 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1133 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
1136 unsigned int GetIndent();
1137 void SetIndent(unsigned int indent);
1138 wxImageList *GetImageList();
1139 wxImageList *GetStateImageList();
1140 void SetImageList(wxImageList *imageList);
1141 void SetStateImageList(wxImageList *imageList);
1142 void AssignImageList(wxImageList* imageList);
1143 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1144 void AssignStateImageList(wxImageList* imageList);
1145 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1147 unsigned int GetSpacing();
1148 void SetSpacing(unsigned int spacing);
1150 wxString GetItemText(const wxTreeItemId& item);
1151 int GetItemImage(const wxTreeItemId& item,
1152 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1153 int GetItemSelectedImage(const wxTreeItemId& item);
1155 void SetItemText(const wxTreeItemId& item, const wxString& text);
1156 void SetItemImage(const wxTreeItemId& item, int image,
1157 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1158 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1159 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1162 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1164 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1165 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1167 data = new wxPyTreeItemData();
1168 data->SetId(item); // set the id
1169 self->SetItemData(item, data);
1174 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1175 data->SetId(item); // set the id
1176 self->SetItemData(item, data);
1179 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1180 // automatically creating data classes.
1181 PyObject* GetPyData(const wxTreeItemId& item) {
1182 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1184 data = new wxPyTreeItemData();
1185 data->SetId(item); // set the id
1186 self->SetItemData(item, data);
1188 return data->GetData();
1191 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1192 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1194 data = new wxPyTreeItemData(obj);
1195 data->SetId(item); // set the id
1196 self->SetItemData(item, data);
1203 // get the item's text colour
1204 wxColour GetItemTextColour(const wxTreeItemId& item) const;
1206 // get the item's background colour
1207 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
1209 // get the item's font
1210 wxFont GetItemFont(const wxTreeItemId& item) const;
1213 bool IsVisible(const wxTreeItemId& item);
1214 bool ItemHasChildren(const wxTreeItemId& item);
1215 bool IsExpanded(const wxTreeItemId& item);
1216 bool IsSelected(const wxTreeItemId& item);
1218 wxTreeItemId GetRootItem();
1219 wxTreeItemId GetSelection();
1220 wxTreeItemId GetItemParent(const wxTreeItemId& item);
1221 //size_t GetSelections(wxArrayTreeItemIds& selection);
1223 PyObject* GetSelections() {
1224 wxPyBeginBlockThreads();
1225 PyObject* rval = PyList_New(0);
1226 wxArrayTreeItemIds array;
1228 num = self->GetSelections(array);
1229 for (x=0; x < num; x++) {
1230 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1231 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), TRUE);
1232 PyList_Append(rval, item);
1234 wxPyEndBlockThreads();
1241 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1243 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT = longzero);
1244 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1245 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1246 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1247 wxTreeItemId GetFirstVisibleItem();
1248 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1249 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1250 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1254 wxTreeItemId AddRoot(const wxString& text,
1255 int image = -1, int selectedImage = -1,
1256 wxPyTreeItemData *data = NULL);
1257 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1258 const wxString& text,
1259 int image = -1, int selectedImage = -1,
1260 wxPyTreeItemData *data = NULL);
1261 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1262 const wxTreeItemId& idPrevious,
1263 const wxString& text,
1264 int image = -1, int selectedImage = -1,
1265 wxPyTreeItemData *data = NULL);
1266 %name(InsertItemBefore)
1267 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1269 const wxString& text,
1270 int image = -1, int selectedImage = -1,
1271 wxPyTreeItemData *data = NULL);
1272 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1273 const wxString& text,
1274 int image = -1, int selectedImage = -1,
1275 wxPyTreeItemData *data = NULL);
1277 void Delete(const wxTreeItemId& item);
1278 void DeleteChildren(const wxTreeItemId& item);
1279 void DeleteAllItems();
1281 void Expand(const wxTreeItemId& item);
1282 void Collapse(const wxTreeItemId& item);
1283 void CollapseAndReset(const wxTreeItemId& item);
1284 void Toggle(const wxTreeItemId& item);
1288 void SelectItem(const wxTreeItemId& item);
1289 void EnsureVisible(const wxTreeItemId& item);
1290 void ScrollTo(const wxTreeItemId& item);
1292 wxTextCtrl* GetEditControl();
1293 void EditLabel(const wxTreeItemId& item);
1295 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1298 void SortChildren(const wxTreeItemId& item);
1300 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1301 bool IsBold(const wxTreeItemId& item) const;
1302 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1306 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1307 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1308 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1311 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1314 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1316 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1318 if (self->GetBoundingRect(item, rect, textOnly)) {
1319 wxPyBeginBlockThreads();
1320 wxRect* r = new wxRect(rect);
1321 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1);
1322 wxPyEndBlockThreads();
1333 %pragma(python) addtoclass = "
1334 # Redefine some methods that SWIG gets a bit confused on...
1335 def GetFirstChild(self, *_args, **_kwargs):
1336 val1,val2 = controls2c.wxTreeCtrl_GetFirstChild(self, *_args, **_kwargs)
1337 val1 = wxTreeItemIdPtr(val1)
1340 def GetNextChild(self, *_args, **_kwargs):
1341 val1,val2 = controls2c.wxTreeCtrl_GetNextChild(self, *_args, **_kwargs)
1342 val1 = wxTreeItemIdPtr(val1)
1345 def HitTest(self, *_args, **_kwargs):
1346 val1, val2 = controls2c.wxTreeCtrl_HitTest(self, *_args, **_kwargs)
1347 val1 = wxTreeItemIdPtr(val1)
1355 //----------------------------------------------------------------------
1360 wxDIRCTRL_SELECT_FIRST,
1361 wxDIRCTRL_SHOW_FILTERS,
1362 wxDIRCTRL_3D_INTERNAL,
1363 wxDIRCTRL_EDIT_LABELS,
1366 wxID_FILTERLISTCTRL,
1370 class wxDirItemData : public wxObject // wxTreeItemData
1373 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
1374 // ~wxDirItemDataEx();
1375 void SetNewDirName( wxString path );
1376 wxString m_path, m_name;
1383 class wxGenericDirCtrl: public wxControl
1386 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
1387 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1388 const wxPoint& pos = wxDefaultPosition,
1389 const wxSize& size = wxDefaultSize,
1390 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1391 const wxString& filter = wxPyEmptyString,
1392 int defaultFilter = 0,
1393 const wxString& name = wxPy_TreeCtrlNameStr);
1394 %name(wxPreGenericDirCtrl)wxGenericDirCtrl();
1396 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1397 %pragma(python) addtomethod = "wxPreGenericDirCtrl:val._setOORInfo(val)"
1399 bool Create(wxWindow *parent, const wxWindowID id = -1,
1400 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1401 const wxPoint& pos = wxDefaultPosition,
1402 const wxSize& size = wxDefaultSize,
1403 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1404 const wxString& filter = wxPyEmptyString,
1405 int defaultFilter = 0,
1406 const wxString& name = wxPy_TreeCtrlNameStr);
1409 // Try to expand as much of the given path as possible.
1410 bool ExpandPath(const wxString& path);
1414 inline wxString GetDefaultPath() const;
1415 void SetDefaultPath(const wxString& path);
1417 // Get dir or filename
1418 wxString GetPath() const ;
1420 // Get selected filename path only (else empty string).
1421 // I.e. don't count a directory as a selection
1422 wxString GetFilePath() const ;
1423 void SetPath(const wxString& path) ;
1425 void ShowHidden( bool show );
1426 bool GetShowHidden();
1428 wxString GetFilter() const;
1429 void SetFilter(const wxString& filter);
1431 int GetFilterIndex() const;
1432 void SetFilterIndex(int n) ;
1434 wxTreeItemId GetRootId();
1436 wxTreeCtrl* GetTreeCtrl() const;
1437 wxDirFilterListCtrl* GetFilterListCtrl() const;
1439 // Collapse & expand the tree, thus re-creating it from scratch:
1440 void ReCreateTree();
1443 // void SetupSections();
1444 // // Parse the filter into an array of filters and an array of descriptions
1445 // int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
1446 // // Find the child that matches the first part of 'path'.
1447 // // E.g. if a child path is "/usr" and 'path' is "/usr/include"
1448 // // then the child for /usr is returned.
1449 // // If the path string has been used (we're at the leaf), done is set to TRUE
1450 // wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
1454 class wxDirFilterListCtrl: public wxChoice
1457 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1458 const wxPoint& pos = wxDefaultPosition,
1459 const wxSize& size = wxDefaultSize,
1461 %name(wxPreDirFilterListCtrl)wxDirFilterListCtrl();
1463 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1464 %pragma(python) addtomethod = "wxPreDirFilterListCtrl:val._setOORInfo(val)"
1466 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1467 const wxPoint& pos = wxDefaultPosition,
1468 const wxSize& size = wxDefaultSize,
1472 void FillFilterList(const wxString& filter, int defaultFilter);
1476 //----------------------------------------------------------------------
1477 //----------------------------------------------------------------------
1480 // Map renamed classes back to their common name for OOR
1481 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1482 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1483 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1486 //----------------------------------------------------------------------