X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/07f20d9a63226a25e71ba6c72e2803c1f58e7903..002c9672c742d419de842c63f0ff20201b375027:/src/generic/wizard.cpp diff --git a/src/generic/wizard.cpp b/src/generic/wizard.cpp index 158b7708e3..bceae5eb16 100644 --- a/src/generic/wizard.cpp +++ b/src/generic/wizard.cpp @@ -21,7 +21,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "wizardg.h" #endif @@ -46,6 +46,29 @@ #include "wx/wizard.h" +// ---------------------------------------------------------------------------- +// wxWizardSizer +// ---------------------------------------------------------------------------- + +class wxWizardSizer : public wxSizer +{ +public: + wxWizardSizer(wxWizard *owner); + + void RecalcSizes(); + wxSize CalcMin(); + + wxSize GetMaxChildSize(); + int Border() const; + +private: + wxSize SiblingSize(wxSizerItem *child); + + wxWizard *m_owner; + bool m_childSizeValid; + wxSize m_childSize; +}; + // ---------------------------------------------------------------------------- // event tables and such // ---------------------------------------------------------------------------- @@ -70,6 +93,14 @@ BEGIN_EVENT_TABLE(wxWizard, wxDialog) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxWizard, wxDialog) + +/* + TODO PROPERTIES : + wxWizard + extstyle + title +*/ + IMPLEMENT_ABSTRACT_CLASS(wxWizardPage, wxPanel) IMPLEMENT_DYNAMIC_CLASS(wxWizardPageSimple, wxWizardPage) IMPLEMENT_DYNAMIC_CLASS(wxWizardEvent, wxNotifyEvent) @@ -139,29 +170,6 @@ wxWizardPage *wxWizardPageSimple::GetNext() const // wxWizardSizer // ---------------------------------------------------------------------------- -class wxWizardSizer : public wxSizer -{ -public: - wxWizardSizer(wxWizard *owner); - - void RecalcSizes(); - wxSize CalcMin(); - - wxSize GetMaxChildSize(); - int Border() const; - -private: - wxSize SiblingSize(wxSizerItem *child); - - wxWizard *m_owner; - bool m_childSizeValid; - wxSize m_childSize; - - DECLARE_CLASS(wxWizardSizer); -}; - -IMPLEMENT_CLASS(wxWizardSizer, wxSizer) - wxWizardSizer::wxWizardSizer(wxWizard *owner) : m_owner(owner) { @@ -191,7 +199,7 @@ wxSize wxWizardSizer::GetMaxChildSize() #endif wxSize maxOfMin; - wxSizerItemList::Node *childNode; + wxSizerItemList::compatibility_iterator childNode; for(childNode = m_children.GetFirst(); childNode; childNode = childNode->GetNext()) @@ -264,6 +272,7 @@ void wxWizard::Init() m_page = (wxWizardPage *)NULL; m_btnPrev = m_btnNext = NULL; m_statbmp = NULL; + m_sizerBmpAndPage = NULL; m_sizerPage = NULL; m_calledSetBorder = false; m_border = 0; @@ -271,11 +280,11 @@ void wxWizard::Init() } bool wxWizard::Create(wxWindow *parent, - int id, - const wxString& title, - const wxBitmap& bitmap, - const wxPoint& pos, - long style) + int id, + const wxString& title, + const wxBitmap& bitmap, + const wxPoint& pos, + long style) { bool result = wxDialog::Create(parent,id,title,pos,wxDefaultSize,style); @@ -300,6 +309,7 @@ void wxWizard::AddBitmapRow(wxBoxSizer *mainColumn) wxEXPAND // No border, (mostly useless) horizontal stretching ); +#if wxUSE_STATBMP if ( m_bitmap.Ok() ) { m_statbmp = new wxStaticBitmap(this, -1, m_bitmap); @@ -315,8 +325,7 @@ void wxWizard::AddBitmapRow(wxBoxSizer *mainColumn) wxEXPAND // No border, (mostly useless) vertical stretching ); } - else - m_statbmp = (wxStaticBitmap *)NULL; +#endif // Added to m_sizerBmpAndPage in FinishLayout m_sizerPage = new wxWizardSizer(this); @@ -342,6 +351,10 @@ void wxWizard::AddStaticLine(wxBoxSizer *mainColumn) void wxWizard::AddBackNextPair(wxBoxSizer *buttonRow) { + wxASSERT_MSG( m_btnNext && m_btnPrev, + _T("You must create the buttons before calling ") + _T("wxWizard::AddBackNextPair") ); + // margin between Back and Next buttons #ifdef __WXMAC__ static const int BACKNEXT_MARGIN = 10; @@ -357,18 +370,26 @@ void wxWizard::AddBackNextPair(wxBoxSizer *buttonRow) 5 // Border width ); - m_btnPrev = new wxButton(this, wxID_BACKWARD, _("< &Back")); backNextPair->Add(m_btnPrev); backNextPair->Add(BACKNEXT_MARGIN,0, 0, // No horizontal stretching wxEXPAND // No border, (mostly useless) vertical stretching ); - m_btnNext = new wxButton(this, wxID_FORWARD, _("&Next >")); backNextPair->Add(m_btnNext); } void wxWizard::AddButtonRow(wxBoxSizer *mainColumn) { + // the order in which the buttons are created determines the TAB order - at least under MSWindows... + // although the 'back' button appears before the 'next' button, a more userfriendly tab order is + // to activate the 'next' button first (create the next button before the back button). + // The reason is: The user will repeatedly enter information in the wizard pages and then wants to + // press 'next'. If a user uses mostly the keyboard, he would have to skip the 'back' button + // everytime. This is annoying. There is a second reason: RETURN acts as TAB. If the 'next' + // button comes first in the TAB order, the user can enter information very fast using the RETURN + // key to TAB to the next entry field and page. This would not be possible, if the 'back' button + // was created before the 'next' button. + wxBoxSizer *buttonRow = new wxBoxSizer(wxHORIZONTAL); mainColumn->Add( buttonRow, @@ -376,9 +397,18 @@ void wxWizard::AddButtonRow(wxBoxSizer *mainColumn) wxALIGN_RIGHT // Right aligned, no border ); + // Desired TAB order is 'next', 'cancel', 'help', 'back'. This makes the 'back' button the last control on the page. + // Create the buttons in the right order... + m_btnNext = new wxButton(this, wxID_FORWARD, _("&Next >")); + wxButton *btnCancel=new wxButton(this, wxID_CANCEL, _("&Cancel")); + wxButton *btnHelp=0; if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON) + btnHelp=new wxButton(this, wxID_HELP, _("&Help")); + m_btnPrev = new wxButton(this, wxID_BACKWARD, _("< &Back")); + + if (btnHelp) buttonRow->Add( - new wxButton(this, wxID_HELP, _("&Help")), + btnHelp, 0, // Horizontally unstretchable wxALL, // Border all around, top aligned 5 // Border width @@ -387,7 +417,7 @@ void wxWizard::AddButtonRow(wxBoxSizer *mainColumn) AddBackNextPair(buttonRow); buttonRow->Add( - new wxButton(this, wxID_CANCEL, _("&Cancel")), + btnCancel, 0, // Horizontally unstretchable wxALL, // Border all around, top aligned 5 // Border width @@ -504,11 +534,12 @@ bool wxWizard::ShowPage(wxWizardPage *page, bool goingForward) { // terminate successfully EndModal(wxID_OK); - if ( !IsModal() ) - { - wxWizardEvent event(wxEVT_WIZARD_FINISHED, GetId(),FALSE, 0); - (void)GetEventHandler()->ProcessEvent(event); - } + + // and notify the user code (this is especially useful for modeless + // wizards) + wxWizardEvent event(wxEVT_WIZARD_FINISHED, GetId(), FALSE, 0); + (void)GetEventHandler()->ProcessEvent(event); + return TRUE; } @@ -526,6 +557,7 @@ bool wxWizard::ShowPage(wxWizardPage *page, bool goingForward) bmpIsDefault = FALSE; } +#if wxUSE_STATBMP // change the bitmap if: // 1) a default bitmap was selected in constructor // 2) this page was constructed with a bitmap @@ -539,6 +571,7 @@ bool wxWizard::ShowPage(wxWizardPage *page, bool goingForward) bmp = m_page->GetBitmap(); m_statbmp->SetBitmap(bmp); } +#endif // and update the buttons state m_btnPrev->Enable(HasPrevPage(m_page)); @@ -552,6 +585,7 @@ bool wxWizard::ShowPage(wxWizardPage *page, bool goingForward) else m_btnNext->SetLabel(_("&Next >")); } + m_btnNext->SetDefault(); // nothing to do: the label was already correct // send the change event to the new page now @@ -602,6 +636,7 @@ wxSizer *wxWizard::GetPageAreaSizer() const void wxWizard::SetBorder(int border) { wxCHECK_RET(!m_started,wxT("wxWizard::SetBorder after RunWizard")); + m_calledSetBorder = true; m_border = border; } @@ -616,8 +651,10 @@ wxSize wxWizard::GetManualPageSize() const totalPageSize.IncTo(m_sizePage); - if(m_statbmp) - totalPageSize.IncTo(wxSize(0,m_bitmap.GetHeight())); + if ( m_statbmp ) + { + totalPageSize.IncTo(wxSize(0, m_bitmap.GetHeight())); + } return totalPageSize; } @@ -691,6 +728,7 @@ void wxWizard::OnWizEvent(wxWizardEvent& event) if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) ) { // the event will be propagated anyhow + event.Skip(); return; } @@ -706,7 +744,7 @@ void wxWizard::OnWizEvent(wxWizardEvent& event) // our public interface // ---------------------------------------------------------------------------- -#ifdef WXWIN_COMPATIBILITY_2_2 +#if WXWIN_COMPATIBILITY_2_2 /* static */ wxWizard *wxWizardBase::Create(wxWindow *parent,