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