Skip to content

Commit

Permalink
Fix restoring focus after showing native modal dialogs in wxMSW
Browse files Browse the repository at this point in the history
This fixes a regression introduced in d311c70 (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.
  • Loading branch information
vadz committed Apr 7, 2022
1 parent 717e851 commit a5a5b1b
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/msw/colordlg.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/msw/dirdlg.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/msw/filedlg.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/msw/fontdlg.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/msw/msgdlg.cpp
Expand Up @@ -539,7 +539,7 @@ int wxMessageDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();

wxWindowDisabler disableOthers(this);
wxWindowDisabler disableOthers(this, GetParent());

#ifdef wxHAS_MSW_TASKDIALOG
if ( HasNativeTaskDialog() )
Expand Down
2 changes: 1 addition & 1 deletion src/msw/printdlg.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/msw/richmsgdlg.cpp
Expand Up @@ -37,7 +37,7 @@ int wxRichMessageDialog::ShowModal()

if ( HasNativeTaskDialog() )
{
wxWindowDisabler disableOthers(this);
wxWindowDisabler disableOthers(this, GetParent());

// create a task dialog
WinStruct<TASKDIALOGCONFIG> tdc;
Expand Down

0 comments on commit a5a5b1b

Please sign in to comment.