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