1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Wrappers for the "gizmo" classes in wx/contrib
7 // Created: 23-Nov-2001
9 // Copyright: (c) 2001 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 "Various *gizmo* classes: `DynamicSashWindow`, `EditableListBox`,
15 `LEDNumberCtrl`, `TreeListCtrl`, etc."
18 %module(docstring=DOCSTRING) gizmos
22 #include "wx/wxPython/wxPython.h"
23 #include "wx/wxPython/pyclasses.h"
25 #include <wx/gizmos/dynamicsash.h>
26 #include <wx/gizmos/editlbox.h>
27 #include <wx/gizmos/splittree.h>
28 #include <wx/gizmos/ledctrl.h>
30 #include <wx/listctrl.h>
31 #include <wx/treectrl.h>
32 #include <wx/imaglist.h>
34 #include "wx/treelistctrl.h"
35 #include "wx/wxPython/pytree.h"
39 //---------------------------------------------------------------------------
43 %pythoncode { wx = _core }
44 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
47 MAKE_CONST_WXSTRING2(DynamicSashNameStr, wxT("dynamicSashWindow"));
48 MAKE_CONST_WXSTRING2(EditableListBoxNameStr, wxT("editableListBox"));
49 MAKE_CONST_WXSTRING2(TreeListCtrlNameStr, wxT("treelistctrl"));
51 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
54 %include _gizmos_rename.i
56 //---------------------------------------------------------------------------
59 wxEVT_DYNAMIC_SASH_SPLIT,
60 wxEVT_DYNAMIC_SASH_UNIFY,
62 wxDS_MANAGE_SCROLLBARS,
68 wxDynamicSashSplitEvents are sent to your view by wxDynamicSashWindow
69 whenever your view is being split by the user. It is your
70 responsibility to handle this event by creating a new view window as
71 a child of the wxDynamicSashWindow. wxDynamicSashWindow will
72 automatically reparent it to the proper place in its window hierarchy.
74 class wxDynamicSashSplitEvent : public wxCommandEvent {
76 wxDynamicSashSplitEvent(wxObject *target);
81 wxDynamicSashUnifyEvents are sent to your view by wxDynamicSashWindow
82 whenever the sash which splits your view and its sibling is being
83 reunified such that your view is expanding to replace its sibling.
84 You needn't do anything with this event if you are allowing
85 wxDynamicSashWindow to manage your view's scrollbars, but it is useful
86 if you are managing the scrollbars yourself so that you can keep
87 the scrollbars' event handlers connected to your view's event handler
90 class wxDynamicSashUnifyEvent : public wxCommandEvent {
92 wxDynamicSashUnifyEvent(wxObject *target);
101 wxDynamicSashWindow widgets manages the way other widgets are viewed.
102 When a wxDynamicSashWindow is first shown, it will contain one child
103 view, a viewport for that child, and a pair of scrollbars to allow the
104 user to navigate the child view area. Next to each scrollbar is a small
105 tab. By clicking on either tab and dragging to the appropriate spot, a
106 user can split the view area into two smaller views separated by a
107 draggable sash. Later, when the user wishes to reunify the two subviews,
108 the user simply drags the sash to the side of the window.
109 wxDynamicSashWindow will automatically reparent the appropriate child
110 view back up the window hierarchy, and the wxDynamicSashWindow will have
111 only one child view once again.
113 As an application developer, you will simply create a wxDynamicSashWindow
114 using either the Create() function or the more complex constructor
115 provided below, and then create a view window whose parent is the
116 wxDynamicSashWindow. The child should respond to
117 wxDynamicSashSplitEvents -- perhaps with an OnSplit() event handler -- by
118 constructing a new view window whose parent is also the
119 wxDynamicSashWindow. That's it! Now your users can dynamically split
120 and reunify the view you provided.
122 If you wish to handle the scrollbar events for your view, rather than
123 allowing wxDynamicSashWindow to do it for you, things are a bit more
124 complex. (You might want to handle scrollbar events yourself, if,
125 for instance, you wish to scroll a subwindow of the view you add to
126 your wxDynamicSashWindow object, rather than scrolling the whole view.)
127 In this case, you will need to construct your wxDynamicSashWindow without
128 the wxDS_MANAGE_SCROLLBARS style and you will need to use the
129 GetHScrollBar() and GetVScrollBar() methods to retrieve the scrollbar
130 controls and call SetEventHanler() on them to redirect the scrolling
131 events whenever your window is reparented by wxDyanmicSashWindow.
132 You will need to set the scrollbars' event handler at three times:
134 * When your view is created
135 * When your view receives a wxDynamicSashSplitEvent
136 * When your view receives a wxDynamicSashUnifyEvent
138 See the dynsash_switch sample application for an example which does this.
142 class wxDynamicSashWindow : public wxWindow {
144 %pythonAppend wxDynamicSashWindow "self._setOORInfo(self)"
145 %pythonAppend wxDynamicSashWindow() ""
147 wxDynamicSashWindow(wxWindow *parent, wxWindowID id,
148 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
149 long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER,
150 const wxString& name = wxPyDynamicSashNameStr);
151 %name(PreDynamicSashWindow)wxDynamicSashWindow();
153 bool Create(wxWindow *parent, wxWindowID id,
154 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
155 long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER,
156 const wxString& name = wxPyDynamicSashNameStr);
158 wxScrollBar *GetHScrollBar(const wxWindow *child) const;
159 wxScrollBar *GetVScrollBar(const wxWindow *child) const;
165 EVT_DYNAMIC_SASH_SPLIT = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_SPLIT, 1 )
166 EVT_DYNAMIC_SASH_UNIFY = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_UNIFY, 1 )
169 //---------------------------------------------------------------------------
170 //---------------------------------------------------------------------------
178 // This class provides a composite control that lets the
179 // user easily enter list of strings
180 class wxEditableListBox : public wxPanel
183 %pythonAppend wxEditableListBox "self._setOORInfo(self)"
184 %pythonAppend wxEditableListBox() ""
186 wxEditableListBox(wxWindow *parent, wxWindowID id,
187 const wxString& label,
188 const wxPoint& pos = wxDefaultPosition,
189 const wxSize& size = wxDefaultSize,
190 long style = wxEL_ALLOW_NEW | wxEL_ALLOW_EDIT | wxEL_ALLOW_DELETE,
191 const wxString& name = wxPyEditableListBoxNameStr);
194 void SetStrings(const wxArrayString& strings);
196 //void GetStrings(wxArrayString& strings);
198 PyObject* GetStrings() {
199 wxArrayString strings;
200 self->GetStrings(strings);
201 return wxArrayString2PyList_helper(strings);
205 wxListCtrl* GetListCtrl();
206 wxBitmapButton* GetDelButton();
207 wxBitmapButton* GetNewButton();
208 wxBitmapButton* GetUpButton();
209 wxBitmapButton* GetDownButton();
210 wxBitmapButton* GetEditButton();
215 //---------------------------------------------------------------------------
219 * wxRemotelyScrolledTreeCtrl
221 * This tree control disables its vertical scrollbar and catches scroll
222 * events passed by a scrolled window higher in the hierarchy.
223 * It also updates the scrolled window vertical scrollbar as appropriate.
227 typedef wxTreeCtrl wxPyTreeCtrl;
230 class wxRemotelyScrolledTreeCtrl: public wxPyTreeCtrl
233 %pythonAppend wxRemotelyScrolledTreeCtrl "self._setOORInfo(self)"
234 %pythonAppend wxRemotelyScrolledTreeCtrl() ""
236 wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id,
237 const wxPoint& pos = wxDefaultPosition,
238 const wxSize& size = wxDefaultSize,
239 long style = wxTR_HAS_BUTTONS);
242 void HideVScrollbar();
244 // Adjust the containing wxScrolledWindow's scrollbars appropriately
245 void AdjustRemoteScrollbars();
247 // Find the scrolled window that contains this control
248 wxScrolledWindow* GetScrolledWindow() const;
250 // Scroll to the given line (in scroll units where each unit is
251 // the height of an item)
252 void ScrollToLine(int posHoriz, int posVert);
254 // The companion window is one which will get notified when certain
255 // events happen such as node expansion
256 void SetCompanionWindow(wxWindow* companion);
257 wxWindow* GetCompanionWindow() const;
263 * wxTreeCompanionWindow
265 * A window displaying values associated with tree control items.
269 class wxPyTreeCompanionWindow: public wxTreeCompanionWindow
272 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
273 const wxPoint& pos = wxDefaultPosition,
274 const wxSize& size = wxDefaultSize,
276 : wxTreeCompanionWindow(parent, id, pos, size, style) {}
279 virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect) {
281 bool blocked = wxPyBeginBlockThreads();
282 if ((found = wxPyCBH_findCallback(m_myInst, "DrawItem"))) {
283 PyObject* dcobj = wxPyMake_wxObject(&dc);
284 PyObject* idobj = wxPyConstructObject((void*)&id, wxT("wxTreeItemId"), False);
285 PyObject* recobj= wxPyConstructObject((void*)&rect, wxT("wxRect"), False);
286 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", dcobj, idobj, recobj));
291 wxPyEndBlockThreads(blocked);
293 wxTreeCompanionWindow::DrawItem(dc, id, rect);
301 %name(TreeCompanionWindow) class wxPyTreeCompanionWindow: public wxWindow
304 %pythonAppend wxPyTreeCompanionWindow "self._setOORInfo(self);self._setCallbackInfo(self, TreeCompanionWindow)"
305 %pythonAppend wxPyTreeCompanionWindow() ""
307 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
308 const wxPoint& pos = wxDefaultPosition,
309 const wxSize& size = wxDefaultSize,
311 void _setCallbackInfo(PyObject* self, PyObject* _class);
313 wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const;
314 void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl);
320 * wxThinSplitterWindow
322 * Implements a splitter with a less obvious sash
323 * than the usual one.
326 class wxThinSplitterWindow: public wxSplitterWindow
329 %pythonAppend wxThinSplitterWindow "self._setOORInfo(self)"
330 %pythonAppend wxThinSplitterWindow() ""
332 wxThinSplitterWindow(wxWindow* parent, wxWindowID id = -1,
333 const wxPoint& pos = wxDefaultPosition,
334 const wxSize& size = wxDefaultSize,
335 long style = wxSP_3D | wxCLIP_CHILDREN);
341 * wxSplitterScrolledWindow
343 * This scrolled window is aware of the fact that one of its
344 * children is a splitter window. It passes on its scroll events
345 * (after some processing) to both splitter children for them
346 * scroll appropriately.
349 class wxSplitterScrolledWindow: public wxScrolledWindow
352 %pythonAppend wxSplitterScrolledWindow "self._setOORInfo(self)"
353 %pythonAppend wxSplitterScrolledWindow() ""
355 wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id = -1,
356 const wxPoint& pos = wxDefaultPosition,
357 const wxSize& size = wxDefaultSize,
362 //---------------------------------------------------------------------------
363 //---------------------------------------------------------------------------
378 class wxLEDNumberCtrl : public wxControl
381 %pythonAppend wxLEDNumberCtrl "self._setOORInfo(self)"
382 %pythonAppend wxLEDNumberCtrl() ""
384 wxLEDNumberCtrl(wxWindow *parent, wxWindowID id = -1,
385 const wxPoint& pos = wxDefaultPosition,
386 const wxSize& size = wxDefaultSize,
387 long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED);
388 %name(PreLEDNumberCtrl) wxLEDNumberCtrl();
390 bool Create(wxWindow *parent, wxWindowID id = -1,
391 const wxPoint& pos = wxDefaultPosition,
392 const wxSize& size = wxDefaultSize,
393 long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED);
395 wxLEDValueAlign GetAlignment() const;
396 bool GetDrawFaded() const;
397 const wxString &GetValue() const;
399 void SetAlignment(wxLEDValueAlign Alignment, bool Redraw = true);
400 void SetDrawFaded(bool DrawFaded, bool Redraw = true);
401 void SetValue(const wxString &Value, bool Redraw = true);
407 //----------------------------------------------------------------------------
408 // wxTreeListCtrl - the multicolumn tree control
409 //----------------------------------------------------------------------------
411 enum wxTreeListColumnAlign {
420 wxTREE_HITTEST_ONITEMCOLUMN
425 // flags for FindItem
435 class wxTreeListColumnInfo: public wxObject {
437 wxTreeListColumnInfo(const wxString& text = wxPyEmptyString,
441 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
443 bool GetShown() const;
444 wxTreeListColumnAlign GetAlignment() const;
445 wxString GetText() const;
446 int GetImage() const;
447 int GetSelectedImage() const;
448 size_t GetWidth() const;
450 // TODO: These all actually return wxTreeListColumnInfo&, any problem with doing it for Python too?
451 void SetShown(bool shown);
452 void SetAlignment(wxTreeListColumnAlign alignment);
453 void SetText(const wxString& text);
454 void SetImage(int image);
455 void SetSelectedImage(int image);
456 void SetWidth(size_t with);
462 %{ // C++ version of Python aware control
463 class wxPyTreeListCtrl : public wxTreeListCtrl {
464 DECLARE_ABSTRACT_CLASS(wxPyTreeListCtrl);
466 wxPyTreeListCtrl() : wxTreeListCtrl() {}
467 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id,
471 const wxValidator &validator,
472 const wxString& name) :
473 wxTreeListCtrl(parent, id, pos, size, style, validator, name) {}
475 int OnCompareItems(const wxTreeItemId& item1,
476 const wxTreeItemId& item2) {
479 bool blocked = wxPyBeginBlockThreads();
480 if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) {
481 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), 0);
482 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), 0);
483 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2));
487 wxPyEndBlockThreads(blocked);
489 rval = wxTreeListCtrl::OnCompareItems(item1, item2);
495 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeListCtrl, wxTreeListCtrl)
504 %name(TreeListCtrl) class wxPyTreeListCtrl : public wxControl
507 %pythonAppend wxPyTreeListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeListCtrl)"
508 %pythonAppend wxPyTreeListCtrl() ""
510 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id = -1,
511 const wxPoint& pos = wxDefaultPosition,
512 const wxSize& size = wxDefaultSize,
513 long style = wxTR_DEFAULT_STYLE,
514 const wxValidator &validator = wxDefaultValidator,
515 const wxString& name = wxPyTreeListCtrlNameStr );
516 %name(PreTreeListCtrl)wxPyTreeListCtrl();
518 bool Create(wxWindow *parent, wxWindowID id = -1,
519 const wxPoint& pos = wxDefaultPosition,
520 const wxSize& size = wxDefaultSize,
521 long style = wxTR_DEFAULT_STYLE,
522 const wxValidator &validator = wxDefaultValidator,
523 const wxString& name = wxPyTreeListCtrlNameStr );
525 void _setCallbackInfo(PyObject* self, PyObject* _class);
528 // get the total number of items in the control
529 size_t GetCount() const;
531 // indent is the number of pixels the children are indented relative to
532 // the parents position. SetIndent() also redraws the control
534 unsigned int GetIndent() const;
535 void SetIndent(unsigned int indent);
537 // line spacing is the space above and below the text on each line
538 unsigned int GetLineSpacing() const;
539 void SetLineSpacing(unsigned int spacing);
541 // image list: these functions allow to associate an image list with
542 // the control and retrieve it. Note that when assigned with
543 // SetImageList, the control does _not_ delete
544 // the associated image list when it's deleted in order to allow image
545 // lists to be shared between different controls. If you use
546 // AssignImageList, the control _does_ delete the image list.
548 // The normal image list is for the icons which correspond to the
549 // normal tree item state (whether it is selected or not).
550 // Additionally, the application might choose to show a state icon
551 // which corresponds to an app-defined item state (for example,
552 // checked/unchecked) which are taken from the state image list.
553 wxImageList *GetImageList() const;
554 wxImageList *GetStateImageList() const;
555 wxImageList *GetButtonsImageList() const;
557 void SetImageList(wxImageList *imageList);
558 void SetStateImageList(wxImageList *imageList);
559 void SetButtonsImageList(wxImageList *imageList);
561 %apply SWIGTYPE *DISOWN { wxImageList *imageList };
562 void AssignImageList(wxImageList *imageList);
563 void AssignStateImageList(wxImageList *imageList);
564 void AssignButtonsImageList(wxImageList *imageList);
565 %clear wxImageList *imageList;
569 void AddColumn(const wxString& text);
570 // void AddColumn(const wxString& text,
572 // wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
573 %name(AddColumnInfo) void AddColumn(const wxTreeListColumnInfo& col);
575 // inserts a column before the given one
576 void InsertColumn(size_t before, const wxString& text);
577 %name(InsertColumnInfo) void InsertColumn(size_t before, const wxTreeListColumnInfo& col);
579 // deletes the given column - does not delete the corresponding column
581 void RemoveColumn(size_t column);
583 // returns the number of columns in the ctrl
584 size_t GetColumnCount() const;
586 void SetColumnWidth(size_t column, size_t width);
587 int GetColumnWidth(size_t column) const;
589 // tells which column is the "main" one, i.e. the "threaded" one
590 void SetMainColumn(size_t column);
591 size_t GetMainColumn() const;
593 void SetColumnText(size_t column, const wxString& text);
594 wxString GetColumnText(size_t column) const;
596 void SetColumn(size_t column, const wxTreeListColumnInfo& info);
597 wxTreeListColumnInfo& GetColumn(size_t column);
599 // other column-related methods
600 void SetColumnAlignment(size_t column, wxTreeListColumnAlign align);
601 wxTreeListColumnAlign GetColumnAlignment(size_t column) const;
603 void SetColumnImage(size_t column, int image);
604 int GetColumnImage(size_t column) const;
606 void ShowColumn(size_t column, bool shown);
607 bool IsColumnShown(size_t column) const;
610 // retrieves item's label of the given column (main column by default)
611 wxString GetItemText(const wxTreeItemId& item, int column = -1) {
612 if (column < 0) column = self->GetMainColumn();
613 return self->GetItemText(item, column);
616 // get one of the images associated with the item (normal by default)
617 int GetItemImage(const wxTreeItemId& item, int column = -1,
618 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
619 if (column < 0) column = self->GetMainColumn();
620 return self->GetItemImage(item, column, which);
623 // set item's label (main column by default)
624 void SetItemText(const wxTreeItemId& item, const wxString& text, int column = -1) {
625 if (column < 0) column = self->GetMainColumn();
626 self->SetItemText(item, column, text);
629 // set one of the images associated with the item (normal by default)
630 // the which parameter is ignored for all columns but the main one
631 void SetItemImage(const wxTreeItemId& item, int image, int column = -1,
632 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
633 if (column < 0) column = self->GetMainColumn();
634 self->SetItemImage(item, column, image, which);
638 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
640 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
641 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
643 data = new wxPyTreeItemData();
644 data->SetId(item); // set the id
645 self->SetItemData(item, data);
650 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
651 data->SetId(item); // set the id
652 self->SetItemData(item, data);
655 // [Get|Set]ItemPyData are short-cuts. Also made somewhat crash-proof by
656 // automatically creating data classes.
657 PyObject* GetItemPyData(const wxTreeItemId& item) {
658 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
660 data = new wxPyTreeItemData();
661 data->SetId(item); // set the id
662 self->SetItemData(item, data);
664 return data->GetData();
667 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
668 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
670 data = new wxPyTreeItemData(obj);
671 data->SetId(item); // set the id
672 self->SetItemData(item, data);
677 %pythoncode { GetPyData = GetItemPyData }
678 %pythoncode { SetPyData = SetItemPyData }
681 // force appearance of [+] button near the item. This is useful to
682 // allow the user to expand the items which don't have any children now
683 // - but instead add them only when needed, thus minimizing memory
684 // usage and loading time.
685 void SetItemHasChildren(const wxTreeItemId& item, bool has = True);
687 // the item will be shown in bold
688 void SetItemBold(const wxTreeItemId& item, bool bold = True);
690 // set the item's text colour
691 void SetItemTextColour(const wxTreeItemId& item, const wxColour& colour);
693 // set the item's background colour
694 void SetItemBackgroundColour(const wxTreeItemId& item,
695 const wxColour& colour);
697 // set the item's font (should be of the same height for all items)
698 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
701 bool GetItemBold(const wxTreeItemId& item) const;
702 wxColour GetItemTextColour(const wxTreeItemId& item) const;
703 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
704 wxFont GetItemFont(const wxTreeItemId& item) const;
706 // is the item visible (it might be outside the view or not expanded)?
707 bool IsVisible(const wxTreeItemId& item) const;
709 // does the item has any children?
710 bool ItemHasChildren(const wxTreeItemId& item) const;
712 // is the item expanded (only makes sense if HasChildren())?
713 bool IsExpanded(const wxTreeItemId& item) const;
715 // is this item currently selected (the same as has focus)?
716 bool IsSelected(const wxTreeItemId& item) const;
718 // is item text in bold font?
719 bool IsBold(const wxTreeItemId& item) const;
721 // if 'recursively' is False, only immediate children count, otherwise
722 // the returned number is the number of all items in this branch
723 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = True);
726 // wxTreeItemId.IsOk() will return False if there is no such item
728 // get the root tree item
729 wxTreeItemId GetRootItem() const;
731 // get the item currently selected (may return NULL if no selection)
732 wxTreeItemId GetSelection() const;
734 // get the items currently selected, return the number of such item
735 //size_t GetSelections(wxArrayTreeItemIds&) const;
737 PyObject* GetSelections() {
738 bool blocked = wxPyBeginBlockThreads();
739 PyObject* rval = PyList_New(0);
740 wxArrayTreeItemIds array;
742 num = self->GetSelections(array);
743 for (x=0; x < num; x++) {
744 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
745 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True);
746 PyList_Append(rval, item);
748 wxPyEndBlockThreads(blocked);
754 // get the parent of this item (may return NULL if root)
755 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
757 // for this enumeration function you must pass in a "cookie" parameter
758 // which is opaque for the application but is necessary for the library
759 // to make these functions reentrant (i.e. allow more than one
760 // enumeration on one and the same object simultaneously). Of course,
761 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
765 // NOTE: These are a copy of the same methods in _treectrl.i, be sure to
766 // update both at the same time. (Or find a good way to refactor!)
768 // Get the first child of this item. Returns a wxTreeItemId and an
769 // opaque "cookie" value that should be passed to GetNextChild in
770 // order to continue the search.
771 PyObject* GetFirstChild(const wxTreeItemId& item) {
773 wxTreeItemId* ritem = new wxTreeItemId(self->GetFirstChild(item, cookie));
774 bool blocked = wxPyBeginBlockThreads();
775 PyObject* tup = PyTuple_New(2);
776 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), True));
777 PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void")));
778 wxPyEndBlockThreads(blocked);
783 // Get the next child of this item. The cookie parameter is the 2nd
784 // value returned from GetFirstChild or the previous GetNextChild.
785 // Returns a wxTreeItemId and an opaque "cookie" value that should be
786 // passed to GetNextChild in order to continue the search.
787 PyObject* GetNextChild(const wxTreeItemId& item, void* cookie) {
788 wxTreeItemId* ritem = new wxTreeItemId(self->GetNextChild(item, cookie));
789 bool blocked = wxPyBeginBlockThreads();
790 PyObject* tup = PyTuple_New(2);
791 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), True));
792 PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void")));
793 wxPyEndBlockThreads(blocked);
798 // TODO: GetPrevChild
802 // get the last child of this item - this method doesn't use cookies
803 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
805 // get the next sibling of this item
806 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
808 // get the previous sibling
809 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
811 // get first visible item
812 wxTreeItemId GetFirstVisibleItem() const;
814 // get the next visible item: item must be visible itself!
815 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
816 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
818 // get the previous visible item: item must be visible itself!
819 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
821 // Only for internal use right now, but should probably be public
822 wxTreeItemId GetNext(const wxTreeItemId& item) const;
825 // add the root node to the tree
826 wxTreeItemId AddRoot(const wxString& text,
827 int image = -1, int selectedImage = -1,
828 wxPyTreeItemData *data = NULL);
830 // insert a new item in as the first child of the parent
831 wxTreeItemId PrependItem(const wxTreeItemId& parent,
832 const wxString& text,
833 int image = -1, int selectedImage = -1,
834 wxPyTreeItemData *data = NULL);
836 // insert a new item after a given one
837 wxTreeItemId InsertItem(const wxTreeItemId& parent,
838 const wxTreeItemId& idPrevious,
839 const wxString& text,
840 int image = -1, int selectedImage = -1,
841 wxPyTreeItemData *data = NULL);
843 // insert a new item before the one with the given index
844 %name(InsertItemBefore)
845 wxTreeItemId InsertItem(const wxTreeItemId& parent,
847 const wxString& text,
848 int image = -1, int selectedImage = -1,
849 wxPyTreeItemData *data = NULL);
851 // insert a new item in as the last child of the parent
852 wxTreeItemId AppendItem(const wxTreeItemId& parent,
853 const wxString& text,
854 int image = -1, int selectedImage = -1,
855 wxPyTreeItemData *data = NULL);
857 // delete this item and associated data if any
858 void Delete(const wxTreeItemId& item);
860 // delete all children (but don't delete the item itself)
861 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
862 void DeleteChildren(const wxTreeItemId& item);
864 // delete all items from the tree
865 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
866 void DeleteAllItems();
869 void Expand(const wxTreeItemId& item);
871 // expand this item and all subitems recursively
872 void ExpandAll(const wxTreeItemId& item);
874 // collapse the item without removing its children
875 void Collapse(const wxTreeItemId& item);
877 // collapse the item and remove all children
878 void CollapseAndReset(const wxTreeItemId& item);
880 // toggles the current state
881 void Toggle(const wxTreeItemId& item);
883 // remove the selection from currently selected item (if any)
888 void SelectItem(const wxTreeItemId& item, bool unselect_others=True,
889 bool extended_select=False);
891 void SelectAll(bool extended_select=False);
893 // make sure this item is visible (expanding the parent item and/or
894 // scrolling to this item if necessary)
895 void EnsureVisible(const wxTreeItemId& item);
897 // scroll to this item (but don't expand its parent)
898 void ScrollTo(const wxTreeItemId& item);
900 // Returns wxTreeItemId, flags, and column
901 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT, int& OUTPUT);
904 // get the bounding rectangle of the item (or of its label only)
905 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
907 if (self->GetBoundingRect(item, rect, textOnly)) {
908 bool blocked = wxPyBeginBlockThreads();
909 wxRect* r = new wxRect(rect);
910 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1);
911 wxPyEndBlockThreads(blocked);
921 // Start editing the item label: this (temporarily) replaces the item
922 // with a one line edit control. The item will be selected if it hadn't
924 void EditLabel( const wxTreeItemId& item );
925 void Edit( const wxTreeItemId& item );
927 // sort the children of this item using OnCompareItems
928 void SortChildren(const wxTreeItemId& item);
931 wxTreeItemId FindItem (const wxTreeItemId& item, const wxString& str, int flags = 0);
933 wxWindow* GetHeaderWindow() const;
934 wxWindow* GetMainWindow() const;
941 //----------------------------------------------------------------------
942 //----------------------------------------------------------------------
946 wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow");
947 wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl");
951 %pragma(python) include="_gizmoextras.py";
953 //----------------------------------------------------------------------
954 //----------------------------------------------------------------------