]> git.saurik.com Git - wxWidgets.git/blob - src/msw/uiaction.cpp
Use library-specific description in their version resources for MSW DLLs.
[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 #ifndef WX_PRECOMP
19 #include "wx/msw/private.h" // For wxGetCursorPosMSW()
20 #endif
21
22 #include "wx/uiaction.h"
23 #include "wx/msw/wrapwin.h"
24
25 #include "wx/msw/private/keyboard.h"
26
27 #include "wx/math.h"
28
29 namespace
30 {
31
32 DWORD EventTypeForMouseButton(int button, bool isDown)
33 {
34 switch (button)
35 {
36 case wxMOUSE_BTN_LEFT:
37 return isDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
38
39 case wxMOUSE_BTN_RIGHT:
40 return isDown ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
41
42 case wxMOUSE_BTN_MIDDLE:
43 return isDown ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
44
45 default:
46 wxFAIL_MSG("Unsupported button passed in.");
47 return (DWORD)-1;
48 }
49 }
50
51 } // anonymous namespace
52
53 bool wxUIActionSimulator::MouseDown(int button)
54 {
55 POINT p;
56 wxGetCursorPosMSW(&p);
57 mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
58 return true;
59 }
60
61 bool wxUIActionSimulator::MouseMove(long x, long y)
62 {
63 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
64 // we need to scale our input too
65 int displayx, displayy;
66 wxDisplaySize(&displayx, &displayy);
67
68 int scaledx = ceil((float)x * 65535.0 / (displayx-1));
69 int scaledy = ceil((float)y * 65535.0 / (displayy-1));
70 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, scaledx, scaledy, 0, 0);
71
72 return true;
73 }
74
75 bool wxUIActionSimulator::MouseUp(int button)
76 {
77 POINT p;
78 wxGetCursorPosMSW(&p);
79 mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0);
80 return true;
81 }
82
83 bool
84 wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
85 {
86 bool isExtended;
87 DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended);
88
89 DWORD flags = 0;
90 if ( isExtended )
91 flags |= KEYEVENTF_EXTENDEDKEY;
92 if ( !isDown )
93 flags |= KEYEVENTF_KEYUP;
94
95 keybd_event(vkkeycode, 0, flags, 0);
96
97 return true;
98 }
99
100 #endif // wxUSE_UIACTIONSIMULATOR