From 858b5e72220c084c9c56f5aad37eb6512818af52 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 6 Jul 2018 22:56:55 +0200 Subject: [PATCH] Prevent losing the focus by active editor when error dialog box is closed Displaying error dialog can cause on some platforms native focus changes what triggers unwanted focus change events in wxPG and disturbs expected sequence of events. To prevent this from happening (regardless of platform), we need to save focused window before dialog box is displayed and restore it after closing the dialog. Closes #18046. --- src/propgrid/propgrid.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index d2509b993a..0c00b79ee1 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -3280,12 +3280,22 @@ bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty* property, wxVariant& W } #endif + // Displaying error dialog box can cause (native) focus changes + // so let's preserve the current focus in order to restore it afterwards. + wxWindow* focusedWnd = wxWindow::FindFocus(); + if ( vfb & wxPG_VFB_SHOW_MESSAGE ) DoShowPropertyError(property, msg); if ( vfb & wxPG_VFB_SHOW_MESSAGEBOX ) /* TRANSLATORS: Caption of message box displaying any property error */ ::wxMessageBox(msg, _("Property Error")); + + // Restore the focus + if ( focusedWnd ) + { + focusedWnd->SetFocus(); + } } return (vfb & wxPG_VFB_STAY_IN_PROPERTY) ? false : true;