]> git.saurik.com Git - wxWidgets.git/commitdiff
On x11 another control may already have the mouse capture when the menu is
authorMichael Wetherell <mike.wetherell@ntlworld.com>
Fri, 6 May 2005 13:42:34 +0000 (13:42 +0000)
committerMichael Wetherell <mike.wetherell@ntlworld.com>
Fri, 6 May 2005 13:42:34 +0000 (13:42 +0000)
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
src/univ/menu.cpp

index ac9364404b1eefed03d4b65a2c5a4b1b5950e7e2..f52f9ea579660882d078ae66747ef272686dd996 100644 (file)
@@ -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;
 
index ba4e56b51934ae2cf2f5d260f1dcb2158a501f47..c5622fc30c51ff76bd75d3416a40a7e39e51ed23 100644 (file)
@@ -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();