1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Wrappers for the "gizmo" classes in wx/contrib
7 // Created: 23-Nov-2001
9 // Copyright: (c) 2001 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/gizmos/dynamicsash.h>
19 #include <wx/gizmos/editlbox.h>
20 #include <wx/gizmos/splittree.h>
21 #include <wx/gizmos/ledctrl.h>
22 #include <wx/listctrl.h>
25 //---------------------------------------------------------------------------
28 %include my_typemaps.i
37 //----------------------------------------------------------------------
40 // Put some wx default wxChar* values into wxStrings.
41 static const wxString wxPyDynamicSashNameStr(wxT("dynamicSashWindow"));
42 static const wxString wxPyEditableListBoxNameStr(wxT("editableListBox"));
45 ///----------------------------------------------------------------------
48 wxEVT_DYNAMIC_SASH_SPLIT,
49 wxEVT_DYNAMIC_SASH_UNIFY,
51 wxDS_MANAGE_SCROLLBARS,
57 wxDynamicSashSplitEvents are sent to your view by wxDynamicSashWindow
58 whenever your view is being split by the user. It is your
59 responsibility to handle this event by creating a new view window as
60 a child of the wxDynamicSashWindow. wxDynamicSashWindow will
61 automatically reparent it to the proper place in its window hierarchy.
63 class wxDynamicSashSplitEvent : public wxCommandEvent {
65 wxDynamicSashSplitEvent(wxObject *target);
70 wxDynamicSashUnifyEvents are sent to your view by wxDynamicSashWindow
71 whenever the sash which splits your view and its sibling is being
72 reunified such that your view is expanding to replace its sibling.
73 You needn't do anything with this event if you are allowing
74 wxDynamicSashWindow to manage your view's scrollbars, but it is useful
75 if you are managing the scrollbars yourself so that you can keep
76 the scrollbars' event handlers connected to your view's event handler
79 class wxDynamicSashUnifyEvent : public wxCommandEvent {
81 wxDynamicSashUnifyEvent(wxObject *target);
90 wxDynamicSashWindow widgets manages the way other widgets are viewed.
91 When a wxDynamicSashWindow is first shown, it will contain one child
92 view, a viewport for that child, and a pair of scrollbars to allow the
93 user to navigate the child view area. Next to each scrollbar is a small
94 tab. By clicking on either tab and dragging to the appropriate spot, a
95 user can split the view area into two smaller views separated by a
96 draggable sash. Later, when the user wishes to reunify the two subviews,
97 the user simply drags the sash to the side of the window.
98 wxDynamicSashWindow will automatically reparent the appropriate child
99 view back up the window hierarchy, and the wxDynamicSashWindow will have
100 only one child view once again.
102 As an application developer, you will simply create a wxDynamicSashWindow
103 using either the Create() function or the more complex constructor
104 provided below, and then create a view window whose parent is the
105 wxDynamicSashWindow. The child should respond to
106 wxDynamicSashSplitEvents -- perhaps with an OnSplit() event handler -- by
107 constructing a new view window whose parent is also the
108 wxDynamicSashWindow. That's it! Now your users can dynamically split
109 and reunify the view you provided.
111 If you wish to handle the scrollbar events for your view, rather than
112 allowing wxDynamicSashWindow to do it for you, things are a bit more
113 complex. (You might want to handle scrollbar events yourself, if,
114 for instance, you wish to scroll a subwindow of the view you add to
115 your wxDynamicSashWindow object, rather than scrolling the whole view.)
116 In this case, you will need to construct your wxDynamicSashWindow without
117 the wxDS_MANAGE_SCROLLBARS style and you will need to use the
118 GetHScrollBar() and GetVScrollBar() methods to retrieve the scrollbar
119 controls and call SetEventHanler() on them to redirect the scrolling
120 events whenever your window is reparented by wxDyanmicSashWindow.
121 You will need to set the scrollbars' event handler at three times:
123 * When your view is created
124 * When your view receives a wxDynamicSashSplitEvent
125 * When your view receives a wxDynamicSashUnifyEvent
127 See the dynsash_switch sample application for an example which does this.
131 class wxDynamicSashWindow : public wxWindow {
133 wxDynamicSashWindow(wxWindow *parent, wxWindowID id,
134 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
135 long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER,
136 const wxString& name = wxPyDynamicSashNameStr);
137 %name(wxPreDynamicSashWindow)wxDynamicSashWindow();
139 bool Create(wxWindow *parent, wxWindowID id,
140 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
141 long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER,
142 const wxString& name = wxPyDynamicSashNameStr);
144 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
145 %pragma(python) addtomethod = "wxPreDynamicSashWindow:val._setOORInfo(val)"
147 wxScrollBar *GetHScrollBar(const wxWindow *child) const;
148 wxScrollBar *GetVScrollBar(const wxWindow *child) const;
153 //----------------------------------------------------------------------
154 // Python functions to act like the event macros
156 %pragma(python) code = "
157 def EVT_DYNAMIC_SASH_SPLIT(win, id, func):
158 win.Connect(id, -1, wxEVT_DYNAMIC_SASH_SPLIT, func)
160 def EVT_DYNAMIC_SASH_UNIFY(win, id, func):
161 win.Connect(id, -1, wxEVT_DYNAMIC_SASH_UNIFY, func)
164 //----------------------------------------------------------------------
165 //----------------------------------------------------------------------
173 // This class provides a composite control that lets the
174 // user easily enter list of strings
175 class wxEditableListBox : public wxPanel
178 wxEditableListBox(wxWindow *parent, wxWindowID id,
179 const wxString& label,
180 const wxPoint& pos = wxDefaultPosition,
181 const wxSize& size = wxDefaultSize,
182 long style = wxEL_ALLOW_NEW | wxEL_ALLOW_EDIT | wxEL_ALLOW_DELETE,
183 const wxString& name = wxPyEditableListBoxNameStr);
185 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
187 void SetStrings(const wxArrayString& strings);
189 //void GetStrings(wxArrayString& strings);
191 PyObject* GetStrings() {
192 wxArrayString strings;
193 self->GetStrings(strings);
194 return wxArrayString2PyList_helper(strings);
198 wxListCtrl* GetListCtrl() { return m_listCtrl; }
199 wxBitmapButton* GetDelButton() { return m_bDel; }
200 wxBitmapButton* GetNewButton() { return m_bNew; }
201 wxBitmapButton* GetUpButton() { return m_bUp; }
202 wxBitmapButton* GetDownButton() { return m_bDown; }
203 wxBitmapButton* GetEditButton() { return m_bEdit; }
208 //----------------------------------------------------------------------
212 * wxRemotelyScrolledTreeCtrl
214 * This tree control disables its vertical scrollbar and catches scroll
215 * events passed by a scrolled window higher in the hierarchy.
216 * It also updates the scrolled window vertical scrollbar as appropriate.
220 typedef wxTreeCtrl wxPyTreeCtrl;
223 class wxRemotelyScrolledTreeCtrl: public wxPyTreeCtrl
226 wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id,
227 const wxPoint& pos = wxDefaultPosition,
228 const wxSize& size = wxDefaultSize,
229 long style = wxTR_HAS_BUTTONS);
230 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
233 void HideVScrollbar();
235 // Adjust the containing wxScrolledWindow's scrollbars appropriately
236 void AdjustRemoteScrollbars();
238 // Find the scrolled window that contains this control
239 wxScrolledWindow* GetScrolledWindow() const;
241 // Scroll to the given line (in scroll units where each unit is
242 // the height of an item)
243 void ScrollToLine(int posHoriz, int posVert);
245 // The companion window is one which will get notified when certain
246 // events happen such as node expansion
247 void SetCompanionWindow(wxWindow* companion);
248 wxWindow* GetCompanionWindow() const;
254 * wxTreeCompanionWindow
256 * A window displaying values associated with tree control items.
260 class wxPyTreeCompanionWindow: public wxTreeCompanionWindow
263 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
264 const wxPoint& pos = wxDefaultPosition,
265 const wxSize& size = wxDefaultSize,
267 : wxTreeCompanionWindow(parent, id, pos, size, style) {}
270 virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect) {
272 wxPyBeginBlockThreads();
273 if ((found = wxPyCBH_findCallback(m_myInst, "DrawItem"))) {
274 PyObject* dcobj = wxPyMake_wxObject(&dc);
275 PyObject* idobj = wxPyConstructObject((void*)&id, "wxTreeItemId", FALSE);
276 PyObject* recobj= wxPyConstructObject((void*)&rect, "wxRect", FALSE);
277 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", dcobj, idobj, recobj));
282 wxPyEndBlockThreads();
284 wxTreeCompanionWindow::DrawItem(dc, id, rect);
292 %name(wxTreeCompanionWindow) class wxPyTreeCompanionWindow: public wxWindow
295 wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
296 const wxPoint& pos = wxDefaultPosition,
297 const wxSize& size = wxDefaultSize,
299 void _setCallbackInfo(PyObject* self, PyObject* _class);
300 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCompanionWindow)"
301 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
303 wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const;
304 void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl);
310 * wxThinSplitterWindow
312 * Implements a splitter with a less obvious sash
313 * than the usual one.
316 class wxThinSplitterWindow: public wxSplitterWindow
319 wxThinSplitterWindow(wxWindow* parent, wxWindowID id = -1,
320 const wxPoint& pos = wxDefaultPosition,
321 const wxSize& size = wxDefaultSize,
322 long style = wxSP_3D | wxCLIP_CHILDREN);
323 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
329 * wxSplitterScrolledWindow
331 * This scrolled window is aware of the fact that one of its
332 * children is a splitter window. It passes on its scroll events
333 * (after some processing) to both splitter children for them
334 * scroll appropriately.
337 class wxSplitterScrolledWindow: public wxScrolledWindow
340 wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id = -1,
341 const wxPoint& pos = wxDefaultPosition,
342 const wxSize& size = wxDefaultSize,
344 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
348 //----------------------------------------------------------------------
349 //----------------------------------------------------------------------
364 class wxLEDNumberCtrl : public wxControl
368 wxLEDNumberCtrl(wxWindow *parent, wxWindowID id = -1,
369 const wxPoint& pos = wxDefaultPosition,
370 const wxSize& size = wxDefaultSize,
371 long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED);
372 %name(wxPreLEDNumberCtrl) wxLEDNumberCtrl();
374 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
375 %pragma(python) addtomethod = "wxPreLEDNumberCtrl:val._setOORInfo(val)"
378 bool Create(wxWindow *parent, wxWindowID id = -1,
379 const wxPoint& pos = wxDefaultPosition,
380 const wxSize& size = wxDefaultSize,
381 long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED);
383 wxLEDValueAlign GetAlignment() const { return m_Alignment; }
384 bool GetDrawFaded() const { return m_DrawFaded; }
385 const wxString &GetValue() const { return m_Value; }
387 void SetAlignment(wxLEDValueAlign Alignment, bool Redraw = true);
388 void SetDrawFaded(bool DrawFaded, bool Redraw = true);
389 void SetValue(const wxString &Value, bool Redraw = true);
393 //----------------------------------------------------------------------
394 //----------------------------------------------------------------------
398 wxClassInfo::CleanUpClasses();
399 wxClassInfo::InitializeClasses();
401 wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow");
405 %pragma(python) include="_gizmoextras.py";
407 //----------------------------------------------------------------------
408 //----------------------------------------------------------------------