]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/gizmos/gizmos.i
Show how to set print data options when using HTMLEasyPrinting
[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, "dynamicSashWindow");
42 MAKE_CONST_WXSTRING2(EditableListBoxNameStr, "editableListBox");
43 MAKE_CONST_WXSTRING2(TreeListCtrlNameStr, "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 %addtofunc wxDynamicSashWindow "self._setOORInfo(self)"
139 %addtofunc 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 %addtofunc wxEditableListBox "self._setOORInfo(self)"
178 %addtofunc 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 %addtofunc wxRemotelyScrolledTreeCtrl "self._setOORInfo(self)"
228 %addtofunc wxRemotelyScrolledTreeCtrl() ""
229
230 wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id,
231 const wxPoint& pos = wxDefaultPosition,
232 const wxSize& size = wxDefaultSize,
233 long style = wxTR_HAS_BUTTONS);
234
235
236 void HideVScrollbar();
237
238 // Adjust the containing wxScrolledWindow's scrollbars appropriately
239 void AdjustRemoteScrollbars();
240
241 // Find the scrolled window that contains this control
242 wxScrolledWindow* GetScrolledWindow() const;
243
244 // Scroll to the given line (in scroll units where each unit is
245 // the height of an item)
246 void ScrollToLine(int posHoriz, int posVert);
247
248 // The companion window is one which will get notified when certain
249 // events happen such as node expansion
250 void SetCompanionWindow(wxWindow* companion);
251 wxWindow* GetCompanionWindow() const;
252 };
253
254
255
256 /*
257 * wxTreeCompanionWindow
258 *
259 * A window displaying values associated with tree control items.
260 */
261
262 %{
263 class wxPyTreeCompanionWindow: public wxTreeCompanionWindow
264 {
265 public:
266 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
267 const wxPoint& pos = wxDefaultPosition,
268 const wxSize& size = wxDefaultSize,
269 long style = 0)
270 : wxTreeCompanionWindow(parent, id, pos, size, style) {}
271
272
273 virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect) {
274 bool found;
275 wxPyBeginBlockThreads();
276 if ((found = wxPyCBH_findCallback(m_myInst, "DrawItem"))) {
277 PyObject* dcobj = wxPyMake_wxObject(&dc);
278 PyObject* idobj = wxPyConstructObject((void*)&id, wxT("wxTreeItemId"), False);
279 PyObject* recobj= wxPyConstructObject((void*)&rect, wxT("wxRect"), False);
280 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", dcobj, idobj, recobj));
281 Py_DECREF(dcobj);
282 Py_DECREF(idobj);
283 Py_DECREF(recobj);
284 }
285 wxPyEndBlockThreads();
286 if (! found)
287 wxTreeCompanionWindow::DrawItem(dc, id, rect);
288 }
289
290 PYPRIVATE;
291 };
292 %}
293
294
295 %name(TreeCompanionWindow) class wxPyTreeCompanionWindow: public wxWindow
296 {
297 public:
298 %addtofunc wxPyTreeCompanionWindow "self._setOORInfo(self);self._setCallbackInfo(self, TreeCompanionWindow)"
299 %addtofunc 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 %addtofunc wxThinSplitterWindow "self._setOORInfo(self)"
324 %addtofunc 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 %addtofunc wxSplitterScrolledWindow "self._setOORInfo(self)"
347 %addtofunc 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 %addtofunc wxLEDNumberCtrl "self._setOORInfo(self)"
376 %addtofunc wxLEDNumberCtrl() ""
377
378 wxLEDNumberCtrl(wxWindow *parent, wxWindowID id = -1,
379 const wxPoint& pos = wxDefaultPosition,
380 const wxSize& size = wxDefaultSize,
381 long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED);
382 %name(PreLEDNumberCtrl) wxLEDNumberCtrl();
383
384 bool Create(wxWindow *parent, wxWindowID id = -1,
385 const wxPoint& pos = wxDefaultPosition,
386 const wxSize& size = wxDefaultSize,
387 long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED);
388
389 wxLEDValueAlign GetAlignment() const;
390 bool GetDrawFaded() const;
391 const wxString &GetValue() const;
392
393 void SetAlignment(wxLEDValueAlign Alignment, bool Redraw = true);
394 void SetDrawFaded(bool DrawFaded, bool Redraw = true);
395 void SetValue(const wxString &Value, bool Redraw = true);
396
397 };
398
399
400
401 //----------------------------------------------------------------------------
402 // wxTreeListCtrl - the multicolumn tree control
403 //----------------------------------------------------------------------------
404
405 enum wxTreeListColumnAlign {
406 wxTL_ALIGN_LEFT,
407 wxTL_ALIGN_RIGHT,
408 wxTL_ALIGN_CENTER
409 };
410
411
412
413 enum {
414 wxTREE_HITTEST_ONITEMCOLUMN
415 };
416
417
418
419
420 class wxTreeListColumnInfo: public wxObject {
421 public:
422 wxTreeListColumnInfo(const wxString& text = wxPyEmptyString,
423 int image = -1,
424 size_t width = 100,
425 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
426
427 wxTreeListColumnAlign GetAlignment() const;
428 wxString GetText() const;
429 int GetImage() const;
430 int GetSelectedImage() const;
431 size_t GetWidth() const;
432
433 void SetAlignment(wxTreeListColumnAlign alignment);
434 void SetText(const wxString& text);
435 void SetImage(int image);
436 void SetSelectedImage(int image);
437 void SetWidth(size_t with);
438 };
439
440
441
442
443 %{ // C++ version of Python aware control
444 class wxPyTreeListCtrl : public wxTreeListCtrl {
445 DECLARE_ABSTRACT_CLASS(wxPyTreeListCtrl);
446 public:
447 wxPyTreeListCtrl() : wxTreeListCtrl() {}
448 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id,
449 const wxPoint& pos,
450 const wxSize& size,
451 long style,
452 const wxValidator &validator,
453 const wxString& name) :
454 wxTreeListCtrl(parent, id, pos, size, style, validator, name) {}
455
456 int OnCompareItems(const wxTreeItemId& item1,
457 const wxTreeItemId& item2) {
458 int rval = 0;
459 bool found;
460 wxPyBeginBlockThreads();
461 if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) {
462 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), 0);
463 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), 0);
464 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2));
465 Py_DECREF(o1);
466 Py_DECREF(o2);
467 }
468 wxPyEndBlockThreads();
469 if (! found)
470 rval = wxTreeListCtrl::OnCompareItems(item1, item2);
471 return rval;
472 }
473 PYPRIVATE;
474 };
475
476 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeListCtrl, wxTreeListCtrl)
477
478 %}
479
480
481
482
483
484
485 %name(TreeListCtrl) class wxPyTreeListCtrl : public wxControl
486 {
487 public:
488 %addtofunc wxPyTreeListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeListCtrl)"
489 %addtofunc 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 %addtofunc AssignImageList "args[1].thisown = 0";
547 void AssignImageList(wxImageList *imageList);
548
549 %addtofunc AssignStateImageList "args[1].thisown = 0";
550 void AssignStateImageList(wxImageList *imageList);
551
552 %addtofunc AssignButtonsImageList "args[1].thisown = 0";
553 void AssignButtonsImageList(wxImageList *imageList);
554
555
556
557 // adds a column
558 void AddColumn(const wxString& text);
559 %name(AddColumnInfo) void AddColumn(const wxTreeListColumnInfo& col);
560
561 // inserts a column before the given one
562 void InsertColumn(size_t before, const wxString& text);
563 %name(InsertColumnInfo) void InsertColumn(size_t before, const wxTreeListColumnInfo& col);
564
565 // deletes the given column - does not delete the corresponding column
566 // of each item
567 void RemoveColumn(size_t column);
568
569 // returns the number of columns in the ctrl
570 size_t GetColumnCount() const;
571
572 void SetColumnWidth(size_t column, size_t width);
573 int GetColumnWidth(size_t column) const;
574
575 // tells which column is the "main" one, i.e. the "threaded" one
576 void SetMainColumn(size_t column);
577 size_t GetMainColumn() const;
578
579 void SetColumnText(size_t column, const wxString& text);
580 wxString GetColumnText(size_t column) const;
581
582 void SetColumn(size_t column, const wxTreeListColumnInfo& info);
583 wxTreeListColumnInfo& GetColumn(size_t column);
584
585 // other column-related methods
586 void SetColumnAlignment(size_t column, wxTreeListColumnAlign align);
587 wxTreeListColumnAlign GetColumnAlignment(size_t column) const;
588
589 void SetColumnImage(size_t column, int image);
590 int GetColumnImage(size_t column) const;
591
592
593 %extend {
594 // retrieves item's label of the given column (main column by default)
595 wxString GetItemText(const wxTreeItemId& item, int column = -1) {
596 if (column < 0) column = self->GetMainColumn();
597 return self->GetItemText(item, column);
598 }
599
600 // get one of the images associated with the item (normal by default)
601 int GetItemImage(const wxTreeItemId& item, int column = -1,
602 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
603 if (column < 0) column = self->GetMainColumn();
604 return self->GetItemImage(item, column, which);
605 }
606
607 // set item's label (main column by default)
608 void SetItemText(const wxTreeItemId& item, const wxString& text, int column = -1) {
609 if (column < 0) column = self->GetMainColumn();
610 self->SetItemText(item, column, text);
611 }
612
613 // set one of the images associated with the item (normal by default)
614 // the which parameter is ignored for all columns but the main one
615 void SetItemImage(const wxTreeItemId& item, int image, int column = -1,
616 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
617 if (column < 0) column = self->GetMainColumn();
618 self->SetItemImage(item, column, image, which);
619 }
620
621
622 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
623 // if needed.
624 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
625 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
626 if (data == NULL) {
627 data = new wxPyTreeItemData();
628 data->SetId(item); // set the id
629 self->SetItemData(item, data);
630 }
631 return data;
632 }
633
634 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
635 data->SetId(item); // set the id
636 self->SetItemData(item, data);
637 }
638
639 // [Get|Set]ItemPyData are short-cuts. Also made somewhat crash-proof by
640 // automatically creating data classes.
641 PyObject* GetItemPyData(const wxTreeItemId& item) {
642 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
643 if (data == NULL) {
644 data = new wxPyTreeItemData();
645 data->SetId(item); // set the id
646 self->SetItemData(item, data);
647 }
648 return data->GetData();
649 }
650
651 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
652 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
653 if (data == NULL) {
654 data = new wxPyTreeItemData(obj);
655 data->SetId(item); // set the id
656 self->SetItemData(item, data);
657 } else
658 data->SetData(obj);
659 }
660 }
661
662
663 // force appearance of [+] button near the item. This is useful to
664 // allow the user to expand the items which don't have any children now
665 // - but instead add them only when needed, thus minimizing memory
666 // usage and loading time.
667 void SetItemHasChildren(const wxTreeItemId& item, bool has = True);
668
669 // the item will be shown in bold
670 void SetItemBold(const wxTreeItemId& item, bool bold = True);
671
672 // set the item's text colour
673 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
674
675 // set the item's background colour
676 void SetItemBackgroundColour(const wxTreeItemId& item,
677 const wxColour& col);
678
679 // set the item's font (should be of the same height for all items)
680 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
681
682
683 bool GetItemBold(const wxTreeItemId& item) const;
684 wxColour GetItemTextColour(const wxTreeItemId& item) const;
685 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
686 wxFont GetItemFont(const wxTreeItemId& item) const;
687
688 // is the item visible (it might be outside the view or not expanded)?
689 bool IsVisible(const wxTreeItemId& item) const;
690
691 // does the item has any children?
692 bool ItemHasChildren(const wxTreeItemId& item) const;
693
694 // is the item expanded (only makes sense if HasChildren())?
695 bool IsExpanded(const wxTreeItemId& item) const;
696
697 // is this item currently selected (the same as has focus)?
698 bool IsSelected(const wxTreeItemId& item) const;
699
700 // is item text in bold font?
701 bool IsBold(const wxTreeItemId& item) const;
702
703 // if 'recursively' is False, only immediate children count, otherwise
704 // the returned number is the number of all items in this branch
705 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = True);
706
707
708 // wxTreeItemId.IsOk() will return False if there is no such item
709
710 // get the root tree item
711 wxTreeItemId GetRootItem() const;
712
713 // get the item currently selected (may return NULL if no selection)
714 wxTreeItemId GetSelection() const;
715
716 // get the items currently selected, return the number of such item
717 //size_t GetSelections(wxArrayTreeItemIds&) const;
718 %extend {
719 PyObject* GetSelections() {
720 wxPyBeginBlockThreads();
721 PyObject* rval = PyList_New(0);
722 wxArrayTreeItemIds array;
723 size_t num, x;
724 num = self->GetSelections(array);
725 for (x=0; x < num; x++) {
726 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
727 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True);
728 PyList_Append(rval, item);
729 }
730 wxPyEndBlockThreads();
731 return rval;
732 }
733 }
734
735
736 // get the parent of this item (may return NULL if root)
737 %name(GetItemParent)wxTreeItemId GetParent(const wxTreeItemId& item) const;
738
739 // for this enumeration function you must pass in a "cookie" parameter
740 // which is opaque for the application but is necessary for the library
741 // to make these functions reentrant (i.e. allow more than one
742 // enumeration on one and the same object simultaneously). Of course,
743 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
744 // the same!
745
746
747 %extend {
748 // Get the first child of this item. Returns a wxTreeItemId and an
749 // opaque "cookie" value that should be passed to GetNextChild in
750 // order to continue the search.
751 PyObject* GetFirstChild(const wxTreeItemId& item) {
752 long cookie = 0;
753 wxTreeItemId ritem = self->GetFirstChild(item, cookie);
754 wxPyBeginBlockThreads();
755 PyObject* tup = PyTuple_New(2);
756 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), true));
757 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
758 wxPyEndBlockThreads();
759 return tup;
760 }
761
762
763 // Get the next child of this item. The cookie parameter is the 2nd
764 // value returned from GetFirstChild or the previous GetNextChild.
765 // Returns a wxTreeItemId and an opaque "cookie" value that should be
766 // passed to GetNextChild in order to continue the search.
767 PyObject* GetNextChild(const wxTreeItemId& item, long cookie) {
768 wxTreeItemId ritem = self->GetNextChild(item, cookie);
769 wxPyBeginBlockThreads();
770 PyObject* tup = PyTuple_New(2);
771 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), true));
772 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
773 wxPyEndBlockThreads();
774 return tup;
775 }
776 }
777
778 // get the last child of this item - this method doesn't use cookies
779 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
780
781 // get the next sibling of this item
782 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
783
784 // get the previous sibling
785 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
786
787 // get first visible item
788 wxTreeItemId GetFirstVisibleItem() const;
789
790 // get the next visible item: item must be visible itself!
791 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
792 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
793
794 // get the previous visible item: item must be visible itself!
795 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
796
797 // Only for internal use right now, but should probably be public
798 wxTreeItemId GetNext(const wxTreeItemId& item) const;
799
800
801 // add the root node to the tree
802 wxTreeItemId AddRoot(const wxString& text,
803 int image = -1, int selectedImage = -1,
804 wxPyTreeItemData *data = NULL);
805
806 // insert a new item in as the first child of the parent
807 wxTreeItemId PrependItem(const wxTreeItemId& parent,
808 const wxString& text,
809 int image = -1, int selectedImage = -1,
810 wxPyTreeItemData *data = NULL);
811
812 // insert a new item after a given one
813 wxTreeItemId InsertItem(const wxTreeItemId& parent,
814 const wxTreeItemId& idPrevious,
815 const wxString& text,
816 int image = -1, int selectedImage = -1,
817 wxPyTreeItemData *data = NULL);
818
819 // insert a new item before the one with the given index
820 %name(InsertItemBefore)
821 wxTreeItemId InsertItem(const wxTreeItemId& parent,
822 size_t index,
823 const wxString& text,
824 int image = -1, int selectedImage = -1,
825 wxPyTreeItemData *data = NULL);
826
827 // insert a new item in as the last child of the parent
828 wxTreeItemId AppendItem(const wxTreeItemId& parent,
829 const wxString& text,
830 int image = -1, int selectedImage = -1,
831 wxPyTreeItemData *data = NULL);
832
833 // delete this item and associated data if any
834 void Delete(const wxTreeItemId& item);
835
836 // delete all children (but don't delete the item itself)
837 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
838 void DeleteChildren(const wxTreeItemId& item);
839
840 // delete all items from the tree
841 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
842 void DeleteAllItems();
843
844 // expand this item
845 void Expand(const wxTreeItemId& item);
846
847 // expand this item and all subitems recursively
848 void ExpandAll(const wxTreeItemId& item);
849
850 // collapse the item without removing its children
851 void Collapse(const wxTreeItemId& item);
852
853 // collapse the item and remove all children
854 void CollapseAndReset(const wxTreeItemId& item);
855
856 // toggles the current state
857 void Toggle(const wxTreeItemId& item);
858
859 // remove the selection from currently selected item (if any)
860 void Unselect();
861 void UnselectAll();
862
863 // select this item
864 void SelectItem(const wxTreeItemId& item, bool unselect_others=True,
865 bool extended_select=False);
866
867 // make sure this item is visible (expanding the parent item and/or
868 // scrolling to this item if necessary)
869 void EnsureVisible(const wxTreeItemId& item);
870
871 // scroll to this item (but don't expand its parent)
872 void ScrollTo(const wxTreeItemId& item);
873
874 // Returns wxTreeItemId, flags, and column
875 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT, int& OUTPUT);
876
877 %extend {
878 // get the bounding rectangle of the item (or of its label only)
879 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
880 wxRect rect;
881 if (self->GetBoundingRect(item, rect, textOnly)) {
882 wxPyBeginBlockThreads();
883 wxRect* r = new wxRect(rect);
884 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1);
885 wxPyEndBlockThreads();
886 return val;
887 }
888 else {
889 RETURN_NONE();
890 }
891 }
892 }
893
894
895 // Start editing the item label: this (temporarily) replaces the item
896 // with a one line edit control. The item will be selected if it hadn't
897 // been before.
898 void EditLabel( const wxTreeItemId& item );
899 void Edit( const wxTreeItemId& item );
900
901 // sort the children of this item using OnCompareItems
902 void SortChildren(const wxTreeItemId& item);
903
904 // get the selected item image
905 int GetItemSelectedImage(const wxTreeItemId& item) const;
906
907 // set the selected item image
908 void SetItemSelectedImage(const wxTreeItemId& item, int image);
909
910
911 wxWindow* GetHeaderWindow() const;
912 wxWindow* GetMainWindow() const;
913
914 };
915
916
917
918
919 //----------------------------------------------------------------------
920 //----------------------------------------------------------------------
921
922 %init %{
923
924 wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow");
925 wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl");
926 %}
927
928
929 %pragma(python) include="_gizmoextras.py";
930
931 //----------------------------------------------------------------------
932 //----------------------------------------------------------------------
933
934
935
936
937
938