]>
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 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/wxprec.h"
17 #include "wx/object.h"
20 #if wxUSE_UIACTIONSIMULATOR
22 #include "wx/uiaction.h"
26 #include "wx/osx/private.h"
27 #include "wx/osx/core/cfref.h"
32 CGEventTapLocation tap
= kCGSessionEventTap
;
34 CGEventType
CGEventTypeForMouseButton(int button
, bool isDown
)
38 case wxMOUSE_BTN_LEFT
:
39 return isDown
? kCGEventLeftMouseDown
: kCGEventLeftMouseUp
;
41 case wxMOUSE_BTN_RIGHT
:
42 return isDown
? kCGEventRightMouseDown
: kCGEventRightMouseUp
;
44 // All the other buttons use the constant OtherMouseDown but we still
45 // want to check for invalid parameters so assert first
47 wxFAIL_MSG("Unsupported button passed in.");
48 // fall back to the only known remaining case
50 case wxMOUSE_BTN_MIDDLE
:
51 return isDown
? kCGEventOtherMouseDown
: kCGEventOtherMouseUp
;
55 CGPoint
GetMousePosition()
58 wxGetMousePosition(&x
, &y
);
67 } // anonymous namespace
69 bool wxUIActionSimulator::MouseDown(int button
)
71 CGEventType type
= CGEventTypeForMouseButton(button
, true);
72 wxCFRef
<CGEventRef
> event(
73 CGEventCreateMouseEvent(NULL
, type
, GetMousePosition(), button
));
78 CGEventSetType(event
, type
);
79 CGEventPost(tap
, event
);
84 bool wxUIActionSimulator::MouseMove(long x
, long y
)
90 CGEventType type
= kCGEventMouseMoved
;
91 wxCFRef
<CGEventRef
> event(
92 CGEventCreateMouseEvent(NULL
, type
, pos
, kCGMouseButtonLeft
));
97 CGEventSetType(event
, type
);
98 CGEventPost(tap
, event
);
103 bool wxUIActionSimulator::MouseUp(int button
)
105 CGEventType type
= CGEventTypeForMouseButton(button
, false);
106 wxCFRef
<CGEventRef
> event(
107 CGEventCreateMouseEvent(NULL
, type
, GetMousePosition(), button
));
112 CGEventSetType(event
, type
);
113 CGEventPost(tap
, event
);
119 wxUIActionSimulator::DoKey(int keycode
, int WXUNUSED(modifiers
), bool isDown
)
121 CGKeyCode cgcode
= wxCharCodeWXToOSX((wxKeyCode
)keycode
);
124 event(CGEventCreateKeyboardEvent(NULL
, cgcode
, isDown
));
128 CGEventPost(kCGHIDEventTap
, event
);
132 #endif // wxUSE_UIACTIONSIMULATOR