1. Implemented support for different icons for different states (expanded,
[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:
8 // Created: 15.08.99
9 // RCS-ID: $Id$
10 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
11 // Licence: wxWindows license
12 ///////////////////////////////////////////////////////////////////////////////
13
14 #ifndef _WX_WIZARD_H_
15 #define _WX_WIZARD_H_
16
17 // ----------------------------------------------------------------------------
18 // headers and other simple declarations
19 // ----------------------------------------------------------------------------
20
21 #ifndef WX_PRECOMP
22 #include "wx/dialog.h" // the base class
23
24 #include "wx/event.h" // wxEVT_XXX constants
25 #endif // WX_PRECOMP
26
27 // forward declarations
28 class WXDLLEXPORT wxWizard;
29
30 // ----------------------------------------------------------------------------
31 // wxWizardPage is one of the wizards screen: it must know what are the
32 // following and preceding pages (which may be NULL for the first/last page).
33 //
34 // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be
35 // used as such (i.e. controls may be placed directly on it &c).
36 // ----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxWizardPage : public wxPanel
39 {
40 public:
41 // ctor: no other parameters are needed because the wizard will resize and
42 // reposition the page anyhow
43 wxWizardPage(wxWizard *parent);
44
45 // these functions are used by the wizard to show another page when the
46 // user chooses "Back" or "Next" button
47 virtual wxWizardPage *GetPrev() const = 0;
48 virtual wxWizardPage *GetNext() const = 0;
49
50 private:
51 DECLARE_ABSTRACT_CLASS(wxWizardPage)
52 };
53
54 // ----------------------------------------------------------------------------
55 // wxWizardPageSimple just returns the pointers given to the ctor and is useful
56 // to create a simple wizard where the order of pages never changes.
57 //
58 // OTOH, it is also possible to dynamicly decide which page to return (i.e.
59 // depending on the user's choices) as the wizard sample shows - in order to do
60 // this, you must derive from wxWizardPage directly.
61 // ----------------------------------------------------------------------------
62
63 class WXDLLEXPORT wxWizardPageSimple : public wxWizardPage
64 {
65 public:
66 // ctor takes the previous and next pages
67 wxWizardPageSimple(wxWizard *parent = NULL, // let it be default ctor too
68 wxWizardPage *prev = (wxWizardPage *)NULL,
69 wxWizardPage *next = (wxWizardPage *)NULL)
70 : wxWizardPage(parent)
71 {
72 m_prev = prev;
73 m_next = next;
74 }
75
76 // the pointers may be also set later - but before starting the wizard
77 void SetPrev(wxWizardPage *prev) { m_prev = prev; }
78 void SetNext(wxWizardPage *next) { m_next = next; }
79
80 // a convenience function to make the pages follow each other
81 static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second)
82 {
83 wxCHECK_RET( first && second,
84 _T("NULL passed to wxWizardPageSimple::Chain") );
85
86 first->SetNext(second);
87 second->SetPrev(first);
88 }
89
90 // base class pure virtuals
91 virtual wxWizardPage *GetPrev() const;
92 virtual wxWizardPage *GetNext() const;
93
94 private:
95 // pointers are private, the derived classes shouldn't mess with them -
96 // just derive from wxWizardPage directly to implement different behaviour
97 wxWizardPage *m_prev,
98 *m_next;
99
100 DECLARE_DYNAMIC_CLASS(wxWizardPageSimple)
101 };
102
103 // ----------------------------------------------------------------------------
104 // wxWizard
105 // ----------------------------------------------------------------------------
106
107 class WXDLLEXPORT wxWizardBase : public wxDialog
108 {
109 public:
110 // create the wizard control
111 static wxWizard *Create(wxWindow *parent,
112 int id = -1,
113 const wxString& title = wxEmptyString,
114 const wxBitmap& bitmap = wxNullBitmap,
115 const wxPoint& pos = wxDefaultPosition,
116 const wxSize& size = wxDefaultSize);
117
118 // executes the wizard starting from the given page, returns TRUE if it was
119 // successfully finished, FALSE if user cancelled it
120 virtual bool RunWizard(wxWizardPage *firstPage) = 0;
121
122 // get the current page (NULL if RunWizard() isn't running)
123 virtual wxWizardPage *GetCurrentPage() const = 0;
124 };
125
126 // include the real class declaration
127 #include "wx/generic/wizard.h"
128
129 // ----------------------------------------------------------------------------
130 // wxWizardEvent class represents an event generated by the wizard: this event
131 // is first sent to the page itself and, if not processed there, goes up the
132 // window hierarchy as usual
133 // ----------------------------------------------------------------------------
134
135 class WXDLLEXPORT wxWizardEvent : public wxNotifyEvent
136 {
137 public:
138 wxWizardEvent(wxEventType type = wxEVT_NULL,
139 int id = -1,
140 bool direction = TRUE);
141
142 // for EVT_WIZARD_PAGE_CHANGING, return TRUE if we're going forward or
143 // FALSE otherwise and for EVT_WIZARD_PAGE_CHANGED return TRUE if we came
144 // from the previous page and FALSE if we returned from the next one
145 // (this function doesn't make sense for CANCEL events)
146 bool GetDirection() const { return m_direction; }
147
148 private:
149 bool m_direction;
150
151 DECLARE_DYNAMIC_CLASS(wxWizardEvent)
152 };
153
154 // ----------------------------------------------------------------------------
155 // macros for handling wxWizardEvents
156 // ----------------------------------------------------------------------------
157
158 typedef void (wxEvtHandler::*wxWizardEventFunction)(wxWizardEvent&);
159
160 // notifies that the page has just been changed (can't be vetoed)
161 #define EVT_WIZARD_PAGE_CHANGED(id, fn) { wxEVT_WIZARD_PAGE_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxWizardEventFunction) & fn, (wxObject *)NULL },
162
163 // the user pressed "<Back" or "Next>" button and the page is going to be
164 // changed - unless the event handler vetoes the event
165 #define EVT_WIZARD_PAGE_CHANGING(id, fn) { wxEVT_WIZARD_PAGE_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxWizardEventFunction) & fn, (wxObject *)NULL },
166
167 // the user pressed "Cancel" button and the wizard is going to be dismissed -
168 // unless the event handler vetoes the event
169 #define EVT_WIZARD_CANCEL(id, fn) { wxEVT_WIZARD_CANCEL, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxWizardEventFunction) & fn, (wxObject *)NULL },
170
171 #endif // _WX_WIZARD_H_