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