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>
22 static const wxString wxPyEmptyString(wxT(""));
25 //----------------------------------------------------------------------
28 %pythoncode { wx = core }
30 %include _wizard_rename.i
32 //----------------------------------------------------------------------
35 wxWIZARD_EX_HELPBUTTON,
38 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGED;
39 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGING;
40 %constant wxEventType wxEVT_WIZARD_CANCEL;
41 %constant wxEventType wxEVT_WIZARD_HELP;
42 %constant wxEventType wxEVT_WIZARD_FINISHED;
47 EVT_WIZARD_PAGE_CHANGED = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGED, 1)
48 EVT_WIZARD_PAGE_CHANGING = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGING, 1)
49 EVT_WIZARD_CANCEL = wx.PyEventBinder( wxEVT_WIZARD_CANCEL, 1)
50 EVT_WIZARD_HELP = wx.PyEventBinder( wxEVT_WIZARD_HELP, 1)
51 EVT_WIZARD_FINISHED = wx.PyEventBinder( wxEVT_WIZARD_FINISHED, 1)
54 //----------------------------------------------------------------------
56 class wxWizardEvent : public wxNotifyEvent
59 wxWizardEvent(wxEventType type = wxEVT_NULL,
61 bool direction = True,
62 wxWizardPage* page = NULL);
64 // for EVT_WIZARD_PAGE_CHANGING, return True if we're going forward or
65 // False otherwise and for EVT_WIZARD_PAGE_CHANGED return True if we came
66 // from the previous page and False if we returned from the next one
67 // (this function doesn't make sense for CANCEL events)
68 bool GetDirection() const { return m_direction; }
70 wxWizardPage* GetPage() const { return m_page; }
74 //----------------------------------------------------------------------
76 // wxWizardPage is one of the wizards screen: it must know what are the
77 // following and preceding pages (which may be NULL for the first/last page).
79 // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be
80 // used as such (i.e. controls may be placed directly on it &c).
81 class wxWizardPage : public wxPanel
84 // // ctor accepts an optional bitmap which will be used for this page instead
85 // // of the default one for this wizard (should be of the same size). Notice
86 // // that no other parameters are needed because the wizard will resize and
87 // // reposition the page anyhow
88 // wxWizardPage(wxWizard *parent,
89 // const wxBitmap& bitmap = wxNullBitmap,
90 // const char* resource = NULL);
91 // %name(PreWizardPage)wxWizardPage();
94 bool Create(wxWizard *parent,
95 const wxBitmap& bitmap = wxNullBitmap,
96 const wxString& resource = wxPyEmptyString) {
98 if (resource.Length())
99 res = (wxChar*)resource.c_str();
100 return self->Create(parent, bitmap, res);
105 // these functions are used by the wizard to show another page when the
106 // user chooses "Back" or "Next" button
107 virtual wxWizardPage *GetPrev() const;
108 virtual wxWizardPage *GetNext() const;
110 // default GetBitmap() will just return m_bitmap which is ok in 99% of
111 // cases - override this method if you want to create the bitmap to be used
112 // dynamically or to do something even more fancy. It's ok to return
113 // wxNullBitmap from here - the default one will be used then.
114 virtual wxBitmap GetBitmap() const;
119 %{ // C++ Version of a Python aware class
120 class wxPyWizardPage : public wxWizardPage {
121 DECLARE_ABSTRACT_CLASS(wxPyWizardPage);
123 wxPyWizardPage() : wxWizardPage() {}
124 wxPyWizardPage(wxWizard *parent,
125 const wxBitmap& bitmap = wxNullBitmap,
126 const wxChar* resource = NULL)
127 : wxWizardPage(parent, bitmap, resource) {}
129 DEC_PYCALLBACK_WIZPG__pure(GetPrev);
130 DEC_PYCALLBACK_WIZPG__pure(GetNext);
131 DEC_PYCALLBACK_BITMAP__pure(GetBitmap);
133 DEC_PYCALLBACK_VOID_INT4(DoMoveWindow);
134 DEC_PYCALLBACK_VOID_INT5(DoSetSize);
135 DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize);
136 DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize);
138 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize);
139 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize);
140 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition);
142 DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize);
143 DEC_PYCALLBACK_SIZE_const(DoGetBestSize);
145 DEC_PYCALLBACK__(InitDialog);
146 DEC_PYCALLBACK_BOOL_(TransferDataFromWindow);
147 DEC_PYCALLBACK_BOOL_(TransferDataToWindow);
148 DEC_PYCALLBACK_BOOL_(Validate);
150 DEC_PYCALLBACK_BOOL_const(AcceptsFocus);
151 DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard);
152 DEC_PYCALLBACK_SIZE_const(GetMaxSize);
154 DEC_PYCALLBACK_VOID_WXWINBASE(AddChild);
155 DEC_PYCALLBACK_VOID_WXWINBASE(RemoveChild);
161 IMPLEMENT_ABSTRACT_CLASS(wxPyWizardPage, wxWizardPage);
163 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetPrev);
164 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetNext);
165 IMP_PYCALLBACK_BITMAP__pure(wxPyWizardPage, wxWizardPage, GetBitmap);
167 IMP_PYCALLBACK_VOID_INT4(wxPyWizardPage, wxWizardPage, DoMoveWindow);
168 IMP_PYCALLBACK_VOID_INT5(wxPyWizardPage, wxWizardPage, DoSetSize);
169 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetClientSize);
170 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetVirtualSize);
172 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetSize);
173 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetClientSize);
174 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetPosition);
176 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetVirtualSize);
177 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetBestSize);
179 IMP_PYCALLBACK__(wxPyWizardPage, wxWizardPage, InitDialog);
180 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataFromWindow);
181 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataToWindow);
182 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, Validate);
184 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocus);
185 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocusFromKeyboard);
186 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, GetMaxSize);
188 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, AddChild);
189 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, RemoveChild);
195 class wxPyWizardPage : public wxWizardPage {
198 %addtofunc wxPyWizardPage "self._setCallbackInfo(self, PyWizardPage);self._setOORInfo(self)"
199 %addtofunc wxPyWizardPage() ""
201 // ctor accepts an optional bitmap which will be used for this page instead
202 // of the default one for this wizard (should be of the same size). Notice
203 // that no other parameters are needed because the wizard will resize and
204 // reposition the page anyhow
206 wxPyWizardPage(wxWizard *parent,
207 const wxBitmap* bitmap = &wxNullBitmap,
208 const wxString* resource = &wxPyEmptyString) {
210 if (resource->Length())
211 res = (wxChar*)resource->c_str();
212 return new wxPyWizardPage(parent, *bitmap, res);
216 %name(PrePyWizardPage)wxPyWizardPage();
219 bool Create(wxWizard *parent,
220 const wxBitmap& bitmap = wxNullBitmap,
221 const wxString& resource = wxPyEmptyString) {
223 if (resource.Length())
224 res = (wxChar*)resource.c_str();
225 return self->Create(parent, bitmap, res);
229 void _setCallbackInfo(PyObject* self, PyObject* _class);
231 void base_DoMoveWindow(int x, int y, int width, int height);
232 void base_DoSetSize(int x, int y, int width, int height,
233 int sizeFlags = wxSIZE_AUTO);
234 void base_DoSetClientSize(int width, int height);
235 void base_DoSetVirtualSize( int x, int y );
238 void, base_DoGetSize( int *OUTPUT, int *OUTPUT ) const,
239 "base_DoGetSize() -> (width, height)");
241 void, base_DoGetClientSize( int *OUTPUT, int *OUTPUT ) const,
242 "base_DoGetClientSize() -> (width, height)");
244 void, base_DoGetPosition( int *OUTPUT, int *OUTPUT ) const,
245 "base_DoGetPosition() -> (x,y)");
247 wxSize base_DoGetVirtualSize() const;
248 wxSize base_DoGetBestSize() const;
250 void base_InitDialog();
251 bool base_TransferDataToWindow();
252 bool base_TransferDataFromWindow();
253 bool base_Validate();
255 bool base_AcceptsFocus() const;
256 bool base_AcceptsFocusFromKeyboard() const;
257 wxSize base_GetMaxSize() const;
259 void base_AddChild(wxWindow* child);
260 void base_RemoveChild(wxWindow* child);
263 //----------------------------------------------------------------------
266 // wxWizardPageSimple just returns the pointers given to the ctor and is useful
267 // to create a simple wizard where the order of pages never changes.
269 // OTOH, it is also possible to dynamicly decide which page to return (i.e.
270 // depending on the user's choices) as the wizard sample shows - in order to do
271 // this, you must derive from wxWizardPage directly.
272 class wxWizardPageSimple : public wxWizardPage
276 %addtofunc wxWizardPageSimple "self._setOORInfo(self)"
277 %addtofunc wxWizardPageSimple() ""
279 // ctor takes the previous and next pages
280 wxWizardPageSimple(wxWizard *parent,
281 wxWizardPage *prev = NULL,
282 wxWizardPage *next = NULL,
283 const wxBitmap& bitmap = wxNullBitmap,
284 const wxChar* resource = NULL);
285 %name(PreWizardPageSimple)wxWizardPageSimple();
287 bool Create(wxWizard *parent = NULL,
288 wxWizardPage *prev = NULL,
289 wxWizardPage *next = NULL,
290 const wxBitmap& bitmap = wxNullBitmap,
291 const wxChar* resource = NULL);
293 // the pointers may be also set later - but before starting the wizard
294 void SetPrev(wxWizardPage *prev);
295 void SetNext(wxWizardPage *next);
297 // a convenience function to make the pages follow each other
298 static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second);
302 //----------------------------------------------------------------------
304 class wxWizard : public wxDialog
307 %addtofunc wxWizard "self._setOORInfo(self)"
308 %addtofunc wxWizard() ""
311 wxWizard(wxWindow *parent,
313 const wxString& title = wxEmptyString,
314 const wxBitmap& bitmap = wxNullBitmap,
315 const wxPoint& pos = wxDefaultPosition,
316 long style = wxDEFAULT_DIALOG_STYLE);
317 %name(PreWizard)wxWizard();
319 bool Create(wxWindow *parent,
321 const wxString& title = wxEmptyString,
322 const wxBitmap& bitmap = wxNullBitmap,
323 const wxPoint& pos = wxDefaultPosition);
328 // executes the wizard starting from the given page, returns True if it was
329 // successfully finished, False if user cancelled it
330 virtual bool RunWizard(wxWizardPage *firstPage);
332 // get the current page (NULL if RunWizard() isn't running)
333 virtual wxWizardPage *GetCurrentPage() const;
335 // set the min size which should be available for the pages: a
336 // wizard will take into account the size of the bitmap (if any)
337 // itself and will never be less than some predefined fixed size
338 virtual void SetPageSize(const wxSize& size);
340 // get the size available for the page: the wizards are not resizeable, so
341 // this size doesn't change
342 virtual wxSize GetPageSize() const;
344 // set the best size for the wizard, i.e. make it big enough to contain all
345 // of the pages starting from the given one
347 // this function may be called several times and possible with different
348 // pages in which case it will only increase the page size if needed (this
349 // may be useful if not all pages are accessible from the first one by
351 virtual void FitToPage(const wxWizardPage *firstPage);
353 // Adding pages to page area sizer enlarges wizard
354 virtual wxSizer *GetPageAreaSizer() const;
356 // Set border around page area. Default is 0 if you add at least one
357 // page to GetPageAreaSizer and 5 if you don't.
358 virtual void SetBorder(int border);
360 // is the wizard running?
361 bool IsRunning() const { return m_page != NULL; }
363 // show the prev/next page, but call TransferDataFromWindow on the current
364 // page first and return False without changing the page if
365 // TransferDataFromWindow() returns False - otherwise, returns True
366 bool ShowPage(wxWizardPage *page, bool goingForward = True);
368 bool HasNextPage(wxWizardPage* page);
369 bool HasPrevPage(wxWizardPage* page);
373 //----------------------------------------------------------------------
378 //---------------------------------------------------------------------------