diff --git a/include/wx/preferences.h b/include/wx/preferences.h index ab1e0a2c99..1a07fd857b 100644 --- a/include/wx/preferences.h +++ b/include/wx/preferences.h @@ -104,8 +104,7 @@ public: // platform, i.e. depending on whether the dialog is modal or not. virtual void Show(wxWindow* parent); - // Hide the currently shown dialog, if any. This doesn't do anything on the - // platforms using modal preferences dialogs but should be called to + // Hide the currently shown dialog, if any. This is typically used to // dismiss the dialog if the object whose preferences it is editing was // closed. void Dismiss(); diff --git a/interface/wx/preferences.h b/interface/wx/preferences.h index 161d78755c..7e0e9f679e 100644 --- a/interface/wx/preferences.h +++ b/interface/wx/preferences.h @@ -82,9 +82,8 @@ public: /** Hide the currently shown dialog, if any. - This doesn't do anything on the platforms using modal preferences - dialogs (e.g. Windows) but should be called to dismiss the dialog if - the object whose preferences it is editing was closed. + This is typically called to dismiss the dialog if the object whose + preferences it is editing was closed. */ void Dismiss(); diff --git a/src/generic/preferencesg.cpp b/src/generic/preferencesg.cpp index 30365e7ebc..231185beed 100644 --- a/src/generic/preferencesg.cpp +++ b/src/generic/preferencesg.cpp @@ -33,6 +33,7 @@ #include "wx/sizer.h" #include "wx/sharedptr.h" #include "wx/scopedptr.h" +#include "wx/scopeguard.h" #include "wx/vector.h" namespace @@ -193,12 +194,19 @@ class wxModalPreferencesEditorImpl : public wxGenericPreferencesEditorImplBase public: wxModalPreferencesEditorImpl() { + m_dlg = NULL; m_currentPage = -1; } virtual void Show(wxWindow* parent) { wxScopedPtr dlg(CreateDialog(parent)); + + // 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); + dlg->Fit(); // Restore the previously selected page, if any. @@ -212,11 +220,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