]>
Commit | Line | Data |
---|---|---|
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 | ||
13 | %define DOCSTRING | |
14 | "`Wizard` is a dialog class that guides the user through a sequence of steps, | |
15 | or pages." | |
16 | %enddef | |
17 | ||
18 | %module(package="wx", docstring=DOCSTRING) wizard | |
19 | ||
20 | %{ | |
21 | #include "wx/wxPython/wxPython.h" | |
22 | #include "wx/wxPython/pyclasses.h" | |
23 | #include "wx/wxPython/printfw.h" | |
24 | ||
25 | #include <wx/wizard.h> | |
26 | ||
27 | %} | |
28 | ||
29 | //---------------------------------------------------------------------- | |
30 | ||
31 | %import windows.i | |
32 | %pythoncode { wx = _core } | |
33 | %pythoncode { __docfilter__ = wx.__DocFilter(globals()) } | |
34 | ||
35 | MAKE_CONST_WXSTRING_NOSWIG(EmptyString); | |
36 | ||
37 | //---------------------------------------------------------------------- | |
38 | ||
39 | enum { | |
40 | wxWIZARD_EX_HELPBUTTON, | |
41 | }; | |
42 | ||
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; | |
48 | ||
49 | ||
50 | ||
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 | } | |
58 | ||
59 | //---------------------------------------------------------------------- | |
60 | ||
61 | class wxWizardEvent : public wxNotifyEvent | |
62 | { | |
63 | public: | |
64 | wxWizardEvent(wxEventType type = wxEVT_NULL, | |
65 | int id = -1, | |
66 | bool direction = true, | |
67 | wxWizardPage* page = NULL); | |
68 | ||
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; | |
74 | ||
75 | wxWizardPage* GetPage() const; | |
76 | ||
77 | %property(Direction, GetDirection, doc="See `GetDirection`"); | |
78 | %property(Page, GetPage, doc="See `GetPage`"); | |
79 | }; | |
80 | ||
81 | ||
82 | //---------------------------------------------------------------------- | |
83 | ||
84 | // wxWizardPage is one of the wizards screen: it must know what are the | |
85 | // following and preceding pages (which may be NULL for the first/last page). | |
86 | // | |
87 | // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be | |
88 | // used as such (i.e. controls may be placed directly on it &c). | |
89 | MustHaveApp(wxWizardPage); | |
90 | class wxWizardPage : public wxPanel | |
91 | { | |
92 | public: | |
93 | // // ctor accepts an optional bitmap which will be used for this page instead | |
94 | // // of the default one for this wizard (should be of the same size). Notice | |
95 | // // that no other parameters are needed because the wizard will resize and | |
96 | // // reposition the page anyhow | |
97 | // wxWizardPage(wxWizard *parent, | |
98 | // const wxBitmap& bitmap = wxNullBitmap, | |
99 | // const char* resource = NULL); | |
100 | // %RenameCtor(PreWizardPage, wxWizardPage()); | |
101 | ||
102 | %extend { | |
103 | bool Create(wxWizard *parent, | |
104 | const wxBitmap& bitmap = wxNullBitmap, | |
105 | const wxString& resource = wxPyEmptyString) { | |
106 | wxChar* res = NULL; | |
107 | if (resource.length()) | |
108 | res = (wxChar*)resource.c_str(); | |
109 | return self->Create(parent, bitmap, res); | |
110 | } | |
111 | } | |
112 | ||
113 | ||
114 | // these functions are used by the wizard to show another page when the | |
115 | // user chooses "Back" or "Next" button | |
116 | virtual wxWizardPage *GetPrev() const; | |
117 | virtual wxWizardPage *GetNext() const; | |
118 | ||
119 | // default GetBitmap() will just return m_bitmap which is ok in 99% of | |
120 | // cases - override this method if you want to create the bitmap to be used | |
121 | // dynamically or to do something even more fancy. It's ok to return | |
122 | // wxNullBitmap from here - the default one will be used then. | |
123 | virtual wxBitmap GetBitmap() const; | |
124 | ||
125 | %property(Bitmap, GetBitmap, doc="See `GetBitmap`"); | |
126 | %property(Next, GetNext, doc="See `GetNext`"); | |
127 | %property(Prev, GetPrev, doc="See `GetPrev`"); | |
128 | }; | |
129 | ||
130 | ||
131 | ||
132 | %{ // C++ Version of a Python aware class | |
133 | class wxPyWizardPage : public wxWizardPage { | |
134 | DECLARE_ABSTRACT_CLASS(wxPyWizardPage) | |
135 | public: | |
136 | wxPyWizardPage() : wxWizardPage() {} | |
137 | wxPyWizardPage(wxWizard *parent, | |
138 | const wxBitmap& bitmap = wxNullBitmap, | |
139 | const wxChar* resource = NULL) | |
140 | : wxWizardPage(parent, bitmap, resource) {} | |
141 | ||
142 | DEC_PYCALLBACK_WIZPG__pure(GetPrev); | |
143 | DEC_PYCALLBACK_WIZPG__pure(GetNext); | |
144 | DEC_PYCALLBACK_BITMAP__pure(GetBitmap); | |
145 | ||
146 | DEC_PYCALLBACK_VOID_INT4(DoMoveWindow); | |
147 | DEC_PYCALLBACK_VOID_INT5(DoSetSize); | |
148 | DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize); | |
149 | DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize); | |
150 | ||
151 | DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize); | |
152 | DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize); | |
153 | DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition); | |
154 | ||
155 | DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize); | |
156 | DEC_PYCALLBACK_SIZE_const(DoGetBestSize); | |
157 | ||
158 | DEC_PYCALLBACK__(InitDialog); | |
159 | DEC_PYCALLBACK_BOOL_(TransferDataFromWindow); | |
160 | DEC_PYCALLBACK_BOOL_(TransferDataToWindow); | |
161 | DEC_PYCALLBACK_BOOL_(Validate); | |
162 | ||
163 | DEC_PYCALLBACK_BOOL_const(AcceptsFocus); | |
164 | DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard); | |
165 | DEC_PYCALLBACK_SIZE_const(GetMaxSize); | |
166 | ||
167 | DEC_PYCALLBACK_VOID_WXWINBASE(AddChild); | |
168 | DEC_PYCALLBACK_VOID_WXWINBASE(RemoveChild); | |
169 | ||
170 | PYPRIVATE; | |
171 | }; | |
172 | ||
173 | ||
174 | IMPLEMENT_ABSTRACT_CLASS(wxPyWizardPage, wxWizardPage); | |
175 | ||
176 | IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetPrev); | |
177 | IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetNext); | |
178 | IMP_PYCALLBACK_BITMAP__pure(wxPyWizardPage, wxWizardPage, GetBitmap); | |
179 | ||
180 | IMP_PYCALLBACK_VOID_INT4(wxPyWizardPage, wxWizardPage, DoMoveWindow); | |
181 | IMP_PYCALLBACK_VOID_INT5(wxPyWizardPage, wxWizardPage, DoSetSize); | |
182 | IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetClientSize); | |
183 | IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetVirtualSize); | |
184 | ||
185 | IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetSize); | |
186 | IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetClientSize); | |
187 | IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetPosition); | |
188 | ||
189 | IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetVirtualSize); | |
190 | IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetBestSize); | |
191 | ||
192 | IMP_PYCALLBACK__(wxPyWizardPage, wxWizardPage, InitDialog); | |
193 | IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataFromWindow); | |
194 | IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataToWindow); | |
195 | IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, Validate); | |
196 | ||
197 | IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocus); | |
198 | IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocusFromKeyboard); | |
199 | IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, GetMaxSize); | |
200 | ||
201 | IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, AddChild); | |
202 | IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, RemoveChild); | |
203 | ||
204 | %} | |
205 | ||
206 | ||
207 | ||
208 | MustHaveApp(wxPyWizardPage); | |
209 | ||
210 | class wxPyWizardPage : public wxWizardPage { | |
211 | public: | |
212 | ||
213 | %pythonAppend wxPyWizardPage "self._setCallbackInfo(self, PyWizardPage);self._setOORInfo(self)" | |
214 | %pythonAppend wxPyWizardPage() "" | |
215 | %typemap(out) wxPyWizardPage*; // turn off this typemap | |
216 | ||
217 | // ctor accepts an optional bitmap which will be used for this page instead | |
218 | // of the default one for this wizard (should be of the same size). Notice | |
219 | // that no other parameters are needed because the wizard will resize and | |
220 | // reposition the page anyhow | |
221 | %extend { | |
222 | wxPyWizardPage(wxWizard *parent, | |
223 | const wxBitmap* bitmap = &wxNullBitmap, | |
224 | const wxString* resource = &wxPyEmptyString) { | |
225 | wxChar* res = NULL; | |
226 | if (resource->length()) | |
227 | res = (wxChar*)resource->c_str(); | |
228 | return new wxPyWizardPage(parent, *bitmap, res); | |
229 | } | |
230 | } | |
231 | ||
232 | %RenameCtor(PrePyWizardPage, wxPyWizardPage()); | |
233 | ||
234 | // Turn it back on again | |
235 | %typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, $owner); } | |
236 | ||
237 | %extend { | |
238 | bool Create(wxWizard *parent, | |
239 | const wxBitmap& bitmap = wxNullBitmap, | |
240 | const wxString& resource = wxPyEmptyString) { | |
241 | wxChar* res = NULL; | |
242 | if (resource.length()) | |
243 | res = (wxChar*)resource.c_str(); | |
244 | return self->Create(parent, bitmap, res); | |
245 | } | |
246 | } | |
247 | ||
248 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
249 | ||
250 | void DoMoveWindow(int x, int y, int width, int height); | |
251 | void DoSetSize(int x, int y, int width, int height, | |
252 | int sizeFlags = wxSIZE_AUTO); | |
253 | void DoSetClientSize(int width, int height); | |
254 | void DoSetVirtualSize( int x, int y ); | |
255 | ||
256 | DocDeclA( | |
257 | void, DoGetSize( int *OUTPUT, int *OUTPUT ) const, | |
258 | "DoGetSize() -> (width, height)"); | |
259 | DocDeclA( | |
260 | void, DoGetClientSize( int *OUTPUT, int *OUTPUT ) const, | |
261 | "DoGetClientSize() -> (width, height)"); | |
262 | DocDeclA( | |
263 | void, DoGetPosition( int *OUTPUT, int *OUTPUT ) const, | |
264 | "DoGetPosition() -> (x,y)"); | |
265 | ||
266 | wxSize DoGetVirtualSize() const; | |
267 | wxSize DoGetBestSize() const; | |
268 | ||
269 | void InitDialog(); | |
270 | bool TransferDataToWindow(); | |
271 | bool TransferDataFromWindow(); | |
272 | bool Validate(); | |
273 | ||
274 | bool AcceptsFocus() const; | |
275 | bool AcceptsFocusFromKeyboard() const; | |
276 | wxSize GetMaxSize() const; | |
277 | ||
278 | void AddChild(wxWindow* child); | |
279 | void RemoveChild(wxWindow* child); | |
280 | ||
281 | bool ShouldInheritColours() const; | |
282 | wxVisualAttributes GetDefaultAttributes(); | |
283 | ||
284 | void OnInternalIdle(); | |
285 | ||
286 | %MAKE_BASE_FUNC(PyWizardPage, DoMoveWindow); | |
287 | %MAKE_BASE_FUNC(PyWizardPage, DoSetSize); | |
288 | %MAKE_BASE_FUNC(PyWizardPage, DoSetClientSize); | |
289 | %MAKE_BASE_FUNC(PyWizardPage, DoSetVirtualSize); | |
290 | %MAKE_BASE_FUNC(PyWizardPage, DoGetSize); | |
291 | %MAKE_BASE_FUNC(PyWizardPage, DoGetClientSize); | |
292 | %MAKE_BASE_FUNC(PyWizardPage, DoGetPosition); | |
293 | %MAKE_BASE_FUNC(PyWizardPage, DoGetVirtualSize); | |
294 | %MAKE_BASE_FUNC(PyWizardPage, DoGetBestSize); | |
295 | %MAKE_BASE_FUNC(PyWizardPage, InitDialog); | |
296 | %MAKE_BASE_FUNC(PyWizardPage, TransferDataToWindow); | |
297 | %MAKE_BASE_FUNC(PyWizardPage, TransferDataFromWindow); | |
298 | %MAKE_BASE_FUNC(PyWizardPage, Validate); | |
299 | %MAKE_BASE_FUNC(PyWizardPage, AcceptsFocus); | |
300 | %MAKE_BASE_FUNC(PyWizardPage, AcceptsFocusFromKeyboard); | |
301 | %MAKE_BASE_FUNC(PyWizardPage, GetMaxSize); | |
302 | %MAKE_BASE_FUNC(PyWizardPage, AddChild); | |
303 | %MAKE_BASE_FUNC(PyWizardPage, RemoveChild); | |
304 | %MAKE_BASE_FUNC(PyWizardPage, ShouldInheritColours); | |
305 | %MAKE_BASE_FUNC(PyWizardPage, GetDefaultAttributes); | |
306 | %MAKE_BASE_FUNC(PyWizardPage, OnInternalIdle); | |
307 | ||
308 | }; | |
309 | ||
310 | //---------------------------------------------------------------------- | |
311 | ||
312 | ||
313 | // wxWizardPageSimple just returns the pointers given to the ctor and is useful | |
314 | // to create a simple wizard where the order of pages never changes. | |
315 | // | |
316 | // OTOH, it is also possible to dynamicly decide which page to return (i.e. | |
317 | // depending on the user's choices) as the wizard sample shows - in order to do | |
318 | // this, you must derive from wxWizardPage directly. | |
319 | MustHaveApp(wxWizardPageSimple); | |
320 | class wxWizardPageSimple : public wxWizardPage | |
321 | { | |
322 | public: | |
323 | ||
324 | %pythonAppend wxWizardPageSimple "self._setOORInfo(self)" | |
325 | %pythonAppend wxWizardPageSimple() "" | |
326 | ||
327 | // ctor takes the previous and next pages | |
328 | wxWizardPageSimple(wxWizard *parent, | |
329 | wxWizardPage *prev = NULL, | |
330 | wxWizardPage *next = NULL, | |
331 | const wxBitmap& bitmap = wxNullBitmap, | |
332 | const wxChar* resource = NULL); | |
333 | %RenameCtor(PreWizardPageSimple, wxWizardPageSimple()); | |
334 | ||
335 | bool Create(wxWizard *parent = NULL, | |
336 | wxWizardPage *prev = NULL, | |
337 | wxWizardPage *next = NULL, | |
338 | const wxBitmap& bitmap = wxNullBitmap, | |
339 | const wxChar* resource = NULL); | |
340 | ||
341 | // the pointers may be also set later - but before starting the wizard | |
342 | void SetPrev(wxWizardPage *prev); | |
343 | void SetNext(wxWizardPage *next); | |
344 | ||
345 | // a convenience function to make the pages follow each other | |
346 | static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second); | |
347 | }; | |
348 | ||
349 | ||
350 | //---------------------------------------------------------------------- | |
351 | ||
352 | MustHaveApp(wxWizard); | |
353 | ||
354 | class wxWizard : public wxDialog | |
355 | { | |
356 | public: | |
357 | %pythonAppend wxWizard "self._setOORInfo(self)" | |
358 | %pythonAppend wxWizard() "" | |
359 | ||
360 | // ctor | |
361 | wxWizard(wxWindow *parent, | |
362 | int id = -1, | |
363 | const wxString& title = wxPyEmptyString, | |
364 | const wxBitmap& bitmap = wxNullBitmap, | |
365 | const wxPoint& pos = wxDefaultPosition, | |
366 | long style = wxDEFAULT_DIALOG_STYLE); | |
367 | %RenameCtor(PreWizard, wxWizard()); | |
368 | ||
369 | bool Create(wxWindow *parent, | |
370 | int id = -1, | |
371 | const wxString& title = wxPyEmptyString, | |
372 | const wxBitmap& bitmap = wxNullBitmap, | |
373 | const wxPoint& pos = wxDefaultPosition); | |
374 | ||
375 | void Init(); | |
376 | ||
377 | ||
378 | // executes the wizard starting from the given page, returns True if it was | |
379 | // successfully finished, False if user cancelled it | |
380 | virtual bool RunWizard(wxWizardPage *firstPage); | |
381 | ||
382 | // get the current page (NULL if RunWizard() isn't running) | |
383 | virtual wxWizardPage *GetCurrentPage() const; | |
384 | ||
385 | // set the min size which should be available for the pages: a | |
386 | // wizard will take into account the size of the bitmap (if any) | |
387 | // itself and will never be less than some predefined fixed size | |
388 | virtual void SetPageSize(const wxSize& size); | |
389 | ||
390 | // get the size available for the page: the wizards are not resizeable, so | |
391 | // this size doesn't change | |
392 | virtual wxSize GetPageSize() const; | |
393 | ||
394 | // set the best size for the wizard, i.e. make it big enough to contain all | |
395 | // of the pages starting from the given one | |
396 | // | |
397 | // this function may be called several times and possible with different | |
398 | // pages in which case it will only increase the page size if needed (this | |
399 | // may be useful if not all pages are accessible from the first one by | |
400 | // default) | |
401 | virtual void FitToPage(const wxWizardPage *firstPage); | |
402 | ||
403 | // Adding pages to page area sizer enlarges wizard | |
404 | virtual wxSizer *GetPageAreaSizer() const; | |
405 | ||
406 | // Set border around page area. Default is 0 if you add at least one | |
407 | // page to GetPageAreaSizer and 5 if you don't. | |
408 | virtual void SetBorder(int border); | |
409 | ||
410 | // is the wizard running? | |
411 | bool IsRunning() const; | |
412 | ||
413 | // show the prev/next page, but call TransferDataFromWindow on the current | |
414 | // page first and return False without changing the page if | |
415 | // TransferDataFromWindow() returns False - otherwise, returns True | |
416 | bool ShowPage(wxWizardPage *page, bool goingForward = true); | |
417 | ||
418 | bool HasNextPage(wxWizardPage* page); | |
419 | bool HasPrevPage(wxWizardPage* page); | |
420 | ||
421 | %property(CurrentPage, GetCurrentPage, doc="See `GetCurrentPage`"); | |
422 | %property(PageAreaSizer, GetPageAreaSizer, doc="See `GetPageAreaSizer`"); | |
423 | %property(PageSize, GetPageSize, SetPageSize, doc="See `GetPageSize` and `SetPageSize`"); | |
424 | }; | |
425 | ||
426 | ||
427 | //---------------------------------------------------------------------- | |
428 | ||
429 | %init %{ | |
430 | %} | |
431 | ||
432 | //--------------------------------------------------------------------------- |