Skip to content

Commit

Permalink
Make native dialogs application-modal in wxMSW
Browse files Browse the repository at this point in the history
Being able to use other application windows while a modal dialog was
shown was unexpected and could easily result in nasty reentrancies, and
was also inconsistent with the behaviour of ShowModal() for the dialogs
defined in wx, so disable all the windows, not just the parent one,
while showing the native modal dialogs too.

Closes #11887.
  • Loading branch information
vadz committed Apr 1, 2022
1 parent b2b58ee commit d311c70
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/msw/colordlg.cpp
Expand Up @@ -177,6 +177,8 @@ int wxColourDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();

wxWindowDisabler disableOthers(this);

wxWindow* const parent = GetParentForModalDialog(m_parent, GetWindowStyle());
WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL;

Expand Down
2 changes: 2 additions & 0 deletions src/msw/dirdlg.cpp
Expand Up @@ -152,6 +152,8 @@ int wxDirDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();

wxWindowDisabler disableOthers(this);

wxWindow* const parent = GetParentForModalDialog();
WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL;

Expand Down
2 changes: 2 additions & 0 deletions src/msw/filedlg.cpp
Expand Up @@ -430,6 +430,8 @@ int wxFileDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();

wxWindowDisabler disableOthers(this);

wxWindow* const parent = GetParentForModalDialog(m_parent, GetWindowStyle());
WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL;

Expand Down
2 changes: 2 additions & 0 deletions src/msw/fontdlg.cpp
Expand Up @@ -92,6 +92,8 @@ int wxFontDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();

wxWindowDisabler disableOthers(this);

wxWindow* const parent = GetParentForModalDialog(m_parent, GetWindowStyle());
WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL;
// It should be OK to always use GDI simulations
Expand Down
2 changes: 2 additions & 0 deletions src/msw/msgdlg.cpp
Expand Up @@ -539,6 +539,8 @@ int wxMessageDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();

wxWindowDisabler disableOthers(this);

#ifdef wxHAS_MSW_TASKDIALOG
if ( HasNativeTaskDialog() )
{
Expand Down
3 changes: 3 additions & 0 deletions src/msw/printdlg.cpp
Expand Up @@ -29,6 +29,7 @@
#include "wx/app.h"
#include "wx/dcprint.h"
#include "wx/cmndata.h"
#include "wx/utils.h" // for wxWindowDisabler
#endif

#include "wx/printdlg.h"
Expand Down Expand Up @@ -805,6 +806,8 @@ int wxWindowsPrintDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();

wxWindowDisabler disableOthers(this);

wxWindow* const parent = GetParentForModalDialog(m_parent, GetWindowStyle());
WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL;

Expand Down
3 changes: 3 additions & 0 deletions src/msw/richmsgdlg.cpp
Expand Up @@ -17,6 +17,7 @@

#ifndef WX_PRECOMP
#include "wx/msw/private.h"
#include "wx/utils.h" // for wxWindowDisabler
#endif

// This will define wxHAS_MSW_TASKDIALOG if we have support for it in the
Expand All @@ -36,6 +37,8 @@ int wxRichMessageDialog::ShowModal()

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

// create a task dialog
WinStruct<TASKDIALOGCONFIG> tdc;
wxMSWTaskDialogConfig wxTdc(*this);
Expand Down

0 comments on commit d311c70

Please sign in to comment.