From: Vadim Zeitlin Date: Thu, 16 May 2013 14:42:56 +0000 (+0000) Subject: Allow to specify the title used by wxPreferencesEditor window. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/654c4b7b14bae64a11ac652984833a048ae832ea?ds=inline Allow to specify the title used by wxPreferencesEditor window. Customize the title is useful for "Settings"-style windows which are used for editing the properties of the given object, that should be identified in the window title, as opposed to the global program preferences. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74006 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/preferences.h b/include/wx/preferences.h index 42f66c5910..472ea8f57b 100644 --- a/include/wx/preferences.h +++ b/include/wx/preferences.h @@ -88,7 +88,7 @@ class WXDLLIMPEXP_CORE wxPreferencesEditor { public: // Ctor creates an empty editor, use AddPage() to add controls to it. - wxPreferencesEditor(); + wxPreferencesEditor(const wxString& title = wxString()); ~wxPreferencesEditor(); // Add a new page to the editor. The editor takes ownership of the page diff --git a/include/wx/private/preferences.h b/include/wx/private/preferences.h index 05ce8f5b1f..f68893a99d 100644 --- a/include/wx/private/preferences.h +++ b/include/wx/private/preferences.h @@ -29,7 +29,7 @@ class wxPreferencesEditorImpl { public: // This is implemented in a platform-specific way. - static wxPreferencesEditorImpl* Create(); + static wxPreferencesEditorImpl* Create(const wxString& title); // These methods simply mirror the public wxPreferencesEditor ones. virtual void AddPage(wxPreferencesPage* page) = 0; diff --git a/interface/wx/preferences.h b/interface/wx/preferences.h index 074a31ca94..3688fa3e06 100644 --- a/interface/wx/preferences.h +++ b/interface/wx/preferences.h @@ -38,8 +38,13 @@ public: Constructor. Creates an empty editor, use AddPage() to add controls to it. + + @param title The title overriding the default title of the top level + window used by the editor. It is recommended to not specify this + parameter to use the native convention for the preferences dialogs + instead. */ - wxPreferencesEditor(); + wxPreferencesEditor(const wxString& title = wxString()); /** Destructor. diff --git a/src/common/preferencescmn.cpp b/src/common/preferencescmn.cpp index 899dc36d2d..f4dca37a23 100644 --- a/src/common/preferencescmn.cpp +++ b/src/common/preferencescmn.cpp @@ -42,8 +42,8 @@ wxString wxStockPreferencesPage::GetName() const return wxString(); // silence compiler warning } -wxPreferencesEditor::wxPreferencesEditor() - : m_impl(wxPreferencesEditorImpl::Create()) +wxPreferencesEditor::wxPreferencesEditor(const wxString& title) + : m_impl(wxPreferencesEditorImpl::Create(title)) { } diff --git a/src/generic/preferencesg.cpp b/src/generic/preferencesg.cpp index 72624a93ec..1481c63302 100644 --- a/src/generic/preferencesg.cpp +++ b/src/generic/preferencesg.cpp @@ -34,11 +34,14 @@ #include "wx/scopedptr.h" #include "wx/vector.h" +namespace +{ + class wxGenericPrefsDialog : public wxDialog { public: - wxGenericPrefsDialog(wxWindow *parent) - : wxDialog(parent, wxID_ANY, _("Preferences"), + wxGenericPrefsDialog(wxWindow *parent, const wxString& title) + : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE & ~(wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxMINIMIZE_BOX)) { @@ -83,6 +86,11 @@ private: class wxGenericPreferencesEditorImplBase : public wxPreferencesEditorImpl { public: + void SetTitle(const wxString& title) + { + m_title = title; + } + virtual void AddPage(wxPreferencesPage* page) { m_pages.push_back(wxSharedPtr(page)); @@ -91,7 +99,10 @@ public: protected: wxGenericPrefsDialog *CreateDialog(wxWindow *parent) { - wxGenericPrefsDialog *dlg = new wxGenericPrefsDialog(parent); + if ( m_title.empty() ) + m_title = _("Preferences"); + + wxGenericPrefsDialog *dlg = new wxGenericPrefsDialog(parent, m_title); // TODO: Don't create all pages immediately like this, do it on demand // when a page is selected in the notebook (as is done on OS X). @@ -113,6 +124,8 @@ protected: typedef wxVector< wxSharedPtr > Pages; Pages m_pages; +private: + wxString m_title; }; @@ -161,6 +174,12 @@ private: wxWeakRef m_win; }; +inline +wxGenericPreferencesEditorImplBase* NewGenericImpl() +{ + return new wxModelessPreferencesEditorImpl; +} + #else // !wxHAS_PREF_EDITOR_MODELESS class wxModalPreferencesEditorImpl : public wxGenericPreferencesEditorImplBase @@ -194,17 +213,24 @@ private: int m_currentPage; }; +inline +wxGenericPreferencesEditorImplBase* NewGenericImpl() +{ + return new wxModalPreferencesEditorImpl; +} + #endif // !wxHAS_PREF_EDITOR_MODELESS +} // anonymous namespace /*static*/ -wxPreferencesEditorImpl* wxPreferencesEditorImpl::Create() +wxPreferencesEditorImpl* wxPreferencesEditorImpl::Create(const wxString& title) { -#ifdef wxHAS_PREF_EDITOR_MODELESS - return new wxModelessPreferencesEditorImpl(); -#else - return new wxModalPreferencesEditorImpl(); -#endif + wxGenericPreferencesEditorImplBase* const impl = NewGenericImpl(); + + impl->SetTitle(title); + + return impl; } #endif // !wxHAS_PREF_EDITOR_NATIVE diff --git a/src/osx/cocoa/preferences.mm b/src/osx/cocoa/preferences.mm index 28d80e3129..81160c7b3e 100644 --- a/src/osx/cocoa/preferences.mm +++ b/src/osx/cocoa/preferences.mm @@ -54,8 +54,8 @@ wxBitmap wxStockPreferencesPage::GetLargeIcon() const class wxCocoaPrefsWindow : public wxFrame { public: - wxCocoaPrefsWindow() - : wxFrame(NULL, wxID_ANY, _("Preferences"), + wxCocoaPrefsWindow(const wxString& title) + : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE & ~(wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxMINIMIZE_BOX)), m_toolbarRealized(false), @@ -191,7 +191,8 @@ private: class wxCocoaPreferencesEditorImpl : public wxPreferencesEditorImpl { public: - wxCocoaPreferencesEditorImpl() : m_win(NULL) + wxCocoaPreferencesEditorImpl(const wxString& title) + : m_win(NULL), m_title(title) { } @@ -232,17 +233,25 @@ private: wxCocoaPrefsWindow* GetWin() { if ( !m_win ) - m_win = new wxCocoaPrefsWindow(); + { + if ( m_title.empty() ) + m_title = _("Preferences"); + + m_win = new wxCocoaPrefsWindow(m_title); + } + return m_win; } wxWeakRef m_win; + + wxString m_title; }; /*static*/ -wxPreferencesEditorImpl* wxPreferencesEditorImpl::Create() +wxPreferencesEditorImpl* wxPreferencesEditorImpl::Create(const wxString& title) { - return new wxCocoaPreferencesEditorImpl(); + return new wxCocoaPreferencesEditorImpl(title); } #endif // wxHAS_PREF_EDITOR_NATIVE