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