Mercurial > sdl-ios-xcode
annotate src/video/maccommon/SDL_macevents.c @ 10:ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Sat, 28 Apr 2001 18:56:58 +0000 |
parents | 74212992fb08 |
children | 2d162219f433 |
rev | line source |
---|---|
0 | 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$"; | |
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) | |
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) | |
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) | |
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) | |
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) | |
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 /* Defined MAC_* constants */ | |
464 MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE; | |
465 MAC_keymap[MK_F1] = SDLK_F1; | |
466 MAC_keymap[MK_F2] = SDLK_F2; | |
467 MAC_keymap[MK_F3] = SDLK_F3; | |
468 MAC_keymap[MK_F4] = SDLK_F4; | |
469 MAC_keymap[MK_F5] = SDLK_F5; | |
470 MAC_keymap[MK_F6] = SDLK_F6; | |
471 MAC_keymap[MK_F7] = SDLK_F7; | |
472 MAC_keymap[MK_F8] = SDLK_F8; | |
473 MAC_keymap[MK_F9] = SDLK_F9; | |
474 MAC_keymap[MK_F10] = SDLK_F10; | |
475 MAC_keymap[MK_F11] = SDLK_F11; | |
476 MAC_keymap[MK_F12] = SDLK_F12; | |
477 MAC_keymap[MK_PRINT] = SDLK_PRINT; | |
478 MAC_keymap[MK_SCROLLOCK] = SDLK_SCROLLOCK; | |
479 MAC_keymap[MK_PAUSE] = SDLK_PAUSE; | |
480 MAC_keymap[MK_POWER] = SDLK_POWER; | |
481 MAC_keymap[MK_BACKQUOTE] = SDLK_BACKQUOTE; | |
482 MAC_keymap[MK_1] = SDLK_1; | |
483 MAC_keymap[MK_2] = SDLK_2; | |
484 MAC_keymap[MK_3] = SDLK_3; | |
485 MAC_keymap[MK_4] = SDLK_4; | |
486 MAC_keymap[MK_5] = SDLK_5; | |
487 MAC_keymap[MK_6] = SDLK_6; | |
488 MAC_keymap[MK_7] = SDLK_7; | |
489 MAC_keymap[MK_8] = SDLK_8; | |
490 MAC_keymap[MK_9] = SDLK_9; | |
491 MAC_keymap[MK_0] = SDLK_0; | |
492 MAC_keymap[MK_MINUS] = SDLK_MINUS; | |
493 MAC_keymap[MK_EQUALS] = SDLK_EQUALS; | |
494 MAC_keymap[MK_BACKSPACE] = SDLK_BACKSPACE; | |
495 MAC_keymap[MK_INSERT] = SDLK_INSERT; | |
496 MAC_keymap[MK_HOME] = SDLK_HOME; | |
497 MAC_keymap[MK_PAGEUP] = SDLK_PAGEUP; | |
498 MAC_keymap[MK_NUMLOCK] = SDLK_NUMLOCK; | |
499 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; | |
500 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; | |
501 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; | |
502 MAC_keymap[MK_TAB] = SDLK_TAB; | |
503 MAC_keymap[MK_q] = SDLK_q; | |
504 MAC_keymap[MK_w] = SDLK_w; | |
505 MAC_keymap[MK_e] = SDLK_e; | |
506 MAC_keymap[MK_r] = SDLK_r; | |
507 MAC_keymap[MK_t] = SDLK_t; | |
508 MAC_keymap[MK_y] = SDLK_y; | |
509 MAC_keymap[MK_u] = SDLK_u; | |
510 MAC_keymap[MK_i] = SDLK_i; | |
511 MAC_keymap[MK_o] = SDLK_o; | |
512 MAC_keymap[MK_p] = SDLK_p; | |
513 MAC_keymap[MK_LEFTBRACKET] = SDLK_LEFTBRACKET; | |
514 MAC_keymap[MK_RIGHTBRACKET] = SDLK_RIGHTBRACKET; | |
515 MAC_keymap[MK_BACKSLASH] = SDLK_BACKSLASH; | |
516 MAC_keymap[MK_DELETE] = SDLK_DELETE; | |
517 MAC_keymap[MK_END] = SDLK_END; | |
518 MAC_keymap[MK_PAGEDOWN] = SDLK_PAGEDOWN; | |
519 MAC_keymap[MK_KP7] = SDLK_KP7; | |
520 MAC_keymap[MK_KP8] = SDLK_KP8; | |
521 MAC_keymap[MK_KP9] = SDLK_KP9; | |
522 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; | |
523 MAC_keymap[MK_CAPSLOCK] = SDLK_CAPSLOCK; | |
524 MAC_keymap[MK_a] = SDLK_a; | |
525 MAC_keymap[MK_s] = SDLK_s; | |
526 MAC_keymap[MK_d] = SDLK_d; | |
527 MAC_keymap[MK_f] = SDLK_f; | |
528 MAC_keymap[MK_g] = SDLK_g; | |
529 MAC_keymap[MK_h] = SDLK_h; | |
530 MAC_keymap[MK_j] = SDLK_j; | |
531 MAC_keymap[MK_k] = SDLK_k; | |
532 MAC_keymap[MK_l] = SDLK_l; | |
533 MAC_keymap[MK_SEMICOLON] = SDLK_SEMICOLON; | |
534 MAC_keymap[MK_QUOTE] = SDLK_QUOTE; | |
535 MAC_keymap[MK_RETURN] = SDLK_RETURN; | |
536 MAC_keymap[MK_KP4] = SDLK_KP4; | |
537 MAC_keymap[MK_KP5] = SDLK_KP5; | |
538 MAC_keymap[MK_KP6] = SDLK_KP6; | |
539 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; | |
540 MAC_keymap[MK_LSHIFT] = SDLK_LSHIFT; | |
541 MAC_keymap[MK_z] = SDLK_z; | |
542 MAC_keymap[MK_x] = SDLK_x; | |
543 MAC_keymap[MK_c] = SDLK_c; | |
544 MAC_keymap[MK_v] = SDLK_v; | |
545 MAC_keymap[MK_b] = SDLK_b; | |
546 MAC_keymap[MK_n] = SDLK_n; | |
547 MAC_keymap[MK_m] = SDLK_m; | |
548 MAC_keymap[MK_COMMA] = SDLK_COMMA; | |
549 MAC_keymap[MK_PERIOD] = SDLK_PERIOD; | |
550 MAC_keymap[MK_SLASH] = SDLK_SLASH; | |
551 #if 0 /* These are the same as the left versions - use left by default */ | |
552 MAC_keymap[MK_RSHIFT] = SDLK_RSHIFT; | |
553 #endif | |
554 MAC_keymap[MK_UP] = SDLK_UP; | |
555 MAC_keymap[MK_KP1] = SDLK_KP1; | |
556 MAC_keymap[MK_KP2] = SDLK_KP2; | |
557 MAC_keymap[MK_KP3] = SDLK_KP3; | |
558 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; | |
559 MAC_keymap[MK_LCTRL] = SDLK_LCTRL; | |
560 MAC_keymap[MK_LALT] = SDLK_LALT; | |
561 MAC_keymap[MK_LMETA] = SDLK_LMETA; | |
562 MAC_keymap[MK_SPACE] = SDLK_SPACE; | |
563 #if 0 /* These are the same as the left versions - use left by default */ | |
564 MAC_keymap[MK_RMETA] = SDLK_RMETA; | |
565 MAC_keymap[MK_RALT] = SDLK_RALT; | |
566 MAC_keymap[MK_RCTRL] = SDLK_RCTRL; | |
567 #endif | |
568 MAC_keymap[MK_LEFT] = SDLK_LEFT; | |
569 MAC_keymap[MK_DOWN] = SDLK_DOWN; | |
570 MAC_keymap[MK_RIGHT] = SDLK_RIGHT; | |
571 MAC_keymap[MK_KP0] = SDLK_KP0; | |
572 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; | |
10
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
573 |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
574 #if defined(__APPLE__) && defined(__MACH__) |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
575 /* Wierd, these keys are on my iBook under MacOS X |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
576 Note that the left arrow keysym is the same as left ctrl!? |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
577 */ |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
578 MAC_keymap[MK_IBOOK_ENTER] = SDLK_KP_ENTER; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
579 MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
580 MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
581 MAC_keymap[MK_IBOOK_UP] = SDLK_UP; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
582 MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT; |
ee3bb7cd06b5
Fixed left arrow on iBook keyboard under MacOS X
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
583 #endif /* MacOS X */ |
0 | 584 } |
585 | |
586 static SDL_keysym *TranslateKey(int scancode, int modifiers, | |
587 SDL_keysym *keysym, int pressed) | |
588 { | |
589 /* Set the keysym information */ | |
590 keysym->scancode = scancode; | |
591 keysym->sym = MAC_keymap[keysym->scancode]; | |
592 keysym->mod = KMOD_NONE; | |
593 keysym->unicode = 0; | |
594 if ( pressed && SDL_TranslateUNICODE ) { | |
595 static unsigned long state = 0; | |
596 static Ptr keymap = nil; | |
597 Ptr new_keymap; | |
598 | |
599 /* Get the current keyboard map resource */ | |
600 new_keymap = (Ptr)GetScriptManagerVariable(smKCHRCache); | |
601 if ( new_keymap != keymap ) { | |
602 keymap = new_keymap; | |
603 state = 0; | |
604 } | |
605 keysym->unicode = KeyTranslate(keymap, | |
606 keysym->scancode|modifiers, &state) & 0xFFFF; | |
607 } | |
608 return(keysym); | |
609 } | |
610 | |
611 void Mac_InitEvents(_THIS) | |
612 { | |
613 /* Create apple menu bar */ | |
614 apple_menu = GetMenu(mApple); | |
615 if ( apple_menu != nil ) { | |
616 AppendResMenu(apple_menu, 'DRVR'); | |
617 InsertMenu(apple_menu, 0); | |
618 } | |
619 DrawMenuBar(); | |
620 | |
621 /* Get rid of spurious events at startup */ | |
622 FlushEvents(everyEvent, 0); | |
623 | |
624 /* Allow every event but keyrepeat */ | |
625 SetEventMask(everyEvent - autoKeyMask); | |
626 } | |
627 | |
628 void Mac_QuitEvents(_THIS) | |
629 { | |
630 ClearMenuBar(); | |
631 if ( apple_menu != nil ) { | |
632 ReleaseResource((char **)apple_menu); | |
633 } | |
634 | |
635 /* Clean up pending events */ | |
636 FlushEvents(everyEvent, 0); | |
637 } | |
638 | |
639 static void Mac_DoAppleMenu(_THIS, long choice) | |
640 { | |
641 #if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */ | |
642 short menu, item; | |
643 | |
644 item = (choice&0xFFFF); | |
645 choice >>= 16; | |
646 menu = (choice&0xFFFF); | |
647 | |
648 switch (menu) { | |
649 case mApple: { | |
650 switch (item) { | |
651 case iAbout: { | |
652 /* Run the about box */; | |
653 } | |
654 break; | |
655 default: { | |
656 Str255 name; | |
657 | |
658 GetMenuItemText(apple_menu, item, name); | |
659 OpenDeskAcc(name); | |
660 } | |
661 break; | |
662 } | |
663 } | |
664 break; | |
665 default: { | |
666 /* Ignore other menus */; | |
667 } | |
668 } | |
669 #endif /* !TARGET_API_MAC_CARBON */ | |
670 } | |
671 | |
672 #if !TARGET_API_MAC_CARBON | |
673 /* Since we don't initialize QuickDraw, we need to get a pointer to qd */ | |
674 QDGlobals *theQD = NULL; | |
675 | |
676 /* Exported to the macmain code */ | |
677 void SDL_InitQuickDraw(struct QDGlobals *the_qd) | |
678 { | |
679 theQD = the_qd; | |
680 } | |
681 #endif |