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