about focused window, replace static variables implementation by DoFindFocus

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77834 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-09-23 17:42:58 +00:00
parent adf61108be
commit f6fdfe8ebc
2 changed files with 7 additions and 17 deletions

View File

@@ -356,7 +356,7 @@ wxWindowX11::~wxWindowX11()
if (g_captureWindow == this) if (g_captureWindow == this)
g_captureWindow = NULL; g_captureWindow = NULL;
if ( gs_focusedWindow == this ) if ( DoFindFocus() == this )
KillFocus(); KillFocus();
DestroyChildren(); DestroyChildren();
@@ -396,19 +396,11 @@ void wxWindowX11::SetFocus()
if (!AcceptsFocus()) if (!AcceptsFocus())
return; return;
if ( gs_focusedWindow == (wxWindow*)this ) if ( DoFindFocus() == (wxWindow*)this )
return; // nothing to do, focused already return; // nothing to do, focused already
wxWindow *oldFocusedWindow = (wxWindow*)xwindow; if ( DoFindFocus() )
DoFindFocus()->KillFocus();
if ( gs_focusedWindow )
{
gs_toBeFocusedWindow = (wxWindow*)this;
gs_focusedWindow->KillFocus();
gs_toBeFocusedWindow = NULL;
}
gs_focusedWindow = (wxWindow*)this;
#if 0 #if 0
if (GetName() == "scrollBar") if (GetName() == "scrollBar")
@@ -440,7 +432,7 @@ void wxWindowX11::SetFocus()
wxFocusEvent event(wxEVT_SET_FOCUS, GetId()); wxFocusEvent event(wxEVT_SET_FOCUS, GetId());
event.SetEventObject(this); event.SetEventObject(this);
event.SetWindow((wxWindow*)oldFocusedWindow); event.SetWindow((wxWindow*)xwindow);
HandleWindowEvent(event); HandleWindowEvent(event);
} }
@@ -448,17 +440,14 @@ void wxWindowX11::SetFocus()
// Kill focus // Kill focus
void wxWindowX11::KillFocus() void wxWindowX11::KillFocus()
{ {
wxCHECK_RET( gs_focusedWindow == this, wxCHECK_RET( DoFindFocus() == this,
"killing focus on window that doesn't have it" ); "killing focus on window that doesn't have it" );
gs_focusedWindow = NULL;
if ( m_isBeingDeleted ) if ( m_isBeingDeleted )
return; // don't send any events from dtor return; // don't send any events from dtor
wxFocusEvent event(wxEVT_KILL_FOCUS, GetId()); wxFocusEvent event(wxEVT_KILL_FOCUS, GetId());
event.SetEventObject(this); event.SetEventObject(this);
event.SetWindow(gs_toBeFocusedWindow);
HandleWindowEvent(event); HandleWindowEvent(event);
} }

View File

@@ -147,6 +147,7 @@ void WindowTestCase::FocusEvent()
wxButton* button = new wxButton(wxTheApp->GetTopWindow(), wxID_ANY); wxButton* button = new wxButton(wxTheApp->GetTopWindow(), wxID_ANY);
wxYield();
button->SetFocus(); button->SetFocus();
CPPUNIT_ASSERT_EQUAL(1, killfocus.GetCount()); CPPUNIT_ASSERT_EQUAL(1, killfocus.GetCount());