]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement EVT_MOUSE_CAPTURE_LOST handling for wxPopupTransientWindow.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 9 Oct 2011 22:02:05 +0000 (22:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 9 Oct 2011 22:02:05 +0000 (22:02 +0000)
Handle mouse capture lost events instead of polling for the mouse status in
EVT_IDLE handler. This is not only more efficient but also catches the cases
when the capture was lost before OnIdle() could be executed which could result
in assertion failures and, before the previous commit, even crashes.

The idle-time code is still used for wxOSX/Carbon because it doesn't seem to
generate mouse capture loss events currently -- but should be removed as soon
as support for these events is added.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/popupwin.h
src/common/popupcmn.cpp

index 03bb274c5a4d97486c7605e3211604d2f1c1f8dd..4f451a644e76e397b0d059354634b519410b070b 100644 (file)
@@ -132,7 +132,9 @@ protected:
     // get alerted when child gets deleted from under us
     void OnDestroy(wxWindowDestroyEvent& event);
 
-#if defined( __WXMSW__ ) || defined( __WXMAC__)
+    // wxOSX/Carbon doesn't generate mouse capture loss events currently so
+    // poll for the capture loss ourselves.
+#if wxOSX_USE_CARBON
     // check if the mouse needs captured or released
     void OnIdle(wxIdleEvent& event);
 #endif
index 6aef738e9debfe94e1c2a7fbe3654503147086d4..36445b9087f4d73c10cbbebeb86562d442338f13 100644 (file)
@@ -76,6 +76,7 @@ public:
 protected:
     // event handlers
     void OnLeftDown(wxMouseEvent& event);
+    void OnCaptureLost(wxMouseCaptureLostEvent& event);
 
 private:
     wxPopupTransientWindow *m_popup;
@@ -106,6 +107,7 @@ private:
 
 BEGIN_EVENT_TABLE(wxPopupWindowHandler, wxEvtHandler)
     EVT_LEFT_DOWN(wxPopupWindowHandler::OnLeftDown)
+    EVT_MOUSE_CAPTURE_LOST(wxPopupWindowHandler::OnCaptureLost)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxPopupFocusHandler, wxEvtHandler)
@@ -114,7 +116,7 @@ BEGIN_EVENT_TABLE(wxPopupFocusHandler, wxEvtHandler)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxPopupTransientWindow, wxPopupWindow)
-#if defined( __WXMSW__ ) || ( defined( __WXMAC__ ) && wxOSX_USE_CARBON )
+#if wxOSX_USE_CARBON
     EVT_IDLE(wxPopupTransientWindow::OnIdle)
 #endif
 END_EVENT_TABLE()
@@ -424,7 +426,7 @@ bool wxPopupTransientWindow::ProcessLeftDown(wxMouseEvent& WXUNUSED(event))
     return false;
 }
 
-#if defined( __WXMSW__ ) || ( defined( __WXMAC__ ) && wxOSX_USE_CARBON )
+#if wxOSX_USE_CARBON
 void wxPopupTransientWindow::OnIdle(wxIdleEvent& event)
 {
     event.Skip();
@@ -450,7 +452,7 @@ void wxPopupTransientWindow::OnIdle(wxIdleEvent& event)
         }
     }
 }
-#endif // __WXMSW__
+#endif // wxOSX/Carbon
 
 
 #if wxUSE_COMBOBOX && defined(__WXUNIVERSAL__)
@@ -600,6 +602,15 @@ void wxPopupWindowHandler::OnLeftDown(wxMouseEvent& event)
 #endif // __WXUNIVERSAL__ && wxUSE_SCROLLBAR
 }
 
+void
+wxPopupWindowHandler::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
+{
+    m_popup->DismissAndNotify();
+
+    // There is no need to skip the event here, normally we've already dealt
+    // with the focus loss.
+}
+
 // ----------------------------------------------------------------------------
 // wxPopupFocusHandler
 // ----------------------------------------------------------------------------