]>
Commit | Line | Data |
---|---|---|
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 | |
5bb302a7 | 7 | // RCS-ID: $Id$ |
a02a5cfc | 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 | 17 | |
8ea82c09 VZ |
18 | #ifndef WX_PRECOMP |
19 | #include "wx/msw/private.h" // For wxGetCursorPosMSW() | |
20 | #endif | |
21 | ||
a02a5cfc | 22 | #include "wx/uiaction.h" |
9b7e0226 | 23 | #include "wx/msw/wrapwin.h" |
a02a5cfc | 24 | |
0c03f52d VZ |
25 | #include "wx/msw/private/keyboard.h" |
26 | ||
616ad491 VZ |
27 | #include "wx/math.h" |
28 | ||
571d991b VZ |
29 | namespace |
30 | { | |
31 | ||
a02a5cfc KO |
32 | DWORD EventTypeForMouseButton(int button, bool isDown) |
33 | { | |
34 | switch (button) | |
35 | { | |
36 | case wxMOUSE_BTN_LEFT: | |
571d991b VZ |
37 | return isDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; |
38 | ||
a02a5cfc | 39 | case wxMOUSE_BTN_RIGHT: |
571d991b VZ |
40 | return isDown ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP; |
41 | ||
a02a5cfc | 42 | case wxMOUSE_BTN_MIDDLE: |
571d991b | 43 | return isDown ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP; |
9b7e0226 | 44 | |
a02a5cfc KO |
45 | default: |
46 | wxFAIL_MSG("Unsupported button passed in."); | |
571d991b | 47 | return (DWORD)-1; |
a02a5cfc KO |
48 | } |
49 | } | |
50 | ||
571d991b VZ |
51 | } // anonymous namespace |
52 | ||
a02a5cfc KO |
53 | bool wxUIActionSimulator::MouseDown(int button) |
54 | { | |
55 | POINT p; | |
d6c37f5b | 56 | wxGetCursorPosMSW(&p); |
a02a5cfc KO |
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) | |
9b7e0226 | 62 | { |
571d991b VZ |
63 | // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535 |
64 | // we need to scale our input too | |
616ad491 | 65 | int displayx, displayy; |
571d991b | 66 | wxDisplaySize(&displayx, &displayy); |
616ad491 | 67 | |
2aa54d47 VZ |
68 | // Casts are safe because x and y are supposed to be less than the display |
69 | // size, so there is no danger of overflow. | |
70 | DWORD scaledx = static_cast<DWORD>(ceil(x * 65535.0 / (displayx-1))); | |
71 | DWORD scaledy = static_cast<DWORD>(ceil(y * 65535.0 / (displayy-1))); | |
571d991b | 72 | mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, scaledx, scaledy, 0, 0); |
616ad491 | 73 | |
a02a5cfc KO |
74 | return true; |
75 | } | |
76 | ||
77 | bool wxUIActionSimulator::MouseUp(int button) | |
78 | { | |
79 | POINT p; | |
d6c37f5b | 80 | wxGetCursorPosMSW(&p); |
a02a5cfc KO |
81 | mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0); |
82 | return true; | |
83 | } | |
84 | ||
37141214 VZ |
85 | bool |
86 | wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown) | |
a02a5cfc | 87 | { |
2dcbc461 | 88 | bool isExtended; |
0c03f52d | 89 | DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended); |
2dcbc461 VZ |
90 | |
91 | DWORD flags = 0; | |
92 | if ( isExtended ) | |
93 | flags |= KEYEVENTF_EXTENDEDKEY; | |
94 | if ( !isDown ) | |
95 | flags |= KEYEVENTF_KEYUP; | |
96 | ||
97 | keybd_event(vkkeycode, 0, flags, 0); | |
571d991b | 98 | |
a02a5cfc KO |
99 | return true; |
100 | } | |
101 | ||
9b7e0226 | 102 | #endif // wxUSE_UIACTIONSIMULATOR |