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