]>
git.saurik.com Git - wxWidgets.git/blob - samples/wizard/wiztest.cpp
69f137a4f516582fbe9f7fef7ec58ba0242cd01c
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindows sample demonstrating wxWizard control
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "wiztest.cpp"
22 #pragma interface "wiztest.cpp"
25 // For compilers that support precompilation, includes "wx/wx.h".
26 #include "wx/wxprec.h"
32 // for all others, include the necessary headers (this file is usually all you
33 // need because it includes almost all "standard" wxWindows headers
38 #include "wx/wizard.h"
41 #include "wiztest.xpm"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // Define a new application type, each program should derive a class from wxApp
49 class MyApp
: public wxApp
52 // override base class virtuals
53 virtual bool OnInit();
58 // ----------------------------------------------------------------------------
59 // some pages for our wizard
60 // ----------------------------------------------------------------------------
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
66 class wxValidationPage
: public wxWizardPageSimple
69 wxValidationPage(wxWizard
*parent
) : wxWizardPageSimple(parent
)
71 m_checkbox
= new wxCheckBox(this, -1, "&Check me");
74 virtual bool TransferDataFromWindow()
76 if ( !m_checkbox
->GetValue() )
78 wxMessageBox("Check the checkbox first!", "No way",
79 wxICON_WARNING
| wxOK
, this);
88 wxCheckBox
*m_checkbox
;
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
97 // directions in which we allow the user to proceed from this page
100 Forward
, Backward
, Both
, Neither
103 wxRadioboxPage(wxWizard
*parent
) : wxWizardPageSimple(parent
)
105 // should correspond to the enum above
106 static wxString choices
[] = { "forward", "backward", "both", "neither" };
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
);
115 // wizard event handlers
116 void OnWizardCancel(wxWizardEvent
& event
)
118 if ( wxMessageBox("Do you really want to cancel?", "Question",
119 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
)
126 void OnWizardPageChanging(wxWizardEvent
& event
)
128 int sel
= m_radio
->GetSelection();
133 if ( event
.GetDirection() && sel
== Forward
)
136 if ( !event
.GetDirection() && sel
== Backward
)
139 wxMessageBox("You can't go there", "Not allowed",
140 wxICON_WARNING
| wxOK
, this);
148 DECLARE_EVENT_TABLE()
151 // this shows how to dynamically (i.e. during run-time) arrange the page order
152 class wxCheckboxPage
: public wxWizardPage
155 wxCheckboxPage(wxWizard
*parent
,
158 : wxWizardPage(parent
)
163 (void)new wxStaticText(this, -1, "Try checking the box below and\n"
164 "then going back and clearing it");
166 m_checkbox
= new wxCheckBox(this, -1, "&Skip the next page",
170 // implement wxWizardPage functions
171 virtual wxWizardPage
*GetPrev() const { return m_prev
; }
172 virtual wxWizardPage
*GetNext() const
174 return m_checkbox
->GetValue() ? m_next
->GetNext() : m_next
;
178 wxWizardPage
*m_prev
,
181 wxCheckBox
*m_checkbox
;
184 // ============================================================================
186 // ============================================================================
188 BEGIN_EVENT_TABLE(wxRadioboxPage
, wxWizardPageSimple
)
189 EVT_WIZARD_PAGE_CHANGING(-1, wxRadioboxPage::OnWizardPageChanging
)
190 EVT_WIZARD_CANCEL(-1, wxRadioboxPage::OnWizardCancel
)
193 // ----------------------------------------------------------------------------
194 // the application class
195 // ----------------------------------------------------------------------------
197 // `Main program' equivalent: the program execution "starts" here
201 wxBitmap
bmpWizard("wiztest.bmp", wxBITMAP_TYPE_BMP
);
203 wxBitmap
bmpWizard(wizimage
);
206 wxWizard
*wizard
= wxWizard::Create(NULL
, -1,
207 "Absolutely Useless Wizard",
210 // a wizard page may be either an object of predefined class
211 wxWizardPageSimple
*page1
= new wxWizardPageSimple(wizard
);
212 (void)new wxStaticText(page1
, -1,
213 "This wizard doesn't help you to do anything at "
216 "The next pages will present you with more useless "
219 // ... or a derived class
220 wxRadioboxPage
*page3
= new wxRadioboxPage(wizard
);
221 wxValidationPage
*page4
= new wxValidationPage(wizard
);
223 // set the page order using a convenience function - could also use
224 // SetNext/Prev directly as below
225 wxWizardPageSimple::Chain(page3
, page4
);
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
);
233 if ( wizard
->RunWizard(page1
) )
235 wxMessageBox("The wizard successfully completed", "That's all",
236 wxICON_INFORMATION
| wxOK
);