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