]> git.saurik.com Git - wxWidgets.git/blame - src/msw/uiaction.cpp
Ignore WM_CLOSE generated by wxMSW edit control when Escape is pressed.
[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
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
KO
17
18#include "wx/uiaction.h"
9b7e0226 19#include "wx/msw/wrapwin.h"
a02a5cfc 20
0c03f52d
VZ
21#include "wx/msw/private/keyboard.h"
22
616ad491
VZ
23#include "wx/math.h"
24
571d991b
VZ
25namespace
26{
27
a02a5cfc
KO
28DWORD EventTypeForMouseButton(int button, bool isDown)
29{
30 switch (button)
31 {
32 case wxMOUSE_BTN_LEFT:
571d991b
VZ
33 return isDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
34
a02a5cfc 35 case wxMOUSE_BTN_RIGHT:
571d991b
VZ
36 return isDown ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
37
a02a5cfc 38 case wxMOUSE_BTN_MIDDLE:
571d991b 39 return isDown ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
9b7e0226 40
a02a5cfc
KO
41 default:
42 wxFAIL_MSG("Unsupported button passed in.");
571d991b 43 return (DWORD)-1;
a02a5cfc
KO
44 }
45}
46
571d991b
VZ
47} // anonymous namespace
48
a02a5cfc
KO
49bool wxUIActionSimulator::MouseDown(int button)
50{
51 POINT p;
52 GetCursorPos(&p);
53 mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
54 return true;
55}
56
57bool wxUIActionSimulator::MouseMove(long x, long y)
9b7e0226 58{
571d991b
VZ
59 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
60 // we need to scale our input too
616ad491 61 int displayx, displayy;
571d991b 62 wxDisplaySize(&displayx, &displayy);
616ad491
VZ
63
64 int scaledx = wxRound(((float)x / displayx) * 65535);
65 int scaledy = wxRound(((float)y / displayy) * 65535);
571d991b 66 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, scaledx, scaledy, 0, 0);
616ad491 67
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
37141214
VZ
79bool
80wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
a02a5cfc 81{
2dcbc461 82 bool isExtended;
0c03f52d 83 DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended);
2dcbc461
VZ
84
85 DWORD flags = 0;
86 if ( isExtended )
87 flags |= KEYEVENTF_EXTENDEDKEY;
88 if ( !isDown )
89 flags |= KEYEVENTF_KEYUP;
90
91 keybd_event(vkkeycode, 0, flags, 0);
571d991b 92
a02a5cfc
KO
93 return true;
94}
95
9b7e0226 96#endif // wxUSE_UIACTIONSIMULATOR