]> git.saurik.com Git - wxWidgets.git/blob - src/generic/wizard.cpp
changed wxAuiBlendColour() to work with unsigned chars instead of doubles as it's...
[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 #include "wx/settings.h"
39 #include "wx/sizer.h"
40 #endif //WX_PRECOMP
41
42 #include "wx/statline.h"
43
44 #include "wx/scrolwin.h"
45 #include "wx/wizard.h"
46 #include "wx/dcmemory.h"
47
48 // ----------------------------------------------------------------------------
49 // wxWizardSizer
50 // ----------------------------------------------------------------------------
51
52 class wxWizardSizer : public wxSizer
53 {
54 public:
55 wxWizardSizer(wxWizard *owner);
56
57 virtual wxSizerItem *Insert(size_t index, wxSizerItem *item);
58
59 virtual void RecalcSizes();
60 virtual wxSize CalcMin();
61
62 // get the max size of all wizard pages
63 wxSize GetMaxChildSize();
64
65 // return the border which can be either set using wxWizard::SetBorder() or
66 // have default value
67 int GetBorder() const;
68
69 // hide the pages which we temporarily "show" when they're added to this
70 // sizer (see Insert())
71 void HidePages();
72
73 private:
74 wxSize SiblingSize(wxSizerItem *child);
75
76 wxWizard *m_owner;
77 wxSize m_childSize;
78 };
79
80 // ----------------------------------------------------------------------------
81 // event tables and such
82 // ----------------------------------------------------------------------------
83
84 DEFINE_EVENT_TYPE(wxEVT_WIZARD_PAGE_CHANGED)
85 DEFINE_EVENT_TYPE(wxEVT_WIZARD_PAGE_CHANGING)
86 DEFINE_EVENT_TYPE(wxEVT_WIZARD_CANCEL)
87 DEFINE_EVENT_TYPE(wxEVT_WIZARD_FINISHED)
88 DEFINE_EVENT_TYPE(wxEVT_WIZARD_HELP)
89
90 BEGIN_EVENT_TABLE(wxWizard, wxDialog)
91 EVT_BUTTON(wxID_CANCEL, wxWizard::OnCancel)
92 EVT_BUTTON(wxID_BACKWARD, wxWizard::OnBackOrNext)
93 EVT_BUTTON(wxID_FORWARD, wxWizard::OnBackOrNext)
94 EVT_BUTTON(wxID_HELP, wxWizard::OnHelp)
95
96 EVT_WIZARD_PAGE_CHANGED(wxID_ANY, wxWizard::OnWizEvent)
97 EVT_WIZARD_PAGE_CHANGING(wxID_ANY, wxWizard::OnWizEvent)
98 EVT_WIZARD_CANCEL(wxID_ANY, wxWizard::OnWizEvent)
99 EVT_WIZARD_FINISHED(wxID_ANY, wxWizard::OnWizEvent)
100 EVT_WIZARD_HELP(wxID_ANY, wxWizard::OnWizEvent)
101 END_EVENT_TABLE()
102
103 IMPLEMENT_DYNAMIC_CLASS(wxWizard, wxDialog)
104
105 /*
106 TODO PROPERTIES :
107 wxWizard
108 extstyle
109 title
110 */
111
112 IMPLEMENT_ABSTRACT_CLASS(wxWizardPage, wxPanel)
113 IMPLEMENT_DYNAMIC_CLASS(wxWizardPageSimple, wxWizardPage)
114 IMPLEMENT_DYNAMIC_CLASS(wxWizardEvent, wxNotifyEvent)
115
116 // ============================================================================
117 // implementation
118 // ============================================================================
119
120 // ----------------------------------------------------------------------------
121 // wxWizardPage
122 // ----------------------------------------------------------------------------
123
124 void wxWizardPage::Init()
125 {
126 m_bitmap = wxNullBitmap;
127 }
128
129 wxWizardPage::wxWizardPage(wxWizard *parent,
130 const wxBitmap& bitmap)
131 {
132 Create(parent, bitmap);
133 }
134
135 bool wxWizardPage::Create(wxWizard *parent,
136 const wxBitmap& bitmap)
137 {
138 if ( !wxPanel::Create(parent, wxID_ANY) )
139 return false;
140
141 m_bitmap = bitmap;
142
143 // initially the page is hidden, it's shown only when it becomes current
144 Hide();
145
146 return true;
147 }
148
149 // ----------------------------------------------------------------------------
150 // wxWizardPageSimple
151 // ----------------------------------------------------------------------------
152
153 wxWizardPage *wxWizardPageSimple::GetPrev() const
154 {
155 return m_prev;
156 }
157
158 wxWizardPage *wxWizardPageSimple::GetNext() const
159 {
160 return m_next;
161 }
162
163 // ----------------------------------------------------------------------------
164 // wxWizardSizer
165 // ----------------------------------------------------------------------------
166
167 wxWizardSizer::wxWizardSizer(wxWizard *owner)
168 : m_owner(owner),
169 m_childSize(wxDefaultSize)
170 {
171 }
172
173 wxSizerItem *wxWizardSizer::Insert(size_t index, wxSizerItem *item)
174 {
175 m_owner->m_usingSizer = true;
176
177 if ( item->IsWindow() )
178 {
179 // we must pretend that the window is shown as otherwise it wouldn't be
180 // taken into account for the layout -- but avoid really showing it, so
181 // just set the internal flag instead of calling wxWindow::Show()
182 item->GetWindow()->wxWindowBase::Show();
183 }
184
185 return wxSizer::Insert(index, item);
186 }
187
188 void wxWizardSizer::HidePages()
189 {
190 for ( wxSizerItemList::compatibility_iterator node = GetChildren().GetFirst();
191 node;
192 node = node->GetNext() )
193 {
194 wxSizerItem * const item = node->GetData();
195 if ( item->IsWindow() )
196 item->GetWindow()->wxWindowBase::Show(false);
197 }
198 }
199
200 void wxWizardSizer::RecalcSizes()
201 {
202 // Effect of this function depends on m_owner->m_page and
203 // it should be called whenever it changes (wxWizard::ShowPage)
204 if ( m_owner->m_page )
205 {
206 m_owner->m_page->SetSize(wxRect(m_position, m_size));
207 }
208 }
209
210 wxSize wxWizardSizer::CalcMin()
211 {
212 return m_owner->GetPageSize();
213 }
214
215 wxSize wxWizardSizer::GetMaxChildSize()
216 {
217 #if !defined(__WXDEBUG__)
218 if ( m_childSize.IsFullySpecified() )
219 return m_childSize;
220 #endif
221
222 wxSize maxOfMin;
223
224 for ( wxSizerItemList::compatibility_iterator childNode = m_children.GetFirst();
225 childNode;
226 childNode = childNode->GetNext() )
227 {
228 wxSizerItem *child = childNode->GetData();
229 maxOfMin.IncTo(child->CalcMin());
230 maxOfMin.IncTo(SiblingSize(child));
231 }
232
233 // No longer applicable since we may change sizes when size adaptation is done
234 #if 0
235 #ifdef __WXDEBUG__
236 if ( m_childSize.IsFullySpecified() && m_childSize != maxOfMin )
237 {
238 wxFAIL_MSG( _T("Size changed in wxWizard::GetPageAreaSizer()")
239 _T("after RunWizard().\n")
240 _T("Did you forget to call GetSizer()->Fit(this) ")
241 _T("for some page?")) ;
242
243 return m_childSize;
244 }
245 #endif // __WXDEBUG__
246 #endif
247
248 if ( m_owner->m_started )
249 {
250 m_childSize = maxOfMin;
251 }
252
253 return maxOfMin;
254 }
255
256 int wxWizardSizer::GetBorder() const
257 {
258 return m_owner->m_border;
259 }
260
261 wxSize wxWizardSizer::SiblingSize(wxSizerItem *child)
262 {
263 wxSize maxSibling;
264
265 if ( child->IsWindow() )
266 {
267 wxWizardPage *page = wxDynamicCast(child->GetWindow(), wxWizardPage);
268 if ( page )
269 {
270 for ( wxWizardPage *sibling = page->GetNext();
271 sibling;
272 sibling = sibling->GetNext() )
273 {
274 if ( sibling->GetSizer() )
275 {
276 maxSibling.IncTo(sibling->GetSizer()->CalcMin());
277 }
278 }
279 }
280 }
281
282 return maxSibling;
283 }
284
285 // ----------------------------------------------------------------------------
286 // generic wxWizard implementation
287 // ----------------------------------------------------------------------------
288
289 void wxWizard::Init()
290 {
291 m_posWizard = wxDefaultPosition;
292 m_page = (wxWizardPage *)NULL;
293 m_btnPrev = m_btnNext = NULL;
294 m_statbmp = NULL;
295 m_sizerBmpAndPage = NULL;
296 m_sizerPage = NULL;
297 m_border = 5;
298 m_started = false;
299 m_wasModal = false;
300 m_usingSizer = false;
301 m_bitmapBackgroundColour = *wxWHITE;
302 m_bitmapPlacement = 0;
303 m_bitmapMinimumWidth = 115;
304 }
305
306 bool wxWizard::Create(wxWindow *parent,
307 int id,
308 const wxString& title,
309 const wxBitmap& bitmap,
310 const wxPoint& pos,
311 long style)
312 {
313 bool result = wxDialog::Create(parent,id,title,pos,wxDefaultSize,style);
314
315 m_posWizard = pos;
316 m_bitmap = bitmap ;
317
318 DoCreateControls();
319
320 return result;
321 }
322
323 wxWizard::~wxWizard()
324 {
325 // normally we don't have to delete this sizer as it's deleted by the
326 // associated window but if we never used it or didn't set it as the window
327 // sizer yet, do delete it manually
328 if ( !m_usingSizer || !m_started )
329 delete m_sizerPage;
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 wxSize bitmapSize(wxDefaultSize);
349 if (GetBitmapPlacement())
350 bitmapSize.x = GetMinimumBitmapWidth();
351
352 m_statbmp = new wxStaticBitmap(this, wxID_ANY, m_bitmap, wxDefaultPosition, bitmapSize);
353 m_sizerBmpAndPage->Add(
354 m_statbmp,
355 0, // No horizontal stretching
356 wxALL, // Border all around, top alignment
357 5 // Border width
358 );
359 m_sizerBmpAndPage->Add(
360 5,0,
361 0, // No horizontal stretching
362 wxEXPAND // No border, (mostly useless) vertical stretching
363 );
364 }
365 #endif
366
367 // Added to m_sizerBmpAndPage later
368 m_sizerPage = new wxWizardSizer(this);
369 }
370
371 void wxWizard::AddStaticLine(wxBoxSizer *mainColumn)
372 {
373 #if wxUSE_STATLINE
374 mainColumn->Add(
375 new wxStaticLine(this, wxID_ANY),
376 0, // Vertically unstretchable
377 wxEXPAND | wxALL, // Border all around, horizontally stretchable
378 5 // Border width
379 );
380 mainColumn->Add(0,5,
381 0, // No vertical stretching
382 wxEXPAND // No border, (mostly useless) horizontal stretching
383 );
384 #else
385 (void)mainColumn;
386 #endif // wxUSE_STATLINE
387 }
388
389 void wxWizard::AddBackNextPair(wxBoxSizer *buttonRow)
390 {
391 wxASSERT_MSG( m_btnNext && m_btnPrev,
392 _T("You must create the buttons before calling ")
393 _T("wxWizard::AddBackNextPair") );
394
395 // margin between Back and Next buttons
396 #ifdef __WXMAC__
397 static const int BACKNEXT_MARGIN = 10;
398 #else
399 static const int BACKNEXT_MARGIN = 0;
400 #endif
401
402 wxBoxSizer *backNextPair = new wxBoxSizer(wxHORIZONTAL);
403 buttonRow->Add(
404 backNextPair,
405 0, // No horizontal stretching
406 wxALL, // Border all around
407 5 // Border width
408 );
409
410 backNextPair->Add(m_btnPrev);
411 backNextPair->Add(BACKNEXT_MARGIN,0,
412 0, // No horizontal stretching
413 wxEXPAND // No border, (mostly useless) vertical stretching
414 );
415 backNextPair->Add(m_btnNext);
416 }
417
418 void wxWizard::AddButtonRow(wxBoxSizer *mainColumn)
419 {
420 // the order in which the buttons are created determines the TAB order - at least under MSWindows...
421 // although the 'back' button appears before the 'next' button, a more userfriendly tab order is
422 // to activate the 'next' button first (create the next button before the back button).
423 // The reason is: The user will repeatedly enter information in the wizard pages and then wants to
424 // press 'next'. If a user uses mostly the keyboard, he would have to skip the 'back' button
425 // everytime. This is annoying. There is a second reason: RETURN acts as TAB. If the 'next'
426 // button comes first in the TAB order, the user can enter information very fast using the RETURN
427 // key to TAB to the next entry field and page. This would not be possible, if the 'back' button
428 // was created before the 'next' button.
429
430 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
431 int buttonStyle = isPda ? wxBU_EXACTFIT : 0;
432
433 wxBoxSizer *buttonRow = new wxBoxSizer(wxHORIZONTAL);
434 #ifdef __WXMAC__
435 if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON)
436 mainColumn->Add(
437 buttonRow,
438 0, // Vertically unstretchable
439 wxGROW|wxALIGN_CENTRE
440 );
441 else
442 #endif
443 mainColumn->Add(
444 buttonRow,
445 0, // Vertically unstretchable
446 wxALIGN_RIGHT // Right aligned, no border
447 );
448
449 // Desired TAB order is 'next', 'cancel', 'help', 'back'. This makes the 'back' button the last control on the page.
450 // Create the buttons in the right order...
451 wxButton *btnHelp=0;
452 #ifdef __WXMAC__
453 if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON)
454 btnHelp=new wxButton(this, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, buttonStyle);
455 #endif
456
457 m_btnNext = new wxButton(this, wxID_FORWARD, _("&Next >"));
458 wxButton *btnCancel=new wxButton(this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, buttonStyle);
459 #ifndef __WXMAC__
460 if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON)
461 btnHelp=new wxButton(this, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, buttonStyle);
462 #endif
463 m_btnPrev = new wxButton(this, wxID_BACKWARD, _("< &Back"), wxDefaultPosition, wxDefaultSize, buttonStyle);
464
465 if (btnHelp)
466 {
467 buttonRow->Add(
468 btnHelp,
469 0, // Horizontally unstretchable
470 wxALL, // Border all around, top aligned
471 5 // Border width
472 );
473 #ifdef __WXMAC__
474 // Put stretchable space between help button and others
475 buttonRow->Add(0, 0, 1, wxALIGN_CENTRE, 0);
476 #endif
477 }
478
479 AddBackNextPair(buttonRow);
480
481 buttonRow->Add(
482 btnCancel,
483 0, // Horizontally unstretchable
484 wxALL, // Border all around, top aligned
485 5 // Border width
486 );
487 }
488
489 void wxWizard::DoCreateControls()
490 {
491 // do nothing if the controls were already created
492 if ( WasCreated() )
493 return;
494
495 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
496
497 // Horizontal stretching, and if not PDA, border all around
498 int mainColumnSizerFlags = isPda ? wxEXPAND : wxALL|wxEXPAND ;
499
500 // wxWindow::SetSizer will be called at end
501 wxBoxSizer *windowSizer = new wxBoxSizer(wxVERTICAL);
502
503 wxBoxSizer *mainColumn = new wxBoxSizer(wxVERTICAL);
504 windowSizer->Add(
505 mainColumn,
506 1, // Vertical stretching
507 mainColumnSizerFlags,
508 5 // Border width
509 );
510
511 AddBitmapRow(mainColumn);
512
513 if (!isPda)
514 AddStaticLine(mainColumn);
515
516 AddButtonRow(mainColumn);
517
518 SetSizer(windowSizer);
519 }
520
521 void wxWizard::SetPageSize(const wxSize& size)
522 {
523 wxCHECK_RET(!m_started, wxT("wxWizard::SetPageSize after RunWizard"));
524 m_sizePage = size;
525 }
526
527 void wxWizard::FitToPage(const wxWizardPage *page)
528 {
529 wxCHECK_RET(!m_started, wxT("wxWizard::FitToPage after RunWizard"));
530
531 while ( page )
532 {
533 wxSize size = page->GetBestSize();
534
535 m_sizePage.IncTo(size);
536
537 page = page->GetNext();
538 }
539 }
540
541 bool wxWizard::ShowPage(wxWizardPage *page, bool goingForward)
542 {
543 wxASSERT_MSG( page != m_page, wxT("this is useless") );
544
545 wxSizerFlags flags(1);
546 flags.Border(wxALL, m_border).Expand();
547
548 if ( !m_started )
549 {
550 if ( m_usingSizer )
551 {
552 m_sizerBmpAndPage->Add(m_sizerPage, flags);
553
554 // now that our layout is computed correctly, hide the pages
555 // artificially shown in wxWizardSizer::Insert() back again
556 m_sizerPage->HidePages();
557 }
558 }
559
560
561 // remember the old bitmap (if any) to compare with the new one later
562 wxBitmap bmpPrev;
563
564 // check for previous page
565 if ( m_page )
566 {
567 // send the event to the old page
568 wxWizardEvent event(wxEVT_WIZARD_PAGE_CHANGING, GetId(),
569 goingForward, m_page);
570 if ( m_page->GetEventHandler()->ProcessEvent(event) &&
571 !event.IsAllowed() )
572 {
573 // vetoed by the page
574 return false;
575 }
576
577 m_page->Hide();
578
579 bmpPrev = m_page->GetBitmap();
580
581 if ( !m_usingSizer )
582 m_sizerBmpAndPage->Detach(m_page);
583 }
584
585 // set the new page
586 m_page = page;
587
588 // is this the end?
589 if ( !m_page )
590 {
591 // terminate successfully
592 if ( IsModal() )
593 {
594 EndModal(wxID_OK);
595 }
596 else
597 {
598 SetReturnCode(wxID_OK);
599 Hide();
600 }
601
602 // and notify the user code (this is especially useful for modeless
603 // wizards)
604 wxWizardEvent event(wxEVT_WIZARD_FINISHED, GetId(), false, 0);
605 (void)GetEventHandler()->ProcessEvent(event);
606
607 return true;
608 }
609
610 // position and show the new page
611 (void)m_page->TransferDataToWindow();
612
613 if ( m_usingSizer )
614 {
615 // wxWizardSizer::RecalcSizes wants to be called when m_page changes
616 m_sizerPage->RecalcSizes();
617 }
618 else // pages are not managed by the sizer
619 {
620 m_sizerBmpAndPage->Add(m_page, flags);
621 m_sizerBmpAndPage->SetItemMinSize(m_page, GetPageSize());
622 }
623
624 #if wxUSE_STATBMP
625 // update the bitmap if:it changed
626 wxBitmap bmp;
627 if ( m_statbmp )
628 {
629 bmp = m_page->GetBitmap();
630 if ( !bmp.Ok() )
631 bmp = m_bitmap;
632
633 if ( !bmpPrev.Ok() )
634 bmpPrev = m_bitmap;
635
636 if (!GetBitmapPlacement())
637 {
638 if ( !bmp.IsSameAs(bmpPrev) )
639 m_statbmp->SetBitmap(bmp);
640 }
641 }
642 #endif // wxUSE_STATBMP
643
644
645 // and update the buttons state
646 m_btnPrev->Enable(HasPrevPage(m_page));
647
648 const bool hasNext = HasNextPage(m_page);
649 const wxString label = hasNext ? _("&Next >") : _("&Finish");
650 if ( label != m_btnNext->GetLabel() )
651 m_btnNext->SetLabel(label);
652
653 m_btnNext->SetDefault();
654
655
656 // send the change event to the new page now
657 wxWizardEvent event(wxEVT_WIZARD_PAGE_CHANGED, GetId(), goingForward, m_page);
658 (void)m_page->GetEventHandler()->ProcessEvent(event);
659
660 // and finally show it
661 m_page->Show();
662 m_page->SetFocus();
663
664 if ( !m_usingSizer )
665 m_sizerBmpAndPage->Layout();
666
667 if ( !m_started )
668 {
669 m_started = true;
670
671 DoWizardLayout();
672 }
673
674 if (GetBitmapPlacement() && m_statbmp)
675 {
676 ResizeBitmap(bmp);
677
678 if ( !bmp.IsSameAs(bmpPrev) )
679 m_statbmp->SetBitmap(bmp);
680
681 if (m_usingSizer)
682 m_sizerPage->RecalcSizes();
683 }
684
685 return true;
686 }
687
688 /// Do fit, and adjust to screen size if necessary
689 void wxWizard::DoWizardLayout()
690 {
691 if ( wxSystemSettings::GetScreenType() > wxSYS_SCREEN_PDA )
692 {
693 if (CanDoLayoutAdaptation())
694 DoLayoutAdaptation();
695 else
696 GetSizer()->SetSizeHints(this);
697
698 if ( m_posWizard == wxDefaultPosition )
699 CentreOnScreen();
700 }
701
702 SetLayoutAdaptationDone(true);
703 }
704
705 bool wxWizard::RunWizard(wxWizardPage *firstPage)
706 {
707 wxCHECK_MSG( firstPage, false, wxT("can't run empty wizard") );
708
709 // can't return false here because there is no old page
710 (void)ShowPage(firstPage, true /* forward */);
711
712 m_wasModal = true;
713
714 return ShowModal() == wxID_OK;
715 }
716
717 wxWizardPage *wxWizard::GetCurrentPage() const
718 {
719 return m_page;
720 }
721
722 wxSize wxWizard::GetPageSize() const
723 {
724 // default width and height of the page
725 int DEFAULT_PAGE_WIDTH,
726 DEFAULT_PAGE_HEIGHT;
727 if ( wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA )
728 {
729 // Make the default page size small enough to fit on screen
730 DEFAULT_PAGE_WIDTH = wxSystemSettings::GetMetric(wxSYS_SCREEN_X) / 2;
731 DEFAULT_PAGE_HEIGHT = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y) / 2;
732 }
733 else // !PDA
734 {
735 DEFAULT_PAGE_WIDTH =
736 DEFAULT_PAGE_HEIGHT = 270;
737 }
738
739 // start with default minimal size
740 wxSize pageSize(DEFAULT_PAGE_WIDTH, DEFAULT_PAGE_HEIGHT);
741
742 // make the page at least as big as specified by user
743 pageSize.IncTo(m_sizePage);
744
745 if ( m_statbmp )
746 {
747 // make the page at least as tall as the bitmap
748 pageSize.IncTo(wxSize(0, m_bitmap.GetHeight()));
749 }
750
751 if ( m_usingSizer )
752 {
753 // make it big enough to contain all pages added to the sizer
754 pageSize.IncTo(m_sizerPage->GetMaxChildSize());
755 }
756
757 return pageSize;
758 }
759
760 wxSizer *wxWizard::GetPageAreaSizer() const
761 {
762 return m_sizerPage;
763 }
764
765 void wxWizard::SetBorder(int border)
766 {
767 wxCHECK_RET(!m_started, wxT("wxWizard::SetBorder after RunWizard"));
768
769 m_border = border;
770 }
771
772 void wxWizard::OnCancel(wxCommandEvent& WXUNUSED(eventUnused))
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 wxWindow *win = m_page ? (wxWindow *)m_page : (wxWindow *)this;
777
778 wxWizardEvent event(wxEVT_WIZARD_CANCEL, GetId(), false, m_page);
779 if ( !win->GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
780 {
781 // no objections - close the dialog
782 if(IsModal())
783 {
784 EndModal(wxID_CANCEL);
785 }
786 else
787 {
788 SetReturnCode(wxID_CANCEL);
789 Hide();
790 }
791 }
792 //else: request to Cancel ignored
793 }
794
795 void wxWizard::OnBackOrNext(wxCommandEvent& event)
796 {
797 wxASSERT_MSG( (event.GetEventObject() == m_btnNext) ||
798 (event.GetEventObject() == m_btnPrev),
799 wxT("unknown button") );
800
801 wxCHECK_RET( m_page, _T("should have a valid current page") );
802
803 // ask the current page first: notice that we do it before calling
804 // GetNext/Prev() because the data transfered from the controls of the page
805 // may change the value returned by these methods
806 if ( !m_page->Validate() || !m_page->TransferDataFromWindow() )
807 {
808 // the page data is incorrect, don't do anything
809 return;
810 }
811
812 bool forward = event.GetEventObject() == m_btnNext;
813
814 wxWizardPage *page;
815 if ( forward )
816 {
817 page = m_page->GetNext();
818 }
819 else // back
820 {
821 page = m_page->GetPrev();
822
823 wxASSERT_MSG( page, wxT("\"<Back\" button should have been disabled") );
824 }
825
826 // just pass to the new page (or maybe not - but we don't care here)
827 (void)ShowPage(page, forward);
828 }
829
830 void wxWizard::OnHelp(wxCommandEvent& WXUNUSED(event))
831 {
832 // this function probably can never be called when we don't have an active
833 // page, but a small extra check won't hurt
834 if(m_page != NULL)
835 {
836 // Create and send the help event to the specific page handler
837 // event data contains the active page so that context-sensitive
838 // help is possible
839 wxWizardEvent eventHelp(wxEVT_WIZARD_HELP, GetId(), true, m_page);
840 (void)m_page->GetEventHandler()->ProcessEvent(eventHelp);
841 }
842 }
843
844 void wxWizard::OnWizEvent(wxWizardEvent& event)
845 {
846 // the dialogs have wxWS_EX_BLOCK_EVENTS style on by default but we want to
847 // propagate wxEVT_WIZARD_XXX to the parent (if any), so do it manually
848 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
849 {
850 // the event will be propagated anyhow
851 event.Skip();
852 }
853 else
854 {
855 wxWindow *parent = GetParent();
856
857 if ( !parent || !parent->GetEventHandler()->ProcessEvent(event) )
858 {
859 event.Skip();
860 }
861 }
862
863 if ( ( !m_wasModal ) &&
864 event.IsAllowed() &&
865 ( event.GetEventType() == wxEVT_WIZARD_FINISHED ||
866 event.GetEventType() == wxEVT_WIZARD_CANCEL
867 )
868 )
869 {
870 Destroy();
871 }
872 }
873
874 void wxWizard::SetBitmap(const wxBitmap& bitmap)
875 {
876 m_bitmap = bitmap;
877 if (m_statbmp)
878 m_statbmp->SetBitmap(m_bitmap);
879 }
880
881 // ----------------------------------------------------------------------------
882 // wxWizardEvent
883 // ----------------------------------------------------------------------------
884
885 wxWizardEvent::wxWizardEvent(wxEventType type, int id, bool direction, wxWizardPage* page)
886 : wxNotifyEvent(type, id)
887 {
888 // Modified 10-20-2001 Robert Cavanaugh
889 // add the active page to the event data
890 m_direction = direction;
891 m_page = page;
892 }
893
894 /// Do the adaptation
895 bool wxWizard::DoLayoutAdaptation()
896 {
897 wxWindowList windows;
898 wxWindowList pages;
899
900 // Make all the pages (that use sizers) scrollable
901 for ( wxSizerItemList::compatibility_iterator node = m_sizerPage->GetChildren().GetFirst(); node; node = node->GetNext() )
902 {
903 wxSizerItem * const item = node->GetData();
904 if ( item->IsWindow() )
905 {
906 wxWizardPage* page = wxDynamicCast(item->GetWindow(), wxWizardPage);
907 if (page)
908 {
909 while (page)
910 {
911 if (!pages.Find(page) && page->GetSizer())
912 {
913 // Create a scrolled window and reparent
914 wxScrolledWindow* scrolledWindow = new wxScrolledWindow(page, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxVSCROLL|wxHSCROLL|wxBORDER_NONE);
915 wxSizer* oldSizer = page->GetSizer();
916
917 wxSizer* newSizer = new wxBoxSizer(wxVERTICAL);
918 newSizer->Add(scrolledWindow,1, wxEXPAND, 0);
919
920 page->SetSizer(newSizer, false /* don't delete the old sizer */);
921
922 scrolledWindow->SetSizer(oldSizer);
923
924 wxStandardDialogLayoutAdapter::DoReparentControls(page, scrolledWindow);
925
926 pages.Append(page);
927 windows.Append(scrolledWindow);
928 }
929 page = page->GetNext();
930 }
931 }
932 }
933 }
934
935 wxStandardDialogLayoutAdapter::DoFitWithScrolling(this, windows);
936
937 // Size event doesn't get sent soon enough on wxGTK
938 DoLayout();
939
940 SetLayoutAdaptationDone(true);
941
942 return true;
943 }
944
945 bool wxWizard::ResizeBitmap(wxBitmap& bmp)
946 {
947 if (!GetBitmapPlacement())
948 return false;
949
950 if (bmp.Ok())
951 {
952 wxSize pageSize = m_sizerPage->GetSize();
953 if (pageSize == wxSize(0,0))
954 pageSize = GetPageSize();
955 int bitmapWidth = wxMax(bmp.GetWidth(), GetMinimumBitmapWidth());
956 int bitmapHeight = pageSize.y;
957
958 if (!m_statbmp->GetBitmap().Ok() || m_statbmp->GetBitmap().GetHeight() != bitmapHeight)
959 {
960 wxBitmap bitmap(bitmapWidth, bitmapHeight);
961 {
962 wxMemoryDC dc;
963 dc.SelectObject(bitmap);
964 dc.SetBackground(wxBrush(m_bitmapBackgroundColour));
965 dc.Clear();
966
967 if (GetBitmapPlacement() & wxWIZARD_TILE)
968 {
969 TileBitmap(wxRect(0, 0, bitmapWidth, bitmapHeight), dc, bmp);
970 }
971 else
972 {
973 int x, y;
974
975 if (GetBitmapPlacement() & wxWIZARD_HALIGN_LEFT)
976 x = 0;
977 else if (GetBitmapPlacement() & wxWIZARD_HALIGN_RIGHT)
978 x = bitmapWidth - bmp.GetWidth();
979 else
980 x = (bitmapWidth - bmp.GetWidth())/2;
981
982 if (GetBitmapPlacement() & wxWIZARD_VALIGN_TOP)
983 y = 0;
984 else if (GetBitmapPlacement() & wxWIZARD_VALIGN_BOTTOM)
985 y = bitmapHeight - bmp.GetHeight();
986 else
987 y = (bitmapHeight - bmp.GetHeight())/2;
988
989 dc.DrawBitmap(bmp, x, y, true);
990 dc.SelectObject(wxNullBitmap);
991 }
992 }
993
994 bmp = bitmap;
995 }
996 }
997
998 return true;
999 }
1000
1001 bool wxWizard::TileBitmap(const wxRect& rect, wxDC& dc, const wxBitmap& bitmap)
1002 {
1003 int w = bitmap.GetWidth();
1004 int h = bitmap.GetHeight();
1005
1006 wxMemoryDC dcMem;
1007
1008 dcMem.SelectObjectAsSource(bitmap);
1009
1010 int i, j;
1011 for (i = rect.x; i < rect.x + rect.width; i += w)
1012 {
1013 for (j = rect.y; j < rect.y + rect.height; j+= h)
1014 dc.Blit(i, j, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
1015 }
1016 dcMem.SelectObject(wxNullBitmap);
1017
1018 return true;
1019 }
1020
1021 #endif // wxUSE_WIZARDDLG