]> git.saurik.com Git - wxWidgets.git/commitdiff
Close a modal dialog even when it doesn't have any buttons.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 27 Sep 2010 11:52:06 +0000 (11:52 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 27 Sep 2010 11:52:06 +0000 (11:52 +0000)
The close button in the dialog title bar should work even if there are no
buttons in the dialog itself (unlike the Escape key which works as an
accelerator for a button), so close the dialog explicitly if the emulated
button click wasn't processed in wxDialogBase::OnCloseWindow().

Closes #12513.

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

src/common/dlgcmn.cpp

index 605365867d708f55a09434e4d4deefc7732d098d..fbe210600960cbd4d9119ab64a61edd68b9d3d01 100644 (file)
@@ -503,15 +503,17 @@ void wxDialogBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 
     closing.Append(this);
 
-    // Note that if a cancel button and handler aren't present in the dialog,
-    // nothing will happen when you close the dialog via the window manager, or
-    // via Close(). We wouldn't want to destroy the dialog by default, since
-    // the dialog may have been created on the stack. However, this does mean
-    // that calling dialog->Close() won't delete the dialog unless the handler
-    // for wxID_CANCEL does so. So use Destroy() if you want to be sure to
-    // destroy the dialog. The default OnCancel (above) simply ends a modal
-    // dialog, and hides a modeless dialog.
-    SendCloseButtonClickEvent();
+    if ( !SendCloseButtonClickEvent() )
+    {
+        // If the handler didn't close the dialog (e.g. because there is no
+        // button with matching id) we still want to close it when the user
+        // clicks the "x" button in the title bar, otherwise we shouldn't even
+        // have put it there.
+        //
+        // Notice that using wxID_CLOSE might have been a better choice but we
+        // use wxID_CANCEL for compatibility reasons.
+        EndDialog(wxID_CANCEL);
+    }
 
     closing.DeleteObject(this);
 }