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