Never restore focus to hidden child.

Don't set focus to a hidden window in our focus management code, this never
makes sense and results in apparent focus loss.

It also fixes, as a side effect, a crash in wxGrid under wxMSW as the focus is
not restored to the hidden grid editor any longer and so the code in its
wxEVT_KILL_FOCUS handler that resulted in the crash is not executed any
longer, see #13349.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68319 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-07-21 13:50:06 +00:00
parent 2b232decc5
commit 26647ae4a7

View File

@@ -650,14 +650,26 @@ bool wxSetFocusToChild(wxWindow *win, wxWindow **childLastFocused)
// It might happen that the window got reparented
if ( (*childLastFocused)->GetParent() == win )
{
wxLogTrace(TRACE_FOCUS,
wxT("SetFocusToChild() => last child (0x%p)."),
(*childLastFocused)->GetHandle());
// And it also could have become hidden in the meanwhile, in this
// case focus its parent instead.
while ( !(*childLastFocused)->IsShown() )
{
*childLastFocused = (*childLastFocused)->GetParent();
if ( !*childLastFocused )
break;
}
// not SetFocusFromKbd(): we're restoring focus back to the old
// window and not setting it as the result of a kbd action
(*childLastFocused)->SetFocus();
return true;
if ( *childLastFocused )
{
wxLogTrace(TRACE_FOCUS,
wxT("SetFocusToChild() => last child (0x%p)."),
(*childLastFocused)->GetHandle());
// not SetFocusFromKbd(): we're restoring focus back to the old
// window and not setting it as the result of a kbd action
(*childLastFocused)->SetFocus();
return true;
}
}
else
{