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.
This commit is contained in:
Artur Wieczorek
2018-07-06 22:56:55 +02:00
parent 5766280311
commit 858b5e7222

View File

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