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