From 26647ae4a7f4982c18a1af8bbfe0910a97b78620 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 21 Jul 2011 13:50:06 +0000 Subject: [PATCH] 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 --- src/common/containr.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/common/containr.cpp b/src/common/containr.cpp index dd4e892faf..29756da696 100644 --- a/src/common/containr.cpp +++ b/src/common/containr.cpp @@ -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 { -- 2.45.2