From a5a5b1bb1553946dbd2b19cff7bf2fbfc9c0717c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 7 Apr 2022 23:43:53 +0100 Subject: [PATCH] Fix restoring focus after showing native modal dialogs in wxMSW This fixes a regression introduced in d311c705d7 (Make native dialogs application-modal in wxMSW, 2022-04-01) which resulted in a focus loss after showing a modal dialog, as the parent window was still disabled when the native modal dialog was closed and so focus couldn't be set to any of its children and was simply lost as the result. Fix this by not disabling the dialog parent ourselves, but leaving handling the parent status to the native modal dialog, which already takes care of disabling the parent it uses when it is shown and re-enabling it when it is dismissed. Still use wxWindowDisabler to disable all the other top level windows, if any, to ensure that the modal dialogs are truly app-modal and not just window-modal, i.e. ensure that #11887 still remains fixed. Closes #22285. --- src/msw/colordlg.cpp | 2 +- src/msw/dirdlg.cpp | 2 +- src/msw/filedlg.cpp | 2 +- src/msw/fontdlg.cpp | 2 +- src/msw/msgdlg.cpp | 2 +- src/msw/printdlg.cpp | 2 +- src/msw/richmsgdlg.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/msw/colordlg.cpp b/src/msw/colordlg.cpp index 882416ddba..06148c24c8 100644 --- a/src/msw/colordlg.cpp +++ b/src/msw/colordlg.cpp @@ -177,7 +177,7 @@ int wxColourDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); - wxWindowDisabler disableOthers(this); + wxWindowDisabler disableOthers(this, GetParent()); wxWindow* const parent = GetParentForModalDialog(m_parent, GetWindowStyle()); WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL; diff --git a/src/msw/dirdlg.cpp b/src/msw/dirdlg.cpp index c520ccbd4d..06d1d92d31 100644 --- a/src/msw/dirdlg.cpp +++ b/src/msw/dirdlg.cpp @@ -152,7 +152,7 @@ int wxDirDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); - wxWindowDisabler disableOthers(this); + wxWindowDisabler disableOthers(this, GetParent()); wxWindow* const parent = GetParentForModalDialog(); WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL; diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index 148b00e916..1baed379cc 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -430,7 +430,7 @@ int wxFileDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); - wxWindowDisabler disableOthers(this); + wxWindowDisabler disableOthers(this, GetParent()); wxWindow* const parent = GetParentForModalDialog(m_parent, GetWindowStyle()); WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL; diff --git a/src/msw/fontdlg.cpp b/src/msw/fontdlg.cpp index fa9d2e3641..c70b55ac50 100644 --- a/src/msw/fontdlg.cpp +++ b/src/msw/fontdlg.cpp @@ -92,7 +92,7 @@ int wxFontDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); - wxWindowDisabler disableOthers(this); + wxWindowDisabler disableOthers(this, GetParent()); wxWindow* const parent = GetParentForModalDialog(m_parent, GetWindowStyle()); WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL; diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index a6f40a1324..21da7f0a5e 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -539,7 +539,7 @@ int wxMessageDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); - wxWindowDisabler disableOthers(this); + wxWindowDisabler disableOthers(this, GetParent()); #ifdef wxHAS_MSW_TASKDIALOG if ( HasNativeTaskDialog() ) diff --git a/src/msw/printdlg.cpp b/src/msw/printdlg.cpp index ac3a54097e..eb09925777 100644 --- a/src/msw/printdlg.cpp +++ b/src/msw/printdlg.cpp @@ -806,7 +806,7 @@ int wxWindowsPrintDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); - wxWindowDisabler disableOthers(this); + wxWindowDisabler disableOthers(this, GetParent()); wxWindow* const parent = GetParentForModalDialog(m_parent, GetWindowStyle()); WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL; diff --git a/src/msw/richmsgdlg.cpp b/src/msw/richmsgdlg.cpp index 488505e4ce..07d44ab143 100644 --- a/src/msw/richmsgdlg.cpp +++ b/src/msw/richmsgdlg.cpp @@ -37,7 +37,7 @@ int wxRichMessageDialog::ShowModal() if ( HasNativeTaskDialog() ) { - wxWindowDisabler disableOthers(this); + wxWindowDisabler disableOthers(this, GetParent()); // create a task dialog WinStruct tdc;