]> git.saurik.com Git - wxWidgets.git/blob - src/common/uiactioncmn.cpp
make methods available to all ports
[wxWidgets.git] / src / common / uiactioncmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/uiactioncmn.cpp
3 // Purpose: wxUIActionSimulator common implementation
4 // Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
5 // Modified by:
6 // Created: 2010-03-06
7 // RCS-ID: $Id$
8 // Copyright: (c) Kevin Ollivier
9 // (c) 2010 Steven Lamerton
10 // (c) 2010 Vadim Zeitlin
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
13
14 #include "wx/wxprec.h"
15
16 #if wxUSE_UIACTIONSIMULATOR
17
18 #include "wx/uiaction.h"
19
20 bool wxUIActionSimulator::MouseClick(int button)
21 {
22 MouseDown(button);
23 MouseUp(button);
24
25 return true;
26 }
27
28 #ifndef __WXOSX__
29
30 bool wxUIActionSimulator::MouseDblClick(int button)
31 {
32 MouseDown(button);
33 MouseUp(button);
34 MouseDown(button);
35 MouseUp(button);
36
37 return true;
38 }
39
40 bool wxUIActionSimulator::MouseClickAndDragTo(long x, long y, int button)
41 {
42 MouseDown(button);
43 MouseMove(x,y);
44 MouseUp(button);
45 return true;
46 }
47
48 #endif
49
50 bool
51 wxUIActionSimulator::MouseDragDrop(long x1, long y1, long x2, long y2,
52 int button)
53 {
54 MouseMove(x1, y1);
55 MouseDown(button);
56 MouseMove(x2, y2);
57 MouseUp(button);
58
59 return true;
60 }
61
62 bool
63 wxUIActionSimulator::Key(int keycode, int modifiers, bool isDown)
64 {
65 wxASSERT_MSG( (modifiers & wxMOD_ALTGR) != wxMOD_ALTGR,
66 "wxMOD_ALTGR is not implemented" );
67 wxASSERT_MSG( !(modifiers & wxMOD_META ),
68 "wxMOD_META is not implemented" );
69 wxASSERT_MSG( !(modifiers & wxMOD_WIN ),
70 "wxMOD_WIN is not implemented" );
71
72 if ( isDown )
73 SimulateModifiers(modifiers, true);
74
75 bool rc = DoKey(keycode, modifiers, isDown);
76
77 if ( !isDown )
78 SimulateModifiers(modifiers, false);
79
80 return rc;
81 }
82
83 void wxUIActionSimulator::SimulateModifiers(int modifiers, bool isDown)
84 {
85 if ( modifiers & wxMOD_SHIFT )
86 DoKey(WXK_SHIFT, modifiers, isDown);
87 if ( modifiers & wxMOD_ALT )
88 DoKey(WXK_ALT, modifiers, isDown);
89 if ( modifiers & wxMOD_CONTROL )
90 DoKey(WXK_CONTROL, modifiers, isDown);
91 }
92
93 bool wxUIActionSimulator::Char(int keycode, int modifiers)
94 {
95 switch(keycode)
96 {
97 case '0':
98 keycode = '0';
99 break;
100 case '1':
101 keycode = '1';
102 break;
103 case '2':
104 keycode = '2';
105 break;
106 case '3':
107 keycode = '3';
108 break;
109 case '4':
110 keycode = '4';
111 break;
112 case '5':
113 keycode = '5';
114 break;
115 case '6':
116 keycode = '6';
117 break;
118 case '7':
119 keycode = '7';
120 break;
121 case '8':
122 keycode = '8';
123 break;
124 case '9':
125 keycode = '9';
126 break;
127 case '+':
128 keycode = '+';
129 break;
130 case '-':
131 keycode = '-';
132 break;
133 case '.':
134 keycode = '.';
135 break;
136 default:
137 break;
138 };
139
140 Key(keycode, modifiers, true);
141 Key(keycode, modifiers, false);
142
143 return true;
144 }
145
146 bool wxUIActionSimulator::Text(const char *s)
147 {
148 while ( *s != '\0' )
149 {
150 const char ch = *s++;
151 if ( !Char(ch, isupper(ch) ? wxMOD_SHIFT : 0) )
152 return false;
153 }
154
155 return true;
156 }
157
158 #endif // wxUSE_UIACTIONSIMULATOR