From 322877484dfe1a510afee8fe7c81eae8f74e7c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 28 Oct 2013 07:48:14 +0000 Subject: [PATCH] Fix wxWindowModalDialogEvent::GetReturnCode() on Windows. *Lots* of native dialogs don't call SetReturnCode() in their ShowModal() implementations in wxMSW. Rather than fixing them all - and having them accidentally broken again and again in the future - fix this just in the generic ShowWindowModal() implementation. This may not be the most elegant fix, but it is bullet-proof. Also revert previous attempt to fix just wxMessageDialog in r74776. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75089 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/dlgcmn.cpp | 8 +++++++- src/msw/msgdlg.cpp | 8 ++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/common/dlgcmn.cpp b/src/common/dlgcmn.cpp index df7ecdff59..3f73371484 100644 --- a/src/common/dlgcmn.cpp +++ b/src/common/dlgcmn.cpp @@ -517,7 +517,13 @@ IMPLEMENT_DYNAMIC_CLASS(wxWindowModalDialogEvent, wxCommandEvent) void wxDialogBase::ShowWindowModal () { - ShowModal(); + int retval = ShowModal(); + // wxWindowModalDialogEvent relies on GetReturnCode() returning correct + // code. Rather than doing it manually in all ShowModal() overrides for + // native dialogs (and getting accidentally broken again), set it here. + // The worst that can happen is that it will be set twice to the same + // value. + SetReturnCode(retval); SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); } diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index e44ca16d1a..02da8a94d8 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -586,9 +586,7 @@ int wxMessageDialog::ShowMessageBox() // do show the dialog int msAns = MessageBox(hWnd, message.t_str(), m_caption.t_str(), msStyle); - int ret = MSWTranslateReturnCode(msAns); - SetReturnCode(ret); - return ret; + return MSWTranslateReturnCode(msAns); } int wxMessageDialog::ShowModal() @@ -623,9 +621,7 @@ int wxMessageDialog::ShowModal() msAns = IDOK; } - int ret = MSWTranslateReturnCode(msAns); - SetReturnCode(ret); - return ret; + return MSWTranslateReturnCode( msAns ); } #endif // wxHAS_MSW_TASKDIALOG