]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
Removed WXWIN_COMPATIBILITY_2_2 together with code guarded by it.
[wxWidgets.git] / src / msw / window.cpp
index ee785b62e6f14406dc6add4a8cc60f7ec7ad77ae..0874381013c364b7b9d0335bad8af1ec2f16c4ba 100644 (file)
 // by setting this to 0 (in the future this should be removed completely)
 #define USE_DEFERRED_SIZING 1
 
+// set this to 1 to filter out duplicate mouse events, e.g. mouse move events
+// when mouse position didnd't change
+#ifdef __WXWINCE__
+    #define wxUSE_MOUSEEVENT_HACK 0
+#else
+    #define wxUSE_MOUSEEVENT_HACK 1
+#endif
+
 // ---------------------------------------------------------------------------
 // global variables
 // ---------------------------------------------------------------------------
@@ -141,6 +149,18 @@ extern const wxChar *wxCanvasClassName;
 // wxGetStdColourMap() and wxWindow::OnSysColourChanged()           (FIXME-MT)
 static bool gs_hasStdCmap = false;
 
+// last mouse event information we need to filter out the duplicates
+#if wxUSE_MOUSEEVENT_HACK
+static struct
+{
+    // mouse position (in screen coordinates)
+    wxPoint pos;
+
+    // last mouse event type
+    wxEventType type;
+} gs_lastMouseEvent;
+#endif // wxUSE_MOUSEEVENT_HACK
+
 // ---------------------------------------------------------------------------
 // private functions
 // ---------------------------------------------------------------------------
@@ -462,12 +482,6 @@ void wxWindowMSW::Init()
     m_xThumbSize = 0;
     m_yThumbSize = 0;
 
-#if wxUSE_MOUSEEVENT_HACK
-    m_lastMouseX =
-    m_lastMouseY = -1;
-    m_lastMouseEvent = -1;
-#endif // wxUSE_MOUSEEVENT_HACK
-
     m_pendingPosition = wxDefaultPosition;
     m_pendingSize = wxDefaultSize;
 }
@@ -806,7 +820,7 @@ void wxWindowMSW::WarpPointer(int x, int y)
     }
 }
 
-void wxWindowMSW::MSWUpdateUIState()
+void wxWindowMSW::MSWUpdateUIState(int action)
 {
     // WM_UPDATEUISTATE only appeared in Windows 2000 so it can do us no good
     // to use it on older systems -- and could possibly do some harm
@@ -824,8 +838,7 @@ void wxWindowMSW::MSWUpdateUIState()
         //     include just one UISF_XXX or both, both are affected, no idea
         //     why
         ::SendMessage(GetHwnd(), WM_UPDATEUISTATE,
-                        MAKEWPARAM(UIS_INITIALIZE,
-                                   UISF_HIDEFOCUS | UISF_HIDEACCEL), 0);
+                      MAKEWPARAM(action, UISF_HIDEFOCUS | UISF_HIDEACCEL), 0);
     }
 }
 
@@ -2084,7 +2097,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                     // this by default, we need to manually send this message
                     // so that controls could change their appearance
                     // appropriately
-                    MSWUpdateUIState();
+                    MSWUpdateUIState(UIS_CLEAR);
 
                     return true;
                 }
@@ -4494,9 +4507,8 @@ void wxWindowMSW::InitMouseEvent(wxMouseEvent& event,
     event.SetId(GetId());
 
 #if wxUSE_MOUSEEVENT_HACK
-    m_lastMouseX = x;
-    m_lastMouseY = y;
-    m_lastMouseEvent = event.GetEventType();
+    gs_lastMouseEvent.pos = ClientToScreen(wxPoint(x, y));
+    gs_lastMouseEvent.type = event.GetEventType();
 #endif // wxUSE_MOUSEEVENT_HACK
 }
 
@@ -4636,17 +4648,22 @@ bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags)
 #endif // HAVE_TRACKMOUSEEVENT 
 
 #if wxUSE_MOUSEEVENT_HACK
-    // Window gets a click down message followed by a mouse move message even
-    // if position isn't changed!  We want to discard the trailing move event
-    // if x and y are the same.
-    if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN ||
-          m_lastMouseEvent == wxEVT_LEFT_DOWN ||
-          m_lastMouseEvent == wxEVT_MIDDLE_DOWN) &&
-         (m_lastMouseX == x && m_lastMouseY == y) )
-    {
-        m_lastMouseEvent = wxEVT_MOTION;
+    // Windows often generates mouse events even if mouse position hasn't
+    // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
+    //
+    // Filter this out as it can result in unexpected behaviour compared to
+    // other platforms
+    if ( gs_lastMouseEvent.type == wxEVT_RIGHT_DOWN ||
+         gs_lastMouseEvent.type == wxEVT_LEFT_DOWN ||
+         gs_lastMouseEvent.type == wxEVT_MIDDLE_DOWN ||
+         gs_lastMouseEvent.type == wxEVT_MOTION )
+    {
+        if ( ClientToScreen(wxPoint(x, y)) == gs_lastMouseEvent.pos )
+        {
+            gs_lastMouseEvent.type = wxEVT_MOTION;
 
-        return false;
+            return false;
+        }
     }
 #endif // wxUSE_MOUSEEVENT_HACK