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
12 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
13 // Licence: wxWindows license
14 ///////////////////////////////////////////////////////////////////////////////
21 // ----------------------------------------------------------------------------
22 // headers and other simple declarations
23 // ----------------------------------------------------------------------------
26 #include "wx/dialog.h" // the base class
27 #include "wx/panel.h" // ditto
29 #include "wx/event.h" // wxEVT_XXX constants
32 // Extended style to specify a help button
33 #define wxWIZARD_EX_HELPBUTTON 0x00000010
35 // forward declarations
36 class WXDLLEXPORT wxWizard
;
38 // ----------------------------------------------------------------------------
39 // wxWizardPage is one of the wizards screen: it must know what are the
40 // following and preceding pages (which may be NULL for the first/last page).
42 // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be
43 // used as such (i.e. controls may be placed directly on it &c).
44 // ----------------------------------------------------------------------------
46 class WXDLLEXPORT wxWizardPage
: public wxPanel
49 wxWizardPage() { Init(); }
51 // ctor accepts an optional bitmap which will be used for this page instead
52 // of the default one for this wizard (should be of the same size). Notice
53 // that no other parameters are needed because the wizard will resize and
54 // reposition the page anyhow
55 wxWizardPage(wxWizard
*parent
,
56 const wxBitmap
& bitmap
= wxNullBitmap
,
57 const wxChar
* resource
= NULL
);
59 bool Create(wxWizard
*parent
,
60 const wxBitmap
& bitmap
= wxNullBitmap
,
61 const wxChar
* resource
= NULL
);
63 // these functions are used by the wizard to show another page when the
64 // user chooses "Back" or "Next" button
65 virtual wxWizardPage
*GetPrev() const = 0;
66 virtual wxWizardPage
*GetNext() const = 0;
68 // default GetBitmap() will just return m_bitmap which is ok in 99% of
69 // cases - override this method if you want to create the bitmap to be used
70 // dynamically or to do something even more fancy. It's ok to return
71 // wxNullBitmap from here - the default one will be used then.
72 virtual wxBitmap
GetBitmap() const { return m_bitmap
; }
75 // common part of ctors:
81 DECLARE_ABSTRACT_CLASS(wxWizardPage
)
84 // ----------------------------------------------------------------------------
85 // wxWizardPageSimple just returns the pointers given to the ctor and is useful
86 // to create a simple wizard where the order of pages never changes.
88 // OTOH, it is also possible to dynamicly decide which page to return (i.e.
89 // depending on the user's choices) as the wizard sample shows - in order to do
90 // this, you must derive from wxWizardPage directly.
91 // ----------------------------------------------------------------------------
93 class WXDLLEXPORT wxWizardPageSimple
: public wxWizardPage
96 wxWizardPageSimple() { Init(); }
98 // ctor takes the previous and next pages
99 wxWizardPageSimple(wxWizard
*parent
,
100 wxWizardPage
*prev
= (wxWizardPage
*)NULL
,
101 wxWizardPage
*next
= (wxWizardPage
*)NULL
,
102 const wxBitmap
& bitmap
= wxNullBitmap
,
103 const wxChar
* resource
= NULL
)
105 Create(parent
, prev
, next
, bitmap
, resource
);
108 bool Create(wxWizard
*parent
= NULL
, // let it be default ctor too
109 wxWizardPage
*prev
= (wxWizardPage
*)NULL
,
110 wxWizardPage
*next
= (wxWizardPage
*)NULL
,
111 const wxBitmap
& bitmap
= wxNullBitmap
,
112 const wxChar
* resource
= NULL
)
116 return wxWizardPage::Create(parent
, bitmap
, resource
);
119 // the pointers may be also set later - but before starting the wizard
120 void SetPrev(wxWizardPage
*prev
) { m_prev
= prev
; }
121 void SetNext(wxWizardPage
*next
) { m_next
= next
; }
123 // a convenience function to make the pages follow each other
124 static void Chain(wxWizardPageSimple
*first
, wxWizardPageSimple
*second
)
126 wxCHECK_RET( first
&& second
,
127 wxT("NULL passed to wxWizardPageSimple::Chain") );
129 first
->SetNext(second
);
130 second
->SetPrev(first
);
133 // base class pure virtuals
134 virtual wxWizardPage
*GetPrev() const;
135 virtual wxWizardPage
*GetNext() const;
138 // common part of ctors:
141 m_prev
= m_next
= NULL
;
144 // pointers are private, the derived classes shouldn't mess with them -
145 // just derive from wxWizardPage directly to implement different behaviour
146 wxWizardPage
*m_prev
,
149 DECLARE_DYNAMIC_CLASS(wxWizardPageSimple
)
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 class WXDLLEXPORT wxWizardBase
: public wxDialog
160 The derived class (i.e. the real wxWizard) has a ctor and Create()
161 function taking the following arguments:
163 wxWizard(wxWindow *parent,
165 const wxString& title = wxEmptyString,
166 const wxBitmap& bitmap = wxNullBitmap,
167 const wxPoint& pos = wxDefaultPosition);
170 // executes the wizard starting from the given page, returns TRUE if it was
171 // successfully finished, FALSE if user cancelled it
172 virtual bool RunWizard(wxWizardPage
*firstPage
) = 0;
174 // get the current page (NULL if RunWizard() isn't running)
175 virtual wxWizardPage
*GetCurrentPage() const = 0;
177 // set the min size which should be available for the pages: a
178 // wizard will take into account the size of the bitmap (if any)
179 // itself and will never be less than some predefined fixed size
180 virtual void SetPageSize(const wxSize
& size
) = 0;
182 // get the size available for the page: the wizards are not resizeable, so
183 // this size doesn't change
184 virtual wxSize
GetPageSize() const = 0;
186 // set the best size for the wizard, i.e. make it big enough to contain all
187 // of the pages starting from the given one
189 // this function may be called several times and possible with different
190 // pages in which case it will only increase the page size if needed (this
191 // may be useful if not all pages are accessible from the first one by
193 virtual void FitToPage(const wxWizardPage
*firstPage
) = 0;
195 // wxWizard should be created using "new wxWizard" now, not with Create()
196 #ifdef WXWIN_COMPATIBILITY_2_2
197 static wxWizard
*Create(wxWindow
*parent
,
199 const wxString
& title
= wxEmptyString
,
200 const wxBitmap
& bitmap
= wxNullBitmap
,
201 const wxPoint
& pos
= wxDefaultPosition
,
202 const wxSize
& size
= wxDefaultSize
);
203 #endif // WXWIN_COMPATIBILITY_2_2
205 // the methods below may be overridden by the derived classes to provide
206 // custom logic for determining the pages order
208 virtual bool HasNextPage(wxWizardPage
*page
)
209 { return page
->GetNext() != NULL
; }
211 virtual bool HasPrevPage(wxWizardPage
*page
)
212 { return page
->GetPrev() != NULL
; }
215 // include the real class declaration
216 #include "wx/generic/wizard.h"
218 // ----------------------------------------------------------------------------
219 // wxWizardEvent class represents an event generated by the wizard: this event
220 // is first sent to the page itself and, if not processed there, goes up the
221 // window hierarchy as usual
222 // ----------------------------------------------------------------------------
224 class WXDLLEXPORT wxWizardEvent
: public wxNotifyEvent
227 wxWizardEvent(wxEventType type
= wxEVT_NULL
,
229 bool direction
= TRUE
,
230 wxWizardPage
* page
= NULL
);
232 // for EVT_WIZARD_PAGE_CHANGING, return TRUE if we're going forward or
233 // FALSE otherwise and for EVT_WIZARD_PAGE_CHANGED return TRUE if we came
234 // from the previous page and FALSE if we returned from the next one
235 // (this function doesn't make sense for CANCEL events)
236 bool GetDirection() const { return m_direction
; }
238 wxWizardPage
* GetPage() const { return m_page
; }
242 wxWizardPage
* m_page
;
244 DECLARE_DYNAMIC_CLASS(wxWizardEvent
)
247 // ----------------------------------------------------------------------------
248 // macros for handling wxWizardEvents
249 // ----------------------------------------------------------------------------
251 BEGIN_DECLARE_EVENT_TYPES()
252 DECLARE_EVENT_TYPE(wxEVT_WIZARD_PAGE_CHANGED
, 900)
253 DECLARE_EVENT_TYPE(wxEVT_WIZARD_PAGE_CHANGING
, 901)
254 DECLARE_EVENT_TYPE(wxEVT_WIZARD_CANCEL
, 902)
255 DECLARE_EVENT_TYPE(wxEVT_WIZARD_HELP
, 903)
256 END_DECLARE_EVENT_TYPES()
258 typedef void (wxEvtHandler::*wxWizardEventFunction
)(wxWizardEvent
&);
260 // notifies that the page has just been changed (can't be vetoed)
261 #define EVT_WIZARD_PAGE_CHANGED(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WIZARD_PAGE_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxWizardEventFunction) & fn, (wxObject *)NULL),
263 // the user pressed "<Back" or "Next>" button and the page is going to be
264 // changed - unless the event handler vetoes the event
265 #define EVT_WIZARD_PAGE_CHANGING(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WIZARD_PAGE_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxWizardEventFunction) & fn, (wxObject *)NULL),
267 // the user pressed "Cancel" button and the wizard is going to be dismissed -
268 // unless the event handler vetoes the event
269 #define EVT_WIZARD_CANCEL(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WIZARD_CANCEL, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxWizardEventFunction) & fn, (wxObject *)NULL),
271 // the user pressed "Help" button
272 #define EVT_WIZARD_HELP(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_WIZARD_HELP, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxWizardEventFunction) & fn, (wxObject *)NULL),
274 #endif // wxUSE_WIZARDDLG
276 #endif // _WX_WIZARD_H_