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