]> git.saurik.com Git - wxWidgets.git/commitdiff
Allow to specify the title used by wxPreferencesEditor window.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 16 May 2013 14:42:56 +0000 (14:42 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 16 May 2013 14:42:56 +0000 (14:42 +0000)
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

include/wx/preferences.h
include/wx/private/preferences.h
interface/wx/preferences.h
src/common/preferencescmn.cpp
src/generic/preferencesg.cpp
src/osx/cocoa/preferences.mm

index 42f66c5910693f76654a5ddcf0620b83d8e80b7c..472ea8f57ba558f0ee0995693dd445d13d43b703 100644 (file)
@@ -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
index 05ce8f5b1fcfbdc45930728e3b7f9f399ae2609f..f68893a99de4e83cf18c7569853267eecb3f072b 100644 (file)
@@ -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;
index 074a31ca9497d53535effdd81e4fc8be0c19fcb1..3688fa3e06384e702243c421793ddf1c80b96065 100644 (file)
@@ -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.
index 899dc36d2d178315e32370c8cd8b80efd341695a..f4dca37a2330e2de5e066d514ae677bcf209bbf7 100644 (file)
@@ -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))
 {
 }
 
index 72624a93eca129d1640f3b3056b87e06aa4dc77a..1481c633025b8b0f6fe3aa95b2dcb9f2fd404866 100644 (file)
 #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<wxPreferencesPage>(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<wxPreferencesPage> > Pages;
     Pages m_pages;
 
+private:
+    wxString m_title;
 };
 
 
@@ -161,6 +174,12 @@ private:
     wxWeakRef<wxWindow> 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
index 28d80e3129533cfbf827e8ee4d3adc98a11c2450..81160c7b3e4d3be0e8456ac4e743342b96b2a8c4 100644 (file)
@@ -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<wxCocoaPrefsWindow> 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