From 516cdd54330f3081d6cef74865298a34e7519d84 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 22 Jan 2002 15:40:06 +0000 Subject: [PATCH] added a hack to work around the dummy kill focus messages under GTK git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13745 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/popupcmn.cpp | 44 +++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/common/popupcmn.cpp b/src/common/popupcmn.cpp index 2fabd49c70..0a79fdd679 100644 --- a/src/common/popupcmn.cpp +++ b/src/common/popupcmn.cpp @@ -76,7 +76,15 @@ private: class wxPopupFocusHandler : public wxEvtHandler { public: - wxPopupFocusHandler(wxPopupTransientWindow *popup) { m_popup = popup; } + wxPopupFocusHandler(wxPopupTransientWindow *popup) + { + m_popup = popup; + +#ifdef __WXGTK__ + // ignore the next few OnKillFocus() calls + m_creationTime = time(NULL); +#endif // __WXGTK__ + } protected: // event handlers @@ -86,6 +94,12 @@ protected: private: wxPopupTransientWindow *m_popup; + // hack around wxGTK bug: we always get several kill focus events + // immediately after creation! +#ifdef __WXGTK__ + time_t m_creationTime; +#endif // __WXGTK__ + DECLARE_EVENT_TABLE() }; @@ -206,33 +220,27 @@ void wxPopupTransientWindow::Popup(wxWindow *winFocus) m_child = this; } - // we can't capture mouse before the window is shown in wxGTK -#ifdef __WXGTK__ + // we can't capture mouse before the window is shown in wxGTK, so do it + // first Show(); -#endif m_child->CaptureMouse(); m_child->PushEventHandler(new wxPopupWindowHandler(this)); -#ifndef __WXGTK__ - Show(); -#endif - m_focus = winFocus ? winFocus : this; m_focus->SetFocus(); +#ifdef __WXMSW__ // FIXME: I don't know why does this happen but sometimes SetFocus() simply // refuses to work under MSW - no error happens but the focus is not // given to the window, i.e. the assert below is triggered // // Try work around this as we can... -#if 0 - wxASSERT_MSG( FindFocus() == m_focus, _T("setting focus failed") ); -#else - m_focus = FindFocus(); -#endif + //wxASSERT_MSG( FindFocus() == m_focus, _T("setting focus failed") ); + m_focus = FindFocus(); if ( m_focus ) +#endif // __WXMSW__ { m_focus->PushEventHandler(new wxPopupFocusHandler(this)); } @@ -379,6 +387,16 @@ void wxPopupWindowHandler::OnLeftDown(wxMouseEvent& event) void wxPopupFocusHandler::OnKillFocus(wxFocusEvent& event) { +#ifdef __WXGTK__ + // ignore the next OnKillFocus() call + if ( time(NULL) < m_creationTime + 1 ) + { + event.Skip(); + + return; + } +#endif // __WXGTK__ + // when we lose focus we always disappear - unless it goes to the popup (in // which case we don't really lose it) if ( event.GetWindow() != m_popup ) -- 2.45.2