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 "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
426 class wxTreeListColumnInfo: public wxObject {
428 wxTreeListColumnInfo(const wxString& text = wxPyEmptyString,
431 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
433 wxTreeListColumnAlign GetAlignment() const;
434 wxString GetText() const;
435 int GetImage() const;
436 int GetSelectedImage() const;
437 size_t GetWidth() const;
439 void SetAlignment(wxTreeListColumnAlign alignment);
440 void SetText(const wxString& text);
441 void SetImage(int image);
442 void SetSelectedImage(int image);
443 void SetWidth(size_t with);
449 %{ // C++ version of Python aware control
450 class wxPyTreeListCtrl : public wxTreeListCtrl {
451 DECLARE_ABSTRACT_CLASS(wxPyTreeListCtrl);
453 wxPyTreeListCtrl() : wxTreeListCtrl() {}
454 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id,
458 const wxValidator &validator,
459 const wxString& name) :
460 wxTreeListCtrl(parent, id, pos, size, style, validator, name) {}
462 int OnCompareItems(const wxTreeItemId& item1,
463 const wxTreeItemId& item2) {
466 bool blocked = wxPyBeginBlockThreads();
467 if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) {
468 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), 0);
469 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), 0);
470 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2));
474 wxPyEndBlockThreads(blocked);
476 rval = wxTreeListCtrl::OnCompareItems(item1, item2);
482 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeListCtrl, wxTreeListCtrl)
491 %name(TreeListCtrl) class wxPyTreeListCtrl : public wxControl
494 %pythonAppend wxPyTreeListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeListCtrl)"
495 %pythonAppend wxPyTreeListCtrl() ""
497 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id = -1,
498 const wxPoint& pos = wxDefaultPosition,
499 const wxSize& size = wxDefaultSize,
500 long style = wxTR_DEFAULT_STYLE,
501 const wxValidator &validator = wxDefaultValidator,
502 const wxString& name = wxPyTreeListCtrlNameStr );
503 %name(PreTreeListCtrl)wxPyTreeListCtrl();
505 bool Create(wxWindow *parent, wxWindowID id = -1,
506 const wxPoint& pos = wxDefaultPosition,
507 const wxSize& size = wxDefaultSize,
508 long style = wxTR_DEFAULT_STYLE,
509 const wxValidator &validator = wxDefaultValidator,
510 const wxString& name = wxPyTreeListCtrlNameStr );
512 void _setCallbackInfo(PyObject* self, PyObject* _class);
515 // get the total number of items in the control
516 size_t GetCount() const;
518 // indent is the number of pixels the children are indented relative to
519 // the parents position. SetIndent() also redraws the control
521 unsigned int GetIndent() const;
522 void SetIndent(unsigned int indent);
524 // spacing is the number of pixels between the start and the Text
525 unsigned int GetSpacing() const;
526 void SetSpacing(unsigned int spacing);
528 // line spacing is the space above and below the text on each line
529 unsigned int GetLineSpacing() const;
530 void SetLineSpacing(unsigned int spacing);
532 // image list: these functions allow to associate an image list with
533 // the control and retrieve it. Note that when assigned with
534 // SetImageList, the control does _not_ delete
535 // the associated image list when it's deleted in order to allow image
536 // lists to be shared between different controls. If you use
537 // AssignImageList, the control _does_ delete the image list.
539 // The normal image list is for the icons which correspond to the
540 // normal tree item state (whether it is selected or not).
541 // Additionally, the application might choose to show a state icon
542 // which corresponds to an app-defined item state (for example,
543 // checked/unchecked) which are taken from the state image list.
544 wxImageList *GetImageList() const;
545 wxImageList *GetStateImageList() const;
546 wxImageList *GetButtonsImageList() const;
548 void SetImageList(wxImageList *imageList);
549 void SetStateImageList(wxImageList *imageList);
550 void SetButtonsImageList(wxImageList *imageList);
552 %apply SWIGTYPE *DISOWN { wxImageList *imageList };
553 void AssignImageList(wxImageList *imageList);
554 void AssignStateImageList(wxImageList *imageList);
555 void AssignButtonsImageList(wxImageList *imageList);
556 %clear wxImageList *imageList;
560 void AddColumn(const wxString& text);
561 %name(AddColumnInfo) void AddColumn(const wxTreeListColumnInfo& col);
563 // inserts a column before the given one
564 void InsertColumn(size_t before, const wxString& text);
565 %name(InsertColumnInfo) void InsertColumn(size_t before, const wxTreeListColumnInfo& col);
567 // deletes the given column - does not delete the corresponding column
569 void RemoveColumn(size_t column);
571 // returns the number of columns in the ctrl
572 size_t GetColumnCount() const;
574 void SetColumnWidth(size_t column, size_t width);
575 int GetColumnWidth(size_t column) const;
577 // tells which column is the "main" one, i.e. the "threaded" one
578 void SetMainColumn(size_t column);
579 size_t GetMainColumn() const;
581 void SetColumnText(size_t column, const wxString& text);
582 wxString GetColumnText(size_t column) const;
584 void SetColumn(size_t column, const wxTreeListColumnInfo& info);
585 wxTreeListColumnInfo& GetColumn(size_t column);
587 // other column-related methods
588 void SetColumnAlignment(size_t column, wxTreeListColumnAlign align);
589 wxTreeListColumnAlign GetColumnAlignment(size_t column) const;
591 void SetColumnImage(size_t column, int image);
592 int GetColumnImage(size_t column) const;
596 // retrieves item's label of the given column (main column by default)
597 wxString GetItemText(const wxTreeItemId& item, int column = -1) {
598 if (column < 0) column = self->GetMainColumn();
599 return self->GetItemText(item, column);
602 // get one of the images associated with the item (normal by default)
603 int GetItemImage(const wxTreeItemId& item, int column = -1,
604 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
605 if (column < 0) column = self->GetMainColumn();
606 return self->GetItemImage(item, column, which);
609 // set item's label (main column by default)
610 void SetItemText(const wxTreeItemId& item, const wxString& text, int column = -1) {
611 if (column < 0) column = self->GetMainColumn();
612 self->SetItemText(item, column, text);
615 // set one of the images associated with the item (normal by default)
616 // the which parameter is ignored for all columns but the main one
617 void SetItemImage(const wxTreeItemId& item, int image, int column = -1,
618 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
619 if (column < 0) column = self->GetMainColumn();
620 self->SetItemImage(item, column, image, which);
624 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
626 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
627 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
629 data = new wxPyTreeItemData();
630 data->SetId(item); // set the id
631 self->SetItemData(item, data);
636 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
637 data->SetId(item); // set the id
638 self->SetItemData(item, data);
641 // [Get|Set]ItemPyData are short-cuts. Also made somewhat crash-proof by
642 // automatically creating data classes.
643 PyObject* GetItemPyData(const wxTreeItemId& item) {
644 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
646 data = new wxPyTreeItemData();
647 data->SetId(item); // set the id
648 self->SetItemData(item, data);
650 return data->GetData();
653 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
654 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
656 data = new wxPyTreeItemData(obj);
657 data->SetId(item); // set the id
658 self->SetItemData(item, data);
663 %pythoncode { GetPyData = GetItemPyData }
664 %pythoncode { SetPyData = SetItemPyData }
667 // force appearance of [+] button near the item. This is useful to
668 // allow the user to expand the items which don't have any children now
669 // - but instead add them only when needed, thus minimizing memory
670 // usage and loading time.
671 void SetItemHasChildren(const wxTreeItemId& item, bool has = True);
673 // the item will be shown in bold
674 void SetItemBold(const wxTreeItemId& item, bool bold = True);
676 // set the item's text colour
677 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
679 // set the item's background colour
680 void SetItemBackgroundColour(const wxTreeItemId& item,
681 const wxColour& col);
683 // set the item's font (should be of the same height for all items)
684 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
687 bool GetItemBold(const wxTreeItemId& item) const;
688 wxColour GetItemTextColour(const wxTreeItemId& item) const;
689 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
690 wxFont GetItemFont(const wxTreeItemId& item) const;
692 // is the item visible (it might be outside the view or not expanded)?
693 bool IsVisible(const wxTreeItemId& item) const;
695 // does the item has any children?
696 bool ItemHasChildren(const wxTreeItemId& item) const;
698 // is the item expanded (only makes sense if HasChildren())?
699 bool IsExpanded(const wxTreeItemId& item) const;
701 // is this item currently selected (the same as has focus)?
702 bool IsSelected(const wxTreeItemId& item) const;
704 // is item text in bold font?
705 bool IsBold(const wxTreeItemId& item) const;
707 // if 'recursively' is False, only immediate children count, otherwise
708 // the returned number is the number of all items in this branch
709 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = True);
712 // wxTreeItemId.IsOk() will return False if there is no such item
714 // get the root tree item
715 wxTreeItemId GetRootItem() const;
717 // get the item currently selected (may return NULL if no selection)
718 wxTreeItemId GetSelection() const;
720 // get the items currently selected, return the number of such item
721 //size_t GetSelections(wxArrayTreeItemIds&) const;
723 PyObject* GetSelections() {
724 bool blocked = wxPyBeginBlockThreads();
725 PyObject* rval = PyList_New(0);
726 wxArrayTreeItemIds array;
728 num = self->GetSelections(array);
729 for (x=0; x < num; x++) {
730 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
731 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True);
732 PyList_Append(rval, item);
734 wxPyEndBlockThreads(blocked);
740 // get the parent of this item (may return NULL if root)
741 %name(GetItemParent)wxTreeItemId GetParent(const wxTreeItemId& item) const;
743 // for this enumeration function you must pass in a "cookie" parameter
744 // which is opaque for the application but is necessary for the library
745 // to make these functions reentrant (i.e. allow more than one
746 // enumeration on one and the same object simultaneously). Of course,
747 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
752 // Get the first child of this item. Returns a wxTreeItemId and an
753 // opaque "cookie" value that should be passed to GetNextChild in
754 // order to continue the search.
755 PyObject* GetFirstChild(const wxTreeItemId& item) {
757 wxTreeItemId* ritem = new wxTreeItemId(self->GetFirstChild(item, cookie));
758 bool blocked = wxPyBeginBlockThreads();
759 PyObject* tup = PyTuple_New(2);
760 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
761 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
762 wxPyEndBlockThreads(blocked);
767 // Get the next child of this item. The cookie parameter is the 2nd
768 // value returned from GetFirstChild or the previous GetNextChild.
769 // Returns a wxTreeItemId and an opaque "cookie" value that should be
770 // passed to GetNextChild in order to continue the search.
771 PyObject* GetNextChild(const wxTreeItemId& item, long cookie) {
772 wxTreeItemId* ritem = new wxTreeItemId(self->GetNextChild(item, cookie));
773 bool blocked = wxPyBeginBlockThreads();
774 PyObject* tup = PyTuple_New(2);
775 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
776 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
777 wxPyEndBlockThreads(blocked);
782 // get the last child of this item - this method doesn't use cookies
783 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
785 // get the next sibling of this item
786 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
788 // get the previous sibling
789 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
791 // get first visible item
792 wxTreeItemId GetFirstVisibleItem() const;
794 // get the next visible item: item must be visible itself!
795 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
796 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
798 // get the previous visible item: item must be visible itself!
799 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
801 // Only for internal use right now, but should probably be public
802 wxTreeItemId GetNext(const wxTreeItemId& item) const;
805 // add the root node to the tree
806 wxTreeItemId AddRoot(const wxString& text,
807 int image = -1, int selectedImage = -1,
808 wxPyTreeItemData *data = NULL);
810 // insert a new item in as the first child of the parent
811 wxTreeItemId PrependItem(const wxTreeItemId& parent,
812 const wxString& text,
813 int image = -1, int selectedImage = -1,
814 wxPyTreeItemData *data = NULL);
816 // insert a new item after a given one
817 wxTreeItemId InsertItem(const wxTreeItemId& parent,
818 const wxTreeItemId& idPrevious,
819 const wxString& text,
820 int image = -1, int selectedImage = -1,
821 wxPyTreeItemData *data = NULL);
823 // insert a new item before the one with the given index
824 %name(InsertItemBefore)
825 wxTreeItemId InsertItem(const wxTreeItemId& parent,
827 const wxString& text,
828 int image = -1, int selectedImage = -1,
829 wxPyTreeItemData *data = NULL);
831 // insert a new item in as the last child of the parent
832 wxTreeItemId AppendItem(const wxTreeItemId& parent,
833 const wxString& text,
834 int image = -1, int selectedImage = -1,
835 wxPyTreeItemData *data = NULL);
837 // delete this item and associated data if any
838 void Delete(const wxTreeItemId& item);
840 // delete all children (but don't delete the item itself)
841 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
842 void DeleteChildren(const wxTreeItemId& item);
844 // delete all items from the tree
845 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
846 void DeleteAllItems();
849 void Expand(const wxTreeItemId& item);
851 // expand this item and all subitems recursively
852 void ExpandAll(const wxTreeItemId& item);
854 // collapse the item without removing its children
855 void Collapse(const wxTreeItemId& item);
857 // collapse the item and remove all children
858 void CollapseAndReset(const wxTreeItemId& item);
860 // toggles the current state
861 void Toggle(const wxTreeItemId& item);
863 // remove the selection from currently selected item (if any)
868 void SelectItem(const wxTreeItemId& item, bool unselect_others=True,
869 bool extended_select=False);
871 // make sure this item is visible (expanding the parent item and/or
872 // scrolling to this item if necessary)
873 void EnsureVisible(const wxTreeItemId& item);
875 // scroll to this item (but don't expand its parent)
876 void ScrollTo(const wxTreeItemId& item);
878 // Returns wxTreeItemId, flags, and column
879 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT, int& OUTPUT);
882 // get the bounding rectangle of the item (or of its label only)
883 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
885 if (self->GetBoundingRect(item, rect, textOnly)) {
886 bool blocked = wxPyBeginBlockThreads();
887 wxRect* r = new wxRect(rect);
888 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1);
889 wxPyEndBlockThreads(blocked);
899 // Start editing the item label: this (temporarily) replaces the item
900 // with a one line edit control. The item will be selected if it hadn't
902 void EditLabel( const wxTreeItemId& item );
903 void Edit( const wxTreeItemId& item );
905 // sort the children of this item using OnCompareItems
906 void SortChildren(const wxTreeItemId& item);
908 // get the selected item image
909 int GetItemSelectedImage(const wxTreeItemId& item) const;
911 // set the selected item image
912 void SetItemSelectedImage(const wxTreeItemId& item, int image);
915 wxWindow* GetHeaderWindow() const;
916 wxWindow* GetMainWindow() const;
923 //----------------------------------------------------------------------
924 //----------------------------------------------------------------------
928 wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow");
929 wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl");
933 %pragma(python) include="_gizmoextras.py";
935 //----------------------------------------------------------------------
936 //----------------------------------------------------------------------