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