]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/wizard.i
Reworked how stock objects are initialized. They now have an
[wxWidgets.git] / wxPython / src / wizard.i
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 %module wizard
14
15 %{
16 #include "wx/wxPython/wxPython.h"
17 #include "wx/wxPython/pyclasses.h"
18 #include "wx/wxPython/printfw.h"
19
20 #include <wx/wizard.h>
21
22 static const wxString wxPyEmptyString(wxT(""));
23 %}
24
25 //----------------------------------------------------------------------
26
27 %import windows.i
28 %pythoncode { wx = core }
29
30 %include _wizard_rename.i
31
32 //----------------------------------------------------------------------
33
34 enum {
35 wxWIZARD_EX_HELPBUTTON,
36 };
37
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;
43
44
45
46 %pythoncode {
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)
52 }
53
54 //----------------------------------------------------------------------
55
56 class wxWizardEvent : public wxNotifyEvent
57 {
58 public:
59 wxWizardEvent(wxEventType type = wxEVT_NULL,
60 int id = -1,
61 bool direction = True,
62 wxWizardPage* page = NULL);
63
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; }
69
70 wxWizardPage* GetPage() const { return m_page; }
71 };
72
73
74 //----------------------------------------------------------------------
75
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).
78 //
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
82 {
83 public:
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();
92
93 %extend {
94 bool Create(wxWizard *parent,
95 const wxBitmap& bitmap = wxNullBitmap,
96 const wxString& resource = wxPyEmptyString) {
97 wxChar* res = NULL;
98 if (resource.Length())
99 res = (wxChar*)resource.c_str();
100 return self->Create(parent, bitmap, res);
101 }
102 }
103
104
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;
109
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;
115 };
116
117
118
119 %{ // C++ Version of a Python aware class
120 class wxPyWizardPage : public wxWizardPage {
121 DECLARE_ABSTRACT_CLASS(wxPyWizardPage);
122 public:
123 wxPyWizardPage() : wxWizardPage() {}
124 wxPyWizardPage(wxWizard *parent,
125 const wxBitmap& bitmap = wxNullBitmap,
126 const wxChar* resource = NULL)
127 : wxWizardPage(parent, bitmap, resource) {}
128
129 DEC_PYCALLBACK_WIZPG__pure(GetPrev);
130 DEC_PYCALLBACK_WIZPG__pure(GetNext);
131 DEC_PYCALLBACK_BITMAP__pure(GetBitmap);
132
133 DEC_PYCALLBACK_VOID_INT4(DoMoveWindow);
134 DEC_PYCALLBACK_VOID_INT5(DoSetSize);
135 DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize);
136 DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize);
137
138 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize);
139 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize);
140 DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition);
141
142 DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize);
143 DEC_PYCALLBACK_SIZE_const(DoGetBestSize);
144
145 DEC_PYCALLBACK__(InitDialog);
146 DEC_PYCALLBACK_BOOL_(TransferDataFromWindow);
147 DEC_PYCALLBACK_BOOL_(TransferDataToWindow);
148 DEC_PYCALLBACK_BOOL_(Validate);
149
150 DEC_PYCALLBACK_BOOL_const(AcceptsFocus);
151 DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard);
152 DEC_PYCALLBACK_SIZE_const(GetMaxSize);
153
154 DEC_PYCALLBACK_VOID_WXWINBASE(AddChild);
155 DEC_PYCALLBACK_VOID_WXWINBASE(RemoveChild);
156
157 PYPRIVATE;
158 };
159
160
161 IMPLEMENT_ABSTRACT_CLASS(wxPyWizardPage, wxWizardPage);
162
163 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetPrev);
164 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetNext);
165 IMP_PYCALLBACK_BITMAP__pure(wxPyWizardPage, wxWizardPage, GetBitmap);
166
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);
171
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);
175
176 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetVirtualSize);
177 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetBestSize);
178
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);
183
184 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocus);
185 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocusFromKeyboard);
186 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, GetMaxSize);
187
188 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, AddChild);
189 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, RemoveChild);
190
191 %}
192
193
194
195 class wxPyWizardPage : public wxWizardPage {
196 public:
197
198 %addtofunc wxPyWizardPage "self._setCallbackInfo(self, PyWizardPage);self._setOORInfo(self)"
199 %addtofunc wxPyWizardPage() ""
200
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
205 %extend {
206 wxPyWizardPage(wxWizard *parent,
207 const wxBitmap* bitmap = &wxNullBitmap,
208 const wxString* resource = &wxPyEmptyString) {
209 wxChar* res = NULL;
210 if (resource->Length())
211 res = (wxChar*)resource->c_str();
212 return new wxPyWizardPage(parent, *bitmap, res);
213 }
214 }
215
216 %name(PrePyWizardPage)wxPyWizardPage();
217
218 %extend {
219 bool Create(wxWizard *parent,
220 const wxBitmap& bitmap = wxNullBitmap,
221 const wxString& resource = wxPyEmptyString) {
222 wxChar* res = NULL;
223 if (resource.Length())
224 res = (wxChar*)resource.c_str();
225 return self->Create(parent, bitmap, res);
226 }
227 }
228
229 void _setCallbackInfo(PyObject* self, PyObject* _class);
230
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 );
236
237 DocDeclA(
238 void, base_DoGetSize( int *OUTPUT, int *OUTPUT ) const,
239 "base_DoGetSize() -> (width, height)");
240 DocDeclA(
241 void, base_DoGetClientSize( int *OUTPUT, int *OUTPUT ) const,
242 "base_DoGetClientSize() -> (width, height)");
243 DocDeclA(
244 void, base_DoGetPosition( int *OUTPUT, int *OUTPUT ) const,
245 "base_DoGetPosition() -> (x,y)");
246
247 wxSize base_DoGetVirtualSize() const;
248 wxSize base_DoGetBestSize() const;
249
250 void base_InitDialog();
251 bool base_TransferDataToWindow();
252 bool base_TransferDataFromWindow();
253 bool base_Validate();
254
255 bool base_AcceptsFocus() const;
256 bool base_AcceptsFocusFromKeyboard() const;
257 wxSize base_GetMaxSize() const;
258
259 void base_AddChild(wxWindow* child);
260 void base_RemoveChild(wxWindow* child);
261 };
262
263 //----------------------------------------------------------------------
264
265
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.
268 //
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
273 {
274 public:
275
276 %addtofunc wxWizardPageSimple "self._setOORInfo(self)"
277 %addtofunc wxWizardPageSimple() ""
278
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();
286
287 bool Create(wxWizard *parent = NULL,
288 wxWizardPage *prev = NULL,
289 wxWizardPage *next = NULL,
290 const wxBitmap& bitmap = wxNullBitmap,
291 const wxChar* resource = NULL);
292
293 // the pointers may be also set later - but before starting the wizard
294 void SetPrev(wxWizardPage *prev);
295 void SetNext(wxWizardPage *next);
296
297 // a convenience function to make the pages follow each other
298 static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second);
299 };
300
301
302 //----------------------------------------------------------------------
303
304 class wxWizard : public wxDialog
305 {
306 public:
307 %addtofunc wxWizard "self._setOORInfo(self)"
308 %addtofunc wxWizard() ""
309
310 // ctor
311 wxWizard(wxWindow *parent,
312 int id = -1,
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();
318
319 bool Create(wxWindow *parent,
320 int id = -1,
321 const wxString& title = wxEmptyString,
322 const wxBitmap& bitmap = wxNullBitmap,
323 const wxPoint& pos = wxDefaultPosition);
324
325 void Init();
326
327
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);
331
332 // get the current page (NULL if RunWizard() isn't running)
333 virtual wxWizardPage *GetCurrentPage() const;
334
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);
339
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;
343
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
346 //
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
350 // default)
351 virtual void FitToPage(const wxWizardPage *firstPage);
352
353 // Adding pages to page area sizer enlarges wizard
354 virtual wxSizer *GetPageAreaSizer() const;
355
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);
359
360 // is the wizard running?
361 bool IsRunning() const { return m_page != NULL; }
362
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);
367
368 bool HasNextPage(wxWizardPage* page);
369 bool HasPrevPage(wxWizardPage* page);
370 };
371
372
373 //----------------------------------------------------------------------
374
375 %init %{
376 %}
377
378 //---------------------------------------------------------------------------