From 18c8dd2be24fb5dcdb2a23e27a98abd67a1e0bde Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 26 Apr 2011 22:57:30 +0000 Subject: [PATCH] Ensure that message boxes with only "OK" can be closed with Escape in wxMSW. The native task dialog doesn't allow using Escape (nor Alt-F4 but this is less annoying) to close it unless it has a Cancel button, so by default the dialogs with only "OK" couldn't be closed with Escape. Work around this by creating a Cancel button with "OK" label instead. This is not ideal but there doesn't seem to be any other way to make this work. See #12501. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67620 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/msgdlg.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index c66806fee4..2334638d82 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -721,16 +721,29 @@ void wxMSWTaskDialogConfig::MSWCommonTaskDialogInit(TASKDIALOGCONFIG &tdc) } else // without Yes/No we're going to have an OK button { - AddTaskDialogButton(tdc, IDOK, TDCBF_OK_BUTTON, btnOKLabel); - if ( style & wxCANCEL ) { + AddTaskDialogButton(tdc, IDOK, TDCBF_OK_BUTTON, btnOKLabel); AddTaskDialogButton(tdc, IDCANCEL, TDCBF_CANCEL_BUTTON, btnCancelLabel); if ( style & wxCANCEL_DEFAULT ) tdc.nDefaultButton = IDCANCEL; } + else // Only "OK" + { + // We actually create a "Cancel" button instead because we want to + // allow closing the dialog box with Escape (and also Alt-F4 or + // clicking the close button in the title bar) which wouldn't work + // without a Cancel button. + if ( !useCustomLabels ) + { + useCustomLabels = true; + btnOKLabel = _("OK"); + } + + AddTaskDialogButton(tdc, IDCANCEL, TDCBF_CANCEL_BUTTON, btnOKLabel); + } } } -- 2.45.2