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