X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5d1b49193b778e39901b83097a34429db2e5b47b..d23ec02c6ab52f60349601be999bab4cf6acbdc4:/src/common/dlgcmn.cpp diff --git a/src/common/dlgcmn.cpp b/src/common/dlgcmn.cpp index 6d3e218315..64011f46c7 100644 --- a/src/common/dlgcmn.cpp +++ b/src/common/dlgcmn.cpp @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "dialogbase.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -40,6 +36,9 @@ #include "wx/containr.h" #endif +#include "wx/statline.h" +#include "wx/sysopt.h" + #if wxUSE_STATTEXT // ---------------------------------------------------------------------------- @@ -57,6 +56,9 @@ public: // max line width or -1 to disable wrapping void Wrap(wxWindow *win, const wxString& text, int widthMax); + // we don't need it, but just to avoid compiler warnings + virtual ~wxTextWrapper() { } + protected: // line may be empty virtual void OnOutputLine(const wxString& line) = 0; @@ -109,7 +111,8 @@ void wxDialogBase::Init() { m_returnCode = 0; m_affirmativeId = wxID_OK; - + m_escapeId = wxID_ANY; + // the dialogs have this flag on by default to prevent the events from the // dialog controls from reaching the parent frame which is usually // undesirable and can lead to unexpected and hard to find bugs @@ -174,6 +177,44 @@ void wxTextWrapper::Wrap(wxWindow *win, const wxString& text, int widthMax) } } +class wxTextSizerWrapper : public wxTextWrapper +{ +public: + wxTextSizerWrapper(wxWindow *win) + { + m_win = win; + m_hLine = 0; + } + + wxSizer *CreateSizer(const wxString& text, int widthMax) + { + m_sizer = new wxBoxSizer(wxVERTICAL); + Wrap(m_win, text, widthMax); + return m_sizer; + } + +protected: + virtual void OnOutputLine(const wxString& line) + { + if ( !line.empty() ) + { + m_sizer->Add(new wxStaticText(m_win, wxID_ANY, line)); + } + else // empty line, no need to create a control for it + { + if ( !m_hLine ) + m_hLine = m_win->GetCharHeight(); + + m_sizer->Add(5, m_hLine); + } + } + +private: + wxWindow *m_win; + wxSizer *m_sizer; + int m_hLine; +}; + wxSizer *wxDialogBase::CreateTextSizer(const wxString& message) { // I admit that this is complete bogus, but it makes @@ -191,88 +232,58 @@ wxSizer *wxDialogBase::CreateTextSizer(const wxString& message) wxString text(message); text.Replace(_T("&"), _T("&&")); - - class TextSizerWrapper : public wxTextWrapper - { - public: - TextSizerWrapper(wxWindow *win) - { - m_win = win; - m_hLine = 0; - } - - wxSizer *CreateSizer(const wxString& text, int widthMax) - { - m_sizer = new wxBoxSizer(wxVERTICAL); - Wrap(m_win, text, widthMax); - return m_sizer; - } - - protected: - virtual void OnOutputLine(const wxString& line) - { - if ( !line.empty() ) - { - m_sizer->Add(new wxStaticText(m_win, wxID_ANY, line)); - } - else // empty line, no need to create a control for it - { - if ( !m_hLine ) - m_hLine = m_win->GetCharHeight(); - - m_sizer->Add(5, m_hLine); - } - } - - private: - wxWindow *m_win; - wxSizer *m_sizer; - int m_hLine; - }; - - TextSizerWrapper wrapper(this); + wxTextSizerWrapper wrapper(this); return wrapper.CreateSizer(text, widthMax); } -void wxStaticTextBase::Wrap(int width) +class wxLabelWrapper : public wxTextWrapper { - class LabelWrapper : public wxTextWrapper +public: + void WrapLabel(wxWindow *text, int widthMax) { - public: - void WrapLabel(wxStaticTextBase *text, int widthMax) - { - m_text.clear(); - Wrap(text, text->GetLabel(), widthMax); - text->SetLabel(m_text); - } + m_text.clear(); + Wrap(text, text->GetLabel(), widthMax); + text->SetLabel(m_text); + } - protected: - virtual void OnOutputLine(const wxString& line) - { - m_text += line; - } +protected: + virtual void OnOutputLine(const wxString& line) + { + m_text += line; + } - virtual void OnNewLine() - { - m_text += _T('\n'); - } + virtual void OnNewLine() + { + m_text += _T('\n'); + } - private: - wxString m_text; - }; +private: + wxString m_text; +}; - LabelWrapper wrapper; +// NB: don't "factor out" the scope operator, SGI MIPSpro 7.3 (but not 7.4) +// gets confused if it doesn't immediately follow the class name +void +#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) +wxStaticText:: +#else +wxStaticTextBase:: +#endif +Wrap(int width) +{ + wxLabelWrapper wrapper; wrapper.WrapLabel(this, width); } #endif // wxUSE_STATTEXT -#if wxUSE_BUTTON - -wxSizer *wxDialogBase::CreateButtonSizer( long flags ) +wxSizer *wxDialogBase::CreateButtonSizer( long flags, bool separated, wxCoord distance ) { #ifdef __SMARTPHONE__ + wxUnusedVar(separated); + wxUnusedVar(distance); + wxDialog* dialog = (wxDialog*) this; if (flags & wxOK){ dialog->SetLeftMenu(wxID_OK); @@ -291,14 +302,64 @@ wxSizer *wxDialogBase::CreateButtonSizer( long flags ) } wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); return sizer; -#else - return CreateStdDialogButtonSizer( flags ); -#endif + +#else // !__SMARTPHONE__ + +#ifdef __POCKETPC__ + // PocketPC guidelines recommend for Ok/Cancel dialogs to use + // OK button located inside caption bar and implement Cancel functionality + // through Undo outside dialog. As native behaviour this will be default + // here but can be easily replaced with real wxButtons + // with "wince.dialog.real-ok-cancel" option set to 1 + if ( ((flags & ~(wxCANCEL|wxNO_DEFAULT))== wxOK) && + (wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"))==0) + ) + { + wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); + return sizer; + } +#endif // __POCKETPC__ + +#if wxUSE_BUTTON + + wxSizer* buttonSizer = CreateStdDialogButtonSizer( flags ); + + // Mac Human Interface Guidelines recommend not to use static lines as grouping elements +#if wxUSE_STATLINE && !defined(__WXMAC__) + if(!separated) + return buttonSizer; + + wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); + topsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxBOTTOM, distance ); + topsizer->Add( buttonSizer, 0, wxEXPAND ); + return topsizer; + +#else // !wxUSE_STATLINE + + wxUnusedVar(separated); + wxUnusedVar(distance); + return buttonSizer; + +#endif // wxUSE_STATLINE/!wxUSE_STATLINE + +#else // !wxUSE_BUTTON + + wxUnusedVar(separated); + wxUnusedVar(distance); + wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); + return sizer; + +#endif // wxUSE_BUTTON/!wxUSE_BUTTON + +#endif // __SMARTPHONE__/!__SMARTPHONE__ } +#if wxUSE_BUTTON + wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags ) { wxStdDialogButtonSizer *sizer = new wxStdDialogButtonSizer(); + wxButton *ok = NULL; wxButton *yes = NULL; wxButton *no = NULL; @@ -328,8 +389,6 @@ wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags ) sizer->AddButton(help); } - sizer->Realize(); - if (flags & wxNO_DEFAULT) { if (no) @@ -351,14 +410,15 @@ wxStdDialogButtonSizer *wxDialogBase::CreateStdDialogButtonSizer( long flags ) yes->SetFocus(); } } - + if (flags & wxOK) SetAffirmativeId(wxID_OK); else if (flags & wxYES) SetAffirmativeId(wxID_YES); + sizer->Realize(); + return sizer; } - #endif // wxUSE_BUTTON