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