From 5b3166fda9d2643d88fc8cc5990853af6312d3df Mon Sep 17 00:00:00 2001 From: Michael Wetherell Date: Fri, 6 May 2005 13:42:34 +0000 Subject: [PATCH] On x11 another control may already have the mouse capture when the menu is trying to release it's capture, so work around that problem. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33968 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/univ/menu.h | 3 +++ src/univ/menu.cpp | 47 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/include/wx/univ/menu.h b/include/wx/univ/menu.h index ac9364404b..f52f9ea579 100644 --- a/include/wx/univ/menu.h +++ b/include/wx/univ/menu.h @@ -248,6 +248,9 @@ protected: // we don't want to have focus except while selecting from menu void GiveAwayFocus(); + // Release the mouse capture if we have it + bool ReleaseMouseCapture(); + // the array containing extra menu info we need wxMenuInfoArray m_menuInfos; diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index ba4e56b519..c5622fc30c 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -2146,9 +2146,6 @@ bool wxMenuBar::ProcessMouseEvent(const wxPoint& pt) return false; } - // FIXME: temporary workaround for crash, to be fixed - // in a later version. -#if 0 // select the new active item DoSelectMenu(currentNew); @@ -2159,7 +2156,6 @@ bool wxMenuBar::ProcessMouseEvent(const wxPoint& pt) // open the new menu if the old one we closed had been opened PopupCurrentMenu(false /* don't select first item - as Windows does */); } -#endif return true; } @@ -2467,12 +2463,9 @@ void wxMenuBar::OnDismissMenu(bool dismissMenuBar) void wxMenuBar::OnDismiss() { - if ( GetCapture() ) - { + if ( ReleaseMouseCapture() ) wxLogTrace(_T("mousecapture"), _T("Releasing mouse from wxMenuBar::OnDismiss")); - GetCapture()->ReleaseMouse(); - } - + if ( m_current != -1 ) { size_t current = m_current; @@ -2484,6 +2477,42 @@ void wxMenuBar::OnDismiss() GiveAwayFocus(); } +bool wxMenuBar::ReleaseMouseCapture() +{ +#if __WXX11__ + // With wxX11, when a menu is closed by clicking away from it, a control + // under the click will still get an event, even though the menu has the + // capture (bug?). So that control may already have taken the capture by + // this point, preventing us from releasing the menu's capture. So to work + // around this, we release both captures, then put back the control's + // capture. + wxWindow *capture = GetCapture(); + if ( capture ) + { + capture->ReleaseMouse(); + + if ( capture == this ) + return true; + + bool had = HasCapture(); + + if ( had ) + ReleaseMouse(); + + capture->CaptureMouse(); + + return had; + } +#else + if ( HasCapture() ) + { + ReleaseMouse(); + return true; + } +#endif + return false; +} + void wxMenuBar::GiveAwayFocus() { GetFrame()->SetFocus(); -- 2.45.2