]> git.saurik.com Git - wxWidgets.git/commitdiff
Destroy modeless wxGenericAboutDialog when it is closed.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 20 Jan 2012 22:11:32 +0000 (22:11 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 20 Jan 2012 22:11:32 +0000 (22:11 +0000)
Don't leave the wxGenericAboutDialog object alive when non-modal about dialog
(as can be used under GTK and OS X) is closed. This is wasteful and, worse,
resulted in the program not exiting after such a dialog was shown because it
counted as a remaining open top level window.

This also fixes the same bug in wxGTK when using GTK+ 2.4.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70413 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/aboutdlgg.h
src/generic/aboutdlgg.cpp

index e45fc24d0dfad86ae9db78675ff6cb3ccd2065b7..9ad4a77e414d47012ab0b66fda1b95c015462835 100644 (file)
@@ -21,6 +21,16 @@ class WXDLLIMPEXP_FWD_ADV wxAboutDialogInfo;
 class WXDLLIMPEXP_FWD_CORE wxSizer;
 class WXDLLIMPEXP_FWD_CORE wxSizerFlags;
 
+// Under GTK and OS X "About" dialogs are not supposed to be modal, unlike MSW
+// and, presumably, all the other platforms.
+#ifndef wxUSE_MODAL_ABOUT_DIALOG
+    #if defined(__WXGTK__) || defined(__WXMAC__)
+        #define wxUSE_MODAL_ABOUT_DIALOG 0
+    #else
+        #define wxUSE_MODAL_ABOUT_DIALOG 1
+    #endif
+#endif // wxUSE_MODAL_ABOUT_DIALOG not defined
+
 // ----------------------------------------------------------------------------
 // wxGenericAboutDialog: generic "About" dialog implementation
 // ----------------------------------------------------------------------------
@@ -73,6 +83,12 @@ private:
     // common part of all ctors
     void Init() { m_sizerText = NULL; }
 
+#if !wxUSE_MODAL_ABOUT_DIALOG
+    // An explicit handler for deleting the dialog when it's closed is needed
+    // when we show it non-modally.
+    void OnCloseWindow(wxCloseEvent& event);
+    void OnOK(wxCommandEvent& event);
+#endif // !wxUSE_MODAL_ABOUT_DIALOG
 
     wxSizer *m_sizerText;
 };
index ee338f01baff8988e3fd8acbdcde218ac0dbbe80..ba95a1cc7443fc402581c89c82c4beefb0bf5a70 100644 (file)
@@ -220,6 +220,13 @@ bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info, wxWindow* paren
 
     CentreOnParent();
 
+#if !wxUSE_MODAL_ABOUT_DIALOG
+    Connect(wxEVT_CLOSE_WINDOW,
+            wxCloseEventHandler(wxGenericAboutDialog::OnCloseWindow));
+    Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
+            wxCommandEventHandler(wxGenericAboutDialog::OnOK));
+#endif // !wxUSE_MODAL_ABOUT_DIALOG
+
     return true;
 }
 
@@ -265,13 +272,31 @@ void wxGenericAboutDialog::AddCollapsiblePane(const wxString& title,
     m_sizerText->Add(pane, wxSizerFlags(0).Expand().Border(wxBOTTOM));
 }
 
+#if !wxUSE_MODAL_ABOUT_DIALOG
+
+void wxGenericAboutDialog::OnCloseWindow(wxCloseEvent& event)
+{
+    Destroy();
+
+    event.Skip();
+}
+
+void wxGenericAboutDialog::OnOK(wxCommandEvent& WXUNUSED(event))
+{
+    // By default a modeless dialog would be just hidden, destroy this one
+    // instead.
+    Destroy();
+}
+
+#endif // !wxUSE_MODAL_ABOUT_DIALOG
+
 // ----------------------------------------------------------------------------
 // public functions
 // ----------------------------------------------------------------------------
 
 void wxGenericAboutBox(const wxAboutDialogInfo& info, wxWindow* parent)
 {
-#if !defined(__WXGTK__) && !defined(__WXMAC__)
+#if wxUSE_MODAL_ABOUT_DIALOG
     wxGenericAboutDialog dlg(info, parent);
     dlg.ShowModal();
 #else