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