notify the event loop that synthesized events are on the queue, wait for them to...
[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 #endif
41
42 bool
43 wxUIActionSimulator::MouseDragDrop(long x1, long y1, long x2, long y2,
44 int button)
45 {
46 MouseMove(x1, y1);
47 MouseDown(button);
48 MouseMove(x2, y2);
49 MouseUp(button);
50
51 return true;
52 }
53
54 bool
55 wxUIActionSimulator::Key(int keycode, int modifiers, bool isDown)
56 {
57 wxASSERT_MSG( (modifiers & wxMOD_ALTGR) != wxMOD_ALTGR,
58 "wxMOD_ALTGR is not implemented" );
59 wxASSERT_MSG( !(modifiers & wxMOD_META ),
60 "wxMOD_META is not implemented" );
61 wxASSERT_MSG( !(modifiers & wxMOD_WIN ),
62 "wxMOD_WIN is not implemented" );
63
64 if ( isDown )
65 SimulateModifiers(modifiers, true);
66
67 bool rc = DoKey(keycode, modifiers, isDown);
68
69 if ( !isDown )
70 SimulateModifiers(modifiers, false);
71
72 return rc;
73 }
74
75 void wxUIActionSimulator::SimulateModifiers(int modifiers, bool isDown)
76 {
77 if ( modifiers & wxMOD_SHIFT )
78 DoKey(WXK_SHIFT, modifiers, isDown);
79 if ( modifiers & wxMOD_ALT )
80 DoKey(WXK_ALT, modifiers, isDown);
81 if ( modifiers & wxMOD_CONTROL )
82 DoKey(WXK_CONTROL, modifiers, isDown);
83 }
84
85 bool wxUIActionSimulator::Char(int keycode, int modifiers)
86 {
87 switch(keycode)
88 {
89 case '0':
90 keycode = '0';
91 break;
92 case '1':
93 keycode = '1';
94 break;
95 case '2':
96 keycode = '2';
97 break;
98 case '3':
99 keycode = '3';
100 break;
101 case '4':
102 keycode = '4';
103 break;
104 case '5':
105 keycode = '5';
106 break;
107 case '6':
108 keycode = '6';
109 break;
110 case '7':
111 keycode = '7';
112 break;
113 case '8':
114 keycode = '8';
115 break;
116 case '9':
117 keycode = '9';
118 break;
119 case '+':
120 keycode = '+';
121 break;
122 case '-':
123 keycode = '-';
124 break;
125 case '.':
126 keycode = '.';
127 break;
128 default:
129 break;
130 };
131
132 Key(keycode, modifiers, true);
133 Key(keycode, modifiers, false);
134
135 return true;
136 }
137
138 bool wxUIActionSimulator::Text(const char *s)
139 {
140 while ( *s != '\0' )
141 {
142 const char ch = *s++;
143 if ( !Char(ch, isupper(ch) ? wxMOD_SHIFT : 0) )
144 return false;
145 }
146
147 return true;
148 }
149
150 #endif // wxUSE_UIACTIONSIMULATOR