]> git.saurik.com Git - wxWidgets.git/blame - src/msw/uiaction.cpp
wxRichTextCtrl::ApplyStyle now applies a paragraph style at the cursor
[wxWidgets.git] / src / msw / uiaction.cpp
CommitLineData
a02a5cfc
KO
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/uiaction.cpp
3// Purpose: wxUIActionSimulator implementation
571d991b 4// Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
a02a5cfc
KO
5// Modified by:
6// Created: 2010-03-06
7// RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
8// Copyright: (c) Kevin Ollivier
571d991b
VZ
9// (c) 2010 Steven Lamerton
10// (c) 2010 Vadim Zeitlin
a02a5cfc
KO
11// Licence: wxWindows licence
12/////////////////////////////////////////////////////////////////////////////
13
14#include "wx/wxprec.h"
15
9b7e0226 16#if wxUSE_UIACTIONSIMULATOR
a02a5cfc
KO
17
18#include "wx/uiaction.h"
19
9b7e0226 20#include "wx/msw/wrapwin.h"
a02a5cfc 21
571d991b
VZ
22namespace
23{
24
a02a5cfc
KO
25DWORD EventTypeForMouseButton(int button, bool isDown)
26{
27 switch (button)
28 {
29 case wxMOUSE_BTN_LEFT:
571d991b
VZ
30 return isDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
31
a02a5cfc 32 case wxMOUSE_BTN_RIGHT:
571d991b
VZ
33 return isDown ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
34
a02a5cfc 35 case wxMOUSE_BTN_MIDDLE:
571d991b 36 return isDown ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
9b7e0226 37
a02a5cfc
KO
38 default:
39 wxFAIL_MSG("Unsupported button passed in.");
571d991b 40 return (DWORD)-1;
a02a5cfc
KO
41 }
42}
43
571d991b
VZ
44void DoSimulateKbdEvent(DWORD vk, bool isDown)
45{
46 keybd_event(vk, 0, isDown ? 0 : KEYEVENTF_KEYUP, 0);
47}
48
49} // anonymous namespace
50
a02a5cfc
KO
51bool wxUIActionSimulator::MouseDown(int button)
52{
53 POINT p;
54 GetCursorPos(&p);
55 mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
56 return true;
57}
58
59bool wxUIActionSimulator::MouseMove(long x, long y)
9b7e0226 60{
571d991b
VZ
61 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
62 // we need to scale our input too
63 int displayx, displayy, scaledx, scaledy;
64 wxDisplaySize(&displayx, &displayy);
65 scaledx = ((float)x / displayx) * 65535;
66 scaledy = ((float)y / displayy) * 65535;
67 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, scaledx, scaledy, 0, 0);
a02a5cfc
KO
68 return true;
69}
70
71bool wxUIActionSimulator::MouseUp(int button)
72{
73 POINT p;
74 GetCursorPos(&p);
75 mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0);
76 return true;
77}
78
571d991b 79bool wxUIActionSimulator::DoKey(int keycode, int modifiers, bool isDown)
a02a5cfc 80{
571d991b
VZ
81 if (isDown)
82 {
83 if (modifiers & wxMOD_SHIFT)
84 DoSimulateKbdEvent(VK_SHIFT, true);
85 if (modifiers & wxMOD_ALT)
86 DoSimulateKbdEvent(VK_MENU, true);
87 if (modifiers & wxMOD_CMD)
88 DoSimulateKbdEvent(VK_CONTROL, true);
89 }
90
91 DWORD vkkeycode = wxCharCodeWXToMSW(keycode);
92 keybd_event(vkkeycode, 0, isDown ? 0 : KEYEVENTF_KEYUP, 0);
93
a02a5cfc 94 if (!isDown)
571d991b
VZ
95 {
96 if (modifiers & wxMOD_SHIFT)
97 DoSimulateKbdEvent(VK_SHIFT, false);
98 if (modifiers & wxMOD_ALT)
99 DoSimulateKbdEvent(VK_MENU, false);
100 if (modifiers & wxMOD_CMD)
101 DoSimulateKbdEvent(VK_CONTROL, false);
102 }
103
a02a5cfc
KO
104 return true;
105}
106
9b7e0226 107#endif // wxUSE_UIACTIONSIMULATOR