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