SDL_epocevents.cpp
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:13k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

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