]> git.saurik.com Git - wxWidgets.git/blame - samples/wizard/wizard.cpp
Removed more traces of wxrcedit
[wxWidgets.git] / samples / wizard / wizard.cpp
CommitLineData
66cd017c 1/////////////////////////////////////////////////////////////////////////////
13f5935c 2// Name: wizard.cpp
be5a51fb 3// Purpose: wxWidgets sample demonstrating wxWizard control
66cd017c 4// Author: Vadim Zeitlin
07f20d9a 5// Modified by: Robert Vazan (sizers)
66cd017c
VZ
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
66cd017c
VZ
20// For compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
07f20d9a 27// for all others, include the necessary headers
66cd017c 28#ifndef WX_PRECOMP
07f20d9a
VZ
29 #include "wx/stattext.h"
30 #include "wx/log.h"
31 #include "wx/app.h"
32 #include "wx/checkbox.h"
f2e93537 33 #include "wx/checklst.h"
07f20d9a
VZ
34 #include "wx/msgdlg.h"
35 #include "wx/radiobox.h"
36 #include "wx/menu.h"
37 #include "wx/sizer.h"
66cd017c
VZ
38#endif
39
40#include "wx/wizard.h"
41
b87654f3
VZ
42#ifndef __WXMSW__
43 #include "wiztest.xpm"
d32011d4 44 #include "wiztest2.xpm"
b87654f3
VZ
45#endif
46
d93c719a
VZ
47// ----------------------------------------------------------------------------
48// constants
49// ----------------------------------------------------------------------------
50
51// ids for menu items
52enum
53{
54 Wizard_Quit = 100,
55 Wizard_Run,
56 Wizard_About = 1000
57};
58
66cd017c
VZ
59// ----------------------------------------------------------------------------
60// private classes
61// ----------------------------------------------------------------------------
62
63// Define a new application type, each program should derive a class from wxApp
64class MyApp : public wxApp
65{
66public:
67 // override base class virtuals
68 virtual bool OnInit();
69};
70
d93c719a
VZ
71class MyFrame : public wxFrame
72{
73public:
74 // ctor(s)
75 MyFrame(const wxString& title);
76
77 // event handlers (these functions should _not_ be virtual)
78 void OnQuit(wxCommandEvent& event);
79 void OnAbout(wxCommandEvent& event);
80 void OnRunWizard(wxCommandEvent& event);
81 void OnWizardCancel(wxWizardEvent& event);
8a7dfb14 82 void OnWizardFinished(wxWizardEvent& event);
d93c719a
VZ
83
84private:
be5a51fb 85 // any class wishing to process wxWidgets events must use this macro
d93c719a
VZ
86 DECLARE_EVENT_TABLE()
87};
66cd017c
VZ
88
89// ----------------------------------------------------------------------------
90// some pages for our wizard
91// ----------------------------------------------------------------------------
92
436aae91 93// This shows how to simply control the validity of the user input by just
66cd017c
VZ
94// overriding TransferDataFromWindow() - of course, in a real program, the
95// check wouldn't be so trivial and the data will be probably saved somewhere
436aae91 96// too.
d93c719a 97//
436aae91 98// It also shows how to use a different bitmap for one of the pages.
74b31181 99class wxValidationPage : public wxWizardPageSimple
66cd017c
VZ
100{
101public:
74b31181 102 wxValidationPage(wxWizard *parent) : wxWizardPageSimple(parent)
66cd017c 103 {
d32011d4 104 m_bitmap = wxBITMAP(wiztest2);
d93c719a 105
71572a74 106 m_checkbox = new wxCheckBox(this, wxID_ANY, _T("&Check me"));
226e5774 107
07f20d9a
VZ
108 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
109 mainSizer->Add(
71572a74 110 new wxStaticText(this, wxID_ANY,
07f20d9a
VZ
111 _T("You need to check the checkbox\n")
112 _T("below before going to the next page\n")),
113 0,
114 wxALL,
115 5
116 );
117
118 mainSizer->Add(
119 m_checkbox,
120 0, // No stretching
121 wxALL,
122 5 // Border
123 );
124 SetSizer(mainSizer);
125 mainSizer->Fit(this);
66cd017c
VZ
126 }
127
128 virtual bool TransferDataFromWindow()
129 {
74b31181 130 if ( !m_checkbox->GetValue() )
66cd017c 131 {
9f84eccd 132 wxMessageBox(_T("Check the checkbox first!"), _T("No way"),
b87654f3 133 wxICON_WARNING | wxOK, this);
66cd017c 134
71572a74 135 return false;
66cd017c
VZ
136 }
137
71572a74 138 return true;
66cd017c
VZ
139 }
140
141private:
142 wxCheckBox *m_checkbox;
143};
144
74b31181
VZ
145// This is a more complicated example of validity checking: using events we may
146// allow to return to the previous page, but not to proceed. It also
147// demonstrates how to intercept [Cancel] button press.
148class wxRadioboxPage : public wxWizardPageSimple
149{
150public:
151 // directions in which we allow the user to proceed from this page
152 enum
153 {
154 Forward, Backward, Both, Neither
155 };
156
157 wxRadioboxPage(wxWizard *parent) : wxWizardPageSimple(parent)
158 {
159 // should correspond to the enum above
dc1efb1d
JS
160 // static wxString choices[] = { "forward", "backward", "both", "neither" };
161 // The above syntax can cause an internal compiler error with gcc.
162 wxString choices[4];
9f84eccd
MB
163 choices[0] = _T("forward");
164 choices[1] = _T("backward");
165 choices[2] = _T("both");
166 choices[3] = _T("neither");
74b31181 167
71572a74 168 m_radio = new wxRadioBox(this, wxID_ANY, _T("Allow to proceed:"),
07f20d9a 169 wxDefaultPosition, wxDefaultSize,
74b31181
VZ
170 WXSIZEOF(choices), choices,
171 1, wxRA_SPECIFY_COLS);
172 m_radio->SetSelection(Both);
226e5774 173
07f20d9a
VZ
174 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
175 mainSizer->Add(
176 m_radio,
177 0, // No stretching
178 wxALL,
179 5 // Border
180 );
226e5774 181
07f20d9a
VZ
182 SetSizer(mainSizer);
183 mainSizer->Fit(this);
74b31181
VZ
184 }
185
186 // wizard event handlers
187 void OnWizardCancel(wxWizardEvent& event)
188 {
9f84eccd 189 if ( wxMessageBox(_T("Do you really want to cancel?"), _T("Question"),
74b31181
VZ
190 wxICON_QUESTION | wxYES_NO, this) != wxYES )
191 {
192 // not confirmed
193 event.Veto();
194 }
195 }
196
197 void OnWizardPageChanging(wxWizardEvent& event)
198 {
199 int sel = m_radio->GetSelection();
200
201 if ( sel == Both )
202 return;
203
204 if ( event.GetDirection() && sel == Forward )
205 return;
206
207 if ( !event.GetDirection() && sel == Backward )
208 return;
209
9f84eccd 210 wxMessageBox(_T("You can't go there"), _T("Not allowed"),
74b31181
VZ
211 wxICON_WARNING | wxOK, this);
212
213 event.Veto();
214 }
215
216private:
217 wxRadioBox *m_radio;
218
219 DECLARE_EVENT_TABLE()
220};
221
436aae91 222// This shows how to dynamically (i.e. during run-time) arrange the page order.
74b31181
VZ
223class wxCheckboxPage : public wxWizardPage
224{
225public:
226 wxCheckboxPage(wxWizard *parent,
227 wxWizardPage *prev,
228 wxWizardPage *next)
229 : wxWizardPage(parent)
230 {
231 m_prev = prev;
232 m_next = next;
226e5774 233
07f20d9a
VZ
234 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
235
236 mainSizer->Add(
71572a74 237 new wxStaticText(this, wxID_ANY, _T("Try checking the box below and\n")
07f20d9a
VZ
238 _T("then going back and clearing it")),
239 0, // No vertical stretching
240 wxALL,
241 5 // Border width
242 );
74b31181 243
71572a74 244 m_checkbox = new wxCheckBox(this, wxID_ANY, _T("&Skip the next page"));
07f20d9a
VZ
245 mainSizer->Add(
246 m_checkbox,
247 0, // No vertical stretching
248 wxALL,
249 5 // Border width
250 );
f2e93537 251
653d7a50 252#if wxUSE_CHECKLISTBOX
f2e93537
RR
253 static const wxChar *aszChoices[] =
254 { _T("Zeroth"), _T("First"), _T("Second"), _T("Third"), _T("Fourth"), _T("Fifth"), _T("Sixth"), _T("Seventh"), _T("Eighth"), _T("Nineth") };
255 wxString *astrChoices = new wxString[WXSIZEOF(aszChoices)];
256 unsigned int ui;
257 for ( ui = 0; ui < WXSIZEOF(aszChoices); ui++ )
258 astrChoices[ui] = aszChoices[ui];
653d7a50 259
226e5774 260 m_checklistbox = new wxCheckListBox(this, wxID_ANY, wxDefaultPosition, wxSize(100,100),
f2e93537 261 WXSIZEOF(aszChoices), astrChoices);
226e5774 262
f2e93537
RR
263 mainSizer->Add(
264 m_checklistbox,
265 0, // No vertical stretching
266 wxALL,
267 5 // Border width
268 );
653d7a50 269#endif // wxUSE_CHECKLISTBOX
226e5774 270
07f20d9a
VZ
271 SetSizer(mainSizer);
272 mainSizer->Fit(this);
74b31181
VZ
273 }
274
275 // implement wxWizardPage functions
276 virtual wxWizardPage *GetPrev() const { return m_prev; }
277 virtual wxWizardPage *GetNext() const
278 {
279 return m_checkbox->GetValue() ? m_next->GetNext() : m_next;
280 }
281
282private:
283 wxWizardPage *m_prev,
284 *m_next;
285
286 wxCheckBox *m_checkbox;
653d7a50 287#if wxUSE_CHECKLISTBOX
f2e93537 288 wxCheckListBox *m_checklistbox;
653d7a50 289#endif
74b31181
VZ
290};
291
66cd017c
VZ
292// ============================================================================
293// implementation
294// ============================================================================
295
d93c719a
VZ
296// ----------------------------------------------------------------------------
297// event tables and such
298// ----------------------------------------------------------------------------
299
300BEGIN_EVENT_TABLE(MyFrame, wxFrame)
301 EVT_MENU(Wizard_Quit, MyFrame::OnQuit)
302 EVT_MENU(Wizard_About, MyFrame::OnAbout)
303 EVT_MENU(Wizard_Run, MyFrame::OnRunWizard)
304
71572a74
WS
305 EVT_WIZARD_CANCEL(wxID_ANY, MyFrame::OnWizardCancel)
306 EVT_WIZARD_FINISHED(wxID_ANY, MyFrame::OnWizardFinished)
d93c719a
VZ
307END_EVENT_TABLE()
308
74b31181 309BEGIN_EVENT_TABLE(wxRadioboxPage, wxWizardPageSimple)
71572a74
WS
310 EVT_WIZARD_PAGE_CHANGING(wxID_ANY, wxRadioboxPage::OnWizardPageChanging)
311 EVT_WIZARD_CANCEL(wxID_ANY, wxRadioboxPage::OnWizardCancel)
74b31181
VZ
312END_EVENT_TABLE()
313
d93c719a
VZ
314IMPLEMENT_APP(MyApp)
315
66cd017c
VZ
316// ----------------------------------------------------------------------------
317// the application class
318// ----------------------------------------------------------------------------
319
320// `Main program' equivalent: the program execution "starts" here
321bool MyApp::OnInit()
322{
9f84eccd 323 MyFrame *frame = new MyFrame(_T("wxWizard Sample"));
d93c719a
VZ
324
325 // and show it (the frames, unlike simple controls, are not shown when
326 // created initially)
71572a74 327 frame->Show(true);
d93c719a
VZ
328
329 // we're done
71572a74 330 return true;
d93c719a
VZ
331}
332
333// ----------------------------------------------------------------------------
334// MyFrame
335// ----------------------------------------------------------------------------
336
337MyFrame::MyFrame(const wxString& title)
71572a74 338 : wxFrame((wxFrame *)NULL, wxID_ANY, title,
d93c719a
VZ
339 wxDefaultPosition, wxSize(250, 150)) // small frame
340{
341 wxMenu *menuFile = new wxMenu;
9f84eccd 342 menuFile->Append(Wizard_Run, _T("&Run wizard...\tCtrl-R"));
d93c719a 343 menuFile->AppendSeparator();
9f84eccd 344 menuFile->Append(Wizard_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
d93c719a
VZ
345
346 wxMenu *helpMenu = new wxMenu;
9f84eccd 347 helpMenu->Append(Wizard_About, _T("&About...\tF1"), _T("Show about dialog"));
d93c719a
VZ
348
349 // now append the freshly created menu to the menu bar...
350 wxMenuBar *menuBar = new wxMenuBar();
9f84eccd
MB
351 menuBar->Append(menuFile, _T("&File"));
352 menuBar->Append(helpMenu, _T("&Help"));
66cd017c 353
d93c719a
VZ
354 // ... and attach this menu bar to the frame
355 SetMenuBar(menuBar);
356
357 // also create status bar which we use in OnWizardCancel
960a83cc 358#if wxUSE_STATUSBAR
d93c719a 359 CreateStatusBar();
960a83cc 360#endif // wxUSE_STATUSBAR
d93c719a
VZ
361}
362
363void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
364{
71572a74
WS
365 // true is to force the frame to close
366 Close(true);
d93c719a
VZ
367}
368
369void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
370{
9f84eccd 371 wxMessageBox(_T("Demo of wxWizard class\n")
749bfe9a 372 _T("(c) 1999, 2000 Vadim Zeitlin"),
9f84eccd 373 _T("About wxWizard sample"), wxOK | wxICON_INFORMATION, this);
d93c719a
VZ
374}
375
376void MyFrame::OnRunWizard(wxCommandEvent& WXUNUSED(event))
377{
71572a74 378 wxWizard *wizard = new wxWizard(this, wxID_ANY,
9f84eccd 379 _T("Absolutely Useless Wizard"),
07f20d9a
VZ
380 wxBITMAP(wiztest),
381 wxDefaultPosition,
382 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
2f6c54eb 383
74b31181
VZ
384 // a wizard page may be either an object of predefined class
385 wxWizardPageSimple *page1 = new wxWizardPageSimple(wizard);
226e5774
WS
386
387 /* wxStaticText *text = */ new wxStaticText(page1, wxID_ANY,
07f20d9a 388 _T("This wizard doesn't help you\nto do anything at all.\n")
9f84eccd 389 _T("\n")
07f20d9a
VZ
390 _T("The next pages will present you\nwith more useless controls."),
391 wxPoint(5,5)
f6bcfd97 392 );
66cd017c 393
74b31181
VZ
394 // ... or a derived class
395 wxRadioboxPage *page3 = new wxRadioboxPage(wizard);
396 wxValidationPage *page4 = new wxValidationPage(wizard);
397
398 // set the page order using a convenience function - could also use
399 // SetNext/Prev directly as below
400 wxWizardPageSimple::Chain(page3, page4);
401
402 // this page is not a wxWizardPageSimple, so we use SetNext/Prev to insert
403 // it into the chain of pages
404 wxCheckboxPage *page2 = new wxCheckboxPage(wizard, page1, page3);
405 page1->SetNext(page2);
406 page3->SetPrev(page2);
66cd017c 407
fa513361 408 // allow the wizard to size itself around the pages
07f20d9a 409 wizard->GetPageAreaSizer()->Add(page1);
226e5774 410
74b31181 411 if ( wizard->RunWizard(page1) )
66cd017c 412 {
9f84eccd 413 wxMessageBox(_T("The wizard successfully completed"), _T("That's all"),
b87654f3 414 wxICON_INFORMATION | wxOK);
66cd017c
VZ
415 }
416
417 wizard->Destroy();
66cd017c 418}
01dba85a 419
8a7dfb14
VZ
420void MyFrame::OnWizardFinished(wxWizardEvent& WXUNUSED(event))
421{
422 wxLogStatus(this, wxT("The wizard finished successfully."));
423}
424
d93c719a
VZ
425void MyFrame::OnWizardCancel(wxWizardEvent& WXUNUSED(event))
426{
4693b20c 427 wxLogStatus(this, wxT("The wizard was cancelled."));
d93c719a 428}