]> git.saurik.com Git - wxWidgets.git/blob - src/generic/wizard.cpp
avoid hidden GetImageList
[wxWidgets.git] / src / generic / wizard.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/wizard.cpp
3 // Purpose: generic implementation of wxWizard class
4 // Author: Vadim Zeitlin
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
9 // Robert Vazan (sizers)
10 // Created: 15.08.99
11 // RCS-ID: $Id$
12 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
13 // Licence: wxWindows licence
14 ///////////////////////////////////////////////////////////////////////////////
15
16 // ============================================================================
17 // declarations
18 // ============================================================================
19
20 // ----------------------------------------------------------------------------
21 // headers
22 // ----------------------------------------------------------------------------
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_WIZARDDLG
32
33 #ifndef WX_PRECOMP
34 #include "wx/dynarray.h"
35 #include "wx/intl.h"
36 #include "wx/statbmp.h"
37 #include "wx/button.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/statline.h"
41 #include "wx/sizer.h"
42 #include "wx/settings.h"
43
44 #include "wx/wizard.h"
45
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;
60
61 private:
62 wxSize SiblingSize(wxSizerItem *child);
63
64 wxWizard *m_owner;
65 bool m_childSizeValid;
66 wxSize m_childSize;
67 };
68
69 // ----------------------------------------------------------------------------
70 // event tables and such
71 // ----------------------------------------------------------------------------
72
73 DEFINE_EVENT_TYPE(wxEVT_WIZARD_PAGE_CHANGED)
74 DEFINE_EVENT_TYPE(wxEVT_WIZARD_PAGE_CHANGING)
75 DEFINE_EVENT_TYPE(wxEVT_WIZARD_CANCEL)
76 DEFINE_EVENT_TYPE(wxEVT_WIZARD_FINISHED)
77 DEFINE_EVENT_TYPE(wxEVT_WIZARD_HELP)
78
79 BEGIN_EVENT_TABLE(wxWizard, wxDialog)
80 EVT_BUTTON(wxID_CANCEL, wxWizard::OnCancel)
81 EVT_BUTTON(wxID_BACKWARD, wxWizard::OnBackOrNext)
82 EVT_BUTTON(wxID_FORWARD, wxWizard::OnBackOrNext)
83 EVT_BUTTON(wxID_HELP, wxWizard::OnHelp)
84
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)
90 END_EVENT_TABLE()
91
92 IMPLEMENT_DYNAMIC_CLASS(wxWizard, wxDialog)
93
94 /*
95 TODO PROPERTIES :
96 wxWizard
97 extstyle
98 title
99 */
100
101 IMPLEMENT_ABSTRACT_CLASS(wxWizardPage, wxPanel)
102 IMPLEMENT_DYNAMIC_CLASS(wxWizardPageSimple, wxWizardPage)
103 IMPLEMENT_DYNAMIC_CLASS(wxWizardEvent, wxNotifyEvent)
104
105 // ============================================================================
106 // implementation
107 // ============================================================================
108
109 // ----------------------------------------------------------------------------
110 // wxWizardPage
111 // ----------------------------------------------------------------------------
112
113 void wxWizardPage::Init()
114 {
115 m_bitmap = wxNullBitmap;
116 }
117
118 wxWizardPage::wxWizardPage(wxWizard *parent,
119 const wxBitmap& bitmap,
120 const wxChar *resource)
121 {
122 Create(parent, bitmap, resource);
123 }
124
125 bool wxWizardPage::Create(wxWizard *parent,
126 const wxBitmap& bitmap,
127 const wxChar *resource)
128 {
129 if ( !wxPanel::Create(parent, wxID_ANY) )
130 return false;
131
132 if ( resource != NULL )
133 {
134 #if wxUSE_WX_RESOURCES
135 #if 0
136 if ( !LoadFromResource(this, resource) )
137 {
138 wxFAIL_MSG(wxT("wxWizardPage LoadFromResource failed!!!!"));
139 }
140 #endif
141 #endif // wxUSE_RESOURCES
142 }
143
144 m_bitmap = bitmap;
145
146 // initially the page is hidden, it's shown only when it becomes current
147 Hide();
148
149 return true;
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 }
165
166 // ----------------------------------------------------------------------------
167 // wxWizardSizer
168 // ----------------------------------------------------------------------------
169
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;
199 wxSizerItemList::compatibility_iterator childNode;
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 }
226
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;
241
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 }
258
259 return maxSibling;
260 }
261
262 // ----------------------------------------------------------------------------
263 // generic wxWizard implementation
264 // ----------------------------------------------------------------------------
265
266 void wxWizard::Init()
267 {
268 m_posWizard = wxDefaultPosition;
269 m_page = (wxWizardPage *)NULL;
270 m_btnPrev = m_btnNext = NULL;
271 m_statbmp = NULL;
272 m_sizerBmpAndPage = NULL;
273 m_sizerPage = NULL;
274 m_calledSetBorder = false;
275 m_border = 0;
276 m_started = false;
277 m_wasModal = false;
278 }
279
280 bool wxWizard::Create(wxWindow *parent,
281 int id,
282 const wxString& title,
283 const wxBitmap& bitmap,
284 const wxPoint& pos,
285 long style)
286 {
287 bool result = wxDialog::Create(parent,id,title,pos,wxDefaultSize,style);
288
289 m_posWizard = pos;
290 m_bitmap = bitmap ;
291
292 DoCreateControls();
293
294 return result;
295 }
296
297 void wxWizard::AddBitmapRow(wxBoxSizer *mainColumn)
298 {
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 );
309
310 #if wxUSE_STATBMP
311 if ( m_bitmap.Ok() )
312 {
313 m_statbmp = new wxStaticBitmap(this, wxID_ANY, m_bitmap);
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 );
325 }
326 #endif
327
328 // Added to m_sizerBmpAndPage in FinishLayout
329 m_sizerPage = new wxWizardSizer(this);
330 }
331
332 void wxWizard::AddStaticLine(wxBoxSizer *mainColumn)
333 {
334 #if wxUSE_STATLINE
335 mainColumn->Add(
336 new wxStaticLine(this, wxID_ANY),
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;
347 #endif // wxUSE_STATLINE
348 }
349
350 void wxWizard::AddBackNextPair(wxBoxSizer *buttonRow)
351 {
352 wxASSERT_MSG( m_btnNext && m_btnPrev,
353 _T("You must create the buttons before calling ")
354 _T("wxWizard::AddBackNextPair") );
355
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
362
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 );
370
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 );
376 backNextPair->Add(m_btnNext);
377 }
378
379 void wxWizard::AddButtonRow(wxBoxSizer *mainColumn)
380 {
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
391 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
392 int buttonStyle = isPda ? wxBU_EXACTFIT : 0;
393
394 wxBoxSizer *buttonRow = new wxBoxSizer(wxHORIZONTAL);
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
404 mainColumn->Add(
405 buttonRow,
406 0, // Vertically unstretchable
407 wxALIGN_RIGHT // Right aligned, no border
408 );
409
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...
412 wxButton *btnHelp=0;
413 #ifdef __WXMAC__
414 if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON)
415 btnHelp=new wxButton(this, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, buttonStyle);
416 #endif
417
418 m_btnNext = new wxButton(this, wxID_FORWARD, _("&Next >"));
419 wxButton *btnCancel=new wxButton(this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, buttonStyle);
420 #ifndef __WXMAC__
421 if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON)
422 btnHelp=new wxButton(this, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, buttonStyle);
423 #endif
424 m_btnPrev = new wxButton(this, wxID_BACKWARD, _("< &Back"), wxDefaultPosition, wxDefaultSize, buttonStyle);
425
426 if (btnHelp)
427 {
428 buttonRow->Add(
429 btnHelp,
430 0, // Horizontally unstretchable
431 wxALL, // Border all around, top aligned
432 5 // Border width
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 }
439
440 AddBackNextPair(buttonRow);
441
442 buttonRow->Add(
443 btnCancel,
444 0, // Horizontally unstretchable
445 wxALL, // Border all around, top aligned
446 5 // Border width
447 );
448 }
449
450 void wxWizard::DoCreateControls()
451 {
452 // do nothing if the controls were already created
453 if ( WasCreated() )
454 return;
455
456 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
457
458 // Horizontal stretching, and if not PDA, border all around
459 int mainColumnSizerFlags = isPda ? wxEXPAND : wxALL|wxEXPAND ;
460
461 // wxWindow::SetSizer will be called at end
462 wxBoxSizer *windowSizer = new wxBoxSizer(wxVERTICAL);
463
464 wxBoxSizer *mainColumn = new wxBoxSizer(wxVERTICAL);
465 windowSizer->Add(
466 mainColumn,
467 1, // Vertical stretching
468 mainColumnSizerFlags,
469 5 // Border width
470 );
471
472 AddBitmapRow(mainColumn);
473
474 if (!isPda)
475 AddStaticLine(mainColumn);
476
477 AddButtonRow(mainColumn);
478
479 // wxWindow::SetSizer should be followed by wxWindow::Fit, but
480 // this is done in FinishLayout anyway so why duplicate it
481 SetSizer(windowSizer);
482 }
483
484 void wxWizard::SetPageSize(const wxSize& size)
485 {
486 wxCHECK_RET(!m_started,wxT("wxWizard::SetPageSize after RunWizard"));
487 m_sizePage = size;
488 }
489
490 void wxWizard::FinishLayout()
491 {
492 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
493
494 // Set to enable wxWizardSizer::GetMaxChildSize
495 m_started = true;
496
497 m_sizerBmpAndPage->Add(
498 m_sizerPage,
499 1, // Horizontal stretching
500 wxEXPAND | wxALL, // Vertically stretchable
501 m_sizerPage->Border()
502 );
503
504 if (!isPda)
505 {
506 GetSizer()->SetSizeHints(this);
507 if ( m_posWizard == wxDefaultPosition )
508 CentreOnScreen();
509 }
510 }
511
512 void wxWizard::FitToPage(const wxWizardPage *page)
513 {
514 wxCHECK_RET(!m_started,wxT("wxWizard::FitToPage after RunWizard"));
515
516 while ( page )
517 {
518 wxSize size = page->GetBestSize();
519
520 m_sizePage.IncTo(size);
521
522 page = page->GetNext();
523 }
524 }
525
526 bool wxWizard::ShowPage(wxWizardPage *page, bool goingForward)
527 {
528 wxASSERT_MSG( page != m_page, wxT("this is useless") );
529
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")
532 bool btnLabelWasNext = true;
533
534 // Modified 10-20-2001 Robert Cavanaugh.
535 // Fixed bug for displaying a new bitmap
536 // in each *consecutive* page
537
538 // flag to indicate if this page uses a new bitmap
539 bool bmpIsDefault = true;
540
541 // use these labels to determine if we need to change the bitmap
542 // for this page
543 wxBitmap bmpPrev, bmpCur;
544
545 // check for previous page
546 if ( m_page )
547 {
548 // send the event to the old page
549 wxWizardEvent event(wxEVT_WIZARD_PAGE_CHANGING, GetId(), goingForward, m_page);
550 if ( m_page->GetEventHandler()->ProcessEvent(event) &&
551 !event.IsAllowed() )
552 {
553 // vetoed by the page
554 return false;
555 }
556
557 m_page->Hide();
558
559 btnLabelWasNext = HasNextPage(m_page);
560
561 // Get the bitmap of the previous page (if it exists)
562 if ( m_page->GetBitmap().Ok() )
563 {
564 bmpPrev = m_page->GetBitmap();
565 }
566 }
567
568 // set the new page
569 m_page = page;
570
571 // is this the end?
572 if ( !m_page )
573 {
574 // terminate successfully
575 if(IsModal())
576 {
577 EndModal(wxID_OK);
578 }
579 else
580 {
581 SetReturnCode(wxID_OK);
582 Hide();
583 }
584
585 // and notify the user code (this is especially useful for modeless
586 // wizards)
587 wxWizardEvent event(wxEVT_WIZARD_FINISHED, GetId(), false, 0);
588 (void)GetEventHandler()->ProcessEvent(event);
589
590 return true;
591 }
592
593 // position and show the new page
594 (void)m_page->TransferDataToWindow();
595
596 // wxWizardSizer::RecalcSizes wants to be called when m_page changes
597 m_sizerPage->RecalcSizes();
598
599 // check if bitmap needs to be updated
600 // update default flag as well
601 if ( m_page->GetBitmap().Ok() )
602 {
603 bmpCur = m_page->GetBitmap();
604 bmpIsDefault = false;
605 }
606
607 #if wxUSE_STATBMP
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
612 if ( m_statbmp && (bmpCur != bmpPrev) )
613 {
614 wxBitmap bmp;
615 if ( bmpIsDefault )
616 bmp = m_bitmap;
617 else
618 bmp = m_page->GetBitmap();
619 m_statbmp->SetBitmap(bmp);
620 }
621 #endif
622
623 // and update the buttons state
624 m_btnPrev->Enable(HasPrevPage(m_page));
625
626 bool hasNext = HasNextPage(m_page);
627 if ( btnLabelWasNext != hasNext )
628 {
629 // need to update
630 if (btnLabelWasNext)
631 m_btnNext->SetLabel(_("&Finish"));
632 else
633 m_btnNext->SetLabel(_("&Next >"));
634 }
635 m_btnNext->SetDefault();
636 // nothing to do: the label was already correct
637
638 // send the change event to the new page now
639 wxWizardEvent event(wxEVT_WIZARD_PAGE_CHANGED, GetId(), goingForward, m_page);
640 (void)m_page->GetEventHandler()->ProcessEvent(event);
641
642 // and finally show it
643 m_page->Show();
644 m_page->SetFocus();
645
646 return true;
647 }
648
649 bool wxWizard::RunWizard(wxWizardPage *firstPage)
650 {
651 wxCHECK_MSG( firstPage, false, wxT("can't run empty wizard") );
652
653 // This cannot be done sooner, because user can change layout options
654 // up to this moment
655 FinishLayout();
656
657 // can't return false here because there is no old page
658 (void)ShowPage(firstPage, true /* forward */);
659
660 m_wasModal = true;
661
662 return ShowModal() == wxID_OK;
663 }
664
665 wxWizardPage *wxWizard::GetCurrentPage() const
666 {
667 return m_page;
668 }
669
670 wxSize wxWizard::GetPageSize() const
671 {
672 wxSize pageSize(GetManualPageSize());
673 pageSize.IncTo(m_sizerPage->GetMaxChildSize());
674 return pageSize;
675 }
676
677 wxSizer *wxWizard::GetPageAreaSizer() const
678 {
679 return m_sizerPage;
680 }
681
682 void wxWizard::SetBorder(int border)
683 {
684 wxCHECK_RET(!m_started,wxT("wxWizard::SetBorder after RunWizard"));
685
686 m_calledSetBorder = true;
687 m_border = border;
688 }
689
690 wxSize wxWizard::GetManualPageSize() const
691 {
692 // default width and height of the page
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 }
702
703 wxSize totalPageSize(DEFAULT_PAGE_WIDTH,DEFAULT_PAGE_HEIGHT);
704
705 totalPageSize.IncTo(m_sizePage);
706
707 if ( m_statbmp )
708 {
709 totalPageSize.IncTo(wxSize(0, m_bitmap.GetHeight()));
710 }
711
712 return totalPageSize;
713 }
714
715 void wxWizard::OnCancel(wxCommandEvent& WXUNUSED(eventUnused))
716 {
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
721 wxWizardEvent event(wxEVT_WIZARD_CANCEL, GetId(), false, m_page);
722 if ( !win->GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
723 {
724 // no objections - close the dialog
725 if(IsModal())
726 {
727 EndModal(wxID_CANCEL);
728 }
729 else
730 {
731 SetReturnCode(wxID_CANCEL);
732 Hide();
733 }
734 }
735 //else: request to Cancel ignored
736 }
737
738 void wxWizard::OnBackOrNext(wxCommandEvent& event)
739 {
740 wxASSERT_MSG( (event.GetEventObject() == m_btnNext) ||
741 (event.GetEventObject() == m_btnPrev),
742 wxT("unknown button") );
743
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
747 if ( m_page && (!m_page->Validate() || !m_page->TransferDataFromWindow()) )
748 {
749 // the page data is incorrect, don't do anything
750 return;
751 }
752
753 bool forward = event.GetEventObject() == m_btnNext;
754
755 wxWizardPage *page;
756 if ( forward )
757 {
758 page = m_page->GetNext();
759 }
760 else // back
761 {
762 page = m_page->GetPrev();
763
764 wxASSERT_MSG( page, wxT("\"<Back\" button should have been disabled") );
765 }
766
767 // just pass to the new page (or may be not - but we don't care here)
768 (void)ShowPage(page, forward);
769 }
770
771 void 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
780 wxWizardEvent eventHelp(wxEVT_WIZARD_HELP, GetId(), true, m_page);
781 (void)m_page->GetEventHandler()->ProcessEvent(eventHelp);
782 }
783 }
784
785 void 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
792 event.Skip();
793 }
794 else
795 {
796 wxWindow *parent = GetParent();
797
798 if ( !parent || !parent->GetEventHandler()->ProcessEvent(event) )
799 {
800 event.Skip();
801 }
802 }
803
804 if ( ( !m_wasModal ) &&
805 event.IsAllowed() &&
806 ( event.GetEventType() == wxEVT_WIZARD_FINISHED ||
807 event.GetEventType() == wxEVT_WIZARD_CANCEL
808 )
809 )
810 {
811 Destroy();
812 }
813 }
814
815 // ----------------------------------------------------------------------------
816 // wxWizardEvent
817 // ----------------------------------------------------------------------------
818
819 wxWizardEvent::wxWizardEvent(wxEventType type, int id, bool direction, wxWizardPage* page)
820 : wxNotifyEvent(type, id)
821 {
822 // Modified 10-20-2001 Robert Cavanaugh
823 // add the active page to the event data
824 m_direction = direction;
825 m_page = page;
826 }
827
828 #endif // wxUSE_WIZARDDLG