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