removed wxABI_VERSION checks
[wxWidgets.git] / include / wx / wizard.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wizard.h
3 // Purpose: wxWizard class: a GUI control presenting the user with a
4 // sequence of dialogs which allows to simply perform some task
5 // Author: Vadim Zeitlin (partly based on work by Ron Kuris and Kevin B.
6 // Smith)
7 // Modified by: Robert Cavanaugh
8 // Added capability to use .WXR resource files in Wizard pages
9 // Added wxWIZARD_HELP event
10 // Robert Vazan (sizers)
11 // Created: 15.08.99
12 // RCS-ID: $Id$
13 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
14 // Licence: wxWindows licence
15 ///////////////////////////////////////////////////////////////////////////////
16
17 #ifndef _WX_WIZARD_H_
18 #define _WX_WIZARD_H_
19
20 #include "wx/defs.h"
21
22 #if wxUSE_WIZARDDLG
23
24 // ----------------------------------------------------------------------------
25 // headers and other simple declarations
26 // ----------------------------------------------------------------------------
27
28 #ifndef WX_PRECOMP
29 #include "wx/dialog.h" // the base class
30 #include "wx/panel.h" // ditto
31
32 #include "wx/event.h" // wxEVT_XXX constants
33 #endif // WX_PRECOMP
34
35 #include "wx/bitmap.h"
36
37 // Extended style to specify a help button
38 #define wxWIZARD_EX_HELPBUTTON 0x00000010
39
40 // forward declarations
41 class WXDLLIMPEXP_ADV wxWizard;
42
43 // ----------------------------------------------------------------------------
44 // wxWizardPage is one of the wizards screen: it must know what are the
45 // following and preceding pages (which may be NULL for the first/last page).
46 //
47 // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be
48 // used as such (i.e. controls may be placed directly on it &c).
49 // ----------------------------------------------------------------------------
50
51 class WXDLLIMPEXP_ADV wxWizardPage : public wxPanel
52 {
53 public:
54 wxWizardPage() { Init(); }
55
56 // ctor accepts an optional bitmap which will be used for this page instead
57 // of the default one for this wizard (should be of the same size). Notice
58 // that no other parameters are needed because the wizard will resize and
59 // reposition the page anyhow
60 wxWizardPage(wxWizard *parent,
61 const wxBitmap& bitmap = wxNullBitmap,
62 const wxChar* resource = NULL);
63
64 bool Create(wxWizard *parent,
65 const wxBitmap& bitmap = wxNullBitmap,
66 const wxChar* resource = NULL);
67
68 // these functions are used by the wizard to show another page when the
69 // user chooses "Back" or "Next" button
70 virtual wxWizardPage *GetPrev() const = 0;
71 virtual wxWizardPage *GetNext() const = 0;
72
73 // default GetBitmap() will just return m_bitmap which is ok in 99% of
74 // cases - override this method if you want to create the bitmap to be used
75 // dynamically or to do something even more fancy. It's ok to return
76 // wxNullBitmap from here - the default one will be used then.
77 virtual wxBitmap GetBitmap() const { return m_bitmap; }
78
79 #if wxUSE_VALIDATORS
80 // Override the base functions to allow a validator to be assigned to this page.
81 virtual bool TransferDataToWindow()
82 {
83 return GetValidator() ? GetValidator()->TransferToWindow()
84 : wxPanel::TransferDataToWindow();
85 }
86
87 virtual bool TransferDataFromWindow()
88 {
89 return GetValidator() ? GetValidator()->TransferFromWindow()
90 : wxPanel::TransferDataFromWindow();
91 }
92
93 virtual bool Validate()
94 {
95 return GetValidator() ? GetValidator()->Validate(this)
96 : wxPanel::Validate();
97 }
98 #endif // wxUSE_VALIDATORS
99
100 protected:
101 // common part of ctors:
102 void Init();
103
104 wxBitmap m_bitmap;
105
106 private:
107 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWizardPage)
108 };
109
110 // ----------------------------------------------------------------------------
111 // wxWizardPageSimple just returns the pointers given to the ctor and is useful
112 // to create a simple wizard where the order of pages never changes.
113 //
114 // OTOH, it is also possible to dynamicly decide which page to return (i.e.
115 // depending on the user's choices) as the wizard sample shows - in order to do
116 // this, you must derive from wxWizardPage directly.
117 // ----------------------------------------------------------------------------
118
119 class WXDLLIMPEXP_ADV wxWizardPageSimple : public wxWizardPage
120 {
121 public:
122 wxWizardPageSimple() { Init(); }
123
124 // ctor takes the previous and next pages
125 wxWizardPageSimple(wxWizard *parent,
126 wxWizardPage *prev = (wxWizardPage *)NULL,
127 wxWizardPage *next = (wxWizardPage *)NULL,
128 const wxBitmap& bitmap = wxNullBitmap,
129 const wxChar* resource = NULL)
130 {
131 Create(parent, prev, next, bitmap, resource);
132 }
133
134 bool Create(wxWizard *parent = NULL, // let it be default ctor too
135 wxWizardPage *prev = (wxWizardPage *)NULL,
136 wxWizardPage *next = (wxWizardPage *)NULL,
137 const wxBitmap& bitmap = wxNullBitmap,
138 const wxChar* resource = NULL)
139 {
140 m_prev = prev;
141 m_next = next;
142 return wxWizardPage::Create(parent, bitmap, resource);
143 }
144
145 // the pointers may be also set later - but before starting the wizard
146 void SetPrev(wxWizardPage *prev) { m_prev = prev; }
147 void SetNext(wxWizardPage *next) { m_next = next; }
148
149 // a convenience function to make the pages follow each other
150 static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second)
151 {
152 wxCHECK_RET( first && second,
153 wxT("NULL passed to wxWizardPageSimple::Chain") );
154
155 first->SetNext(second);
156 second->SetPrev(first);
157 }
158
159 // base class pure virtuals
160 virtual wxWizardPage *GetPrev() const;
161 virtual wxWizardPage *GetNext() const;
162
163 private:
164 // common part of ctors:
165 void Init()
166 {
167 m_prev = m_next = NULL;
168 }
169
170 // pointers are private, the derived classes shouldn't mess with them -
171 // just derive from wxWizardPage directly to implement different behaviour
172 wxWizardPage *m_prev,
173 *m_next;
174
175 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWizardPageSimple)
176 };
177
178 // ----------------------------------------------------------------------------
179 // wxWizard
180 // ----------------------------------------------------------------------------
181
182 class WXDLLIMPEXP_ADV wxWizardBase : public wxDialog
183 {
184 public:
185 /*
186 The derived class (i.e. the real wxWizard) has a ctor and Create()
187 function taking the following arguments:
188
189 wxWizard(wxWindow *parent,
190 int id = wxID_ANY,
191 const wxString& title = wxEmptyString,
192 const wxBitmap& bitmap = wxNullBitmap,
193 const wxPoint& pos = wxDefaultPosition,
194 long style = wxDEFAULT_DIALOG_STYLE);
195 */
196 wxWizardBase() { }
197
198 // executes the wizard starting from the given page, returns true if it was
199 // successfully finished, false if user cancelled it
200 virtual bool RunWizard(wxWizardPage *firstPage) = 0;
201
202 // get the current page (NULL if RunWizard() isn't running)
203 virtual wxWizardPage *GetCurrentPage() const = 0;
204
205 // set the min size which should be available for the pages: a
206 // wizard will take into account the size of the bitmap (if any)
207 // itself and will never be less than some predefined fixed size
208 virtual void SetPageSize(const wxSize& size) = 0;
209
210 // get the size available for the page
211 virtual wxSize GetPageSize() const = 0;
212
213 // set the best size for the wizard, i.e. make it big enough to contain all
214 // of the pages starting from the given one
215 //
216 // this function may be called several times and possible with different
217 // pages in which case it will only increase the page size if needed (this
218 // may be useful if not all pages are accessible from the first one by
219 // default)
220 virtual void FitToPage(const wxWizardPage *firstPage) = 0;
221
222 // Adding pages to page area sizer enlarges wizard
223 virtual wxSizer *GetPageAreaSizer() const = 0;
224
225 // Set border around page area. Default is 0 if you add at least one
226 // page to GetPageAreaSizer and 5 if you don't.
227 virtual void SetBorder(int border) = 0;
228
229 // wxWizard should be created using "new wxWizard" now, not with Create()
230 #if WXWIN_COMPATIBILITY_2_2
231 wxDEPRECATED( static wxWizard *Create(wxWindow *parent,
232 int id = wxID_ANY,
233 const wxString& title = wxEmptyString,
234 const wxBitmap& bitmap = wxNullBitmap,
235 const wxPoint& pos = wxDefaultPosition,
236 const wxSize& size = wxDefaultSize) );
237 #endif // WXWIN_COMPATIBILITY_2_2
238
239 // the methods below may be overridden by the derived classes to provide
240 // custom logic for determining the pages order
241
242 virtual bool HasNextPage(wxWizardPage *page)
243 { return page->GetNext() != NULL; }
244
245 virtual bool HasPrevPage(wxWizardPage *page)
246 { return page->GetPrev() != NULL; }
247
248 /// Override these functions to stop InitDialog from calling TransferDataToWindow
249 /// for _all_ pages when the wizard starts. Instead 'ShowPage' will call
250 /// TransferDataToWindow for the first page only.
251 bool TransferDataToWindow() { return true; }
252 bool TransferDataFromWindow() { return true; }
253 bool Validate() { return true; }
254
255 private:
256 DECLARE_NO_COPY_CLASS(wxWizardBase)
257 };
258
259 // include the real class declaration
260 #include "wx/generic/wizard.h"
261
262 // ----------------------------------------------------------------------------
263 // wxWizardEvent class represents an event generated by the wizard: this event
264 // is first sent to the page itself and, if not processed there, goes up the
265 // window hierarchy as usual
266 // ----------------------------------------------------------------------------
267
268 class WXDLLIMPEXP_ADV wxWizardEvent : public wxNotifyEvent
269 {
270 public:
271 wxWizardEvent(wxEventType type = wxEVT_NULL,
272 int id = wxID_ANY,
273 bool direction = true,
274 wxWizardPage* page = NULL);
275
276 // for EVT_WIZARD_PAGE_CHANGING, return true if we're going forward or
277 // false otherwise and for EVT_WIZARD_PAGE_CHANGED return true if we came
278 // from the previous page and false if we returned from the next one
279 // (this function doesn't make sense for CANCEL events)
280 bool GetDirection() const { return m_direction; }
281
282 wxWizardPage* GetPage() const { return m_page; }
283
284 private:
285 bool m_direction;
286 wxWizardPage* m_page;
287
288 DECLARE_DYNAMIC_CLASS(wxWizardEvent)
289 DECLARE_NO_COPY_CLASS(wxWizardEvent)
290 };
291
292 // ----------------------------------------------------------------------------
293 // macros for handling wxWizardEvents
294 // ----------------------------------------------------------------------------
295
296 BEGIN_DECLARE_EVENT_TYPES()
297 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_WIZARD_PAGE_CHANGED, 900)
298 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_WIZARD_PAGE_CHANGING, 901)
299 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_WIZARD_CANCEL, 902)
300 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_WIZARD_HELP, 903)
301 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_WIZARD_FINISHED, 903)
302 END_DECLARE_EVENT_TYPES()
303
304 typedef void (wxEvtHandler::*wxWizardEventFunction)(wxWizardEvent&);
305
306 #define wxWizardEventHandler(func) \
307 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWizardEventFunction, &func)
308
309 #define wx__DECLARE_WIZARDEVT(evt, id, fn) \
310 wx__DECLARE_EVT1(wxEVT_WIZARD_ ## evt, id, wxWizardEventHandler(fn))
311
312 // notifies that the page has just been changed (can't be vetoed)
313 #define EVT_WIZARD_PAGE_CHANGED(id, fn) wx__DECLARE_WIZARDEVT(PAGE_CHANGED, id, fn)
314
315 // the user pressed "<Back" or "Next>" button and the page is going to be
316 // changed - unless the event handler vetoes the event
317 #define EVT_WIZARD_PAGE_CHANGING(id, fn) wx__DECLARE_WIZARDEVT(PAGE_CHANGING, id, fn)
318
319 // the user pressed "Cancel" button and the wizard is going to be dismissed -
320 // unless the event handler vetoes the event
321 #define EVT_WIZARD_CANCEL(id, fn) wx__DECLARE_WIZARDEVT(CANCEL, id, fn)
322
323 // the user pressed "Finish" button and the wizard is going to be dismissed -
324 #define EVT_WIZARD_FINISHED(id, fn) wx__DECLARE_WIZARDEVT(FINISHED, id, fn)
325
326 // the user pressed "Help" button
327 #define EVT_WIZARD_HELP(id, fn) wx__DECLARE_WIZARDEVT(HELP, id, fn)
328
329 #endif // wxUSE_WIZARDDLG
330
331 #endif // _WX_WIZARD_H_