comparison src/video/epoc/SDL_epocevents.cpp @ 173:83018110dce8

Added initial support for EPOC/Symbian OS (thanks Hannu!)
author Sam Lantinga <slouken@libsdl.org>
date Tue, 11 Sep 2001 20:38:49 +0000
parents
children e8157fcb3114
comparison
equal deleted inserted replaced
172:37e3ca9254c7 173:83018110dce8
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 /*
24 SDL_epocevents.cpp
25 Handle the event stream, converting Epoc events into SDL events
26
27 Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
28 */
29
30
31 #include <stdio.h>
32 #undef NULL
33
34 extern "C" {
35 #include "SDL_error.h"
36 #include "SDL_video.h"
37 #include "SDL_keysym.h"
38 #include "SDL_keyboard.h"
39 #include "SDL_events_c.h"
40 #include "SDL_timer.h"
41 }; /* extern "C" */
42
43 #include "SDL_epocvideo.h"
44 #include "SDL_epocevents_c.h"
45
46 #include <hal.h>
47
48 extern "C" {
49 /* The translation tables from a console scancode to a SDL keysym */
50 static SDLKey keymap[MAX_SCANCODE];
51 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym);
52 }; /* extern "C" */
53
54 TBool isCursorVisible = ETrue;
55
56 int EPOC_HandleWsEvent(_THIS, const TWsEvent& aWsEvent)
57 {
58 int posted = 0;
59 SDL_keysym keysym;
60
61
62 switch (aWsEvent.Type()) {
63
64 case EEventPointer: /* Mouse pointer events */
65 {
66 const TPointerEvent* pointerEvent = aWsEvent.Pointer();
67 TPoint mousePos = pointerEvent->iPosition;
68
69 //SDL_TRACE1("SDL: EPOC_HandleWsEvent, pointerEvent->iType=%d", pointerEvent->iType); //!!
70
71 if (Private->EPOC_ShrinkedHeight) {
72 mousePos.iY <<= 1; /* Scale y coordinate to shrinked screen height */
73 }
74 posted += SDL_PrivateMouseMotion(0, 0, mousePos.iX, mousePos.iY); /* Absolute position on screen */
75 if (pointerEvent->iType==TPointerEvent::EButton1Down) {
76 posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0);
77 }
78 else if (pointerEvent->iType==TPointerEvent::EButton1Up) {
79 posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0);
80 }
81 else if (pointerEvent->iType==TPointerEvent::EButton2Down) {
82 posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0);
83 }
84 else if (pointerEvent->iType==TPointerEvent::EButton2Up) {
85 posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0);
86 }
87 //!!posted += SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(aWsEvent.Key()->iScanCode, &keysym));
88 break;
89 }
90
91 case EEventKeyDown: /* Key events */
92 {
93 (void*)TranslateKey(aWsEvent.Key()->iScanCode, &keysym);
94
95 /* Special handling */
96 switch((int)keysym.sym) {
97 case SDLK_CAPSLOCK:
98 if (!isCursorVisible) {
99 /* Enable virtual cursor */
100 HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible);
101 }
102 else {
103 /* Disable virtual cursor */
104 HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible);
105 }
106 isCursorVisible = !isCursorVisible;
107 break;
108 }
109
110 posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
111 break;
112 }
113
114 case EEventKeyUp: /* Key events */
115 {
116 posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(aWsEvent.Key()->iScanCode, &keysym));
117 break;
118 }
119
120 case EEventFocusGained: /* SDL window got focus */
121 {
122 //Private->EPOC_IsWindowFocused = ETrue;
123 /* Draw window background and screen buffer */
124 RedrawWindowL(_this);
125 break;
126 }
127
128 case EEventFocusLost: /* SDL window lost focus */
129 {
130 //Private->EPOC_IsWindowFocused = EFalse;
131
132 // Wait and eat events until focus is gained again
133 /*
134 while (ETrue) {
135 Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
136 User::WaitForRequest(Private->EPOC_WsEventStatus);
137 Private->EPOC_WsSession.GetEvent(Private->EPOC_WsEvent);
138 TInt eventType = Private->EPOC_WsEvent.Type();
139 Private->EPOC_WsEventStatus = KRequestPending;
140 //Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
141 if (eventType == EEventFocusGained) {
142 RedrawWindowL(_this);
143 break;
144 }
145 }
146 */
147 break;
148 }
149
150 case EEventModifiersChanged:
151 {
152 TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged();
153 TUint modstate = KMOD_NONE;
154 if (modEvent->iModifiers == EModifierLeftShift)
155 modstate |= KMOD_LSHIFT;
156 if (modEvent->iModifiers == EModifierRightShift)
157 modstate |= KMOD_RSHIFT;
158 if (modEvent->iModifiers == EModifierLeftCtrl)
159 modstate |= KMOD_LCTRL;
160 if (modEvent->iModifiers == EModifierRightCtrl)
161 modstate |= KMOD_RCTRL;
162 if (modEvent->iModifiers == EModifierLeftAlt)
163 modstate |= KMOD_LALT;
164 if (modEvent->iModifiers == EModifierRightAlt)
165 modstate |= KMOD_RALT;
166 if (modEvent->iModifiers == EModifierLeftFunc)
167 modstate |= KMOD_LMETA;
168 if (modEvent->iModifiers == EModifierRightFunc)
169 modstate |= KMOD_RMETA;
170 if (modEvent->iModifiers == EModifierCapsLock)
171 modstate |= KMOD_CAPS;
172 SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT)));
173 break;
174 }
175 default:
176 break;
177 }
178
179 return posted;
180 }
181
182 extern "C" {
183
184 void EPOC_PumpEvents(_THIS)
185 {
186 int posted = 0; // !! Do we need this?
187 //Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
188 while (Private->EPOC_WsEventStatus != KRequestPending) {
189
190 Private->EPOC_WsSession.GetEvent(Private->EPOC_WsEvent);
191 posted = EPOC_HandleWsEvent(_this, Private->EPOC_WsEvent);
192 Private->EPOC_WsEventStatus = KRequestPending;
193 Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus);
194 }
195 }
196
197
198 void EPOC_InitOSKeymap(_THIS)
199 {
200 int i;
201
202 /* Initialize the key translation table */
203 for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
204 keymap[i] = SDLK_UNKNOWN;
205
206
207 /* Numbers */
208 for ( i = 0; i<32; ++i ){
209 keymap[' ' + i] = (SDLKey)(SDLK_SPACE+i);
210 }
211 /* e.g. Alphabet keys */
212 for ( i = 0; i<32; ++i ){
213 keymap['A' + i] = (SDLKey)(SDLK_a+i);
214 }
215
216 keymap[EStdKeyBackspace] = SDLK_BACKSPACE;
217 keymap[EStdKeyTab] = SDLK_TAB;
218 keymap[EStdKeyEnter] = SDLK_RETURN;
219 keymap[EStdKeyEscape] = SDLK_ESCAPE;
220 keymap[EStdKeySpace] = SDLK_SPACE;
221 keymap[EStdKeyPause] = SDLK_PAUSE;
222 keymap[EStdKeyHome] = SDLK_HOME;
223 keymap[EStdKeyEnd] = SDLK_END;
224 keymap[EStdKeyPageUp] = SDLK_PAGEUP;
225 keymap[EStdKeyPageDown] = SDLK_PAGEDOWN;
226 keymap[EStdKeyDelete] = SDLK_DELETE;
227 keymap[EStdKeyUpArrow] = SDLK_UP;
228 keymap[EStdKeyDownArrow] = SDLK_DOWN;
229 keymap[EStdKeyLeftArrow] = SDLK_LEFT;
230 keymap[EStdKeyRightArrow] = SDLK_RIGHT;
231 keymap[EStdKeyCapsLock] = SDLK_CAPSLOCK;
232 keymap[EStdKeyLeftShift] = SDLK_LSHIFT;
233 keymap[EStdKeyRightShift] = SDLK_RSHIFT;
234 keymap[EStdKeyLeftAlt] = SDLK_LALT;
235 keymap[EStdKeyRightAlt] = SDLK_RALT;
236 keymap[EStdKeyLeftCtrl] = SDLK_LCTRL;
237 keymap[EStdKeyRightCtrl] = SDLK_RCTRL;
238 keymap[EStdKeyLeftFunc] = SDLK_LMETA;
239 keymap[EStdKeyRightFunc] = SDLK_RMETA;
240 keymap[EStdKeyInsert] = SDLK_INSERT;
241 keymap[EStdKeyComma] = SDLK_COMMA;
242 keymap[EStdKeyFullStop] = SDLK_PERIOD;
243 keymap[EStdKeyForwardSlash] = SDLK_SLASH;
244 keymap[EStdKeyBackSlash] = SDLK_BACKSLASH;
245 keymap[EStdKeySemiColon] = SDLK_SEMICOLON;
246 keymap[EStdKeySingleQuote] = SDLK_QUOTE;
247 keymap[EStdKeyHash] = SDLK_HASH;
248 keymap[EStdKeySquareBracketLeft] = SDLK_LEFTBRACKET;
249 keymap[EStdKeySquareBracketRight] = SDLK_RIGHTBRACKET;
250 keymap[EStdKeyMinus] = SDLK_MINUS;
251 keymap[EStdKeyEquals] = SDLK_EQUALS;
252
253 keymap[EStdKeyF1] = SDLK_F1; /* chr + q */
254 keymap[EStdKeyF2] = SDLK_F2; /* chr + w */
255 keymap[EStdKeyF3] = SDLK_F3; /* chr + e */
256 keymap[EStdKeyF4] = SDLK_F4; /* chr + r */
257 keymap[EStdKeyF5] = SDLK_F5; /* chr + t */
258 keymap[EStdKeyF6] = SDLK_F6; /* chr + y */
259 keymap[EStdKeyF7] = SDLK_F7; /* chr + i */
260 keymap[EStdKeyF8] = SDLK_F8; /* chr + o */
261
262 keymap[EStdKeyF9] = SDLK_F9; /* chr + a */
263 keymap[EStdKeyF10] = SDLK_F10; /* chr + s */
264 keymap[EStdKeyF11] = SDLK_F11; /* chr + d */
265 keymap[EStdKeyF12] = SDLK_F12; /* chr + f */
266
267 /* !!TODO
268 EStdKeyNumLock=0x1b,
269 EStdKeyScrollLock=0x1c,
270
271 EStdKeyNkpForwardSlash=0x84,
272 EStdKeyNkpAsterisk=0x85,
273 EStdKeyNkpMinus=0x86,
274 EStdKeyNkpPlus=0x87,
275 EStdKeyNkpEnter=0x88,
276 EStdKeyNkp1=0x89,
277 EStdKeyNkp2=0x8a,
278 EStdKeyNkp3=0x8b,
279 EStdKeyNkp4=0x8c,
280 EStdKeyNkp5=0x8d,
281 EStdKeyNkp6=0x8e,
282 EStdKeyNkp7=0x8f,
283 EStdKeyNkp8=0x90,
284 EStdKeyNkp9=0x91,
285 EStdKeyNkp0=0x92,
286 EStdKeyNkpFullStop=0x93,
287 EStdKeyMenu=0x94,
288 EStdKeyBacklightOn=0x95,
289 EStdKeyBacklightOff=0x96,
290 EStdKeyBacklightToggle=0x97,
291 EStdKeyIncContrast=0x98,
292 EStdKeyDecContrast=0x99,
293 EStdKeySliderDown=0x9a,
294 EStdKeySliderUp=0x9b,
295 EStdKeyDictaphonePlay=0x9c,
296 EStdKeyDictaphoneStop=0x9d,
297 EStdKeyDictaphoneRecord=0x9e,
298 EStdKeyHelp=0x9f,
299 EStdKeyOff=0xa0,
300 EStdKeyDial=0xa1,
301 EStdKeyIncVolume=0xa2,
302 EStdKeyDecVolume=0xa3,
303 EStdKeyDevice0=0xa4,
304 EStdKeyDevice1=0xa5,
305 EStdKeyDevice2=0xa6,
306 EStdKeyDevice3=0xa7,
307 EStdKeyDevice4=0xa8,
308 EStdKeyDevice5=0xa9,
309 EStdKeyDevice6=0xaa,
310 EStdKeyDevice7=0xab,
311 EStdKeyDevice8=0xac,
312 EStdKeyDevice9=0xad,
313 EStdKeyDeviceA=0xae,
314 EStdKeyDeviceB=0xaf,
315 EStdKeyDeviceC=0xb0,
316 EStdKeyDeviceD=0xb1,
317 EStdKeyDeviceE=0xb2,
318 EStdKeyDeviceF=0xb3,
319 EStdKeyApplication0=0xb4,
320 EStdKeyApplication1=0xb5,
321 EStdKeyApplication2=0xb6,
322 EStdKeyApplication3=0xb7,
323 EStdKeyApplication4=0xb8,
324 EStdKeyApplication5=0xb9,
325 EStdKeyApplication6=0xba,
326 EStdKeyApplication7=0xbb,
327 EStdKeyApplication8=0xbc,
328 EStdKeyApplication9=0xbd,
329 EStdKeyApplicationA=0xbe,
330 EStdKeyApplicationB=0xbf,
331 EStdKeyApplicationC=0xc0,
332 EStdKeyApplicationD=0xc1,
333 EStdKeyApplicationE=0xc2,
334 EStdKeyApplicationF=0xc3,
335 EStdKeyYes=0xc4,
336 EStdKeyNo=0xc5,
337 EStdKeyIncBrightness=0xc6,
338 EStdKeyDecBrightness=0xc7,
339 EStdKeyCaseOpen=0xc8,
340 EStdKeyCaseClose=0xc9
341 */
342
343 }
344
345
346
347 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
348 {
349 char debug[256];
350 //SDL_TRACE1("SDL: TranslateKey, scancode=%d", scancode); //!!
351
352 /* Set the keysym information */
353
354 keysym->scancode = scancode;
355
356 if ((scancode >= MAX_SCANCODE) &&
357 ((scancode - ENonCharacterKeyBase + 0x0081) >= MAX_SCANCODE)) {
358 SDL_SetError("Too big scancode");
359 keysym->scancode = SDLK_UNKNOWN;
360 keysym->mod = KMOD_NONE;
361 return keysym;
362 }
363
364 keysym->mod = SDL_GetModState(); //!!Is this right??
365
366 /* Handle function keys: F1, F2, F3 ... */
367 if (keysym->mod & KMOD_META) {
368 if (scancode >= 'A' && scancode < ('A' + 24)) { /* first 32 alphapet keys */
369 switch(scancode) {
370 case 'Q': scancode = EStdKeyF1; break;
371 case 'W': scancode = EStdKeyF2; break;
372 case 'E': scancode = EStdKeyF3; break;
373 case 'R': scancode = EStdKeyF4; break;
374 case 'T': scancode = EStdKeyF5; break;
375 case 'Y': scancode = EStdKeyF6; break;
376 case 'U': scancode = EStdKeyF7; break;
377 case 'I': scancode = EStdKeyF8; break;
378 case 'A': scancode = EStdKeyF9; break;
379 case 'S': scancode = EStdKeyF10; break;
380 case 'D': scancode = EStdKeyF11; break;
381 case 'F': scancode = EStdKeyF12; break;
382 }
383 keysym->sym = keymap[scancode];
384 }
385 }
386
387 if (scancode >= ENonCharacterKeyBase) {
388 // Non character keys
389 keysym->sym = keymap[scancode -
390 ENonCharacterKeyBase + 0x0081]; // !!hard coded
391 } else {
392 keysym->sym = keymap[scancode];
393 }
394
395
396 /* If UNICODE is on, get the UNICODE value for the key */
397 keysym->unicode = 0;
398
399 #if 0 // !!TODO:unicode
400
401 if ( SDL_TranslateUNICODE )
402 {
403 /* Populate the unicode field with the ASCII value */
404 keysym->unicode = scancode;
405 }
406 #endif
407
408 //!!
409 //sprintf(debug, "SDL: TranslateKey: keysym->scancode=%d, keysym->sym=%d, keysym->mod=%d",
410 // keysym->scancode, keysym->sym, keysym->mod);
411 //SDL_TRACE(debug); //!!
412
413 return(keysym);
414 }
415
416 }; /* extern "C" */
417
418