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