Merge wxUIActionSimulator fixes from SOC2010_GUI_TEST branch.
Correct a lot of problems with the initial implementation, notably make the API consistent across all platforms, e.g. all keyboard-related methods now take just a wxKeyCode. Add some useful higher-level helpers such as Text() and MouseDragDrop(). Improve documentation. wxUIActionSimulator now works under MSW, GTK and OS X and is enabled by default. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65385 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/msw/uiaction.cpp
|
||||
// Purpose: wxUIActionSimulator implementation
|
||||
// Author: Kevin Ollivier
|
||||
// Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 2010-03-06
|
||||
// RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
|
||||
// Copyright: (c) Kevin Ollivier
|
||||
// (c) 2010 Steven Lamerton
|
||||
// (c) 2010 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -17,32 +19,35 @@
|
||||
|
||||
#include "wx/msw/wrapwin.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
DWORD EventTypeForMouseButton(int button, bool isDown)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case wxMOUSE_BTN_LEFT:
|
||||
if (isDown)
|
||||
return MOUSEEVENTF_LEFTDOWN;
|
||||
else
|
||||
return MOUSEEVENTF_LEFTUP;
|
||||
return isDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
|
||||
|
||||
case wxMOUSE_BTN_RIGHT:
|
||||
if (isDown)
|
||||
return MOUSEEVENTF_RIGHTDOWN;
|
||||
else
|
||||
return MOUSEEVENTF_RIGHTUP;
|
||||
return isDown ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
|
||||
|
||||
case wxMOUSE_BTN_MIDDLE:
|
||||
if (isDown)
|
||||
return MOUSEEVENTF_MIDDLEDOWN;
|
||||
else
|
||||
return MOUSEEVENTF_MIDDLEUP;
|
||||
return isDown ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG("Unsupported button passed in.");
|
||||
return -1;
|
||||
return (DWORD)-1;
|
||||
}
|
||||
}
|
||||
|
||||
void DoSimulateKbdEvent(DWORD vk, bool isDown)
|
||||
{
|
||||
keybd_event(vk, 0, isDown ? 0 : KEYEVENTF_KEYUP, 0);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
bool wxUIActionSimulator::MouseDown(int button)
|
||||
{
|
||||
POINT p;
|
||||
@@ -53,7 +58,13 @@ bool wxUIActionSimulator::MouseDown(int button)
|
||||
|
||||
bool wxUIActionSimulator::MouseMove(long x, long y)
|
||||
{
|
||||
mouse_event(MOUSEEVENTF_MOVE, x, y, 0, 0);
|
||||
// Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
|
||||
// we need to scale our input too
|
||||
int displayx, displayy, scaledx, scaledy;
|
||||
wxDisplaySize(&displayx, &displayy);
|
||||
scaledx = ((float)x / displayx) * 65535;
|
||||
scaledy = ((float)y / displayy) * 65535;
|
||||
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, scaledx, scaledy, 0, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,12 +76,31 @@ bool wxUIActionSimulator::MouseUp(int button)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxUIActionSimulator::Key(int keycode, bool isDown, bool shiftDown, bool cmdDown, bool altDown)
|
||||
bool wxUIActionSimulator::DoKey(int keycode, int modifiers, bool isDown)
|
||||
{
|
||||
DWORD flags = 0;
|
||||
if (isDown)
|
||||
{
|
||||
if (modifiers & wxMOD_SHIFT)
|
||||
DoSimulateKbdEvent(VK_SHIFT, true);
|
||||
if (modifiers & wxMOD_ALT)
|
||||
DoSimulateKbdEvent(VK_MENU, true);
|
||||
if (modifiers & wxMOD_CMD)
|
||||
DoSimulateKbdEvent(VK_CONTROL, true);
|
||||
}
|
||||
|
||||
DWORD vkkeycode = wxCharCodeWXToMSW(keycode);
|
||||
keybd_event(vkkeycode, 0, isDown ? 0 : KEYEVENTF_KEYUP, 0);
|
||||
|
||||
if (!isDown)
|
||||
flags = KEYEVENTF_KEYUP;
|
||||
keybd_event(keycode, 0, flags, 0);
|
||||
{
|
||||
if (modifiers & wxMOD_SHIFT)
|
||||
DoSimulateKbdEvent(VK_SHIFT, false);
|
||||
if (modifiers & wxMOD_ALT)
|
||||
DoSimulateKbdEvent(VK_MENU, false);
|
||||
if (modifiers & wxMOD_CMD)
|
||||
DoSimulateKbdEvent(VK_CONTROL, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user