]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/uiaction_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/uiaction_osx.cpp
3 // Purpose: wxUIActionSimulator implementation
4 // Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
8 // Copyright: (c) Kevin Ollivier
9 // (c) 2010 Steven Lamerton
10 // (c) 2010 Vadim Zeitlin
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
16 #if wxUSE_UIACTIONSIMULATOR
18 #include "wx/uiaction.h"
22 #include "wx/osx/private.h"
23 #include "wx/osx/core/cfref.h"
28 CGEventTapLocation tap
= kCGSessionEventTap
;
30 CGEventType
CGEventTypeForMouseButton(int button
, bool isDown
)
34 case wxMOUSE_BTN_LEFT
:
35 return isDown
? kCGEventLeftMouseDown
: kCGEventLeftMouseUp
;
37 case wxMOUSE_BTN_RIGHT
:
38 return isDown
? kCGEventRightMouseDown
: kCGEventRightMouseUp
;
40 // All the other buttons use the constant OtherMouseDown but we still
41 // want to check for invalid parameters so assert first
43 wxFAIL_MSG("Unsupported button passed in.");
44 // fall back to the only known remaining case
46 case wxMOUSE_BTN_MIDDLE
:
47 return isDown
? kCGEventOtherMouseDown
: kCGEventOtherMouseUp
;
51 CGPoint
GetMousePosition()
54 wxGetMousePosition(&x
, &y
);
63 } // anonymous namespace
65 bool wxUIActionSimulator::MouseDown(int button
)
67 CGEventType type
= CGEventTypeForMouseButton(button
, true);
68 wxCFRef
<CGEventRef
> event(
69 CGEventCreateMouseEvent(NULL
, type
, GetMousePosition(), button
));
74 CGEventSetType(event
, type
);
75 CGEventPost(tap
, event
);
80 bool wxUIActionSimulator::MouseMove(long x
, long y
)
86 CGEventType type
= kCGEventMouseMoved
;
87 wxCFRef
<CGEventRef
> event(
88 CGEventCreateMouseEvent(NULL
, type
, pos
, kCGMouseButtonLeft
));
93 CGEventSetType(event
, type
);
94 CGEventPost(tap
, event
);
99 bool wxUIActionSimulator::MouseUp(int button
)
101 CGEventType type
= CGEventTypeForMouseButton(button
, false);
102 wxCFRef
<CGEventRef
> event(
103 CGEventCreateMouseEvent(NULL
, type
, GetMousePosition(), button
));
108 CGEventSetType(event
, type
);
109 CGEventPost(tap
, event
);
115 wxUIActionSimulator::DoKey(int keycode
, int WXUNUSED(modifiers
), bool isDown
)
117 CGKeyCode cgcode
= wxCharCodeWXToOSX((wxKeyCode
)keycode
);
120 event(CGEventCreateKeyboardEvent(NULL
, cgcode
, isDown
));
124 CGEventPost(kCGHIDEventTap
, event
);
128 #endif // wxUSE_UIACTIONSIMULATOR