]> git.saurik.com Git - wxWidgets.git/blame - src/msw/uiaction.cpp
Don't use DDEExec registry key in wxMSW wxExecute() if it's empty.
[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
a02a5cfc 7// Copyright: (c) Kevin Ollivier
571d991b
VZ
8// (c) 2010 Steven Lamerton
9// (c) 2010 Vadim Zeitlin
a02a5cfc
KO
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#include "wx/wxprec.h"
14
9b7e0226 15#if wxUSE_UIACTIONSIMULATOR
a02a5cfc 16
8ea82c09
VZ
17#ifndef WX_PRECOMP
18 #include "wx/msw/private.h" // For wxGetCursorPosMSW()
19#endif
20
a02a5cfc 21#include "wx/uiaction.h"
9b7e0226 22#include "wx/msw/wrapwin.h"
a02a5cfc 23
0c03f52d
VZ
24#include "wx/msw/private/keyboard.h"
25
616ad491
VZ
26#include "wx/math.h"
27
571d991b
VZ
28namespace
29{
30
a02a5cfc
KO
31DWORD EventTypeForMouseButton(int button, bool isDown)
32{
33 switch (button)
34 {
35 case wxMOUSE_BTN_LEFT:
571d991b
VZ
36 return isDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
37
a02a5cfc 38 case wxMOUSE_BTN_RIGHT:
571d991b
VZ
39 return isDown ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
40
a02a5cfc 41 case wxMOUSE_BTN_MIDDLE:
571d991b 42 return isDown ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
9b7e0226 43
a02a5cfc
KO
44 default:
45 wxFAIL_MSG("Unsupported button passed in.");
571d991b 46 return (DWORD)-1;
a02a5cfc
KO
47 }
48}
49
571d991b
VZ
50} // anonymous namespace
51
a02a5cfc
KO
52bool wxUIActionSimulator::MouseDown(int button)
53{
54 POINT p;
d6c37f5b 55 wxGetCursorPosMSW(&p);
a02a5cfc
KO
56 mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
57 return true;
58}
59
60bool wxUIActionSimulator::MouseMove(long x, long y)
9b7e0226 61{
571d991b
VZ
62 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
63 // we need to scale our input too
616ad491 64 int displayx, displayy;
571d991b 65 wxDisplaySize(&displayx, &displayy);
616ad491 66
2aa54d47
VZ
67 // Casts are safe because x and y are supposed to be less than the display
68 // size, so there is no danger of overflow.
69 DWORD scaledx = static_cast<DWORD>(ceil(x * 65535.0 / (displayx-1)));
70 DWORD scaledy = static_cast<DWORD>(ceil(y * 65535.0 / (displayy-1)));
571d991b 71 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, scaledx, scaledy, 0, 0);
616ad491 72
a02a5cfc
KO
73 return true;
74}
75
76bool wxUIActionSimulator::MouseUp(int button)
77{
78 POINT p;
d6c37f5b 79 wxGetCursorPosMSW(&p);
a02a5cfc
KO
80 mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0);
81 return true;
82}
83
37141214
VZ
84bool
85wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
a02a5cfc 86{
2dcbc461 87 bool isExtended;
0c03f52d 88 DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended);
2dcbc461
VZ
89
90 DWORD flags = 0;
91 if ( isExtended )
92 flags |= KEYEVENTF_EXTENDEDKEY;
93 if ( !isDown )
94 flags |= KEYEVENTF_KEYUP;
95
96 keybd_event(vkkeycode, 0, flags, 0);
571d991b 97
a02a5cfc
KO
98 return true;
99}
100
9b7e0226 101#endif // wxUSE_UIACTIONSIMULATOR