From b0ad1918b955df68f2a38dc6720b91a49844a10d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 18 Aug 2013 13:28:06 +0000 Subject: [PATCH] No changes, just use wxRecursionGuard instead of manual boolean flag. Use wxRecursionGuard with the flag indicating whether the mouse capture is changing to ensure that we always reset it correctly and make the code slightly shorter. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74674 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/wincmn.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 74c8056983..b3479ab8d0 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -72,6 +72,7 @@ #endif #include "wx/platinfo.h" +#include "wx/recguard.h" #include "wx/private/window.h" #ifdef __WINDOWS__ @@ -3216,8 +3217,8 @@ struct WindowNext // the window that currently has mouse capture wxWindow *current = NULL; -// indicates if execution is inside CaptureMouse/ReleaseMouse -bool changing = false; +// Flag preventing reentrancy in {Capture,Release}Mouse(). +wxRecursionGuardFlag changing; } // wxMouseCapture @@ -3225,9 +3226,8 @@ void wxWindowBase::CaptureMouse() { wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast(this)); - wxASSERT_MSG( !wxMouseCapture::changing, wxT("recursive CaptureMouse call?") ); - - wxMouseCapture::changing = true; + wxRecursionGuard guard(wxMouseCapture::changing); + wxASSERT_MSG( !guard.IsInside(), wxT("recursive CaptureMouse call?") ); wxWindow *winOld = GetCapture(); if ( winOld ) @@ -3244,23 +3244,20 @@ void wxWindowBase::CaptureMouse() DoCaptureMouse(); wxMouseCapture::current = (wxWindow*)this; - - wxMouseCapture::changing = false; } void wxWindowBase::ReleaseMouse() { wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast(this)); - wxASSERT_MSG( !wxMouseCapture::changing, wxT("recursive ReleaseMouse call?") ); + wxRecursionGuard guard(wxMouseCapture::changing); + wxASSERT_MSG( !guard.IsInside(), wxT("recursive ReleaseMouse call?") ); wxASSERT_MSG( GetCapture() == this, "attempt to release mouse, but this window hasn't captured it" ); wxASSERT_MSG( wxMouseCapture::current == this, "attempt to release mouse, but this window hasn't captured it" ); - wxMouseCapture::changing = true; - DoReleaseMouse(); wxMouseCapture::current = NULL; @@ -3275,8 +3272,6 @@ void wxWindowBase::ReleaseMouse() } //else: stack is empty, no previous capture - wxMouseCapture::changing = false; - wxLogTrace(wxT("mousecapture"), (const wxChar *) wxT("After ReleaseMouse() mouse is captured by %p"), static_cast(GetCapture())); @@ -3301,7 +3296,8 @@ void wxWindowBase::NotifyCaptureLost() { // don't do anything if capture lost was expected, i.e. resulted from // a wx call to ReleaseMouse or CaptureMouse: - if ( wxMouseCapture::changing ) + wxRecursionGuard guard(wxMouseCapture::changing); + if ( guard.IsInside() ) return; // if the capture was lost unexpectedly, notify every window that has -- 2.45.2