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