/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/generic/wizard.cpp
ViewVC logotype

Annotation of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/generic/wizard.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22