src/video/maccommon/SDL_macevents.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. Mac_HandleActivate
  2. myGlobalToLocal
  3. Mac_HandleEvents
  4. Mac_PumpEvents
  5. Mac_InitOSKeymap
  6. TranslateKey
  7. Mac_InitEvents
  8. Mac_QuitEvents
  9. Mac_DoAppleMenu
  10. SDL_InitQuickDraw

   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 #ifdef SAVE_RCSID
  24 static char rcsid =
  25  "@(#) $Id: SDL_macevents.c,v 1.1.2.17 2001/02/21 07:39:56 hercules Exp $";
  26 #endif
  27 
  28 #include <stdio.h>
  29 
  30 #if TARGET_API_MAC_CARBON
  31 #include <Carbon.h>
  32 #else
  33 #include <Script.h>
  34 #include <LowMem.h>
  35 #include <Devices.h>
  36 #include <DiskInit.h>
  37 #include <ToolUtils.h>
  38 #endif
  39 
  40 #include "SDL_events.h"
  41 #include "SDL_video.h"
  42 #include "SDL_error.h"
  43 #include "SDL_syswm.h"
  44 #include "SDL_events_c.h"
  45 #include "SDL_cursor_c.h"
  46 #include "SDL_sysevents.h"
  47 #include "SDL_macevents_c.h"
  48 #include "SDL_mackeys.h"
  49 #include "SDL_macmouse_c.h"
  50 
  51 /* Define this to be able to collapse SDL windows.
  52 #define USE_APPEARANCE_MANAGER
  53  */
  54 
  55 /* Macintosh resource constants */
  56 #define mApple  128                     /* Apple menu resource */
  57 #define iAbout  1                       /* About menu item */
  58 
  59 /* Functions to handle the About menu */
  60 static void Mac_DoAppleMenu(_THIS, long item);
  61 
  62 /* The translation table from a macintosh key scancode to a SDL keysym */
  63 static SDLKey MAC_keymap[256];
  64 static SDL_keysym *TranslateKey(int scancode, int modifiers,
  65                                 SDL_keysym *keysym, int pressed);
  66 
  67 /* Handle activation and deactivation  -- returns whether an event was posted */
  68 static int Mac_HandleActivate(int activate)
     /* [<][>][^][v][top][bottom][index][help] */
  69 {
  70         if ( activate ) {
  71                 /* Show the current SDL application cursor */
  72                 SDL_SetCursor(NULL);
  73 
  74                 /* put our mask back case it changed during context switch */
  75                 SetEventMask(everyEvent - autoKeyMask);
  76         } else {
  77 #if TARGET_API_MAC_CARBON
  78                 { Cursor cursor;
  79                         SetCursor(GetQDGlobalsArrow(&cursor));
  80                 }
  81 #else
  82                 SetCursor(&theQD->arrow);
  83 #endif
  84                 if ( ! Mac_cursor_showing ) {
  85                         ShowCursor();
  86                         Mac_cursor_showing = 1;
  87                 }
  88         }
  89         return(SDL_PrivateAppActive(activate, SDL_APPINPUTFOCUS));
  90 }
  91 
  92 static void myGlobalToLocal(_THIS, Point *pt)
     /* [<][>][^][v][top][bottom][index][help] */
  93 {
  94         if ( SDL_VideoSurface && !(SDL_VideoSurface->flags&SDL_FULLSCREEN) ) {
  95                 GrafPtr saveport;
  96                 GetPort(&saveport);
  97 #if TARGET_API_MAC_CARBON
  98                 SetPort(GetWindowPort(SDL_Window));
  99 #else
 100                 SetPort(SDL_Window);
 101 #endif
 102                 GlobalToLocal(pt);
 103                 SetPort(saveport);
 104         }
 105 }
 106 
 107 /* The main MacOS event handler */
 108 static int Mac_HandleEvents(_THIS, int wait4it)
     /* [<][>][^][v][top][bottom][index][help] */
 109 {
 110         int i;
 111         EventRecord event;
 112 
 113 #if TARGET_API_MAC_CARBON
 114         /* There's no GetOSEvent() in the Carbon API. *sigh* */
 115 #define cooperative_multitasking 1
 116 #else
 117         int cooperative_multitasking;
 118         /* If we're running fullscreen, we can hog the MacOS events,
 119            otherwise we had better play nicely with the other apps.
 120         */
 121         if ( this->screen && (this->screen->flags & SDL_FULLSCREEN) ) {
 122                 cooperative_multitasking = 0;
 123         } else {
 124                 cooperative_multitasking = 1;
 125         }
 126 #endif
 127 
 128         /* If we call WaitNextEvent(), MacOS will check other processes
 129          * and allow them to run, and perform other high-level processing.
 130          */
 131         if ( cooperative_multitasking || wait4it ) {
 132                 UInt32 wait_time;
 133 
 134                 /* Are we polling or not? */
 135                 if ( wait4it ) {
 136                         wait_time = 2147483647;
 137                 } else {
 138                         wait_time = 0;
 139                 }
 140                 WaitNextEvent(everyEvent, &event, wait_time, nil);
 141         } else {
 142 #if ! TARGET_API_MAC_CARBON
 143                 GetOSEvent(everyEvent, &event);
 144 #endif
 145         }
 146 
 147 #if TARGET_API_MAC_CARBON
 148         /* for some reason, event.where isn't set ? */
 149         GetGlobalMouse ( &event.where );
 150 #endif
 151     
 152         /* Check for mouse motion */
 153         if ( (event.where.h != last_where.h) ||
 154              (event.where.v != last_where.v) ) {
 155                 Point pt;
 156                 pt = last_where = event.where;
 157                 myGlobalToLocal(this, &pt);
 158                 SDL_PrivateMouseMotion(0, 0, pt.h, pt.v);
 159         }
 160 
 161         /* Check the current state of the keyboard */
 162         if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
 163                 KeyMap keys;
 164 
 165                 /* Check for special non-event keys */
 166                 if ( event.modifiers != last_mods ) {
 167                         static struct {
 168                                 EventModifiers mask;
 169                                 SDLKey key;
 170                         } mods[] = {
 171                                 { alphaLock,            SDLK_CAPSLOCK },
 172 #if 0 /* These are handled below in the GetKeys() code */
 173                                 { cmdKey,               SDLK_LMETA },
 174                                 { shiftKey,             SDLK_LSHIFT },
 175                                 { rightShiftKey,        SDLK_RSHIFT },
 176                                 { optionKey,            SDLK_LALT },
 177                                 { rightOptionKey,       SDLK_RALT },
 178                                 { controlKey,           SDLK_LCTRL },
 179                                 { rightControlKey,      SDLK_RCTRL },
 180 #endif /* 0 */
 181                                 { 0,                    0 }
 182                         };
 183                         SDL_keysym keysym;
 184                         Uint8 mode;
 185                         EventModifiers mod, mask;
 186                 
 187 
 188                         /* Set up the keyboard event */
 189                         keysym.scancode = 0;
 190                         keysym.sym = SDLK_UNKNOWN;
 191                         keysym.mod = KMOD_NONE;
 192                         keysym.unicode = 0;
 193 
 194                         /* See what has changed, and generate events */
 195                         mod = event.modifiers;
 196                         for ( i=0; mods[i].mask; ++i ) {
 197                                 mask = mods[i].mask;
 198                                 if ( (mod&mask) != (last_mods&mask) ) {
 199                                         keysym.sym = mods[i].key;
 200                                         if ( (mod&mask) ||
 201                                              (mods[i].key == SDLK_CAPSLOCK) ) {
 202                                                 mode = SDL_PRESSED;
 203                                         } else {
 204                                                 mode = SDL_RELEASED;
 205                                         }
 206                                         SDL_PrivateKeyboard(mode, &keysym);
 207                                 }
 208                         }
 209 
 210                         /* Save state for next time */
 211                         last_mods = mod;
 212                 }
 213 
 214                 /* Check for normal event keys, but we have to scan the
 215                    actual keyboard state because on MacOS X a keydown event
 216                    is immediately followed by a keyup event.
 217                 */
 218                 GetKeys(keys);
 219                 if ( (keys[0] != last_keys[0]) || (keys[1] != last_keys[1]) ||
 220                      (keys[2] != last_keys[2]) || (keys[3] != last_keys[3]) ) {
 221                         SDL_keysym keysym;
 222                         int old_bit, new_bit;
 223 
 224 #ifdef DEBUG_KEYBOARD
 225                         fprintf(sterr, "New keys: 0x%x 0x%x 0x%x 0x%x\n",
 226                                 new_keys[0], new_keys[1],
 227                                 new_keys[2], new_keys[3]);
 228 #endif
 229                         for ( i=0; i<128; ++i ) {
 230                                 old_bit = (((Uint8 *)last_keys)[i/8]>>(i%8)) & 0x01;
 231                                 new_bit = (((Uint8 *)keys)[i/8]>>(i%8)) & 0x01;
 232                                 if ( old_bit != new_bit ) {
 233                                         /* Post the keyboard event */
 234 #ifdef DEBUG_KEYBOARD
 235                                         fprintf(stderr,"Scancode: 0x%2.2X\n",i);
 236 #endif
 237                                         SDL_PrivateKeyboard(new_bit,
 238                                             TranslateKey(i, event.modifiers,
 239                                                          &keysym, new_bit));
 240                                 }
 241                         }
 242 
 243                         /* Save state for next time */
 244                         last_keys[0] = keys[0];
 245                         last_keys[1] = keys[1];
 246                         last_keys[2] = keys[2];
 247                         last_keys[3] = keys[3];
 248                 }
 249         }
 250 
 251         /* Handle normal events */
 252         switch (event.what) {
 253           case mouseDown: {
 254                 WindowRef win;
 255                 short area;
 256                                 
 257                 area = FindWindow(event.where, &win);
 258                 /* Support switching between the SIOUX console
 259                    and SDL_Window by clicking in the window.
 260                  */
 261                 if ( win && (win != FrontWindow()) ) {
 262                         SelectWindow(win);
 263                 } 
 264                 switch (area) {
 265                   case inMenuBar: /* Only the apple menu exists */
 266                         Mac_DoAppleMenu(this, MenuSelect(event.where));
 267                         HiliteMenu(0);
 268                         break;
 269                   case inDrag:
 270 #if TARGET_API_MAC_CARBON
 271                         DragWindow(win, event.where, NULL);
 272 #else
 273                         DragWindow(win, event.where, &theQD->screenBits.bounds);
 274 #endif
 275                         break;
 276                   case inGoAway:
 277                         if ( TrackGoAway(win, event.where) ) {
 278                                 SDL_PrivateQuit();
 279                         }
 280                         break;
 281                   case inContent:
 282                         myGlobalToLocal(this, &event.where);
 283                         /* Treat command-click as right mouse button */
 284                         if ( event.modifiers & optionKey ) {
 285                             SDL_PrivateMouseButton(SDL_PRESSED,
 286                                         2,event.where.h,event.where.v);
 287                         }
 288                         else if ( event.modifiers & cmdKey ) {
 289                             SDL_PrivateMouseButton(SDL_PRESSED,
 290                                         3,event.where.h,event.where.v);
 291                         } else {
 292                             SDL_PrivateMouseButton(SDL_PRESSED,
 293                                         1,event.where.h,event.where.v);
 294                         }
 295                         break;
 296                   case inGrow: {
 297                         int newSize;
 298 
 299                         /* Don't allow resize if video mode isn't resizable */
 300                         if ( ! SDL_PublicSurface ||
 301                              ! (SDL_PublicSurface->flags & SDL_RESIZABLE) ) {
 302                                 break;
 303                         }
 304 #if TARGET_API_MAC_CARBON
 305                         newSize = GrowWindow(win, event.where, NULL);
 306 #else
 307                         newSize = GrowWindow(win, event.where, &theQD->screenBits.bounds);
 308 #endif
 309                         if ( newSize ) {
 310 #if !TARGET_API_MAC_CARBON
 311                                 EraseRect ( &theQD->screenBits.bounds );
 312 #endif
 313                                 SizeWindow ( win, LoWord (newSize), HiWord (newSize), 1 );
 314                                 SDL_PrivateResize ( LoWord (newSize), HiWord (newSize) );
 315                         }
 316                         } break;
 317                   case inZoomIn:
 318                   case inZoomOut:
 319                         if ( TrackBox (win, event.where, area )) {
 320                                 Rect rect;
 321 #if !TARGET_API_MAC_CARBON
 322                                 EraseRect ( &theQD->screenBits.bounds );
 323 #endif
 324                                 ZoomWindow ( win, area, 0);
 325                                 if ( area == inZoomIn ) {
 326                                         GetWindowUserState(SDL_Window, &rect);
 327                                 } else {
 328                                         GetWindowStandardState(SDL_Window, &rect);
 329                                 }
 330                                 SDL_PrivateResize (rect.right-rect.left,
 331                                                    rect.bottom-rect.top);
 332                         }
 333                         break;
 334 #if TARGET_API_MAC_CARBON
 335                   case inCollapseBox:
 336                         if ( TrackBox (win, event.where, area )) {
 337                                 if ( IsWindowCollapsable(win) ) {
 338                                         CollapseWindow (win, !IsWindowCollapsed(win));
 339                                         // There should be something done like in inGrow case, but...
 340                                 }
 341                         }
 342                         break;
 343 #endif /* TARGET_API_MAC_CARBON */
 344                   case inSysWindow:
 345 #if TARGET_API_MAC_CARBON
 346                         /* Never happens in Carbon? */
 347 #else
 348                         SystemClick(&event, win);
 349 #endif
 350                         break;
 351                   default:
 352                         break;
 353                 }
 354           }
 355           break;
 356           case mouseUp: {
 357                 myGlobalToLocal(this, &event.where);
 358                 /* Treat command-click as right mouse button */
 359                 if ( event.modifiers & cmdKey ) {
 360                     SDL_PrivateMouseButton(SDL_RELEASED,
 361                                 3, event.where.h, event.where.v);
 362                 }
 363                 else if ( event.modifiers & optionKey ) {
 364                     SDL_PrivateMouseButton(SDL_RELEASED,
 365                                 2,event.where.h,event.where.v);
 366                 } else {
 367                     SDL_PrivateMouseButton(SDL_RELEASED,
 368                                 1, event.where.h, event.where.v);
 369                 }
 370           }
 371           break;
 372 #if 0 /* Handled above the switch statement */
 373           case keyDown: {
 374                 SDL_keysym keysym;
 375 
 376                 SDL_PrivateKeyboard(SDL_PRESSED,
 377                         TranslateKey((event.message&keyCodeMask)>>8
 378                                      event.modifiers, &keysym, 1));
 379           }
 380           break;
 381           case keyUp: {
 382                 SDL_keysym keysym;
 383 
 384                 SDL_PrivateKeyboard(SDL_RELEASED,
 385                         TranslateKey((event.message&keyCodeMask)>>8
 386                                      event.modifiers, &keysym, 0));
 387           }
 388           break;
 389 #endif
 390           case updateEvt: {
 391                 BeginUpdate(SDL_Window);
 392                 if ( (SDL_VideoSurface->flags & SDL_HWSURFACE) ==
 393                                                 SDL_SWSURFACE ) {
 394                         SDL_UpdateRect(SDL_VideoSurface, 0, 0, 0, 0);
 395                 }
 396                 EndUpdate(SDL_Window);
 397           }
 398           /* If this was an update event for the SIOUX console, we return 0
 399              in order to stop an endless series of updates being triggered.
 400           */
 401           if ( (WindowRef) event.message != SDL_Window ) {
 402                 return 0;
 403           }
 404           break;
 405           case activateEvt: {
 406                 Mac_HandleActivate(!!(event.modifiers & activeFlag));
 407           }
 408           break;
 409           case diskEvt: {
 410 #if TARGET_API_MAC_CARBON
 411                 /* What are we supposed to do? */;
 412 #else
 413                 if ( ((event.message>>16)&0xFFFF) != noErr ) {
 414                         Point spot;
 415                         SetPt(&spot, 0x0070, 0x0050);
 416                         DIBadMount(spot, event.message);
 417                 }
 418 #endif
 419           }
 420           break;
 421           case osEvt: {
 422                 switch ((event.message>>24) & 0xFF) {
 423 #if 0 /* Handled above the switch statement */
 424                   case mouseMovedMessage: {
 425                         myGlobalToLocal(this, &event.where);
 426                         SDL_PrivateMouseMotion(0, 0,
 427                                         event.where.h, event.where.v);
 428                   }
 429                   break;
 430 #endif /* 0 */
 431                   case suspendResumeMessage: {
 432                         Mac_HandleActivate(!!(event.message & resumeFlag));
 433                   }
 434                   break;
 435                 }
 436           }
 437           break;
 438           default: {
 439                 ;
 440           }
 441           break;
 442         }
 443         return (event.what != nullEvent);
 444 }
 445 
 446 
 447 void Mac_PumpEvents(_THIS)
     /* [<][>][^][v][top][bottom][index][help] */
 448 {
 449         /* Process pending MacOS events */
 450         while ( Mac_HandleEvents(this, 0) ) {
 451                 /* Loop and check again */;
 452         }
 453 }
 454 
 455 void Mac_InitOSKeymap(_THIS)
     /* [<][>][^][v][top][bottom][index][help] */
 456 {
 457         int i;
 458 
 459         /* Map the MAC keysyms */
 460         for ( i=0; i<SDL_TABLESIZE(MAC_keymap); ++i )
 461                 MAC_keymap[i] = SDLK_UNKNOWN;
 462 
 463         /* Wierd, these keys are on my iBook under MacOS X */
 464         MAC_keymap[MK_IBOOK_ENTER] = SDLK_KP_ENTER;
 465         MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT;
 466         MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN;
 467         MAC_keymap[MK_IBOOK_UP] = SDLK_UP;
 468         MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT;
 469 
 470         /* Defined MAC_* constants */
 471         MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE;
 472         MAC_keymap[MK_F1] = SDLK_F1;
 473         MAC_keymap[MK_F2] = SDLK_F2;
 474         MAC_keymap[MK_F3] = SDLK_F3;
 475         MAC_keymap[MK_F4] = SDLK_F4;
 476         MAC_keymap[MK_F5] = SDLK_F5;
 477         MAC_keymap[MK_F6] = SDLK_F6;
 478         MAC_keymap[MK_F7] = SDLK_F7;
 479         MAC_keymap[MK_F8] = SDLK_F8;
 480         MAC_keymap[MK_F9] = SDLK_F9;
 481         MAC_keymap[MK_F10] = SDLK_F10;
 482         MAC_keymap[MK_F11] = SDLK_F11;
 483         MAC_keymap[MK_F12] = SDLK_F12;
 484         MAC_keymap[MK_PRINT] = SDLK_PRINT;
 485         MAC_keymap[MK_SCROLLOCK] = SDLK_SCROLLOCK;
 486         MAC_keymap[MK_PAUSE] = SDLK_PAUSE;
 487         MAC_keymap[MK_POWER] = SDLK_POWER;
 488         MAC_keymap[MK_BACKQUOTE] = SDLK_BACKQUOTE;
 489         MAC_keymap[MK_1] = SDLK_1;
 490         MAC_keymap[MK_2] = SDLK_2;
 491         MAC_keymap[MK_3] = SDLK_3;
 492         MAC_keymap[MK_4] = SDLK_4;
 493         MAC_keymap[MK_5] = SDLK_5;
 494         MAC_keymap[MK_6] = SDLK_6;
 495         MAC_keymap[MK_7] = SDLK_7;
 496         MAC_keymap[MK_8] = SDLK_8;
 497         MAC_keymap[MK_9] = SDLK_9;
 498         MAC_keymap[MK_0] = SDLK_0;
 499         MAC_keymap[MK_MINUS] = SDLK_MINUS;
 500         MAC_keymap[MK_EQUALS] = SDLK_EQUALS;
 501         MAC_keymap[MK_BACKSPACE] = SDLK_BACKSPACE;
 502         MAC_keymap[MK_INSERT] = SDLK_INSERT;
 503         MAC_keymap[MK_HOME] = SDLK_HOME;
 504         MAC_keymap[MK_PAGEUP] = SDLK_PAGEUP;
 505         MAC_keymap[MK_NUMLOCK] = SDLK_NUMLOCK;
 506         MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS;
 507         MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE;
 508         MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
 509         MAC_keymap[MK_TAB] = SDLK_TAB;
 510         MAC_keymap[MK_q] = SDLK_q;
 511         MAC_keymap[MK_w] = SDLK_w;
 512         MAC_keymap[MK_e] = SDLK_e;
 513         MAC_keymap[MK_r] = SDLK_r;
 514         MAC_keymap[MK_t] = SDLK_t;
 515         MAC_keymap[MK_y] = SDLK_y;
 516         MAC_keymap[MK_u] = SDLK_u;
 517         MAC_keymap[MK_i] = SDLK_i;
 518         MAC_keymap[MK_o] = SDLK_o;
 519         MAC_keymap[MK_p] = SDLK_p;
 520         MAC_keymap[MK_LEFTBRACKET] = SDLK_LEFTBRACKET;
 521         MAC_keymap[MK_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
 522         MAC_keymap[MK_BACKSLASH] = SDLK_BACKSLASH;
 523         MAC_keymap[MK_DELETE] = SDLK_DELETE;
 524         MAC_keymap[MK_END] = SDLK_END;
 525         MAC_keymap[MK_PAGEDOWN] = SDLK_PAGEDOWN;
 526         MAC_keymap[MK_KP7] = SDLK_KP7;
 527         MAC_keymap[MK_KP8] = SDLK_KP8;
 528         MAC_keymap[MK_KP9] = SDLK_KP9;
 529         MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS;
 530         MAC_keymap[MK_CAPSLOCK] = SDLK_CAPSLOCK;
 531         MAC_keymap[MK_a] = SDLK_a;
 532         MAC_keymap[MK_s] = SDLK_s;
 533         MAC_keymap[MK_d] = SDLK_d;
 534         MAC_keymap[MK_f] = SDLK_f;
 535         MAC_keymap[MK_g] = SDLK_g;
 536         MAC_keymap[MK_h] = SDLK_h;
 537         MAC_keymap[MK_j] = SDLK_j;
 538         MAC_keymap[MK_k] = SDLK_k;
 539         MAC_keymap[MK_l] = SDLK_l;
 540         MAC_keymap[MK_SEMICOLON] = SDLK_SEMICOLON;
 541         MAC_keymap[MK_QUOTE] = SDLK_QUOTE;
 542         MAC_keymap[MK_RETURN] = SDLK_RETURN;
 543         MAC_keymap[MK_KP4] = SDLK_KP4;
 544         MAC_keymap[MK_KP5] = SDLK_KP5;
 545         MAC_keymap[MK_KP6] = SDLK_KP6;
 546         MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS;
 547         MAC_keymap[MK_LSHIFT] = SDLK_LSHIFT;
 548         MAC_keymap[MK_z] = SDLK_z;
 549         MAC_keymap[MK_x] = SDLK_x;
 550         MAC_keymap[MK_c] = SDLK_c;
 551         MAC_keymap[MK_v] = SDLK_v;
 552         MAC_keymap[MK_b] = SDLK_b;
 553         MAC_keymap[MK_n] = SDLK_n;
 554         MAC_keymap[MK_m] = SDLK_m;
 555         MAC_keymap[MK_COMMA] = SDLK_COMMA;
 556         MAC_keymap[MK_PERIOD] = SDLK_PERIOD;
 557         MAC_keymap[MK_SLASH] = SDLK_SLASH;
 558 #if 0   /* These are the same as the left versions - use left by default */
 559         MAC_keymap[MK_RSHIFT] = SDLK_RSHIFT;
 560 #endif
 561         MAC_keymap[MK_UP] = SDLK_UP;
 562         MAC_keymap[MK_KP1] = SDLK_KP1;
 563         MAC_keymap[MK_KP2] = SDLK_KP2;
 564         MAC_keymap[MK_KP3] = SDLK_KP3;
 565         MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER;
 566         MAC_keymap[MK_LCTRL] = SDLK_LCTRL;
 567         MAC_keymap[MK_LALT] = SDLK_LALT;
 568         MAC_keymap[MK_LMETA] = SDLK_LMETA;
 569         MAC_keymap[MK_SPACE] = SDLK_SPACE;
 570 #if 0   /* These are the same as the left versions - use left by default */
 571         MAC_keymap[MK_RMETA] = SDLK_RMETA;
 572         MAC_keymap[MK_RALT] = SDLK_RALT;
 573         MAC_keymap[MK_RCTRL] = SDLK_RCTRL;
 574 #endif
 575         MAC_keymap[MK_LEFT] = SDLK_LEFT;
 576         MAC_keymap[MK_DOWN] = SDLK_DOWN;
 577         MAC_keymap[MK_RIGHT] = SDLK_RIGHT;
 578         MAC_keymap[MK_KP0] = SDLK_KP0;
 579         MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD;
 580 }
 581 
 582 static SDL_keysym *TranslateKey(int scancode, int modifiers,
     /* [<][>][^][v][top][bottom][index][help] */
 583                                 SDL_keysym *keysym, int pressed)
 584 {
 585         /* Set the keysym information */
 586         keysym->scancode = scancode;
 587         keysym->sym = MAC_keymap[keysym->scancode];
 588         keysym->mod = KMOD_NONE;
 589         keysym->unicode = 0;
 590         if ( pressed && SDL_TranslateUNICODE ) {
 591                 static unsigned long state = 0;
 592                 static Ptr keymap = nil;
 593                 Ptr new_keymap;
 594 
 595                 /* Get the current keyboard map resource */
 596                 new_keymap = (Ptr)GetScriptManagerVariable(smKCHRCache);
 597                 if ( new_keymap != keymap ) {
 598                         keymap = new_keymap;
 599                         state = 0;
 600                 }
 601                 keysym->unicode = KeyTranslate(keymap,
 602                         keysym->scancode|modifiers, &state) & 0xFFFF;
 603         }
 604         return(keysym);
 605 }
 606 
 607 void Mac_InitEvents(_THIS)
     /* [<][>][^][v][top][bottom][index][help] */
 608 {
 609         /* Create apple menu bar */
 610         apple_menu = GetMenu(mApple);
 611         if ( apple_menu != nil ) {
 612                 AppendResMenu(apple_menu, 'DRVR');
 613                 InsertMenu(apple_menu, 0);
 614         }
 615         DrawMenuBar();
 616 
 617         /* Get rid of spurious events at startup */
 618         FlushEvents(everyEvent, 0);
 619         
 620         /* Allow every event but keyrepeat */
 621         SetEventMask(everyEvent - autoKeyMask);
 622 }
 623 
 624 void Mac_QuitEvents(_THIS)
     /* [<][>][^][v][top][bottom][index][help] */
 625 {
 626         ClearMenuBar();
 627         if ( apple_menu != nil ) {
 628                 ReleaseResource((char **)apple_menu);
 629         }
 630 
 631         /* Clean up pending events */
 632         FlushEvents(everyEvent, 0);
 633 }
 634 
 635 static void Mac_DoAppleMenu(_THIS, long choice)
     /* [<][>][^][v][top][bottom][index][help] */
 636 {
 637 #if !TARGET_API_MAC_CARBON  /* No Apple menu in OS X */
 638         short menu, item;
 639 
 640         item = (choice&0xFFFF);
 641         choice >>= 16;
 642         menu = (choice&0xFFFF);
 643         
 644         switch (menu) {
 645                 case mApple: {
 646                         switch (item) {
 647                                 case iAbout: {
 648                                         /* Run the about box */;
 649                                 }
 650                                 break;
 651                                 default: {
 652                                         Str255 name;
 653                                         
 654                                         GetMenuItemText(apple_menu, item, name);
 655                                         OpenDeskAcc(name);
 656                                 }
 657                                 break;
 658                         }
 659                 }
 660                 break;
 661                 default: {
 662                         /* Ignore other menus */;
 663                 }
 664         }
 665 #endif /* !TARGET_API_MAC_CARBON */
 666 }
 667 
 668 #if !TARGET_API_MAC_CARBON
 669 /* Since we don't initialize QuickDraw, we need to get a pointer to qd */
 670 QDGlobals *theQD = NULL;
 671 
 672 /* Exported to the macmain code */
 673 void SDL_InitQuickDraw(struct QDGlobals *the_qd)
     /* [<][>][^][v][top][bottom][index][help] */
 674 {
 675         theQD = the_qd;
 676 }
 677 #endif

/* [<][>][^][v][top][bottom][index][help] */