]>
Commit | Line | Data |
---|---|---|
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) | |
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 | // RCS-ID: $Id$ | |
13 | // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
14 | // Licence: wxWindows licence | |
15 | /////////////////////////////////////////////////////////////////////////////// | |
16 | ||
17 | #ifndef _WX_WIZARD_H_ | |
18 | #define _WX_WIZARD_H_ | |
19 | ||
20 | #include "wx/defs.h" | |
21 | ||
22 | #if wxUSE_WIZARDDLG | |
23 | ||
24 | // ---------------------------------------------------------------------------- | |
25 | // headers and other simple declarations | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
28 | #include "wx/dialog.h" // the base class | |
29 | #include "wx/panel.h" // ditto | |
30 | #include "wx/event.h" // wxEVT_XXX constants | |
31 | #include "wx/bitmap.h" | |
32 | ||
33 | // Extended style to specify a help button | |
34 | #define wxWIZARD_EX_HELPBUTTON 0x00000010 | |
35 | ||
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 | ||
45 | // forward declarations | |
46 | class WXDLLIMPEXP_FWD_ADV wxWizard; | |
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 | ||
56 | class WXDLLIMPEXP_ADV wxWizardPage : public wxPanel | |
57 | { | |
58 | public: | |
59 | wxWizardPage() { Init(); } | |
60 | ||
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 | |
64 | // reposition the page anyhow | |
65 | wxWizardPage(wxWizard *parent, | |
66 | const wxBitmap& bitmap = wxNullBitmap); | |
67 | ||
68 | bool Create(wxWizard *parent, | |
69 | const wxBitmap& bitmap = wxNullBitmap); | |
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 | ||
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. | |
80 | virtual wxBitmap GetBitmap() const { return m_bitmap; } | |
81 | ||
82 | #if wxUSE_VALIDATORS | |
83 | // Override the base functions to allow a validator to be assigned to this page. | |
84 | virtual bool TransferDataToWindow() | |
85 | { | |
86 | return GetValidator() ? GetValidator()->TransferToWindow() | |
87 | : wxPanel::TransferDataToWindow(); | |
88 | } | |
89 | ||
90 | virtual bool TransferDataFromWindow() | |
91 | { | |
92 | return GetValidator() ? GetValidator()->TransferFromWindow() | |
93 | : wxPanel::TransferDataFromWindow(); | |
94 | } | |
95 | ||
96 | virtual bool Validate() | |
97 | { | |
98 | return GetValidator() ? GetValidator()->Validate(this) | |
99 | : wxPanel::Validate(); | |
100 | } | |
101 | #endif // wxUSE_VALIDATORS | |
102 | ||
103 | protected: | |
104 | // common part of ctors: | |
105 | void Init(); | |
106 | ||
107 | wxBitmap m_bitmap; | |
108 | ||
109 | private: | |
110 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxWizardPage) | |
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 | ||
122 | class WXDLLIMPEXP_ADV wxWizardPageSimple : public wxWizardPage | |
123 | { | |
124 | public: | |
125 | wxWizardPageSimple() { Init(); } | |
126 | ||
127 | // ctor takes the previous and next pages | |
128 | wxWizardPageSimple(wxWizard *parent, | |
129 | wxWizardPage *prev = (wxWizardPage *)NULL, | |
130 | wxWizardPage *next = (wxWizardPage *)NULL, | |
131 | const wxBitmap& bitmap = wxNullBitmap) | |
132 | { | |
133 | Create(parent, prev, next, bitmap); | |
134 | } | |
135 | ||
136 | bool Create(wxWizard *parent = NULL, // let it be default ctor too | |
137 | wxWizardPage *prev = (wxWizardPage *)NULL, | |
138 | wxWizardPage *next = (wxWizardPage *)NULL, | |
139 | const wxBitmap& bitmap = wxNullBitmap) | |
140 | { | |
141 | m_prev = prev; | |
142 | m_next = next; | |
143 | return wxWizardPage::Create(parent, bitmap); | |
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 | ||
150 | // a convenience function to make the pages follow each other | |
151 | static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second) | |
152 | { | |
153 | wxCHECK_RET( first && second, | |
154 | wxT("NULL passed to wxWizardPageSimple::Chain") ); | |
155 | ||
156 | first->SetNext(second); | |
157 | second->SetPrev(first); | |
158 | } | |
159 | ||
160 | // base class pure virtuals | |
161 | virtual wxWizardPage *GetPrev() const; | |
162 | virtual wxWizardPage *GetNext() const; | |
163 | ||
164 | private: | |
165 | // common part of ctors: | |
166 | void Init() | |
167 | { | |
168 | m_prev = m_next = NULL; | |
169 | } | |
170 | ||
171 | // pointers are private, the derived classes shouldn't mess with them - | |
172 | // just derive from wxWizardPage directly to implement different behaviour | |
173 | wxWizardPage *m_prev, | |
174 | *m_next; | |
175 | ||
176 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxWizardPageSimple) | |
177 | }; | |
178 | ||
179 | // ---------------------------------------------------------------------------- | |
180 | // wxWizard | |
181 | // ---------------------------------------------------------------------------- | |
182 | ||
183 | class WXDLLIMPEXP_ADV wxWizardBase : public wxDialog | |
184 | { | |
185 | public: | |
186 | /* | |
187 | The derived class (i.e. the real wxWizard) has a ctor and Create() | |
188 | function taking the following arguments: | |
189 | ||
190 | wxWizard(wxWindow *parent, | |
191 | int id = wxID_ANY, | |
192 | const wxString& title = wxEmptyString, | |
193 | const wxBitmap& bitmap = wxNullBitmap, | |
194 | const wxPoint& pos = wxDefaultPosition, | |
195 | long style = wxDEFAULT_DIALOG_STYLE); | |
196 | */ | |
197 | wxWizardBase() { } | |
198 | ||
199 | // executes the wizard starting from the given page, returns true if it was | |
200 | // successfully finished, false if user cancelled it | |
201 | virtual bool RunWizard(wxWizardPage *firstPage) = 0; | |
202 | ||
203 | // get the current page (NULL if RunWizard() isn't running) | |
204 | virtual wxWizardPage *GetCurrentPage() const = 0; | |
205 | ||
206 | // set the min size which should be available for the pages: a | |
207 | // wizard will take into account the size of the bitmap (if any) | |
208 | // itself and will never be less than some predefined fixed size | |
209 | virtual void SetPageSize(const wxSize& size) = 0; | |
210 | ||
211 | // get the size available for the page | |
212 | virtual wxSize GetPageSize() const = 0; | |
213 | ||
214 | // set the best size for the wizard, i.e. make it big enough to contain all | |
215 | // of the pages starting from the given one | |
216 | // | |
217 | // this function may be called several times and possible with different | |
218 | // pages in which case it will only increase the page size if needed (this | |
219 | // may be useful if not all pages are accessible from the first one by | |
220 | // default) | |
221 | virtual void FitToPage(const wxWizardPage *firstPage) = 0; | |
222 | ||
223 | // Adding pages to page area sizer enlarges wizard | |
224 | virtual wxSizer *GetPageAreaSizer() const = 0; | |
225 | ||
226 | // Set border around page area. Default is 0 if you add at least one | |
227 | // page to GetPageAreaSizer and 5 if you don't. | |
228 | virtual void SetBorder(int border) = 0; | |
229 | ||
230 | // the methods below may be overridden by the derived classes to provide | |
231 | // custom logic for determining the pages order | |
232 | ||
233 | virtual bool HasNextPage(wxWizardPage *page) | |
234 | { return page->GetNext() != NULL; } | |
235 | ||
236 | virtual bool HasPrevPage(wxWizardPage *page) | |
237 | { return page->GetPrev() != NULL; } | |
238 | ||
239 | /// Override these functions to stop InitDialog from calling TransferDataToWindow | |
240 | /// for _all_ pages when the wizard starts. Instead 'ShowPage' will call | |
241 | /// TransferDataToWindow for the first page only. | |
242 | bool TransferDataToWindow() { return true; } | |
243 | bool TransferDataFromWindow() { return true; } | |
244 | bool Validate() { return true; } | |
245 | ||
246 | private: | |
247 | DECLARE_NO_COPY_CLASS(wxWizardBase) | |
248 | }; | |
249 | ||
250 | // include the real class declaration | |
251 | #include "wx/generic/wizard.h" | |
252 | ||
253 | // ---------------------------------------------------------------------------- | |
254 | // wxWizardEvent class represents an event generated by the wizard: this event | |
255 | // is first sent to the page itself and, if not processed there, goes up the | |
256 | // window hierarchy as usual | |
257 | // ---------------------------------------------------------------------------- | |
258 | ||
259 | class WXDLLIMPEXP_ADV wxWizardEvent : public wxNotifyEvent | |
260 | { | |
261 | public: | |
262 | wxWizardEvent(wxEventType type = wxEVT_NULL, | |
263 | int id = wxID_ANY, | |
264 | bool direction = true, | |
265 | wxWizardPage* page = NULL); | |
266 | ||
267 | // for EVT_WIZARD_PAGE_CHANGING, return true if we're going forward or | |
268 | // false otherwise and for EVT_WIZARD_PAGE_CHANGED return true if we came | |
269 | // from the previous page and false if we returned from the next one | |
270 | // (this function doesn't make sense for CANCEL events) | |
271 | bool GetDirection() const { return m_direction; } | |
272 | ||
273 | wxWizardPage* GetPage() const { return m_page; } | |
274 | ||
275 | virtual wxEvent *Clone() const { return new wxWizardEvent(*this); } | |
276 | ||
277 | private: | |
278 | bool m_direction; | |
279 | wxWizardPage* m_page; | |
280 | ||
281 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWizardEvent) | |
282 | }; | |
283 | ||
284 | // ---------------------------------------------------------------------------- | |
285 | // macros for handling wxWizardEvents | |
286 | // ---------------------------------------------------------------------------- | |
287 | ||
288 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_WIZARD_PAGE_CHANGED; | |
289 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_WIZARD_PAGE_CHANGING; | |
290 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_WIZARD_CANCEL; | |
291 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_WIZARD_HELP; | |
292 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_WIZARD_FINISHED; | |
293 | ||
294 | typedef void (wxEvtHandler::*wxWizardEventFunction)(wxWizardEvent&); | |
295 | ||
296 | #define wxWizardEventHandler(func) \ | |
297 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWizardEventFunction, &func) | |
298 | ||
299 | #define wx__DECLARE_WIZARDEVT(evt, id, fn) \ | |
300 | wx__DECLARE_EVT1(wxEVT_WIZARD_ ## evt, id, wxWizardEventHandler(fn)) | |
301 | ||
302 | // notifies that the page has just been changed (can't be vetoed) | |
303 | #define EVT_WIZARD_PAGE_CHANGED(id, fn) wx__DECLARE_WIZARDEVT(PAGE_CHANGED, id, fn) | |
304 | ||
305 | // the user pressed "<Back" or "Next>" button and the page is going to be | |
306 | // changed - unless the event handler vetoes the event | |
307 | #define EVT_WIZARD_PAGE_CHANGING(id, fn) wx__DECLARE_WIZARDEVT(PAGE_CHANGING, id, fn) | |
308 | ||
309 | // the user pressed "Cancel" button and the wizard is going to be dismissed - | |
310 | // unless the event handler vetoes the event | |
311 | #define EVT_WIZARD_CANCEL(id, fn) wx__DECLARE_WIZARDEVT(CANCEL, id, fn) | |
312 | ||
313 | // the user pressed "Finish" button and the wizard is going to be dismissed - | |
314 | #define EVT_WIZARD_FINISHED(id, fn) wx__DECLARE_WIZARDEVT(FINISHED, id, fn) | |
315 | ||
316 | // the user pressed "Help" button | |
317 | #define EVT_WIZARD_HELP(id, fn) wx__DECLARE_WIZARDEVT(HELP, id, fn) | |
318 | ||
319 | #endif // wxUSE_WIZARDDLG | |
320 | ||
321 | #endif // _WX_WIZARD_H_ |