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