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 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/wxPython/wxPython.h"
17 #include "wx/wxPython/pyclasses.h"
18 #include "wx/wxPython/printfw.h"
20 #include <wx/wizard.h>
24 //----------------------------------------------------------------------
27 %pythoncode { wx = _core }
28 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
30 %include _wizard_rename.i
32 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
34 //----------------------------------------------------------------------
37 wxWIZARD_EX_HELPBUTTON,
40 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGED;
41 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGING;
42 %constant wxEventType wxEVT_WIZARD_CANCEL;
43 %constant wxEventType wxEVT_WIZARD_HELP;
44 %constant wxEventType wxEVT_WIZARD_FINISHED;
49 EVT_WIZARD_PAGE_CHANGED = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGED, 1)
50 EVT_WIZARD_PAGE_CHANGING = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGING, 1)
51 EVT_WIZARD_CANCEL = wx.PyEventBinder( wxEVT_WIZARD_CANCEL, 1)
52 EVT_WIZARD_HELP = wx.PyEventBinder( wxEVT_WIZARD_HELP, 1)
53 EVT_WIZARD_FINISHED = wx.PyEventBinder( wxEVT_WIZARD_FINISHED, 1)
56 //----------------------------------------------------------------------
58 class wxWizardEvent : public wxNotifyEvent
61 wxWizardEvent(wxEventType type = wxEVT_NULL,
63 bool direction = True,
64 wxWizardPage* page = NULL);
66 // for EVT_WIZARD_PAGE_CHANGING, return True if we're going forward or
67 // False otherwise and for EVT_WIZARD_PAGE_CHANGED return True if we came
68 // from the previous page and False if we returned from the next one
69 // (this function doesn't make sense for CANCEL events)
70 bool GetDirection() const { return m_direction; }
72 wxWizardPage* GetPage() const { return m_page; }
76 //----------------------------------------------------------------------
78 // wxWizardPage is one of the wizards screen: it must know what are the
79 // following and preceding pages (which may be NULL for the first/last page).
81 // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be
82 // used as such (i.e. controls may be placed directly on it &c).
83 class wxWizardPage : public wxPanel
86 // // ctor accepts an optional bitmap which will be used for this page instead
87 // // of the default one for this wizard (should be of the same size). Notice
88 // // that no other parameters are needed because the wizard will resize and
89 // // reposition the page anyhow
90 // wxWizardPage(wxWizard *parent,
91 // const wxBitmap& bitmap = wxNullBitmap,
92 // const char* resource = NULL);
93 // %name(PreWizardPage)wxWizardPage();
96 bool Create(wxWizard *parent,
97 const wxBitmap& bitmap = wxNullBitmap,
98 const wxString& resource = wxPyEmptyString) {
100 if (resource.Length())
101 res = (wxChar*)resource.c_str();
102 return self->Create(parent, bitmap, res);
107 // these functions are used by the wizard to show another page when the
108 // user chooses "Back" or "Next" button
109 virtual wxWizardPage *GetPrev() const;
110 virtual wxWizardPage *GetNext() const;
112 // default GetBitmap() will just return m_bitmap which is ok in 99% of
113 // cases - override this method if you want to create the bitmap to be used
114 // dynamically or to do something even more fancy. It's ok to return
115 // wxNullBitmap from here - the default one will be used then.
116 virtual wxBitmap GetBitmap() const;
121 %{ // C++ Version of a Python aware class
122 class wxPyWizardPage : public wxWizardPage {
123 DECLARE_ABSTRACT_CLASS(wxPyWizardPage);
125 wxPyWizardPage() : wxWizardPage() {}
126 wxPyWizardPage(wxWizard *parent,
127 const wxBitmap& bitmap = wxNullBitmap,
128 const wxChar* resource = NULL)
129 : wxWizardPage(parent, bitmap, resource) {}
131 DEC_PYCALLBACK_WIZPG__pure(GetPrev);
132 DEC_PYCALLBACK_WIZPG__pure(GetNext);
133 DEC_PYCALLBACK_BITMAP__pure(GetBitmap);
135 DEC_PYCALLBACK_VOID_INT4(DoMoveWindow);
136 DEC_PYCALLBACK_VOID_INT5(DoSetSize);
137 DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize);
138 DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize);
140 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize);
141 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize);
142 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition);
144 DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize);
145 DEC_PYCALLBACK_SIZE_const(DoGetBestSize);
147 DEC_PYCALLBACK__(InitDialog);
148 DEC_PYCALLBACK_BOOL_(TransferDataFromWindow);
149 DEC_PYCALLBACK_BOOL_(TransferDataToWindow);
150 DEC_PYCALLBACK_BOOL_(Validate);
152 DEC_PYCALLBACK_BOOL_const(AcceptsFocus);
153 DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard);
154 DEC_PYCALLBACK_SIZE_const(GetMaxSize);
156 DEC_PYCALLBACK_VOID_WXWINBASE(AddChild);
157 DEC_PYCALLBACK_VOID_WXWINBASE(RemoveChild);
163 IMPLEMENT_ABSTRACT_CLASS(wxPyWizardPage, wxWizardPage);
165 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetPrev);
166 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetNext);
167 IMP_PYCALLBACK_BITMAP__pure(wxPyWizardPage, wxWizardPage, GetBitmap);
169 IMP_PYCALLBACK_VOID_INT4(wxPyWizardPage, wxWizardPage, DoMoveWindow);
170 IMP_PYCALLBACK_VOID_INT5(wxPyWizardPage, wxWizardPage, DoSetSize);
171 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetClientSize);
172 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetVirtualSize);
174 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetSize);
175 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetClientSize);
176 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetPosition);
178 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetVirtualSize);
179 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetBestSize);
181 IMP_PYCALLBACK__(wxPyWizardPage, wxWizardPage, InitDialog);
182 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataFromWindow);
183 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataToWindow);
184 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, Validate);
186 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocus);
187 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocusFromKeyboard);
188 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, GetMaxSize);
190 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, AddChild);
191 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, RemoveChild);
197 class wxPyWizardPage : public wxWizardPage {
200 %pythonAppend wxPyWizardPage "self._setCallbackInfo(self, PyWizardPage);self._setOORInfo(self)"
201 %pythonAppend wxPyWizardPage() ""
203 // ctor accepts an optional bitmap which will be used for this page instead
204 // of the default one for this wizard (should be of the same size). Notice
205 // that no other parameters are needed because the wizard will resize and
206 // reposition the page anyhow
208 wxPyWizardPage(wxWizard *parent,
209 const wxBitmap* bitmap = &wxNullBitmap,
210 const wxString* resource = &wxPyEmptyString) {
212 if (resource->Length())
213 res = (wxChar*)resource->c_str();
214 return new wxPyWizardPage(parent, *bitmap, res);
218 %name(PrePyWizardPage)wxPyWizardPage();
221 bool Create(wxWizard *parent,
222 const wxBitmap& bitmap = wxNullBitmap,
223 const wxString& resource = wxPyEmptyString) {
225 if (resource.Length())
226 res = (wxChar*)resource.c_str();
227 return self->Create(parent, bitmap, res);
231 void _setCallbackInfo(PyObject* self, PyObject* _class);
233 void base_DoMoveWindow(int x, int y, int width, int height);
234 void base_DoSetSize(int x, int y, int width, int height,
235 int sizeFlags = wxSIZE_AUTO);
236 void base_DoSetClientSize(int width, int height);
237 void base_DoSetVirtualSize( int x, int y );
240 void, base_DoGetSize( int *OUTPUT, int *OUTPUT ) const,
241 "base_DoGetSize() -> (width, height)");
243 void, base_DoGetClientSize( int *OUTPUT, int *OUTPUT ) const,
244 "base_DoGetClientSize() -> (width, height)");
246 void, base_DoGetPosition( int *OUTPUT, int *OUTPUT ) const,
247 "base_DoGetPosition() -> (x,y)");
249 wxSize base_DoGetVirtualSize() const;
250 wxSize base_DoGetBestSize() const;
252 void base_InitDialog();
253 bool base_TransferDataToWindow();
254 bool base_TransferDataFromWindow();
255 bool base_Validate();
257 bool base_AcceptsFocus() const;
258 bool base_AcceptsFocusFromKeyboard() const;
259 wxSize base_GetMaxSize() const;
261 void base_AddChild(wxWindow* child);
262 void base_RemoveChild(wxWindow* child);
265 //----------------------------------------------------------------------
268 // wxWizardPageSimple just returns the pointers given to the ctor and is useful
269 // to create a simple wizard where the order of pages never changes.
271 // OTOH, it is also possible to dynamicly decide which page to return (i.e.
272 // depending on the user's choices) as the wizard sample shows - in order to do
273 // this, you must derive from wxWizardPage directly.
274 class wxWizardPageSimple : public wxWizardPage
278 %pythonAppend wxWizardPageSimple "self._setOORInfo(self)"
279 %pythonAppend wxWizardPageSimple() ""
281 // ctor takes the previous and next pages
282 wxWizardPageSimple(wxWizard *parent,
283 wxWizardPage *prev = NULL,
284 wxWizardPage *next = NULL,
285 const wxBitmap& bitmap = wxNullBitmap,
286 const wxChar* resource = NULL);
287 %name(PreWizardPageSimple)wxWizardPageSimple();
289 bool Create(wxWizard *parent = NULL,
290 wxWizardPage *prev = NULL,
291 wxWizardPage *next = NULL,
292 const wxBitmap& bitmap = wxNullBitmap,
293 const wxChar* resource = NULL);
295 // the pointers may be also set later - but before starting the wizard
296 void SetPrev(wxWizardPage *prev);
297 void SetNext(wxWizardPage *next);
299 // a convenience function to make the pages follow each other
300 static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second);
304 //----------------------------------------------------------------------
306 class wxWizard : public wxDialog
309 %pythonAppend wxWizard "self._setOORInfo(self)"
310 %pythonAppend wxWizard() ""
313 wxWizard(wxWindow *parent,
315 const wxString& title = wxPyEmptyString,
316 const wxBitmap& bitmap = wxNullBitmap,
317 const wxPoint& pos = wxDefaultPosition,
318 long style = wxDEFAULT_DIALOG_STYLE);
319 %name(PreWizard)wxWizard();
321 bool Create(wxWindow *parent,
323 const wxString& title = wxPyEmptyString,
324 const wxBitmap& bitmap = wxNullBitmap,
325 const wxPoint& pos = wxDefaultPosition);
330 // executes the wizard starting from the given page, returns True if it was
331 // successfully finished, False if user cancelled it
332 virtual bool RunWizard(wxWizardPage *firstPage);
334 // get the current page (NULL if RunWizard() isn't running)
335 virtual wxWizardPage *GetCurrentPage() const;
337 // set the min size which should be available for the pages: a
338 // wizard will take into account the size of the bitmap (if any)
339 // itself and will never be less than some predefined fixed size
340 virtual void SetPageSize(const wxSize& size);
342 // get the size available for the page: the wizards are not resizeable, so
343 // this size doesn't change
344 virtual wxSize GetPageSize() const;
346 // set the best size for the wizard, i.e. make it big enough to contain all
347 // of the pages starting from the given one
349 // this function may be called several times and possible with different
350 // pages in which case it will only increase the page size if needed (this
351 // may be useful if not all pages are accessible from the first one by
353 virtual void FitToPage(const wxWizardPage *firstPage);
355 // Adding pages to page area sizer enlarges wizard
356 virtual wxSizer *GetPageAreaSizer() const;
358 // Set border around page area. Default is 0 if you add at least one
359 // page to GetPageAreaSizer and 5 if you don't.
360 virtual void SetBorder(int border);
362 // is the wizard running?
363 bool IsRunning() const { return m_page != NULL; }
365 // show the prev/next page, but call TransferDataFromWindow on the current
366 // page first and return False without changing the page if
367 // TransferDataFromWindow() returns False - otherwise, returns True
368 bool ShowPage(wxWizardPage *page, bool goingForward = True);
370 bool HasNextPage(wxWizardPage* page);
371 bool HasPrevPage(wxWizardPage* page);
375 //----------------------------------------------------------------------
380 //---------------------------------------------------------------------------