Make native dialogs application-modal in wxMSW

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.
This commit is contained in:
Vadim Zeitlin
2022-04-01 01:47:06 +01:00
parent b2b58ee6cf
commit d311c705d7
7 changed files with 16 additions and 0 deletions

View File

@@ -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;

View File

@@ -152,6 +152,8 @@ int wxDirDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();
wxWindowDisabler disableOthers(this);
wxWindow* const parent = GetParentForModalDialog();
WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL;

View File

@@ -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;

View File

@@ -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

View File

@@ -539,6 +539,8 @@ int wxMessageDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();
wxWindowDisabler disableOthers(this);
#ifdef wxHAS_MSW_TASKDIALOG
if ( HasNativeTaskDialog() )
{

View File

@@ -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"
@@ -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;

View File

@@ -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
@@ -36,6 +37,8 @@ int wxRichMessageDialog::ShowModal()
if ( HasNativeTaskDialog() )
{
wxWindowDisabler disableOthers(this);
// create a task dialog
WinStruct<TASKDIALOGCONFIG> tdc;
wxMSWTaskDialogConfig wxTdc(*this);