X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0c03f52d02470366a1b1370d918fa5779997e7f0..ad653fa23069c5d9378247084f03c9a718c3ad62:/src/msw/uiaction.cpp?ds=sidebyside diff --git a/src/msw/uiaction.cpp b/src/msw/uiaction.cpp index eb5bfd1e34..bc5bde1ad1 100644 --- a/src/msw/uiaction.cpp +++ b/src/msw/uiaction.cpp @@ -15,11 +15,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 +53,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 +62,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; }