// 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
#if wxUSE_UIACTIONSIMULATOR
+#ifndef WX_PRECOMP
+ #include "wx/msw/private.h" // For wxGetCursorPosMSW()
+#endif
+
#include "wx/uiaction.h"
-#include "wx/window.h" //for wxCharCodeWXToMSW
#include "wx/msw/wrapwin.h"
+#include "wx/msw/private/keyboard.h"
+
+#include "wx/math.h"
+
namespace
{
bool wxUIActionSimulator::MouseDown(int button)
{
POINT p;
- GetCursorPos(&p);
+ wxGetCursorPosMSW(&p);
mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
return true;
}
{
// 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<DWORD>(ceil(x * 65535.0 / (displayx-1)));
+ DWORD scaledy = static_cast<DWORD>(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;
}
wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
{
bool isExtended;
- DWORD vkkeycode = wxCharCodeWXToMSW(keycode, &isExtended);
+ DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended);
DWORD flags = 0;
if ( isExtended )