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(""));
55 //----------------------------------------------------------------------
58 /* List control event types */
59 wxEVT_COMMAND_LIST_BEGIN_DRAG,
60 wxEVT_COMMAND_LIST_BEGIN_RDRAG,
61 wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT,
62 wxEVT_COMMAND_LIST_END_LABEL_EDIT,
63 wxEVT_COMMAND_LIST_DELETE_ITEM,
64 wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS,
65 wxEVT_COMMAND_LIST_GET_INFO,
66 wxEVT_COMMAND_LIST_SET_INFO,
67 wxEVT_COMMAND_LIST_ITEM_SELECTED,
68 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
69 wxEVT_COMMAND_LIST_KEY_DOWN,
70 wxEVT_COMMAND_LIST_INSERT_ITEM,
71 wxEVT_COMMAND_LIST_COL_CLICK,
72 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
73 wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK,
74 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
75 wxEVT_COMMAND_LIST_CACHE_HINT,
76 wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
77 wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
78 wxEVT_COMMAND_LIST_COL_DRAGGING,
79 wxEVT_COMMAND_LIST_COL_END_DRAG,
80 wxEVT_COMMAND_LIST_ITEM_FOCUSED,
84 %pragma(python) code = "
85 def EVT_LIST_BEGIN_DRAG(win, id, func):
86 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func)
88 def EVT_LIST_BEGIN_RDRAG(win, id, func):
89 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func)
91 def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func):
92 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func)
94 def EVT_LIST_END_LABEL_EDIT(win, id, func):
95 win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func)
97 def EVT_LIST_DELETE_ITEM(win, id, func):
98 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func)
100 def EVT_LIST_DELETE_ALL_ITEMS(win, id, func):
101 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func)
103 def EVT_LIST_GET_INFO(win, id, func):
104 win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func)
106 def EVT_LIST_SET_INFO(win, id, func):
107 win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func)
109 def EVT_LIST_ITEM_SELECTED(win, id, func):
110 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func)
112 def EVT_LIST_ITEM_DESELECTED(win, id, func):
113 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func)
115 def EVT_LIST_KEY_DOWN(win, id, func):
116 win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func)
118 def EVT_LIST_INSERT_ITEM(win, id, func):
119 win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func)
121 def EVT_LIST_COL_CLICK(win, id, func):
122 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
124 def EVT_LIST_COL_RIGHT_CLICK(win, id, func):
125 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, func)
127 def EVT_LIST_COL_BEGIN_DRAG(win, id, func):
128 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, func)
130 def EVT_LIST_COL_DRAGGING(win, id, func):
131 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_DRAGGING, func)
133 def EVT_LIST_COL_END_DRAG(win, id, func):
134 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_END_DRAG, func)
136 def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
137 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
139 def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
140 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
142 def EVT_LIST_ITEM_ACTIVATED(win, id, func):
143 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func)
145 def EVT_LIST_CACHE_HINT(win, id, func):
146 win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func)
148 def EVT_LIST_ITEM_FOCUSED(win, id, func):
149 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_FOCUSED, func)
172 wxLC_SORT_DESCENDING,
193 wxLIST_STATE_DONTCARE,
194 wxLIST_STATE_DROPHILITED,
195 wxLIST_STATE_FOCUSED,
196 wxLIST_STATE_SELECTED,
200 wxLIST_HITTEST_ABOVE,
201 wxLIST_HITTEST_BELOW,
202 wxLIST_HITTEST_NOWHERE,
203 wxLIST_HITTEST_ONITEMICON,
204 wxLIST_HITTEST_ONITEMLABEL,
205 wxLIST_HITTEST_ONITEMRIGHT,
206 wxLIST_HITTEST_ONITEMSTATEICON,
207 wxLIST_HITTEST_TOLEFT,
208 wxLIST_HITTEST_TORIGHT,
209 wxLIST_HITTEST_ONITEM,
211 // Flags for GetNextItem
219 wxLIST_ALIGN_DEFAULT,
222 wxLIST_ALIGN_SNAP_TO_GRID,
224 // Autosize values for SetColumnWidth
225 wxLIST_AUTOSIZE = -1,
226 wxLIST_AUTOSIZE_USEHEADER = -2,
228 // Flag values for GetItemRect
233 // Flag values for FindItem (MSW only)
244 enum wxListColumnFormat
248 wxLIST_FORMAT_CENTRE,
249 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
260 wxListItemAttr(const wxColour& colText = wxNullColour,
261 const wxColour& colBack = wxNullColour,
262 const wxFont& font = wxNullFont);
266 void SetTextColour(const wxColour& colText);
267 void SetBackgroundColour(const wxColour& colBack);
268 void SetFont(const wxFont& font);
271 bool HasTextColour();
272 bool HasBackgroundColour();
275 wxColour GetTextColour();
276 wxColour GetBackgroundColour();
281 class wxListItem : public wxObject {
288 void ClearAttributes();
291 void SetMask(long mask);
293 void SetColumn(int col);
294 void SetState(long state);
295 void SetStateMask(long stateMask);
296 void SetText(const wxString& text);
297 void SetImage(int image);
298 void SetData(long data);
300 void SetWidth(int width);
301 void SetAlign(wxListColumnFormat align);
303 void SetTextColour(const wxColour& colText);
304 void SetBackgroundColour(const wxColour& colBack);
305 void SetFont(const wxFont& font);
312 const wxString& GetText();
317 wxListColumnFormat GetAlign();
319 wxListItemAttr *GetAttributes();
320 bool HasAttributes();
322 wxColour GetTextColour() const;
323 wxColour GetBackgroundColour() const;
324 wxFont GetFont() const;
326 // these members are public for compatibility
327 long m_mask; // Indicates what fields are valid
328 long m_itemId; // The zero-based item position
329 int m_col; // Zero-based column, if in report mode
330 long m_state; // The state of the item
331 long m_stateMask;// Which flags of m_state are valid (uses same flags)
332 wxString m_text; // The label/header text
333 int m_image; // The zero-based index into an image list
334 long m_data; // App-defined data
337 int m_format; // left, right, centre
338 int m_width; // width of column
343 class wxListEvent: public wxNotifyEvent {
345 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
358 const wxString& GetLabel();
359 const wxString& GetText();
363 const wxListItem& GetItem();
370 %{ // C++ Version of a Python aware class
371 class wxPyListCtrl : public wxListCtrl {
372 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
374 wxPyListCtrl() : wxListCtrl() {}
375 wxPyListCtrl(wxWindow* parent, wxWindowID id,
379 const wxValidator& validator,
380 const wxString& name) :
381 wxListCtrl(parent, id, pos, size, style, validator, name) {}
383 bool Create(wxWindow* parent, wxWindowID id,
387 const wxValidator& validator,
388 const wxString& name) {
389 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
392 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
393 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
394 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
399 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
401 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
402 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
403 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
408 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
410 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
411 const wxPoint& pos = wxDefaultPosition,
412 const wxSize& size = wxDefaultSize,
413 long style = wxLC_ICON,
414 const wxValidator& validator = wxDefaultValidator,
415 const wxString& name = wxPyListCtrlNameStr);
416 %name(wxPreListCtrl)wxPyListCtrl();
418 bool Create(wxWindow* parent, wxWindowID id = -1,
419 const wxPoint& pos = wxDefaultPosition,
420 const wxSize& size = wxDefaultSize,
421 long style = wxLC_ICON,
422 const wxValidator& validator = wxDefaultValidator,
423 const wxString& name = wxPyListCtrlNameStr);
425 void _setCallbackInfo(PyObject* self, PyObject* _class);
426 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxListCtrl)"
428 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
429 %pragma(python) addtomethod = "wxPreListCtrl:val._setOORInfo(val)"
431 // Set the control colours
432 bool SetForegroundColour(const wxColour& col);
433 bool SetBackgroundColour(const wxColour& col);
435 // Gets information about this column
436 // bool GetColumn(int col, wxListItem& item) const;
438 %new wxListItem* GetColumn(int col) {
440 if (self->GetColumn(col, item))
441 return new wxListItem(item);
445 } // The OOR typemaps don't know what to do with the %new, so fix it up.
446 %pragma(python) addtoclass = "
447 def GetItem(self, *_args, **_kwargs):
448 val = apply(controls2c.wxListCtrl_GetColumn,(self,) + _args, _kwargs)
449 if val is not None: val.thisown = 1
453 // Sets information about this column
454 bool SetColumn(int col, wxListItem& item) ;
456 // Gets the column width
457 int GetColumnWidth(int col) const;
459 // Sets the column width
460 bool SetColumnWidth(int col, int width) ;
462 // Gets the number of items that can fit vertically in the
463 // visible area of the list control (list or report view)
464 // or the total number of items in the list control (icon
465 // or small icon view)
466 int GetCountPerPage() const;
469 // Gets the edit control for editing labels.
470 wxTextCtrl* GetEditControl() const;
473 //bool GetItem(wxListItem& info) const ;
475 // Gets information about the item
476 %new wxListItem* GetItem(long itemId, int col=0) {
477 wxListItem* info = new wxListItem;
478 info->m_itemId = itemId;
480 info->m_mask = 0xFFFF;
481 self->GetItem(*info);
484 } // The OOR typemaps don't know what to do with the %new, so fix it up.
485 %pragma(python) addtoclass = "
486 def GetItem(self, *_args, **_kwargs):
487 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
493 // Sets information about the item
494 bool SetItem(wxListItem& info) ;
496 // Sets a string field at a particular column
497 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
499 // Gets the item state
500 int GetItemState(long item, long stateMask) const ;
502 // Sets the item state
503 bool SetItemState(long item, long state, long stateMask) ;
505 // Sets the item image
506 bool SetItemImage(long item, int image, int selImage) ;
508 // Gets the item text
509 wxString GetItemText(long item) const ;
511 // Sets the item text
512 void SetItemText(long item, const wxString& str) ;
514 // Gets the item data
515 long GetItemData(long item) const ;
517 // Sets the item data
518 bool SetItemData(long item, long data) ;
521 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
522 //bool GetItemPosition(long item, wxPoint& pos) const ;
524 // Gets the item position
526 %new wxPoint* GetItemPosition(long item) {
527 wxPoint* pos = new wxPoint;
528 self->GetItemPosition(item, *pos);
531 // Gets the item rectangle
532 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
533 wxRect* rect= new wxRect;
534 self->GetItemRect(item, *rect, code);
540 // Sets the item position
541 bool SetItemPosition(long item, const wxPoint& pos) ;
543 // Gets the number of items in the list control
544 int GetItemCount() const;
546 // Gets the number of columns in the list control
547 int GetColumnCount() const;
549 // Retrieves the spacing between icons in pixels.
550 // If small is TRUE, gets the spacing for the small icon
551 // view, otherwise the large icon view.
552 int GetItemSpacing(bool isSmall) const;
554 // Gets the number of selected items in the list control
555 int GetSelectedItemCount() const;
557 // Gets the text colour of the listview
558 wxColour GetTextColour() const;
560 // Sets the text colour of the listview
561 void SetTextColour(const wxColour& col);
563 // Gets the index of the topmost visible item when in
564 // list or report view
565 long GetTopItem() const ;
567 // Add or remove a single window style
568 void SetSingleStyle(long style, bool add = TRUE) ;
570 // Set the whole window style
571 void SetWindowStyleFlag(long style) ;
573 // Searches for an item, starting from 'item'.
574 // item can be -1 to find the first item that matches the
576 // Returns the item or -1 if unsuccessful.
577 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
579 // Gets one of the three image lists
580 wxImageList *GetImageList(int which) const ;
582 // Sets the image list
583 void SetImageList(wxImageList *imageList, int which) ;
584 void AssignImageList(wxImageList *imageList, int which) ;
585 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
587 // returns true if it is a virtual list control
588 bool IsVirtual() const;
590 // refresh items selectively (only useful for virtual list controls)
591 void RefreshItem(long item);
592 void RefreshItems(long itemFrom, long itemTo);
594 // Arranges the items
595 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
598 bool DeleteItem(long item);
601 bool DeleteAllItems() ;
604 bool DeleteColumn(int col);
606 // Deletes all columns
607 bool DeleteAllColumns();
609 // Clears items, and columns if there are any.
614 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
616 // End label editing, optionally cancelling the edit
617 bool EndEditLabel(bool cancel);
620 // Ensures this item is visible
621 bool EnsureVisible(long item) ;
623 // Find an item whose label matches this string, starting from the item after 'start'
624 // or the beginning if 'start' is -1.
625 long FindItem(long start, const wxString& str, bool partial = FALSE);
627 // Find an item whose data matches this data, starting from the item after 'start'
628 // or the beginning if 'start' is -1.
629 %name(FindItemData)long FindItem(long start, long data);
631 // Find an item nearest this position in the specified direction, starting from
632 // the item after 'start' or the beginning if 'start' is -1.
633 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
635 // Determines which item (if any) is at the specified point,
636 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
637 long HitTest(const wxPoint& point, int& OUTPUT);
639 // Inserts an item, returning the index of the new item if successful,
641 long InsertItem(wxListItem& info);
643 // Insert a string item
644 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
646 // Insert an image item
647 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
649 // Insert an image/string item
650 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
652 // For list view mode (only), inserts a column.
653 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
655 long InsertColumn(long col,
656 const wxString& heading,
657 int format = wxLIST_FORMAT_LEFT,
660 // set the number of items in a virtual list control
661 void SetItemCount(long count);
663 // Scrolls the list control. If in icon, small icon or report view mode,
664 // x specifies the number of pixels to scroll. If in list view mode, x
665 // specifies the number of columns to scroll.
666 // If in icon, small icon or list view mode, y specifies the number of pixels
667 // to scroll. If in report view mode, y specifies the number of lines to scroll.
668 bool ScrollList(int dx, int dy);
670 // bool SortItems(wxListCtrlCompare fn, long data);
673 // func is a function which takes 2 long arguments: item1, item2.
674 // item1 is the long data associated with a first item (NOT the index).
675 // item2 is the long data associated with a second item (NOT the index).
676 // The return value is a negative number if the first item should precede the second
677 // item, a positive number of the second item should precede the first,
678 // or zero if the two items are equivalent.
679 bool SortItems(PyObject* func) {
680 if (!PyCallable_Check(func))
682 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
686 %pragma(python) addtoclass = "
689 def Select(self, idx, on=1):
690 '''[de]select an item'''
691 if on: state = wxLIST_STATE_SELECTED
693 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
695 def Focus(self, idx):
696 '''Focus and show the given item'''
697 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
698 self.EnsureVisible(idx)
700 def GetFocusedItem(self):
701 '''get the currently focused item or -1 if none'''
702 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
704 def IsSelected(self, idx):
705 '''return TRUE if the item is selected'''
706 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
708 def SetColumnImage(self, col, image):
710 item.SetMask(wxLIST_MASK_IMAGE)
712 self.SetColumn(col, item)
714 def ClearColumnImage(self, col):
715 self.SetColumnImage(col, -1)
717 def Append(self, entry):
718 '''Append an item to the list control. The entry parameter should be a
719 sequence with an item for each column'''
721 pos = self.GetItemCount()
722 self.InsertStringItem(pos, str(entry[0]))
723 for i in range(1, len(entry)):
724 self.SetStringItem(pos, i, str(entry[i]))
731 %{ // Python aware sorting function for wxPyListCtrl
732 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
734 PyObject* func = (PyObject*)funcPtr;
735 wxPyBeginBlockThreads();
737 PyObject* args = Py_BuildValue("(ii)", item1, item2);
738 PyObject* result = PyEval_CallObject(func, args);
741 retval = PyInt_AsLong(result);
745 wxPyEndBlockThreads();
751 //----------------------------------------------------------------------
753 class wxListView : public wxPyListCtrl
756 wxListView( wxWindow *parent,
758 const wxPoint& pos = wxDefaultPosition,
759 const wxSize& size = wxDefaultSize,
760 long style = wxLC_REPORT,
761 const wxValidator& validator = wxDefaultValidator,
762 const wxString& name = wxPyListCtrlNameStr);
763 %name(wxPreListView)wxListView();
765 bool Create( wxWindow *parent,
767 const wxPoint& pos = wxDefaultPosition,
768 const wxSize& size = wxDefaultSize,
769 long style = wxLC_REPORT,
770 const wxValidator& validator = wxDefaultValidator,
771 const wxString& name = wxPyListCtrlNameStr);
773 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
774 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
776 // [de]select an item
777 void Select(long n, bool on = TRUE);
779 // focus and show the given item
780 void Focus(long index);
782 // get the currently focused item or -1 if none
783 long GetFocusedItem() const;
785 // get first and subsequent selected items, return -1 when no more
786 long GetNextSelected(long item) const;
787 long GetFirstSelected() const;
789 // return TRUE if the item is selected
790 bool IsSelected(long index);
792 void SetColumnImage(int col, int image);
793 void ClearColumnImage(int col);
797 //----------------------------------------------------------------------
811 wxTR_FULL_ROW_HIGHLIGHT,
817 wxTR_HAS_VARIABLE_ROW_HEIGHT,
824 wxTreeItemIcon_Normal, // not selected, not expanded
825 wxTreeItemIcon_Selected, // selected, not expanded
826 wxTreeItemIcon_Expanded, // not selected, expanded
827 wxTreeItemIcon_SelectedExpanded, // selected, expanded
832 // constants for HitTest
834 wxTREE_HITTEST_ABOVE,
835 wxTREE_HITTEST_BELOW,
836 wxTREE_HITTEST_NOWHERE,
837 wxTREE_HITTEST_ONITEMBUTTON,
838 wxTREE_HITTEST_ONITEMICON,
839 wxTREE_HITTEST_ONITEMINDENT,
840 wxTREE_HITTEST_ONITEMLABEL,
841 wxTREE_HITTEST_ONITEMRIGHT,
842 wxTREE_HITTEST_ONITEMSTATEICON,
843 wxTREE_HITTEST_TOLEFT,
844 wxTREE_HITTEST_TORIGHT,
845 wxTREE_HITTEST_ONITEMUPPERPART,
846 wxTREE_HITTEST_ONITEMLOWERPART,
847 wxTREE_HITTEST_ONITEM
852 /* Tree control event types */
853 wxEVT_COMMAND_TREE_BEGIN_DRAG,
854 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
855 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
856 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
857 wxEVT_COMMAND_TREE_DELETE_ITEM,
858 wxEVT_COMMAND_TREE_GET_INFO,
859 wxEVT_COMMAND_TREE_SET_INFO,
860 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
861 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
862 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
863 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
864 wxEVT_COMMAND_TREE_SEL_CHANGED,
865 wxEVT_COMMAND_TREE_SEL_CHANGING,
866 wxEVT_COMMAND_TREE_KEY_DOWN,
867 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
868 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
869 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
870 wxEVT_COMMAND_TREE_END_DRAG,
874 %pragma(python) code = "
876 def EVT_TREE_BEGIN_DRAG(win, id, func):
877 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
879 def EVT_TREE_BEGIN_RDRAG(win, id, func):
880 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
882 def EVT_TREE_END_DRAG(win, id, func):
883 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
885 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
886 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
888 def EVT_TREE_END_LABEL_EDIT(win, id, func):
889 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
891 def EVT_TREE_GET_INFO(win, id, func):
892 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
894 def EVT_TREE_SET_INFO(win, id, func):
895 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
897 def EVT_TREE_ITEM_EXPANDED(win, id, func):
898 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
900 def EVT_TREE_ITEM_EXPANDING(win, id, func):
901 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
903 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
904 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
906 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
907 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
909 def EVT_TREE_SEL_CHANGED(win, id, func):
910 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
912 def EVT_TREE_SEL_CHANGING(win, id, func):
913 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
915 def EVT_TREE_KEY_DOWN(win, id, func):
916 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
918 def EVT_TREE_DELETE_ITEM(win, id, func):
919 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
921 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
922 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
924 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
925 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
927 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
928 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
936 //wxTreeItemAttr() { }
937 wxTreeItemAttr(const wxColour& colText = wxNullColour,
938 const wxColour& colBack = wxNullColour,
939 const wxFont& font = wxNullFont);
942 void SetTextColour(const wxColour& colText);
943 void SetBackgroundColour(const wxColour& colBack);
944 void SetFont(const wxFont& font);
947 bool HasTextColour();
948 bool HasBackgroundColour();
951 wxColour GetTextColour();
952 wxColour GetBackgroundColour();
962 %pragma(python) addtoclass = "Ok = IsOk"
965 int __cmp__(wxTreeItemId* other) {
966 if (! other) return -1;
967 return *self != *other;
975 class wxPyTreeItemData : public wxTreeItemData {
977 wxPyTreeItemData(PyObject* obj = NULL) {
984 ~wxPyTreeItemData() {
985 wxPyBeginBlockThreads();
987 wxPyEndBlockThreads();
990 PyObject* GetData() {
995 void SetData(PyObject* obj) {
996 wxPyBeginBlockThreads();
998 wxPyEndBlockThreads();
1009 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
1011 wxPyTreeItemData(PyObject* obj = NULL);
1013 PyObject* GetData();
1014 void SetData(PyObject* obj);
1016 const wxTreeItemId& GetId();
1017 void SetId(const wxTreeItemId& id);
1022 class wxTreeEvent : public wxNotifyEvent {
1024 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
1026 wxTreeItemId GetItem();
1027 wxTreeItemId GetOldItem();
1029 const wxKeyEvent& GetKeyEvent();
1031 const wxString& GetLabel();
1036 %{ // C++ version of Python aware wxTreeCtrl
1037 class wxPyTreeCtrl : public wxTreeCtrl {
1038 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
1040 wxPyTreeCtrl() : wxTreeCtrl() {}
1041 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1045 const wxValidator& validator,
1046 const wxString& name) :
1047 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1049 bool Create(wxWindow *parent, wxWindowID id,
1053 const wxValidator& validator,
1054 const wxString& name) {
1055 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1059 int OnCompareItems(const wxTreeItemId& item1,
1060 const wxTreeItemId& item2) {
1063 wxPyBeginBlockThreads();
1064 if ((found = m_myInst.findCallback("OnCompareItems")))
1065 rval = m_myInst.callCallback(Py_BuildValue(
1067 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
1068 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
1069 wxPyEndBlockThreads();
1071 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1077 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1081 // These are for the GetFirstChild/GetNextChild methods below
1082 %typemap(python, in) long& INOUT = long* INOUT;
1083 %typemap(python, argout) long& INOUT = long* INOUT;
1086 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1088 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1089 const wxPoint& pos = wxDefaultPosition,
1090 const wxSize& size = wxDefaultSize,
1091 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1092 const wxValidator& validator = wxDefaultValidator,
1093 const wxString& name = wxPy_TreeCtrlNameStr);
1094 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1096 bool Create(wxWindow *parent, wxWindowID id = -1,
1097 const wxPoint& pos = wxDefaultPosition,
1098 const wxSize& size = wxDefaultSize,
1099 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1100 const wxValidator& validator = wxDefaultValidator,
1101 const wxString& name = wxPy_TreeCtrlNameStr);
1103 void _setCallbackInfo(PyObject* self, PyObject* _class);
1104 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)"
1106 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1107 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
1110 unsigned int GetIndent();
1111 void SetIndent(unsigned int indent);
1112 wxImageList *GetImageList();
1113 wxImageList *GetStateImageList();
1114 void SetImageList(wxImageList *imageList);
1115 void SetStateImageList(wxImageList *imageList);
1116 void AssignImageList(wxImageList* imageList);
1117 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1118 void AssignStateImageList(wxImageList* imageList);
1119 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1121 unsigned int GetSpacing();
1122 void SetSpacing(unsigned int spacing);
1124 wxString GetItemText(const wxTreeItemId& item);
1125 int GetItemImage(const wxTreeItemId& item,
1126 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1127 int GetItemSelectedImage(const wxTreeItemId& item);
1129 void SetItemText(const wxTreeItemId& item, const wxString& text);
1130 void SetItemImage(const wxTreeItemId& item, int image,
1131 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1132 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1133 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1136 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1138 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1139 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1141 data = new wxPyTreeItemData();
1142 data->SetId(item); // set the id
1143 self->SetItemData(item, data);
1148 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1149 data->SetId(item); // set the id
1150 self->SetItemData(item, data);
1153 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1154 // automatically creating data classes.
1155 PyObject* GetPyData(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);
1162 return data->GetData();
1165 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1166 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1168 data = new wxPyTreeItemData(obj);
1169 data->SetId(item); // set the id
1170 self->SetItemData(item, data);
1177 bool IsVisible(const wxTreeItemId& item);
1178 bool ItemHasChildren(const wxTreeItemId& item);
1179 bool IsExpanded(const wxTreeItemId& item);
1180 bool IsSelected(const wxTreeItemId& item);
1182 wxTreeItemId GetRootItem();
1183 wxTreeItemId GetSelection();
1184 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1185 //size_t GetSelections(wxArrayTreeItemIds& selection);
1187 PyObject* GetSelections() {
1188 wxPyBeginBlockThreads();
1189 PyObject* rval = PyList_New(0);
1190 wxArrayTreeItemIds array;
1192 num = self->GetSelections(array);
1193 for (x=0; x < num; x++) {
1194 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1195 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1196 PyList_Append(rval, item);
1198 wxPyEndBlockThreads();
1205 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1207 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
1208 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1209 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1210 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1211 wxTreeItemId GetFirstVisibleItem();
1212 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1213 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1214 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1218 wxTreeItemId AddRoot(const wxString& text,
1219 int image = -1, int selectedImage = -1,
1220 wxPyTreeItemData *data = NULL);
1221 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1222 const wxString& text,
1223 int image = -1, int selectedImage = -1,
1224 wxPyTreeItemData *data = NULL);
1225 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1226 const wxTreeItemId& idPrevious,
1227 const wxString& text,
1228 int image = -1, int selectedImage = -1,
1229 wxPyTreeItemData *data = NULL);
1230 %name(InsertItemBefore)
1231 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1233 const wxString& text,
1234 int image = -1, int selectedImage = -1,
1235 wxPyTreeItemData *data = NULL);
1236 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1237 const wxString& text,
1238 int image = -1, int selectedImage = -1,
1239 wxPyTreeItemData *data = NULL);
1241 void Delete(const wxTreeItemId& item);
1242 void DeleteChildren(const wxTreeItemId& item);
1243 void DeleteAllItems();
1245 void Expand(const wxTreeItemId& item);
1246 void Collapse(const wxTreeItemId& item);
1247 void CollapseAndReset(const wxTreeItemId& item);
1248 void Toggle(const wxTreeItemId& item);
1252 void SelectItem(const wxTreeItemId& item);
1253 void EnsureVisible(const wxTreeItemId& item);
1254 void ScrollTo(const wxTreeItemId& item);
1256 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1257 wxTextCtrl* GetEditControl();
1258 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1260 void EditLabel(const wxTreeItemId& item);
1263 void SortChildren(const wxTreeItemId& item);
1265 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1266 bool IsBold(const wxTreeItemId& item) const;
1267 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1271 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1272 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1273 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1276 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1279 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1281 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1283 if (self->GetBoundingRect(item, rect, textOnly)) {
1284 wxPyBeginBlockThreads();
1285 wxRect* r = new wxRect(rect);
1286 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1287 wxPyEndBlockThreads();
1298 %pragma(python) addtoclass = "
1299 # Redefine some methods that SWIG gets a bit confused on...
1300 def GetFirstChild(self, *_args, **_kwargs):
1301 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1302 val1 = wxTreeItemIdPtr(val1)
1305 def GetNextChild(self, *_args, **_kwargs):
1306 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1307 val1 = wxTreeItemIdPtr(val1)
1310 def HitTest(self, *_args, **_kwargs):
1311 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1312 val1 = wxTreeItemIdPtr(val1)
1320 //----------------------------------------------------------------------
1325 wxDIRCTRL_SELECT_FIRST,
1326 wxDIRCTRL_SHOW_FILTERS,
1327 wxDIRCTRL_3D_INTERNAL,
1331 class wxDirItemData : public wxObject // wxTreeItemData
1334 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
1335 // ~wxDirItemDataEx();
1336 void SetNewDirName( wxString path );
1337 wxString m_path, m_name;
1344 class wxGenericDirCtrl: public wxControl
1347 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
1348 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1349 const wxPoint& pos = wxDefaultPosition,
1350 const wxSize& size = wxDefaultSize,
1351 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1352 const wxString& filter = wxPyEmptyString,
1353 int defaultFilter = 0,
1354 const wxString& name = wxPy_TreeCtrlNameStr);
1355 %name(wxPreGenericDirCtrl)wxGenericDirCtrl();
1357 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1358 %pragma(python) addtomethod = "wxPreGenericDirCtrl:val._setOORInfo(val)"
1360 bool Create(wxWindow *parent, const wxWindowID id = -1,
1361 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1362 const wxPoint& pos = wxDefaultPosition,
1363 const wxSize& size = wxDefaultSize,
1364 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1365 const wxString& filter = wxPyEmptyString,
1366 int defaultFilter = 0,
1367 const wxString& name = wxPy_TreeCtrlNameStr);
1370 // Try to expand as much of the given path as possible.
1371 bool ExpandPath(const wxString& path);
1375 inline wxString GetDefaultPath() const;
1376 void SetDefaultPath(const wxString& path);
1378 // Get dir or filename
1379 wxString GetPath() const ;
1381 // Get selected filename path only (else empty string).
1382 // I.e. don't count a directory as a selection
1383 wxString GetFilePath() const ;
1384 void SetPath(const wxString& path) ;
1386 void ShowHidden( bool show );
1387 bool GetShowHidden();
1389 wxString GetFilter() const;
1390 void SetFilter(const wxString& filter);
1392 int GetFilterIndex() const;
1393 void SetFilterIndex(int n) ;
1395 wxTreeItemId GetRootId();
1397 wxTreeCtrl* GetTreeCtrl() const;
1398 wxDirFilterListCtrl* GetFilterListCtrl() const;
1401 // void SetupSections();
1402 // // Parse the filter into an array of filters and an array of descriptions
1403 // int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
1404 // // Find the child that matches the first part of 'path'.
1405 // // E.g. if a child path is "/usr" and 'path' is "/usr/include"
1406 // // then the child for /usr is returned.
1407 // // If the path string has been used (we're at the leaf), done is set to TRUE
1408 // wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
1412 class wxDirFilterListCtrl: public wxChoice
1415 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1416 const wxPoint& pos = wxDefaultPosition,
1417 const wxSize& size = wxDefaultSize,
1419 %name(wxPreDirFilterListCtrl)wxDirFilterListCtrl();
1421 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1422 %pragma(python) addtomethod = "wxPreDirFilterListCtrl:val._setOORInfo(val)"
1424 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1425 const wxPoint& pos = wxDefaultPosition,
1426 const wxSize& size = wxDefaultSize,
1430 void FillFilterList(const wxString& filter, int defaultFilter);
1434 //----------------------------------------------------------------------
1435 //----------------------------------------------------------------------
1438 // Map renamed classes back to their common name for OOR
1439 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1440 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1441 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1444 //----------------------------------------------------------------------