]>
Commit | Line | Data |
---|---|---|
a02a5cfc KO |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/common/uiactioncmn.cpp | |
3 | // Purpose: wxUIActionSimulator common 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 | ||
14 | #include "wx/wxprec.h" | |
15 | ||
9b7e0226 VZ |
16 | #if wxUSE_UIACTIONSIMULATOR |
17 | ||
a02a5cfc KO |
18 | #include "wx/uiaction.h" |
19 | ||
9b7e0226 | 20 | bool wxUIActionSimulator::MouseClick(int button) |
a02a5cfc KO |
21 | { |
22 | MouseDown(button); | |
23 | MouseUp(button); | |
9b7e0226 | 24 | |
a02a5cfc KO |
25 | return true; |
26 | } | |
27 | ||
cd0f218c SC |
28 | #ifndef __WXOSX__ |
29 | ||
9b7e0226 | 30 | bool wxUIActionSimulator::MouseDblClick(int button) |
a02a5cfc KO |
31 | { |
32 | MouseDown(button); | |
33 | MouseUp(button); | |
34 | MouseDown(button); | |
35 | MouseUp(button); | |
9b7e0226 | 36 | |
a02a5cfc KO |
37 | return true; |
38 | } | |
39 | ||
e5354813 | 40 | bool wxUIActionSimulator::MouseDragDrop(long x1, long y1, long x2, long y2, |
571d991b | 41 | int button) |
a02a5cfc KO |
42 | { |
43 | MouseMove(x1, y1); | |
44 | MouseDown(button); | |
9b7e0226 | 45 | MouseMove(x2, y2); |
a02a5cfc | 46 | MouseUp(button); |
e5354813 | 47 | |
a02a5cfc KO |
48 | return true; |
49 | } | |
50 | ||
e5354813 SC |
51 | #endif |
52 | ||
571d991b VZ |
53 | bool |
54 | wxUIActionSimulator::Key(int keycode, int modifiers, bool isDown) | |
55 | { | |
571d991b VZ |
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 | ||
37141214 VZ |
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); | |
571d991b VZ |
82 | } |
83 | ||
37141214 | 84 | bool wxUIActionSimulator::Char(int keycode, int modifiers) |
571d991b | 85 | { |
c0c9009c VZ |
86 | switch(keycode) |
87 | { | |
88 | case '0': | |
1863484b | 89 | keycode = '0'; |
c0c9009c VZ |
90 | break; |
91 | case '1': | |
1863484b | 92 | keycode = '1'; |
c0c9009c VZ |
93 | break; |
94 | case '2': | |
1863484b | 95 | keycode = '2'; |
c0c9009c VZ |
96 | break; |
97 | case '3': | |
1863484b | 98 | keycode = '3'; |
c0c9009c VZ |
99 | break; |
100 | case '4': | |
1863484b | 101 | keycode = '4'; |
c0c9009c VZ |
102 | break; |
103 | case '5': | |
1863484b | 104 | keycode = '5'; |
c0c9009c VZ |
105 | break; |
106 | case '6': | |
1863484b | 107 | keycode = '6'; |
c0c9009c VZ |
108 | break; |
109 | case '7': | |
1863484b | 110 | keycode = '7'; |
c0c9009c VZ |
111 | break; |
112 | case '8': | |
1863484b | 113 | keycode = '8'; |
c0c9009c VZ |
114 | break; |
115 | case '9': | |
1863484b | 116 | keycode = '9'; |
c0c9009c VZ |
117 | break; |
118 | case '+': | |
1863484b | 119 | keycode = '+'; |
c0c9009c VZ |
120 | break; |
121 | case '-': | |
1863484b | 122 | keycode = '-'; |
c0c9009c VZ |
123 | break; |
124 | case '.': | |
1863484b | 125 | keycode = '.'; |
c0c9009c VZ |
126 | break; |
127 | default: | |
128 | break; | |
129 | }; | |
130 | ||
571d991b VZ |
131 | Key(keycode, modifiers, true); |
132 | Key(keycode, modifiers, false); | |
133 | ||
134 | return true; | |
135 | } | |
136 | ||
137 | bool wxUIActionSimulator::Text(const char *s) | |
a02a5cfc | 138 | { |
571d991b VZ |
139 | while ( *s != '\0' ) |
140 | { | |
141 | const char ch = *s++; | |
571d991b VZ |
142 | if ( !Char(ch, isupper(ch) ? wxMOD_SHIFT : 0) ) |
143 | return false; | |
144 | } | |
9b7e0226 | 145 | |
a02a5cfc | 146 | return true; |
9b7e0226 VZ |
147 | } |
148 | ||
149 | #endif // wxUSE_UIACTIONSIMULATOR |