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