]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/gizmos/gizmos.i
Regenerated metadata
[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 bool blocked = 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(blocked);
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 bool blocked = 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(blocked);
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 %pythoncode { GetPyData = GetItemPyData }
658 %pythoncode { SetPyData = SetItemPyData }
659
660
661 // force appearance of [+] button near the item. This is useful to
662 // allow the user to expand the items which don't have any children now
663 // - but instead add them only when needed, thus minimizing memory
664 // usage and loading time.
665 void SetItemHasChildren(const wxTreeItemId& item, bool has = True);
666
667 // the item will be shown in bold
668 void SetItemBold(const wxTreeItemId& item, bool bold = True);
669
670 // set the item's text colour
671 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
672
673 // set the item's background colour
674 void SetItemBackgroundColour(const wxTreeItemId& item,
675 const wxColour& col);
676
677 // set the item's font (should be of the same height for all items)
678 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
679
680
681 bool GetItemBold(const wxTreeItemId& item) const;
682 wxColour GetItemTextColour(const wxTreeItemId& item) const;
683 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
684 wxFont GetItemFont(const wxTreeItemId& item) const;
685
686 // is the item visible (it might be outside the view or not expanded)?
687 bool IsVisible(const wxTreeItemId& item) const;
688
689 // does the item has any children?
690 bool ItemHasChildren(const wxTreeItemId& item) const;
691
692 // is the item expanded (only makes sense if HasChildren())?
693 bool IsExpanded(const wxTreeItemId& item) const;
694
695 // is this item currently selected (the same as has focus)?
696 bool IsSelected(const wxTreeItemId& item) const;
697
698 // is item text in bold font?
699 bool IsBold(const wxTreeItemId& item) const;
700
701 // if 'recursively' is False, only immediate children count, otherwise
702 // the returned number is the number of all items in this branch
703 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = True);
704
705
706 // wxTreeItemId.IsOk() will return False if there is no such item
707
708 // get the root tree item
709 wxTreeItemId GetRootItem() const;
710
711 // get the item currently selected (may return NULL if no selection)
712 wxTreeItemId GetSelection() const;
713
714 // get the items currently selected, return the number of such item
715 //size_t GetSelections(wxArrayTreeItemIds&) const;
716 %extend {
717 PyObject* GetSelections() {
718 bool blocked = wxPyBeginBlockThreads();
719 PyObject* rval = PyList_New(0);
720 wxArrayTreeItemIds array;
721 size_t num, x;
722 num = self->GetSelections(array);
723 for (x=0; x < num; x++) {
724 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
725 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True);
726 PyList_Append(rval, item);
727 }
728 wxPyEndBlockThreads(blocked);
729 return rval;
730 }
731 }
732
733
734 // get the parent of this item (may return NULL if root)
735 %name(GetItemParent)wxTreeItemId GetParent(const wxTreeItemId& item) const;
736
737 // for this enumeration function you must pass in a "cookie" parameter
738 // which is opaque for the application but is necessary for the library
739 // to make these functions reentrant (i.e. allow more than one
740 // enumeration on one and the same object simultaneously). Of course,
741 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
742 // the same!
743
744
745 %extend {
746 // Get the first child of this item. Returns a wxTreeItemId and an
747 // opaque "cookie" value that should be passed to GetNextChild in
748 // order to continue the search.
749 PyObject* GetFirstChild(const wxTreeItemId& item) {
750 long cookie = 0;
751 wxTreeItemId ritem = self->GetFirstChild(item, cookie);
752 bool blocked = wxPyBeginBlockThreads();
753 PyObject* tup = PyTuple_New(2);
754 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), true));
755 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
756 wxPyEndBlockThreads(blocked);
757 return tup;
758 }
759
760
761 // Get the next child of this item. The cookie parameter is the 2nd
762 // value returned from GetFirstChild or the previous GetNextChild.
763 // Returns a wxTreeItemId and an opaque "cookie" value that should be
764 // passed to GetNextChild in order to continue the search.
765 PyObject* GetNextChild(const wxTreeItemId& item, long cookie) {
766 wxTreeItemId ritem = self->GetNextChild(item, cookie);
767 bool blocked = wxPyBeginBlockThreads();
768 PyObject* tup = PyTuple_New(2);
769 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), true));
770 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
771 wxPyEndBlockThreads(blocked);
772 return tup;
773 }
774 }
775
776 // get the last child of this item - this method doesn't use cookies
777 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
778
779 // get the next sibling of this item
780 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
781
782 // get the previous sibling
783 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
784
785 // get first visible item
786 wxTreeItemId GetFirstVisibleItem() const;
787
788 // get the next visible item: item must be visible itself!
789 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
790 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
791
792 // get the previous visible item: item must be visible itself!
793 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
794
795 // Only for internal use right now, but should probably be public
796 wxTreeItemId GetNext(const wxTreeItemId& item) const;
797
798
799 // add the root node to the tree
800 wxTreeItemId AddRoot(const wxString& text,
801 int image = -1, int selectedImage = -1,
802 wxPyTreeItemData *data = NULL);
803
804 // insert a new item in as the first child of the parent
805 wxTreeItemId PrependItem(const wxTreeItemId& parent,
806 const wxString& text,
807 int image = -1, int selectedImage = -1,
808 wxPyTreeItemData *data = NULL);
809
810 // insert a new item after a given one
811 wxTreeItemId InsertItem(const wxTreeItemId& parent,
812 const wxTreeItemId& idPrevious,
813 const wxString& text,
814 int image = -1, int selectedImage = -1,
815 wxPyTreeItemData *data = NULL);
816
817 // insert a new item before the one with the given index
818 %name(InsertItemBefore)
819 wxTreeItemId InsertItem(const wxTreeItemId& parent,
820 size_t index,
821 const wxString& text,
822 int image = -1, int selectedImage = -1,
823 wxPyTreeItemData *data = NULL);
824
825 // insert a new item in as the last child of the parent
826 wxTreeItemId AppendItem(const wxTreeItemId& parent,
827 const wxString& text,
828 int image = -1, int selectedImage = -1,
829 wxPyTreeItemData *data = NULL);
830
831 // delete this item and associated data if any
832 void Delete(const wxTreeItemId& item);
833
834 // delete all children (but don't delete the item itself)
835 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
836 void DeleteChildren(const wxTreeItemId& item);
837
838 // delete all items from the tree
839 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
840 void DeleteAllItems();
841
842 // expand this item
843 void Expand(const wxTreeItemId& item);
844
845 // expand this item and all subitems recursively
846 void ExpandAll(const wxTreeItemId& item);
847
848 // collapse the item without removing its children
849 void Collapse(const wxTreeItemId& item);
850
851 // collapse the item and remove all children
852 void CollapseAndReset(const wxTreeItemId& item);
853
854 // toggles the current state
855 void Toggle(const wxTreeItemId& item);
856
857 // remove the selection from currently selected item (if any)
858 void Unselect();
859 void UnselectAll();
860
861 // select this item
862 void SelectItem(const wxTreeItemId& item, bool unselect_others=True,
863 bool extended_select=False);
864
865 // make sure this item is visible (expanding the parent item and/or
866 // scrolling to this item if necessary)
867 void EnsureVisible(const wxTreeItemId& item);
868
869 // scroll to this item (but don't expand its parent)
870 void ScrollTo(const wxTreeItemId& item);
871
872 // Returns wxTreeItemId, flags, and column
873 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT, int& OUTPUT);
874
875 %extend {
876 // get the bounding rectangle of the item (or of its label only)
877 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
878 wxRect rect;
879 if (self->GetBoundingRect(item, rect, textOnly)) {
880 bool blocked = wxPyBeginBlockThreads();
881 wxRect* r = new wxRect(rect);
882 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1);
883 wxPyEndBlockThreads(blocked);
884 return val;
885 }
886 else {
887 RETURN_NONE();
888 }
889 }
890 }
891
892
893 // Start editing the item label: this (temporarily) replaces the item
894 // with a one line edit control. The item will be selected if it hadn't
895 // been before.
896 void EditLabel( const wxTreeItemId& item );
897 void Edit( const wxTreeItemId& item );
898
899 // sort the children of this item using OnCompareItems
900 void SortChildren(const wxTreeItemId& item);
901
902 // get the selected item image
903 int GetItemSelectedImage(const wxTreeItemId& item) const;
904
905 // set the selected item image
906 void SetItemSelectedImage(const wxTreeItemId& item, int image);
907
908
909 wxWindow* GetHeaderWindow() const;
910 wxWindow* GetMainWindow() const;
911
912 };
913
914
915
916
917 //----------------------------------------------------------------------
918 //----------------------------------------------------------------------
919
920 %init %{
921
922 wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow");
923 wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl");
924 %}
925
926
927 %pragma(python) include="_gizmoextras.py";
928
929 //----------------------------------------------------------------------
930 //----------------------------------------------------------------------
931
932
933
934
935
936