]> git.saurik.com Git - wxWidgets.git/blame - src/osx/uiaction_osx.cpp
Use IsThisEnabled() to test if AUI child is enabled, not IsEnabled().
[wxWidgets.git] / src / osx / uiaction_osx.cpp
CommitLineData
a02a5cfc
KO
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/uiaction_osx.cpp
3// Purpose: wxUIActionSimulator implementation
571d991b 4// Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
a02a5cfc
KO
5// Modified by:
6// Created: 2010-03-06
b5b208a1 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
9b7e0226
VZ
14#include "wx/defs.h"
15
16#if wxUSE_UIACTIONSIMULATOR
17
18#include "wx/uiaction.h"
a02a5cfc 19
571d991b
VZ
20#include "wx/log.h"
21
22#include "wx/osx/private.h"
23#include "wx/osx/core/cfref.h"
24
25namespace
26{
eeb7bdd0 27
a02a5cfc
KO
28CGEventTapLocation tap = kCGSessionEventTap;
29
30CGEventType CGEventTypeForMouseButton(int button, bool isDown)
31{
571d991b 32 switch ( button )
a02a5cfc
KO
33 {
34 case wxMOUSE_BTN_LEFT:
571d991b 35 return isDown ? kCGEventLeftMouseDown : kCGEventLeftMouseUp;
9b7e0226 36
571d991b
VZ
37 case wxMOUSE_BTN_RIGHT:
38 return isDown ? kCGEventRightMouseDown : kCGEventRightMouseUp;
9b7e0226 39
571d991b
VZ
40 // All the other buttons use the constant OtherMouseDown but we still
41 // want to check for invalid parameters so assert first
a02a5cfc 42 default:
571d991b
VZ
43 wxFAIL_MSG("Unsupported button passed in.");
44 // fall back to the only known remaining case
45
46 case wxMOUSE_BTN_MIDDLE:
47 return isDown ? kCGEventOtherMouseDown : kCGEventOtherMouseUp;
a02a5cfc
KO
48 }
49}
50
571d991b 51CGPoint GetMousePosition()
a02a5cfc 52{
571d991b
VZ
53 int x, y;
54 wxGetMousePosition(&x, &y);
55
56 CGPoint pos;
57 pos.x = x;
58 pos.y = y;
59
60 return pos;
61}
62
571d991b
VZ
63} // anonymous namespace
64
a02a5cfc
KO
65bool wxUIActionSimulator::MouseDown(int button)
66{
a02a5cfc 67 CGEventType type = CGEventTypeForMouseButton(button, true);
571d991b
VZ
68 wxCFRef<CGEventRef> event(
69 CGEventCreateMouseEvent(NULL, type, GetMousePosition(), button));
70
71 if ( !event )
72 return false;
73
a02a5cfc 74 CGEventSetType(event, type);
571d991b 75 CGEventPost(tap, event);
9b7e0226 76
a02a5cfc
KO
77 return true;
78}
79
80bool wxUIActionSimulator::MouseMove(long x, long y)
81{
82 CGPoint pos;
83 pos.x = x;
84 pos.y = y;
571d991b 85
a02a5cfc 86 CGEventType type = kCGEventMouseMoved;
571d991b
VZ
87 wxCFRef<CGEventRef> event(
88 CGEventCreateMouseEvent(NULL, type, pos, kCGMouseButtonLeft));
9b7e0226 89
571d991b
VZ
90 if ( !event )
91 return false;
92
93 CGEventSetType(event, type);
94 CGEventPost(tap, event);
9b7e0226 95
a02a5cfc
KO
96 return true;
97}
98
99bool wxUIActionSimulator::MouseUp(int button)
100{
a02a5cfc 101 CGEventType type = CGEventTypeForMouseButton(button, false);
571d991b
VZ
102 wxCFRef<CGEventRef> event(
103 CGEventCreateMouseEvent(NULL, type, GetMousePosition(), button));
9b7e0226 104
571d991b
VZ
105 if ( !event )
106 return false;
107
108 CGEventSetType(event, type);
109 CGEventPost(tap, event);
a02a5cfc
KO
110
111 return true;
112}
113
03bec791
VZ
114bool
115wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
a02a5cfc 116{
571d991b 117 CGKeyCode cgcode = wxCharCodeWXToOSX((wxKeyCode)keycode);
571d991b 118
37141214
VZ
119 wxCFRef<CGEventRef>
120 event(CGEventCreateKeyboardEvent(NULL, cgcode, isDown));
121 if ( !event )
122 return false;
9b7e0226 123
37141214 124 CGEventPost(kCGHIDEventTap, event);
a02a5cfc
KO
125 return true;
126}
127
9b7e0226 128#endif // wxUSE_UIACTIONSIMULATOR
a02a5cfc 129