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>
25 //----------------------------------------------------------------------
28 %include my_typemaps.i
30 // Import some definitions of other classes, etc.
38 %pragma(python) code = "import wx"
41 //----------------------------------------------------------------------
42 //----------------------------------------------------------------------
45 /* List control event types */
46 wxEVT_COMMAND_LIST_BEGIN_DRAG,
47 wxEVT_COMMAND_LIST_BEGIN_RDRAG,
48 wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT,
49 wxEVT_COMMAND_LIST_END_LABEL_EDIT,
50 wxEVT_COMMAND_LIST_DELETE_ITEM,
51 wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS,
52 wxEVT_COMMAND_LIST_GET_INFO,
53 wxEVT_COMMAND_LIST_SET_INFO,
54 wxEVT_COMMAND_LIST_ITEM_SELECTED,
55 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
56 wxEVT_COMMAND_LIST_KEY_DOWN,
57 wxEVT_COMMAND_LIST_INSERT_ITEM,
58 wxEVT_COMMAND_LIST_COL_CLICK,
59 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
60 wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK,
61 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
62 wxEVT_COMMAND_LIST_CACHE_HINT,
66 %pragma(python) code = "
67 def EVT_LIST_BEGIN_DRAG(win, id, func):
68 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func)
70 def EVT_LIST_BEGIN_RDRAG(win, id, func):
71 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func)
73 def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func):
74 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func)
76 def EVT_LIST_END_LABEL_EDIT(win, id, func):
77 win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func)
79 def EVT_LIST_DELETE_ITEM(win, id, func):
80 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func)
82 def EVT_LIST_DELETE_ALL_ITEMS(win, id, func):
83 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func)
85 def EVT_LIST_GET_INFO(win, id, func):
86 win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func)
88 def EVT_LIST_SET_INFO(win, id, func):
89 win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func)
91 def EVT_LIST_ITEM_SELECTED(win, id, func):
92 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func)
94 def EVT_LIST_ITEM_DESELECTED(win, id, func):
95 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func)
97 def EVT_LIST_KEY_DOWN(win, id, func):
98 win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func)
100 def EVT_LIST_INSERT_ITEM(win, id, func):
101 win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func)
103 def EVT_LIST_COL_CLICK(win, id, func):
104 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
106 def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
107 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
109 def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
110 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
112 def EVT_LIST_ITEM_ACTIVATED(win, id, func):
113 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func)
115 def EVT_LIST_CACHE_HINT(win, id, func):
116 win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func)
139 wxLC_SORT_DESCENDING,
159 wxLIST_STATE_DONTCARE,
160 wxLIST_STATE_DROPHILITED,
161 wxLIST_STATE_FOCUSED,
162 wxLIST_STATE_SELECTED,
166 wxLIST_HITTEST_ABOVE,
167 wxLIST_HITTEST_BELOW,
168 wxLIST_HITTEST_NOWHERE,
169 wxLIST_HITTEST_ONITEMICON,
170 wxLIST_HITTEST_ONITEMLABEL,
171 wxLIST_HITTEST_ONITEMRIGHT,
172 wxLIST_HITTEST_ONITEMSTATEICON,
173 wxLIST_HITTEST_TOLEFT,
174 wxLIST_HITTEST_TORIGHT,
175 wxLIST_HITTEST_ONITEM,
177 // Flags for GetNextItem
185 wxLIST_ALIGN_DEFAULT,
188 wxLIST_ALIGN_SNAP_TO_GRID,
190 // Autosize values for SetColumnWidth
191 wxLIST_AUTOSIZE = -1,
192 wxLIST_AUTOSIZE_USEHEADER = -2,
194 // Flag values for GetItemRect
199 // Flag values for FindItem (MSW only)
210 enum wxListColumnFormat
214 wxLIST_FORMAT_CENTRE,
215 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
226 wxListItemAttr(const wxColour& colText = wxNullColour,
227 const wxColour& colBack = wxNullColour,
228 const wxFont& font = wxNullFont);
232 void SetTextColour(const wxColour& colText);
233 void SetBackgroundColour(const wxColour& colBack);
234 void SetFont(const wxFont& font);
237 bool HasTextColour();
238 bool HasBackgroundColour();
241 const wxColour& GetTextColour();
242 const wxColour& GetBackgroundColour();
243 const wxFont& GetFont();
247 class wxListItem : public wxObject {
254 void ClearAttributes();
257 void SetMask(long mask);
259 void SetColumn(int col);
260 void SetState(long state);
261 void SetStateMask(long stateMask);
262 void SetText(const wxString& text);
263 void SetImage(int image);
264 void SetData(long data);
266 void SetWidth(int width);
267 void SetAlign(wxListColumnFormat align);
269 void SetTextColour(const wxColour& colText);
270 void SetBackgroundColour(const wxColour& colBack);
271 void SetFont(const wxFont& font);
278 const wxString& GetText();
283 wxListColumnFormat GetAlign();
285 wxListItemAttr *GetAttributes();
286 bool HasAttributes();
288 wxColour GetTextColour() const;
289 wxColour GetBackgroundColour() const;
290 wxFont GetFont() const;
292 // these members are public for compatibility
293 long m_mask; // Indicates what fields are valid
294 long m_itemId; // The zero-based item position
295 int m_col; // Zero-based column, if in report mode
296 long m_state; // The state of the item
297 long m_stateMask;// Which flags of m_state are valid (uses same flags)
298 wxString m_text; // The label/header text
299 int m_image; // The zero-based index into an image list
300 long m_data; // App-defined data
303 int m_format; // left, right, centre
304 int m_width; // width of column
309 class wxListEvent: public wxNotifyEvent {
326 const wxString& GetLabel();
327 const wxString& GetText();
331 const wxListItem& GetItem();
335 %{ // C++ Version of a Python aware class
336 class wxPyListCtrl : public wxListCtrl {
337 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
339 wxPyListCtrl() : wxListCtrl() {}
340 wxPyListCtrl(wxWindow* parent, wxWindowID id,
344 const wxValidator& validator,
346 wxListCtrl(parent, id, pos, size, style, validator, name) {}
348 bool Create(wxWindow* parent, wxWindowID id,
352 const wxValidator& validator,
354 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
357 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
358 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
359 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
364 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
366 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
367 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
368 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
372 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
374 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
375 const wxPoint& pos = wxDefaultPosition,
376 const wxSize& size = wxDefaultSize,
377 long style = wxLC_ICON,
378 const wxValidator& validator = wxDefaultValidator,
379 char* name = "listCtrl");
380 %name(wxPreListCtrl)wxPyListCtrl();
382 bool Create(wxWindow* parent, wxWindowID id = -1,
383 const wxPoint& pos = wxDefaultPosition,
384 const wxSize& size = wxDefaultSize,
385 long style = wxLC_ICON,
386 const wxValidator& validator = wxDefaultValidator,
387 char* name = "listCtrl");
389 void _setSelf(PyObject* self, PyObject* _class);
390 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxListCtrl)"
393 // Set the control colours
394 bool SetForegroundColour(const wxColour& col);
395 bool SetBackgroundColour(const wxColour& col);
397 // Gets information about this column
398 bool GetColumn(int col, wxListItem& item) const;
400 // Sets information about this column
401 bool SetColumn(int col, wxListItem& item) ;
403 // Gets the column width
404 int GetColumnWidth(int col) const;
406 // Sets the column width
407 bool SetColumnWidth(int col, int width) ;
409 // Gets the number of items that can fit vertically in the
410 // visible area of the list control (list or report view)
411 // or the total number of items in the list control (icon
412 // or small icon view)
413 int GetCountPerPage() const;
416 // Gets the edit control for editing labels.
417 wxTextCtrl* GetEditControl() const;
420 //bool GetItem(wxListItem& info) const ;
422 // Gets information about the item
423 %new wxListItem* GetItem(long itemId, int col=0) {
424 wxListItem* info = new wxListItem;
425 info->m_itemId = itemId;
427 info->m_mask = 0xFFFF;
428 self->GetItem(*info);
431 } // The OOR typemaps don't know what to do with the %new, so fix it up.
432 %pragma(python) addtoclass = "
433 def GetItem(self, *_args, **_kwargs):
434 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
440 // Sets information about the item
441 bool SetItem(wxListItem& info) ;
443 // Sets a string field at a particular column
444 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
446 // Gets the item state
447 int GetItemState(long item, long stateMask) const ;
449 // Sets the item state
450 bool SetItemState(long item, long state, long stateMask) ;
452 // Sets the item image
453 bool SetItemImage(long item, int image, int selImage) ;
455 // Gets the item text
456 wxString GetItemText(long item) const ;
458 // Sets the item text
459 void SetItemText(long item, const wxString& str) ;
461 // Gets the item data
462 long GetItemData(long item) const ;
464 // Sets the item data
465 bool SetItemData(long item, long data) ;
468 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
469 //bool GetItemPosition(long item, wxPoint& pos) const ;
471 // Gets the item position
473 %new wxPoint* GetItemPosition(long item) {
474 wxPoint* pos = new wxPoint;
475 self->GetItemPosition(item, *pos);
478 // Gets the item rectangle
479 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
480 wxRect* rect= new wxRect;
481 self->GetItemRect(item, *rect, code);
487 // Sets the item position
488 bool SetItemPosition(long item, const wxPoint& pos) ;
490 // Gets the number of items in the list control
491 int GetItemCount() const;
493 // Gets the number of columns in the list control
494 int GetColumnCount() const { return m_colCount; }
496 // Retrieves the spacing between icons in pixels.
497 // If small is TRUE, gets the spacing for the small icon
498 // view, otherwise the large icon view.
499 int GetItemSpacing(bool isSmall) const;
501 // Gets the number of selected items in the list control
502 int GetSelectedItemCount() const;
504 // Gets the text colour of the listview
505 wxColour GetTextColour() const;
507 // Sets the text colour of the listview
508 void SetTextColour(const wxColour& col);
510 // Gets the index of the topmost visible item when in
511 // list or report view
512 long GetTopItem() const ;
514 // Add or remove a single window style
515 void SetSingleStyle(long style, bool add = TRUE) ;
517 // Set the whole window style
518 void SetWindowStyleFlag(long style) ;
520 // Searches for an item, starting from 'item'.
521 // item can be -1 to find the first item that matches the
523 // Returns the item or -1 if unsuccessful.
524 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
526 // Gets one of the three image lists
527 wxImageList *GetImageList(int which) const ;
529 // Sets the image list
530 void SetImageList(wxImageList *imageList, int which) ;
531 void AssignImageList(wxImageList *imageList, int which) ;
532 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
534 // returns true if it is a virtual list control
535 bool IsVirtual() const;
537 // refresh items selectively (only useful for virtual list controls)
538 void RefreshItem(long item);
539 void RefreshItems(long itemFrom, long itemTo);
544 // Arranges the items
545 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
548 bool DeleteItem(long item);
551 bool DeleteAllItems() ;
554 bool DeleteColumn(int col);
556 // Deletes all columns
557 bool DeleteAllColumns();
559 // Clears items, and columns if there are any.
564 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
566 // End label editing, optionally cancelling the edit
567 bool EndEditLabel(bool cancel);
570 // Ensures this item is visible
571 bool EnsureVisible(long item) ;
573 // Find an item whose label matches this string, starting from the item after 'start'
574 // or the beginning if 'start' is -1.
575 long FindItem(long start, const wxString& str, bool partial = FALSE);
577 // Find an item whose data matches this data, starting from the item after 'start'
578 // or the beginning if 'start' is -1.
579 %name(FindItemData)long FindItem(long start, long data);
581 // Find an item nearest this position in the specified direction, starting from
582 // the item after 'start' or the beginning if 'start' is -1.
583 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
585 // Determines which item (if any) is at the specified point,
586 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
587 long HitTest(const wxPoint& point, int& OUTPUT);
589 // Inserts an item, returning the index of the new item if successful,
591 long InsertItem(wxListItem& info);
593 // Insert a string item
594 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
596 // Insert an image item
597 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
599 // Insert an image/string item
600 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
602 // For list view mode (only), inserts a column.
603 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
605 long InsertColumn(long col,
606 const wxString& heading,
607 int format = wxLIST_FORMAT_LEFT,
610 // set the number of items in a virtual list control
611 void SetItemCount(long count);
613 // Scrolls the list control. If in icon, small icon or report view mode,
614 // x specifies the number of pixels to scroll. If in list view mode, x
615 // specifies the number of columns to scroll.
616 // If in icon, small icon or list view mode, y specifies the number of pixels
617 // to scroll. If in report view mode, y specifies the number of lines to scroll.
618 bool ScrollList(int dx, int dy);
620 // bool SortItems(wxListCtrlCompare fn, long data);
623 // func is a function which takes 2 long arguments: item1, item2.
624 // item1 is the long data associated with a first item (NOT the index).
625 // item2 is the long data associated with a second item (NOT the index).
626 // The return value is a negative number if the first item should precede the second
627 // item, a positive number of the second item should precede the first,
628 // or zero if the two items are equivalent.
629 bool SortItems(PyObject* func) {
630 if (!PyCallable_Check(func))
632 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
641 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
643 PyObject* func = (PyObject*)funcPtr;
644 bool doSave = wxPyRestoreThread();
646 PyObject* args = Py_BuildValue("(ii)", item1, item2);
647 PyObject* result = PyEval_CallObject(func, args);
650 retval = PyInt_AsLong(result);
654 wxPySaveThread(doSave);
660 //----------------------------------------------------------------------
678 wxTR_HAS_VARIABLE_ROW_HEIGHT,
685 wxTreeItemIcon_Normal, // not selected, not expanded
686 wxTreeItemIcon_Selected, // selected, not expanded
687 wxTreeItemIcon_Expanded, // not selected, expanded
688 wxTreeItemIcon_SelectedExpanded, // selected, expanded
693 // constants for HitTest
695 wxTREE_HITTEST_ABOVE,
696 wxTREE_HITTEST_BELOW,
697 wxTREE_HITTEST_NOWHERE,
698 wxTREE_HITTEST_ONITEMBUTTON,
699 wxTREE_HITTEST_ONITEMICON,
700 wxTREE_HITTEST_ONITEMINDENT,
701 wxTREE_HITTEST_ONITEMLABEL,
702 wxTREE_HITTEST_ONITEMRIGHT,
703 wxTREE_HITTEST_ONITEMSTATEICON,
704 wxTREE_HITTEST_TOLEFT,
705 wxTREE_HITTEST_TORIGHT,
706 wxTREE_HITTEST_ONITEMUPPERPART,
707 wxTREE_HITTEST_ONITEMLOWERPART,
708 wxTREE_HITTEST_ONITEM
713 /* Tree control event types */
714 wxEVT_COMMAND_TREE_BEGIN_DRAG,
715 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
716 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
717 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
718 wxEVT_COMMAND_TREE_DELETE_ITEM,
719 wxEVT_COMMAND_TREE_GET_INFO,
720 wxEVT_COMMAND_TREE_SET_INFO,
721 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
722 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
723 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
724 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
725 wxEVT_COMMAND_TREE_SEL_CHANGED,
726 wxEVT_COMMAND_TREE_SEL_CHANGING,
727 wxEVT_COMMAND_TREE_KEY_DOWN,
728 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
729 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
730 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
731 wxEVT_COMMAND_TREE_END_DRAG,
735 %pragma(python) code = "
737 def EVT_TREE_BEGIN_DRAG(win, id, func):
738 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
740 def EVT_TREE_BEGIN_RDRAG(win, id, func):
741 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
743 def EVT_TREE_END_DRAG(win, id, func):
744 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
746 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
747 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
749 def EVT_TREE_END_LABEL_EDIT(win, id, func):
750 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
752 def EVT_TREE_GET_INFO(win, id, func):
753 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
755 def EVT_TREE_SET_INFO(win, id, func):
756 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
758 def EVT_TREE_ITEM_EXPANDED(win, id, func):
759 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
761 def EVT_TREE_ITEM_EXPANDING(win, id, func):
762 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
764 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
765 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
767 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
768 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
770 def EVT_TREE_SEL_CHANGED(win, id, func):
771 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
773 def EVT_TREE_SEL_CHANGING(win, id, func):
774 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
776 def EVT_TREE_KEY_DOWN(win, id, func):
777 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
779 def EVT_TREE_DELETE_ITEM(win, id, func):
780 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
782 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
783 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
785 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
786 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
788 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
789 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
797 //wxTreeItemAttr() { }
798 wxTreeItemAttr(const wxColour& colText = wxNullColour,
799 const wxColour& colBack = wxNullColour,
800 const wxFont& font = wxNullFont);
803 void SetTextColour(const wxColour& colText);
804 void SetBackgroundColour(const wxColour& colBack);
805 void SetFont(const wxFont& font);
808 bool HasTextColour();
809 bool HasBackgroundColour();
812 const wxColour& GetTextColour();
813 const wxColour& GetBackgroundColour();
814 const wxFont& GetFont();
825 int __cmp__(wxTreeItemId* other) {
826 if (! other) return -1;
827 return *self != *other;
835 class wxPyTreeItemData : public wxTreeItemData {
837 wxPyTreeItemData(PyObject* obj = NULL) {
844 ~wxPyTreeItemData() {
845 bool doSave = wxPyRestoreThread();
847 wxPySaveThread(doSave);
850 PyObject* GetData() {
855 void SetData(PyObject* obj) {
856 bool doSave = wxPyRestoreThread();
858 wxPySaveThread(doSave);
869 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
871 wxPyTreeItemData(PyObject* obj = NULL);
874 void SetData(PyObject* obj);
876 const wxTreeItemId& GetId();
877 void SetId(const wxTreeItemId& id);
882 class wxTreeEvent : public wxNotifyEvent {
884 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
886 wxTreeItemId GetItem();
887 wxTreeItemId GetOldItem();
890 const wxString& GetLabel();
895 %{ // C++ version of Python aware wxTreeCtrl
896 class wxPyTreeCtrl : public wxTreeCtrl {
897 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
899 wxPyTreeCtrl() : wxTreeCtrl() {}
900 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
904 const wxValidator& validator,
906 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
908 bool Create(wxWindow *parent, wxWindowID id,
912 const wxValidator& validator,
914 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
918 int OnCompareItems(const wxTreeItemId& item1,
919 const wxTreeItemId& item2) {
921 bool doSave = wxPyRestoreThread();
922 if (m_myInst.findCallback("OnCompareItems"))
923 rval = m_myInst.callCallback(Py_BuildValue(
925 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
926 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
928 rval = wxTreeCtrl::OnCompareItems(item1, item2);
929 wxPySaveThread(doSave);
935 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
939 // These are for the GetFirstChild/GetNextChild methods below
940 %typemap(python, in) long& INOUT = long* INOUT;
941 %typemap(python, argout) long& INOUT = long* INOUT;
944 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
946 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
947 const wxPoint& pos = wxDefaultPosition,
948 const wxSize& size = wxDefaultSize,
949 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
950 const wxValidator& validator = wxDefaultValidator,
951 char* name = "wxTreeCtrl");
952 %name(wxPreTreeCtrl)wxPyTreeCtrl();
954 bool Create(wxWindow *parent, wxWindowID id = -1,
955 const wxPoint& pos = wxDefaultPosition,
956 const wxSize& size = wxDefaultSize,
957 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
958 const wxValidator& validator = wxDefaultValidator,
959 char* name = "wxTreeCtrl");
961 void _setSelf(PyObject* self, PyObject* _class);
962 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTreeCtrl)"
965 unsigned int GetIndent();
966 void SetIndent(unsigned int indent);
967 wxImageList *GetImageList();
968 wxImageList *GetStateImageList();
969 void SetImageList(wxImageList *imageList);
970 void SetStateImageList(wxImageList *imageList);
971 void AssignImageList(wxImageList* imageList);
972 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
973 void AssignStateImageList(wxImageList* imageList);
974 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
976 unsigned int GetSpacing();
977 void SetSpacing(unsigned int spacing);
979 wxString GetItemText(const wxTreeItemId& item);
980 int GetItemImage(const wxTreeItemId& item,
981 wxTreeItemIcon which = wxTreeItemIcon_Normal);
982 int GetItemSelectedImage(const wxTreeItemId& item);
984 void SetItemText(const wxTreeItemId& item, const wxString& text);
985 void SetItemImage(const wxTreeItemId& item, int image,
986 wxTreeItemIcon which = wxTreeItemIcon_Normal);
987 void SetItemSelectedImage(const wxTreeItemId& item, int image);
988 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
991 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
993 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
994 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
996 data = new wxPyTreeItemData();
997 data->SetId(item); // set the id
998 self->SetItemData(item, data);
1003 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1004 data->SetId(item); // set the id
1005 self->SetItemData(item, data);
1008 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1009 // automatically creating data classes.
1010 PyObject* GetPyData(const wxTreeItemId& item) {
1011 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1013 data = new wxPyTreeItemData();
1014 data->SetId(item); // set the id
1015 self->SetItemData(item, data);
1017 return data->GetData();
1020 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1021 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1023 data = new wxPyTreeItemData(obj);
1024 data->SetId(item); // set the id
1025 self->SetItemData(item, data);
1032 bool IsVisible(const wxTreeItemId& item);
1033 bool ItemHasChildren(const wxTreeItemId& item);
1034 bool IsExpanded(const wxTreeItemId& item);
1035 bool IsSelected(const wxTreeItemId& item);
1037 wxTreeItemId GetRootItem();
1038 wxTreeItemId GetSelection();
1039 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1040 //size_t GetSelections(wxArrayTreeItemIds& selection);
1042 PyObject* GetSelections() {
1043 bool doSave = wxPyRestoreThread();
1044 PyObject* rval = PyList_New(0);
1045 wxArrayTreeItemIds array;
1047 num = self->GetSelections(array);
1048 for (x=0; x < num; x++) {
1049 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1050 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1051 PyList_Append(rval, item);
1053 wxPySaveThread(doSave);
1060 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1062 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
1063 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1064 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1065 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1066 wxTreeItemId GetFirstVisibleItem();
1067 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1068 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1069 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1073 wxTreeItemId AddRoot(const wxString& text,
1074 int image = -1, int selectedImage = -1,
1075 wxPyTreeItemData *data = NULL);
1076 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1077 const wxString& text,
1078 int image = -1, int selectedImage = -1,
1079 wxPyTreeItemData *data = NULL);
1080 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1081 const wxTreeItemId& idPrevious,
1082 const wxString& text,
1083 int image = -1, int selectedImage = -1,
1084 wxPyTreeItemData *data = NULL);
1085 %name(InsertItemBefore)
1086 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1088 const wxString& text,
1089 int image = -1, int selectedImage = -1,
1090 wxTreeItemData *data = NULL);
1091 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1092 const wxString& text,
1093 int image = -1, int selectedImage = -1,
1094 wxPyTreeItemData *data = NULL);
1096 void Delete(const wxTreeItemId& item);
1097 void DeleteChildren(const wxTreeItemId& item);
1098 void DeleteAllItems();
1100 void Expand(const wxTreeItemId& item);
1101 void Collapse(const wxTreeItemId& item);
1102 void CollapseAndReset(const wxTreeItemId& item);
1103 void Toggle(const wxTreeItemId& item);
1107 void SelectItem(const wxTreeItemId& item);
1108 void EnsureVisible(const wxTreeItemId& item);
1109 void ScrollTo(const wxTreeItemId& item);
1111 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1112 wxTextCtrl* GetEditControl();
1113 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1115 void EditLabel(const wxTreeItemId& item);
1118 void SortChildren(const wxTreeItemId& item);
1120 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1121 bool IsBold(const wxTreeItemId& item) const;
1122 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1126 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1127 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1128 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1131 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1133 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1135 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1137 if (self->GetBoundingRect(item, rect, textOnly)) {
1138 bool doSave = wxPyRestoreThread();
1139 wxRect* r = new wxRect(rect);
1140 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1141 wxPySaveThread(doSave);
1152 %pragma(python) addtoclass = "
1153 # Redefine some methods that SWIG gets a bit confused on...
1154 def GetFirstChild(self, *_args, **_kwargs):
1155 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1156 val1 = wxTreeItemIdPtr(val1)
1159 def GetNextChild(self, *_args, **_kwargs):
1160 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1161 val1 = wxTreeItemIdPtr(val1)
1164 def HitTest(self, *_args, **_kwargs):
1165 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1166 val1 = wxTreeItemIdPtr(val1)
1173 //----------------------------------------------------------------------
1176 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1177 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1180 //----------------------------------------------------------------------