]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/contrib/gizmos/gizmos.i
GetClientAreaOrigin should be public
[wxWidgets.git] / wxPython / contrib / gizmos / gizmos.i
... / ...
CommitLineData
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(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
47MAKE_CONST_WXSTRING2(DynamicSashNameStr, wxT("dynamicSashWindow"));
48MAKE_CONST_WXSTRING2(EditableListBoxNameStr, wxT("editableListBox"));
49MAKE_CONST_WXSTRING2(TreeListCtrlNameStr, wxT("treelistctrl"));
50
51MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
52
53
54%include _gizmos_rename.i
55
56//---------------------------------------------------------------------------
57
58enum {
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*/
74class wxDynamicSashSplitEvent : public wxCommandEvent {
75public:
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*/
90class wxDynamicSashUnifyEvent : public wxCommandEvent {
91public:
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
142class wxDynamicSashWindow : public wxWindow {
143public:
144 %pythonAppend wxDynamicSashWindow "self._setOORInfo(self)"
145 %pythonAppend wxDynamicSashWindow() ""
146
147 wxDynamicSashWindow(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 %name(PreDynamicSashWindow)wxDynamicSashWindow();
152
153 bool Create(wxWindow *parent, wxWindowID id,
154 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
155 long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER,
156 const wxString& name = wxPyDynamicSashNameStr);
157
158 wxScrollBar *GetHScrollBar(const wxWindow *child) const;
159 wxScrollBar *GetVScrollBar(const wxWindow *child) const;
160};
161
162
163
164%pythoncode {
165EVT_DYNAMIC_SASH_SPLIT = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_SPLIT, 1 )
166EVT_DYNAMIC_SASH_UNIFY = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_UNIFY, 1 )
167}
168
169//---------------------------------------------------------------------------
170//---------------------------------------------------------------------------
171
172enum {
173 wxEL_ALLOW_NEW,
174 wxEL_ALLOW_EDIT,
175 wxEL_ALLOW_DELETE,
176};
177
178// This class provides a composite control that lets the
179// user easily enter list of strings
180class wxEditableListBox : public wxPanel
181{
182public:
183 %pythonAppend wxEditableListBox "self._setOORInfo(self)"
184 %pythonAppend wxEditableListBox() ""
185
186 wxEditableListBox(wxWindow *parent, wxWindowID id,
187 const wxString& label,
188 const wxPoint& pos = wxDefaultPosition,
189 const wxSize& size = wxDefaultSize,
190 long style = wxEL_ALLOW_NEW | wxEL_ALLOW_EDIT | wxEL_ALLOW_DELETE,
191 const wxString& name = wxPyEditableListBoxNameStr);
192
193
194 void SetStrings(const wxArrayString& strings);
195
196 //void GetStrings(wxArrayString& strings);
197 %extend {
198 PyObject* GetStrings() {
199 wxArrayString strings;
200 self->GetStrings(strings);
201 return wxArrayString2PyList_helper(strings);
202 }
203 }
204
205 wxListCtrl* GetListCtrl();
206 wxBitmapButton* GetDelButton();
207 wxBitmapButton* GetNewButton();
208 wxBitmapButton* GetUpButton();
209 wxBitmapButton* GetDownButton();
210 wxBitmapButton* GetEditButton();
211};
212
213
214
215//---------------------------------------------------------------------------
216
217
218/*
219 * wxRemotelyScrolledTreeCtrl
220 *
221 * This tree control disables its vertical scrollbar and catches scroll
222 * events passed by a scrolled window higher in the hierarchy.
223 * It also updates the scrolled window vertical scrollbar as appropriate.
224 */
225
226%{
227 typedef wxTreeCtrl wxPyTreeCtrl;
228%}
229
230class wxRemotelyScrolledTreeCtrl: public wxPyTreeCtrl
231{
232public:
233 %pythonAppend wxRemotelyScrolledTreeCtrl "self._setOORInfo(self)"
234 %pythonAppend wxRemotelyScrolledTreeCtrl() ""
235
236 wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id,
237 const wxPoint& pos = wxDefaultPosition,
238 const wxSize& size = wxDefaultSize,
239 long style = wxTR_HAS_BUTTONS);
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%{
269class wxPyTreeCompanionWindow: public wxTreeCompanionWindow
270{
271public:
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 bool blocked = 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(blocked);
292 if (! found)
293 wxTreeCompanionWindow::DrawItem(dc, id, rect);
294 }
295
296 PYPRIVATE;
297};
298%}
299
300
301%name(TreeCompanionWindow) class wxPyTreeCompanionWindow: public wxWindow
302{
303public:
304 %pythonAppend wxPyTreeCompanionWindow "self._setOORInfo(self);self._setCallbackInfo(self, TreeCompanionWindow)"
305 %pythonAppend wxPyTreeCompanionWindow() ""
306
307 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
308 const wxPoint& pos = wxDefaultPosition,
309 const wxSize& size = wxDefaultSize,
310 long style = 0);
311 void _setCallbackInfo(PyObject* self, PyObject* _class);
312
313 wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const;
314 void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl);
315};
316
317
318
319/*
320 * wxThinSplitterWindow
321 *
322 * Implements a splitter with a less obvious sash
323 * than the usual one.
324 */
325
326class wxThinSplitterWindow: public wxSplitterWindow
327{
328public:
329 %pythonAppend wxThinSplitterWindow "self._setOORInfo(self)"
330 %pythonAppend wxThinSplitterWindow() ""
331
332 wxThinSplitterWindow(wxWindow* parent, wxWindowID id = -1,
333 const wxPoint& pos = wxDefaultPosition,
334 const wxSize& size = wxDefaultSize,
335 long style = wxSP_3D | wxCLIP_CHILDREN);
336};
337
338
339
340/*
341 * wxSplitterScrolledWindow
342 *
343 * This scrolled window is aware of the fact that one of its
344 * children is a splitter window. It passes on its scroll events
345 * (after some processing) to both splitter children for them
346 * scroll appropriately.
347 */
348
349class wxSplitterScrolledWindow: public wxScrolledWindow
350{
351public:
352 %pythonAppend wxSplitterScrolledWindow "self._setOORInfo(self)"
353 %pythonAppend wxSplitterScrolledWindow() ""
354
355 wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id = -1,
356 const wxPoint& pos = wxDefaultPosition,
357 const wxSize& size = wxDefaultSize,
358 long style = 0);
359};
360
361
362//---------------------------------------------------------------------------
363//---------------------------------------------------------------------------
364
365
366enum wxLEDValueAlign
367{
368 wxLED_ALIGN_LEFT,
369 wxLED_ALIGN_RIGHT,
370 wxLED_ALIGN_CENTER,
371
372 wxLED_ALIGN_MASK,
373
374 wxLED_DRAW_FADED,
375};
376
377
378class wxLEDNumberCtrl : public wxControl
379{
380public:
381 %pythonAppend wxLEDNumberCtrl "self._setOORInfo(self)"
382 %pythonAppend wxLEDNumberCtrl() ""
383
384 wxLEDNumberCtrl(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 %name(PreLEDNumberCtrl) wxLEDNumberCtrl();
389
390 bool Create(wxWindow *parent, wxWindowID id = -1,
391 const wxPoint& pos = wxDefaultPosition,
392 const wxSize& size = wxDefaultSize,
393 long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED);
394
395 wxLEDValueAlign GetAlignment() const;
396 bool GetDrawFaded() const;
397 const wxString &GetValue() const;
398
399 void SetAlignment(wxLEDValueAlign Alignment, bool Redraw = true);
400 void SetDrawFaded(bool DrawFaded, bool Redraw = true);
401 void SetValue(const wxString &Value, bool Redraw = true);
402
403};
404
405
406
407//----------------------------------------------------------------------------
408// wxTreeListCtrl - the multicolumn tree control
409//----------------------------------------------------------------------------
410
411enum wxTreeListColumnAlign {
412 wxTL_ALIGN_LEFT,
413 wxTL_ALIGN_RIGHT,
414 wxTL_ALIGN_CENTER
415};
416
417
418
419enum {
420 wxTREE_HITTEST_ONITEMCOLUMN
421};
422
423
424enum {
425 // flags for FindItem
426 wxTL_SEARCH_VISIBLE,
427 wxTL_SEARCH_LEVEL,
428 wxTL_SEARCH_FULL,
429 wxTL_SEARCH_PARTIAL,
430 wxTL_SEARCH_NOCASE
431};
432
433
434
435class wxTreeListColumnInfo: public wxObject {
436public:
437 wxTreeListColumnInfo(const wxString& text = wxPyEmptyString,
438 int image = -1,
439 size_t width = 100,
440 bool shown = True,
441 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
442
443 bool GetShown() const;
444 wxTreeListColumnAlign GetAlignment() const;
445 wxString GetText() const;
446 int GetImage() const;
447 int GetSelectedImage() const;
448 size_t GetWidth() const;
449
450 // TODO: These all actually return wxTreeListColumnInfo&, any problem with doing it for Python too?
451 void SetShown(bool shown);
452 void SetAlignment(wxTreeListColumnAlign alignment);
453 void SetText(const wxString& text);
454 void SetImage(int image);
455 void SetSelectedImage(int image);
456 void SetWidth(size_t with);
457};
458
459
460
461
462%{ // C++ version of Python aware control
463class wxPyTreeListCtrl : public wxTreeListCtrl {
464 DECLARE_ABSTRACT_CLASS(wxPyTreeListCtrl);
465public:
466 wxPyTreeListCtrl() : wxTreeListCtrl() {}
467 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id,
468 const wxPoint& pos,
469 const wxSize& size,
470 long style,
471 const wxValidator &validator,
472 const wxString& name) :
473 wxTreeListCtrl(parent, id, pos, size, style, validator, name) {}
474
475 int OnCompareItems(const wxTreeItemId& item1,
476 const wxTreeItemId& item2) {
477 int rval = 0;
478 bool found;
479 bool blocked = wxPyBeginBlockThreads();
480 if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) {
481 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), 0);
482 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), 0);
483 rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2));
484 Py_DECREF(o1);
485 Py_DECREF(o2);
486 }
487 wxPyEndBlockThreads(blocked);
488 if (! found)
489 rval = wxTreeListCtrl::OnCompareItems(item1, item2);
490 return rval;
491 }
492 PYPRIVATE;
493};
494
495IMPLEMENT_ABSTRACT_CLASS(wxPyTreeListCtrl, wxTreeListCtrl)
496
497%}
498
499
500
501
502
503
504%name(TreeListCtrl) class wxPyTreeListCtrl : public wxControl
505{
506public:
507 %pythonAppend wxPyTreeListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeListCtrl)"
508 %pythonAppend wxPyTreeListCtrl() ""
509
510 wxPyTreeListCtrl(wxWindow *parent, wxWindowID id = -1,
511 const wxPoint& pos = wxDefaultPosition,
512 const wxSize& size = wxDefaultSize,
513 long style = wxTR_DEFAULT_STYLE,
514 const wxValidator &validator = wxDefaultValidator,
515 const wxString& name = wxPyTreeListCtrlNameStr );
516 %name(PreTreeListCtrl)wxPyTreeListCtrl();
517
518 bool Create(wxWindow *parent, wxWindowID id = -1,
519 const wxPoint& pos = wxDefaultPosition,
520 const wxSize& size = wxDefaultSize,
521 long style = wxTR_DEFAULT_STYLE,
522 const wxValidator &validator = wxDefaultValidator,
523 const wxString& name = wxPyTreeListCtrlNameStr );
524
525 void _setCallbackInfo(PyObject* self, PyObject* _class);
526
527
528 // get the total number of items in the control
529 size_t GetCount() const;
530
531 // indent is the number of pixels the children are indented relative to
532 // the parents position. SetIndent() also redraws the control
533 // immediately.
534 unsigned int GetIndent() const;
535 void SetIndent(unsigned int indent);
536
537 // line spacing is the space above and below the text on each line
538 unsigned int GetLineSpacing() const;
539 void SetLineSpacing(unsigned int spacing);
540
541 // image list: these functions allow to associate an image list with
542 // the control and retrieve it. Note that when assigned with
543 // SetImageList, the control does _not_ delete
544 // the associated image list when it's deleted in order to allow image
545 // lists to be shared between different controls. If you use
546 // AssignImageList, the control _does_ delete the image list.
547 //
548 // The normal image list is for the icons which correspond to the
549 // normal tree item state (whether it is selected or not).
550 // Additionally, the application might choose to show a state icon
551 // which corresponds to an app-defined item state (for example,
552 // checked/unchecked) which are taken from the state image list.
553 wxImageList *GetImageList() const;
554 wxImageList *GetStateImageList() const;
555 wxImageList *GetButtonsImageList() const;
556
557 void SetImageList(wxImageList *imageList);
558 void SetStateImageList(wxImageList *imageList);
559 void SetButtonsImageList(wxImageList *imageList);
560
561 %apply SWIGTYPE *DISOWN { wxImageList *imageList };
562 void AssignImageList(wxImageList *imageList);
563 void AssignStateImageList(wxImageList *imageList);
564 void AssignButtonsImageList(wxImageList *imageList);
565 %clear wxImageList *imageList;
566
567
568 // adds a column
569 void AddColumn(const wxString& text);
570// void AddColumn(const wxString& text,
571// size_t width,
572// wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
573 %name(AddColumnInfo) void AddColumn(const wxTreeListColumnInfo& col);
574
575 // inserts a column before the given one
576 void InsertColumn(size_t before, const wxString& text);
577 %name(InsertColumnInfo) void InsertColumn(size_t before, const wxTreeListColumnInfo& col);
578
579 // deletes the given column - does not delete the corresponding column
580 // of each item
581 void RemoveColumn(size_t column);
582
583 // returns the number of columns in the ctrl
584 size_t GetColumnCount() const;
585
586 void SetColumnWidth(size_t column, size_t width);
587 int GetColumnWidth(size_t column) const;
588
589 // tells which column is the "main" one, i.e. the "threaded" one
590 void SetMainColumn(size_t column);
591 size_t GetMainColumn() const;
592
593 void SetColumnText(size_t column, const wxString& text);
594 wxString GetColumnText(size_t column) const;
595
596 void SetColumn(size_t column, const wxTreeListColumnInfo& info);
597 wxTreeListColumnInfo& GetColumn(size_t column);
598
599 // other column-related methods
600 void SetColumnAlignment(size_t column, wxTreeListColumnAlign align);
601 wxTreeListColumnAlign GetColumnAlignment(size_t column) const;
602
603 void SetColumnImage(size_t column, int image);
604 int GetColumnImage(size_t column) const;
605
606 void ShowColumn(size_t column, bool shown);
607 bool IsColumnShown(size_t column) const;
608
609 %extend {
610 // retrieves item's label of the given column (main column by default)
611 wxString GetItemText(const wxTreeItemId& item, int column = -1) {
612 if (column < 0) column = self->GetMainColumn();
613 return self->GetItemText(item, column);
614 }
615
616 // get one of the images associated with the item (normal by default)
617 int GetItemImage(const wxTreeItemId& item, int column = -1,
618 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
619 if (column < 0) column = self->GetMainColumn();
620 return self->GetItemImage(item, column, which);
621 }
622
623 // set item's label (main column by default)
624 void SetItemText(const wxTreeItemId& item, const wxString& text, int column = -1) {
625 if (column < 0) column = self->GetMainColumn();
626 self->SetItemText(item, column, text);
627 }
628
629 // set one of the images associated with the item (normal by default)
630 // the which parameter is ignored for all columns but the main one
631 void SetItemImage(const wxTreeItemId& item, int image, int column = -1,
632 wxTreeItemIcon which = wxTreeItemIcon_Normal) {
633 if (column < 0) column = self->GetMainColumn();
634 self->SetItemImage(item, column, image, which);
635 }
636
637
638 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
639 // if needed.
640 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
641 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
642 if (data == NULL) {
643 data = new wxPyTreeItemData();
644 data->SetId(item); // set the id
645 self->SetItemData(item, data);
646 }
647 return data;
648 }
649
650 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
651 data->SetId(item); // set the id
652 self->SetItemData(item, data);
653 }
654
655 // [Get|Set]ItemPyData are short-cuts. Also made somewhat crash-proof by
656 // automatically creating data classes.
657 PyObject* GetItemPyData(const wxTreeItemId& item) {
658 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
659 if (data == NULL) {
660 data = new wxPyTreeItemData();
661 data->SetId(item); // set the id
662 self->SetItemData(item, data);
663 }
664 return data->GetData();
665 }
666
667 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
668 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
669 if (data == NULL) {
670 data = new wxPyTreeItemData(obj);
671 data->SetId(item); // set the id
672 self->SetItemData(item, data);
673 } else
674 data->SetData(obj);
675 }
676 }
677 %pythoncode { GetPyData = GetItemPyData }
678 %pythoncode { SetPyData = SetItemPyData }
679
680
681 // force appearance of [+] button near the item. This is useful to
682 // allow the user to expand the items which don't have any children now
683 // - but instead add them only when needed, thus minimizing memory
684 // usage and loading time.
685 void SetItemHasChildren(const wxTreeItemId& item, bool has = True);
686
687 // the item will be shown in bold
688 void SetItemBold(const wxTreeItemId& item, bool bold = True);
689
690 // set the item's text colour
691 void SetItemTextColour(const wxTreeItemId& item, const wxColour& colour);
692
693 // set the item's background colour
694 void SetItemBackgroundColour(const wxTreeItemId& item,
695 const wxColour& colour);
696
697 // set the item's font (should be of the same height for all items)
698 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
699
700
701 bool GetItemBold(const wxTreeItemId& item) const;
702 wxColour GetItemTextColour(const wxTreeItemId& item) const;
703 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
704 wxFont GetItemFont(const wxTreeItemId& item) const;
705
706 // is the item visible (it might be outside the view or not expanded)?
707 bool IsVisible(const wxTreeItemId& item) const;
708
709 // does the item has any children?
710 bool ItemHasChildren(const wxTreeItemId& item) const;
711
712 // is the item expanded (only makes sense if HasChildren())?
713 bool IsExpanded(const wxTreeItemId& item) const;
714
715 // is this item currently selected (the same as has focus)?
716 bool IsSelected(const wxTreeItemId& item) const;
717
718 // is item text in bold font?
719 bool IsBold(const wxTreeItemId& item) const;
720
721 // if 'recursively' is False, only immediate children count, otherwise
722 // the returned number is the number of all items in this branch
723 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = True);
724
725
726 // wxTreeItemId.IsOk() will return False if there is no such item
727
728 // get the root tree item
729 wxTreeItemId GetRootItem() const;
730
731 // get the item currently selected (may return NULL if no selection)
732 wxTreeItemId GetSelection() const;
733
734 // get the items currently selected, return the number of such item
735 //size_t GetSelections(wxArrayTreeItemIds&) const;
736 %extend {
737 PyObject* GetSelections() {
738 bool blocked = wxPyBeginBlockThreads();
739 PyObject* rval = PyList_New(0);
740 wxArrayTreeItemIds array;
741 size_t num, x;
742 num = self->GetSelections(array);
743 for (x=0; x < num; x++) {
744 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
745 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True);
746 PyList_Append(rval, item);
747 }
748 wxPyEndBlockThreads(blocked);
749 return rval;
750 }
751 }
752
753
754 // get the parent of this item (may return NULL if root)
755 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
756
757 // for this enumeration function you must pass in a "cookie" parameter
758 // which is opaque for the application but is necessary for the library
759 // to make these functions reentrant (i.e. allow more than one
760 // enumeration on one and the same object simultaneously). Of course,
761 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
762 // the same!
763
764
765 // NOTE: These are a copy of the same methods in _treectrl.i, be sure to
766 // update both at the same time. (Or find a good way to refactor!)
767 %extend {
768 // Get the first child of this item. Returns a wxTreeItemId and an
769 // opaque "cookie" value that should be passed to GetNextChild in
770 // order to continue the search.
771 PyObject* GetFirstChild(const wxTreeItemId& item) {
772 void* cookie = 0;
773 wxTreeItemId* ritem = new wxTreeItemId(self->GetFirstChild(item, cookie));
774 bool blocked = wxPyBeginBlockThreads();
775 PyObject* tup = PyTuple_New(2);
776 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), True));
777 PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void")));
778 wxPyEndBlockThreads(blocked);
779 return tup;
780 }
781
782
783 // Get the next child of this item. The cookie parameter is the 2nd
784 // value returned from GetFirstChild or the previous GetNextChild.
785 // Returns a wxTreeItemId and an opaque "cookie" value that should be
786 // passed to GetNextChild in order to continue the search.
787 PyObject* GetNextChild(const wxTreeItemId& item, void* cookie) {
788 wxTreeItemId* ritem = new wxTreeItemId(self->GetNextChild(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 // TODO: GetPrevChild
799
800 }
801
802 // get the last child of this item - this method doesn't use cookies
803 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
804
805 // get the next sibling of this item
806 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
807
808 // get the previous sibling
809 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
810
811 // get first visible item
812 wxTreeItemId GetFirstVisibleItem() const;
813
814 // get the next visible item: item must be visible itself!
815 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
816 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
817
818 // get the previous visible item: item must be visible itself!
819 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
820
821 // Only for internal use right now, but should probably be public
822 wxTreeItemId GetNext(const wxTreeItemId& item) const;
823
824
825 // add the root node to the tree
826 wxTreeItemId AddRoot(const wxString& text,
827 int image = -1, int selectedImage = -1,
828 wxPyTreeItemData *data = NULL);
829
830 // insert a new item in as the first child of the parent
831 wxTreeItemId PrependItem(const wxTreeItemId& parent,
832 const wxString& text,
833 int image = -1, int selectedImage = -1,
834 wxPyTreeItemData *data = NULL);
835
836 // insert a new item after a given one
837 wxTreeItemId InsertItem(const wxTreeItemId& parent,
838 const wxTreeItemId& idPrevious,
839 const wxString& text,
840 int image = -1, int selectedImage = -1,
841 wxPyTreeItemData *data = NULL);
842
843 // insert a new item before the one with the given index
844 %name(InsertItemBefore)
845 wxTreeItemId InsertItem(const wxTreeItemId& parent,
846 size_t index,
847 const wxString& text,
848 int image = -1, int selectedImage = -1,
849 wxPyTreeItemData *data = NULL);
850
851 // insert a new item in as the last child of the parent
852 wxTreeItemId AppendItem(const wxTreeItemId& parent,
853 const wxString& text,
854 int image = -1, int selectedImage = -1,
855 wxPyTreeItemData *data = NULL);
856
857 // delete this item and associated data if any
858 void Delete(const wxTreeItemId& item);
859
860 // delete all children (but don't delete the item itself)
861 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
862 void DeleteChildren(const wxTreeItemId& item);
863
864 // delete all items from the tree
865 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
866 void DeleteAllItems();
867
868 // expand this item
869 void Expand(const wxTreeItemId& item);
870
871 // expand this item and all subitems recursively
872 void ExpandAll(const wxTreeItemId& item);
873
874 // collapse the item without removing its children
875 void Collapse(const wxTreeItemId& item);
876
877 // collapse the item and remove all children
878 void CollapseAndReset(const wxTreeItemId& item);
879
880 // toggles the current state
881 void Toggle(const wxTreeItemId& item);
882
883 // remove the selection from currently selected item (if any)
884 void Unselect();
885 void UnselectAll();
886
887 // select this item
888 void SelectItem(const wxTreeItemId& item, bool unselect_others=True,
889 bool extended_select=False);
890
891 void SelectAll(bool extended_select=False);
892
893 // make sure this item is visible (expanding the parent item and/or
894 // scrolling to this item if necessary)
895 void EnsureVisible(const wxTreeItemId& item);
896
897 // scroll to this item (but don't expand its parent)
898 void ScrollTo(const wxTreeItemId& item);
899
900 // Returns wxTreeItemId, flags, and column
901 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT, int& OUTPUT);
902
903 %extend {
904 // get the bounding rectangle of the item (or of its label only)
905 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) {
906 wxRect rect;
907 if (self->GetBoundingRect(item, rect, textOnly)) {
908 bool blocked = wxPyBeginBlockThreads();
909 wxRect* r = new wxRect(rect);
910 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1);
911 wxPyEndBlockThreads(blocked);
912 return val;
913 }
914 else {
915 RETURN_NONE();
916 }
917 }
918 }
919
920
921 // Start editing the item label: this (temporarily) replaces the item
922 // with a one line edit control. The item will be selected if it hadn't
923 // been before.
924 void EditLabel( const wxTreeItemId& item );
925 void Edit( const wxTreeItemId& item );
926
927 // sort the children of this item using OnCompareItems
928 void SortChildren(const wxTreeItemId& item);
929
930 // searching
931 wxTreeItemId FindItem (const wxTreeItemId& item, const wxString& str, int flags = 0);
932
933 wxWindow* GetHeaderWindow() const;
934 wxWindow* GetMainWindow() const;
935
936};
937
938
939
940
941//----------------------------------------------------------------------
942//----------------------------------------------------------------------
943
944%init %{
945
946 wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow");
947 wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl");
948%}
949
950
951%pragma(python) include="_gizmoextras.py";
952
953//----------------------------------------------------------------------
954//----------------------------------------------------------------------
955