]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/preferencesg.cpp
using Run of base class
[wxWidgets.git] / src / generic / preferencesg.cpp
index 30365e7ebc44ceb2c8f710a010d73688a6492c6a..97236af30522c4a29a37a55e3b71a9edc60a3909 100644 (file)
@@ -3,7 +3,6 @@
 // Purpose:     Implementation of wxPreferencesEditor.
 // Author:      Vaclav Slavik
 // Created:     2013-02-19
-// RCS-ID:      $Id$
 // Copyright:   (c) 2013 Vaclav Slavik <vslavik@fastmail.fm>
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
@@ -23,6 +22,8 @@
     #pragma hdrstop
 #endif
 
+#if wxUSE_PREFERENCES_EDITOR
+
 #include "wx/private/preferences.h"
 
 #ifndef wxHAS_PREF_EDITOR_NATIVE
@@ -33,6 +34,7 @@
 #include "wx/sizer.h"
 #include "wx/sharedptr.h"
 #include "wx/scopedptr.h"
+#include "wx/scopeguard.h"
 #include "wx/vector.h"
 
 namespace
@@ -124,6 +126,8 @@ protected:
             dlg->AddPage(i->get());
         }
 
+        dlg->Fit();
+
         return dlg;
     }
 
@@ -193,13 +197,18 @@ class wxModalPreferencesEditorImpl : public wxGenericPreferencesEditorImplBase
 public:
     wxModalPreferencesEditorImpl()
     {
+        m_dlg = NULL;
         m_currentPage = -1;
     }
 
     virtual void Show(wxWindow* parent)
     {
         wxScopedPtr<wxGenericPrefsDialog> dlg(CreateDialog(parent));
-        dlg->Fit();
+
+        // Store it for Dismiss() but ensure that the pointer is reset to NULL
+        // when the dialog is destroyed on leaving this function.
+        m_dlg = dlg.get();
+        wxON_BLOCK_EXIT_NULL(m_dlg);
 
         // Restore the previously selected page, if any.
         if ( m_currentPage != -1 )
@@ -212,11 +221,18 @@ public:
 
     virtual void Dismiss()
     {
-        // nothing to do
+        if ( m_dlg )
+        {
+            m_dlg->EndModal(wxID_CANCEL);
+            m_dlg = NULL;
+        }
     }
 
 private:
+    wxGenericPrefsDialog* m_dlg;
     int m_currentPage;
+
+    wxDECLARE_NO_COPY_CLASS(wxModalPreferencesEditorImpl);
 };
 
 inline
@@ -240,3 +256,5 @@ wxPreferencesEditorImpl* wxPreferencesEditorImpl::Create(const wxString& title)
 }
 
 #endif // !wxHAS_PREF_EDITOR_NATIVE
+
+#endif // wxUSE_PREFERENCES_EDITOR