]> 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 %module gizmos
14
15
16 %{
17 #include "wx/wxPython/wxPython.h"
18 #include "wx/wxPython/pyclasses.h"
19
20 #include <wx/gizmos/dynamicsash.h>
21 #include <wx/gizmos/editlbox.h>
22 #include <wx/gizmos/splittree.h>
23 #include <wx/gizmos/ledctrl.h>
24
25 #include <wx/listctrl.h>
26 #include <wx/treectrl.h>
27 #include <wx/imaglist.h>
28
29 #include "treelistctrl.h"
30 #include "wx/wxPython/pytree.h"
31
32 %}
33
34 //---------------------------------------------------------------------------
35
36 %import windows.i
37 %import controls.i
38 %pythoncode { wx = _core }
39 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
40
41
42 MAKE_CONST_WXSTRING2(DynamicSashNameStr, wxT("dynamicSashWindow"));
43 MAKE_CONST_WXSTRING2(EditableListBoxNameStr, wxT("editableListBox"));
44 MAKE_CONST_WXSTRING2(TreeListCtrlNameStr, wxT("treelistctrl"));
45
46 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
47
48
49 %include _gizmos_rename.i
50
51 //---------------------------------------------------------------------------
52
53 enum {
54 wxEVT_DYNAMIC_SASH_SPLIT,
55 wxEVT_DYNAMIC_SASH_UNIFY,
56
57 wxDS_MANAGE_SCROLLBARS,
58 wxDS_DRAG_CORNER,
59 };
60
61
62 /*
63 wxDynamicSashSplitEvents are sent to your view by wxDynamicSashWindow
64 whenever your view is being split by the user. It is your
65 responsibility to handle this event by creating a new view window as
66 a child of the wxDynamicSashWindow. wxDynamicSashWindow will
67 automatically reparent it to the proper place in its window hierarchy.
68 */
69 class wxDynamicSashSplitEvent : public wxCommandEvent {
70 public:
71 wxDynamicSashSplitEvent(wxObject *target);
72 };
73
74
75 /*
76 wxDynamicSashUnifyEvents are sent to your view by wxDynamicSashWindow
77 whenever the sash which splits your view and its sibling is being
78 reunified such that your view is expanding to replace its sibling.
79 You needn't do anything with this event if you are allowing
80 wxDynamicSashWindow to manage your view's scrollbars, but it is useful
81 if you are managing the scrollbars yourself so that you can keep
82 the scrollbars' event handlers connected to your view's event handler
83 class.
84 */
85 class wxDynamicSashUnifyEvent : public wxCommandEvent {
86 public:
87 wxDynamicSashUnifyEvent(wxObject *target);
88 };
89
90
91
92 /*
93
94 wxDynamicSashWindow
95
96 wxDynamicSashWindow widgets manages the way other widgets are viewed.
97 When a wxDynamicSashWindow is first shown, it will contain one child
98 view, a viewport for that child, and a pair of scrollbars to allow the
99 user to navigate the child view area. Next to each scrollbar is a small
100 tab. By clicking on either tab and dragging to the appropriate spot, a
101 user can split the view area into two smaller views separated by a
102 draggable sash. Later, when the user wishes to reunify the two subviews,
103 the user simply drags the sash to the side of the window.
104 wxDynamicSashWindow will automatically reparent the appropriate child
105 view back up the window hierarchy, and the wxDynamicSashWindow will have
106 only one child view once again.
107
108 As an application developer, you will simply create a wxDynamicSashWindow
109 using either the Create() function or the more complex constructor
110 provided below, and then create a view window whose parent is the
111 wxDynamicSashWindow. The child should respond to
112 wxDynamicSashSplitEvents -- perhaps with an OnSplit() event handler -- by
113 constructing a new view window whose parent is also the
114 wxDynamicSashWindow. That's it! Now your users can dynamically split
115 and reunify the view you provided.
116
117 If you wish to handle the scrollbar events for your view, rather than
118 allowing wxDynamicSashWindow to do it for you, things are a bit more
119 complex. (You might want to handle scrollbar events yourself, if,
120 for instance, you wish to scroll a subwindow of the view you add to
121 your wxDynamicSashWindow object, rather than scrolling the whole view.)
122 In this case, you will need to construct your wxDynamicSashWindow without
123 the wxDS_MANAGE_SCROLLBARS style and you will need to use the
124 GetHScrollBar() and GetVScrollBar() methods to retrieve the scrollbar
125 controls and call SetEventHanler() on them to redirect the scrolling
126 events whenever your window is reparented by wxDyanmicSashWindow.
127 You will need to set the scrollbars' event handler at three times:
128
129 * When your view is created
130 * When your view receives a wxDynamicSashSplitEvent
131 * When your view receives a wxDynamicSashUnifyEvent
132
133 See the dynsash_switch sample application for an example which does this.
134
135 */
136
137 class wxDynamicSashWindow : public wxWindow {
138 public:
139 %pythonAppend wxDynamicSashWindow "self._setOORInfo(self)"
140 %pythonAppend wxDynamicSashWindow() ""
141
142 wxDynamicSashWindow(wxWindow *parent, wxWindowID id,
143 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
144 long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER,
145 const wxString& name = wxPyDynamicSashNameStr);
146 %name(PreDynamicSashWindow)wxDynamicSashWindow();
147
148 bool Create(wxWindow *parent, wxWindowID id,
149 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
150 long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER,
151 const wxString& name = wxPyDynamicSashNameStr);
152
153 wxScrollBar *GetHScrollBar(const wxWindow *child) const;
154 wxScrollBar *GetVScrollBar(const wxWindow *child) const;
155 };
156
157
158
159 %pythoncode {
160 EVT_DYNAMIC_SASH_SPLIT = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_SPLIT, 1 )
161 EVT_DYNAMIC_SASH_UNIFY = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_UNIFY, 1 )
162 }
163
164 //---------------------------------------------------------------------------
165 //---------------------------------------------------------------------------
166
167 enum {
168 wxEL_ALLOW_NEW,
169 wxEL_ALLOW_EDIT,
170 wxEL_ALLOW_DELETE,
171 };
172
173 // This class provides a composite control that lets the
174 // user easily enter list of strings
175 class wxEditableListBox : public wxPanel
176 {
177 public:
178 %pythonAppend wxEditableListBox "self._setOORInfo(self)"
179 %pythonAppend wxEditableListBox() ""
180
181 wxEditableListBox(wxWindow *parent, wxWindowID id,
182 const wxString& label,
183 const wxPoint& pos = wxDefaultPosition,
184 const wxSize& size = wxDefaultSize,
185 long style = wxEL_ALLOW_NEW | wxEL_ALLOW_EDIT | wxEL_ALLOW_DELETE,
186 const wxString& name = wxPyEditableListBoxNameStr);
187
188
189 void SetStrings(const wxArrayString& strings);
190
191 //void GetStrings(wxArrayString& strings);
192 %extend {
193 PyObject* GetStrings() {
194 wxArrayString strings;
195 self->GetStrings(strings);
196 return wxArrayString2PyList_helper(strings);
197 }
198 }
199
200 wxListCtrl* GetListCtrl();
201 wxBitmapButton* GetDelButton();
202 wxBitmapButton* GetNewButton();
203 wxBitmapButton* GetUpButton();
204 wxBitmapButton* GetDownButton();
205 wxBitmapButton* GetEditButton();
206 };
207
208
209
210 //---------------------------------------------------------------------------
211
212
213 /*
214 * wxRemotelyScrolledTreeCtrl
215 *
216 * This tree control disables its vertical scrollbar and catches scroll
217 * events passed by a scrolled window higher in the hierarchy.
218 * It also updates the scrolled window vertical scrollbar as appropriate.
219 */
220
221 %{
222 typedef wxTreeCtrl wxPyTreeCtrl;
223 %}
224
225 class wxRemotelyScrolledTreeCtrl: public wxPyTreeCtrl
226 {
227 public:
228 %pythonAppend wxRemotelyScrolledTreeCtrl "self._setOORInfo(self)"
229 %pythonAppend wxRemotelyScrolledTreeCtrl() ""
230
231 wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id,
232 const wxPoint& pos = wxDefaultPosition,
233 const wxSize& size = wxDefaultSize,
234 long style = wxTR_HAS_BUTTONS);
235
236
237 void HideVScrollbar();
238
239 // Adjust the containing wxScrolledWindow's scrollbars appropriately
240 void AdjustRemoteScrollbars();
241
242 // Find the scrolled window that contains this control
243 wxScrolledWindow* GetScrolledWindow() const;
244
245 // Scroll to the given line (in scroll units where each unit is
246 // the height of an item)
247 void ScrollToLine(int posHoriz, int posVert);
248
249 // The companion window is one which will get notified when certain
250 // events happen such as node expansion
251 void SetCompanionWindow(wxWindow* companion);
252 wxWindow* GetCompanionWindow() const;
253 };
254
255
256
257 /*
258 * wxTreeCompanionWindow
259 *
260 * A window displaying values associated with tree control items.
261 */
262
263 %{
264 class wxPyTreeCompanionWindow: public wxTreeCompanionWindow
265 {
266 public:
267 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
268 const wxPoint& pos = wxDefaultPosition,
269 const wxSize& size = wxDefaultSize,
270 long style = 0)
271 : wxTreeCompanionWindow(parent, id, pos, size, style) {}
272
273
274 virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect) {
275 bool found;
276 bool blocked = wxPyBeginBlockThreads();
277 if ((found = wxPyCBH_findCallback(m_myInst, "DrawItem"))) {
278 PyObject* dcobj = wxPyMake_wxObject(&dc);
279 PyObject* idobj = wxPyConstructObject((void*)&id, wxT("wxTreeItemId"), False);
280 PyObject* recobj= wxPyConstructObject((void*)&rect, wxT("wxRect"), False);
281 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", dcobj, idobj, recobj));
282 Py_DECREF(dcobj);
283 Py_DECREF(idobj);
284 Py_DECREF(recobj);
285 }
286 wxPyEndBlockThreads(blocked);
287 if (! found)
288 wxTreeCompanionWindow::DrawItem(dc, id, rect);
289 }
290
291 PYPRIVATE;
292 };
293 %}
294
295
296 %name(TreeCompanionWindow) class wxPyTreeCompanionWindow: public wxWindow
297 {
298 public:
299 %pythonAppend wxPyTreeCompanionWindow "self._setOORInfo(self);self._setCallbackInfo(self, TreeCompanionWindow)"
300 %pythonAppend wxPyTreeCompanionWindow() ""
301
302 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
303 const wxPoint& pos = wxDefaultPosition,
304 const wxSize& size = wxDefaultSize,
305 long style = 0);
306 void _setCallbackInfo(PyObject* self, PyObject* _class);
307
308 wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const;
309 void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl);
310 };
311
312
313
314 /*
315 * wxThinSplitterWindow
316 *
317 * Implements a splitter with a less obvious sash
318 * than the usual one.
319 */
320
321 class wxThinSplitterWindow: public wxSplitterWindow
322 {
323 public:
324 %pythonAppend wxThinSplitterWindow "self._setOORInfo(self)"
325 %pythonAppend wxThinSplitterWindow() ""
326
327 wxThinSplitterWindow(wxWindow* parent, wxWindowID id = -1,
328 const wxPoint& pos = wxDefaultPosition,
329 const wxSize& size = wxDefaultSize,
330 long style = wxSP_3D | wxCLIP_CHILDREN);
331 };
332
333
334
335 /*
336 * wxSplitterScrolledWindow
337 *
338 * This scrolled window is aware of the fact that one of its
339 * children is a splitter window. It passes on its scroll events
340 * (after some processing) to both splitter children for them
341 * scroll appropriately.
342 */
343
344 class wxSplitterScrolledWindow: public wxScrolledWindow
345 {
346 public:
347 %pythonAppend wxSplitterScrolledWindow "self._setOORInfo(self)"
348 %pythonAppend wxSplitterScrolledWindow() ""
349
350 wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id = -1,
351 const wxPoint& pos = wxDefaultPosition,
352 const wxSize& size = wxDefaultSize,
353 long style = 0);
354 };
355
356
357 //---------------------------------------------------------------------------
358 //---------------------------------------------------------------------------
359
360
361 enum wxLEDValueAlign
362 {
363 wxLED_ALIGN_LEFT,
364 wxLED_ALIGN_RIGHT,
365 wxLED_ALIGN_CENTER,
366
367 wxLED_ALIGN_MASK,
368
369 wxLED_DRAW_FADED,
370 };
371
372
373 class wxLEDNumberCtrl : public wxControl
374 {
375 public:
376 %pythonAppend wxLEDNumberCtrl "self._setOORInfo(self)"
377 %pythonAppend wxLEDNumberCtrl() ""
378
379 wxLEDNumberCtrl(wxWindow *parent, wxWindowID id = -1,
380 const wxPoint& pos = wxDefaultPosition,
381 const wxSize& size = wxDefaultSize,
382 long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED);
383 %name(PreLEDNumberCtrl) wxLEDNumberCtrl();
384
385 bool Create(wxWindow *parent, wxWindowID id = -1,
386 const wxPoint& pos = wxDefaultPosition,
387 const wxSize& size = wxDefaultSize,
388 long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED);
389
390 wxLEDValueAlign GetAlignment() const;
391 bool GetDrawFaded() const;
392 const wxString &GetValue() const;
393
394 void SetAlignment(wxLEDValueAlign Alignment, bool Redraw = true);
395 void SetDrawFaded(bool DrawFaded, bool Redraw = true);
396 void SetValue(const wxString &Value, bool Redraw = true);
397
398 };
399
400
401
402 //----------------------------------------------------------------------------
403 // wxTreeListCtrl - the multicolumn tree control
404 //----------------------------------------------------------------------------
405
406 enum wxTreeListColumnAlign {
407 wxTL_ALIGN_LEFT,
408 wxTL_ALIGN_RIGHT,
409 wxTL_ALIGN_CENTER
410 };
411
412
413
414 enum {
415 wxTREE_HITTEST_ONITEMCOLUMN
416 };
417
418
419
420
421 class wxTreeListColumnInfo: public wxObject {
422 public:
423 wxTreeListColumnInfo(const wxString& text = wxPyEmptyString,
424 int image = -1,
425 size_t width = 100,
426 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
427
428 wxTreeListColumnAlign GetAlignment() const;
429 wxString GetText() const;
430 int GetImage() const;
431 int GetSelectedImage() const;
432 size_t GetWidth() const;
433
434 void SetAlignment(wxTreeListColumnAlign alignment);
435 void SetText(const wxString& text);
436 void SetImage(int image);
437 void SetSelectedImage(int image);
438 void SetWidth(size_t with);
439 };
440
441
442
443
444 %{ // C++ version of Python aware control
445 class wxPyTreeListCtrl : public wxTreeListCtrl {
446 DECLARE_ABSTRACT_CLASS(wxPyTreeListCtrl);
447 public:
448 wxPyTreeListCtrl() : wxTreeListCtrl() {}
449 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id,
450 const wxPoint& pos,
451 const wxSize& size,
452 long style,
453 const wxValidator &validator,
454 const wxString& name) :
455 wxTreeListCtrl(parent, id, pos, size, style, validator, name) {}
456
457 int OnCompareItems(const wxTreeItemId& item1,
458 const wxTreeItemId& item2) {
459 int rval = 0;
460 bool found;
461 bool blocked = wxPyBeginBlockThreads();
462 if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) {
463 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), 0);
464 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), 0);
465 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2));
466 Py_DECREF(o1);
467 Py_DECREF(o2);
468 }
469 wxPyEndBlockThreads(blocked);
470 if (! found)
471 rval = wxTreeListCtrl::OnCompareItems(item1, item2);
472 return rval;
473 }
474 PYPRIVATE;
475 };
476
477 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeListCtrl, wxTreeListCtrl)
478
479 %}
480
481
482
483
484
485
486 %name(TreeListCtrl) class wxPyTreeListCtrl : public wxControl
487 {
488 public:
489 %pythonAppend wxPyTreeListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeListCtrl)"
490 %pythonAppend wxPyTreeListCtrl() ""
491
492 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id = -1,
493 const wxPoint& pos = wxDefaultPosition,
494 const wxSize& size = wxDefaultSize,
495 long style = wxTR_DEFAULT_STYLE,
496 const wxValidator &validator = wxDefaultValidator,
497 const wxString& name = wxPyTreeListCtrlNameStr );
498 %name(PreTreeListCtrl)wxPyTreeListCtrl();
499
500 bool Create(wxWindow *parent, wxWindowID id = -1,
501 const wxPoint& pos = wxDefaultPosition,
502 const wxSize& size = wxDefaultSize,
503 long style = wxTR_DEFAULT_STYLE,
504 const wxValidator &validator = wxDefaultValidator,
505 const wxString& name = wxPyTreeListCtrlNameStr );
506
507 void _setCallbackInfo(PyObject* self, PyObject* _class);
508
509
510 // get the total number of items in the control
511 size_t GetCount() const;
512
513 // indent is the number of pixels the children are indented relative to
514 // the parents position. SetIndent() also redraws the control
515 // immediately.
516 unsigned int GetIndent() const;
517 void SetIndent(unsigned int indent);
518
519 // spacing is the number of pixels between the start and the Text
520 unsigned int GetSpacing() const;
521 void SetSpacing(unsigned int spacing);
522
523 // line spacing is the space above and below the text on each line
524 unsigned int GetLineSpacing() const;
525 void SetLineSpacing(unsigned int spacing);
526
527 // image list: these functions allow to associate an image list with
528 // the control and retrieve it. Note that when assigned with
529 // SetImageList, the control does _not_ delete
530 // the associated image list when it's deleted in order to allow image
531 // lists to be shared between different controls. If you use
532 // AssignImageList, the control _does_ delete the image list.
533 //
534 // The normal image list is for the icons which correspond to the
535 // normal tree item state (whether it is selected or not).
536 // Additionally, the application might choose to show a state icon
537 // which corresponds to an app-defined item state (for example,
538 // checked/unchecked) which are taken from the state image list.
539 wxImageList *GetImageList() const;
540 wxImageList *GetStateImageList() const;
541 wxImageList *GetButtonsImageList() const;
542
543 void SetImageList(wxImageList *imageList);
544 void SetStateImageList(wxImageList *imageList);
545 void SetButtonsImageList(wxImageList *imageList);
546
547 %apply SWIGTYPE *DISOWN { wxImageList *imageList };
548 void AssignImageList(wxImageList *imageList);
549 void AssignStateImageList(wxImageList *imageList);
550 void AssignButtonsImageList(wxImageList *imageList);
551 %clear wxImageList *imageList;
552
553
554 // adds a column
555 void AddColumn(const wxString& text);
556 %name(AddColumnInfo) void AddColumn(const wxTreeListColumnInfo& col);
557
558 // inserts a column before the given one
559 void InsertColumn(size_t before, const wxString& text);
560 %name(InsertColumnInfo) void InsertColumn(size_t before, const wxTreeListColumnInfo& col);
561
562 // deletes the given column - does not delete the corresponding column
563 // of each item
564 void RemoveColumn(size_t column);
565
566 // returns the number of columns in the ctrl
567 size_t GetColumnCount() const;
568
569 void SetColumnWidth(size_t column, size_t width);
570 int GetColumnWidth(size_t column) const;
571
572 // tells which column is the "main" one, i.e. the "threaded" one
573 void SetMainColumn(size_t column);
574 size_t GetMainColumn() const;
575
576 void SetColumnText(size_t column, const wxString& text);
577 wxString GetColumnText(size_t column) const;
578
579 void SetColumn(size_t column, const wxTreeListColumnInfo& info);
580 wxTreeListColumnInfo& GetColumn(size_t column);
581
582 // other column-related methods
583 void SetColumnAlignment(size_t column, wxTreeListColumnAlign align);
584 wxTreeListColumnAlign GetColumnAlignment(size_t column) const;
585
586 void SetColumnImage(size_t column, int image);
587 int GetColumnImage(size_t column) const;
588
589
590 %extend {
591 // retrieves item's label of the given column (main column by default)
592 wxString GetItemText(const wxTreeItemId& item, int column = -1) {
593 if (column < 0) column = self->GetMainColumn();
594 return self->GetItemText(item, column);
595 }
596
597 // get one of the images associated with the item (normal by default)
598 int GetItemImage(const wxTreeItemId& item, int column = -1,
599 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
600 if (column < 0) column = self->GetMainColumn();
601 return self->GetItemImage(item, column, which);
602 }
603
604 // set item's label (main column by default)
605 void SetItemText(const wxTreeItemId& item, const wxString& text, int column = -1) {
606 if (column < 0) column = self->GetMainColumn();
607 self->SetItemText(item, column, text);
608 }
609
610 // set one of the images associated with the item (normal by default)
611 // the which parameter is ignored for all columns but the main one
612 void SetItemImage(const wxTreeItemId& item, int image, int column = -1,
613 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
614 if (column < 0) column = self->GetMainColumn();
615 self->SetItemImage(item, column, image, which);
616 }
617
618
619 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
620 // if needed.
621 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
622 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
623 if (data == NULL) {
624 data = new wxPyTreeItemData();
625 data->SetId(item); // set the id
626 self->SetItemData(item, data);
627 }
628 return data;
629 }
630
631 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
632 data->SetId(item); // set the id
633 self->SetItemData(item, data);
634 }
635
636 // [Get|Set]ItemPyData are short-cuts. Also made somewhat crash-proof by
637 // automatically creating data classes.
638 PyObject* GetItemPyData(const wxTreeItemId& item) {
639 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
640 if (data == NULL) {
641 data = new wxPyTreeItemData();
642 data->SetId(item); // set the id
643 self->SetItemData(item, data);
644 }
645 return data->GetData();
646 }
647
648 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
649 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
650 if (data == NULL) {
651 data = new wxPyTreeItemData(obj);
652 data->SetId(item); // set the id
653 self->SetItemData(item, data);
654 } else
655 data->SetData(obj);
656 }
657 }
658 %pythoncode { GetPyData = GetItemPyData }
659 %pythoncode { SetPyData = SetItemPyData }
660
661
662 // force appearance of [+] button near the item. This is useful to
663 // allow the user to expand the items which don't have any children now
664 // - but instead add them only when needed, thus minimizing memory
665 // usage and loading time.
666 void SetItemHasChildren(const wxTreeItemId& item, bool has = True);
667
668 // the item will be shown in bold
669 void SetItemBold(const wxTreeItemId& item, bool bold = True);
670
671 // set the item's text colour
672 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
673
674 // set the item's background colour
675 void SetItemBackgroundColour(const wxTreeItemId& item,
676 const wxColour& col);
677
678 // set the item's font (should be of the same height for all items)
679 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
680
681
682 bool GetItemBold(const wxTreeItemId& item) const;
683 wxColour GetItemTextColour(const wxTreeItemId& item) const;
684 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
685 wxFont GetItemFont(const wxTreeItemId& item) const;
686
687 // is the item visible (it might be outside the view or not expanded)?
688 bool IsVisible(const wxTreeItemId& item) const;
689
690 // does the item has any children?
691 bool ItemHasChildren(const wxTreeItemId& item) const;
692
693 // is the item expanded (only makes sense if HasChildren())?
694 bool IsExpanded(const wxTreeItemId& item) const;
695
696 // is this item currently selected (the same as has focus)?
697 bool IsSelected(const wxTreeItemId& item) const;
698
699 // is item text in bold font?
700 bool IsBold(const wxTreeItemId& item) const;
701
702 // if 'recursively' is False, only immediate children count, otherwise
703 // the returned number is the number of all items in this branch
704 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = True);
705
706
707 // wxTreeItemId.IsOk() will return False if there is no such item
708
709 // get the root tree item
710 wxTreeItemId GetRootItem() const;
711
712 // get the item currently selected (may return NULL if no selection)
713 wxTreeItemId GetSelection() const;
714
715 // get the items currently selected, return the number of such item
716 //size_t GetSelections(wxArrayTreeItemIds&) const;
717 %extend {
718 PyObject* GetSelections() {
719 bool blocked = wxPyBeginBlockThreads();
720 PyObject* rval = PyList_New(0);
721 wxArrayTreeItemIds array;
722 size_t num, x;
723 num = self->GetSelections(array);
724 for (x=0; x < num; x++) {
725 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
726 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True);
727 PyList_Append(rval, item);
728 }
729 wxPyEndBlockThreads(blocked);
730 return rval;
731 }
732 }
733
734
735 // get the parent of this item (may return NULL if root)
736 %name(GetItemParent)wxTreeItemId GetParent(const wxTreeItemId& item) const;
737
738 // for this enumeration function you must pass in a "cookie" parameter
739 // which is opaque for the application but is necessary for the library
740 // to make these functions reentrant (i.e. allow more than one
741 // enumeration on one and the same object simultaneously). Of course,
742 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
743 // the same!
744
745
746 %extend {
747 // Get the first child of this item. Returns a wxTreeItemId and an
748 // opaque "cookie" value that should be passed to GetNextChild in
749 // order to continue the search.
750 PyObject* GetFirstChild(const wxTreeItemId& item) {
751 long cookie = 0;
752 wxTreeItemId* ritem = new wxTreeItemId(self->GetFirstChild(item, cookie));
753 bool blocked = wxPyBeginBlockThreads();
754 PyObject* tup = PyTuple_New(2);
755 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
756 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
757 wxPyEndBlockThreads(blocked);
758 return tup;
759 }
760
761
762 // Get the next child of this item. The cookie parameter is the 2nd
763 // value returned from GetFirstChild or the previous GetNextChild.
764 // Returns a wxTreeItemId and an opaque "cookie" value that should be
765 // passed to GetNextChild in order to continue the search.
766 PyObject* GetNextChild(const wxTreeItemId& item, long cookie) {
767 wxTreeItemId* ritem = new wxTreeItemId(self->GetNextChild(item, cookie));
768 bool blocked = wxPyBeginBlockThreads();
769 PyObject* tup = PyTuple_New(2);
770 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
771 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
772 wxPyEndBlockThreads(blocked);
773 return tup;
774 }
775 }
776
777 // get the last child of this item - this method doesn't use cookies
778 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
779
780 // get the next sibling of this item
781 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
782
783 // get the previous sibling
784 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
785
786 // get first visible item
787 wxTreeItemId GetFirstVisibleItem() const;
788
789 // get the next visible item: item must be visible itself!
790 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
791 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
792
793 // get the previous visible item: item must be visible itself!
794 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
795
796 // Only for internal use right now, but should probably be public
797 wxTreeItemId GetNext(const wxTreeItemId& item) const;
798
799
800 // add the root node to the tree
801 wxTreeItemId AddRoot(const wxString& text,
802 int image = -1, int selectedImage = -1,
803 wxPyTreeItemData *data = NULL);
804
805 // insert a new item in as the first child of the parent
806 wxTreeItemId PrependItem(const wxTreeItemId& parent,
807 const wxString& text,
808 int image = -1, int selectedImage = -1,
809 wxPyTreeItemData *data = NULL);
810
811 // insert a new item after a given one
812 wxTreeItemId InsertItem(const wxTreeItemId& parent,
813 const wxTreeItemId& idPrevious,
814 const wxString& text,
815 int image = -1, int selectedImage = -1,
816 wxPyTreeItemData *data = NULL);
817
818 // insert a new item before the one with the given index
819 %name(InsertItemBefore)
820 wxTreeItemId InsertItem(const wxTreeItemId& parent,
821 size_t index,
822 const wxString& text,
823 int image = -1, int selectedImage = -1,
824 wxPyTreeItemData *data = NULL);
825
826 // insert a new item in as the last child of the parent
827 wxTreeItemId AppendItem(const wxTreeItemId& parent,
828 const wxString& text,
829 int image = -1, int selectedImage = -1,
830 wxPyTreeItemData *data = NULL);
831
832 // delete this item and associated data if any
833 void Delete(const wxTreeItemId& item);
834
835 // delete all children (but don't delete the item itself)
836 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
837 void DeleteChildren(const wxTreeItemId& item);
838
839 // delete all items from the tree
840 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
841 void DeleteAllItems();
842
843 // expand this item
844 void Expand(const wxTreeItemId& item);
845
846 // expand this item and all subitems recursively
847 void ExpandAll(const wxTreeItemId& item);
848
849 // collapse the item without removing its children
850 void Collapse(const wxTreeItemId& item);
851
852 // collapse the item and remove all children
853 void CollapseAndReset(const wxTreeItemId& item);
854
855 // toggles the current state
856 void Toggle(const wxTreeItemId& item);
857
858 // remove the selection from currently selected item (if any)
859 void Unselect();
860 void UnselectAll();
861
862 // select this item
863 void SelectItem(const wxTreeItemId& item, bool unselect_others=True,
864 bool extended_select=False);
865
866 // make sure this item is visible (expanding the parent item and/or
867 // scrolling to this item if necessary)
868 void EnsureVisible(const wxTreeItemId& item);
869
870 // scroll to this item (but don't expand its parent)
871 void ScrollTo(const wxTreeItemId& item);
872
873 // Returns wxTreeItemId, flags, and column
874 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT, int& OUTPUT);
875
876 %extend {
877 // get the bounding rectangle of the item (or of its label only)
878 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
879 wxRect rect;
880 if (self->GetBoundingRect(item, rect, textOnly)) {
881 bool blocked = wxPyBeginBlockThreads();
882 wxRect* r = new wxRect(rect);
883 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1);
884 wxPyEndBlockThreads(blocked);
885 return val;
886 }
887 else {
888 RETURN_NONE();
889 }
890 }
891 }
892
893
894 // Start editing the item label: this (temporarily) replaces the item
895 // with a one line edit control. The item will be selected if it hadn't
896 // been before.
897 void EditLabel( const wxTreeItemId& item );
898 void Edit( const wxTreeItemId& item );
899
900 // sort the children of this item using OnCompareItems
901 void SortChildren(const wxTreeItemId& item);
902
903 // get the selected item image
904 int GetItemSelectedImage(const wxTreeItemId& item) const;
905
906 // set the selected item image
907 void SetItemSelectedImage(const wxTreeItemId& item, int image);
908
909
910 wxWindow* GetHeaderWindow() const;
911 wxWindow* GetMainWindow() const;
912
913 };
914
915
916
917
918 //----------------------------------------------------------------------
919 //----------------------------------------------------------------------
920
921 %init %{
922
923 wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow");
924 wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl");
925 %}
926
927
928 %pragma(python) include="_gizmoextras.py";
929
930 //----------------------------------------------------------------------
931 //----------------------------------------------------------------------
932
933
934
935
936
937