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 //----------------------------------------------------------------------
43 //----------------------------------------------------------------------
46 /* List control event types */
47 wxEVT_COMMAND_LIST_BEGIN_DRAG,
48 wxEVT_COMMAND_LIST_BEGIN_RDRAG,
49 wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT,
50 wxEVT_COMMAND_LIST_END_LABEL_EDIT,
51 wxEVT_COMMAND_LIST_DELETE_ITEM,
52 wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS,
53 wxEVT_COMMAND_LIST_GET_INFO,
54 wxEVT_COMMAND_LIST_SET_INFO,
55 wxEVT_COMMAND_LIST_ITEM_SELECTED,
56 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
57 wxEVT_COMMAND_LIST_KEY_DOWN,
58 wxEVT_COMMAND_LIST_INSERT_ITEM,
59 wxEVT_COMMAND_LIST_COL_CLICK,
60 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
61 wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK,
62 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
63 wxEVT_COMMAND_LIST_CACHE_HINT,
64 wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
65 wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
66 wxEVT_COMMAND_LIST_COL_DRAGGING,
67 wxEVT_COMMAND_LIST_COL_END_DRAG,
68 wxEVT_COMMAND_LIST_ITEM_FOCUSED,
72 %pragma(python) code = "
73 def EVT_LIST_BEGIN_DRAG(win, id, func):
74 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func)
76 def EVT_LIST_BEGIN_RDRAG(win, id, func):
77 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func)
79 def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func):
80 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func)
82 def EVT_LIST_END_LABEL_EDIT(win, id, func):
83 win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func)
85 def EVT_LIST_DELETE_ITEM(win, id, func):
86 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func)
88 def EVT_LIST_DELETE_ALL_ITEMS(win, id, func):
89 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func)
91 def EVT_LIST_GET_INFO(win, id, func):
92 win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func)
94 def EVT_LIST_SET_INFO(win, id, func):
95 win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func)
97 def EVT_LIST_ITEM_SELECTED(win, id, func):
98 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func)
100 def EVT_LIST_ITEM_DESELECTED(win, id, func):
101 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func)
103 def EVT_LIST_KEY_DOWN(win, id, func):
104 win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func)
106 def EVT_LIST_INSERT_ITEM(win, id, func):
107 win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func)
109 def EVT_LIST_COL_CLICK(win, id, func):
110 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
112 def EVT_LIST_COL_RIGHT_CLICK(win, id, func):
113 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, func)
115 def EVT_LIST_COL_BEGIN_DRAG(win, id, func):
116 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, func)
118 def EVT_LIST_COL_DRAGGING(win, id, func):
119 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_DRAGGING, func)
121 def EVT_LIST_COL_END_DRAG(win, id, func):
122 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_END_DRAG, func)
124 def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
125 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
127 def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
128 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
130 def EVT_LIST_ITEM_ACTIVATED(win, id, func):
131 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func)
133 def EVT_LIST_CACHE_HINT(win, id, func):
134 win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func)
136 def EVT_LIST_ITEM_FOCUSED(win, id, func):
137 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_FOCUSED, func)
160 wxLC_SORT_DESCENDING,
181 wxLIST_STATE_DONTCARE,
182 wxLIST_STATE_DROPHILITED,
183 wxLIST_STATE_FOCUSED,
184 wxLIST_STATE_SELECTED,
188 wxLIST_HITTEST_ABOVE,
189 wxLIST_HITTEST_BELOW,
190 wxLIST_HITTEST_NOWHERE,
191 wxLIST_HITTEST_ONITEMICON,
192 wxLIST_HITTEST_ONITEMLABEL,
193 wxLIST_HITTEST_ONITEMRIGHT,
194 wxLIST_HITTEST_ONITEMSTATEICON,
195 wxLIST_HITTEST_TOLEFT,
196 wxLIST_HITTEST_TORIGHT,
197 wxLIST_HITTEST_ONITEM,
199 // Flags for GetNextItem
207 wxLIST_ALIGN_DEFAULT,
210 wxLIST_ALIGN_SNAP_TO_GRID,
212 // Autosize values for SetColumnWidth
213 wxLIST_AUTOSIZE = -1,
214 wxLIST_AUTOSIZE_USEHEADER = -2,
216 // Flag values for GetItemRect
221 // Flag values for FindItem (MSW only)
232 enum wxListColumnFormat
236 wxLIST_FORMAT_CENTRE,
237 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
248 wxListItemAttr(const wxColour& colText = wxNullColour,
249 const wxColour& colBack = wxNullColour,
250 const wxFont& font = wxNullFont);
254 void SetTextColour(const wxColour& colText);
255 void SetBackgroundColour(const wxColour& colBack);
256 void SetFont(const wxFont& font);
259 bool HasTextColour();
260 bool HasBackgroundColour();
263 wxColour GetTextColour();
264 wxColour GetBackgroundColour();
269 class wxListItem : public wxObject {
276 void ClearAttributes();
279 void SetMask(long mask);
281 void SetColumn(int col);
282 void SetState(long state);
283 void SetStateMask(long stateMask);
284 void SetText(const wxString& text);
285 void SetImage(int image);
286 void SetData(long data);
288 void SetWidth(int width);
289 void SetAlign(wxListColumnFormat align);
291 void SetTextColour(const wxColour& colText);
292 void SetBackgroundColour(const wxColour& colBack);
293 void SetFont(const wxFont& font);
300 const wxString& GetText();
305 wxListColumnFormat GetAlign();
307 wxListItemAttr *GetAttributes();
308 bool HasAttributes();
310 wxColour GetTextColour() const;
311 wxColour GetBackgroundColour() const;
312 wxFont GetFont() const;
314 // these members are public for compatibility
315 long m_mask; // Indicates what fields are valid
316 long m_itemId; // The zero-based item position
317 int m_col; // Zero-based column, if in report mode
318 long m_state; // The state of the item
319 long m_stateMask;// Which flags of m_state are valid (uses same flags)
320 wxString m_text; // The label/header text
321 int m_image; // The zero-based index into an image list
322 long m_data; // App-defined data
325 int m_format; // left, right, centre
326 int m_width; // width of column
331 class wxListEvent: public wxNotifyEvent {
333 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
346 const wxString& GetLabel();
347 const wxString& GetText();
351 const wxListItem& GetItem();
358 %{ // C++ Version of a Python aware class
359 class wxPyListCtrl : public wxListCtrl {
360 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
362 wxPyListCtrl() : wxListCtrl() {}
363 wxPyListCtrl(wxWindow* parent, wxWindowID id,
367 const wxValidator& validator,
369 wxListCtrl(parent, id, pos, size, style, validator, name) {}
371 bool Create(wxWindow* parent, wxWindowID id,
375 const wxValidator& validator,
377 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
380 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
381 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
382 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
387 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
389 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
390 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
391 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
396 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
398 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
399 const wxPoint& pos = wxDefaultPosition,
400 const wxSize& size = wxDefaultSize,
401 long style = wxLC_ICON,
402 const wxValidator& validator = wxDefaultValidator,
403 char* name = "listCtrl");
404 %name(wxPreListCtrl)wxPyListCtrl();
406 bool Create(wxWindow* parent, wxWindowID id = -1,
407 const wxPoint& pos = wxDefaultPosition,
408 const wxSize& size = wxDefaultSize,
409 long style = wxLC_ICON,
410 const wxValidator& validator = wxDefaultValidator,
411 char* name = "listCtrl");
413 void _setCallbackInfo(PyObject* self, PyObject* _class);
414 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxListCtrl)"
416 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
417 %pragma(python) addtomethod = "wxPreListCtrl:val._setOORInfo(val)"
419 // Set the control colours
420 bool SetForegroundColour(const wxColour& col);
421 bool SetBackgroundColour(const wxColour& col);
423 // Gets information about this column
424 // bool GetColumn(int col, wxListItem& item) const;
426 %new wxListItem* GetColumn(int col) {
428 if (self->GetColumn(col, item))
429 return new wxListItem(item);
433 } // The OOR typemaps don't know what to do with the %new, so fix it up.
434 %pragma(python) addtoclass = "
435 def GetItem(self, *_args, **_kwargs):
436 val = apply(controls2c.wxListCtrl_GetColumn,(self,) + _args, _kwargs)
437 if val is not None: val.thisown = 1
441 // Sets information about this column
442 bool SetColumn(int col, wxListItem& item) ;
444 // Gets the column width
445 int GetColumnWidth(int col) const;
447 // Sets the column width
448 bool SetColumnWidth(int col, int width) ;
450 // Gets the number of items that can fit vertically in the
451 // visible area of the list control (list or report view)
452 // or the total number of items in the list control (icon
453 // or small icon view)
454 int GetCountPerPage() const;
457 // Gets the edit control for editing labels.
458 wxTextCtrl* GetEditControl() const;
461 //bool GetItem(wxListItem& info) const ;
463 // Gets information about the item
464 %new wxListItem* GetItem(long itemId, int col=0) {
465 wxListItem* info = new wxListItem;
466 info->m_itemId = itemId;
468 info->m_mask = 0xFFFF;
469 self->GetItem(*info);
472 } // The OOR typemaps don't know what to do with the %new, so fix it up.
473 %pragma(python) addtoclass = "
474 def GetItem(self, *_args, **_kwargs):
475 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
481 // Sets information about the item
482 bool SetItem(wxListItem& info) ;
484 // Sets a string field at a particular column
485 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
487 // Gets the item state
488 int GetItemState(long item, long stateMask) const ;
490 // Sets the item state
491 bool SetItemState(long item, long state, long stateMask) ;
493 // Sets the item image
494 bool SetItemImage(long item, int image, int selImage) ;
496 // Gets the item text
497 wxString GetItemText(long item) const ;
499 // Sets the item text
500 void SetItemText(long item, const wxString& str) ;
502 // Gets the item data
503 long GetItemData(long item) const ;
505 // Sets the item data
506 bool SetItemData(long item, long data) ;
509 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
510 //bool GetItemPosition(long item, wxPoint& pos) const ;
512 // Gets the item position
514 %new wxPoint* GetItemPosition(long item) {
515 wxPoint* pos = new wxPoint;
516 self->GetItemPosition(item, *pos);
519 // Gets the item rectangle
520 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
521 wxRect* rect= new wxRect;
522 self->GetItemRect(item, *rect, code);
528 // Sets the item position
529 bool SetItemPosition(long item, const wxPoint& pos) ;
531 // Gets the number of items in the list control
532 int GetItemCount() const;
534 // Gets the number of columns in the list control
535 int GetColumnCount() const;
537 // Retrieves the spacing between icons in pixels.
538 // If small is TRUE, gets the spacing for the small icon
539 // view, otherwise the large icon view.
540 int GetItemSpacing(bool isSmall) const;
542 // Gets the number of selected items in the list control
543 int GetSelectedItemCount() const;
545 // Gets the text colour of the listview
546 wxColour GetTextColour() const;
548 // Sets the text colour of the listview
549 void SetTextColour(const wxColour& col);
551 // Gets the index of the topmost visible item when in
552 // list or report view
553 long GetTopItem() const ;
555 // Add or remove a single window style
556 void SetSingleStyle(long style, bool add = TRUE) ;
558 // Set the whole window style
559 void SetWindowStyleFlag(long style) ;
561 // Searches for an item, starting from 'item'.
562 // item can be -1 to find the first item that matches the
564 // Returns the item or -1 if unsuccessful.
565 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
567 // Gets one of the three image lists
568 wxImageList *GetImageList(int which) const ;
570 // Sets the image list
571 void SetImageList(wxImageList *imageList, int which) ;
572 void AssignImageList(wxImageList *imageList, int which) ;
573 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
575 // returns true if it is a virtual list control
576 bool IsVirtual() const;
578 // refresh items selectively (only useful for virtual list controls)
579 void RefreshItem(long item);
580 void RefreshItems(long itemFrom, long itemTo);
582 // Arranges the items
583 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
586 bool DeleteItem(long item);
589 bool DeleteAllItems() ;
592 bool DeleteColumn(int col);
594 // Deletes all columns
595 bool DeleteAllColumns();
597 // Clears items, and columns if there are any.
602 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
604 // End label editing, optionally cancelling the edit
605 bool EndEditLabel(bool cancel);
608 // Ensures this item is visible
609 bool EnsureVisible(long item) ;
611 // Find an item whose label matches this string, starting from the item after 'start'
612 // or the beginning if 'start' is -1.
613 long FindItem(long start, const wxString& str, bool partial = FALSE);
615 // Find an item whose data matches this data, starting from the item after 'start'
616 // or the beginning if 'start' is -1.
617 %name(FindItemData)long FindItem(long start, long data);
619 // Find an item nearest this position in the specified direction, starting from
620 // the item after 'start' or the beginning if 'start' is -1.
621 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
623 // Determines which item (if any) is at the specified point,
624 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
625 long HitTest(const wxPoint& point, int& OUTPUT);
627 // Inserts an item, returning the index of the new item if successful,
629 long InsertItem(wxListItem& info);
631 // Insert a string item
632 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
634 // Insert an image item
635 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
637 // Insert an image/string item
638 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
640 // For list view mode (only), inserts a column.
641 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
643 long InsertColumn(long col,
644 const wxString& heading,
645 int format = wxLIST_FORMAT_LEFT,
648 // set the number of items in a virtual list control
649 void SetItemCount(long count);
651 // Scrolls the list control. If in icon, small icon or report view mode,
652 // x specifies the number of pixels to scroll. If in list view mode, x
653 // specifies the number of columns to scroll.
654 // If in icon, small icon or list view mode, y specifies the number of pixels
655 // to scroll. If in report view mode, y specifies the number of lines to scroll.
656 bool ScrollList(int dx, int dy);
658 // bool SortItems(wxListCtrlCompare fn, long data);
661 // func is a function which takes 2 long arguments: item1, item2.
662 // item1 is the long data associated with a first item (NOT the index).
663 // item2 is the long data associated with a second item (NOT the index).
664 // The return value is a negative number if the first item should precede the second
665 // item, a positive number of the second item should precede the first,
666 // or zero if the two items are equivalent.
667 bool SortItems(PyObject* func) {
668 if (!PyCallable_Check(func))
670 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
674 %pragma(python) addtoclass = "
677 def Select(self, idx, on=1):
678 '''[de]select an item'''
679 if on: state = wxLIST_STATE_SELECTED
681 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
683 def Focus(self, idx):
684 '''Focus and show the given item'''
685 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
686 self.EnsureVisible(idx)
688 def GetFocusedItem(self):
689 '''get the currently focused item or -1 if none'''
690 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
692 def IsSelected(self, idx):
693 '''return TRUE if the item is selected'''
694 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
696 def SetColumnImage(self, col, image):
698 item.SetMask(wxLIST_MASK_IMAGE)
700 self.SetColumn(col, item)
702 def ClearColumnImage(self, col):
703 self.SetColumnImage(col, -1)
705 def Append(self, entry):
706 '''Append an item to the list control. The entry parameter should be a
707 sequence with an item for each column'''
709 pos = self.GetItemCount()
710 self.InsertStringItem(pos, str(entry[0]))
711 for i in range(1, len(entry)):
712 self.SetStringItem(pos, i, str(entry[i]))
719 %{ // Python aware sorting function for wxPyListCtrl
720 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
722 PyObject* func = (PyObject*)funcPtr;
723 wxPyBeginBlockThreads();
725 PyObject* args = Py_BuildValue("(ii)", item1, item2);
726 PyObject* result = PyEval_CallObject(func, args);
729 retval = PyInt_AsLong(result);
733 wxPyEndBlockThreads();
739 //----------------------------------------------------------------------
741 class wxListView : public wxPyListCtrl
744 wxListView( wxWindow *parent,
746 const wxPoint& pos = wxDefaultPosition,
747 const wxSize& size = wxDefaultSize,
748 long style = wxLC_REPORT,
749 const wxValidator& validator = wxDefaultValidator,
750 const wxString &name = "listctrl" );
751 %name(wxPreListView)wxListView();
753 bool Create( wxWindow *parent,
755 const wxPoint& pos = wxDefaultPosition,
756 const wxSize& size = wxDefaultSize,
757 long style = wxLC_REPORT,
758 const wxValidator& validator = wxDefaultValidator,
759 const wxString &name = "listctrl" );
761 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
762 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
764 // [de]select an item
765 void Select(long n, bool on = TRUE);
767 // focus and show the given item
768 void Focus(long index);
770 // get the currently focused item or -1 if none
771 long GetFocusedItem() const;
773 // get first and subsequent selected items, return -1 when no more
774 long GetNextSelected(long item) const;
775 long GetFirstSelected() const;
777 // return TRUE if the item is selected
778 bool IsSelected(long index);
780 void SetColumnImage(int col, int image);
781 void ClearColumnImage(int col);
785 //----------------------------------------------------------------------
799 wxTR_FULL_ROW_HIGHLIGHT,
805 wxTR_HAS_VARIABLE_ROW_HEIGHT,
812 wxTreeItemIcon_Normal, // not selected, not expanded
813 wxTreeItemIcon_Selected, // selected, not expanded
814 wxTreeItemIcon_Expanded, // not selected, expanded
815 wxTreeItemIcon_SelectedExpanded, // selected, expanded
820 // constants for HitTest
822 wxTREE_HITTEST_ABOVE,
823 wxTREE_HITTEST_BELOW,
824 wxTREE_HITTEST_NOWHERE,
825 wxTREE_HITTEST_ONITEMBUTTON,
826 wxTREE_HITTEST_ONITEMICON,
827 wxTREE_HITTEST_ONITEMINDENT,
828 wxTREE_HITTEST_ONITEMLABEL,
829 wxTREE_HITTEST_ONITEMRIGHT,
830 wxTREE_HITTEST_ONITEMSTATEICON,
831 wxTREE_HITTEST_TOLEFT,
832 wxTREE_HITTEST_TORIGHT,
833 wxTREE_HITTEST_ONITEMUPPERPART,
834 wxTREE_HITTEST_ONITEMLOWERPART,
835 wxTREE_HITTEST_ONITEM
840 /* Tree control event types */
841 wxEVT_COMMAND_TREE_BEGIN_DRAG,
842 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
843 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
844 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
845 wxEVT_COMMAND_TREE_DELETE_ITEM,
846 wxEVT_COMMAND_TREE_GET_INFO,
847 wxEVT_COMMAND_TREE_SET_INFO,
848 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
849 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
850 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
851 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
852 wxEVT_COMMAND_TREE_SEL_CHANGED,
853 wxEVT_COMMAND_TREE_SEL_CHANGING,
854 wxEVT_COMMAND_TREE_KEY_DOWN,
855 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
856 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
857 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
858 wxEVT_COMMAND_TREE_END_DRAG,
862 %pragma(python) code = "
864 def EVT_TREE_BEGIN_DRAG(win, id, func):
865 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
867 def EVT_TREE_BEGIN_RDRAG(win, id, func):
868 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
870 def EVT_TREE_END_DRAG(win, id, func):
871 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
873 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
874 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
876 def EVT_TREE_END_LABEL_EDIT(win, id, func):
877 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
879 def EVT_TREE_GET_INFO(win, id, func):
880 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
882 def EVT_TREE_SET_INFO(win, id, func):
883 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
885 def EVT_TREE_ITEM_EXPANDED(win, id, func):
886 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
888 def EVT_TREE_ITEM_EXPANDING(win, id, func):
889 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
891 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
892 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
894 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
895 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
897 def EVT_TREE_SEL_CHANGED(win, id, func):
898 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
900 def EVT_TREE_SEL_CHANGING(win, id, func):
901 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
903 def EVT_TREE_KEY_DOWN(win, id, func):
904 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
906 def EVT_TREE_DELETE_ITEM(win, id, func):
907 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
909 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
910 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
912 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
913 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
915 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
916 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
924 //wxTreeItemAttr() { }
925 wxTreeItemAttr(const wxColour& colText = wxNullColour,
926 const wxColour& colBack = wxNullColour,
927 const wxFont& font = wxNullFont);
930 void SetTextColour(const wxColour& colText);
931 void SetBackgroundColour(const wxColour& colBack);
932 void SetFont(const wxFont& font);
935 bool HasTextColour();
936 bool HasBackgroundColour();
939 wxColour GetTextColour();
940 wxColour GetBackgroundColour();
950 %pragma(python) addtoclass = "Ok = IsOk"
953 int __cmp__(wxTreeItemId* other) {
954 if (! other) return -1;
955 return *self != *other;
963 class wxPyTreeItemData : public wxTreeItemData {
965 wxPyTreeItemData(PyObject* obj = NULL) {
972 ~wxPyTreeItemData() {
973 wxPyBeginBlockThreads();
975 wxPyEndBlockThreads();
978 PyObject* GetData() {
983 void SetData(PyObject* obj) {
984 wxPyBeginBlockThreads();
986 wxPyEndBlockThreads();
997 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
999 wxPyTreeItemData(PyObject* obj = NULL);
1001 PyObject* GetData();
1002 void SetData(PyObject* obj);
1004 const wxTreeItemId& GetId();
1005 void SetId(const wxTreeItemId& id);
1010 class wxTreeEvent : public wxNotifyEvent {
1012 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
1014 wxTreeItemId GetItem();
1015 wxTreeItemId GetOldItem();
1017 const wxKeyEvent& GetKeyEvent();
1019 const wxString& GetLabel();
1024 %{ // C++ version of Python aware wxTreeCtrl
1025 class wxPyTreeCtrl : public wxTreeCtrl {
1026 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
1028 wxPyTreeCtrl() : wxTreeCtrl() {}
1029 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1033 const wxValidator& validator,
1035 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1037 bool Create(wxWindow *parent, wxWindowID id,
1041 const wxValidator& validator,
1043 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1047 int OnCompareItems(const wxTreeItemId& item1,
1048 const wxTreeItemId& item2) {
1051 wxPyBeginBlockThreads();
1052 if ((found = m_myInst.findCallback("OnCompareItems")))
1053 rval = m_myInst.callCallback(Py_BuildValue(
1055 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
1056 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
1057 wxPyEndBlockThreads();
1059 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1065 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1069 // These are for the GetFirstChild/GetNextChild methods below
1070 %typemap(python, in) long& INOUT = long* INOUT;
1071 %typemap(python, argout) long& INOUT = long* INOUT;
1074 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1076 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1077 const wxPoint& pos = wxDefaultPosition,
1078 const wxSize& size = wxDefaultSize,
1079 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1080 const wxValidator& validator = wxDefaultValidator,
1081 char* name = "wxTreeCtrl");
1082 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1084 bool Create(wxWindow *parent, wxWindowID id = -1,
1085 const wxPoint& pos = wxDefaultPosition,
1086 const wxSize& size = wxDefaultSize,
1087 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1088 const wxValidator& validator = wxDefaultValidator,
1089 char* name = "wxTreeCtrl");
1091 void _setCallbackInfo(PyObject* self, PyObject* _class);
1092 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)"
1094 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1095 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
1098 unsigned int GetIndent();
1099 void SetIndent(unsigned int indent);
1100 wxImageList *GetImageList();
1101 wxImageList *GetStateImageList();
1102 void SetImageList(wxImageList *imageList);
1103 void SetStateImageList(wxImageList *imageList);
1104 void AssignImageList(wxImageList* imageList);
1105 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1106 void AssignStateImageList(wxImageList* imageList);
1107 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1109 unsigned int GetSpacing();
1110 void SetSpacing(unsigned int spacing);
1112 wxString GetItemText(const wxTreeItemId& item);
1113 int GetItemImage(const wxTreeItemId& item,
1114 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1115 int GetItemSelectedImage(const wxTreeItemId& item);
1117 void SetItemText(const wxTreeItemId& item, const wxString& text);
1118 void SetItemImage(const wxTreeItemId& item, int image,
1119 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1120 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1121 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1124 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1126 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1127 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1129 data = new wxPyTreeItemData();
1130 data->SetId(item); // set the id
1131 self->SetItemData(item, data);
1136 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1137 data->SetId(item); // set the id
1138 self->SetItemData(item, data);
1141 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1142 // automatically creating data classes.
1143 PyObject* GetPyData(const wxTreeItemId& item) {
1144 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1146 data = new wxPyTreeItemData();
1147 data->SetId(item); // set the id
1148 self->SetItemData(item, data);
1150 return data->GetData();
1153 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1154 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1156 data = new wxPyTreeItemData(obj);
1157 data->SetId(item); // set the id
1158 self->SetItemData(item, data);
1165 bool IsVisible(const wxTreeItemId& item);
1166 bool ItemHasChildren(const wxTreeItemId& item);
1167 bool IsExpanded(const wxTreeItemId& item);
1168 bool IsSelected(const wxTreeItemId& item);
1170 wxTreeItemId GetRootItem();
1171 wxTreeItemId GetSelection();
1172 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1173 //size_t GetSelections(wxArrayTreeItemIds& selection);
1175 PyObject* GetSelections() {
1176 wxPyBeginBlockThreads();
1177 PyObject* rval = PyList_New(0);
1178 wxArrayTreeItemIds array;
1180 num = self->GetSelections(array);
1181 for (x=0; x < num; x++) {
1182 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1183 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1184 PyList_Append(rval, item);
1186 wxPyEndBlockThreads();
1193 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1195 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
1196 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1197 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1198 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1199 wxTreeItemId GetFirstVisibleItem();
1200 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1201 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1202 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1206 wxTreeItemId AddRoot(const wxString& text,
1207 int image = -1, int selectedImage = -1,
1208 wxPyTreeItemData *data = NULL);
1209 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1210 const wxString& text,
1211 int image = -1, int selectedImage = -1,
1212 wxPyTreeItemData *data = NULL);
1213 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1214 const wxTreeItemId& idPrevious,
1215 const wxString& text,
1216 int image = -1, int selectedImage = -1,
1217 wxPyTreeItemData *data = NULL);
1218 %name(InsertItemBefore)
1219 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1221 const wxString& text,
1222 int image = -1, int selectedImage = -1,
1223 wxPyTreeItemData *data = NULL);
1224 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1225 const wxString& text,
1226 int image = -1, int selectedImage = -1,
1227 wxPyTreeItemData *data = NULL);
1229 void Delete(const wxTreeItemId& item);
1230 void DeleteChildren(const wxTreeItemId& item);
1231 void DeleteAllItems();
1233 void Expand(const wxTreeItemId& item);
1234 void Collapse(const wxTreeItemId& item);
1235 void CollapseAndReset(const wxTreeItemId& item);
1236 void Toggle(const wxTreeItemId& item);
1240 void SelectItem(const wxTreeItemId& item);
1241 void EnsureVisible(const wxTreeItemId& item);
1242 void ScrollTo(const wxTreeItemId& item);
1244 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1245 wxTextCtrl* GetEditControl();
1246 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1248 void EditLabel(const wxTreeItemId& item);
1251 void SortChildren(const wxTreeItemId& item);
1253 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1254 bool IsBold(const wxTreeItemId& item) const;
1255 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1259 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1260 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1261 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1264 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1267 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1269 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1271 if (self->GetBoundingRect(item, rect, textOnly)) {
1272 wxPyBeginBlockThreads();
1273 wxRect* r = new wxRect(rect);
1274 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1275 wxPyEndBlockThreads();
1286 %pragma(python) addtoclass = "
1287 # Redefine some methods that SWIG gets a bit confused on...
1288 def GetFirstChild(self, *_args, **_kwargs):
1289 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1290 val1 = wxTreeItemIdPtr(val1)
1293 def GetNextChild(self, *_args, **_kwargs):
1294 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1295 val1 = wxTreeItemIdPtr(val1)
1298 def HitTest(self, *_args, **_kwargs):
1299 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1300 val1 = wxTreeItemIdPtr(val1)
1308 //----------------------------------------------------------------------
1313 wxDIRCTRL_SELECT_FIRST,
1314 wxDIRCTRL_SHOW_FILTERS,
1315 wxDIRCTRL_3D_INTERNAL,
1319 class wxDirItemData : public wxObject // wxTreeItemData
1322 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
1323 // ~wxDirItemDataEx();
1324 void SetNewDirName( wxString path );
1325 wxString m_path, m_name;
1332 class wxGenericDirCtrl: public wxControl
1335 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
1336 const char* dir = wxDirDialogDefaultFolderStr,
1337 const wxPoint& pos = wxDefaultPosition,
1338 const wxSize& size = wxDefaultSize,
1339 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1340 const char* filter = wxEmptyString,
1341 int defaultFilter = 0,
1342 const char* name = "dirCtrl" );
1343 %name(wxPreGenericDirCtrl)wxGenericDirCtrl();
1345 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1346 %pragma(python) addtomethod = "wxPreGenericDirCtrl:val._setOORInfo(val)"
1348 bool Create(wxWindow *parent, const wxWindowID id = -1,
1349 const char* dir = wxDirDialogDefaultFolderStr,
1350 const wxPoint& pos = wxDefaultPosition,
1351 const wxSize& size = wxDefaultSize,
1352 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1353 const char* filter = wxEmptyString,
1354 int defaultFilter = 0,
1355 const char* name = "dirCtrl" );
1358 // Try to expand as much of the given path as possible.
1359 bool ExpandPath(const wxString& path);
1363 inline wxString GetDefaultPath() const;
1364 void SetDefaultPath(const wxString& path);
1366 // Get dir or filename
1367 wxString GetPath() const ;
1369 // Get selected filename path only (else empty string).
1370 // I.e. don't count a directory as a selection
1371 wxString GetFilePath() const ;
1372 void SetPath(const wxString& path) ;
1374 void ShowHidden( bool show );
1375 bool GetShowHidden();
1377 wxString GetFilter() const;
1378 void SetFilter(const wxString& filter);
1380 int GetFilterIndex() const;
1381 void SetFilterIndex(int n) ;
1383 wxTreeItemId GetRootId();
1385 wxTreeCtrl* GetTreeCtrl() const;
1386 wxDirFilterListCtrl* GetFilterListCtrl() const;
1389 // void SetupSections();
1390 // // Parse the filter into an array of filters and an array of descriptions
1391 // int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
1392 // // Find the child that matches the first part of 'path'.
1393 // // E.g. if a child path is "/usr" and 'path' is "/usr/include"
1394 // // then the child for /usr is returned.
1395 // // If the path string has been used (we're at the leaf), done is set to TRUE
1396 // wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
1400 class wxDirFilterListCtrl: public wxChoice
1403 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1404 const wxPoint& pos = wxDefaultPosition,
1405 const wxSize& size = wxDefaultSize,
1407 %name(wxPreDirFilterListCtrl)wxDirFilterListCtrl();
1409 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1410 %pragma(python) addtomethod = "wxPreDirFilterListCtrl:val._setOORInfo(val)"
1412 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1413 const wxPoint& pos = wxDefaultPosition,
1414 const wxSize& size = wxDefaultSize,
1418 void FillFilterList(const wxString& filter, int defaultFilter);
1422 //----------------------------------------------------------------------
1423 //----------------------------------------------------------------------
1426 // Map renamed classes back to their common name for OOR
1427 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1428 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1429 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1432 //----------------------------------------------------------------------