src/video/photon/SDL_ph_events.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 19 Feb 2006 23:46:34 +0000
changeset 1379 c0a74f199ecf
parent 1361 19418e4422cb
child 1402 d910939febfa
permissions -rw-r--r--
Use only safe string functions
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 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     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /* Handle the event stream, converting photon events into SDL events */
    24 
    25 #include <stdio.h>
    26 #include <setjmp.h>
    27 #include <sys/time.h>
    28 
    29 #include <Ph.h>
    30 #include <photon/PkKeyDef.h>
    31 
    32 #include "SDL.h"
    33 #include "SDL_syswm.h"
    34 #include "../SDL_sysvideo.h"
    35 #include "../../events/SDL_sysevents.h"
    36 #include "../../events/SDL_events_c.h"
    37 #include "SDL_ph_video.h"
    38 #include "SDL_ph_modes_c.h"
    39 #include "SDL_ph_image_c.h"
    40 #include "SDL_ph_events_c.h"
    41 #include "SDL_phyuv_c.h"
    42 
    43 /* The translation tables from a photon keysym to a SDL keysym */
    44 static SDLKey ODD_keymap[256];
    45 static SDLKey MISC_keymap[0xFF + 1];
    46 SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym);
    47 
    48 /* Check to see if this is a repeated key.
    49    (idea shamelessly lifted from GII -- thanks guys! :) */
    50 static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
    51 {
    52     PhRect_t *rect = PhGetRects( winEvent );
    53 
    54     int centre_x, centre_y;
    55     int dx, dy;
    56     short abs_x, abs_y;
    57     int posted;
    58 
    59     centre_x = SDL_VideoSurface->w / 2;
    60     centre_y = SDL_VideoSurface->h / 2;
    61 
    62     dx = rect->ul.x - centre_x;
    63     dy = rect->ul.y - centre_y;
    64 
    65     posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
    66 
    67     /* Move mouse cursor to middle of the window */
    68     PtGetAbsPosition( window, &abs_x, &abs_y );
    69     PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y);
    70 
    71     return (posted);
    72 }
    73 
    74 /* Control which motion flags the window has set, a flags value of -1 sets
    75  * MOTION_BUTTON and MOTION_NOBUTTON */
    76 
    77 static void set_motion_sensitivity(_THIS, unsigned int flags)
    78 {
    79     int rid;
    80     int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
    81     PhRegion_t region;
    82 
    83     if( window )
    84     {
    85         rid = PtWidgetRid(window);
    86         if( rid != 0 && PhRegionQuery(rid, &region, NULL, NULL, 0) == 0 )
    87         {
    88             region.events_sense=(region.events_sense & ~fields)|(flags & fields);
    89             PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
    90         }
    91     }
    92 }
    93 
    94 /* Convert the photon button state value to an SDL value */
    95 static Uint8 ph2sdl_mousebutton(unsigned short button_state)
    96 {
    97     Uint8 mouse_button = 0;
    98 
    99     if (button_state & Ph_BUTTON_SELECT)
   100         mouse_button |= SDL_BUTTON_LEFT;
   101     if (button_state & Ph_BUTTON_MENU)
   102         mouse_button |= SDL_BUTTON_RIGHT;
   103     if (button_state & Ph_BUTTON_ADJUST)
   104         mouse_button |= SDL_BUTTON_MIDDLE;
   105 
   106     return (mouse_button);
   107 }
   108 
   109 static int ph_DispatchEvent(_THIS)
   110 {
   111     int posted;
   112     PhRect_t* rect;
   113     PhPointerEvent_t* pointerEvent;
   114     PhKeyEvent_t* keyEvent;
   115     PhWindowEvent_t* winEvent;
   116     int i, buttons;
   117     SDL_Rect sdlrects[PH_SDL_MAX_RECTS];
   118 	
   119     posted = 0;
   120 	
   121     switch (event->type)
   122     {
   123         case Ph_EV_BOUNDARY:
   124         {
   125             if (event->subtype == Ph_EV_PTR_ENTER)
   126             {
   127                 posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   128             }
   129             else if (event->subtype ==Ph_EV_PTR_LEAVE)
   130             {
   131                 posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);	
   132             }
   133         }
   134         break;
   135 
   136         case Ph_EV_PTR_MOTION_BUTTON:
   137         case Ph_EV_PTR_MOTION_NOBUTTON:
   138         {
   139             if (SDL_VideoSurface)
   140             {
   141                 pointerEvent = PhGetData(event);
   142                 rect = PhGetRects(event);
   143 
   144                 if (mouse_relative)
   145                 {
   146                     posted = ph_WarpedMotion(this, event);
   147                 }
   148                 else
   149                 {
   150                     posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y);
   151                 }
   152             }
   153         }
   154         break;
   155 
   156         case Ph_EV_BUT_PRESS:
   157         {
   158             pointerEvent = PhGetData( event );
   159             buttons = ph2sdl_mousebutton( pointerEvent->buttons );
   160             if (buttons != 0)
   161             {
   162                 posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0);
   163             }
   164         }
   165         break;
   166 
   167         case Ph_EV_BUT_RELEASE:
   168         {
   169             pointerEvent = PhGetData(event);
   170             buttons = ph2sdl_mousebutton(pointerEvent->buttons);
   171             if (event->subtype == Ph_EV_RELEASE_REAL && buttons != 0)
   172             {
   173                 posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
   174             }
   175             else if(event->subtype == Ph_EV_RELEASE_PHANTOM)
   176             {
   177                 /* If the mouse is outside the window,
   178                  * only a phantom release event is sent, so
   179                  * check if the window doesn't have mouse focus.
   180                  * Not perfect, maybe checking the mouse button
   181                  * state for Ph_EV_BOUNDARY events would be
   182                  * better. */
   183                 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0)
   184 		{
   185                     posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
   186                 }
   187             }
   188         }
   189         break;
   190 
   191         case Ph_EV_WM:
   192         {
   193             winEvent = PhGetData(event);
   194 
   195             /* losing focus */
   196             if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
   197             {
   198                 set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
   199                 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
   200             }
   201             /* gaining focus */
   202             else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
   203             {
   204                 set_motion_sensitivity(this, -1);
   205                 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   206             }
   207             /* request quit */
   208             else if (winEvent->event_f==Ph_WM_CLOSE)
   209             {
   210                 posted = SDL_PrivateQuit();
   211             }
   212             /* request hide/unhide */
   213             else if (winEvent->event_f==Ph_WM_HIDE)
   214             {
   215                 if (currently_hided)
   216                 {
   217                    /* got unhide window event                                */
   218                    /* TODO: restore application's palette if in palette mode */
   219                    currently_hided=0;
   220                 }
   221                 else
   222                 {
   223                    /* got hide window event                                  */
   224                    /* TODO: restore original palette if in palette mode      */
   225                    currently_hided=1;
   226                 }
   227             }
   228             /* request to resize */
   229             else if (winEvent->event_f==Ph_WM_RESIZE)
   230             {
   231                 currently_maximized=0;
   232                 #if (_NTO_VERSION < 630)
   233                    SDL_PrivateResize(winEvent->size.w+1, winEvent->size.h+1);
   234                 #else
   235                    /* QNX 6.3.0 have this bug fixed */
   236                    SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
   237                 #endif /* _NTO_VERSION */
   238             }
   239             /* request to move */
   240             else if (winEvent->event_f==Ph_WM_MOVE)
   241             {
   242                 if (current_overlay!=NULL)
   243                 {
   244                    int lockedstate=current_overlay->hwdata->locked;
   245                    int chromastate=current_overlay->hwdata->ischromakey;
   246                    int error;
   247                    SDL_Rect target;
   248 
   249                    current_overlay->hwdata->locked=1;
   250                    target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
   251                    target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
   252                    target.w=current_overlay->hwdata->CurrentViewPort.size.w;
   253                    target.h=current_overlay->hwdata->CurrentViewPort.size.h;
   254                    current_overlay->hwdata->ischromakey=0;
   255                    error=ph_DisplayYUVOverlay(this, current_overlay, &target);
   256                    if (!error)
   257                    {
   258                        current_overlay->hwdata->ischromakey=chromastate;
   259                        current_overlay->hwdata->locked=lockedstate;
   260                    }
   261                 }
   262             }
   263             /* maximize request */
   264             else if (winEvent->event_f==Ph_WM_MAX)
   265             {
   266                 /* window already moved and resized here */
   267                 currently_maximized=1;
   268             }
   269             /* restore request */
   270             else if (winEvent->event_f==Ph_WM_RESTORE)
   271             {
   272                 /* window already moved and resized here */
   273                 currently_maximized=0;
   274             }
   275         }
   276         break;
   277 
   278         /* window has been resized, moved or removed */
   279         case Ph_EV_EXPOSE:
   280         {
   281             if (event->num_rects!=0)
   282             {
   283                 int numrects;
   284 
   285                 if (SDL_VideoSurface)
   286                 {
   287                     rect = PhGetRects(event);
   288                     if (event->num_rects>PH_SDL_MAX_RECTS)
   289                     {
   290                        /* sorry, buffers underrun, we'll update only first PH_SDL_MAX_RECTS rects */
   291                        numrects=PH_SDL_MAX_RECTS;
   292                     }
   293 
   294                     for(i=0; i<event->num_rects; i++)
   295                     {
   296                         sdlrects[i].x = rect[i].ul.x;
   297                         sdlrects[i].y = rect[i].ul.y;
   298                         sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
   299                         sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
   300                     }
   301 
   302                     this->UpdateRects(this, event->num_rects, sdlrects);
   303 
   304                     if (current_overlay!=NULL)
   305                     {
   306                         int lockedstate=current_overlay->hwdata->locked;
   307                         int error;
   308                         SDL_Rect target;
   309 
   310                         current_overlay->hwdata->locked=1;
   311                         target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
   312                         target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
   313                         target.w=current_overlay->hwdata->CurrentViewPort.size.w;
   314                         target.h=current_overlay->hwdata->CurrentViewPort.size.h;
   315                         current_overlay->hwdata->forcedredraw=1;
   316                         error=ph_DisplayYUVOverlay(this, current_overlay, &target);
   317                         if (!error)
   318                         {
   319                             current_overlay->hwdata->forcedredraw=0;
   320                             current_overlay->hwdata->locked=lockedstate;
   321                         }
   322                     }
   323                 }
   324             }
   325         }
   326 	break;
   327 
   328         case Ph_EV_KEY:
   329         {
   330             SDL_keysym keysym;
   331 
   332             posted = 0;
   333 
   334             keyEvent = PhGetData( event );
   335 
   336             if (Pk_KF_Key_Down & keyEvent->key_flags)
   337             {
   338                 /* split the wheel events from real key events */
   339                 if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   340                 {
   341                    posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
   342                    break;
   343                 }
   344                 if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   345                 {
   346                    posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
   347                    break;
   348                 }
   349                 posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
   350             }
   351             else /* must be key release */
   352             {
   353                 /* split the wheel events from real key events */
   354                 if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   355                 {
   356                    posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
   357                    break;
   358                 }
   359                 if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   360                 {
   361                    posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
   362                    break;
   363                 }
   364                 posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
   365             }
   366         }
   367         break;
   368         
   369         case Ph_EV_INFO:
   370         {
   371            if (event->subtype==Ph_OFFSCREEN_INVALID)
   372            {
   373               unsigned long* EvInfoData;
   374 
   375               EvInfoData=(unsigned long*)PhGetData(event);
   376 
   377               switch (*EvInfoData)
   378               {
   379                  case Pg_VIDEO_MODE_SWITCHED:
   380                       {
   381                       }
   382                       break;
   383                  case Pg_ENTERED_DIRECT:
   384                       {
   385                       }
   386                       break;
   387                  case Pg_EXITED_DIRECT:
   388                       {
   389                       }
   390                       break;
   391                  case Pg_DRIVER_STARTED:
   392                       {
   393                       }
   394                       break;
   395               }
   396            }
   397         }
   398         break;
   399     }
   400 
   401     return(posted);
   402 }
   403 
   404 /* perform a blocking read if no events available */
   405 int ph_Pending(_THIS)
   406 {
   407     /* Flush the display connection and look to see if events are queued */
   408     PgFlush();
   409 
   410     while (1)
   411     {
   412         switch(PhEventPeek(event, EVENT_SIZE))
   413         {
   414             case Ph_EVENT_MSG:
   415                  return 1;
   416             case -1:
   417                  SDL_SetError("ph_Pending(): PhEventNext failed.\n");
   418                  return 0;
   419             default:
   420                  return 0;
   421         }
   422     }
   423 
   424     /* Oh well, nothing is ready .. */
   425     return(0);
   426 }
   427 
   428 void ph_PumpEvents(_THIS)
   429 {
   430     /* Flush the display connection and look to see if events are queued */
   431     PgFlush();
   432 
   433     while (ph_Pending(this))
   434     {
   435         PtEventHandler(event);
   436         ph_DispatchEvent(this);
   437     }
   438 }
   439 
   440 void ph_InitKeymap(void)
   441 {
   442     int i;
   443 
   444     /* Odd keys used in international keyboards */
   445     for (i=0; i<SDL_arraysize(ODD_keymap); ++i)
   446     {
   447         ODD_keymap[i] = SDLK_UNKNOWN;
   448     }
   449 
   450     /* Map the miscellaneous keys */
   451     for (i=0; i<SDL_arraysize(MISC_keymap); ++i)
   452     {
   453         MISC_keymap[i] = SDLK_UNKNOWN;
   454     }
   455 
   456     MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
   457     MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
   458     MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
   459     MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
   460     MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
   461     MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
   462     MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
   463 
   464     MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
   465     MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
   466     MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
   467     MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
   468     MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
   469     MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
   470     MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
   471     MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
   472     MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
   473     MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
   474 
   475     MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
   476     MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
   477     MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
   478     MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
   479     MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
   480     MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
   481     MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
   482 
   483     MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
   484     MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
   485     MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
   486     MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
   487     MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
   488     MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
   489     MISC_keymap[Pk_End&0xFF] = SDLK_END;
   490     MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
   491     MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
   492 
   493     MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
   494     MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
   495     MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
   496     MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
   497     MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
   498     MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
   499     MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
   500     MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
   501     MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
   502     MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
   503     MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
   504     MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
   505     MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
   506     MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
   507     MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
   508 
   509     MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
   510     MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
   511     MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
   512     MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
   513     MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
   514     MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
   515     MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
   516     MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
   517     MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
   518     MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
   519     MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
   520     MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;
   521     MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;
   522     MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key    */
   523 
   524     MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
   525     MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
   526     MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
   527     MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;        /* Windows "Menu" key */
   528 
   529     MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
   530 
   531     /* Left "Windows" key, but it can't be catched by application */
   532     MISC_keymap[Pk_Hyper_L&0xFF] = SDLK_LSUPER;
   533 }
   534 
   535 static unsigned long cap;
   536 
   537 SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
   538 {
   539     /* 'sym' is set to the value of the key with modifiers applied to it.
   540        This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
   541        We will assume it is valid. */
   542 
   543     /* FIXME: This needs to check whether the cap & scancode is valid */
   544 
   545     cap = key->key_cap;
   546 
   547     switch (cap>>8)
   548     {
   549         case 0x00:  /* Latin 1 */
   550         case 0x01:  /* Latin 2 */
   551         case 0x02:  /* Latin 3 */
   552         case 0x03:  /* Latin 4 */
   553         case 0x04:  /* Katakana */
   554         case 0x05:  /* Arabic */
   555         case 0x06:  /* Cyrillic */
   556         case 0x07:  /* Greek */
   557         case 0x08:  /* Technical */
   558         case 0x0A:  /* Publishing */
   559         case 0x0C:  /* Hebrew */
   560         case 0x0D:  /* Thai */
   561                    keysym->sym = (SDLKey)(cap&0xFF);
   562                    /* Map capital letter syms to lowercase */
   563                    if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
   564                        keysym->sym += ('a'-'A');
   565                    break;
   566         case 0xF0:
   567                    keysym->sym = MISC_keymap[cap&0xFF];
   568                    break;
   569         default:
   570                    keysym->sym = SDLK_UNKNOWN;                
   571                    break;
   572     }
   573 
   574     keysym->scancode = key->key_scan;
   575     keysym->unicode = 0;
   576 
   577     if (SDL_TranslateUNICODE)
   578     {
   579         char utf8[MB_CUR_MAX];
   580         int utf8len;
   581         wchar_t unicode;
   582 
   583         switch (keysym->scancode)
   584         {
   585            /* Esc key */
   586            case 0x01: keysym->unicode = 27;
   587                       break;
   588            /* BackSpace key */
   589            case 0x0E: keysym->unicode = 127;
   590                       break;
   591            /* Enter key */
   592            case 0x1C: keysym->unicode = 10;
   593                       break;
   594            default:
   595                       utf8len = PhKeyToMb(utf8, key);
   596                       if (utf8len > 0)
   597                       {
   598                          utf8len = mbtowc(&unicode, utf8, utf8len);
   599                          if (utf8len > 0)
   600                          {
   601                              keysym->unicode = unicode;
   602                          }
   603                       }
   604                       break;
   605         }
   606 
   607     }
   608 
   609     return (keysym);
   610 }
   611 
   612 void ph_InitOSKeymap(_THIS)
   613 {
   614     ph_InitKeymap();
   615 }