From: Vadim Zeitlin Date: Mon, 27 Sep 2010 11:52:06 +0000 (+0000) Subject: Close a modal dialog even when it doesn't have any buttons. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ffc71ce59daf0b93697aac0a50bb3fdb9391b0ca?ds=inline Close a modal dialog even when it doesn't have any buttons. 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 --- diff --git a/src/common/dlgcmn.cpp b/src/common/dlgcmn.cpp index 605365867d..fbe2106009 100644 --- a/src/common/dlgcmn.cpp +++ b/src/common/dlgcmn.cpp @@ -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); }