1 ///////////////////////////////////////////////////////////////////////////////
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.
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)
13 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
14 // Licence: wxWindows licence
15 ///////////////////////////////////////////////////////////////////////////////
22 // ----------------------------------------------------------------------------
23 // headers and other simple declarations
24 // ----------------------------------------------------------------------------
27 #include "wx/dialog.h" // the base class
28 #include "wx/panel.h" // ditto
30 #include "wx/event.h" // wxEVT_XXX constants
33 #include "wx/bitmap.h"
35 // Extended style to specify a help button
36 #define wxWIZARD_EX_HELPBUTTON 0x00000010
38 // forward declarations
39 class WXDLLIMPEXP_ADV wxWizard
;
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).
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 // ----------------------------------------------------------------------------
49 class WXDLLIMPEXP_ADV wxWizardPage
: public wxPanel
52 wxWizardPage() { Init(); }
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
57 // reposition the page anyhow
58 wxWizardPage(wxWizard
*parent
,
59 const wxBitmap
& bitmap
= wxNullBitmap
,
60 const wxChar
* resource
= NULL
);
62 bool Create(wxWizard
*parent
,
63 const wxBitmap
& bitmap
= wxNullBitmap
,
64 const wxChar
* resource
= NULL
);
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;
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.
75 virtual wxBitmap
GetBitmap() const { return m_bitmap
; }
78 /// Override the base functions to allow a validator to be assigned to this page.
79 bool TransferDataToWindow()
81 return GetValidator() ? GetValidator()->TransferToWindow() : wxPanel::TransferDataToWindow();
83 bool TransferDataFromWindow()
85 return GetValidator() ? GetValidator()->TransferFromWindow() : wxPanel::TransferDataFromWindow();
89 return GetValidator() ? GetValidator()->Validate(this) : wxPanel::Validate();
91 #endif // wxUSE_VALIDATOR
94 // common part of ctors:
100 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWizardPage
)
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.
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 // ----------------------------------------------------------------------------
112 class WXDLLIMPEXP_ADV wxWizardPageSimple
: public wxWizardPage
115 wxWizardPageSimple() { Init(); }
117 // ctor takes the previous and next pages
118 wxWizardPageSimple(wxWizard
*parent
,
119 wxWizardPage
*prev
= (wxWizardPage
*)NULL
,
120 wxWizardPage
*next
= (wxWizardPage
*)NULL
,
121 const wxBitmap
& bitmap
= wxNullBitmap
,
122 const wxChar
* resource
= NULL
)
124 Create(parent
, prev
, next
, bitmap
, resource
);
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
)
135 return wxWizardPage::Create(parent
, bitmap
, resource
);
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
; }
142 // a convenience function to make the pages follow each other
143 static void Chain(wxWizardPageSimple
*first
, wxWizardPageSimple
*second
)
145 wxCHECK_RET( first
&& second
,
146 wxT("NULL passed to wxWizardPageSimple::Chain") );
148 first
->SetNext(second
);
149 second
->SetPrev(first
);
152 // base class pure virtuals
153 virtual wxWizardPage
*GetPrev() const;
154 virtual wxWizardPage
*GetNext() const;
157 // common part of ctors:
160 m_prev
= m_next
= NULL
;
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
,
168 DECLARE_DYNAMIC_CLASS_NO_COPY(wxWizardPageSimple
)
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 class WXDLLIMPEXP_ADV wxWizardBase
: public wxDialog
179 The derived class (i.e. the real wxWizard) has a ctor and Create()
180 function taking the following arguments:
182 wxWizard(wxWindow *parent,
184 const wxString& title = wxEmptyString,
185 const wxBitmap& bitmap = wxNullBitmap,
186 const wxPoint& pos = wxDefaultPosition,
187 long style = wxDEFAULT_DIALOG_STYLE);
191 // executes the wizard starting from the given page, returns TRUE if it was
192 // successfully finished, FALSE if user cancelled it
193 virtual bool RunWizard(wxWizardPage
*firstPage
) = 0;
195 // get the current page (NULL if RunWizard() isn't running)
196 virtual wxWizardPage
*GetCurrentPage() const = 0;
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;
203 // get the size available for the page
204 virtual wxSize
GetPageSize() const = 0;
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
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
213 virtual void FitToPage(const wxWizardPage
*firstPage
) = 0;
215 // Adding pages to page area sizer enlarges wizard
216 virtual wxSizer
*GetPageAreaSizer() const = 0;
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;
222 // wxWizard should be created using "new wxWizard" now, not with Create()
223 #if WXWIN_COMPATIBILITY_2_2
224 static wxWizard
*Create(wxWindow
*parent
,
226 const wxString
& title
= wxEmptyString
,
227 const wxBitmap
& bitmap
= wxNullBitmap
,
228 const wxPoint
& pos
= wxDefaultPosition
,
229 const wxSize
& size
= wxDefaultSize
);
230 #endif // WXWIN_COMPATIBILITY_2_2
232 // the methods below may be overridden by the derived classes to provide
233 // custom logic for determining the pages order
235 virtual bool HasNextPage(wxWizardPage
*page
)
236 { return page
->GetNext() != NULL
; }
238 virtual bool HasPrevPage(wxWizardPage
*page
)
239 { return page
->GetPrev() != NULL
; }
241 /// Override these functions to stop InitDialog from calling TransferDataToWindow
242 /// for _all_ pages when the wizard starts. Instead 'ShowPage' will call
243 /// TransferDataToWindow for the first page only.
244 bool TransferDataToWindow() { return true; }
245 bool TransferDataFromWindow() { return true; }
246 bool Validate() { return true; }
249 DECLARE_NO_COPY_CLASS(wxWizardBase
)
252 // include the real class declaration
253 #include "wx/generic/wizard.h"
255 // ----------------------------------------------------------------------------
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
259 // ----------------------------------------------------------------------------
261 class WXDLLIMPEXP_ADV wxWizardEvent
: public wxNotifyEvent
264 wxWizardEvent(wxEventType type
= wxEVT_NULL
,
266 bool direction
= TRUE
,
267 wxWizardPage
* page
= NULL
);
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
272 // (this function doesn't make sense for CANCEL events)
273 bool GetDirection() const { return m_direction
; }
275 wxWizardPage
* GetPage() const { return m_page
; }
279 wxWizardPage
* m_page
;
281 DECLARE_DYNAMIC_CLASS(wxWizardEvent
)
282 DECLARE_NO_COPY_CLASS(wxWizardEvent
)
285 // ----------------------------------------------------------------------------
286 // macros for handling wxWizardEvents
287 // ----------------------------------------------------------------------------
289 BEGIN_DECLARE_EVENT_TYPES()
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)
295 END_DECLARE_EVENT_TYPES()
297 typedef void (wxEvtHandler::*wxWizardEventFunction
)(wxWizardEvent
&);
299 // notifies that the page has just been changed (can't be vetoed)
300 #define EVT_WIZARD_PAGE_CHANGED(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WIZARD_PAGE_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxWizardEventFunction, & fn ), (wxObject *)NULL),
302 // the user pressed "<Back" or "Next>" button and the page is going to be
303 // changed - unless the event handler vetoes the event
304 #define EVT_WIZARD_PAGE_CHANGING(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WIZARD_PAGE_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxWizardEventFunction, & fn ), (wxObject *)NULL),
306 // the user pressed "Cancel" button and the wizard is going to be dismissed -
307 // unless the event handler vetoes the event
308 #define EVT_WIZARD_CANCEL(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WIZARD_CANCEL, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxWizardEventFunction, & fn ), (wxObject *)NULL),
310 // the user pressed "Finish" button and the wizard is going to be dismissed -
311 #define EVT_WIZARD_FINISHED(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WIZARD_FINISHED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxWizardEventFunction, & fn ), (wxObject *)NULL),
313 // the user pressed "Help" button
314 #define EVT_WIZARD_HELP(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WIZARD_HELP, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxWizardEventFunction, & fn ), (wxObject *)NULL),
316 #endif // wxUSE_WIZARDDLG
318 #endif // _WX_WIZARD_H_