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