]> git.saurik.com Git - wxWidgets.git/blob - src/msw/uiaction.cpp
Make the source files non-executable again.
[wxWidgets.git] / src / msw / uiaction.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/uiaction.cpp
3 // Purpose: wxUIActionSimulator implementation
4 // Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
5 // Modified by:
6 // Created: 2010-03-06
7 // RCS-ID: $Id$
8 // Copyright: (c) Kevin Ollivier
9 // (c) 2010 Steven Lamerton
10 // (c) 2010 Vadim Zeitlin
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
13
14 #include "wx/wxprec.h"
15
16 #if wxUSE_UIACTIONSIMULATOR
17
18 #include "wx/uiaction.h"
19 #include "wx/msw/wrapwin.h"
20
21 #include "wx/msw/private/keyboard.h"
22
23 namespace
24 {
25
26 DWORD EventTypeForMouseButton(int button, bool isDown)
27 {
28 switch (button)
29 {
30 case wxMOUSE_BTN_LEFT:
31 return isDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
32
33 case wxMOUSE_BTN_RIGHT:
34 return isDown ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
35
36 case wxMOUSE_BTN_MIDDLE:
37 return isDown ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
38
39 default:
40 wxFAIL_MSG("Unsupported button passed in.");
41 return (DWORD)-1;
42 }
43 }
44
45 } // anonymous namespace
46
47 bool wxUIActionSimulator::MouseDown(int button)
48 {
49 POINT p;
50 GetCursorPos(&p);
51 mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
52 return true;
53 }
54
55 bool wxUIActionSimulator::MouseMove(long x, long y)
56 {
57 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
58 // we need to scale our input too
59 int displayx, displayy, scaledx, scaledy;
60 wxDisplaySize(&displayx, &displayy);
61 scaledx = ((float)x / displayx) * 65535;
62 scaledy = ((float)y / displayy) * 65535;
63 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, scaledx, scaledy, 0, 0);
64 return true;
65 }
66
67 bool wxUIActionSimulator::MouseUp(int button)
68 {
69 POINT p;
70 GetCursorPos(&p);
71 mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0);
72 return true;
73 }
74
75 bool
76 wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
77 {
78 bool isExtended;
79 DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended);
80
81 DWORD flags = 0;
82 if ( isExtended )
83 flags |= KEYEVENTF_EXTENDEDKEY;
84 if ( !isDown )
85 flags |= KEYEVENTF_KEYUP;
86
87 keybd_event(vkkeycode, 0, flags, 0);
88
89 return true;
90 }
91
92 #endif // wxUSE_UIACTIONSIMULATOR