]>
Commit | Line | Data |
---|---|---|
66cd017c VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wiztest.cpp | |
3 | // Purpose: wxWindows sample demonstrating wxWizard control | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 15.08.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vadim Zeitlin | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "wiztest.cpp" | |
22 | #pragma interface "wiztest.cpp" | |
23 | #endif | |
24 | ||
25 | // For compilers that support precompilation, includes "wx/wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
29 | #pragma hdrstop | |
30 | #endif | |
31 | ||
32 | // for all others, include the necessary headers (this file is usually all you | |
33 | // need because it includes almost all "standard" wxWindows headers | |
34 | #ifndef WX_PRECOMP | |
35 | #include "wx/wx.h" | |
36 | #endif | |
37 | ||
38 | #include "wx/wizard.h" | |
39 | ||
b87654f3 VZ |
40 | #ifndef __WXMSW__ |
41 | #include "wiztest.xpm" | |
42 | #endif | |
43 | ||
66cd017c VZ |
44 | // ---------------------------------------------------------------------------- |
45 | // private classes | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | // Define a new application type, each program should derive a class from wxApp | |
49 | class MyApp : public wxApp | |
50 | { | |
51 | public: | |
52 | // override base class virtuals | |
53 | virtual bool OnInit(); | |
54 | }; | |
55 | ||
56 | IMPLEMENT_APP(MyApp) | |
57 | ||
58 | // ---------------------------------------------------------------------------- | |
59 | // some pages for our wizard | |
60 | // ---------------------------------------------------------------------------- | |
61 | ||
62 | // this shows how to simply control the validity of the user input by just | |
63 | // overriding TransferDataFromWindow() - of course, in a real program, the | |
64 | // check wouldn't be so trivial and the data will be probably saved somewhere | |
65 | // too | |
74b31181 | 66 | class wxValidationPage : public wxWizardPageSimple |
66cd017c VZ |
67 | { |
68 | public: | |
74b31181 | 69 | wxValidationPage(wxWizard *parent) : wxWizardPageSimple(parent) |
66cd017c | 70 | { |
74b31181 | 71 | m_checkbox = new wxCheckBox(this, -1, "&Check me"); |
66cd017c VZ |
72 | } |
73 | ||
74 | virtual bool TransferDataFromWindow() | |
75 | { | |
74b31181 | 76 | if ( !m_checkbox->GetValue() ) |
66cd017c | 77 | { |
74b31181 | 78 | wxMessageBox("Check the checkbox first!", "No way", |
b87654f3 | 79 | wxICON_WARNING | wxOK, this); |
66cd017c VZ |
80 | |
81 | return FALSE; | |
82 | } | |
83 | ||
84 | return TRUE; | |
85 | } | |
86 | ||
87 | private: | |
88 | wxCheckBox *m_checkbox; | |
89 | }; | |
90 | ||
74b31181 VZ |
91 | // This is a more complicated example of validity checking: using events we may |
92 | // allow to return to the previous page, but not to proceed. It also | |
93 | // demonstrates how to intercept [Cancel] button press. | |
94 | class wxRadioboxPage : public wxWizardPageSimple | |
95 | { | |
96 | public: | |
97 | // directions in which we allow the user to proceed from this page | |
98 | enum | |
99 | { | |
100 | Forward, Backward, Both, Neither | |
101 | }; | |
102 | ||
103 | wxRadioboxPage(wxWizard *parent) : wxWizardPageSimple(parent) | |
104 | { | |
105 | // should correspond to the enum above | |
106 | static wxString choices[] = { "forward", "backward", "both", "neither" }; | |
107 | ||
108 | m_radio = new wxRadioBox(this, -1, "Allow to proceed:", | |
109 | wxPoint(5, 5), wxDefaultSize, | |
110 | WXSIZEOF(choices), choices, | |
111 | 1, wxRA_SPECIFY_COLS); | |
112 | m_radio->SetSelection(Both); | |
113 | } | |
114 | ||
115 | // wizard event handlers | |
116 | void OnWizardCancel(wxWizardEvent& event) | |
117 | { | |
118 | if ( wxMessageBox("Do you really want to cancel?", "Question", | |
119 | wxICON_QUESTION | wxYES_NO, this) != wxYES ) | |
120 | { | |
121 | // not confirmed | |
122 | event.Veto(); | |
123 | } | |
124 | } | |
125 | ||
126 | void OnWizardPageChanging(wxWizardEvent& event) | |
127 | { | |
128 | int sel = m_radio->GetSelection(); | |
129 | ||
130 | if ( sel == Both ) | |
131 | return; | |
132 | ||
133 | if ( event.GetDirection() && sel == Forward ) | |
134 | return; | |
135 | ||
136 | if ( !event.GetDirection() && sel == Backward ) | |
137 | return; | |
138 | ||
139 | wxMessageBox("You can't go there", "Not allowed", | |
140 | wxICON_WARNING | wxOK, this); | |
141 | ||
142 | event.Veto(); | |
143 | } | |
144 | ||
145 | private: | |
146 | wxRadioBox *m_radio; | |
147 | ||
148 | DECLARE_EVENT_TABLE() | |
149 | }; | |
150 | ||
151 | // this shows how to dynamically (i.e. during run-time) arrange the page order | |
152 | class wxCheckboxPage : public wxWizardPage | |
153 | { | |
154 | public: | |
155 | wxCheckboxPage(wxWizard *parent, | |
156 | wxWizardPage *prev, | |
157 | wxWizardPage *next) | |
158 | : wxWizardPage(parent) | |
159 | { | |
160 | m_prev = prev; | |
161 | m_next = next; | |
162 | ||
163 | (void)new wxStaticText(this, -1, "Try checking the box below and\n" | |
164 | "then going back and clearing it"); | |
165 | ||
166 | m_checkbox = new wxCheckBox(this, -1, "&Skip the next page", | |
167 | wxPoint(5, 30)); | |
168 | } | |
169 | ||
170 | // implement wxWizardPage functions | |
171 | virtual wxWizardPage *GetPrev() const { return m_prev; } | |
172 | virtual wxWizardPage *GetNext() const | |
173 | { | |
174 | return m_checkbox->GetValue() ? m_next->GetNext() : m_next; | |
175 | } | |
176 | ||
177 | private: | |
178 | wxWizardPage *m_prev, | |
179 | *m_next; | |
180 | ||
181 | wxCheckBox *m_checkbox; | |
182 | }; | |
183 | ||
66cd017c VZ |
184 | // ============================================================================ |
185 | // implementation | |
186 | // ============================================================================ | |
187 | ||
74b31181 VZ |
188 | BEGIN_EVENT_TABLE(wxRadioboxPage, wxWizardPageSimple) |
189 | EVT_WIZARD_PAGE_CHANGING(-1, wxRadioboxPage::OnWizardPageChanging) | |
190 | EVT_WIZARD_CANCEL(-1, wxRadioboxPage::OnWizardCancel) | |
191 | END_EVENT_TABLE() | |
192 | ||
66cd017c VZ |
193 | // ---------------------------------------------------------------------------- |
194 | // the application class | |
195 | // ---------------------------------------------------------------------------- | |
196 | ||
197 | // `Main program' equivalent: the program execution "starts" here | |
198 | bool MyApp::OnInit() | |
199 | { | |
b87654f3 | 200 | #ifdef __WXMSW__ |
66cd017c | 201 | wxBitmap bmpWizard("wiztest.bmp", wxBITMAP_TYPE_BMP); |
b87654f3 VZ |
202 | #else |
203 | wxBitmap bmpWizard(wizimage); | |
204 | #endif | |
66cd017c VZ |
205 | |
206 | wxWizard *wizard = wxWizard::Create(NULL, -1, | |
207 | "Absolutely Useless Wizard", | |
208 | bmpWizard); | |
209 | ||
74b31181 VZ |
210 | // a wizard page may be either an object of predefined class |
211 | wxWizardPageSimple *page1 = new wxWizardPageSimple(wizard); | |
212 | (void)new wxStaticText(page1, -1, | |
66cd017c VZ |
213 | "This wizard doesn't help you to do anything at " |
214 | "all.\n" | |
215 | "\n" | |
216 | "The next pages will present you with more useless " | |
217 | "controls."); | |
66cd017c | 218 | |
74b31181 VZ |
219 | // ... or a derived class |
220 | wxRadioboxPage *page3 = new wxRadioboxPage(wizard); | |
221 | wxValidationPage *page4 = new wxValidationPage(wizard); | |
222 | ||
223 | // set the page order using a convenience function - could also use | |
224 | // SetNext/Prev directly as below | |
225 | wxWizardPageSimple::Chain(page3, page4); | |
226 | ||
227 | // this page is not a wxWizardPageSimple, so we use SetNext/Prev to insert | |
228 | // it into the chain of pages | |
229 | wxCheckboxPage *page2 = new wxCheckboxPage(wizard, page1, page3); | |
230 | page1->SetNext(page2); | |
231 | page3->SetPrev(page2); | |
66cd017c | 232 | |
74b31181 | 233 | if ( wizard->RunWizard(page1) ) |
66cd017c VZ |
234 | { |
235 | wxMessageBox("The wizard successfully completed", "That's all", | |
b87654f3 | 236 | wxICON_INFORMATION | wxOK); |
66cd017c VZ |
237 | } |
238 | ||
239 | wizard->Destroy(); | |
240 | ||
241 | // we're done | |
242 | return FALSE; | |
243 | } | |
01dba85a | 244 |