]> git.saurik.com Git - wxWidgets.git/blame - src/osx/uiaction_osx.cpp
storing current event for dnd support, adding default data-drag image, fixes #12065
[wxWidgets.git] / src / osx / uiaction_osx.cpp
CommitLineData
a02a5cfc
KO
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/uiaction_osx.cpp
3// Purpose: wxUIActionSimulator implementation
4// Author: Kevin Ollivier
5// Modified by:
6// Created: 2010-03-06
7// RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
8// Copyright: (c) Kevin Ollivier
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
9b7e0226
VZ
12#include "wx/defs.h"
13
14#if wxUSE_UIACTIONSIMULATOR
15
16#include "wx/uiaction.h"
a02a5cfc
KO
17
18#include <ApplicationServices/ApplicationServices.h>
19
20CGEventTapLocation tap = kCGSessionEventTap;
21
22CGEventType CGEventTypeForMouseButton(int button, bool isDown)
23{
24 switch (button)
25 {
26 case wxMOUSE_BTN_LEFT:
27 if (isDown)
28 return kCGEventLeftMouseDown;
29 else
30 return kCGEventLeftMouseUp;
31 case wxMOUSE_BTN_RIGHT:
32 if (isDown)
33 return kCGEventRightMouseDown;
34 else
35 return kCGEventRightMouseUp;
9b7e0226
VZ
36
37 // Apparently all other buttons use the constant OtherMouseDown
38
a02a5cfc
KO
39 default:
40 if (isDown)
41 return kCGEventOtherMouseDown;
42 else
43 return kCGEventOtherMouseUp;
44 }
45}
46
47void SendCharCode(CGCharCode keycode, bool isDown)
48{
49 CGEventRef event = CGEventCreateKeyboardEvent(NULL, keycode, isDown);
50 if (event)
51 {
52 CGEventPost(kCGHIDEventTap, event);
53 }
54 CFRelease(event);
55}
56
57bool wxUIActionSimulator::MouseDown(int button)
58{
59 CGPoint pos;
60 int x, y;
9b7e0226 61 wxGetMousePosition(&x, &y);
a02a5cfc
KO
62 pos.x = x;
63 pos.y = y;
64 CGEventType type = CGEventTypeForMouseButton(button, true);
65 CGEventRef event = CGEventCreateMouseEvent(NULL, type, pos, button);
66 CGEventSetType(event, type);
9b7e0226 67
a02a5cfc
KO
68 if (event)
69 {
70 CGEventPost(tap, event);
71 }
72 CFRelease(event);
73 return true;
74}
75
76bool wxUIActionSimulator::MouseMove(long x, long y)
77{
78 CGPoint pos;
79 pos.x = x;
80 pos.y = y;
81 CGEventType type = kCGEventMouseMoved;
82 CGEventRef event = CGEventCreateMouseEvent(NULL, type, pos, kCGMouseButtonLeft);
83 CGEventSetType(event, type);
9b7e0226 84
a02a5cfc
KO
85 if (event)
86 {
87 CGEventPost(tap, event);
88 }
89 CFRelease(event);
9b7e0226 90
a02a5cfc
KO
91 return true;
92}
93
94bool wxUIActionSimulator::MouseUp(int button)
95{
96 CGPoint pos;
97 int x, y;
9b7e0226 98 wxGetMousePosition(&x, &y);
a02a5cfc
KO
99 pos.x = x;
100 pos.y = y;
101 CGEventType type = CGEventTypeForMouseButton(button, false);
102 CGEventRef event = CGEventCreateMouseEvent(NULL, type, pos, button);
103 CGEventSetType(event, type);
9b7e0226 104
a02a5cfc
KO
105 if (event)
106 {
107 CGEventPost(tap, event);
108 }
109 CFRelease(event);
110
111 return true;
112}
113
114bool wxUIActionSimulator::Key(int keycode, bool isDown, bool shiftDown, bool cmdDown, bool altDown)
115{
116 if (shiftDown)
117 SendCharCode((CGCharCode)56, true);
118 if (altDown)
119 SendCharCode((CGCharCode)58, true);
120 if (cmdDown)
121 SendCharCode((CGCharCode)55, true);
122
123 SendCharCode((CGCharCode)keycode, isDown);
124
125 if (shiftDown)
126 SendCharCode((CGCharCode)56, false);
127 if (altDown)
128 SendCharCode((CGCharCode)58, false);
129 if (cmdDown)
130 SendCharCode((CGCharCode)55, false);
9b7e0226 131
a02a5cfc
KO
132 return true;
133}
134
9b7e0226 135#endif // wxUSE_UIACTIONSIMULATOR
a02a5cfc 136