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