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 }
29 %include _wizard_rename.i
31 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
33 //----------------------------------------------------------------------
36 wxWIZARD_EX_HELPBUTTON,
39 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGED;
40 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGING;
41 %constant wxEventType wxEVT_WIZARD_CANCEL;
42 %constant wxEventType wxEVT_WIZARD_HELP;
43 %constant wxEventType wxEVT_WIZARD_FINISHED;
48 EVT_WIZARD_PAGE_CHANGED = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGED, 1)
49 EVT_WIZARD_PAGE_CHANGING = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGING, 1)
50 EVT_WIZARD_CANCEL = wx.PyEventBinder( wxEVT_WIZARD_CANCEL, 1)
51 EVT_WIZARD_HELP = wx.PyEventBinder( wxEVT_WIZARD_HELP, 1)
52 EVT_WIZARD_FINISHED = wx.PyEventBinder( wxEVT_WIZARD_FINISHED, 1)
55 //----------------------------------------------------------------------
57 class wxWizardEvent : public wxNotifyEvent
60 wxWizardEvent(wxEventType type = wxEVT_NULL,
62 bool direction = True,
63 wxWizardPage* page = NULL);
65 // for EVT_WIZARD_PAGE_CHANGING, return True if we're going forward or
66 // False otherwise and for EVT_WIZARD_PAGE_CHANGED return True if we came
67 // from the previous page and False if we returned from the next one
68 // (this function doesn't make sense for CANCEL events)
69 bool GetDirection() const { return m_direction; }
71 wxWizardPage* GetPage() const { return m_page; }
75 //----------------------------------------------------------------------
77 // wxWizardPage is one of the wizards screen: it must know what are the
78 // following and preceding pages (which may be NULL for the first/last page).
80 // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be
81 // used as such (i.e. controls may be placed directly on it &c).
82 class wxWizardPage : public wxPanel
85 // // ctor accepts an optional bitmap which will be used for this page instead
86 // // of the default one for this wizard (should be of the same size). Notice
87 // // that no other parameters are needed because the wizard will resize and
88 // // reposition the page anyhow
89 // wxWizardPage(wxWizard *parent,
90 // const wxBitmap& bitmap = wxNullBitmap,
91 // const char* resource = NULL);
92 // %name(PreWizardPage)wxWizardPage();
95 bool Create(wxWizard *parent,
96 const wxBitmap& bitmap = wxNullBitmap,
97 const wxString& resource = wxPyEmptyString) {
99 if (resource.Length())
100 res = (wxChar*)resource.c_str();
101 return self->Create(parent, bitmap, res);
106 // these functions are used by the wizard to show another page when the
107 // user chooses "Back" or "Next" button
108 virtual wxWizardPage *GetPrev() const;
109 virtual wxWizardPage *GetNext() const;
111 // default GetBitmap() will just return m_bitmap which is ok in 99% of
112 // cases - override this method if you want to create the bitmap to be used
113 // dynamically or to do something even more fancy. It's ok to return
114 // wxNullBitmap from here - the default one will be used then.
115 virtual wxBitmap GetBitmap() const;
120 %{ // C++ Version of a Python aware class
121 class wxPyWizardPage : public wxWizardPage {
122 DECLARE_ABSTRACT_CLASS(wxPyWizardPage);
124 wxPyWizardPage() : wxWizardPage() {}
125 wxPyWizardPage(wxWizard *parent,
126 const wxBitmap& bitmap = wxNullBitmap,
127 const wxChar* resource = NULL)
128 : wxWizardPage(parent, bitmap, resource) {}
130 DEC_PYCALLBACK_WIZPG__pure(GetPrev);
131 DEC_PYCALLBACK_WIZPG__pure(GetNext);
132 DEC_PYCALLBACK_BITMAP__pure(GetBitmap);
134 DEC_PYCALLBACK_VOID_INT4(DoMoveWindow);
135 DEC_PYCALLBACK_VOID_INT5(DoSetSize);
136 DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize);
137 DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize);
139 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize);
140 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize);
141 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition);
143 DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize);
144 DEC_PYCALLBACK_SIZE_const(DoGetBestSize);
146 DEC_PYCALLBACK__(InitDialog);
147 DEC_PYCALLBACK_BOOL_(TransferDataFromWindow);
148 DEC_PYCALLBACK_BOOL_(TransferDataToWindow);
149 DEC_PYCALLBACK_BOOL_(Validate);
151 DEC_PYCALLBACK_BOOL_const(AcceptsFocus);
152 DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard);
153 DEC_PYCALLBACK_SIZE_const(GetMaxSize);
155 DEC_PYCALLBACK_VOID_WXWINBASE(AddChild);
156 DEC_PYCALLBACK_VOID_WXWINBASE(RemoveChild);
162 IMPLEMENT_ABSTRACT_CLASS(wxPyWizardPage, wxWizardPage);
164 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetPrev);
165 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetNext);
166 IMP_PYCALLBACK_BITMAP__pure(wxPyWizardPage, wxWizardPage, GetBitmap);
168 IMP_PYCALLBACK_VOID_INT4(wxPyWizardPage, wxWizardPage, DoMoveWindow);
169 IMP_PYCALLBACK_VOID_INT5(wxPyWizardPage, wxWizardPage, DoSetSize);
170 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetClientSize);
171 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetVirtualSize);
173 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetSize);
174 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetClientSize);
175 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetPosition);
177 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetVirtualSize);
178 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetBestSize);
180 IMP_PYCALLBACK__(wxPyWizardPage, wxWizardPage, InitDialog);
181 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataFromWindow);
182 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataToWindow);
183 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, Validate);
185 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocus);
186 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocusFromKeyboard);
187 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, GetMaxSize);
189 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, AddChild);
190 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, RemoveChild);
196 class wxPyWizardPage : public wxWizardPage {
199 %pythonAppend wxPyWizardPage "self._setCallbackInfo(self, PyWizardPage);self._setOORInfo(self)"
200 %pythonAppend wxPyWizardPage() ""
202 // ctor accepts an optional bitmap which will be used for this page instead
203 // of the default one for this wizard (should be of the same size). Notice
204 // that no other parameters are needed because the wizard will resize and
205 // reposition the page anyhow
207 wxPyWizardPage(wxWizard *parent,
208 const wxBitmap* bitmap = &wxNullBitmap,
209 const wxString* resource = &wxPyEmptyString) {
211 if (resource->Length())
212 res = (wxChar*)resource->c_str();
213 return new wxPyWizardPage(parent, *bitmap, res);
217 %name(PrePyWizardPage)wxPyWizardPage();
220 bool Create(wxWizard *parent,
221 const wxBitmap& bitmap = wxNullBitmap,
222 const wxString& resource = wxPyEmptyString) {
224 if (resource.Length())
225 res = (wxChar*)resource.c_str();
226 return self->Create(parent, bitmap, res);
230 void _setCallbackInfo(PyObject* self, PyObject* _class);
232 void base_DoMoveWindow(int x, int y, int width, int height);
233 void base_DoSetSize(int x, int y, int width, int height,
234 int sizeFlags = wxSIZE_AUTO);
235 void base_DoSetClientSize(int width, int height);
236 void base_DoSetVirtualSize( int x, int y );
239 void, base_DoGetSize( int *OUTPUT, int *OUTPUT ) const,
240 "base_DoGetSize() -> (width, height)");
242 void, base_DoGetClientSize( int *OUTPUT, int *OUTPUT ) const,
243 "base_DoGetClientSize() -> (width, height)");
245 void, base_DoGetPosition( int *OUTPUT, int *OUTPUT ) const,
246 "base_DoGetPosition() -> (x,y)");
248 wxSize base_DoGetVirtualSize() const;
249 wxSize base_DoGetBestSize() const;
251 void base_InitDialog();
252 bool base_TransferDataToWindow();
253 bool base_TransferDataFromWindow();
254 bool base_Validate();
256 bool base_AcceptsFocus() const;
257 bool base_AcceptsFocusFromKeyboard() const;
258 wxSize base_GetMaxSize() const;
260 void base_AddChild(wxWindow* child);
261 void base_RemoveChild(wxWindow* child);
264 //----------------------------------------------------------------------
267 // wxWizardPageSimple just returns the pointers given to the ctor and is useful
268 // to create a simple wizard where the order of pages never changes.
270 // OTOH, it is also possible to dynamicly decide which page to return (i.e.
271 // depending on the user's choices) as the wizard sample shows - in order to do
272 // this, you must derive from wxWizardPage directly.
273 class wxWizardPageSimple : public wxWizardPage
277 %pythonAppend wxWizardPageSimple "self._setOORInfo(self)"
278 %pythonAppend wxWizardPageSimple() ""
280 // ctor takes the previous and next pages
281 wxWizardPageSimple(wxWizard *parent,
282 wxWizardPage *prev = NULL,
283 wxWizardPage *next = NULL,
284 const wxBitmap& bitmap = wxNullBitmap,
285 const wxChar* resource = NULL);
286 %name(PreWizardPageSimple)wxWizardPageSimple();
288 bool Create(wxWizard *parent = NULL,
289 wxWizardPage *prev = NULL,
290 wxWizardPage *next = NULL,
291 const wxBitmap& bitmap = wxNullBitmap,
292 const wxChar* resource = NULL);
294 // the pointers may be also set later - but before starting the wizard
295 void SetPrev(wxWizardPage *prev);
296 void SetNext(wxWizardPage *next);
298 // a convenience function to make the pages follow each other
299 static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second);
303 //----------------------------------------------------------------------
305 class wxWizard : public wxDialog
308 %pythonAppend wxWizard "self._setOORInfo(self)"
309 %pythonAppend wxWizard() ""
312 wxWizard(wxWindow *parent,
314 const wxString& title = wxPyEmptyString,
315 const wxBitmap& bitmap = wxNullBitmap,
316 const wxPoint& pos = wxDefaultPosition,
317 long style = wxDEFAULT_DIALOG_STYLE);
318 %name(PreWizard)wxWizard();
320 bool Create(wxWindow *parent,
322 const wxString& title = wxPyEmptyString,
323 const wxBitmap& bitmap = wxNullBitmap,
324 const wxPoint& pos = wxDefaultPosition);
329 // executes the wizard starting from the given page, returns True if it was
330 // successfully finished, False if user cancelled it
331 virtual bool RunWizard(wxWizardPage *firstPage);
333 // get the current page (NULL if RunWizard() isn't running)
334 virtual wxWizardPage *GetCurrentPage() const;
336 // set the min size which should be available for the pages: a
337 // wizard will take into account the size of the bitmap (if any)
338 // itself and will never be less than some predefined fixed size
339 virtual void SetPageSize(const wxSize& size);
341 // get the size available for the page: the wizards are not resizeable, so
342 // this size doesn't change
343 virtual wxSize GetPageSize() const;
345 // set the best size for the wizard, i.e. make it big enough to contain all
346 // of the pages starting from the given one
348 // this function may be called several times and possible with different
349 // pages in which case it will only increase the page size if needed (this
350 // may be useful if not all pages are accessible from the first one by
352 virtual void FitToPage(const wxWizardPage *firstPage);
354 // Adding pages to page area sizer enlarges wizard
355 virtual wxSizer *GetPageAreaSizer() const;
357 // Set border around page area. Default is 0 if you add at least one
358 // page to GetPageAreaSizer and 5 if you don't.
359 virtual void SetBorder(int border);
361 // is the wizard running?
362 bool IsRunning() const { return m_page != NULL; }
364 // show the prev/next page, but call TransferDataFromWindow on the current
365 // page first and return False without changing the page if
366 // TransferDataFromWindow() returns False - otherwise, returns True
367 bool ShowPage(wxWizardPage *page, bool goingForward = True);
369 bool HasNextPage(wxWizardPage* page);
370 bool HasPrevPage(wxWizardPage* page);
374 //----------------------------------------------------------------------
379 //---------------------------------------------------------------------------