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