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();
336 class wxPyListCtrl : public wxListCtrl {
337 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
339 wxPyListCtrl(wxWindow* parent, wxWindowID id,
343 const wxValidator& validator,
345 wxListCtrl(parent, id, pos, size, style, validator, name) {}
347 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
348 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
349 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
354 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
356 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
357 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
358 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
362 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
364 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
365 const wxPoint& pos = wxDefaultPosition,
366 const wxSize& size = wxDefaultSize,
367 long style = wxLC_ICON,
368 const wxValidator& validator = wxDefaultValidator,
369 char* name = "listCtrl");
371 void _setSelf(PyObject* self, PyObject* _class);
372 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
373 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxListCtrl)"
376 // Set the control colours
377 bool SetForegroundColour(const wxColour& col);
378 bool SetBackgroundColour(const wxColour& col);
380 // Gets information about this column
381 bool GetColumn(int col, wxListItem& item) const;
383 // Sets information about this column
384 bool SetColumn(int col, wxListItem& item) ;
386 // Gets the column width
387 int GetColumnWidth(int col) const;
389 // Sets the column width
390 bool SetColumnWidth(int col, int width) ;
392 // Gets the number of items that can fit vertically in the
393 // visible area of the list control (list or report view)
394 // or the total number of items in the list control (icon
395 // or small icon view)
396 int GetCountPerPage() const;
398 // Gets the edit control for editing labels.
399 wxTextCtrl* GetEditControl() const;
402 //bool GetItem(wxListItem& info) const ;
404 // Gets information about the item
405 %new wxListItem* GetItem(long itemId, int col=0) {
406 wxListItem* info = new wxListItem;
407 info->m_itemId = itemId;
409 info->m_mask = 0xFFFF;
410 self->GetItem(*info);
413 } // The OOR typemaps don't know what to do with the %new, so fix it up.
414 %pragma(python) addtoclass = "
415 def GetItem(self, *_args, **_kwargs):
416 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
422 // Sets information about the item
423 bool SetItem(wxListItem& info) ;
425 // Sets a string field at a particular column
426 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
428 // Gets the item state
429 int GetItemState(long item, long stateMask) const ;
431 // Sets the item state
432 bool SetItemState(long item, long state, long stateMask) ;
434 // Sets the item image
435 bool SetItemImage(long item, int image, int selImage) ;
437 // Gets the item text
438 wxString GetItemText(long item) const ;
440 // Sets the item text
441 void SetItemText(long item, const wxString& str) ;
443 // Gets the item data
444 long GetItemData(long item) const ;
446 // Sets the item data
447 bool SetItemData(long item, long data) ;
450 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
451 //bool GetItemPosition(long item, wxPoint& pos) const ;
453 // Gets the item position
454 %new wxPoint* GetItemPosition(long item) {
455 wxPoint* pos = new wxPoint;
456 self->GetItemPosition(item, *pos);
459 // Gets the item rectangle
460 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
461 wxRect* rect= new wxRect;
462 self->GetItemRect(item, *rect, code);
468 // Sets the item position
469 bool SetItemPosition(long item, const wxPoint& pos) ;
471 // Gets the number of items in the list control
472 int GetItemCount() const;
474 // Gets the number of columns in the list control
475 int GetColumnCount() const { return m_colCount; }
477 // Retrieves the spacing between icons in pixels.
478 // If small is TRUE, gets the spacing for the small icon
479 // view, otherwise the large icon view.
480 int GetItemSpacing(bool isSmall) const;
482 // Gets the number of selected items in the list control
483 int GetSelectedItemCount() const;
485 // Gets the text colour of the listview
486 wxColour GetTextColour() const;
488 // Sets the text colour of the listview
489 void SetTextColour(const wxColour& col);
491 // Gets the index of the topmost visible item when in
492 // list or report view
493 long GetTopItem() const ;
495 // Add or remove a single window style
496 void SetSingleStyle(long style, bool add = TRUE) ;
498 // Set the whole window style
499 void SetWindowStyleFlag(long style) ;
501 // Searches for an item, starting from 'item'.
502 // item can be -1 to find the first item that matches the
504 // Returns the item or -1 if unsuccessful.
505 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
507 // Gets one of the three image lists
508 wxImageList *GetImageList(int which) const ;
510 // Sets the image list
511 void SetImageList(wxImageList *imageList, int which) ;
512 void AssignImageList(wxImageList *imageList, int which) ;
513 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
515 // returns true if it is a virtual list control
516 bool IsVirtual() const;
518 // refresh items selectively (only useful for virtual list controls)
519 void RefreshItem(long item);
520 void RefreshItems(long itemFrom, long itemTo);
525 // Arranges the items
526 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
529 bool DeleteItem(long item);
532 bool DeleteAllItems() ;
535 bool DeleteColumn(int col);
537 // Deletes all columns
538 bool DeleteAllColumns();
540 // Clears items, and columns if there are any.
544 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
546 // End label editing, optionally cancelling the edit
547 bool EndEditLabel(bool cancel);
549 // Ensures this item is visible
550 bool EnsureVisible(long item) ;
552 // Find an item whose label matches this string, starting from the item after 'start'
553 // or the beginning if 'start' is -1.
554 long FindItem(long start, const wxString& str, bool partial = FALSE);
556 // Find an item whose data matches this data, starting from the item after 'start'
557 // or the beginning if 'start' is -1.
558 %name(FindItemData)long FindItem(long start, long data);
560 // Find an item nearest this position in the specified direction, starting from
561 // the item after 'start' or the beginning if 'start' is -1.
562 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
564 // Determines which item (if any) is at the specified point,
565 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
566 long HitTest(const wxPoint& point, int& OUTPUT);
568 // Inserts an item, returning the index of the new item if successful,
570 long InsertItem(wxListItem& info);
572 // Insert a string item
573 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
575 // Insert an image item
576 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
578 // Insert an image/string item
579 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
581 // For list view mode (only), inserts a column.
582 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
584 long InsertColumn(long col,
585 const wxString& heading,
586 int format = wxLIST_FORMAT_LEFT,
589 // set the number of items in a virtual list control
590 void SetItemCount(long count);
592 // Scrolls the list control. If in icon, small icon or report view mode,
593 // x specifies the number of pixels to scroll. If in list view mode, x
594 // specifies the number of columns to scroll.
595 // If in icon, small icon or list view mode, y specifies the number of pixels
596 // to scroll. If in report view mode, y specifies the number of lines to scroll.
597 bool ScrollList(int dx, int dy);
599 // bool SortItems(wxListCtrlCompare fn, long data);
602 // func is a function which takes 2 long arguments: item1, item2.
603 // item1 is the long data associated with a first item (NOT the index).
604 // item2 is the long data associated with a second item (NOT the index).
605 // The return value is a negative number if the first item should precede the second
606 // item, a positive number of the second item should precede the first,
607 // or zero if the two items are equivalent.
608 bool SortItems(PyObject* func) {
609 if (!PyCallable_Check(func))
611 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
620 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
622 PyObject* func = (PyObject*)funcPtr;
623 bool doSave = wxPyRestoreThread();
625 PyObject* args = Py_BuildValue("(ii)", item1, item2);
626 PyObject* result = PyEval_CallObject(func, args);
629 retval = PyInt_AsLong(result);
633 wxPySaveThread(doSave);
639 //----------------------------------------------------------------------
643 wxTreeItemIcon_Normal, // not selected, not expanded
644 wxTreeItemIcon_Selected, // selected, not expanded
645 wxTreeItemIcon_Expanded, // not selected, expanded
646 wxTreeItemIcon_SelectedExpanded, // selected, expanded
651 // constants for HitTest
653 wxTREE_HITTEST_ABOVE,
654 wxTREE_HITTEST_BELOW,
655 wxTREE_HITTEST_NOWHERE,
656 wxTREE_HITTEST_ONITEMBUTTON,
657 wxTREE_HITTEST_ONITEMICON,
658 wxTREE_HITTEST_ONITEMINDENT,
659 wxTREE_HITTEST_ONITEMLABEL,
660 wxTREE_HITTEST_ONITEMRIGHT,
661 wxTREE_HITTEST_ONITEMSTATEICON,
662 wxTREE_HITTEST_TOLEFT,
663 wxTREE_HITTEST_TORIGHT,
664 wxTREE_HITTEST_ONITEMUPPERPART,
665 wxTREE_HITTEST_ONITEMLOWERPART,
666 wxTREE_HITTEST_ONITEM
671 /* Tree control event types */
672 wxEVT_COMMAND_TREE_BEGIN_DRAG,
673 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
674 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
675 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
676 wxEVT_COMMAND_TREE_DELETE_ITEM,
677 wxEVT_COMMAND_TREE_GET_INFO,
678 wxEVT_COMMAND_TREE_SET_INFO,
679 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
680 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
681 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
682 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
683 wxEVT_COMMAND_TREE_SEL_CHANGED,
684 wxEVT_COMMAND_TREE_SEL_CHANGING,
685 wxEVT_COMMAND_TREE_KEY_DOWN,
686 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
687 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
688 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
689 wxEVT_COMMAND_TREE_END_DRAG,
700 int __cmp__(wxTreeItemId* other) {
701 if (! other) return -1;
702 return *self != *other;
710 class wxPyTreeItemData : public wxTreeItemData {
712 wxPyTreeItemData(PyObject* obj = NULL) {
719 ~wxPyTreeItemData() {
720 bool doSave = wxPyRestoreThread();
722 wxPySaveThread(doSave);
725 PyObject* GetData() {
730 void SetData(PyObject* obj) {
731 bool doSave = wxPyRestoreThread();
733 wxPySaveThread(doSave);
744 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
746 wxPyTreeItemData(PyObject* obj = NULL);
749 void SetData(PyObject* obj);
751 const wxTreeItemId& GetId();
752 void SetId(const wxTreeItemId& id);
757 class wxTreeEvent : public wxNotifyEvent {
759 wxTreeItemId GetItem();
760 wxTreeItemId GetOldItem();
763 const wxString& GetLabel();
769 class wxPyTreeCtrl : public wxTreeCtrl {
770 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
772 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
776 const wxValidator& validator,
778 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
780 int OnCompareItems(const wxTreeItemId& item1,
781 const wxTreeItemId& item2) {
783 bool doSave = wxPyRestoreThread();
784 if (m_myInst.findCallback("OnCompareItems"))
785 rval = m_myInst.callCallback(Py_BuildValue(
787 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
788 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
790 rval = wxTreeCtrl::OnCompareItems(item1, item2);
791 wxPySaveThread(doSave);
797 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
801 // These are for the GetFirstChild/GetNextChild methods below
802 %typemap(python, in) long& INOUT = long* INOUT;
803 %typemap(python, argout) long& INOUT = long* INOUT;
806 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
808 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
809 const wxPoint& pos = wxDefaultPosition,
810 const wxSize& size = wxDefaultSize,
811 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
812 const wxValidator& validator = wxDefaultValidator,
813 char* name = "wxTreeCtrl");
815 void _setSelf(PyObject* self, PyObject* _class);
816 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
817 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTreeCtrl)"
819 void AssignImageList(wxImageList* imageList);
820 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
822 unsigned int GetIndent();
823 void SetIndent(unsigned int indent);
824 wxImageList *GetImageList();
825 wxImageList *GetStateImageList();
826 void SetImageList(wxImageList *imageList);
827 void SetStateImageList(wxImageList *imageList);
829 unsigned int GetSpacing();
830 void SetSpacing(unsigned int spacing);
832 wxString GetItemText(const wxTreeItemId& item);
833 int GetItemImage(const wxTreeItemId& item,
834 wxTreeItemIcon which = wxTreeItemIcon_Normal);
835 int GetItemSelectedImage(const wxTreeItemId& item);
837 void SetItemText(const wxTreeItemId& item, const wxString& text);
838 void SetItemImage(const wxTreeItemId& item, int image,
839 wxTreeItemIcon which = wxTreeItemIcon_Normal);
840 void SetItemSelectedImage(const wxTreeItemId& item, int image);
841 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
844 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
846 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
847 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
849 data = new wxPyTreeItemData();
850 data->SetId(item); // set the id
851 self->SetItemData(item, data);
856 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
857 data->SetId(item); // set the id
858 self->SetItemData(item, data);
861 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
862 // automatically creating data classes.
863 PyObject* GetPyData(const wxTreeItemId& item) {
864 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
866 data = new wxPyTreeItemData();
867 data->SetId(item); // set the id
868 self->SetItemData(item, data);
870 return data->GetData();
873 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
874 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
876 data = new wxPyTreeItemData(obj);
877 data->SetId(item); // set the id
878 self->SetItemData(item, data);
885 bool IsVisible(const wxTreeItemId& item);
886 bool ItemHasChildren(const wxTreeItemId& item);
887 bool IsExpanded(const wxTreeItemId& item);
888 bool IsSelected(const wxTreeItemId& item);
890 wxTreeItemId GetRootItem();
891 wxTreeItemId GetSelection();
892 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
893 //size_t GetSelections(wxArrayTreeItemIds& selection);
895 PyObject* GetSelections() {
896 bool doSave = wxPyRestoreThread();
897 PyObject* rval = PyList_New(0);
898 wxArrayTreeItemIds array;
900 num = self->GetSelections(array);
901 for (x=0; x < num; x++) {
902 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
903 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
904 PyList_Append(rval, item);
906 wxPySaveThread(doSave);
913 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
915 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
916 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
917 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
918 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
919 wxTreeItemId GetFirstVisibleItem();
920 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
921 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
922 wxTreeItemId GetLastChild(const wxTreeItemId& item);
926 wxTreeItemId AddRoot(const wxString& text,
927 int image = -1, int selectedImage = -1,
928 wxPyTreeItemData *data = NULL);
929 wxTreeItemId PrependItem(const wxTreeItemId& parent,
930 const wxString& text,
931 int image = -1, int selectedImage = -1,
932 wxPyTreeItemData *data = NULL);
933 wxTreeItemId InsertItem(const wxTreeItemId& parent,
934 const wxTreeItemId& idPrevious,
935 const wxString& text,
936 int image = -1, int selectedImage = -1,
937 wxPyTreeItemData *data = NULL);
938 %name(InsertItemBefore)
939 wxTreeItemId InsertItem(const wxTreeItemId& parent,
941 const wxString& text,
942 int image = -1, int selectedImage = -1,
943 wxTreeItemData *data = NULL);
944 wxTreeItemId AppendItem(const wxTreeItemId& parent,
945 const wxString& text,
946 int image = -1, int selectedImage = -1,
947 wxPyTreeItemData *data = NULL);
949 void Delete(const wxTreeItemId& item);
950 void DeleteChildren(const wxTreeItemId& item);
951 void DeleteAllItems();
953 void Expand(const wxTreeItemId& item);
954 void Collapse(const wxTreeItemId& item);
955 void CollapseAndReset(const wxTreeItemId& item);
956 void Toggle(const wxTreeItemId& item);
960 void SelectItem(const wxTreeItemId& item);
961 void EnsureVisible(const wxTreeItemId& item);
962 void ScrollTo(const wxTreeItemId& item);
964 wxTextCtrl* EditLabel(const wxTreeItemId& item);
965 wxTextCtrl* GetEditControl();
966 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
968 void EditLabel(const wxTreeItemId& item);
971 void SortChildren(const wxTreeItemId& item);
973 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
974 bool IsBold(const wxTreeItemId& item) const;
975 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
979 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
980 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
981 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
984 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
986 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
988 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
990 if (self->GetBoundingRect(item, rect, textOnly)) {
991 bool doSave = wxPyRestoreThread();
992 wxRect* r = new wxRect(rect);
993 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
994 wxPySaveThread(doSave);
1005 %pragma(python) addtoclass = "
1006 # Redefine some methods that SWIG gets a bit confused on...
1007 def GetFirstChild(self, *_args, **_kwargs):
1008 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1009 val1 = wxTreeItemIdPtr(val1)
1012 def GetNextChild(self, *_args, **_kwargs):
1013 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1014 val1 = wxTreeItemIdPtr(val1)
1017 def HitTest(self, *_args, **_kwargs):
1018 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1019 val1 = wxTreeItemIdPtr(val1)
1026 //----------------------------------------------------------------------
1033 /* tab control event types */
1034 wxEVT_COMMAND_TAB_SEL_CHANGED,
1035 wxEVT_COMMAND_TAB_SEL_CHANGING,
1039 class wxTabEvent : public wxCommandEvent {
1045 class wxTabCtrl : public wxControl {
1047 wxTabCtrl(wxWindow* parent, wxWindowID id,
1048 const wxPoint& pos = wxDefaultPosition,
1049 const wxSize& size = wxDefaultSize,
1051 char* name = "tabCtrl");
1053 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
1055 bool DeleteAllItems();
1056 bool DeleteItem(int item);
1057 wxImageList* GetImageList();
1059 // TODO: void* GetItemData();
1060 int GetItemImage(int item);
1063 %new wxRect* GetItemRect(int item) {
1064 wxRect* rect = new wxRect;
1065 self->GetItemRect(item, *rect);
1070 wxString GetItemText(int item);
1073 int HitTest(const wxPoint& pt, long& OUTPUT);
1074 void InsertItem(int item, const wxString& text,
1075 int imageId = -1, void* clientData = NULL);
1076 // TODO: bool SetItemData(int item, void* data);
1077 bool SetItemImage(int item, int image);
1078 void SetImageList(wxImageList* imageList);
1079 void SetItemSize(const wxSize& size);
1080 bool SetItemText(int item, const wxString& text);
1081 void SetPadding(const wxSize& padding);
1082 int SetSelection(int item);
1089 //----------------------------------------------------------------------
1092 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1093 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1096 //----------------------------------------------------------------------