author | alwin <alwin> | 2004-08-02 08:19:00 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-08-02 08:19:00 (UTC) |
commit | eb1b398e44c55058d65be0a8d5d8c24db9b6d874 (patch) (unidiff) | |
tree | 5c7b84214e1a414f1de7d006cea49f57addabc82 | |
parent | 26e22b14963afc0e75b9bfdbdf97110249ae87c5 (diff) | |
download | opie-eb1b398e44c55058d65be0a8d5d8c24db9b6d874.zip opie-eb1b398e44c55058d65be0a8d5d8c24db9b6d874.tar.gz opie-eb1b398e44c55058d65be0a8d5d8c24db9b6d874.tar.bz2 |
ignore keys no actions are defined
-rw-r--r-- | noncore/applets/zkbapplet/keyzcfg/zkb.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkb.cpp b/noncore/applets/zkbapplet/keyzcfg/zkb.cpp index a357b88..3cc3669 100644 --- a/noncore/applets/zkbapplet/keyzcfg/zkb.cpp +++ b/noncore/applets/zkbapplet/keyzcfg/zkb.cpp | |||
@@ -1,592 +1,593 @@ | |||
1 | #include "zkb.h" | 1 | #include "zkb.h" |
2 | 2 | ||
3 | /* OPIE */ | 3 | /* OPIE */ |
4 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | #include <opie2/okeyfilter.h> | 5 | #include <opie2/okeyfilter.h> |
6 | 6 | ||
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | 8 | ||
9 | // Implementation of Action class | 9 | // Implementation of Action class |
10 | Action::Action():state(0), keycode(0), unicode(0), flags(0) { | 10 | Action::Action():state(0), keycode(0), unicode(0), flags(0) { |
11 | } | 11 | } |
12 | 12 | ||
13 | Action::Action(State* s, ushort kc, ushort uni, int f): | 13 | Action::Action(State* s, ushort kc, ushort uni, int f): |
14 | state(s), keycode(kc), unicode(uni), flags(f) { | 14 | state(s), keycode(kc), unicode(uni), flags(f) { |
15 | } | 15 | } |
16 | 16 | ||
17 | Action::~Action() { | 17 | Action::~Action() { |
18 | } | 18 | } |
19 | 19 | ||
20 | State* Action::getState() const { | 20 | State* Action::getState() const { |
21 | return state; | 21 | return state; |
22 | } | 22 | } |
23 | 23 | ||
24 | void Action::setState(State* s) { | 24 | void Action::setState(State* s) { |
25 | state = s; | 25 | state = s; |
26 | setDefined(true); | 26 | setDefined(true); |
27 | } | 27 | } |
28 | 28 | ||
29 | bool Action::hasEvent() const { | 29 | bool Action::hasEvent() const { |
30 | return flags & Event; | 30 | return flags & Event; |
31 | } | 31 | } |
32 | 32 | ||
33 | void Action::setEvent(bool e) { | 33 | void Action::setEvent(bool e) { |
34 | flags = (flags & ~Event) | ((e) ? Event : 0); | 34 | flags = (flags & ~Event) | ((e) ? Event : 0); |
35 | 35 | ||
36 | if (e) { | 36 | if (e) { |
37 | setDefined(true); | 37 | setDefined(true); |
38 | } else { | 38 | } else { |
39 | if (state == 0) { | 39 | if (state == 0) { |
40 | setDefined(false); | 40 | setDefined(false); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
45 | bool Action::isDefined() const { | 45 | bool Action::isDefined() const { |
46 | return flags & Defined; | 46 | return flags & Defined; |
47 | } | 47 | } |
48 | 48 | ||
49 | void Action::setDefined(bool d) { | 49 | void Action::setDefined(bool d) { |
50 | flags = (flags & ~Defined) | ((d) ? Defined : 0); | 50 | flags = (flags & ~Defined) | ((d) ? Defined : 0); |
51 | } | 51 | } |
52 | 52 | ||
53 | int Action::getKeycode() const { | 53 | int Action::getKeycode() const { |
54 | return keycode; | 54 | return keycode; |
55 | } | 55 | } |
56 | 56 | ||
57 | void Action::setKeycode(int c) { | 57 | void Action::setKeycode(int c) { |
58 | keycode = (ushort) c; | 58 | keycode = (ushort) c; |
59 | setEvent(true); | 59 | setEvent(true); |
60 | } | 60 | } |
61 | 61 | ||
62 | int Action::getUnicode() const { | 62 | int Action::getUnicode() const { |
63 | return unicode; | 63 | return unicode; |
64 | } | 64 | } |
65 | 65 | ||
66 | void Action::setUnicode(int u) { | 66 | void Action::setUnicode(int u) { |
67 | unicode = (ushort) u; | 67 | unicode = (ushort) u; |
68 | setEvent(true); | 68 | setEvent(true); |
69 | } | 69 | } |
70 | 70 | ||
71 | int Action::getModifiers() const { | 71 | int Action::getModifiers() const { |
72 | int ret = 0; | 72 | int ret = 0; |
73 | if (flags & Shift_Mod) { | 73 | if (flags & Shift_Mod) { |
74 | ret |= Qt::ShiftButton; | 74 | ret |= Qt::ShiftButton; |
75 | } | 75 | } |
76 | 76 | ||
77 | if (flags & Ctrl_Mod) { | 77 | if (flags & Ctrl_Mod) { |
78 | ret |= Qt::ControlButton; | 78 | ret |= Qt::ControlButton; |
79 | } | 79 | } |
80 | 80 | ||
81 | if (flags & Alt_Mod) { | 81 | if (flags & Alt_Mod) { |
82 | ret |= Qt::AltButton; | 82 | ret |= Qt::AltButton; |
83 | } | 83 | } |
84 | 84 | ||
85 | if (flags & Keypad_Mod) { | 85 | if (flags & Keypad_Mod) { |
86 | ret |= Qt::Keypad; | 86 | ret |= Qt::Keypad; |
87 | } | 87 | } |
88 | 88 | ||
89 | return ret; | 89 | return ret; |
90 | } | 90 | } |
91 | 91 | ||
92 | void Action::setModifiers(int m) { | 92 | void Action::setModifiers(int m) { |
93 | int n = 0; | 93 | int n = 0; |
94 | 94 | ||
95 | if (m & Qt::ShiftButton) { | 95 | if (m & Qt::ShiftButton) { |
96 | n |= Shift_Mod; | 96 | n |= Shift_Mod; |
97 | } | 97 | } |
98 | 98 | ||
99 | if (m & Qt::ControlButton) { | 99 | if (m & Qt::ControlButton) { |
100 | n |= Ctrl_Mod; | 100 | n |= Ctrl_Mod; |
101 | } | 101 | } |
102 | 102 | ||
103 | if (m & Qt::AltButton) { | 103 | if (m & Qt::AltButton) { |
104 | n |= Alt_Mod; | 104 | n |= Alt_Mod; |
105 | } | 105 | } |
106 | 106 | ||
107 | if (m & Qt::Keypad) { | 107 | if (m & Qt::Keypad) { |
108 | n |= Keypad_Mod; | 108 | n |= Keypad_Mod; |
109 | } | 109 | } |
110 | 110 | ||
111 | flags = flags & ~Mod_Bits | n; | 111 | flags = flags & ~Mod_Bits | n; |
112 | setEvent(true); | 112 | setEvent(true); |
113 | } | 113 | } |
114 | 114 | ||
115 | bool Action::isPressed() const { | 115 | bool Action::isPressed() const { |
116 | return (flags & Press) != 0; | 116 | return (flags & Press) != 0; |
117 | } | 117 | } |
118 | 118 | ||
119 | void Action::setPressed(bool p) { | 119 | void Action::setPressed(bool p) { |
120 | flags = (flags & ~Press) | ((p) ? Press : 0); | 120 | flags = (flags & ~Press) | ((p) ? Press : 0); |
121 | setEvent(true); | 121 | setEvent(true); |
122 | } | 122 | } |
123 | 123 | ||
124 | bool Action::isAutorepeat() const { | 124 | bool Action::isAutorepeat() const { |
125 | return (flags & Autorepeat) != 0; | 125 | return (flags & Autorepeat) != 0; |
126 | } | 126 | } |
127 | 127 | ||
128 | void Action::setAutorepeat(bool p) { | 128 | void Action::setAutorepeat(bool p) { |
129 | flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0); | 129 | flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0); |
130 | setEvent(true); | 130 | setEvent(true); |
131 | } | 131 | } |
132 | 132 | ||
133 | // Implementation of State class | 133 | // Implementation of State class |
134 | const short State::x1[] = { /* from 0x20 to 0x5f */ | 134 | const short State::x1[] = { /* from 0x20 to 0x5f */ |
135 | 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ | 135 | 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ |
136 | 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ | 136 | 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ |
137 | 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ | 137 | 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ |
138 | 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ | 138 | 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ |
139 | 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ | 139 | 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ |
140 | 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ | 140 | 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ |
141 | 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ | 141 | 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ |
142 | 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ | 142 | 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ |
143 | 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ | 143 | 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ |
144 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ | 144 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ |
145 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ | 145 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ |
146 | -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ | 146 | -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ |
147 | }; | 147 | }; |
148 | 148 | ||
149 | const short State::x2[] = { /* from 0x1000 to 0x1057*/ | 149 | const short State::x2[] = { /* from 0x1000 to 0x1057*/ |
150 | 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ | 150 | 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ |
151 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ | 151 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ |
152 | -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ | 152 | -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ |
153 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ | 153 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ |
154 | 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ | 154 | 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ |
155 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ | 155 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ |
156 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ | 156 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ |
157 | 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ | 157 | 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ |
158 | -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ | 158 | -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ |
159 | -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ | 159 | -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ |
160 | 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ | 160 | 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ |
161 | }; | 161 | }; |
162 | 162 | ||
163 | State::State(State* p):parent(p), keys(0) { | 163 | State::State(State* p):parent(p), keys(0) { |
164 | keys = new Action[Key_Max * 2 + 1]; | 164 | keys = new Action[Key_Max * 2 + 1]; |
165 | } | 165 | } |
166 | 166 | ||
167 | State::State(const State& s) { | 167 | State::State(const State& s) { |
168 | parent = s.parent; | 168 | parent = s.parent; |
169 | keys = new Action[Key_Max * 2 + 1]; | 169 | keys = new Action[Key_Max * 2 + 1]; |
170 | memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); | 170 | memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); |
171 | } | 171 | } |
172 | 172 | ||
173 | State::~State() { | 173 | State::~State() { |
174 | if (keys!=0) { | 174 | if (keys!=0) { |
175 | delete [] keys; | 175 | delete [] keys; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | Action* State::get(int keycode, bool pressed, bool follow) const { | 179 | Action* State::get(int keycode, bool pressed, bool follow) const { |
180 | Action* ret = 0; | 180 | Action* ret = 0; |
181 | int n = translateKeycode(keycode); | 181 | int n = translateKeycode(keycode); |
182 | 182 | ||
183 | if (n != -1 && keys != 0) { | 183 | if (n != -1 && keys != 0) { |
184 | if (pressed) { | 184 | if (pressed) { |
185 | n += Key_Max; | 185 | n += Key_Max; |
186 | } | 186 | } |
187 | ret = &keys[n]; | 187 | ret = &keys[n]; |
188 | } | 188 | } |
189 | 189 | ||
190 | if (ret==0 || !ret->isDefined()) { | 190 | if (ret==0 || !ret->isDefined()) { |
191 | if (follow && parent!=0) { | 191 | if (follow && parent!=0) { |
192 | ret = parent->get(keycode, pressed, follow); | 192 | ret = parent->get(keycode, pressed, follow); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | return ret; | 196 | return ret; |
197 | } | 197 | } |
198 | 198 | ||
199 | bool State::set(int keycode, bool pressed, Action& action) { | 199 | bool State::set(int keycode, bool pressed, Action& action) { |
200 | int n = translateKeycode(keycode); | 200 | int n = translateKeycode(keycode); |
201 | 201 | ||
202 | if (n==-1 || keys==0) { | 202 | if (n==-1 || keys==0) { |
203 | return false; | 203 | return false; |
204 | } | 204 | } |
205 | 205 | ||
206 | if (pressed) { | 206 | if (pressed) { |
207 | n += Key_Max + 1; | 207 | n += Key_Max + 1; |
208 | } | 208 | } |
209 | 209 | ||
210 | keys[n] = action; | 210 | keys[n] = action; |
211 | return true; | 211 | return true; |
212 | } | 212 | } |
213 | 213 | ||
214 | State* State::getParent() const { | 214 | State* State::getParent() const { |
215 | return parent; | 215 | return parent; |
216 | } | 216 | } |
217 | 217 | ||
218 | void State::setParent(State* s) { | 218 | void State::setParent(State* s) { |
219 | parent = s; | 219 | parent = s; |
220 | } | 220 | } |
221 | 221 | ||
222 | int State::translateKeycode(int keycode) const { | 222 | int State::translateKeycode(int keycode) const { |
223 | if (keycode < 0x20) { | 223 | if (keycode < 0x20) { |
224 | return -1; | 224 | return -1; |
225 | } | 225 | } |
226 | 226 | ||
227 | if (keycode < 0x80) { | 227 | if (keycode < 0x80) { |
228 | return x1[keycode - 0x20]; | 228 | return x1[keycode - 0x20]; |
229 | } | 229 | } |
230 | 230 | ||
231 | if (keycode < 0x1000) { | 231 | if (keycode < 0x1000) { |
232 | return -1; | 232 | return -1; |
233 | } | 233 | } |
234 | 234 | ||
235 | if (keycode < 0x1057) { | 235 | if (keycode < 0x1057) { |
236 | return x2[keycode - 0x1000]; | 236 | return x2[keycode - 0x1000]; |
237 | } | 237 | } |
238 | 238 | ||
239 | return -1; | 239 | return -1; |
240 | } | 240 | } |
241 | 241 | ||
242 | // Implementation of Keymap class | 242 | // Implementation of Keymap class |
243 | Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { | 243 | Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { |
244 | repeatDelay=400; | 244 | repeatDelay=400; |
245 | repeatPeriod=80; | 245 | repeatPeriod=80; |
246 | connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); | 246 | connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); |
247 | } | 247 | } |
248 | 248 | ||
249 | Keymap::~Keymap() { | 249 | Keymap::~Keymap() { |
250 | odebug << "removing keyboard filter for zkb"<<oendl; | 250 | odebug << "removing keyboard filter for zkb"<<oendl; |
251 | Opie::Core::OKeyFilter::inst()->remHandler(this); | 251 | Opie::Core::OKeyFilter::inst()->remHandler(this); |
252 | QMap<QString, State*>::Iterator it; | 252 | QMap<QString, State*>::Iterator it; |
253 | for(it = states.begin(); it != states.end(); ++it) { | 253 | for(it = states.begin(); it != states.end(); ++it) { |
254 | delete it.data(); | 254 | delete it.data(); |
255 | } | 255 | } |
256 | states.clear(); | 256 | states.clear(); |
257 | } | 257 | } |
258 | 258 | ||
259 | bool Keymap::filter(int unicode, int keycode, int modifiers, | 259 | bool Keymap::filter(int unicode, int keycode, int modifiers, |
260 | bool isPress, bool autoRepeat) { | 260 | bool isPress, bool autoRepeat) { |
261 | 261 | ||
262 | odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode | ||
263 | << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl; | ||
264 | |||
265 | if (!enabled) { | 262 | if (!enabled) { |
266 | return false; | 263 | return false; |
267 | } | 264 | } |
268 | 265 | ||
266 | odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode | ||
267 | << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl; | ||
268 | |||
269 | // the second check is workaround to make suspend work if | 269 | // the second check is workaround to make suspend work if |
270 | // the user pressed it right after he did resume. for some | 270 | // the user pressed it right after he did resume. for some |
271 | // reason the event sent by qt has autoRepeat true in this | 271 | // reason the event sent by qt has autoRepeat true in this |
272 | // case | 272 | // case |
273 | if (autoRepeat && keycode != 4177) { | 273 | if (autoRepeat && keycode != 4177) { |
274 | return true; | 274 | return true; |
275 | } | 275 | } |
276 | 276 | ||
277 | (void) unicode; (void) modifiers; | 277 | (void) unicode; (void) modifiers; |
278 | 278 | ||
279 | Action* action = currentState->get(keycode, isPress, true); | 279 | Action* action = currentState->get(keycode, isPress, true); |
280 | if (action==0 || !action->isDefined()) { | 280 | if (action==0 || !action->isDefined()) { |
281 | return true; | 281 | odebug << "no action defined for that"<<oendl; |
282 | return false; | ||
282 | } | 283 | } |
283 | 284 | ||
284 | if (action->hasEvent()) { | 285 | if (action->hasEvent()) { |
285 | odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode() | 286 | odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode() |
286 | << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl; | 287 | << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl; |
287 | 288 | ||
288 | QWSServer::sendKeyEvent(action->getUnicode(), | 289 | QWSServer::sendKeyEvent(action->getUnicode(), |
289 | action->getKeycode(), action->getModifiers(), | 290 | action->getKeycode(), action->getModifiers(), |
290 | action->isPressed(), false); | 291 | action->isPressed(), false); |
291 | } | 292 | } |
292 | 293 | ||
293 | if (action->isAutorepeat()) { | 294 | if (action->isAutorepeat()) { |
294 | autoRepeatAction = action; | 295 | autoRepeatAction = action; |
295 | repeater.start(repeatDelay, TRUE); | 296 | repeater.start(repeatDelay, TRUE); |
296 | } else { | 297 | } else { |
297 | autoRepeatAction = 0; | 298 | autoRepeatAction = 0; |
298 | } | 299 | } |
299 | 300 | ||
300 | State* nstate = action->getState(); | 301 | State* nstate = action->getState(); |
301 | if (nstate != 0) { | 302 | if (nstate != 0) { |
302 | setCurrentState(nstate); | 303 | setCurrentState(nstate); |
303 | QString lbl = getCurrentLabel(); | 304 | QString lbl = getCurrentLabel(); |
304 | if (!lbl.isEmpty()) { | 305 | if (!lbl.isEmpty()) { |
305 | emit stateChanged(lbl); | 306 | emit stateChanged(lbl); |
306 | } | 307 | } |
307 | } | 308 | } |
308 | 309 | ||
309 | 310 | ||
310 | return true; | 311 | return true; |
311 | } | 312 | } |
312 | 313 | ||
313 | void Keymap::enable() { | 314 | void Keymap::enable() { |
314 | enabled = true; | 315 | enabled = true; |
315 | } | 316 | } |
316 | 317 | ||
317 | void Keymap::disable() { | 318 | void Keymap::disable() { |
318 | enabled = false; | 319 | enabled = false; |
319 | } | 320 | } |
320 | 321 | ||
321 | QStringList Keymap::listStates() { | 322 | QStringList Keymap::listStates() { |
322 | QStringList ret; | 323 | QStringList ret; |
323 | 324 | ||
324 | QMap<QString, State*>::Iterator it; | 325 | QMap<QString, State*>::Iterator it; |
325 | for(it = states.begin(); it != states.end(); ++it) { | 326 | for(it = states.begin(); it != states.end(); ++it) { |
326 | ret.append(it.key()); | 327 | ret.append(it.key()); |
327 | } | 328 | } |
328 | 329 | ||
329 | return ret; | 330 | return ret; |
330 | } | 331 | } |
331 | 332 | ||
332 | State* Keymap::getStateByName(const QString& name) { | 333 | State* Keymap::getStateByName(const QString& name) { |
333 | QMap<QString, State*>::Iterator it = states.find(name); | 334 | QMap<QString, State*>::Iterator it = states.find(name); |
334 | 335 | ||
335 | if (it == states.end()) { | 336 | if (it == states.end()) { |
336 | return 0; | 337 | return 0; |
337 | } | 338 | } |
338 | 339 | ||
339 | return it.data(); | 340 | return it.data(); |
340 | } | 341 | } |
341 | 342 | ||
342 | QStringList Keymap::listLabels() { | 343 | QStringList Keymap::listLabels() { |
343 | QStringList ret; | 344 | QStringList ret; |
344 | 345 | ||
345 | for(uint i = 0; i < labelList.count(); i++) { | 346 | for(uint i = 0; i < labelList.count(); i++) { |
346 | ret.append(*labelList.at(i)); | 347 | ret.append(*labelList.at(i)); |
347 | } | 348 | } |
348 | 349 | ||
349 | return ret; | 350 | return ret; |
350 | } | 351 | } |
351 | 352 | ||
352 | State* Keymap::getStateByLabel(const QString& label) { | 353 | State* Keymap::getStateByLabel(const QString& label) { |
353 | QMap<QString, QString>::Iterator lit = labels.find(label); | 354 | QMap<QString, QString>::Iterator lit = labels.find(label); |
354 | State* state = 0; | 355 | State* state = 0; |
355 | 356 | ||
356 | if (lit == labels.end()) { | 357 | if (lit == labels.end()) { |
357 | return 0; | 358 | return 0; |
358 | } | 359 | } |
359 | 360 | ||
360 | QString name = lit.data(); | 361 | QString name = lit.data(); |
361 | 362 | ||
362 | int n = name.find(":*"); | 363 | int n = name.find(":*"); |
363 | if (n>=0 && n==(int)(name.length()-2)) { | 364 | if (n>=0 && n==(int)(name.length()-2)) { |
364 | name=name.left(name.length() - 1); | 365 | name=name.left(name.length() - 1); |
365 | 366 | ||
366 | n = currentStateName.findRev(":"); | 367 | n = currentStateName.findRev(":"); |
367 | if (n >= 0) { | 368 | if (n >= 0) { |
368 | name += currentStateName.mid(n+1); | 369 | name += currentStateName.mid(n+1); |
369 | } | 370 | } |
370 | } | 371 | } |
371 | 372 | ||
372 | // odebug << "look for: " << name.utf8() << "\n" << oendl; | 373 | // odebug << "look for: " << name.utf8() << "\n" << oendl; |
373 | QMap<QString, State*>::Iterator sit = states.find(name); | 374 | QMap<QString, State*>::Iterator sit = states.find(name); |
374 | if (sit != states.end()) { | 375 | if (sit != states.end()) { |
375 | state = sit.data(); | 376 | state = sit.data(); |
376 | } | 377 | } |
377 | 378 | ||
378 | return state; | 379 | return state; |
379 | } | 380 | } |
380 | 381 | ||
381 | bool Keymap::addState(const QString& name, State* state) { | 382 | bool Keymap::addState(const QString& name, State* state) { |
382 | if (states.find(name) != states.end()) { | 383 | if (states.find(name) != states.end()) { |
383 | return false; | 384 | return false; |
384 | } | 385 | } |
385 | 386 | ||
386 | states.insert(name, state); | 387 | states.insert(name, state); |
387 | lsmapInSync = false; | 388 | lsmapInSync = false; |
388 | 389 | ||
389 | if (currentState == 0) { | 390 | if (currentState == 0) { |
390 | setCurrentState(state); | 391 | setCurrentState(state); |
391 | } | 392 | } |
392 | 393 | ||
393 | return true; | 394 | return true; |
394 | } | 395 | } |
395 | 396 | ||
396 | State* Keymap::getCurrentState() const { | 397 | State* Keymap::getCurrentState() const { |
397 | return currentState; | 398 | return currentState; |
398 | } | 399 | } |
399 | 400 | ||
400 | QString Keymap::getCurrentLabel() { | 401 | QString Keymap::getCurrentLabel() { |
401 | return currentLabel; | 402 | return currentLabel; |
402 | } | 403 | } |
403 | 404 | ||
404 | bool Keymap::setCurrentState(State* state) { | 405 | bool Keymap::setCurrentState(State* state) { |
405 | QMap<QString, State*>::Iterator it; | 406 | QMap<QString, State*>::Iterator it; |
406 | for(it = states.begin(); it != states.end(); ++it) { | 407 | for(it = states.begin(); it != states.end(); ++it) { |
407 | State* s = it.data(); | 408 | State* s = it.data(); |
408 | if (s == state) { | 409 | if (s == state) { |
409 | currentState = s; | 410 | currentState = s; |
410 | currentStateName = it.key(); | 411 | currentStateName = it.key(); |
411 | 412 | ||
412 | odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl; | 413 | odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl; |
413 | 414 | ||
414 | if (!lsmapInSync) { | 415 | if (!lsmapInSync) { |
415 | generateLabelStateMaps(); | 416 | generateLabelStateMaps(); |
416 | } | 417 | } |
417 | 418 | ||
418 | QMap<State*, QString>::Iterator tit; | 419 | QMap<State*, QString>::Iterator tit; |
419 | tit = stateLabelMap.find(state); | 420 | tit = stateLabelMap.find(state); |
420 | if (tit != stateLabelMap.end()) { | 421 | if (tit != stateLabelMap.end()) { |
421 | currentLabel = tit.data(); | 422 | currentLabel = tit.data(); |
422 | } else { | 423 | } else { |
423 | // odebug << "no label for: " + currentStateName + "\n" << oendl; | 424 | // odebug << "no label for: " + currentStateName + "\n" << oendl; |
424 | currentLabel = ""; | 425 | currentLabel = ""; |
425 | } | 426 | } |
426 | 427 | ||
427 | return true; | 428 | return true; |
428 | } | 429 | } |
429 | } | 430 | } |
430 | 431 | ||
431 | return false; | 432 | return false; |
432 | } | 433 | } |
433 | 434 | ||
434 | bool Keymap::removeState(const QString& name, bool force) { | 435 | bool Keymap::removeState(const QString& name, bool force) { |
435 | QMap<QString, State*>::Iterator it = states.find(name); | 436 | QMap<QString, State*>::Iterator it = states.find(name); |
436 | 437 | ||
437 | if (it == states.end()) { | 438 | if (it == states.end()) { |
438 | return false; | 439 | return false; |
439 | } | 440 | } |
440 | 441 | ||
441 | State* state = it.data(); | 442 | State* state = it.data(); |
442 | QList<Action> acts = findStateUsage(state); | 443 | QList<Action> acts = findStateUsage(state); |
443 | 444 | ||
444 | if (!acts.isEmpty()) { | 445 | if (!acts.isEmpty()) { |
445 | if (!force) { | 446 | if (!force) { |
446 | return false; | 447 | return false; |
447 | } else { | 448 | } else { |
448 | for(Action* a = acts.first(); a != 0; a = acts.next()) { | 449 | for(Action* a = acts.first(); a != 0; a = acts.next()) { |
449 | a->setState(0); | 450 | a->setState(0); |
450 | } | 451 | } |
451 | } | 452 | } |
452 | } | 453 | } |
453 | 454 | ||
454 | if (state == currentState) { | 455 | if (state == currentState) { |
455 | if (states.begin() != states.end()) { | 456 | if (states.begin() != states.end()) { |
456 | setCurrentState(states.begin().data()); | 457 | setCurrentState(states.begin().data()); |
457 | } | 458 | } |
458 | } | 459 | } |
459 | 460 | ||
460 | states.remove(it); | 461 | states.remove(it); |
461 | delete state; | 462 | delete state; |
462 | 463 | ||
463 | lsmapInSync = false; | 464 | lsmapInSync = false; |
464 | 465 | ||
465 | return true; | 466 | return true; |
466 | } | 467 | } |
467 | 468 | ||
468 | void Keymap::autoRepeat() { | 469 | void Keymap::autoRepeat() { |
469 | if (autoRepeatAction != 0) { | 470 | if (autoRepeatAction != 0) { |
470 | odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode() | 471 | odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode() |
471 | << ", keycode=" << autoRepeatAction->getKeycode() | 472 | << ", keycode=" << autoRepeatAction->getKeycode() |
472 | << ", modifiers=" << autoRepeatAction->getModifiers() | 473 | << ", modifiers=" << autoRepeatAction->getModifiers() |
473 | << "ispressed=" << autoRepeatAction->isPressed() << oendl; | 474 | << "ispressed=" << autoRepeatAction->isPressed() << oendl; |
474 | 475 | ||
475 | QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), | 476 | QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), |
476 | autoRepeatAction->getKeycode(), | 477 | autoRepeatAction->getKeycode(), |
477 | autoRepeatAction->getModifiers(), | 478 | autoRepeatAction->getModifiers(), |
478 | autoRepeatAction->isPressed(), true); | 479 | autoRepeatAction->isPressed(), true); |
479 | } | 480 | } |
480 | 481 | ||
481 | repeater.start(repeatPeriod, TRUE); | 482 | repeater.start(repeatPeriod, TRUE); |
482 | } | 483 | } |
483 | 484 | ||
484 | bool Keymap::addLabel(const QString& label, const QString& state, int index) { | 485 | bool Keymap::addLabel(const QString& label, const QString& state, int index) { |
485 | if (labels.find(label) != labels.end()) { | 486 | if (labels.find(label) != labels.end()) { |
486 | return false; | 487 | return false; |
487 | } | 488 | } |
488 | 489 | ||
489 | labels.insert(label, state); | 490 | labels.insert(label, state); |
490 | const QString& l = labels.find(label).key(); | 491 | const QString& l = labels.find(label).key(); |
491 | if (index == -1) { | 492 | if (index == -1) { |
492 | labelList.append(l); | 493 | labelList.append(l); |
493 | } else { | 494 | } else { |
494 | labelList.insert(labelList.at(index), l); | 495 | labelList.insert(labelList.at(index), l); |
495 | } | 496 | } |
496 | 497 | ||
497 | lsmapInSync = false; | 498 | lsmapInSync = false; |
498 | 499 | ||
499 | return true; | 500 | return true; |
500 | } | 501 | } |
501 | 502 | ||
502 | bool Keymap::removeLabel(const QString& label) { | 503 | bool Keymap::removeLabel(const QString& label) { |
503 | 504 | ||
504 | if (labels.find(label) == labels.end()) { | 505 | if (labels.find(label) == labels.end()) { |
505 | return false; | 506 | return false; |
506 | } | 507 | } |
507 | 508 | ||
508 | labels.remove(label); | 509 | labels.remove(label); |
509 | labelList.remove(label); | 510 | labelList.remove(label); |
510 | lsmapInSync = false; | 511 | lsmapInSync = false; |
511 | 512 | ||
512 | if (label == currentLabel) { | 513 | if (label == currentLabel) { |
513 | currentLabel = ""; | 514 | currentLabel = ""; |
514 | } | 515 | } |
515 | 516 | ||
516 | return true; | 517 | return true; |
517 | } | 518 | } |
518 | 519 | ||
519 | int Keymap::getAutorepeatDelay() const { | 520 | int Keymap::getAutorepeatDelay() const { |
520 | return repeatDelay; | 521 | return repeatDelay; |
521 | } | 522 | } |
522 | 523 | ||
523 | void Keymap::setAutorepeatDelay(int n) { | 524 | void Keymap::setAutorepeatDelay(int n) { |
524 | repeatDelay = n; | 525 | repeatDelay = n; |
525 | } | 526 | } |
526 | 527 | ||
527 | int Keymap::getAutorepeatPeriod() const { | 528 | int Keymap::getAutorepeatPeriod() const { |
528 | return repeatPeriod; | 529 | return repeatPeriod; |
529 | } | 530 | } |
530 | 531 | ||
531 | void Keymap::setAutorepeatPeriod(int n) { | 532 | void Keymap::setAutorepeatPeriod(int n) { |
532 | repeatPeriod = n; | 533 | repeatPeriod = n; |
533 | } | 534 | } |
534 | 535 | ||
535 | QList<Action> Keymap::findStateUsage(State* s) { | 536 | QList<Action> Keymap::findStateUsage(State* s) { |
536 | QList<Action> ret; | 537 | QList<Action> ret; |
537 | 538 | ||
538 | QMap<QString, State*>::Iterator it; | 539 | QMap<QString, State*>::Iterator it; |
539 | for(it = states.begin(); it != states.end(); ++it) { | 540 | for(it = states.begin(); it != states.end(); ++it) { |
540 | State* state = it.data(); | 541 | State* state = it.data(); |
541 | 542 | ||
542 | for(int i = 0; i < 0x1100; i++) { | 543 | for(int i = 0; i < 0x1100; i++) { |
543 | Action* action = state->get(i, false); | 544 | Action* action = state->get(i, false); |
544 | if (action!=0 && action->getState()==s) { | 545 | if (action!=0 && action->getState()==s) { |
545 | ret.append(action); | 546 | ret.append(action); |
546 | } | 547 | } |
547 | 548 | ||
548 | action = state->get(i, true); | 549 | action = state->get(i, true); |
549 | if (action!=0 && action->getState()==s) { | 550 | if (action!=0 && action->getState()==s) { |
550 | ret.append(action); | 551 | ret.append(action); |
551 | } | 552 | } |
552 | } | 553 | } |
553 | } | 554 | } |
554 | 555 | ||
555 | return ret; | 556 | return ret; |
556 | } | 557 | } |
557 | 558 | ||
558 | void Keymap::generateLabelStateMaps() { | 559 | void Keymap::generateLabelStateMaps() { |
559 | stateLabelMap.clear(); | 560 | stateLabelMap.clear(); |
560 | 561 | ||
561 | QMap<QString, QString>::Iterator lit; | 562 | QMap<QString, QString>::Iterator lit; |
562 | for(lit = labels.begin(); lit != labels.end(); ++lit) { | 563 | for(lit = labels.begin(); lit != labels.end(); ++lit) { |
563 | QString label = lit.key(); | 564 | QString label = lit.key(); |
564 | QString name = lit.data(); | 565 | QString name = lit.data(); |
565 | 566 | ||
566 | bool wc = false; | 567 | bool wc = false; |
567 | int n = name.find("*"); | 568 | int n = name.find("*"); |
568 | if (n>=0 && n==(int)(name.length()-1)) { | 569 | if (n>=0 && n==(int)(name.length()-1)) { |
569 | name=name.left(name.length() - 1); | 570 | name=name.left(name.length() - 1); |
570 | wc = true; | 571 | wc = true; |
571 | } | 572 | } |
572 | 573 | ||
573 | QMap<QString, State*>::Iterator sit; | 574 | QMap<QString, State*>::Iterator sit; |
574 | for(sit = states.begin(); sit != states.end(); ++sit) { | 575 | for(sit = states.begin(); sit != states.end(); ++sit) { |
575 | QString sname = sit.key(); | 576 | QString sname = sit.key(); |
576 | State* state = sit.data(); | 577 | State* state = sit.data(); |
577 | 578 | ||
578 | if (sname.length() < name.length()) { | 579 | if (sname.length() < name.length()) { |
579 | continue; | 580 | continue; |
580 | } | 581 | } |
581 | 582 | ||
582 | if (sname.left(name.length()) == name) { | 583 | if (sname.left(name.length()) == name) { |
583 | if (wc || sname.length()==name.length()) { | 584 | if (wc || sname.length()==name.length()) { |
584 | stateLabelMap.insert(state, label); | 585 | stateLabelMap.insert(state, label); |
585 | } | 586 | } |
586 | 587 | ||
587 | } | 588 | } |
588 | } | 589 | } |
589 | } | 590 | } |
590 | 591 | ||
591 | lsmapInSync = true; | 592 | lsmapInSync = true; |
592 | } | 593 | } |