1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Classes for wxWizard and etc.
7 // Created: 16-Aug-2002
9 // Copyright: (c) 2002 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 "`Wizard` is a dialog class that guides the user through a sequence of steps,
18 %module(package="wx", docstring=DOCSTRING) wizard
21 #include "wx/wxPython/wxPython.h"
22 #include "wx/wxPython/pyclasses.h"
23 #include "wx/wxPython/printfw.h"
25 #include <wx/wizard.h>
29 //----------------------------------------------------------------------
32 %pythoncode { wx = _core }
33 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
35 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
37 //----------------------------------------------------------------------
40 wxWIZARD_EX_HELPBUTTON,
43 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGED;
44 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGING;
45 %constant wxEventType wxEVT_WIZARD_CANCEL;
46 %constant wxEventType wxEVT_WIZARD_HELP;
47 %constant wxEventType wxEVT_WIZARD_FINISHED;
52 EVT_WIZARD_PAGE_CHANGED = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGED, 1)
53 EVT_WIZARD_PAGE_CHANGING = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGING, 1)
54 EVT_WIZARD_CANCEL = wx.PyEventBinder( wxEVT_WIZARD_CANCEL, 1)
55 EVT_WIZARD_HELP = wx.PyEventBinder( wxEVT_WIZARD_HELP, 1)
56 EVT_WIZARD_FINISHED = wx.PyEventBinder( wxEVT_WIZARD_FINISHED, 1)
59 //----------------------------------------------------------------------
61 class wxWizardEvent : public wxNotifyEvent
64 wxWizardEvent(wxEventType type = wxEVT_NULL,
66 bool direction = true,
67 wxWizardPage* page = NULL);
69 // for EVT_WIZARD_PAGE_CHANGING, return True if we're going forward or
70 // False otherwise and for EVT_WIZARD_PAGE_CHANGED return True if we came
71 // from the previous page and False if we returned from the next one
72 // (this function doesn't make sense for CANCEL events)
73 bool GetDirection() const { return m_direction; }
75 wxWizardPage* GetPage() const { return m_page; }
79 //----------------------------------------------------------------------
81 // wxWizardPage is one of the wizards screen: it must know what are the
82 // following and preceding pages (which may be NULL for the first/last page).
84 // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be
85 // used as such (i.e. controls may be placed directly on it &c).
86 MustHaveApp(wxWizardPage);
87 class wxWizardPage : public wxPanel
90 // // ctor accepts an optional bitmap which will be used for this page instead
91 // // of the default one for this wizard (should be of the same size). Notice
92 // // that no other parameters are needed because the wizard will resize and
93 // // reposition the page anyhow
94 // wxWizardPage(wxWizard *parent,
95 // const wxBitmap& bitmap = wxNullBitmap,
96 // const char* resource = NULL);
97 // %RenameCtor(PreWizardPage, wxWizardPage());
100 bool Create(wxWizard *parent,
101 const wxBitmap& bitmap = wxNullBitmap,
102 const wxString& resource = wxPyEmptyString) {
104 if (resource.length())
105 res = (wxChar*)resource.c_str();
106 return self->Create(parent, bitmap, res);
111 // these functions are used by the wizard to show another page when the
112 // user chooses "Back" or "Next" button
113 virtual wxWizardPage *GetPrev() const;
114 virtual wxWizardPage *GetNext() const;
116 // default GetBitmap() will just return m_bitmap which is ok in 99% of
117 // cases - override this method if you want to create the bitmap to be used
118 // dynamically or to do something even more fancy. It's ok to return
119 // wxNullBitmap from here - the default one will be used then.
120 virtual wxBitmap GetBitmap() const;
125 %{ // C++ Version of a Python aware class
126 class wxPyWizardPage : public wxWizardPage {
127 DECLARE_ABSTRACT_CLASS(wxPyWizardPage)
129 wxPyWizardPage() : wxWizardPage() {}
130 wxPyWizardPage(wxWizard *parent,
131 const wxBitmap& bitmap = wxNullBitmap,
132 const wxChar* resource = NULL)
133 : wxWizardPage(parent, bitmap, resource) {}
135 DEC_PYCALLBACK_WIZPG__pure(GetPrev);
136 DEC_PYCALLBACK_WIZPG__pure(GetNext);
137 DEC_PYCALLBACK_BITMAP__pure(GetBitmap);
139 DEC_PYCALLBACK_VOID_INT4(DoMoveWindow);
140 DEC_PYCALLBACK_VOID_INT5(DoSetSize);
141 DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize);
142 DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize);
144 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize);
145 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize);
146 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition);
148 DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize);
149 DEC_PYCALLBACK_SIZE_const(DoGetBestSize);
151 DEC_PYCALLBACK__(InitDialog);
152 DEC_PYCALLBACK_BOOL_(TransferDataFromWindow);
153 DEC_PYCALLBACK_BOOL_(TransferDataToWindow);
154 DEC_PYCALLBACK_BOOL_(Validate);
156 DEC_PYCALLBACK_BOOL_const(AcceptsFocus);
157 DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard);
158 DEC_PYCALLBACK_SIZE_const(GetMaxSize);
160 DEC_PYCALLBACK_VOID_WXWINBASE(AddChild);
161 DEC_PYCALLBACK_VOID_WXWINBASE(RemoveChild);
167 IMPLEMENT_ABSTRACT_CLASS(wxPyWizardPage, wxWizardPage);
169 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetPrev);
170 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetNext);
171 IMP_PYCALLBACK_BITMAP__pure(wxPyWizardPage, wxWizardPage, GetBitmap);
173 IMP_PYCALLBACK_VOID_INT4(wxPyWizardPage, wxWizardPage, DoMoveWindow);
174 IMP_PYCALLBACK_VOID_INT5(wxPyWizardPage, wxWizardPage, DoSetSize);
175 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetClientSize);
176 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetVirtualSize);
178 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetSize);
179 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetClientSize);
180 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetPosition);
182 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetVirtualSize);
183 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetBestSize);
185 IMP_PYCALLBACK__(wxPyWizardPage, wxWizardPage, InitDialog);
186 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataFromWindow);
187 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataToWindow);
188 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, Validate);
190 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocus);
191 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocusFromKeyboard);
192 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, GetMaxSize);
194 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, AddChild);
195 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, RemoveChild);
201 MustHaveApp(wxPyWizardPage);
203 class wxPyWizardPage : public wxWizardPage {
206 %pythonAppend wxPyWizardPage "self._setCallbackInfo(self, PyWizardPage);self._setOORInfo(self)"
207 %pythonAppend wxPyWizardPage() ""
208 %typemap(out) wxPyWizardPage*; // turn off this typemap
210 // ctor accepts an optional bitmap which will be used for this page instead
211 // of the default one for this wizard (should be of the same size). Notice
212 // that no other parameters are needed because the wizard will resize and
213 // reposition the page anyhow
215 wxPyWizardPage(wxWizard *parent,
216 const wxBitmap* bitmap = &wxNullBitmap,
217 const wxString* resource = &wxPyEmptyString) {
219 if (resource->length())
220 res = (wxChar*)resource->c_str();
221 return new wxPyWizardPage(parent, *bitmap, res);
225 %RenameCtor(PrePyWizardPage, wxPyWizardPage());
227 // Turn it back on again
228 %typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, $owner); }
231 bool Create(wxWizard *parent,
232 const wxBitmap& bitmap = wxNullBitmap,
233 const wxString& resource = wxPyEmptyString) {
235 if (resource.length())
236 res = (wxChar*)resource.c_str();
237 return self->Create(parent, bitmap, res);
241 void _setCallbackInfo(PyObject* self, PyObject* _class);
243 void DoMoveWindow(int x, int y, int width, int height);
244 void DoSetSize(int x, int y, int width, int height,
245 int sizeFlags = wxSIZE_AUTO);
246 void DoSetClientSize(int width, int height);
247 void DoSetVirtualSize( int x, int y );
250 void, DoGetSize( int *OUTPUT, int *OUTPUT ) const,
251 "DoGetSize() -> (width, height)");
253 void, DoGetClientSize( int *OUTPUT, int *OUTPUT ) const,
254 "DoGetClientSize() -> (width, height)");
256 void, DoGetPosition( int *OUTPUT, int *OUTPUT ) const,
257 "DoGetPosition() -> (x,y)");
259 wxSize DoGetVirtualSize() const;
260 wxSize DoGetBestSize() const;
263 bool TransferDataToWindow();
264 bool TransferDataFromWindow();
267 bool AcceptsFocus() const;
268 bool AcceptsFocusFromKeyboard() const;
269 wxSize GetMaxSize() const;
271 void AddChild(wxWindow* child);
272 void RemoveChild(wxWindow* child);
274 bool ShouldInheritColours() const;
275 wxVisualAttributes GetDefaultAttributes();
277 void OnInternalIdle();
279 %MAKE_BASE_FUNC(PyWizardPage, DoMoveWindow);
280 %MAKE_BASE_FUNC(PyWizardPage, DoSetSize);
281 %MAKE_BASE_FUNC(PyWizardPage, DoSetClientSize);
282 %MAKE_BASE_FUNC(PyWizardPage, DoSetVirtualSize);
283 %MAKE_BASE_FUNC(PyWizardPage, DoGetSize);
284 %MAKE_BASE_FUNC(PyWizardPage, DoGetClientSize);
285 %MAKE_BASE_FUNC(PyWizardPage, DoGetPosition);
286 %MAKE_BASE_FUNC(PyWizardPage, DoGetVirtualSize);
287 %MAKE_BASE_FUNC(PyWizardPage, DoGetBestSize);
288 %MAKE_BASE_FUNC(PyWizardPage, InitDialog);
289 %MAKE_BASE_FUNC(PyWizardPage, TransferDataToWindow);
290 %MAKE_BASE_FUNC(PyWizardPage, TransferDataFromWindow);
291 %MAKE_BASE_FUNC(PyWizardPage, Validate);
292 %MAKE_BASE_FUNC(PyWizardPage, AcceptsFocus);
293 %MAKE_BASE_FUNC(PyWizardPage, AcceptsFocusFromKeyboard);
294 %MAKE_BASE_FUNC(PyWizardPage, GetMaxSize);
295 %MAKE_BASE_FUNC(PyWizardPage, AddChild);
296 %MAKE_BASE_FUNC(PyWizardPage, RemoveChild);
297 %MAKE_BASE_FUNC(PyWizardPage, ShouldInheritColours);
298 %MAKE_BASE_FUNC(PyWizardPage, GetDefaultAttributes);
299 %MAKE_BASE_FUNC(PyWizardPage, OnInternalIdle);
303 //----------------------------------------------------------------------
306 // wxWizardPageSimple just returns the pointers given to the ctor and is useful
307 // to create a simple wizard where the order of pages never changes.
309 // OTOH, it is also possible to dynamicly decide which page to return (i.e.
310 // depending on the user's choices) as the wizard sample shows - in order to do
311 // this, you must derive from wxWizardPage directly.
312 MustHaveApp(wxWizardPageSimple);
313 class wxWizardPageSimple : public wxWizardPage
317 %pythonAppend wxWizardPageSimple "self._setOORInfo(self)"
318 %pythonAppend wxWizardPageSimple() ""
320 // ctor takes the previous and next pages
321 wxWizardPageSimple(wxWizard *parent,
322 wxWizardPage *prev = NULL,
323 wxWizardPage *next = NULL,
324 const wxBitmap& bitmap = wxNullBitmap,
325 const wxChar* resource = NULL);
326 %RenameCtor(PreWizardPageSimple, wxWizardPageSimple());
328 bool Create(wxWizard *parent = NULL,
329 wxWizardPage *prev = NULL,
330 wxWizardPage *next = NULL,
331 const wxBitmap& bitmap = wxNullBitmap,
332 const wxChar* resource = NULL);
334 // the pointers may be also set later - but before starting the wizard
335 void SetPrev(wxWizardPage *prev);
336 void SetNext(wxWizardPage *next);
338 // a convenience function to make the pages follow each other
339 static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second);
343 //----------------------------------------------------------------------
345 MustHaveApp(wxWizard);
347 class wxWizard : public wxDialog
350 %pythonAppend wxWizard "self._setOORInfo(self)"
351 %pythonAppend wxWizard() ""
354 wxWizard(wxWindow *parent,
356 const wxString& title = wxPyEmptyString,
357 const wxBitmap& bitmap = wxNullBitmap,
358 const wxPoint& pos = wxDefaultPosition,
359 long style = wxDEFAULT_DIALOG_STYLE);
360 %RenameCtor(PreWizard, wxWizard());
362 bool Create(wxWindow *parent,
364 const wxString& title = wxPyEmptyString,
365 const wxBitmap& bitmap = wxNullBitmap,
366 const wxPoint& pos = wxDefaultPosition);
371 // executes the wizard starting from the given page, returns True if it was
372 // successfully finished, False if user cancelled it
373 virtual bool RunWizard(wxWizardPage *firstPage);
375 // get the current page (NULL if RunWizard() isn't running)
376 virtual wxWizardPage *GetCurrentPage() const;
378 // set the min size which should be available for the pages: a
379 // wizard will take into account the size of the bitmap (if any)
380 // itself and will never be less than some predefined fixed size
381 virtual void SetPageSize(const wxSize& size);
383 // get the size available for the page: the wizards are not resizeable, so
384 // this size doesn't change
385 virtual wxSize GetPageSize() const;
387 // set the best size for the wizard, i.e. make it big enough to contain all
388 // of the pages starting from the given one
390 // this function may be called several times and possible with different
391 // pages in which case it will only increase the page size if needed (this
392 // may be useful if not all pages are accessible from the first one by
394 virtual void FitToPage(const wxWizardPage *firstPage);
396 // Adding pages to page area sizer enlarges wizard
397 virtual wxSizer *GetPageAreaSizer() const;
399 // Set border around page area. Default is 0 if you add at least one
400 // page to GetPageAreaSizer and 5 if you don't.
401 virtual void SetBorder(int border);
403 // is the wizard running?
404 bool IsRunning() const;
406 // show the prev/next page, but call TransferDataFromWindow on the current
407 // page first and return False without changing the page if
408 // TransferDataFromWindow() returns False - otherwise, returns True
409 bool ShowPage(wxWizardPage *page, bool goingForward = true);
411 bool HasNextPage(wxWizardPage* page);
412 bool HasPrevPage(wxWizardPage* page);
416 //----------------------------------------------------------------------
421 //---------------------------------------------------------------------------