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