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