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