]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/gizmos/gizmos.i
reSWIGged
[wxWidgets.git] / wxPython / contrib / gizmos / gizmos.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gizmos.i
3 // Purpose: Wrappers for the "gizmo" classes in wx/contrib
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 23-Nov-2001
8 // RCS-ID: $Id$
9 // Copyright: (c) 2001 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %define DOCSTRING
14 "Various *gizmo* classes: `DynamicSashWindow`, `EditableListBox`,
15 `LEDNumberCtrl`, `TreeListCtrl`, etc."
16 %enddef
17
18 %module(docstring=DOCSTRING) gizmos
19
20
21 %{
22 #include "wx/wxPython/wxPython.h"
23 #include "wx/wxPython/pyclasses.h"
24
25 #include <wx/gizmos/dynamicsash.h>
26 #include <wx/gizmos/editlbox.h>
27 #include <wx/gizmos/splittree.h>
28 #include <wx/gizmos/ledctrl.h>
29
30 #include <wx/listctrl.h>
31 #include <wx/treectrl.h>
32 #include <wx/imaglist.h>
33
34 #include "treelistctrl.h"
35 #include "wx/wxPython/pytree.h"
36
37 %}
38
39 //---------------------------------------------------------------------------
40
41 %import windows.i
42 %import controls.i
43 %pythoncode { wx = _core }
44 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
45
46
47 MAKE_CONST_WXSTRING2(DynamicSashNameStr, wxT("dynamicSashWindow"));
48 MAKE_CONST_WXSTRING2(EditableListBoxNameStr, wxT("editableListBox"));
49 MAKE_CONST_WXSTRING2(TreeListCtrlNameStr, wxT("treelistctrl"));
50
51 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
52
53
54 %include _gizmos_rename.i
55
56 //---------------------------------------------------------------------------
57
58 enum {
59 wxEVT_DYNAMIC_SASH_SPLIT,
60 wxEVT_DYNAMIC_SASH_UNIFY,
61
62 wxDS_MANAGE_SCROLLBARS,
63 wxDS_DRAG_CORNER,
64 };
65
66
67 /*
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.
73 */
74 class wxDynamicSashSplitEvent : public wxCommandEvent {
75 public:
76 wxDynamicSashSplitEvent(wxObject *target);
77 };
78
79
80 /*
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
88 class.
89 */
90 class wxDynamicSashUnifyEvent : public wxCommandEvent {
91 public:
92 wxDynamicSashUnifyEvent(wxObject *target);
93 };
94
95
96
97 /*
98
99 wxDynamicSashWindow
100
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.
112
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.
121
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:
133
134 * When your view is created
135 * When your view receives a wxDynamicSashSplitEvent
136 * When your view receives a wxDynamicSashUnifyEvent
137
138 See the dynsash_switch sample application for an example which does this.
139
140 */
141
142 class wxDynamicSashWindow : public wxWindow {
143 public:
144 %pythonAppend wxDynamicSashWindow "self._setOORInfo(self)"
145 %pythonAppend wxDynamicSashWindow() ""
146
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();
152
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);
157
158 wxScrollBar *GetHScrollBar(const wxWindow *child) const;
159 wxScrollBar *GetVScrollBar(const wxWindow *child) const;
160 };
161
162
163
164 %pythoncode {
165 EVT_DYNAMIC_SASH_SPLIT = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_SPLIT, 1 )
166 EVT_DYNAMIC_SASH_UNIFY = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_UNIFY, 1 )
167 }
168
169 //---------------------------------------------------------------------------
170 //---------------------------------------------------------------------------
171
172 enum {
173 wxEL_ALLOW_NEW,
174 wxEL_ALLOW_EDIT,
175 wxEL_ALLOW_DELETE,
176 };
177
178 // This class provides a composite control that lets the
179 // user easily enter list of strings
180 class wxEditableListBox : public wxPanel
181 {
182 public:
183 %pythonAppend wxEditableListBox "self._setOORInfo(self)"
184 %pythonAppend wxEditableListBox() ""
185
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);
192
193
194 void SetStrings(const wxArrayString& strings);
195
196 //void GetStrings(wxArrayString& strings);
197 %extend {
198 PyObject* GetStrings() {
199 wxArrayString strings;
200 self->GetStrings(strings);
201 return wxArrayString2PyList_helper(strings);
202 }
203 }
204
205 wxListCtrl* GetListCtrl();
206 wxBitmapButton* GetDelButton();
207 wxBitmapButton* GetNewButton();
208 wxBitmapButton* GetUpButton();
209 wxBitmapButton* GetDownButton();
210 wxBitmapButton* GetEditButton();
211 };
212
213
214
215 //---------------------------------------------------------------------------
216
217
218 /*
219 * wxRemotelyScrolledTreeCtrl
220 *
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.
224 */
225
226 %{
227 typedef wxTreeCtrl wxPyTreeCtrl;
228 %}
229
230 class wxRemotelyScrolledTreeCtrl: public wxPyTreeCtrl
231 {
232 public:
233 %pythonAppend wxRemotelyScrolledTreeCtrl "self._setOORInfo(self)"
234 %pythonAppend wxRemotelyScrolledTreeCtrl() ""
235
236 wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id,
237 const wxPoint& pos = wxDefaultPosition,
238 const wxSize& size = wxDefaultSize,
239 long style = wxTR_HAS_BUTTONS);
240
241
242 void HideVScrollbar();
243
244 // Adjust the containing wxScrolledWindow's scrollbars appropriately
245 void AdjustRemoteScrollbars();
246
247 // Find the scrolled window that contains this control
248 wxScrolledWindow* GetScrolledWindow() const;
249
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);
253
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;
258 };
259
260
261
262 /*
263 * wxTreeCompanionWindow
264 *
265 * A window displaying values associated with tree control items.
266 */
267
268 %{
269 class wxPyTreeCompanionWindow: public wxTreeCompanionWindow
270 {
271 public:
272 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
273 const wxPoint& pos = wxDefaultPosition,
274 const wxSize& size = wxDefaultSize,
275 long style = 0)
276 : wxTreeCompanionWindow(parent, id, pos, size, style) {}
277
278
279 virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect) {
280 bool found;
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));
287 Py_DECREF(dcobj);
288 Py_DECREF(idobj);
289 Py_DECREF(recobj);
290 }
291 wxPyEndBlockThreads(blocked);
292 if (! found)
293 wxTreeCompanionWindow::DrawItem(dc, id, rect);
294 }
295
296 PYPRIVATE;
297 };
298 %}
299
300
301 %name(TreeCompanionWindow) class wxPyTreeCompanionWindow: public wxWindow
302 {
303 public:
304 %pythonAppend wxPyTreeCompanionWindow "self._setOORInfo(self);self._setCallbackInfo(self, TreeCompanionWindow)"
305 %pythonAppend wxPyTreeCompanionWindow() ""
306
307 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
308 const wxPoint& pos = wxDefaultPosition,
309 const wxSize& size = wxDefaultSize,
310 long style = 0);
311 void _setCallbackInfo(PyObject* self, PyObject* _class);
312
313 wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const;
314 void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl);
315 };
316
317
318
319 /*
320 * wxThinSplitterWindow
321 *
322 * Implements a splitter with a less obvious sash
323 * than the usual one.
324 */
325
326 class wxThinSplitterWindow: public wxSplitterWindow
327 {
328 public:
329 %pythonAppend wxThinSplitterWindow "self._setOORInfo(self)"
330 %pythonAppend wxThinSplitterWindow() ""
331
332 wxThinSplitterWindow(wxWindow* parent, wxWindowID id = -1,
333 const wxPoint& pos = wxDefaultPosition,
334 const wxSize& size = wxDefaultSize,
335 long style = wxSP_3D | wxCLIP_CHILDREN);
336 };
337
338
339
340 /*
341 * wxSplitterScrolledWindow
342 *
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.
347 */
348
349 class wxSplitterScrolledWindow: public wxScrolledWindow
350 {
351 public:
352 %pythonAppend wxSplitterScrolledWindow "self._setOORInfo(self)"
353 %pythonAppend wxSplitterScrolledWindow() ""
354
355 wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id = -1,
356 const wxPoint& pos = wxDefaultPosition,
357 const wxSize& size = wxDefaultSize,
358 long style = 0);
359 };
360
361
362 //---------------------------------------------------------------------------
363 //---------------------------------------------------------------------------
364
365
366 enum wxLEDValueAlign
367 {
368 wxLED_ALIGN_LEFT,
369 wxLED_ALIGN_RIGHT,
370 wxLED_ALIGN_CENTER,
371
372 wxLED_ALIGN_MASK,
373
374 wxLED_DRAW_FADED,
375 };
376
377
378 class wxLEDNumberCtrl : public wxControl
379 {
380 public:
381 %pythonAppend wxLEDNumberCtrl "self._setOORInfo(self)"
382 %pythonAppend wxLEDNumberCtrl() ""
383
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();
389
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);
394
395 wxLEDValueAlign GetAlignment() const;
396 bool GetDrawFaded() const;
397 const wxString &GetValue() const;
398
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);
402
403 };
404
405
406
407 //----------------------------------------------------------------------------
408 // wxTreeListCtrl - the multicolumn tree control
409 //----------------------------------------------------------------------------
410
411 enum wxTreeListColumnAlign {
412 wxTL_ALIGN_LEFT,
413 wxTL_ALIGN_RIGHT,
414 wxTL_ALIGN_CENTER
415 };
416
417
418
419 enum {
420 wxTREE_HITTEST_ONITEMCOLUMN
421 };
422
423
424
425
426 class wxTreeListColumnInfo: public wxObject {
427 public:
428 wxTreeListColumnInfo(const wxString& text = wxPyEmptyString,
429 int image = -1,
430 size_t width = 100,
431 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
432
433 wxTreeListColumnAlign GetAlignment() const;
434 wxString GetText() const;
435 int GetImage() const;
436 int GetSelectedImage() const;
437 size_t GetWidth() const;
438
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);
444 };
445
446
447
448
449 %{ // C++ version of Python aware control
450 class wxPyTreeListCtrl : public wxTreeListCtrl {
451 DECLARE_ABSTRACT_CLASS(wxPyTreeListCtrl);
452 public:
453 wxPyTreeListCtrl() : wxTreeListCtrl() {}
454 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id,
455 const wxPoint& pos,
456 const wxSize& size,
457 long style,
458 const wxValidator &validator,
459 const wxString& name) :
460 wxTreeListCtrl(parent, id, pos, size, style, validator, name) {}
461
462 int OnCompareItems(const wxTreeItemId& item1,
463 const wxTreeItemId& item2) {
464 int rval = 0;
465 bool found;
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));
471 Py_DECREF(o1);
472 Py_DECREF(o2);
473 }
474 wxPyEndBlockThreads(blocked);
475 if (! found)
476 rval = wxTreeListCtrl::OnCompareItems(item1, item2);
477 return rval;
478 }
479 PYPRIVATE;
480 };
481
482 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeListCtrl, wxTreeListCtrl)
483
484 %}
485
486
487
488
489
490
491 %name(TreeListCtrl) class wxPyTreeListCtrl : public wxControl
492 {
493 public:
494 %pythonAppend wxPyTreeListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeListCtrl)"
495 %pythonAppend wxPyTreeListCtrl() ""
496
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();
504
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 );
511
512 void _setCallbackInfo(PyObject* self, PyObject* _class);
513
514
515 // get the total number of items in the control
516 size_t GetCount() const;
517
518 // indent is the number of pixels the children are indented relative to
519 // the parents position. SetIndent() also redraws the control
520 // immediately.
521 unsigned int GetIndent() const;
522 void SetIndent(unsigned int indent);
523
524 // spacing is the number of pixels between the start and the Text
525 unsigned int GetSpacing() const;
526 void SetSpacing(unsigned int spacing);
527
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);
531
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.
538 //
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;
547
548 void SetImageList(wxImageList *imageList);
549 void SetStateImageList(wxImageList *imageList);
550 void SetButtonsImageList(wxImageList *imageList);
551
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;
557
558
559 // adds a column
560 void AddColumn(const wxString& text);
561 %name(AddColumnInfo) void AddColumn(const wxTreeListColumnInfo& col);
562
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);
566
567 // deletes the given column - does not delete the corresponding column
568 // of each item
569 void RemoveColumn(size_t column);
570
571 // returns the number of columns in the ctrl
572 size_t GetColumnCount() const;
573
574 void SetColumnWidth(size_t column, size_t width);
575 int GetColumnWidth(size_t column) const;
576
577 // tells which column is the "main" one, i.e. the "threaded" one
578 void SetMainColumn(size_t column);
579 size_t GetMainColumn() const;
580
581 void SetColumnText(size_t column, const wxString& text);
582 wxString GetColumnText(size_t column) const;
583
584 void SetColumn(size_t column, const wxTreeListColumnInfo& info);
585 wxTreeListColumnInfo& GetColumn(size_t column);
586
587 // other column-related methods
588 void SetColumnAlignment(size_t column, wxTreeListColumnAlign align);
589 wxTreeListColumnAlign GetColumnAlignment(size_t column) const;
590
591 void SetColumnImage(size_t column, int image);
592 int GetColumnImage(size_t column) const;
593
594
595 %extend {
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);
600 }
601
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);
607 }
608
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);
613 }
614
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);
621 }
622
623
624 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
625 // if needed.
626 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
627 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
628 if (data == NULL) {
629 data = new wxPyTreeItemData();
630 data->SetId(item); // set the id
631 self->SetItemData(item, data);
632 }
633 return data;
634 }
635
636 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
637 data->SetId(item); // set the id
638 self->SetItemData(item, data);
639 }
640
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);
645 if (data == NULL) {
646 data = new wxPyTreeItemData();
647 data->SetId(item); // set the id
648 self->SetItemData(item, data);
649 }
650 return data->GetData();
651 }
652
653 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
654 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
655 if (data == NULL) {
656 data = new wxPyTreeItemData(obj);
657 data->SetId(item); // set the id
658 self->SetItemData(item, data);
659 } else
660 data->SetData(obj);
661 }
662 }
663 %pythoncode { GetPyData = GetItemPyData }
664 %pythoncode { SetPyData = SetItemPyData }
665
666
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);
672
673 // the item will be shown in bold
674 void SetItemBold(const wxTreeItemId& item, bool bold = True);
675
676 // set the item's text colour
677 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
678
679 // set the item's background colour
680 void SetItemBackgroundColour(const wxTreeItemId& item,
681 const wxColour& col);
682
683 // set the item's font (should be of the same height for all items)
684 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
685
686
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;
691
692 // is the item visible (it might be outside the view or not expanded)?
693 bool IsVisible(const wxTreeItemId& item) const;
694
695 // does the item has any children?
696 bool ItemHasChildren(const wxTreeItemId& item) const;
697
698 // is the item expanded (only makes sense if HasChildren())?
699 bool IsExpanded(const wxTreeItemId& item) const;
700
701 // is this item currently selected (the same as has focus)?
702 bool IsSelected(const wxTreeItemId& item) const;
703
704 // is item text in bold font?
705 bool IsBold(const wxTreeItemId& item) const;
706
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);
710
711
712 // wxTreeItemId.IsOk() will return False if there is no such item
713
714 // get the root tree item
715 wxTreeItemId GetRootItem() const;
716
717 // get the item currently selected (may return NULL if no selection)
718 wxTreeItemId GetSelection() const;
719
720 // get the items currently selected, return the number of such item
721 //size_t GetSelections(wxArrayTreeItemIds&) const;
722 %extend {
723 PyObject* GetSelections() {
724 bool blocked = wxPyBeginBlockThreads();
725 PyObject* rval = PyList_New(0);
726 wxArrayTreeItemIds array;
727 size_t num, x;
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);
733 }
734 wxPyEndBlockThreads(blocked);
735 return rval;
736 }
737 }
738
739
740 // get the parent of this item (may return NULL if root)
741 %name(GetItemParent)wxTreeItemId GetParent(const wxTreeItemId& item) const;
742
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
748 // the same!
749
750
751 %extend {
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) {
756 long cookie = 0;
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);
763 return tup;
764 }
765
766
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);
778 return tup;
779 }
780 }
781
782 // get the last child of this item - this method doesn't use cookies
783 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
784
785 // get the next sibling of this item
786 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
787
788 // get the previous sibling
789 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
790
791 // get first visible item
792 wxTreeItemId GetFirstVisibleItem() const;
793
794 // get the next visible item: item must be visible itself!
795 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
796 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
797
798 // get the previous visible item: item must be visible itself!
799 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
800
801 // Only for internal use right now, but should probably be public
802 wxTreeItemId GetNext(const wxTreeItemId& item) const;
803
804
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);
809
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);
815
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);
822
823 // insert a new item before the one with the given index
824 %name(InsertItemBefore)
825 wxTreeItemId InsertItem(const wxTreeItemId& parent,
826 size_t index,
827 const wxString& text,
828 int image = -1, int selectedImage = -1,
829 wxPyTreeItemData *data = NULL);
830
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);
836
837 // delete this item and associated data if any
838 void Delete(const wxTreeItemId& item);
839
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);
843
844 // delete all items from the tree
845 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
846 void DeleteAllItems();
847
848 // expand this item
849 void Expand(const wxTreeItemId& item);
850
851 // expand this item and all subitems recursively
852 void ExpandAll(const wxTreeItemId& item);
853
854 // collapse the item without removing its children
855 void Collapse(const wxTreeItemId& item);
856
857 // collapse the item and remove all children
858 void CollapseAndReset(const wxTreeItemId& item);
859
860 // toggles the current state
861 void Toggle(const wxTreeItemId& item);
862
863 // remove the selection from currently selected item (if any)
864 void Unselect();
865 void UnselectAll();
866
867 // select this item
868 void SelectItem(const wxTreeItemId& item, bool unselect_others=True,
869 bool extended_select=False);
870
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);
874
875 // scroll to this item (but don't expand its parent)
876 void ScrollTo(const wxTreeItemId& item);
877
878 // Returns wxTreeItemId, flags, and column
879 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT, int& OUTPUT);
880
881 %extend {
882 // get the bounding rectangle of the item (or of its label only)
883 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
884 wxRect rect;
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);
890 return val;
891 }
892 else {
893 RETURN_NONE();
894 }
895 }
896 }
897
898
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
901 // been before.
902 void EditLabel( const wxTreeItemId& item );
903 void Edit( const wxTreeItemId& item );
904
905 // sort the children of this item using OnCompareItems
906 void SortChildren(const wxTreeItemId& item);
907
908 // get the selected item image
909 int GetItemSelectedImage(const wxTreeItemId& item) const;
910
911 // set the selected item image
912 void SetItemSelectedImage(const wxTreeItemId& item, int image);
913
914
915 wxWindow* GetHeaderWindow() const;
916 wxWindow* GetMainWindow() const;
917
918 };
919
920
921
922
923 //----------------------------------------------------------------------
924 //----------------------------------------------------------------------
925
926 %init %{
927
928 wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow");
929 wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl");
930 %}
931
932
933 %pragma(python) include="_gizmoextras.py";
934
935 //----------------------------------------------------------------------
936 //----------------------------------------------------------------------
937
938
939
940
941
942