]>
Commit | Line | Data |
---|---|---|
af83019e RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wizard.i | |
3 | // Purpose: Classes for wxWizard and etc. | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 16-Aug-2002 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2002 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
c8fac2b6 RD |
13 | %define DOCSTRING |
14 | "`Wizard` is a dialog class that guides the user through a sequence of steps, | |
15 | or pages." | |
16 | %enddef | |
b2eb030f RD |
17 | |
18 | %module(package="wx", docstring=DOCSTRING) wizard | |
af83019e RD |
19 | |
20 | %{ | |
d14a1e28 RD |
21 | #include "wx/wxPython/wxPython.h" |
22 | #include "wx/wxPython/pyclasses.h" | |
23 | #include "wx/wxPython/printfw.h" | |
24 | ||
af83019e | 25 | #include <wx/wizard.h> |
d14a1e28 | 26 | |
af83019e RD |
27 | %} |
28 | ||
29 | //---------------------------------------------------------------------- | |
30 | ||
af83019e | 31 | %import windows.i |
54f9ee45 | 32 | %pythoncode { wx = _core } |
99109c0f | 33 | %pythoncode { __docfilter__ = wx.__DocFilter(globals()) } |
af83019e | 34 | |
b2dc1044 RD |
35 | MAKE_CONST_WXSTRING_NOSWIG(EmptyString); |
36 | ||
af83019e RD |
37 | //---------------------------------------------------------------------- |
38 | ||
39 | enum { | |
40 | wxWIZARD_EX_HELPBUTTON, | |
af83019e RD |
41 | }; |
42 | ||
d14a1e28 RD |
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; | |
af83019e | 48 | |
af83019e | 49 | |
af83019e | 50 | |
d14a1e28 RD |
51 | %pythoncode { |
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) | |
57 | } | |
af83019e RD |
58 | |
59 | //---------------------------------------------------------------------- | |
60 | ||
61 | class wxWizardEvent : public wxNotifyEvent | |
62 | { | |
63 | public: | |
64 | wxWizardEvent(wxEventType type = wxEVT_NULL, | |
65 | int id = -1, | |
a72f4631 | 66 | bool direction = true, |
af83019e RD |
67 | wxWizardPage* page = NULL); |
68 | ||
dd9f7fea RD |
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 | |
af83019e RD |
72 | // (this function doesn't make sense for CANCEL events) |
73 | bool GetDirection() const { return m_direction; } | |
74 | ||
75 | wxWizardPage* GetPage() const { return m_page; } | |
76 | }; | |
77 | ||
78 | ||
79 | //---------------------------------------------------------------------- | |
80 | ||
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). | |
83 | // | |
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). | |
ab1f7d2a | 86 | MustHaveApp(wxWizardPage); |
af83019e RD |
87 | class wxWizardPage : public wxPanel |
88 | { | |
89 | public: | |
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); | |
1b8c7ba6 | 97 | // %RenameCtor(PreWizardPage, wxWizardPage()); |
af83019e | 98 | |
d14a1e28 | 99 | %extend { |
dd4a4b90 RD |
100 | bool Create(wxWizard *parent, |
101 | const wxBitmap& bitmap = wxNullBitmap, | |
102 | const wxString& resource = wxPyEmptyString) { | |
103 | wxChar* res = NULL; | |
2fbb702b | 104 | if (resource.length()) |
dd4a4b90 RD |
105 | res = (wxChar*)resource.c_str(); |
106 | return self->Create(parent, bitmap, res); | |
107 | } | |
108 | } | |
109 | ||
af83019e | 110 | |
af83019e RD |
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; | |
115 | ||
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; | |
121 | }; | |
122 | ||
123 | ||
124 | ||
125 | %{ // C++ Version of a Python aware class | |
126 | class wxPyWizardPage : public wxWizardPage { | |
4617be08 | 127 | DECLARE_ABSTRACT_CLASS(wxPyWizardPage) |
af83019e RD |
128 | public: |
129 | wxPyWizardPage() : wxWizardPage() {} | |
130 | wxPyWizardPage(wxWizard *parent, | |
131 | const wxBitmap& bitmap = wxNullBitmap, | |
132 | const wxChar* resource = NULL) | |
133 | : wxWizardPage(parent, bitmap, resource) {} | |
134 | ||
135 | DEC_PYCALLBACK_WIZPG__pure(GetPrev); | |
136 | DEC_PYCALLBACK_WIZPG__pure(GetNext); | |
137 | DEC_PYCALLBACK_BITMAP__pure(GetBitmap); | |
138 | ||
139 | DEC_PYCALLBACK_VOID_INT4(DoMoveWindow); | |
140 | DEC_PYCALLBACK_VOID_INT5(DoSetSize); | |
141 | DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize); | |
142 | DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize); | |
143 | ||
144 | DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize); | |
145 | DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize); | |
146 | DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition); | |
147 | ||
148 | DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize); | |
149 | DEC_PYCALLBACK_SIZE_const(DoGetBestSize); | |
150 | ||
151 | DEC_PYCALLBACK__(InitDialog); | |
152 | DEC_PYCALLBACK_BOOL_(TransferDataFromWindow); | |
153 | DEC_PYCALLBACK_BOOL_(TransferDataToWindow); | |
154 | DEC_PYCALLBACK_BOOL_(Validate); | |
155 | ||
156 | DEC_PYCALLBACK_BOOL_const(AcceptsFocus); | |
157 | DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard); | |
158 | DEC_PYCALLBACK_SIZE_const(GetMaxSize); | |
159 | ||
160 | DEC_PYCALLBACK_VOID_WXWINBASE(AddChild); | |
161 | DEC_PYCALLBACK_VOID_WXWINBASE(RemoveChild); | |
162 | ||
163 | PYPRIVATE; | |
164 | }; | |
165 | ||
166 | ||
167 | IMPLEMENT_ABSTRACT_CLASS(wxPyWizardPage, wxWizardPage); | |
168 | ||
169 | IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetPrev); | |
170 | IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetNext); | |
171 | IMP_PYCALLBACK_BITMAP__pure(wxPyWizardPage, wxWizardPage, GetBitmap); | |
172 | ||
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); | |
177 | ||
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); | |
181 | ||
182 | IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetVirtualSize); | |
183 | IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetBestSize); | |
184 | ||
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); | |
189 | ||
190 | IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocus); | |
191 | IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocusFromKeyboard); | |
192 | IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, GetMaxSize); | |
193 | ||
194 | IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, AddChild); | |
195 | IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, RemoveChild); | |
196 | ||
197 | %} | |
198 | ||
199 | ||
200 | ||
ab1f7d2a RD |
201 | MustHaveApp(wxPyWizardPage); |
202 | ||
af83019e RD |
203 | class wxPyWizardPage : public wxWizardPage { |
204 | public: | |
d14a1e28 | 205 | |
2b9048c5 RD |
206 | %pythonAppend wxPyWizardPage "self._setCallbackInfo(self, PyWizardPage);self._setOORInfo(self)" |
207 | %pythonAppend wxPyWizardPage() "" | |
b39c3fa0 | 208 | %typemap(out) wxPyWizardPage*; // turn off this typemap |
d14a1e28 | 209 | |
af83019e RD |
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 | |
d14a1e28 | 214 | %extend { |
dd4a4b90 RD |
215 | wxPyWizardPage(wxWizard *parent, |
216 | const wxBitmap* bitmap = &wxNullBitmap, | |
217 | const wxString* resource = &wxPyEmptyString) { | |
218 | wxChar* res = NULL; | |
2fbb702b | 219 | if (resource->length()) |
dd4a4b90 RD |
220 | res = (wxChar*)resource->c_str(); |
221 | return new wxPyWizardPage(parent, *bitmap, res); | |
222 | } | |
223 | } | |
224 | ||
1b8c7ba6 | 225 | %RenameCtor(PrePyWizardPage, wxPyWizardPage()); |
af83019e | 226 | |
b39c3fa0 RD |
227 | // Turn it back on again |
228 | %typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, $owner); } | |
229 | ||
d14a1e28 | 230 | %extend { |
dd4a4b90 RD |
231 | bool Create(wxWizard *parent, |
232 | const wxBitmap& bitmap = wxNullBitmap, | |
233 | const wxString& resource = wxPyEmptyString) { | |
234 | wxChar* res = NULL; | |
2fbb702b | 235 | if (resource.length()) |
dd4a4b90 RD |
236 | res = (wxChar*)resource.c_str(); |
237 | return self->Create(parent, bitmap, res); | |
238 | } | |
239 | } | |
af83019e RD |
240 | |
241 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
af83019e | 242 | |
a7a01418 RD |
243 | void DoMoveWindow(int x, int y, int width, int height); |
244 | void DoSetSize(int x, int y, int width, int height, | |
af83019e | 245 | int sizeFlags = wxSIZE_AUTO); |
a7a01418 RD |
246 | void DoSetClientSize(int width, int height); |
247 | void DoSetVirtualSize( int x, int y ); | |
af83019e | 248 | |
322913ce | 249 | DocDeclA( |
a7a01418 RD |
250 | void, DoGetSize( int *OUTPUT, int *OUTPUT ) const, |
251 | "DoGetSize() -> (width, height)"); | |
322913ce | 252 | DocDeclA( |
a7a01418 RD |
253 | void, DoGetClientSize( int *OUTPUT, int *OUTPUT ) const, |
254 | "DoGetClientSize() -> (width, height)"); | |
322913ce | 255 | DocDeclA( |
a7a01418 RD |
256 | void, DoGetPosition( int *OUTPUT, int *OUTPUT ) const, |
257 | "DoGetPosition() -> (x,y)"); | |
258 | ||
259 | wxSize DoGetVirtualSize() const; | |
260 | wxSize DoGetBestSize() const; | |
261 | ||
262 | void InitDialog(); | |
263 | bool TransferDataToWindow(); | |
264 | bool TransferDataFromWindow(); | |
265 | bool Validate(); | |
266 | ||
267 | bool AcceptsFocus() const; | |
268 | bool AcceptsFocusFromKeyboard() const; | |
269 | wxSize GetMaxSize() const; | |
270 | ||
271 | void AddChild(wxWindow* child); | |
272 | void RemoveChild(wxWindow* child); | |
273 | ||
274 | bool ShouldInheritColours() const; | |
275 | wxVisualAttributes GetDefaultAttributes(); | |
276 | ||
277 | void OnInternalIdle(); | |
278 | ||
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); | |
300 | ||
af83019e RD |
301 | }; |
302 | ||
303 | //---------------------------------------------------------------------- | |
304 | ||
305 | ||
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. | |
308 | // | |
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. | |
ab1f7d2a | 312 | MustHaveApp(wxWizardPageSimple); |
af83019e RD |
313 | class wxWizardPageSimple : public wxWizardPage |
314 | { | |
315 | public: | |
d14a1e28 | 316 | |
2b9048c5 RD |
317 | %pythonAppend wxWizardPageSimple "self._setOORInfo(self)" |
318 | %pythonAppend wxWizardPageSimple() "" | |
d14a1e28 | 319 | |
af83019e RD |
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); | |
1b8c7ba6 | 326 | %RenameCtor(PreWizardPageSimple, wxWizardPageSimple()); |
af83019e RD |
327 | |
328 | bool Create(wxWizard *parent = NULL, | |
329 | wxWizardPage *prev = NULL, | |
330 | wxWizardPage *next = NULL, | |
331 | const wxBitmap& bitmap = wxNullBitmap, | |
332 | const wxChar* resource = NULL); | |
333 | ||
af83019e RD |
334 | // the pointers may be also set later - but before starting the wizard |
335 | void SetPrev(wxWizardPage *prev); | |
336 | void SetNext(wxWizardPage *next); | |
337 | ||
338 | // a convenience function to make the pages follow each other | |
339 | static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second); | |
340 | }; | |
341 | ||
342 | ||
343 | //---------------------------------------------------------------------- | |
344 | ||
ab1f7d2a RD |
345 | MustHaveApp(wxWizard); |
346 | ||
af83019e RD |
347 | class wxWizard : public wxDialog |
348 | { | |
349 | public: | |
2b9048c5 RD |
350 | %pythonAppend wxWizard "self._setOORInfo(self)" |
351 | %pythonAppend wxWizard() "" | |
d14a1e28 | 352 | |
af83019e RD |
353 | // ctor |
354 | wxWizard(wxWindow *parent, | |
355 | int id = -1, | |
b2dc1044 | 356 | const wxString& title = wxPyEmptyString, |
af83019e | 357 | const wxBitmap& bitmap = wxNullBitmap, |
3ef86e32 RD |
358 | const wxPoint& pos = wxDefaultPosition, |
359 | long style = wxDEFAULT_DIALOG_STYLE); | |
1b8c7ba6 | 360 | %RenameCtor(PreWizard, wxWizard()); |
af83019e RD |
361 | |
362 | bool Create(wxWindow *parent, | |
363 | int id = -1, | |
b2dc1044 | 364 | const wxString& title = wxPyEmptyString, |
af83019e RD |
365 | const wxBitmap& bitmap = wxNullBitmap, |
366 | const wxPoint& pos = wxDefaultPosition); | |
367 | ||
368 | void Init(); | |
369 | ||
370 | ||
dd9f7fea RD |
371 | // executes the wizard starting from the given page, returns True if it was |
372 | // successfully finished, False if user cancelled it | |
af83019e RD |
373 | virtual bool RunWizard(wxWizardPage *firstPage); |
374 | ||
375 | // get the current page (NULL if RunWizard() isn't running) | |
376 | virtual wxWizardPage *GetCurrentPage() const; | |
377 | ||
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); | |
382 | ||
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; | |
386 | ||
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 | |
389 | // | |
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 | |
393 | // default) | |
394 | virtual void FitToPage(const wxWizardPage *firstPage); | |
395 | ||
3ef86e32 RD |
396 | // Adding pages to page area sizer enlarges wizard |
397 | virtual wxSizer *GetPageAreaSizer() const; | |
398 | ||
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); | |
402 | ||
af83019e | 403 | // is the wizard running? |
2fbb702b | 404 | bool IsRunning() const; |
af83019e RD |
405 | |
406 | // show the prev/next page, but call TransferDataFromWindow on the current | |
dd9f7fea RD |
407 | // page first and return False without changing the page if |
408 | // TransferDataFromWindow() returns False - otherwise, returns True | |
a72f4631 | 409 | bool ShowPage(wxWizardPage *page, bool goingForward = true); |
1e4a197e RD |
410 | |
411 | bool HasNextPage(wxWizardPage* page); | |
412 | bool HasPrevPage(wxWizardPage* page); | |
af83019e RD |
413 | }; |
414 | ||
415 | ||
416 | //---------------------------------------------------------------------- | |
85260f24 RD |
417 | |
418 | %init %{ | |
85260f24 RD |
419 | %} |
420 | ||
af83019e | 421 | //--------------------------------------------------------------------------- |