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