]> git.saurik.com Git - wxWidgets.git/blame - samples/wizard/wizard.cpp
reSWIGged
[wxWidgets.git] / samples / wizard / wizard.cpp
CommitLineData
66cd017c 1/////////////////////////////////////////////////////////////////////////////
13f5935c 2// Name: wizard.cpp
66cd017c
VZ
3// Purpose: wxWindows sample demonstrating wxWizard control
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"
33 #include "wx/msgdlg.h"
34 #include "wx/radiobox.h"
35 #include "wx/menu.h"
36 #include "wx/sizer.h"
66cd017c
VZ
37#endif
38
39#include "wx/wizard.h"
40
b87654f3
VZ
41#ifndef __WXMSW__
42 #include "wiztest.xpm"
d32011d4 43 #include "wiztest2.xpm"
b87654f3
VZ
44#endif
45
d93c719a
VZ
46// ----------------------------------------------------------------------------
47// constants
48// ----------------------------------------------------------------------------
49
50// ids for menu items
51enum
52{
53 Wizard_Quit = 100,
54 Wizard_Run,
55 Wizard_About = 1000
56};
57
66cd017c
VZ
58// ----------------------------------------------------------------------------
59// private classes
60// ----------------------------------------------------------------------------
61
62// Define a new application type, each program should derive a class from wxApp
63class MyApp : public wxApp
64{
65public:
66 // override base class virtuals
67 virtual bool OnInit();
68};
69
d93c719a
VZ
70class MyFrame : public wxFrame
71{
72public:
73 // ctor(s)
74 MyFrame(const wxString& title);
75
76 // event handlers (these functions should _not_ be virtual)
77 void OnQuit(wxCommandEvent& event);
78 void OnAbout(wxCommandEvent& event);
79 void OnRunWizard(wxCommandEvent& event);
80 void OnWizardCancel(wxWizardEvent& event);
8a7dfb14 81 void OnWizardFinished(wxWizardEvent& event);
d93c719a
VZ
82
83private:
84 // any class wishing to process wxWindows events must use this macro
85 DECLARE_EVENT_TABLE()
86};
66cd017c
VZ
87
88// ----------------------------------------------------------------------------
89// some pages for our wizard
90// ----------------------------------------------------------------------------
91
92// this shows how to simply control the validity of the user input by just
93// overriding TransferDataFromWindow() - of course, in a real program, the
94// check wouldn't be so trivial and the data will be probably saved somewhere
95// too
d93c719a
VZ
96//
97// it also shows how to use a different bitmap for one of the pages
74b31181 98class wxValidationPage : public wxWizardPageSimple
66cd017c
VZ
99{
100public:
74b31181 101 wxValidationPage(wxWizard *parent) : wxWizardPageSimple(parent)
66cd017c 102 {
d32011d4 103 m_bitmap = wxBITMAP(wiztest2);
d93c719a 104
9f84eccd 105 m_checkbox = new wxCheckBox(this, -1, _T("&Check me"));
07f20d9a
VZ
106
107 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
108 mainSizer->Add(
109 new wxStaticText(this, -1,
110 _T("You need to check the checkbox\n")
111 _T("below before going to the next page\n")),
112 0,
113 wxALL,
114 5
115 );
116
117 mainSizer->Add(
118 m_checkbox,
119 0, // No stretching
120 wxALL,
121 5 // Border
122 );
123 SetSizer(mainSizer);
124 mainSizer->Fit(this);
66cd017c
VZ
125 }
126
127 virtual bool TransferDataFromWindow()
128 {
74b31181 129 if ( !m_checkbox->GetValue() )
66cd017c 130 {
9f84eccd 131 wxMessageBox(_T("Check the checkbox first!"), _T("No way"),
b87654f3 132 wxICON_WARNING | wxOK, this);
66cd017c
VZ
133
134 return FALSE;
135 }
136
137 return TRUE;
138 }
139
140private:
141 wxCheckBox *m_checkbox;
142};
143
74b31181
VZ
144// This is a more complicated example of validity checking: using events we may
145// allow to return to the previous page, but not to proceed. It also
146// demonstrates how to intercept [Cancel] button press.
147class wxRadioboxPage : public wxWizardPageSimple
148{
149public:
150 // directions in which we allow the user to proceed from this page
151 enum
152 {
153 Forward, Backward, Both, Neither
154 };
155
156 wxRadioboxPage(wxWizard *parent) : wxWizardPageSimple(parent)
157 {
158 // should correspond to the enum above
dc1efb1d
JS
159 // static wxString choices[] = { "forward", "backward", "both", "neither" };
160 // The above syntax can cause an internal compiler error with gcc.
161 wxString choices[4];
9f84eccd
MB
162 choices[0] = _T("forward");
163 choices[1] = _T("backward");
164 choices[2] = _T("both");
165 choices[3] = _T("neither");
74b31181 166
9f84eccd 167 m_radio = new wxRadioBox(this, -1, _T("Allow to proceed:"),
07f20d9a 168 wxDefaultPosition, wxDefaultSize,
74b31181
VZ
169 WXSIZEOF(choices), choices,
170 1, wxRA_SPECIFY_COLS);
171 m_radio->SetSelection(Both);
07f20d9a
VZ
172
173 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
174 mainSizer->Add(
175 m_radio,
176 0, // No stretching
177 wxALL,
178 5 // Border
179 );
180 SetSizer(mainSizer);
181 mainSizer->Fit(this);
74b31181
VZ
182 }
183
184 // wizard event handlers
185 void OnWizardCancel(wxWizardEvent& event)
186 {
9f84eccd 187 if ( wxMessageBox(_T("Do you really want to cancel?"), _T("Question"),
74b31181
VZ
188 wxICON_QUESTION | wxYES_NO, this) != wxYES )
189 {
190 // not confirmed
191 event.Veto();
192 }
193 }
194
195 void OnWizardPageChanging(wxWizardEvent& event)
196 {
197 int sel = m_radio->GetSelection();
198
199 if ( sel == Both )
200 return;
201
202 if ( event.GetDirection() && sel == Forward )
203 return;
204
205 if ( !event.GetDirection() && sel == Backward )
206 return;
207
9f84eccd 208 wxMessageBox(_T("You can't go there"), _T("Not allowed"),
74b31181
VZ
209 wxICON_WARNING | wxOK, this);
210
211 event.Veto();
212 }
213
214private:
215 wxRadioBox *m_radio;
216
217 DECLARE_EVENT_TABLE()
218};
219
220// this shows how to dynamically (i.e. during run-time) arrange the page order
221class wxCheckboxPage : public wxWizardPage
222{
223public:
224 wxCheckboxPage(wxWizard *parent,
225 wxWizardPage *prev,
226 wxWizardPage *next)
227 : wxWizardPage(parent)
228 {
229 m_prev = prev;
230 m_next = next;
07f20d9a
VZ
231
232 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
233
234 mainSizer->Add(
235 new wxStaticText(this, -1, _T("Try checking the box below and\n")
236 _T("then going back and clearing it")),
237 0, // No vertical stretching
238 wxALL,
239 5 // Border width
240 );
74b31181 241
07f20d9a
VZ
242 m_checkbox = new wxCheckBox(this, -1, _T("&Skip the next page"));
243 mainSizer->Add(
244 m_checkbox,
245 0, // No vertical stretching
246 wxALL,
247 5 // Border width
248 );
249
250 SetSizer(mainSizer);
251 mainSizer->Fit(this);
74b31181
VZ
252 }
253
254 // implement wxWizardPage functions
255 virtual wxWizardPage *GetPrev() const { return m_prev; }
256 virtual wxWizardPage *GetNext() const
257 {
258 return m_checkbox->GetValue() ? m_next->GetNext() : m_next;
259 }
260
261private:
262 wxWizardPage *m_prev,
263 *m_next;
264
265 wxCheckBox *m_checkbox;
266};
267
66cd017c
VZ
268// ============================================================================
269// implementation
270// ============================================================================
271
d93c719a
VZ
272// ----------------------------------------------------------------------------
273// event tables and such
274// ----------------------------------------------------------------------------
275
276BEGIN_EVENT_TABLE(MyFrame, wxFrame)
277 EVT_MENU(Wizard_Quit, MyFrame::OnQuit)
278 EVT_MENU(Wizard_About, MyFrame::OnAbout)
279 EVT_MENU(Wizard_Run, MyFrame::OnRunWizard)
280
281 EVT_WIZARD_CANCEL(-1, MyFrame::OnWizardCancel)
8a7dfb14 282 EVT_WIZARD_FINISHED(-1, MyFrame::OnWizardFinished)
d93c719a
VZ
283END_EVENT_TABLE()
284
74b31181
VZ
285BEGIN_EVENT_TABLE(wxRadioboxPage, wxWizardPageSimple)
286 EVT_WIZARD_PAGE_CHANGING(-1, wxRadioboxPage::OnWizardPageChanging)
287 EVT_WIZARD_CANCEL(-1, wxRadioboxPage::OnWizardCancel)
288END_EVENT_TABLE()
289
d93c719a
VZ
290IMPLEMENT_APP(MyApp)
291
66cd017c
VZ
292// ----------------------------------------------------------------------------
293// the application class
294// ----------------------------------------------------------------------------
295
296// `Main program' equivalent: the program execution "starts" here
297bool MyApp::OnInit()
298{
9f84eccd 299 MyFrame *frame = new MyFrame(_T("wxWizard Sample"));
d93c719a
VZ
300
301 // and show it (the frames, unlike simple controls, are not shown when
302 // created initially)
303 frame->Show(TRUE);
304
305 // we're done
306 return TRUE;
307}
308
309// ----------------------------------------------------------------------------
310// MyFrame
311// ----------------------------------------------------------------------------
312
313MyFrame::MyFrame(const wxString& title)
314 : wxFrame((wxFrame *)NULL, -1, title,
315 wxDefaultPosition, wxSize(250, 150)) // small frame
316{
317 wxMenu *menuFile = new wxMenu;
9f84eccd 318 menuFile->Append(Wizard_Run, _T("&Run wizard...\tCtrl-R"));
d93c719a 319 menuFile->AppendSeparator();
9f84eccd 320 menuFile->Append(Wizard_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
d93c719a
VZ
321
322 wxMenu *helpMenu = new wxMenu;
9f84eccd 323 helpMenu->Append(Wizard_About, _T("&About...\tF1"), _T("Show about dialog"));
d93c719a
VZ
324
325 // now append the freshly created menu to the menu bar...
326 wxMenuBar *menuBar = new wxMenuBar();
9f84eccd
MB
327 menuBar->Append(menuFile, _T("&File"));
328 menuBar->Append(helpMenu, _T("&Help"));
66cd017c 329
d93c719a
VZ
330 // ... and attach this menu bar to the frame
331 SetMenuBar(menuBar);
332
333 // also create status bar which we use in OnWizardCancel
334 CreateStatusBar();
335}
336
337void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
338{
339 // TRUE is to force the frame to close
340 Close(TRUE);
341}
342
343void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
344{
9f84eccd
MB
345 wxMessageBox(_T("Demo of wxWizard class\n")
346