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 item.SetMask(0xFFFF);
448 if (self->GetColumn(col, item))
449 return new wxListItem(item);
453 } // The OOR typemaps don't know what to do with the %new, so fix it up.
454 %pragma(python) addtoclass = "
455 def GetColumn(self, *_args, **_kwargs):
456 val = apply(controls2c.wxListCtrl_GetColumn,(self,) + _args, _kwargs)
457 if val is not None: val.thisown = 1
461 // Sets information about this column
462 bool SetColumn(int col, wxListItem& item) ;
464 // Gets the column width
465 int GetColumnWidth(int col) const;
467 // Sets the column width
468 bool SetColumnWidth(int col, int width) ;
470 // Gets the number of items that can fit vertically in the
471 // visible area of the list control (list or report view)
472 // or the total number of items in the list control (icon
473 // or small icon view)
474 int GetCountPerPage() const;
477 // Gets the edit control for editing labels.
478 wxTextCtrl* GetEditControl() const;
481 //bool GetItem(wxListItem& info) const ;
483 // Gets information about the item
484 %new wxListItem* GetItem(long itemId, int col=0) {
485 wxListItem* info = new wxListItem;
486 info->m_itemId = itemId;
488 info->m_mask = 0xFFFF;
489 self->GetItem(*info);
492 } // The OOR typemaps don't know what to do with the %new, so fix it up.
493 %pragma(python) addtoclass = "
494 def GetItem(self, *_args, **_kwargs):
495 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
496 if val is not None: val.thisown = 1
501 // Sets information about the item
502 bool SetItem(wxListItem& info) ;
504 // Sets a string field at a particular column
505 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
507 // Gets the item state
508 int GetItemState(long item, long stateMask) const ;
510 // Sets the item state
511 bool SetItemState(long item, long state, long stateMask) ;
513 // Sets the item image
514 bool SetItemImage(long item, int image, int selImage) ;
516 // Gets the item text
517 wxString GetItemText(long item) const ;
519 // Sets the item text
520 void SetItemText(long item, const wxString& str) ;
522 // Gets the item data
523 long GetItemData(long item) const ;
525 // Sets the item data
526 bool SetItemData(long item, long data) ;
529 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
530 //bool GetItemPosition(long item, wxPoint& pos) const ;
532 // Gets the item position
534 %new wxPoint* GetItemPosition(long item) {
535 wxPoint* pos = new wxPoint;
536 self->GetItemPosition(item, *pos);
539 // Gets the item rectangle
540 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
541 wxRect* rect= new wxRect;
542 self->GetItemRect(item, *rect, code);
548 // Sets the item position
549 bool SetItemPosition(long item, const wxPoint& pos) ;
551 // Gets the number of items in the list control
552 int GetItemCount() const;
554 // Gets the number of columns in the list control
555 int GetColumnCount() const;
557 // Retrieves the spacing between icons in pixels.
558 // If small is TRUE, gets the spacing for the small icon
559 // view, otherwise the large icon view.
560 int GetItemSpacing(bool isSmall) const;
562 // Gets the number of selected items in the list control
563 int GetSelectedItemCount() const;
565 // Gets the text colour of the listview
566 wxColour GetTextColour() const;
568 // Sets the text colour of the listview
569 void SetTextColour(const wxColour& col);
571 // Gets the index of the topmost visible item when in
572 // list or report view
573 long GetTopItem() const ;
575 // Add or remove a single window style
576 void SetSingleStyle(long style, bool add = TRUE) ;
578 // Set the whole window style
579 void SetWindowStyleFlag(long style) ;
581 // Searches for an item, starting from 'item'.
582 // item can be -1 to find the first item that matches the
584 // Returns the item or -1 if unsuccessful.
585 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
587 // Gets one of the three image lists
588 wxImageList *GetImageList(int which) const ;
590 // Sets the image list
591 void SetImageList(wxImageList *imageList, int which) ;
592 void AssignImageList(wxImageList *imageList, int which) ;
593 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
595 // returns true if it is a virtual list control
596 bool IsVirtual() const;
598 // refresh items selectively (only useful for virtual list controls)
599 void RefreshItem(long item);
600 void RefreshItems(long itemFrom, long itemTo);
602 // Arranges the items
603 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
606 bool DeleteItem(long item);
609 bool DeleteAllItems() ;
612 bool DeleteColumn(int col);
614 // Deletes all columns
615 bool DeleteAllColumns();
617 // Clears items, and columns if there are any.
622 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
624 // End label editing, optionally cancelling the edit
625 bool EndEditLabel(bool cancel);
628 // Ensures this item is visible
629 bool EnsureVisible(long item) ;
631 // Find an item whose label matches this string, starting from the item after 'start'
632 // or the beginning if 'start' is -1.
633 long FindItem(long start, const wxString& str, bool partial = FALSE);
635 // Find an item whose data matches this data, starting from the item after 'start'
636 // or the beginning if 'start' is -1.
637 %name(FindItemData)long FindItem(long start, long data);
639 // Find an item nearest this position in the specified direction, starting from
640 // the item after 'start' or the beginning if 'start' is -1.
641 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
643 // Determines which item (if any) is at the specified point,
644 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
645 long HitTest(const wxPoint& point, int& OUTPUT);
647 // Inserts an item, returning the index of the new item if successful,
649 long InsertItem(wxListItem& info);
651 // Insert a string item
652 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
654 // Insert an image item
655 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
657 // Insert an image/string item
658 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
660 // For list view mode (only), inserts a column.
661 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
663 long InsertColumn(long col,
664 const wxString& heading,
665 int format = wxLIST_FORMAT_LEFT,
668 // set the number of items in a virtual list control
669 void SetItemCount(long count);
671 // Scrolls the list control. If in icon, small icon or report view mode,
672 // x specifies the number of pixels to scroll. If in list view mode, x
673 // specifies the number of columns to scroll.
674 // If in icon, small icon or list view mode, y specifies the number of pixels
675 // to scroll. If in report view mode, y specifies the number of lines to scroll.
676 bool ScrollList(int dx, int dy);
678 void SetItemTextColour( long item, const wxColour& col);
679 wxColour GetItemTextColour( long item ) const;
680 void SetItemBackgroundColour( long item, const wxColour &col);
681 wxColour GetItemBackgroundColour( long item ) const;
684 %pragma(python) addtoclass = "
687 def Select(self, idx, on=1):
688 '''[de]select an item'''
689 if on: state = wxLIST_STATE_SELECTED
691 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
693 def Focus(self, idx):
694 '''Focus and show the given item'''
695 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
696 self.EnsureVisible(idx)
698 def GetFocusedItem(self):
699 '''get the currently focused item or -1 if none'''
700 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
702 def IsSelected(self, idx):
703 '''return TRUE if the item is selected'''
704 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
706 def SetColumnImage(self, col, image):
708 item.SetMask(wxLIST_MASK_IMAGE)
710 self.SetColumn(col, item)
712 def ClearColumnImage(self, col):
713 self.SetColumnImage(col, -1)
715 def Append(self, entry):
716 '''Append an item to the list control. The entry parameter should be a
717 sequence with an item for each column'''
719 pos = self.GetItemCount()
720 self.InsertStringItem(pos, str(entry[0]))
721 for i in range(1, len(entry)):
722 self.SetStringItem(pos, i, str(entry[i]))
727 // bool SortItems(wxListCtrlCompare fn, long data);
730 // func is a function which takes 2 long arguments: item1, item2.
731 // item1 is the long data associated with a first item (NOT the index).
732 // item2 is the long data associated with a second item (NOT the index).
733 // The return value is a negative number if the first item should precede the second
734 // item, a positive number of the second item should precede the first,
735 // or zero if the two items are equivalent.
736 bool SortItems(PyObject* func) {
737 if (!PyCallable_Check(func))
739 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
746 %{ // Python aware sorting function for wxPyListCtrl
747 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
749 PyObject* func = (PyObject*)funcPtr;
750 wxPyBeginBlockThreads();
752 PyObject* args = Py_BuildValue("(ii)", item1, item2);
753 PyObject* result = PyEval_CallObject(func, args);
756 retval = PyInt_AsLong(result);
760 wxPyEndBlockThreads();
766 //----------------------------------------------------------------------
768 class wxListView : public wxPyListCtrl
771 wxListView( wxWindow *parent,
773 const wxPoint& pos = wxDefaultPosition,
774 const wxSize& size = wxDefaultSize,
775 long style = wxLC_REPORT,
776 const wxValidator& validator = wxDefaultValidator,
777 const wxString& name = wxPyListCtrlNameStr);
778 %name(wxPreListView)wxListView();
780 bool Create( wxWindow *parent,
782 const wxPoint& pos = wxDefaultPosition,
783 const wxSize& size = wxDefaultSize,
784 long style = wxLC_REPORT,
785 const wxValidator& validator = wxDefaultValidator,
786 const wxString& name = wxPyListCtrlNameStr);
788 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
789 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
791 // [de]select an item
792 void Select(long n, bool on = TRUE);
794 // focus and show the given item
795 void Focus(long index);
797 // get the currently focused item or -1 if none
798 long GetFocusedItem() const;
800 // get first and subsequent selected items, return -1 when no more
801 long GetNextSelected(long item) const;
802 long GetFirstSelected() const;
804 // return TRUE if the item is selected
805 bool IsSelected(long index);
807 void SetColumnImage(int col, int image);
808 void ClearColumnImage(int col);
812 //----------------------------------------------------------------------
826 wxTR_FULL_ROW_HIGHLIGHT,
832 wxTR_HAS_VARIABLE_ROW_HEIGHT,
839 wxTreeItemIcon_Normal, // not selected, not expanded
840 wxTreeItemIcon_Selected, // selected, not expanded
841 wxTreeItemIcon_Expanded, // not selected, expanded
842 wxTreeItemIcon_SelectedExpanded, // selected, expanded
847 // constants for HitTest
849 wxTREE_HITTEST_ABOVE,
850 wxTREE_HITTEST_BELOW,
851 wxTREE_HITTEST_NOWHERE,
852 wxTREE_HITTEST_ONITEMBUTTON,
853 wxTREE_HITTEST_ONITEMICON,
854 wxTREE_HITTEST_ONITEMINDENT,
855 wxTREE_HITTEST_ONITEMLABEL,
856 wxTREE_HITTEST_ONITEMRIGHT,
857 wxTREE_HITTEST_ONITEMSTATEICON,
858 wxTREE_HITTEST_TOLEFT,
859 wxTREE_HITTEST_TORIGHT,
860 wxTREE_HITTEST_ONITEMUPPERPART,
861 wxTREE_HITTEST_ONITEMLOWERPART,
862 wxTREE_HITTEST_ONITEM
867 /* Tree control event types */
868 wxEVT_COMMAND_TREE_BEGIN_DRAG,
869 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
870 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
871 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
872 wxEVT_COMMAND_TREE_DELETE_ITEM,
873 wxEVT_COMMAND_TREE_GET_INFO,
874 wxEVT_COMMAND_TREE_SET_INFO,
875 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
876 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
877 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
878 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
879 wxEVT_COMMAND_TREE_SEL_CHANGED,
880 wxEVT_COMMAND_TREE_SEL_CHANGING,
881 wxEVT_COMMAND_TREE_KEY_DOWN,
882 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
883 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
884 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
885 wxEVT_COMMAND_TREE_END_DRAG,
889 %pragma(python) code = "
891 def EVT_TREE_BEGIN_DRAG(win, id, func):
892 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
894 def EVT_TREE_BEGIN_RDRAG(win, id, func):
895 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
897 def EVT_TREE_END_DRAG(win, id, func):
898 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
900 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
901 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
903 def EVT_TREE_END_LABEL_EDIT(win, id, func):
904 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
906 def EVT_TREE_GET_INFO(win, id, func):
907 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
909 def EVT_TREE_SET_INFO(win, id, func):
910 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
912 def EVT_TREE_ITEM_EXPANDED(win, id, func):
913 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
915 def EVT_TREE_ITEM_EXPANDING(win, id, func):
916 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
918 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
919 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
921 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
922 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
924 def EVT_TREE_SEL_CHANGED(win, id, func):
925 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
927 def EVT_TREE_SEL_CHANGING(win, id, func):
928 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
930 def EVT_TREE_KEY_DOWN(win, id, func):
931 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
933 def EVT_TREE_DELETE_ITEM(win, id, func):
934 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
936 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
937 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
939 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
940 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
942 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
943 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
951 //wxTreeItemAttr() { }
952 wxTreeItemAttr(const wxColour& colText = wxNullColour,
953 const wxColour& colBack = wxNullColour,
954 const wxFont& font = wxNullFont);
957 void SetTextColour(const wxColour& colText);
958 void SetBackgroundColour(const wxColour& colBack);
959 void SetFont(const wxFont& font);
962 bool HasTextColour();
963 bool HasBackgroundColour();
966 wxColour GetTextColour();
967 wxColour GetBackgroundColour();
977 %pragma(python) addtoclass = "Ok = IsOk"
980 int __cmp__(wxTreeItemId* other) {
981 if (! other) return -1;
982 return *self != *other;
990 class wxPyTreeItemData : public wxTreeItemData {
992 wxPyTreeItemData(PyObject* obj = NULL) {
999 ~wxPyTreeItemData() {
1000 wxPyBeginBlockThreads();
1002 wxPyEndBlockThreads();
1005 PyObject* GetData() {
1010 void SetData(PyObject* obj) {
1011 wxPyBeginBlockThreads();
1013 wxPyEndBlockThreads();
1024 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
1026 wxPyTreeItemData(PyObject* obj = NULL);
1028 PyObject* GetData();
1029 void SetData(PyObject* obj);
1031 const wxTreeItemId& GetId();
1032 void SetId(const wxTreeItemId& id);
1037 class wxTreeEvent : public wxNotifyEvent {
1039 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
1041 wxTreeItemId GetItem();
1042 wxTreeItemId GetOldItem();
1044 const wxKeyEvent& GetKeyEvent();
1046 const wxString& GetLabel();
1051 %{ // C++ version of Python aware wxTreeCtrl
1052 class wxPyTreeCtrl : public wxTreeCtrl {
1053 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
1055 wxPyTreeCtrl() : wxTreeCtrl() {}
1056 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1060 const wxValidator& validator,
1061 const wxString& name) :
1062 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1064 bool Create(wxWindow *parent, wxWindowID id,
1068 const wxValidator& validator,
1069 const wxString& name) {
1070 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1074 int OnCompareItems(const wxTreeItemId& item1,
1075 const wxTreeItemId& item2) {
1078 wxPyBeginBlockThreads();
1079 if ((found = m_myInst.findCallback("OnCompareItems"))) {
1080 PyObject *o1 = wxPyConstructObject((void*)&item1, "wxTreeItemId");
1081 PyObject *o2 = wxPyConstructObject((void*)&item2, "wxTreeItemId");
1082 rval = m_myInst.callCallback(Py_BuildValue("(OO)",o1,o2));
1086 wxPyEndBlockThreads();
1088 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1094 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1098 // These are for the GetFirstChild/GetNextChild methods below
1099 %typemap(python, in) long& INOUT = long* INOUT;
1100 %typemap(python, argout) long& INOUT = long* INOUT;
1103 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1105 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1106 const wxPoint& pos = wxDefaultPosition,
1107 const wxSize& size = wxDefaultSize,
1108 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1109 const wxValidator& validator = wxDefaultValidator,
1110 const wxString& name = wxPy_TreeCtrlNameStr);
1111 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1113 bool Create(wxWindow *parent, wxWindowID id = -1,
1114 const wxPoint& pos = wxDefaultPosition,
1115 const wxSize& size = wxDefaultSize,
1116 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1117 const wxValidator& validator = wxDefaultValidator,
1118 const wxString& name = wxPy_TreeCtrlNameStr);
1120 void _setCallbackInfo(PyObject* self, PyObject* _class);
1121 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)"
1123 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1124 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
1127 unsigned int GetIndent();
1128 void SetIndent(unsigned int indent);
1129 wxImageList *GetImageList();
1130 wxImageList *GetStateImageList();
1131 void SetImageList(wxImageList *imageList);
1132 void SetStateImageList(wxImageList *imageList);
1133 void AssignImageList(wxImageList* imageList);
1134 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1135 void AssignStateImageList(wxImageList* imageList);
1136 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1138 unsigned int GetSpacing();
1139 void SetSpacing(unsigned int spacing);
1141 wxString GetItemText(const wxTreeItemId& item);
1142 int GetItemImage(const wxTreeItemId& item,
1143 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1144 int GetItemSelectedImage(const wxTreeItemId& item);
1146 void SetItemText(const wxTreeItemId& item, const wxString& text);
1147 void SetItemImage(const wxTreeItemId& item, int image,
1148 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1149 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1150 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1153 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1155 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1156 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1158 data = new wxPyTreeItemData();
1159 data->SetId(item); // set the id
1160 self->SetItemData(item, data);
1165 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1166 data->SetId(item); // set the id
1167 self->SetItemData(item, data);
1170 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1171 // automatically creating data classes.
1172 PyObject* GetPyData(const wxTreeItemId& item) {
1173 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1175 data = new wxPyTreeItemData();
1176 data->SetId(item); // set the id
1177 self->SetItemData(item, data);
1179 return data->GetData();
1182 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1183 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1185 data = new wxPyTreeItemData(obj);
1186 data->SetId(item); // set the id
1187 self->SetItemData(item, data);
1194 bool IsVisible(const wxTreeItemId& item);
1195 bool ItemHasChildren(const wxTreeItemId& item);
1196 bool IsExpanded(const wxTreeItemId& item);
1197 bool IsSelected(const wxTreeItemId& item);
1199 wxTreeItemId GetRootItem();
1200 wxTreeItemId GetSelection();
1201 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1202 //size_t GetSelections(wxArrayTreeItemIds& selection);
1204 PyObject* GetSelections() {
1205 wxPyBeginBlockThreads();
1206 PyObject* rval = PyList_New(0);
1207 wxArrayTreeItemIds array;
1209 num = self->GetSelections(array);
1210 for (x=0; x < num; x++) {
1211 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1212 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1213 PyList_Append(rval, item);
1215 wxPyEndBlockThreads();
1222 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1224 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT = longzero);
1225 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1226 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1227 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1228 wxTreeItemId GetFirstVisibleItem();
1229 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1230 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1231 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1235 wxTreeItemId AddRoot(const wxString& text,
1236 int image = -1, int selectedImage = -1,
1237 wxPyTreeItemData *data = NULL);
1238 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1239 const wxString& text,
1240 int image = -1, int selectedImage = -1,
1241 wxPyTreeItemData *data = NULL);
1242 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1243 const wxTreeItemId& idPrevious,
1244 const wxString& text,
1245 int image = -1, int selectedImage = -1,
1246 wxPyTreeItemData *data = NULL);
1247 %name(InsertItemBefore)
1248 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1250 const wxString& text,
1251 int image = -1, int selectedImage = -1,
1252 wxPyTreeItemData *data = NULL);
1253 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1254 const wxString& text,
1255 int image = -1, int selectedImage = -1,
1256 wxPyTreeItemData *data = NULL);
1258 void Delete(const wxTreeItemId& item);
1259 void DeleteChildren(const wxTreeItemId& item);
1260 void DeleteAllItems();
1262 void Expand(const wxTreeItemId& item);
1263 void Collapse(const wxTreeItemId& item);
1264 void CollapseAndReset(const wxTreeItemId& item);
1265 void Toggle(const wxTreeItemId& item);
1269 void SelectItem(const wxTreeItemId& item);
1270 void EnsureVisible(const wxTreeItemId& item);
1271 void ScrollTo(const wxTreeItemId& item);
1273 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1274 wxTextCtrl* GetEditControl();
1275 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1277 void EditLabel(const wxTreeItemId& item);
1280 void SortChildren(const wxTreeItemId& item);
1282 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1283 bool IsBold(const wxTreeItemId& item) const;
1284 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1288 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1289 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1290 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1293 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1296 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1298 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1300 if (self->GetBoundingRect(item, rect, textOnly)) {
1301 wxPyBeginBlockThreads();
1302 wxRect* r = new wxRect(rect);
1303 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1304 wxPyEndBlockThreads();
1315 %pragma(python) addtoclass = "
1316 # Redefine some methods that SWIG gets a bit confused on...
1317 def GetFirstChild(self, *_args, **_kwargs):
1318 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1319 val1 = wxTreeItemIdPtr(val1)
1322 def GetNextChild(self, *_args, **_kwargs):
1323 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1324 val1 = wxTreeItemIdPtr(val1)
1327 def HitTest(self, *_args, **_kwargs):
1328 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1329 val1 = wxTreeItemIdPtr(val1)
1337 //----------------------------------------------------------------------
1342 wxDIRCTRL_SELECT_FIRST,
1343 wxDIRCTRL_SHOW_FILTERS,
1344 wxDIRCTRL_3D_INTERNAL,
1345 wxDIRCTRL_EDIT_LABELS,
1348 wxID_FILTERLISTCTRL,
1352 class wxDirItemData : public wxObject // wxTreeItemData
1355 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
1356 // ~wxDirItemDataEx();
1357 void SetNewDirName( wxString path );
1358 wxString m_path, m_name;
1365 class wxGenericDirCtrl: public wxControl
1368 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
1369 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1370 const wxPoint& pos = wxDefaultPosition,
1371 const wxSize& size = wxDefaultSize,
1372 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1373 const wxString& filter = wxPyEmptyString,
1374 int defaultFilter = 0,
1375 const wxString& name = wxPy_TreeCtrlNameStr);
1376 %name(wxPreGenericDirCtrl)wxGenericDirCtrl();
1378 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1379 %pragma(python) addtomethod = "wxPreGenericDirCtrl:val._setOORInfo(val)"
1381 bool Create(wxWindow *parent, const wxWindowID id = -1,
1382 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1383 const wxPoint& pos = wxDefaultPosition,
1384 const wxSize& size = wxDefaultSize,
1385 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1386 const wxString& filter = wxPyEmptyString,
1387 int defaultFilter = 0,
1388 const wxString& name = wxPy_TreeCtrlNameStr);
1391 // Try to expand as much of the given path as possible.
1392 bool ExpandPath(const wxString& path);
1396 inline wxString GetDefaultPath() const;
1397 void SetDefaultPath(const wxString& path);
1399 // Get dir or filename
1400 wxString GetPath() const ;
1402 // Get selected filename path only (else empty string).
1403 // I.e. don't count a directory as a selection
1404 wxString GetFilePath() const ;
1405 void SetPath(const wxString& path) ;
1407 void ShowHidden( bool show );
1408 bool GetShowHidden();
1410 wxString GetFilter() const;
1411 void SetFilter(const wxString& filter);
1413 int GetFilterIndex() const;
1414 void SetFilterIndex(int n) ;
1416 wxTreeItemId GetRootId();
1418 wxTreeCtrl* GetTreeCtrl() const;
1419 wxDirFilterListCtrl* GetFilterListCtrl() const;
1422 // void SetupSections();
1423 // // Parse the filter into an array of filters and an array of descriptions
1424 // int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
1425 // // Find the child that matches the first part of 'path'.
1426 // // E.g. if a child path is "/usr" and 'path' is "/usr/include"
1427 // // then the child for /usr is returned.
1428 // // If the path string has been used (we're at the leaf), done is set to TRUE
1429 // wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
1433 class wxDirFilterListCtrl: public wxChoice
1436 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1437 const wxPoint& pos = wxDefaultPosition,
1438 const wxSize& size = wxDefaultSize,
1440 %name(wxPreDirFilterListCtrl)wxDirFilterListCtrl();
1442 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1443 %pragma(python) addtomethod = "wxPreDirFilterListCtrl:val._setOORInfo(val)"
1445 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1446 const wxPoint& pos = wxDefaultPosition,
1447 const wxSize& size = wxDefaultSize,
1451 void FillFilterList(const wxString& filter, int defaultFilter);
1455 //----------------------------------------------------------------------
1456 //----------------------------------------------------------------------
1459 // Map renamed classes back to their common name for OOR
1460 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1461 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1462 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1465 //----------------------------------------------------------------------