X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0c03f52d02470366a1b1370d918fa5779997e7f0..55c534803fc222e8fea96cada9b7715763814046:/src/msw/uiaction.cpp diff --git a/src/msw/uiaction.cpp b/src/msw/uiaction.cpp index eb5bfd1e34..5308d9c0f1 100644 --- a/src/msw/uiaction.cpp +++ b/src/msw/uiaction.cpp @@ -4,7 +4,6 @@ // Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin // Modified by: // Created: 2010-03-06 -// RCS-ID: $Id$ // Copyright: (c) Kevin Ollivier // (c) 2010 Steven Lamerton // (c) 2010 Vadim Zeitlin @@ -15,11 +14,17 @@ #if wxUSE_UIACTIONSIMULATOR +#ifndef WX_PRECOMP + #include "wx/msw/private.h" // For wxGetCursorPosMSW() +#endif + #include "wx/uiaction.h" #include "wx/msw/wrapwin.h" #include "wx/msw/private/keyboard.h" +#include "wx/math.h" + namespace { @@ -47,7 +52,7 @@ DWORD EventTypeForMouseButton(int button, bool isDown) bool wxUIActionSimulator::MouseDown(int button) { POINT p; - GetCursorPos(&p); + wxGetCursorPosMSW(&p); mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0); return true; } @@ -56,18 +61,22 @@ bool wxUIActionSimulator::MouseMove(long x, long y) { // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535 // we need to scale our input too - int displayx, displayy, scaledx, scaledy; + int displayx, displayy; wxDisplaySize(&displayx, &displayy); - scaledx = ((float)x / displayx) * 65535; - scaledy = ((float)y / displayy) * 65535; + + // Casts are safe because x and y are supposed to be less than the display + // size, so there is no danger of overflow. + DWORD scaledx = static_cast(ceil(x * 65535.0 / (displayx-1))); + DWORD scaledy = static_cast(ceil(y * 65535.0 / (displayy-1))); mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, scaledx, scaledy, 0, 0); + return true; } bool wxUIActionSimulator::MouseUp(int button) { POINT p; - GetCursorPos(&p); + wxGetCursorPosMSW(&p); mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0); return true; }