Mercurial > sdl-ios-xcode
comparison src/video/maccommon/SDL_macevents.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
52 /* Macintosh resource constants */ | 52 /* Macintosh resource constants */ |
53 #define mApple 128 /* Apple menu resource */ | 53 #define mApple 128 /* Apple menu resource */ |
54 #define iAbout 1 /* About menu item */ | 54 #define iAbout 1 /* About menu item */ |
55 | 55 |
56 /* Functions to handle the About menu */ | 56 /* Functions to handle the About menu */ |
57 static void Mac_DoAppleMenu (_THIS, long item); | 57 static void Mac_DoAppleMenu(_THIS, long item); |
58 | 58 |
59 /* The translation table from a macintosh key scancode to a SDL keysym */ | 59 /* The translation table from a macintosh key scancode to a SDL keysym */ |
60 static SDLKey MAC_keymap[256]; | 60 static SDLKey MAC_keymap[256]; |
61 static SDL_keysym *TranslateKey (int scancode, int modifiers, | 61 static SDL_keysym *TranslateKey(int scancode, int modifiers, |
62 SDL_keysym * keysym, int pressed); | 62 SDL_keysym * keysym, int pressed); |
63 | 63 |
64 /* Handle activation and deactivation -- returns whether an event was posted */ | 64 /* Handle activation and deactivation -- returns whether an event was posted */ |
65 static int | 65 static int |
66 Mac_HandleActivate (int activate) | 66 Mac_HandleActivate(int activate) |
67 { | 67 { |
68 if (activate) { | 68 if (activate) { |
69 /* Show the current SDL application cursor */ | 69 /* Show the current SDL application cursor */ |
70 SDL_SetCursor (NULL); | 70 SDL_SetCursor(NULL); |
71 | 71 |
72 /* put our mask back case it changed during context switch */ | 72 /* put our mask back case it changed during context switch */ |
73 SetEventMask (everyEvent & ~autoKeyMask); | 73 SetEventMask(everyEvent & ~autoKeyMask); |
74 } else { | 74 } else { |
75 #if TARGET_API_MAC_CARBON | 75 #if TARGET_API_MAC_CARBON |
76 { | 76 { |
77 Cursor cursor; | 77 Cursor cursor; |
78 SetCursor (GetQDGlobalsArrow (&cursor)); | 78 SetCursor(GetQDGlobalsArrow(&cursor)); |
79 } | 79 } |
80 #else | 80 #else |
81 SetCursor (&theQD->arrow); | 81 SetCursor(&theQD->arrow); |
82 #endif | 82 #endif |
83 if (!Mac_cursor_showing) { | 83 if (!Mac_cursor_showing) { |
84 ShowCursor (); | 84 ShowCursor(); |
85 Mac_cursor_showing = 1; | 85 Mac_cursor_showing = 1; |
86 } | 86 } |
87 } | 87 } |
88 return (SDL_PrivateAppActive (activate, SDL_APPINPUTFOCUS)); | 88 return (SDL_PrivateAppActive(activate, SDL_APPINPUTFOCUS)); |
89 } | 89 } |
90 | 90 |
91 static void | 91 static void |
92 myGlobalToLocal (_THIS, Point * pt) | 92 myGlobalToLocal(_THIS, Point * pt) |
93 { | 93 { |
94 if (SDL_VideoSurface && !(SDL_VideoSurface->flags & SDL_FULLSCREEN)) { | 94 if (SDL_VideoSurface && !(SDL_VideoSurface->flags & SDL_FULLSCREEN)) { |
95 GrafPtr saveport; | 95 GrafPtr saveport; |
96 GetPort (&saveport); | 96 GetPort(&saveport); |
97 #if TARGET_API_MAC_CARBON | 97 #if TARGET_API_MAC_CARBON |
98 SetPort (GetWindowPort (SDL_Window)); | 98 SetPort(GetWindowPort(SDL_Window)); |
99 #else | 99 #else |
100 SetPort (SDL_Window); | 100 SetPort(SDL_Window); |
101 #endif | 101 #endif |
102 GlobalToLocal (pt); | 102 GlobalToLocal(pt); |
103 SetPort (saveport); | 103 SetPort(saveport); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 /* The main MacOS event handler */ | 107 /* The main MacOS event handler */ |
108 static int | 108 static int |
109 Mac_HandleEvents (_THIS, int wait4it) | 109 Mac_HandleEvents(_THIS, int wait4it) |
110 { | 110 { |
111 static int mouse_button = 1; | 111 static int mouse_button = 1; |
112 int i; | 112 int i; |
113 EventRecord event; | 113 EventRecord event; |
114 | 114 |
137 if (wait4it) { | 137 if (wait4it) { |
138 wait_time = 2147483647; | 138 wait_time = 2147483647; |
139 } else { | 139 } else { |
140 wait_time = 0; | 140 wait_time = 0; |
141 } | 141 } |
142 WaitNextEvent (everyEvent, &event, wait_time, nil); | 142 WaitNextEvent(everyEvent, &event, wait_time, nil); |
143 } else { | 143 } else { |
144 #if ! TARGET_API_MAC_CARBON | 144 #if ! TARGET_API_MAC_CARBON |
145 GetOSEvent (everyEvent, &event); | 145 GetOSEvent(everyEvent, &event); |
146 #endif | 146 #endif |
147 } | 147 } |
148 | 148 |
149 #if TARGET_API_MAC_CARBON | 149 #if TARGET_API_MAC_CARBON |
150 /* for some reason, event.where isn't set ? */ | 150 /* for some reason, event.where isn't set ? */ |
151 GetGlobalMouse (&event.where); | 151 GetGlobalMouse(&event.where); |
152 #endif | 152 #endif |
153 | 153 |
154 /* Check for mouse motion */ | 154 /* Check for mouse motion */ |
155 if ((event.where.h != last_where.h) || (event.where.v != last_where.v)) { | 155 if ((event.where.h != last_where.h) || (event.where.v != last_where.v)) { |
156 Point pt; | 156 Point pt; |
157 pt = last_where = event.where; | 157 pt = last_where = event.where; |
158 myGlobalToLocal (this, &pt); | 158 myGlobalToLocal(this, &pt); |
159 SDL_PrivateMouseMotion (0, 0, pt.h, pt.v); | 159 SDL_PrivateMouseMotion(0, 0, pt.h, pt.v); |
160 } | 160 } |
161 | 161 |
162 /* Check the current state of the keyboard */ | 162 /* Check the current state of the keyboard */ |
163 if (SDL_GetAppState () & SDL_APPINPUTFOCUS) { | 163 if (SDL_GetAppState() & SDL_APPINPUTFOCUS) { |
164 KeyMap keys; | 164 KeyMap keys; |
165 | 165 |
166 /* Check for special non-event keys */ | 166 /* Check for special non-event keys */ |
167 if (event.modifiers != last_mods) { | 167 if (event.modifiers != last_mods) { |
168 static struct | 168 static struct |
205 if ((mod & mask) || (mods[i].key == SDLK_CAPSLOCK)) { | 205 if ((mod & mask) || (mods[i].key == SDLK_CAPSLOCK)) { |
206 mode = SDL_PRESSED; | 206 mode = SDL_PRESSED; |
207 } else { | 207 } else { |
208 mode = SDL_RELEASED; | 208 mode = SDL_RELEASED; |
209 } | 209 } |
210 SDL_PrivateKeyboard (mode, &keysym); | 210 SDL_PrivateKeyboard(mode, &keysym); |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 /* Save state for next time */ | 214 /* Save state for next time */ |
215 last_mods = mod; | 215 last_mods = mod; |
217 | 217 |
218 /* Check for normal event keys, but we have to scan the | 218 /* Check for normal event keys, but we have to scan the |
219 actual keyboard state because on Mac OS X a keydown event | 219 actual keyboard state because on Mac OS X a keydown event |
220 is immediately followed by a keyup event. | 220 is immediately followed by a keyup event. |
221 */ | 221 */ |
222 GetKeys (keys); | 222 GetKeys(keys); |
223 if ((keys[0] != last_keys[0]) || (keys[1] != last_keys[1]) || | 223 if ((keys[0] != last_keys[0]) || (keys[1] != last_keys[1]) || |
224 (keys[2] != last_keys[2]) || (keys[3] != last_keys[3])) { | 224 (keys[2] != last_keys[2]) || (keys[3] != last_keys[3])) { |
225 SDL_keysym keysym; | 225 SDL_keysym keysym; |
226 int old_bit, new_bit; | 226 int old_bit, new_bit; |
227 | 227 |
228 #ifdef DEBUG_KEYBOARD | 228 #ifdef DEBUG_KEYBOARD |
229 fprintf (sterr, "New keys: 0x%x 0x%x 0x%x 0x%x\n", | 229 fprintf(sterr, "New keys: 0x%x 0x%x 0x%x 0x%x\n", |
230 new_keys[0], new_keys[1], new_keys[2], new_keys[3]); | 230 new_keys[0], new_keys[1], new_keys[2], new_keys[3]); |
231 #endif | 231 #endif |
232 for (i = 0; i < 128; ++i) { | 232 for (i = 0; i < 128; ++i) { |
233 old_bit = (((Uint8 *) last_keys)[i / 8] >> (i % 8)) & 0x01; | 233 old_bit = (((Uint8 *) last_keys)[i / 8] >> (i % 8)) & 0x01; |
234 new_bit = (((Uint8 *) keys)[i / 8] >> (i % 8)) & 0x01; | 234 new_bit = (((Uint8 *) keys)[i / 8] >> (i % 8)) & 0x01; |
235 if (old_bit != new_bit) { | 235 if (old_bit != new_bit) { |
236 /* Post the keyboard event */ | 236 /* Post the keyboard event */ |
237 #ifdef DEBUG_KEYBOARD | 237 #ifdef DEBUG_KEYBOARD |
238 fprintf (stderr, "Scancode: 0x%2.2X\n", i); | 238 fprintf(stderr, "Scancode: 0x%2.2X\n", i); |
239 #endif | 239 #endif |
240 SDL_PrivateKeyboard (new_bit, | 240 SDL_PrivateKeyboard(new_bit, |
241 TranslateKey (i, | 241 TranslateKey(i, |
242 event. | 242 event. |
243 modifiers, | 243 modifiers, |
244 &keysym, new_bit)); | 244 &keysym, new_bit)); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 /* Save state for next time */ | 248 /* Save state for next time */ |
249 last_keys[0] = keys[0]; | 249 last_keys[0] = keys[0]; |
258 case mouseDown: | 258 case mouseDown: |
259 { | 259 { |
260 WindowRef win; | 260 WindowRef win; |
261 short area; | 261 short area; |
262 | 262 |
263 area = FindWindow (event.where, &win); | 263 area = FindWindow(event.where, &win); |
264 /* Support switching between the SIOUX console | 264 /* Support switching between the SIOUX console |
265 and SDL_Window by clicking in the window. | 265 and SDL_Window by clicking in the window. |
266 */ | 266 */ |
267 if (win && (win != FrontWindow ())) { | 267 if (win && (win != FrontWindow())) { |
268 SelectWindow (win); | 268 SelectWindow(win); |
269 } | 269 } |
270 switch (area) { | 270 switch (area) { |
271 case inMenuBar: /* Only the apple menu exists */ | 271 case inMenuBar: /* Only the apple menu exists */ |
272 Mac_DoAppleMenu (this, MenuSelect (event.where)); | 272 Mac_DoAppleMenu(this, MenuSelect(event.where)); |
273 HiliteMenu (0); | 273 HiliteMenu(0); |
274 break; | 274 break; |
275 case inDrag: | 275 case inDrag: |
276 #if TARGET_API_MAC_CARBON | 276 #if TARGET_API_MAC_CARBON |
277 DragWindow (win, event.where, NULL); | 277 DragWindow(win, event.where, NULL); |
278 #else | 278 #else |
279 DragWindow (win, event.where, &theQD->screenBits.bounds); | 279 DragWindow(win, event.where, &theQD->screenBits.bounds); |
280 #endif | 280 #endif |
281 break; | 281 break; |
282 case inGoAway: | 282 case inGoAway: |
283 if (TrackGoAway (win, event.where)) { | 283 if (TrackGoAway(win, event.where)) { |
284 SDL_PrivateQuit (); | 284 SDL_PrivateQuit(); |
285 } | 285 } |
286 break; | 286 break; |
287 case inContent: | 287 case inContent: |
288 myGlobalToLocal (this, &event.where); | 288 myGlobalToLocal(this, &event.where); |
289 /* Treat command-click as right mouse button */ | 289 /* Treat command-click as right mouse button */ |
290 if (event.modifiers & optionKey) { | 290 if (event.modifiers & optionKey) { |
291 mouse_button = 2; | 291 mouse_button = 2; |
292 } else if (event.modifiers & cmdKey) { | 292 } else if (event.modifiers & cmdKey) { |
293 mouse_button = 3; | 293 mouse_button = 3; |
294 } else { | 294 } else { |
295 mouse_button = 1; | 295 mouse_button = 1; |
296 } | 296 } |
297 SDL_PrivateMouseButton (SDL_PRESSED, | 297 SDL_PrivateMouseButton(SDL_PRESSED, |
298 mouse_button, event.where.h, | 298 mouse_button, event.where.h, |
299 event.where.v); | 299 event.where.v); |
300 break; | 300 break; |
301 case inGrow: | 301 case inGrow: |
302 { | 302 { |
303 int newSize; | 303 int newSize; |
304 | 304 |
306 if (!SDL_PublicSurface || | 306 if (!SDL_PublicSurface || |
307 !(SDL_PublicSurface->flags & SDL_RESIZABLE)) { | 307 !(SDL_PublicSurface->flags & SDL_RESIZABLE)) { |
308 break; | 308 break; |
309 } | 309 } |
310 #if TARGET_API_MAC_CARBON | 310 #if TARGET_API_MAC_CARBON |
311 newSize = GrowWindow (win, event.where, NULL); | 311 newSize = GrowWindow(win, event.where, NULL); |
312 #else | 312 #else |
313 newSize = | 313 newSize = |
314 GrowWindow (win, event.where, | 314 GrowWindow(win, event.where, |
315 &theQD->screenBits.bounds); | 315 &theQD->screenBits.bounds); |
316 #endif | 316 #endif |
317 if (newSize) { | 317 if (newSize) { |
318 #if !TARGET_API_MAC_CARBON | 318 #if !TARGET_API_MAC_CARBON |
319 EraseRect (&theQD->screenBits.bounds); | 319 EraseRect(&theQD->screenBits.bounds); |
320 #endif | 320 #endif |
321 SizeWindow (win, LoWord (newSize), | 321 SizeWindow(win, LoWord(newSize), HiWord(newSize), 1); |
322 HiWord (newSize), 1); | 322 SDL_PrivateResize(LoWord(newSize), HiWord(newSize)); |
323 SDL_PrivateResize (LoWord (newSize), | |
324 HiWord (newSize)); | |
325 } | 323 } |
326 } | 324 } |
327 break; | 325 break; |
328 case inZoomIn: | 326 case inZoomIn: |
329 case inZoomOut: | 327 case inZoomOut: |
330 if (TrackBox (win, event.where, area)) { | 328 if (TrackBox(win, event.where, area)) { |
331 Rect rect; | 329 Rect rect; |
332 #if !TARGET_API_MAC_CARBON | 330 #if !TARGET_API_MAC_CARBON |
333 EraseRect (&theQD->screenBits.bounds); | 331 EraseRect(&theQD->screenBits.bounds); |
334 #endif | 332 #endif |
335 ZoomWindow (win, area, 0); | 333 ZoomWindow(win, area, 0); |
336 if (area == inZoomIn) { | 334 if (area == inZoomIn) { |
337 GetWindowUserState (SDL_Window, &rect); | 335 GetWindowUserState(SDL_Window, &rect); |
338 } else { | 336 } else { |
339 GetWindowStandardState (SDL_Window, &rect); | 337 GetWindowStandardState(SDL_Window, &rect); |
340 } | 338 } |
341 SDL_PrivateResize (rect.right - rect.left, | 339 SDL_PrivateResize(rect.right - rect.left, |
342 rect.bottom - rect.top); | 340 rect.bottom - rect.top); |
343 } | 341 } |
344 break; | 342 break; |
345 #if TARGET_API_MAC_CARBON | 343 #if TARGET_API_MAC_CARBON |
346 case inCollapseBox: | 344 case inCollapseBox: |
347 if (TrackBox (win, event.where, area)) { | 345 if (TrackBox(win, event.where, area)) { |
348 if (IsWindowCollapsable (win)) { | 346 if (IsWindowCollapsable(win)) { |
349 CollapseWindow (win, !IsWindowCollapsed (win)); | 347 CollapseWindow(win, !IsWindowCollapsed(win)); |
350 /* There should be something done like in inGrow case, but... */ | 348 /* There should be something done like in inGrow case, but... */ |
351 } | 349 } |
352 } | 350 } |
353 break; | 351 break; |
354 #endif /* TARGET_API_MAC_CARBON */ | 352 #endif /* TARGET_API_MAC_CARBON */ |
355 case inSysWindow: | 353 case inSysWindow: |
356 #if TARGET_API_MAC_CARBON | 354 #if TARGET_API_MAC_CARBON |
357 /* Never happens in Carbon? */ | 355 /* Never happens in Carbon? */ |
358 #else | 356 #else |
359 SystemClick (&event, win); | 357 SystemClick(&event, win); |
360 #endif | 358 #endif |
361 break; | 359 break; |
362 default: | 360 default: |
363 break; | 361 break; |
364 } | 362 } |
365 } | 363 } |
366 break; | 364 break; |
367 case mouseUp: | 365 case mouseUp: |
368 { | 366 { |
369 myGlobalToLocal (this, &event.where); | 367 myGlobalToLocal(this, &event.where); |
370 /* Release the mouse button we simulated in the last press. | 368 /* Release the mouse button we simulated in the last press. |
371 The drawback of this methos is we cannot press more than | 369 The drawback of this methos is we cannot press more than |
372 one button. However, this doesn't matter, since there is | 370 one button. However, this doesn't matter, since there is |
373 only a single logical mouse button, even if you have a | 371 only a single logical mouse button, even if you have a |
374 multi-button mouse, this doesn't matter at all. | 372 multi-button mouse, this doesn't matter at all. |
375 */ | 373 */ |
376 SDL_PrivateMouseButton (SDL_RELEASED, | 374 SDL_PrivateMouseButton(SDL_RELEASED, |
377 mouse_button, event.where.h, | 375 mouse_button, event.where.h, |
378 event.where.v); | 376 event.where.v); |
379 } | 377 } |
380 break; | 378 break; |
381 #if 0 /* Handled above the switch statement */ | 379 #if 0 /* Handled above the switch statement */ |
382 case keyDown: | 380 case keyDown: |
383 { | 381 { |
384 SDL_keysym keysym; | 382 SDL_keysym keysym; |
385 | 383 |
386 SDL_PrivateKeyboard (SDL_PRESSED, | 384 SDL_PrivateKeyboard(SDL_PRESSED, |
387 TranslateKey ((event. | 385 TranslateKey((event. |
388 message & keyCodeMask) >> 8 | 386 message & keyCodeMask) >> 8 |
389 event.modifiers, &keysym, 1)); | 387 event.modifiers, &keysym, 1)); |
390 } | 388 } |
391 break; | 389 break; |
392 case keyUp: | 390 case keyUp: |
393 { | 391 { |
394 SDL_keysym keysym; | 392 SDL_keysym keysym; |
395 | 393 |
396 SDL_PrivateKeyboard (SDL_RELEASED, | 394 SDL_PrivateKeyboard(SDL_RELEASED, |
397 TranslateKey ((event. | 395 TranslateKey((event. |
398 message & keyCodeMask) >> 8 | 396 message & keyCodeMask) >> 8 |
399 event.modifiers, &keysym, 0)); | 397 event.modifiers, &keysym, 0)); |
400 } | 398 } |
401 break; | 399 break; |
402 #endif | 400 #endif |
403 case updateEvt: | 401 case updateEvt: |
404 { | 402 { |
405 BeginUpdate (SDL_Window); | 403 BeginUpdate(SDL_Window); |
406 #if SDL_VIDEO_OPENGL | 404 #if SDL_VIDEO_OPENGL |
407 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) | 405 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) |
408 SDL_GL_SwapBuffers (); | 406 SDL_GL_SwapBuffers(); |
409 else | 407 else |
410 #endif | 408 #endif |
411 if ((SDL_VideoSurface->flags & SDL_HWSURFACE) == SDL_SWSURFACE) { | 409 if ((SDL_VideoSurface->flags & SDL_HWSURFACE) == SDL_SWSURFACE) { |
412 SDL_UpdateRect (SDL_VideoSurface, 0, 0, 0, 0); | 410 SDL_UpdateRect(SDL_VideoSurface, 0, 0, 0, 0); |
413 } | 411 } |
414 EndUpdate (SDL_Window); | 412 EndUpdate(SDL_Window); |
415 } | 413 } |
416 /* If this was an update event for the SIOUX console, we return 0 | 414 /* If this was an update event for the SIOUX console, we return 0 |
417 in order to stop an endless series of updates being triggered. | 415 in order to stop an endless series of updates being triggered. |
418 */ | 416 */ |
419 if ((WindowRef) event.message != SDL_Window) { | 417 if ((WindowRef) event.message != SDL_Window) { |
420 return 0; | 418 return 0; |
421 } | 419 } |
422 break; | 420 break; |
423 case activateEvt: | 421 case activateEvt: |
424 { | 422 { |
425 Mac_HandleActivate (!!(event.modifiers & activeFlag)); | 423 Mac_HandleActivate(!!(event.modifiers & activeFlag)); |
426 } | 424 } |
427 break; | 425 break; |
428 case diskEvt: | 426 case diskEvt: |
429 { | 427 { |
430 #if TARGET_API_MAC_CARBON | 428 #if TARGET_API_MAC_CARBON |
431 /* What are we supposed to do? */ ; | 429 /* What are we supposed to do? */ ; |
432 #else | 430 #else |
433 if (((event.message >> 16) & 0xFFFF) != noErr) { | 431 if (((event.message >> 16) & 0xFFFF) != noErr) { |
434 Point spot; | 432 Point spot; |
435 SetPt (&spot, 0x0070, 0x0050); | 433 SetPt(&spot, 0x0070, 0x0050); |
436 DIBadMount (spot, event.message); | 434 DIBadMount(spot, event.message); |
437 } | 435 } |
438 #endif | 436 #endif |
439 } | 437 } |
440 break; | 438 break; |
441 case osEvt: | 439 case osEvt: |
442 { | 440 { |
443 switch ((event.message >> 24) & 0xFF) { | 441 switch ((event.message >> 24) & 0xFF) { |
444 #if 0 /* Handled above the switch statement */ | 442 #if 0 /* Handled above the switch statement */ |
445 case mouseMovedMessage: | 443 case mouseMovedMessage: |
446 { | 444 { |
447 myGlobalToLocal (this, &event.where); | 445 myGlobalToLocal(this, &event.where); |
448 SDL_PrivateMouseMotion (0, 0, | 446 SDL_PrivateMouseMotion(0, 0, |
449 event.where.h, event.where.v); | 447 event.where.h, event.where.v); |
450 } | 448 } |
451 break; | 449 break; |
452 #endif /* 0 */ | 450 #endif /* 0 */ |
453 case suspendResumeMessage: | 451 case suspendResumeMessage: |
454 { | 452 { |
455 Mac_HandleActivate (!!(event.message & resumeFlag)); | 453 Mac_HandleActivate(!!(event.message & resumeFlag)); |
456 } | 454 } |
457 break; | 455 break; |
458 } | 456 } |
459 } | 457 } |
460 break; | 458 break; |
467 return (event.what != nullEvent); | 465 return (event.what != nullEvent); |
468 } | 466 } |
469 | 467 |
470 | 468 |
471 void | 469 void |
472 Mac_PumpEvents (_THIS) | 470 Mac_PumpEvents(_THIS) |
473 { | 471 { |
474 /* Process pending MacOS events */ | 472 /* Process pending MacOS events */ |
475 while (Mac_HandleEvents (this, 0)) { | 473 while (Mac_HandleEvents(this, 0)) { |
476 /* Loop and check again */ ; | 474 /* Loop and check again */ ; |
477 } | 475 } |
478 } | 476 } |
479 | 477 |
480 void | 478 void |
481 Mac_InitOSKeymap (_THIS) | 479 Mac_InitOSKeymap(_THIS) |
482 { | 480 { |
483 const void *KCHRPtr; | 481 const void *KCHRPtr; |
484 UInt32 state; | 482 UInt32 state; |
485 UInt32 value; | 483 UInt32 value; |
486 int i; | 484 int i; |
487 int world = SDLK_WORLD_0; | 485 int world = SDLK_WORLD_0; |
488 | 486 |
489 /* Map the MAC keysyms */ | 487 /* Map the MAC keysyms */ |
490 for (i = 0; i < SDL_arraysize (MAC_keymap); ++i) | 488 for (i = 0; i < SDL_arraysize(MAC_keymap); ++i) |
491 MAC_keymap[i] = SDLK_UNKNOWN; | 489 MAC_keymap[i] = SDLK_UNKNOWN; |
492 | 490 |
493 /* Defined MAC_* constants */ | 491 /* Defined MAC_* constants */ |
494 MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE; | 492 MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE; |
495 MAC_keymap[MK_F1] = SDLK_F1; | 493 MAC_keymap[MK_F1] = SDLK_F1; |
618 * bascially only useful for ascii char keys. This is also the reason | 616 * bascially only useful for ascii char keys. This is also the reason |
619 * why we keep the static table, too. | 617 * why we keep the static table, too. |
620 */ | 618 */ |
621 | 619 |
622 /* Get a pointer to the systems cached KCHR */ | 620 /* Get a pointer to the systems cached KCHR */ |
623 KCHRPtr = (void *) GetScriptManagerVariable (smKCHRCache); | 621 KCHRPtr = (void *) GetScriptManagerVariable(smKCHRCache); |
624 if (KCHRPtr) { | 622 if (KCHRPtr) { |
625 /* Loop over all 127 possible scan codes */ | 623 /* Loop over all 127 possible scan codes */ |
626 for (i = 0; i < 0x7F; i++) { | 624 for (i = 0; i < 0x7F; i++) { |
627 /* We pretend a clean start to begin with (i.e. no dead keys active */ | 625 /* We pretend a clean start to begin with (i.e. no dead keys active */ |
628 state = 0; | 626 state = 0; |
629 | 627 |
630 /* Now translate the key code to a key value */ | 628 /* Now translate the key code to a key value */ |
631 value = KeyTranslate (KCHRPtr, i, &state) & 0xff; | 629 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; |
632 | 630 |
633 /* If the state become 0, it was a dead key. We need to translate again, | 631 /* If the state become 0, it was a dead key. We need to translate again, |
634 passing in the new state, to get the actual key value */ | 632 passing in the new state, to get the actual key value */ |
635 if (state != 0) | 633 if (state != 0) |
636 value = KeyTranslate (KCHRPtr, i, &state) & 0xff; | 634 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; |
637 | 635 |
638 /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */ | 636 /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */ |
639 if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */ | 637 if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */ |
640 MAC_keymap[i] = world++; | 638 MAC_keymap[i] = world++; |
641 else if (value >= 32) /* non-control ASCII char */ | 639 else if (value >= 32) /* non-control ASCII char */ |
668 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; | 666 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; |
669 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; | 667 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; |
670 } | 668 } |
671 | 669 |
672 static SDL_keysym * | 670 static SDL_keysym * |
673 TranslateKey (int scancode, int modifiers, SDL_keysym * keysym, int pressed) | 671 TranslateKey(int scancode, int modifiers, SDL_keysym * keysym, int pressed) |
674 { | 672 { |
675 /* Set the keysym information */ | 673 /* Set the keysym information */ |
676 keysym->scancode = scancode; | 674 keysym->scancode = scancode; |
677 keysym->sym = MAC_keymap[keysym->scancode]; | 675 keysym->sym = MAC_keymap[keysym->scancode]; |
678 keysym->mod = KMOD_NONE; | 676 keysym->mod = KMOD_NONE; |
681 static unsigned long state = 0; | 679 static unsigned long state = 0; |
682 static Ptr keymap = nil; | 680 static Ptr keymap = nil; |
683 Ptr new_keymap; | 681 Ptr new_keymap; |
684 | 682 |
685 /* Get the current keyboard map resource */ | 683 /* Get the current keyboard map resource */ |
686 new_keymap = (Ptr) GetScriptManagerVariable (smKCHRCache); | 684 new_keymap = (Ptr) GetScriptManagerVariable(smKCHRCache); |
687 if (new_keymap != keymap) { | 685 if (new_keymap != keymap) { |
688 keymap = new_keymap; | 686 keymap = new_keymap; |
689 state = 0; | 687 state = 0; |
690 } | 688 } |
691 keysym->unicode = KeyTranslate (keymap, | 689 keysym->unicode = KeyTranslate(keymap, |
692 keysym->scancode | modifiers, | 690 keysym->scancode | modifiers, |
693 &state) & 0xFFFF; | 691 &state) & 0xFFFF; |
694 } | 692 } |
695 return (keysym); | 693 return (keysym); |
696 } | 694 } |
697 | 695 |
698 void | 696 void |
699 Mac_InitEvents (_THIS) | 697 Mac_InitEvents(_THIS) |
700 { | 698 { |
701 /* Create apple menu bar */ | 699 /* Create apple menu bar */ |
702 apple_menu = GetMenu (mApple); | 700 apple_menu = GetMenu(mApple); |
703 if (apple_menu != nil) { | 701 if (apple_menu != nil) { |
704 AppendResMenu (apple_menu, 'DRVR'); | 702 AppendResMenu(apple_menu, 'DRVR'); |
705 InsertMenu (apple_menu, 0); | 703 InsertMenu(apple_menu, 0); |
706 } | 704 } |
707 DrawMenuBar (); | 705 DrawMenuBar(); |
708 | 706 |
709 /* Get rid of spurious events at startup */ | 707 /* Get rid of spurious events at startup */ |
710 FlushEvents (everyEvent, 0); | 708 FlushEvents(everyEvent, 0); |
711 | 709 |
712 /* Allow every event but keyrepeat */ | 710 /* Allow every event but keyrepeat */ |
713 SetEventMask (everyEvent & ~autoKeyMask); | 711 SetEventMask(everyEvent & ~autoKeyMask); |
714 } | 712 } |
715 | 713 |
716 void | 714 void |
717 Mac_QuitEvents (_THIS) | 715 Mac_QuitEvents(_THIS) |
718 { | 716 { |
719 ClearMenuBar (); | 717 ClearMenuBar(); |
720 if (apple_menu != nil) { | 718 if (apple_menu != nil) { |
721 ReleaseResource ((char **) apple_menu); | 719 ReleaseResource((char **) apple_menu); |
722 } | 720 } |
723 | 721 |
724 /* Clean up pending events */ | 722 /* Clean up pending events */ |
725 FlushEvents (everyEvent, 0); | 723 FlushEvents(everyEvent, 0); |
726 } | 724 } |
727 | 725 |
728 static void | 726 static void |
729 Mac_DoAppleMenu (_THIS, long choice) | 727 Mac_DoAppleMenu(_THIS, long choice) |
730 { | 728 { |
731 #if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */ | 729 #if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */ |
732 short menu, item; | 730 short menu, item; |
733 | 731 |
734 item = (choice & 0xFFFF); | 732 item = (choice & 0xFFFF); |
746 break; | 744 break; |
747 default: | 745 default: |
748 { | 746 { |
749 Str255 name; | 747 Str255 name; |
750 | 748 |
751 GetMenuItemText (apple_menu, item, name); | 749 GetMenuItemText(apple_menu, item, name); |
752 OpenDeskAcc (name); | 750 OpenDeskAcc(name); |
753 } | 751 } |
754 break; | 752 break; |
755 } | 753 } |
756 } | 754 } |
757 break; | 755 break; |
768 QDGlobals *theQD = NULL; | 766 QDGlobals *theQD = NULL; |
769 #endif | 767 #endif |
770 | 768 |
771 /* Exported to the macmain code */ | 769 /* Exported to the macmain code */ |
772 void | 770 void |
773 SDL_InitQuickDraw (struct QDGlobals *the_qd) | 771 SDL_InitQuickDraw(struct QDGlobals *the_qd) |
774 { | 772 { |
775 #if !TARGET_API_MAC_CARBON | 773 #if !TARGET_API_MAC_CARBON |
776 theQD = the_qd; | 774 theQD = the_qd; |
777 #endif | 775 #endif |
778 } | 776 } |