]>
Commit | Line | Data |
---|---|---|
66cd017c | 1 | /////////////////////////////////////////////////////////////////////////////// |
94c09a19 | 2 | // Name: src/generic/wizard.cpp |
66cd017c VZ |
3 | // Purpose: generic implementation of wxWizard class |
4 | // Author: Vadim Zeitlin | |
a0a48a3f VZ |
5 | // Modified by: Robert Cavanaugh |
6 | // 1) Added capability for wxWizardPage to accept resources | |
7 | // 2) Added "Help" button handler stub | |
8 | // 3) Fixed ShowPage() bug on displaying bitmaps | |
07f20d9a | 9 | // Robert Vazan (sizers) |
66cd017c VZ |
10 | // Created: 15.08.99 |
11 | // RCS-ID: $Id$ | |
12 | // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 13 | // Licence: wxWindows licence |
66cd017c VZ |
14 | /////////////////////////////////////////////////////////////////////////////// |
15 | ||
16 | // ============================================================================ | |
17 | // declarations | |
18 | // ============================================================================ | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // headers | |
22 | // ---------------------------------------------------------------------------- | |
23 | ||
66cd017c VZ |
24 | // For compilers that support precompilation, includes "wx.h". |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
1e6feb95 VZ |
31 | #if wxUSE_WIZARDDLG |
32 | ||
66cd017c VZ |
33 | #ifndef WX_PRECOMP |
34 | #include "wx/dynarray.h" | |
35 | #include "wx/intl.h" | |
b87654f3 | 36 | #include "wx/statbmp.h" |
f6bcfd97 | 37 | #include "wx/button.h" |
9eddec69 | 38 | #include "wx/settings.h" |
ed2fbeb8 | 39 | #include "wx/sizer.h" |
66cd017c VZ |
40 | #endif //WX_PRECOMP |
41 | ||
42 | #include "wx/statline.h" | |
43 | ||
44 | #include "wx/wizard.h" | |
45 | ||
aedd6d6a VZ |
46 | // ---------------------------------------------------------------------------- |
47 | // wxWizardSizer | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | class wxWizardSizer : public wxSizer | |
51 | { | |
52 | public: | |
53 | wxWizardSizer(wxWizard *owner); | |
54 | ||
0a9ed8f1 VZ |
55 | virtual wxSizerItem *Insert(size_t index, wxSizerItem *item); |
56 | ||
88517d90 VZ |
57 | virtual void RecalcSizes(); |
58 | virtual wxSize CalcMin(); | |
aedd6d6a | 59 | |
88517d90 | 60 | // get the max size of all wizard pages |
aedd6d6a | 61 | wxSize GetMaxChildSize(); |
88517d90 VZ |
62 | |
63 | // return the border which can be either set using wxWizard::SetBorder() or | |
64 | // have default value | |
65 | int GetBorder() const; | |
ca65c044 | 66 | |
0a9ed8f1 VZ |
67 | // hide the pages which we temporarily "show" when they're added to this |
68 | // sizer (see Insert()) | |
69 | void HidePages(); | |
70 | ||
aedd6d6a VZ |
71 | private: |
72 | wxSize SiblingSize(wxSizerItem *child); | |
ca65c044 | 73 | |
aedd6d6a | 74 | wxWizard *m_owner; |
aedd6d6a VZ |
75 | wxSize m_childSize; |
76 | }; | |
77 | ||
66cd017c VZ |
78 | // ---------------------------------------------------------------------------- |
79 | // event tables and such | |
80 | // ---------------------------------------------------------------------------- | |
81 | ||
2e4df4bf VZ |
82 | DEFINE_EVENT_TYPE(wxEVT_WIZARD_PAGE_CHANGED) |
83 | DEFINE_EVENT_TYPE(wxEVT_WIZARD_PAGE_CHANGING) | |
84 | DEFINE_EVENT_TYPE(wxEVT_WIZARD_CANCEL) | |
1d30a0a1 | 85 | DEFINE_EVENT_TYPE(wxEVT_WIZARD_FINISHED) |
f80bf901 | 86 | DEFINE_EVENT_TYPE(wxEVT_WIZARD_HELP) |
2e4df4bf | 87 | |
74b31181 VZ |
88 | BEGIN_EVENT_TABLE(wxWizard, wxDialog) |
89 | EVT_BUTTON(wxID_CANCEL, wxWizard::OnCancel) | |
f80bf901 VZ |
90 | EVT_BUTTON(wxID_BACKWARD, wxWizard::OnBackOrNext) |
91 | EVT_BUTTON(wxID_FORWARD, wxWizard::OnBackOrNext) | |
92 | EVT_BUTTON(wxID_HELP, wxWizard::OnHelp) | |
91c68292 | 93 | |
ca65c044 WS |
94 | EVT_WIZARD_PAGE_CHANGED(wxID_ANY, wxWizard::OnWizEvent) |
95 | EVT_WIZARD_PAGE_CHANGING(wxID_ANY, wxWizard::OnWizEvent) | |
96 | EVT_WIZARD_CANCEL(wxID_ANY, wxWizard::OnWizEvent) | |
97 | EVT_WIZARD_FINISHED(wxID_ANY, wxWizard::OnWizEvent) | |
98 | EVT_WIZARD_HELP(wxID_ANY, wxWizard::OnWizEvent) | |
66cd017c VZ |
99 | END_EVENT_TABLE() |
100 | ||
74b31181 | 101 | IMPLEMENT_DYNAMIC_CLASS(wxWizard, wxDialog) |
066f1b7a SC |
102 | |
103 | /* | |
ca65c044 WS |
104 | TODO PROPERTIES : |
105 | wxWizard | |
106 | extstyle | |
107 | title | |
066f1b7a SC |
108 | */ |
109 | ||
74b31181 VZ |
110 | IMPLEMENT_ABSTRACT_CLASS(wxWizardPage, wxPanel) |
111 | IMPLEMENT_DYNAMIC_CLASS(wxWizardPageSimple, wxWizardPage) | |
66cd017c VZ |
112 | IMPLEMENT_DYNAMIC_CLASS(wxWizardEvent, wxNotifyEvent) |
113 | ||
114 | // ============================================================================ | |
115 | // implementation | |
116 | // ============================================================================ | |
117 | ||
74b31181 VZ |
118 | // ---------------------------------------------------------------------------- |
119 | // wxWizardPage | |
120 | // ---------------------------------------------------------------------------- | |
121 | ||
c7de4135 VS |
122 | void wxWizardPage::Init() |
123 | { | |
124 | m_bitmap = wxNullBitmap; | |
125 | } | |
126 | ||
a0a48a3f | 127 | wxWizardPage::wxWizardPage(wxWizard *parent, |
cf63f3d3 | 128 | const wxBitmap& bitmap) |
74b31181 | 129 | { |
cf63f3d3 | 130 | Create(parent, bitmap); |
c7de4135 | 131 | } |
91c68292 | 132 | |
c7de4135 | 133 | bool wxWizardPage::Create(wxWizard *parent, |
cf63f3d3 | 134 | const wxBitmap& bitmap) |
c7de4135 | 135 | { |
ca65c044 WS |
136 | if ( !wxPanel::Create(parent, wxID_ANY) ) |
137 | return false; | |
c7de4135 | 138 | |
636d266b | 139 | m_bitmap = bitmap; |
a0a48a3f | 140 | |
74b31181 VZ |
141 | // initially the page is hidden, it's shown only when it becomes current |
142 | Hide(); | |
91c68292 | 143 | |
ca65c044 | 144 | return true; |
74b31181 VZ |
145 | } |
146 | ||
147 | // ---------------------------------------------------------------------------- | |
148 | // wxWizardPageSimple | |
149 | // ---------------------------------------------------------------------------- | |
150 | ||
151 | wxWizardPage *wxWizardPageSimple::GetPrev() const | |
152 | { | |
153 | return m_prev; | |
154 | } | |
155 | ||
156 | wxWizardPage *wxWizardPageSimple::GetNext() const | |
157 | { | |
158 | return m_next; | |
159 | } | |
07f20d9a VZ |
160 | |
161 | // ---------------------------------------------------------------------------- | |
162 | // wxWizardSizer | |
163 | // ---------------------------------------------------------------------------- | |
164 | ||
07f20d9a | 165 | wxWizardSizer::wxWizardSizer(wxWizard *owner) |
0a089246 VZ |
166 | : m_owner(owner), |
167 | m_childSize(wxDefaultSize) | |
07f20d9a | 168 | { |
07f20d9a VZ |
169 | } |
170 | ||
0a9ed8f1 VZ |
171 | wxSizerItem *wxWizardSizer::Insert(size_t index, wxSizerItem *item) |
172 | { | |
0a089246 VZ |
173 | m_owner->m_usingSizer = true; |
174 | ||
0a9ed8f1 VZ |
175 | if ( item->IsWindow() ) |
176 | { | |
177 | // we must pretend that the window is shown as otherwise it wouldn't be | |
178 | // taken into account for the layout -- but avoid really showing it, so | |
179 | // just set the internal flag instead of calling wxWindow::Show() | |
180 | item->GetWindow()->wxWindowBase::Show(); | |
181 | } | |
182 | ||
183 | return wxSizer::Insert(index, item); | |
184 | } | |
185 | ||
186 | void wxWizardSizer::HidePages() | |
187 | { | |
188 | for ( wxSizerItemList::compatibility_iterator node = GetChildren().GetFirst(); | |
189 | node; | |
190 | node = node->GetNext() ) | |
191 | { | |
192 | wxSizerItem * const item = node->GetData(); | |
193 | if ( item->IsWindow() ) | |
194 | item->GetWindow()->wxWindowBase::Show(false); | |
195 | } | |
196 | } | |
197 | ||
07f20d9a VZ |
198 | void wxWizardSizer::RecalcSizes() |
199 | { | |
200 | // Effect of this function depends on m_owner->m_page and | |
201 | // it should be called whenever it changes (wxWizard::ShowPage) | |
202 | if ( m_owner->m_page ) | |
203 | { | |
0a089246 | 204 | m_owner->m_page->SetSize(wxRect(m_position, m_size)); |
07f20d9a VZ |
205 | } |
206 | } | |
207 | ||
208 | wxSize wxWizardSizer::CalcMin() | |
209 | { | |
210 | return m_owner->GetPageSize(); | |
211 | } | |
212 | ||
213 | wxSize wxWizardSizer::GetMaxChildSize() | |
214 | { | |
215 | #if !defined(__WXDEBUG__) | |
0a089246 | 216 | if ( m_childSize.IsFullySpecified() ) |
07f20d9a VZ |
217 | return m_childSize; |
218 | #endif | |
219 | ||
220 | wxSize maxOfMin; | |
07f20d9a | 221 | |
0a089246 VZ |
222 | for ( wxSizerItemList::compatibility_iterator childNode = m_children.GetFirst(); |
223 | childNode; | |
224 | childNode = childNode->GetNext() ) | |
07f20d9a VZ |
225 | { |
226 | wxSizerItem *child = childNode->GetData(); | |
227 | maxOfMin.IncTo(child->CalcMin()); | |
228 | maxOfMin.IncTo(SiblingSize(child)); | |
229 | } | |
230 | ||
231 | #ifdef __WXDEBUG__ | |
0a089246 | 232 | if ( m_childSize.IsFullySpecified() && m_childSize != maxOfMin ) |
07f20d9a VZ |
233 | { |
234 | wxFAIL_MSG( _T("Size changed in wxWizard::GetPageAreaSizer()") | |
235 | _T("after RunWizard().\n") | |
236 | _T("Did you forget to call GetSizer()->Fit(this) ") | |
237 | _T("for some page?")) ; | |
238 | ||
239 | return m_childSize; | |
240 | } | |
241 | #endif // __WXDEBUG__ | |
242 | ||
243 | if ( m_owner->m_started ) | |
244 | { | |
07f20d9a VZ |
245 | m_childSize = maxOfMin; |
246 | } | |
ca65c044 | 247 | |
07f20d9a VZ |
248 | return maxOfMin; |
249 | } | |
250 | ||
88517d90 | 251 | int wxWizardSizer::GetBorder() const |
07f20d9a | 252 | { |
0a089246 | 253 | return m_owner->m_border; |
07f20d9a VZ |
254 | } |
255 | ||
256 | wxSize wxWizardSizer::SiblingSize(wxSizerItem *child) | |
257 | { | |
258 | wxSize maxSibling; | |
ca65c044 | 259 | |
07f20d9a VZ |
260 | if ( child->IsWindow() ) |
261 | { | |
262 | wxWizardPage *page = wxDynamicCast(child->GetWindow(), wxWizardPage); | |
263 | if ( page ) | |
264 | { | |
265 | for ( wxWizardPage *sibling = page->GetNext(); | |
266 | sibling; | |
267 | sibling = sibling->GetNext() ) | |
268 | { | |
269 | if ( sibling->GetSizer() ) | |
270 | { | |
271 | maxSibling.IncTo(sibling->GetSizer()->CalcMin()); | |
272 | } | |
273 | } | |
274 | } | |
275 | } | |
ca65c044 | 276 | |
07f20d9a VZ |
277 | return maxSibling; |
278 | } | |
279 | ||
66cd017c VZ |
280 | // ---------------------------------------------------------------------------- |
281 | // generic wxWizard implementation | |
282 | // ---------------------------------------------------------------------------- | |
283 | ||
77436c4c JS |
284 | void wxWizard::Init() |
285 | { | |
286 | m_posWizard = wxDefaultPosition; | |
287 | m_page = (wxWizardPage *)NULL; | |
288 | m_btnPrev = m_btnNext = NULL; | |
289 | m_statbmp = NULL; | |
aedd6d6a | 290 | m_sizerBmpAndPage = NULL; |
07f20d9a | 291 | m_sizerPage = NULL; |
0a089246 | 292 | m_border = 5; |
07f20d9a | 293 | m_started = false; |
94c09a19 | 294 | m_wasModal = false; |
0a089246 | 295 | m_usingSizer = false; |
77436c4c JS |
296 | } |
297 | ||
298 | bool wxWizard::Create(wxWindow *parent, | |
aedd6d6a VZ |
299 | int id, |
300 | const wxString& title, | |
301 | const wxBitmap& bitmap, | |
302 | const wxPoint& pos, | |
303 | long style) | |
66cd017c | 304 | { |
07f20d9a | 305 | bool result = wxDialog::Create(parent,id,title,pos,wxDefaultSize,style); |
ca65c044 | 306 | |
77436c4c JS |
307 | m_posWizard = pos; |
308 | m_bitmap = bitmap ; | |
636d266b | 309 | |
07f20d9a | 310 | DoCreateControls(); |
ca65c044 | 311 | |
07f20d9a | 312 | return result; |
f6bcfd97 BP |
313 | } |
314 | ||
07f20d9a | 315 | void wxWizard::AddBitmapRow(wxBoxSizer *mainColumn) |
f6bcfd97 | 316 | { |
07f20d9a VZ |
317 | m_sizerBmpAndPage = new wxBoxSizer(wxHORIZONTAL); |
318 | mainColumn->Add( | |
319 | m_sizerBmpAndPage, | |
320 | 1, // Vertically stretchable | |
321 | wxEXPAND // Horizonal stretching, no border | |
322 | ); | |
323 | mainColumn->Add(0,5, | |
324 | 0, // No vertical stretching | |
325 | wxEXPAND // No border, (mostly useless) horizontal stretching | |
326 | ); | |
66cd017c | 327 | |
461dae94 | 328 | #if wxUSE_STATBMP |
f6bcfd97 | 329 | if ( m_bitmap.Ok() ) |
66cd017c | 330 | { |
ca65c044 | 331 | m_statbmp = new wxStaticBitmap(this, wxID_ANY, m_bitmap); |
07f20d9a VZ |
332 | m_sizerBmpAndPage->Add( |
333 | m_statbmp, | |
334 | 0, // No horizontal stretching | |
335 | wxALL, // Border all around, top alignment | |
336 | 5 // Border width | |
337 | ); | |
338 | m_sizerBmpAndPage->Add( | |
339 | 5,0, | |
340 | 0, // No horizontal stretching | |
341 | wxEXPAND // No border, (mostly useless) vertical stretching | |
342 | ); | |
66cd017c | 343 | } |
461dae94 | 344 | #endif |
f1df0927 | 345 | |
0a089246 | 346 | // Added to m_sizerBmpAndPage later |
07f20d9a VZ |
347 | m_sizerPage = new wxWizardSizer(this); |
348 | } | |
74b31181 | 349 | |
07f20d9a VZ |
350 | void wxWizard::AddStaticLine(wxBoxSizer *mainColumn) |
351 | { | |
74b31181 | 352 | #if wxUSE_STATLINE |
07f20d9a | 353 | mainColumn->Add( |
ca65c044 | 354 | new wxStaticLine(this, wxID_ANY), |
07f20d9a VZ |
355 | 0, // Vertically unstretchable |
356 | wxEXPAND | wxALL, // Border all around, horizontally stretchable | |
357 | 5 // Border width | |
358 | ); | |
359 | mainColumn->Add(0,5, | |
360 | 0, // No vertical stretching | |
361 | wxEXPAND // No border, (mostly useless) horizontal stretching | |
362 | ); | |
363 | #else | |
364 | (void)mainColumn; | |
f6bcfd97 | 365 | #endif // wxUSE_STATLINE |
07f20d9a | 366 | } |
74b31181 | 367 | |
07f20d9a VZ |
368 | void wxWizard::AddBackNextPair(wxBoxSizer *buttonRow) |
369 | { | |
54cf600d VZ |
370 | wxASSERT_MSG( m_btnNext && m_btnPrev, |
371 | _T("You must create the buttons before calling ") | |
372 | _T("wxWizard::AddBackNextPair") ); | |
373 | ||
07f20d9a VZ |
374 | // margin between Back and Next buttons |
375 | #ifdef __WXMAC__ | |
376 | static const int BACKNEXT_MARGIN = 10; | |
377 | #else | |
378 | static const int BACKNEXT_MARGIN = 0; | |
379 | #endif | |
66cd017c | 380 | |
07f20d9a VZ |
381 | wxBoxSizer *backNextPair = new wxBoxSizer(wxHORIZONTAL); |
382 | buttonRow->Add( | |
383 | backNextPair, | |
384 | 0, // No horizontal stretching | |
385 | wxALL, // Border all around | |
386 | 5 // Border width | |
387 | ); | |
ca65c044 | 388 | |
07f20d9a VZ |
389 | backNextPair->Add(m_btnPrev); |
390 | backNextPair->Add(BACKNEXT_MARGIN,0, | |
391 | 0, // No horizontal stretching | |
392 | wxEXPAND // No border, (mostly useless) vertical stretching | |
393 | ); | |
07f20d9a VZ |
394 | backNextPair->Add(m_btnNext); |
395 | } | |
66cd017c | 396 | |
07f20d9a VZ |
397 | void wxWizard::AddButtonRow(wxBoxSizer *mainColumn) |
398 | { | |
9473e9a4 VZ |
399 | // the order in which the buttons are created determines the TAB order - at least under MSWindows... |
400 | // although the 'back' button appears before the 'next' button, a more userfriendly tab order is | |
401 | // to activate the 'next' button first (create the next button before the back button). | |
402 | // The reason is: The user will repeatedly enter information in the wizard pages and then wants to | |
403 | // press 'next'. If a user uses mostly the keyboard, he would have to skip the 'back' button | |
404 | // everytime. This is annoying. There is a second reason: RETURN acts as TAB. If the 'next' | |
405 | // button comes first in the TAB order, the user can enter information very fast using the RETURN | |
406 | // key to TAB to the next entry field and page. This would not be possible, if the 'back' button | |
407 | // was created before the 'next' button. | |
408 | ||
a6328131 | 409 | bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
94c09a19 | 410 | int buttonStyle = isPda ? wxBU_EXACTFIT : 0; |
a6328131 | 411 | |
07f20d9a | 412 | wxBoxSizer *buttonRow = new wxBoxSizer(wxHORIZONTAL); |
977a3818 JS |
413 | #ifdef __WXMAC__ |
414 | if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON) | |
415 | mainColumn->Add( | |
416 | buttonRow, | |
417 | 0, // Vertically unstretchable | |
418 | wxGROW|wxALIGN_CENTRE | |
419 | ); | |
420 | else | |
421 | #endif | |
07f20d9a VZ |
422 | mainColumn->Add( |
423 | buttonRow, | |
424 | 0, // Vertically unstretchable | |
425 | wxALIGN_RIGHT // Right aligned, no border | |
426 | ); | |
66cd017c | 427 | |
9473e9a4 VZ |
428 | // Desired TAB order is 'next', 'cancel', 'help', 'back'. This makes the 'back' button the last control on the page. |
429 | // Create the buttons in the right order... | |
977a3818 JS |
430 | wxButton *btnHelp=0; |
431 | #ifdef __WXMAC__ | |
432 | if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON) | |
a6328131 | 433 | btnHelp=new wxButton(this, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, buttonStyle); |
977a3818 JS |
434 | #endif |
435 | ||
9473e9a4 | 436 | m_btnNext = new wxButton(this, wxID_FORWARD, _("&Next >")); |
a6328131 | 437 | wxButton *btnCancel=new wxButton(this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, buttonStyle); |
977a3818 | 438 | #ifndef __WXMAC__ |
07f20d9a | 439 | if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON) |
a6328131 | 440 | btnHelp=new wxButton(this, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, buttonStyle); |
977a3818 | 441 | #endif |
a6328131 | 442 | m_btnPrev = new wxButton(this, wxID_BACKWARD, _("< &Back"), wxDefaultPosition, wxDefaultSize, buttonStyle); |
9473e9a4 VZ |
443 | |
444 | if (btnHelp) | |
977a3818 | 445 | { |
07f20d9a | 446 | buttonRow->Add( |
9473e9a4 | 447 | btnHelp, |
07f20d9a VZ |
448 | 0, // Horizontally unstretchable |
449 | wxALL, // Border all around, top aligned | |
450 | 5 // Border width | |
977a3818 JS |
451 | ); |
452 | #ifdef __WXMAC__ | |
453 | // Put stretchable space between help button and others | |
454 | buttonRow->Add(0, 0, 1, wxALIGN_CENTRE, 0); | |
455 | #endif | |
456 | } | |
07f20d9a VZ |
457 | |
458 | AddBackNextPair(buttonRow); | |
ca65c044 | 459 | |
07f20d9a | 460 | buttonRow->Add( |
9473e9a4 | 461 | btnCancel, |
07f20d9a VZ |
462 | 0, // Horizontally unstretchable |
463 | wxALL, // Border all around, top aligned | |
464 | 5 // Border width | |
465 | ); | |
466 | } | |
66cd017c | 467 | |
07f20d9a VZ |
468 | void wxWizard::DoCreateControls() |
469 | { | |
470 | // do nothing if the controls were already created | |
471 | if ( WasCreated() ) | |
472 | return; | |
ca65c044 | 473 | |
a6328131 | 474 | bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
94c09a19 | 475 | |
a6328131 JS |
476 | // Horizontal stretching, and if not PDA, border all around |
477 | int mainColumnSizerFlags = isPda ? wxEXPAND : wxALL|wxEXPAND ; | |
94c09a19 | 478 | |
07f20d9a VZ |
479 | // wxWindow::SetSizer will be called at end |
480 | wxBoxSizer *windowSizer = new wxBoxSizer(wxVERTICAL); | |
ca65c044 | 481 | |
07f20d9a VZ |
482 | wxBoxSizer *mainColumn = new wxBoxSizer(wxVERTICAL); |
483 | windowSizer->Add( | |
484 | mainColumn, | |
485 | 1, // Vertical stretching | |
a6328131 | 486 | mainColumnSizerFlags, |
07f20d9a VZ |
487 | 5 // Border width |
488 | ); | |
ca65c044 | 489 | |
07f20d9a | 490 | AddBitmapRow(mainColumn); |
94c09a19 | 491 | |
a6328131 JS |
492 | if (!isPda) |
493 | AddStaticLine(mainColumn); | |
94c09a19 | 494 | |
07f20d9a | 495 | AddButtonRow(mainColumn); |
ca65c044 | 496 | |
07f20d9a | 497 | SetSizer(windowSizer); |
66cd017c VZ |
498 | } |
499 | ||
f6bcfd97 BP |
500 | void wxWizard::SetPageSize(const wxSize& size) |
501 | { | |
0a089246 | 502 | wxCHECK_RET(!m_started, wxT("wxWizard::SetPageSize after RunWizard")); |
f6bcfd97 BP |
503 | m_sizePage = size; |
504 | } | |
505 | ||
07f20d9a VZ |
506 | void wxWizard::FitToPage(const wxWizardPage *page) |
507 | { | |
0a089246 | 508 | wxCHECK_RET(!m_started, wxT("wxWizard::FitToPage after RunWizard")); |
ca65c044 | 509 | |
c73b439f VZ |
510 | while ( page ) |
511 | { | |
512 | wxSize size = page->GetBestSize(); | |
513 | ||
07f20d9a | 514 | m_sizePage.IncTo(size); |
c73b439f VZ |
515 | |
516 | page = page->GetNext(); | |
517 | } | |
c73b439f VZ |
518 | } |
519 | ||
74b31181 | 520 | bool wxWizard::ShowPage(wxWizardPage *page, bool goingForward) |
66cd017c | 521 | { |
223d09f6 | 522 | wxASSERT_MSG( page != m_page, wxT("this is useless") ); |
66cd017c | 523 | |
0a089246 VZ |
524 | wxSizerFlags flags(1); |
525 | flags.Border(wxALL, m_border).Expand(); | |
526 | ||
527 | if ( !m_started ) | |
528 | { | |
529 | if ( m_usingSizer ) | |
530 | { | |
531 | m_sizerBmpAndPage->Add(m_sizerPage, flags); | |
532 | ||
533 | // now that our layout is computed correctly, hide the pages | |
534 | // artificially shown in wxWizardSizer::Insert() back again | |
535 | m_sizerPage->HidePages(); | |
536 | } | |
537 | } | |
538 | ||
539 | ||
74b31181 VZ |
540 | // we'll use this to decide whether we have to change the label of this |
541 | // button or not (initially the label is "Next") | |
ca65c044 | 542 | bool btnLabelWasNext = true; |
66cd017c | 543 | |
0a089246 VZ |
544 | // remember the old bitmap (if any) to compare with the new one later |
545 | wxBitmap bmpPrev; | |
7cc5041d VZ |
546 | |
547 | // check for previous page | |
74b31181 | 548 | if ( m_page ) |
66cd017c | 549 | { |
74b31181 | 550 | // send the event to the old page |
0a089246 VZ |
551 | wxWizardEvent event(wxEVT_WIZARD_PAGE_CHANGING, GetId(), |
552 | goingForward, m_page); | |
74b31181 VZ |
553 | if ( m_page->GetEventHandler()->ProcessEvent(event) && |
554 | !event.IsAllowed() ) | |
555 | { | |
556 | // vetoed by the page | |
ca65c044 | 557 | return false; |
74b31181 | 558 | } |
66cd017c | 559 | |
74b31181 VZ |
560 | m_page->Hide(); |
561 | ||
2b5f62a0 | 562 | btnLabelWasNext = HasNextPage(m_page); |
7cc5041d | 563 | |
0a089246 VZ |
564 | bmpPrev = m_page->GetBitmap(); |
565 | ||
566 | if ( !m_usingSizer ) | |
567 | m_sizerBmpAndPage->Detach(m_page); | |
dee5b92f | 568 | } |
66cd017c | 569 | |
7cc5041d | 570 | // set the new page |
66cd017c | 571 | m_page = page; |
66cd017c | 572 | |
74b31181 VZ |
573 | // is this the end? |
574 | if ( !m_page ) | |
66cd017c | 575 | { |
74b31181 | 576 | // terminate successfully |
0a089246 | 577 | if ( IsModal() ) |
b3eb133b WS |
578 | { |
579 | EndModal(wxID_OK); | |
580 | } | |
581 | else | |
582 | { | |
583 | SetReturnCode(wxID_OK); | |
584 | Hide(); | |
585 | } | |
64c2fa13 VZ |
586 | |
587 | // and notify the user code (this is especially useful for modeless | |
588 | // wizards) | |
ca65c044 | 589 | wxWizardEvent event(wxEVT_WIZARD_FINISHED, GetId(), false, 0); |
64c2fa13 VZ |
590 | (void)GetEventHandler()->ProcessEvent(event); |
591 | ||
ca65c044 | 592 | return true; |
74b31181 | 593 | } |
66cd017c | 594 | |
74b31181 VZ |
595 | // position and show the new page |
596 | (void)m_page->TransferDataToWindow(); | |
ca65c044 | 597 | |
0a089246 | 598 | if ( m_usingSizer ) |
7cc5041d | 599 | { |
0a089246 VZ |
600 | // wxWizardSizer::RecalcSizes wants to be called when m_page changes |
601 | m_sizerPage->RecalcSizes(); | |
602 | } | |
603 | else // pages are not managed by the sizer | |
604 | { | |
605 | m_sizerBmpAndPage->Add(m_page, flags); | |
606 | m_sizerBmpAndPage->SetItemMinSize(m_page, GetPageSize()); | |
7cc5041d VZ |
607 | } |
608 | ||
461dae94 | 609 | #if wxUSE_STATBMP |
0a089246 VZ |
610 | // update the bitmap if:it changed |
611 | if ( m_statbmp ) | |
f1df0927 | 612 | { |
0a089246 VZ |
613 | wxBitmap bmp = m_page->GetBitmap(); |
614 | if ( !bmp.Ok() ) | |
cfd88569 | 615 | bmp = m_bitmap; |
0a089246 VZ |
616 | |
617 | if ( !bmpPrev.Ok() ) | |
618 | bmpPrev = m_bitmap; | |
619 | ||
a3ab1c18 | 620 | if ( !bmp.IsSameAs(bmpPrev) ) |
0a089246 | 621 | m_statbmp->SetBitmap(bmp); |
f1df0927 | 622 | } |
0a089246 VZ |
623 | #endif // wxUSE_STATBMP |
624 | ||
f1df0927 | 625 | |
74b31181 | 626 | // and update the buttons state |
2b5f62a0 | 627 | m_btnPrev->Enable(HasPrevPage(m_page)); |
66cd017c | 628 | |
2b5f62a0 | 629 | bool hasNext = HasNextPage(m_page); |
8f177c8e | 630 | if ( btnLabelWasNext != hasNext ) |
66cd017c | 631 | { |
c9f78968 VS |
632 | if ( hasNext ) |
633 | m_btnNext->SetLabel(_("&Next >")); | |
634 | else | |
635 | m_btnNext->SetLabel(_("&Finish")); | |
66cd017c | 636 | } |
74b31181 | 637 | // nothing to do: the label was already correct |
66cd017c | 638 | |
0a089246 VZ |
639 | m_btnNext->SetDefault(); |
640 | ||
641 | ||
5bc28e84 | 642 | // send the change event to the new page now |
2365e5cb | 643 | wxWizardEvent event(wxEVT_WIZARD_PAGE_CHANGED, GetId(), goingForward, m_page); |
5bc28e84 VZ |
644 | (void)m_page->GetEventHandler()->ProcessEvent(event); |
645 | ||
646 | // and finally show it | |
647 | m_page->Show(); | |
648 | m_page->SetFocus(); | |
649 | ||
0a089246 VZ |
650 | if ( !m_usingSizer ) |
651 | m_sizerBmpAndPage->Layout(); | |
652 | ||
653 | if ( !m_started ) | |
654 | { | |
655 | m_started = true; | |
656 | ||
657 | if ( wxSystemSettings::GetScreenType() > wxSYS_SCREEN_PDA ) | |
658 | { | |
659 | GetSizer()->SetSizeHints(this); | |
660 | if ( m_posWizard == wxDefaultPosition ) | |
661 | CentreOnScreen(); | |
662 | } | |
663 | } | |
664 | ||
ca65c044 | 665 | return true; |
66cd017c VZ |
666 | } |
667 | ||
74b31181 | 668 | bool wxWizard::RunWizard(wxWizardPage *firstPage) |
66cd017c | 669 | { |
ca65c044 WS |
670 | wxCHECK_MSG( firstPage, false, wxT("can't run empty wizard") ); |
671 | ||
ca65c044 WS |
672 | // can't return false here because there is no old page |
673 | (void)ShowPage(firstPage, true /* forward */); | |
66cd017c | 674 | |
94c09a19 | 675 | m_wasModal = true; |
37f6a080 | 676 | |
66cd017c VZ |
677 | return ShowModal() == wxID_OK; |
678 | } | |
679 | ||
74b31181 | 680 | wxWizardPage *wxWizard::GetCurrentPage() const |
66cd017c | 681 | { |
74b31181 | 682 | return m_page; |
66cd017c VZ |
683 | } |
684 | ||
4fe5383d | 685 | wxSize wxWizard::GetPageSize() const |
07f20d9a VZ |
686 | { |
687 | // default width and height of the page | |
0a089246 VZ |
688 | int DEFAULT_PAGE_WIDTH, |
689 | DEFAULT_PAGE_HEIGHT; | |
690 | if ( wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA ) | |
a6328131 JS |
691 | { |
692 | // Make the default page size small enough to fit on screen | |
693 | DEFAULT_PAGE_WIDTH = wxSystemSettings::GetMetric(wxSYS_SCREEN_X) / 2; | |
694 | DEFAULT_PAGE_HEIGHT = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y) / 2; | |
695 | } | |
0a089246 VZ |
696 | else // !PDA |
697 | { | |
698 | DEFAULT_PAGE_WIDTH = | |
699 | DEFAULT_PAGE_HEIGHT = 270; | |
700 | } | |
94c09a19 | 701 | |
0a089246 VZ |
702 | // start with default minimal size |
703 | wxSize pageSize(DEFAULT_PAGE_WIDTH, DEFAULT_PAGE_HEIGHT); | |
ca65c044 | 704 | |
0a089246 VZ |
705 | // make the page at least as big as specified by user |
706 | pageSize.IncTo(m_sizePage); | |
ca65c044 | 707 | |
aedd6d6a VZ |
708 | if ( m_statbmp ) |
709 | { | |
0a089246 VZ |
710 | // make the page at least as tall as the bitmap |
711 | pageSize.IncTo(wxSize(0, m_bitmap.GetHeight())); | |
aedd6d6a | 712 | } |
ca65c044 | 713 | |
0a089246 VZ |
714 | if ( m_usingSizer ) |
715 | { | |
716 | // make it big enough to contain all pages added to the sizer | |
717 | pageSize.IncTo(m_sizerPage->GetMaxChildSize()); | |
718 | } | |
719 | ||
720 | return pageSize; | |
721 | } | |
722 | ||
723 | wxSizer *wxWizard::GetPageAreaSizer() const | |
724 | { | |
725 | return m_sizerPage; | |
726 | } | |
727 | ||
728 | void wxWizard::SetBorder(int border) | |
729 | { | |
730 | wxCHECK_RET(!m_started, wxT("wxWizard::SetBorder after RunWizard")); | |
731 | ||
732 | m_border = border; | |
4fe5383d VZ |
733 | } |
734 | ||
20f18ea1 | 735 | void wxWizard::OnCancel(wxCommandEvent& WXUNUSED(eventUnused)) |
66cd017c | 736 | { |
74b31181 VZ |
737 | // this function probably can never be called when we don't have an active |
738 | // page, but a small extra check won't hurt | |
739 | wxWindow *win = m_page ? (wxWindow *)m_page : (wxWindow *)this; | |
740 | ||
ca65c044 | 741 | wxWizardEvent event(wxEVT_WIZARD_CANCEL, GetId(), false, m_page); |
74b31181 | 742 | if ( !win->GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) |
66cd017c VZ |
743 | { |
744 | // no objections - close the dialog | |
b3eb133b WS |
745 | if(IsModal()) |
746 | { | |
747 | EndModal(wxID_CANCEL); | |
748 | } | |
749 | else | |
750 | { | |
751 | SetReturnCode(wxID_CANCEL); | |
752 | Hide(); | |
753 | } | |
66cd017c VZ |
754 | } |
755 | //else: request to Cancel ignored | |
756 | } | |
757 | ||
74b31181 | 758 | void wxWizard::OnBackOrNext(wxCommandEvent& event) |
66cd017c VZ |
759 | { |
760 | wxASSERT_MSG( (event.GetEventObject() == m_btnNext) || | |
761 | (event.GetEventObject() == m_btnPrev), | |
223d09f6 | 762 | wxT("unknown button") ); |
66cd017c | 763 | |
47e64664 VZ |
764 | wxCHECK_RET( m_page, _T("should have a valid current page") ); |
765 | ||
f6bcfd97 BP |
766 | // ask the current page first: notice that we do it before calling |
767 | // GetNext/Prev() because the data transfered from the controls of the page | |
768 | // may change the value returned by these methods | |
47e64664 | 769 | if ( !m_page->Validate() || !m_page->TransferDataFromWindow() ) |
f6bcfd97 BP |
770 | { |
771 | // the page data is incorrect, don't do anything | |
772 | return; | |
773 | } | |
774 | ||
74b31181 | 775 | bool forward = event.GetEventObject() == m_btnNext; |
66cd017c | 776 | |
74b31181 VZ |
777 | wxWizardPage *page; |
778 | if ( forward ) | |
66cd017c | 779 | { |
74b31181 | 780 | page = m_page->GetNext(); |
66cd017c | 781 | } |
74b31181 | 782 | else // back |
66cd017c | 783 | { |
74b31181 VZ |
784 | page = m_page->GetPrev(); |
785 | ||
223d09f6 | 786 | wxASSERT_MSG( page, wxT("\"<Back\" button should have been disabled") ); |
66cd017c | 787 | } |
74b31181 | 788 | |
0a089246 | 789 | // just pass to the new page (or maybe not - but we don't care here) |
74b31181 | 790 | (void)ShowPage(page, forward); |
66cd017c VZ |
791 | } |
792 | ||
f80bf901 VZ |
793 | void wxWizard::OnHelp(wxCommandEvent& WXUNUSED(event)) |
794 | { | |
795 | // this function probably can never be called when we don't have an active | |
796 | // page, but a small extra check won't hurt | |
797 | if(m_page != NULL) | |
798 | { | |
799 | // Create and send the help event to the specific page handler | |
800 | // event data contains the active page so that context-sensitive | |
801 | // help is possible | |
ca65c044 | 802 | wxWizardEvent eventHelp(wxEVT_WIZARD_HELP, GetId(), true, m_page); |
f80bf901 VZ |
803 | (void)m_page->GetEventHandler()->ProcessEvent(eventHelp); |
804 | } | |
805 | } | |
806 | ||
91c68292 VZ |
807 | void wxWizard::OnWizEvent(wxWizardEvent& event) |
808 | { | |
809 | // the dialogs have wxWS_EX_BLOCK_EVENTS style on by default but we want to | |
810 | // propagate wxEVT_WIZARD_XXX to the parent (if any), so do it manually | |
811 | if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) ) | |
812 | { | |
813 | // the event will be propagated anyhow | |
0a640208 | 814 | event.Skip(); |
91c68292 | 815 | } |
b3eb133b WS |
816 | else |
817 | { | |
818 | wxWindow *parent = GetParent(); | |
91c68292 | 819 | |
b3eb133b WS |
820 | if ( !parent || !parent->GetEventHandler()->ProcessEvent(event) ) |
821 | { | |
822 | event.Skip(); | |
823 | } | |
824 | } | |
37f6a080 | 825 | |
94c09a19 | 826 | if ( ( !m_wasModal ) && |
37f6a080 JS |
827 | event.IsAllowed() && |
828 | ( event.GetEventType() == wxEVT_WIZARD_FINISHED || | |
829 | event.GetEventType() == wxEVT_WIZARD_CANCEL | |
830 | ) | |
831 | ) | |
832 | { | |
37f6a080 JS |
833 | Destroy(); |
834 | } | |
91c68292 | 835 | } |
f80bf901 | 836 | |
66cd017c VZ |
837 | // ---------------------------------------------------------------------------- |
838 | // wxWizardEvent | |
839 | // ---------------------------------------------------------------------------- | |
840 | ||
f80bf901 | 841 | wxWizardEvent::wxWizardEvent(wxEventType type, int id, bool direction, wxWizardPage* page) |
66cd017c VZ |
842 | : wxNotifyEvent(type, id) |
843 | { | |
f80bf901 VZ |
844 | // Modified 10-20-2001 Robert Cavanaugh |
845 | // add the active page to the event data | |
74b31181 | 846 | m_direction = direction; |
f80bf901 | 847 | m_page = page; |
66cd017c | 848 | } |
74b31181 | 849 | |
1e6feb95 | 850 | #endif // wxUSE_WIZARDDLG |