comparison src/video/maccommon/SDL_macevents.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents e49147870aac
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
48 /* Define this to be able to collapse SDL windows. 48 /* Define this to be able to collapse SDL windows.
49 #define USE_APPEARANCE_MANAGER 49 #define USE_APPEARANCE_MANAGER
50 */ 50 */
51 51
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 Mac_HandleActivate(int activate) 65 static int
66 { 66 Mac_HandleActivate (int activate)
67 if ( activate ) { 67 {
68 /* Show the current SDL application cursor */ 68 if (activate) {
69 SDL_SetCursor(NULL); 69 /* Show the current SDL application cursor */
70 70 SDL_SetCursor (NULL);
71 /* put our mask back case it changed during context switch */ 71
72 SetEventMask(everyEvent & ~autoKeyMask); 72 /* put our mask back case it changed during context switch */
73 } else { 73 SetEventMask (everyEvent & ~autoKeyMask);
74 #if TARGET_API_MAC_CARBON 74 } else {
75 { Cursor cursor; 75 #if TARGET_API_MAC_CARBON
76 SetCursor(GetQDGlobalsArrow(&cursor)); 76 {
77 } 77 Cursor cursor;
78 SetCursor (GetQDGlobalsArrow (&cursor));
79 }
78 #else 80 #else
79 SetCursor(&theQD->arrow); 81 SetCursor (&theQD->arrow);
80 #endif 82 #endif
81 if ( ! Mac_cursor_showing ) { 83 if (!Mac_cursor_showing) {
82 ShowCursor(); 84 ShowCursor ();
83 Mac_cursor_showing = 1; 85 Mac_cursor_showing = 1;
84 } 86 }
85 } 87 }
86 return(SDL_PrivateAppActive(activate, SDL_APPINPUTFOCUS)); 88 return (SDL_PrivateAppActive (activate, SDL_APPINPUTFOCUS));
87 } 89 }
88 90
89 static void myGlobalToLocal(_THIS, Point *pt) 91 static void
90 { 92 myGlobalToLocal (_THIS, Point * pt)
91 if ( SDL_VideoSurface && !(SDL_VideoSurface->flags&SDL_FULLSCREEN) ) { 93 {
92 GrafPtr saveport; 94 if (SDL_VideoSurface && !(SDL_VideoSurface->flags & SDL_FULLSCREEN)) {
93 GetPort(&saveport); 95 GrafPtr saveport;
94 #if TARGET_API_MAC_CARBON 96 GetPort (&saveport);
95 SetPort(GetWindowPort(SDL_Window)); 97 #if TARGET_API_MAC_CARBON
98 SetPort (GetWindowPort (SDL_Window));
96 #else 99 #else
97 SetPort(SDL_Window); 100 SetPort (SDL_Window);
98 #endif 101 #endif
99 GlobalToLocal(pt); 102 GlobalToLocal (pt);
100 SetPort(saveport); 103 SetPort (saveport);
101 } 104 }
102 } 105 }
103 106
104 /* The main MacOS event handler */ 107 /* The main MacOS event handler */
105 static int Mac_HandleEvents(_THIS, int wait4it) 108 static int
106 { 109 Mac_HandleEvents (_THIS, int wait4it)
107 static int mouse_button = 1; 110 {
108 int i; 111 static int mouse_button = 1;
109 EventRecord event; 112 int i;
110 113 EventRecord event;
111 #if TARGET_API_MAC_CARBON 114
112 /* There's no GetOSEvent() in the Carbon API. *sigh* */ 115 #if TARGET_API_MAC_CARBON
116 /* There's no GetOSEvent() in the Carbon API. *sigh* */
113 #define cooperative_multitasking 1 117 #define cooperative_multitasking 1
114 #else 118 #else
115 int cooperative_multitasking; 119 int cooperative_multitasking;
116 /* If we're running fullscreen, we can hog the MacOS events, 120 /* If we're running fullscreen, we can hog the MacOS events,
117 otherwise we had better play nicely with the other apps. 121 otherwise we had better play nicely with the other apps.
118 */ 122 */
119 if ( this->screen && (this->screen->flags & SDL_FULLSCREEN) ) { 123 if (this->screen && (this->screen->flags & SDL_FULLSCREEN)) {
120 cooperative_multitasking = 0; 124 cooperative_multitasking = 0;
121 } else { 125 } else {
122 cooperative_multitasking = 1; 126 cooperative_multitasking = 1;
123 } 127 }
124 #endif 128 #endif
125 129
126 /* If we call WaitNextEvent(), MacOS will check other processes 130 /* If we call WaitNextEvent(), MacOS will check other processes
127 * and allow them to run, and perform other high-level processing. 131 * and allow them to run, and perform other high-level processing.
128 */ 132 */
129 if ( cooperative_multitasking || wait4it ) { 133 if (cooperative_multitasking || wait4it) {
130 UInt32 wait_time; 134 UInt32 wait_time;
131 135
132 /* Are we polling or not? */ 136 /* Are we polling or not? */
133 if ( wait4it ) { 137 if (wait4it) {
134 wait_time = 2147483647; 138 wait_time = 2147483647;
135 } else { 139 } else {
136 wait_time = 0; 140 wait_time = 0;
137 } 141 }
138 WaitNextEvent(everyEvent, &event, wait_time, nil); 142 WaitNextEvent (everyEvent, &event, wait_time, nil);
139 } else { 143 } else {
140 #if ! TARGET_API_MAC_CARBON 144 #if ! TARGET_API_MAC_CARBON
141 GetOSEvent(everyEvent, &event); 145 GetOSEvent (everyEvent, &event);
142 #endif 146 #endif
143 } 147 }
144 148
145 #if TARGET_API_MAC_CARBON 149 #if TARGET_API_MAC_CARBON
146 /* for some reason, event.where isn't set ? */ 150 /* for some reason, event.where isn't set ? */
147 GetGlobalMouse ( &event.where ); 151 GetGlobalMouse (&event.where);
148 #endif 152 #endif
149 153
150 /* Check for mouse motion */ 154 /* Check for mouse motion */
151 if ( (event.where.h != last_where.h) || 155 if ((event.where.h != last_where.h) || (event.where.v != last_where.v)) {
152 (event.where.v != last_where.v) ) { 156 Point pt;
153 Point pt; 157 pt = last_where = event.where;
154 pt = last_where = event.where; 158 myGlobalToLocal (this, &pt);
155 myGlobalToLocal(this, &pt); 159 SDL_PrivateMouseMotion (0, 0, pt.h, pt.v);
156 SDL_PrivateMouseMotion(0, 0, pt.h, pt.v); 160 }
157 } 161
158 162 /* Check the current state of the keyboard */
159 /* Check the current state of the keyboard */ 163 if (SDL_GetAppState () & SDL_APPINPUTFOCUS) {
160 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { 164 KeyMap keys;
161 KeyMap keys; 165
162 166 /* Check for special non-event keys */
163 /* Check for special non-event keys */ 167 if (event.modifiers != last_mods) {
164 if ( event.modifiers != last_mods ) { 168 static struct
165 static struct { 169 {
166 EventModifiers mask; 170 EventModifiers mask;
167 SDLKey key; 171 SDLKey key;
168 } mods[] = { 172 } mods[] = {
169 { alphaLock, SDLK_CAPSLOCK }, 173 {
170 #if 0 /* These are handled below in the GetKeys() code */ 174 alphaLock, SDLK_CAPSLOCK},
171 { cmdKey, SDLK_LMETA }, 175 #if 0 /* These are handled below in the GetKeys() code */
172 { shiftKey, SDLK_LSHIFT }, 176 {
173 { rightShiftKey, SDLK_RSHIFT }, 177 cmdKey, SDLK_LMETA}, {
174 { optionKey, SDLK_LALT }, 178 shiftKey, SDLK_LSHIFT}, {
175 { rightOptionKey, SDLK_RALT }, 179 rightShiftKey, SDLK_RSHIFT}, {
176 { controlKey, SDLK_LCTRL }, 180 optionKey, SDLK_LALT}, {
177 { rightControlKey, SDLK_RCTRL }, 181 rightOptionKey, SDLK_RALT}, {
182 controlKey, SDLK_LCTRL}, {
183 rightControlKey, SDLK_RCTRL},
178 #endif /* 0 */ 184 #endif /* 0 */
179 { 0, 0 } 185 {
180 }; 186 0, 0}
181 SDL_keysym keysym; 187 };
182 Uint8 mode; 188 SDL_keysym keysym;
183 EventModifiers mod, mask; 189 Uint8 mode;
184 190 EventModifiers mod, mask;
185 191
186 /* Set up the keyboard event */ 192
187 keysym.scancode = 0; 193 /* Set up the keyboard event */
188 keysym.sym = SDLK_UNKNOWN; 194 keysym.scancode = 0;
189 keysym.mod = KMOD_NONE; 195 keysym.sym = SDLK_UNKNOWN;
190 keysym.unicode = 0; 196 keysym.mod = KMOD_NONE;
191 197 keysym.unicode = 0;
192 /* See what has changed, and generate events */ 198
193 mod = event.modifiers; 199 /* See what has changed, and generate events */
194 for ( i=0; mods[i].mask; ++i ) { 200 mod = event.modifiers;
195 mask = mods[i].mask; 201 for (i = 0; mods[i].mask; ++i) {
196 if ( (mod&mask) != (last_mods&mask) ) { 202 mask = mods[i].mask;
197 keysym.sym = mods[i].key; 203 if ((mod & mask) != (last_mods & mask)) {
198 if ( (mod&mask) || 204 keysym.sym = mods[i].key;
199 (mods[i].key == SDLK_CAPSLOCK) ) { 205 if ((mod & mask) || (mods[i].key == SDLK_CAPSLOCK)) {
200 mode = SDL_PRESSED; 206 mode = SDL_PRESSED;
201 } else { 207 } else {
202 mode = SDL_RELEASED; 208 mode = SDL_RELEASED;
203 } 209 }
204 SDL_PrivateKeyboard(mode, &keysym); 210 SDL_PrivateKeyboard (mode, &keysym);
205 } 211 }
206 } 212 }
207 213
208 /* Save state for next time */ 214 /* Save state for next time */
209 last_mods = mod; 215 last_mods = mod;
210 } 216 }
211 217
212 /* Check for normal event keys, but we have to scan the 218 /* Check for normal event keys, but we have to scan the
213 actual keyboard state because on Mac OS X a keydown event 219 actual keyboard state because on Mac OS X a keydown event
214 is immediately followed by a keyup event. 220 is immediately followed by a keyup event.
215 */ 221 */
216 GetKeys(keys); 222 GetKeys (keys);
217 if ( (keys[0] != last_keys[0]) || (keys[1] != last_keys[1]) || 223 if ((keys[0] != last_keys[0]) || (keys[1] != last_keys[1]) ||
218 (keys[2] != last_keys[2]) || (keys[3] != last_keys[3]) ) { 224 (keys[2] != last_keys[2]) || (keys[3] != last_keys[3])) {
219 SDL_keysym keysym; 225 SDL_keysym keysym;
220 int old_bit, new_bit; 226 int old_bit, new_bit;
221 227
222 #ifdef DEBUG_KEYBOARD 228 #ifdef DEBUG_KEYBOARD
223 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",
224 new_keys[0], new_keys[1], 230 new_keys[0], new_keys[1], new_keys[2], new_keys[3]);
225 new_keys[2], new_keys[3]); 231 #endif
226 #endif 232 for (i = 0; i < 128; ++i) {
227 for ( i=0; i<128; ++i ) { 233 old_bit = (((Uint8 *) last_keys)[i / 8] >> (i % 8)) & 0x01;
228 old_bit = (((Uint8 *)last_keys)[i/8]>>(i%8)) & 0x01; 234 new_bit = (((Uint8 *) keys)[i / 8] >> (i % 8)) & 0x01;
229 new_bit = (((Uint8 *)keys)[i/8]>>(i%8)) & 0x01; 235 if (old_bit != new_bit) {
230 if ( old_bit != new_bit ) { 236 /* Post the keyboard event */
231 /* Post the keyboard event */
232 #ifdef DEBUG_KEYBOARD 237 #ifdef DEBUG_KEYBOARD
233 fprintf(stderr,"Scancode: 0x%2.2X\n",i); 238 fprintf (stderr, "Scancode: 0x%2.2X\n", i);
234 #endif 239 #endif
235 SDL_PrivateKeyboard(new_bit, 240 SDL_PrivateKeyboard (new_bit,
236 TranslateKey(i, event.modifiers, 241 TranslateKey (i,
237 &keysym, new_bit)); 242 event.
238 } 243 modifiers,
239 } 244 &keysym, new_bit));
240 245 }
241 /* Save state for next time */ 246 }
242 last_keys[0] = keys[0]; 247
243 last_keys[1] = keys[1]; 248 /* Save state for next time */
244 last_keys[2] = keys[2]; 249 last_keys[0] = keys[0];
245 last_keys[3] = keys[3]; 250 last_keys[1] = keys[1];
246 } 251 last_keys[2] = keys[2];
247 } 252 last_keys[3] = keys[3];
248 253 }
249 /* Handle normal events */ 254 }
250 switch (event.what) { 255
251 case mouseDown: { 256 /* Handle normal events */
252 WindowRef win; 257 switch (event.what) {
253 short area; 258 case mouseDown:
254 259 {
255 area = FindWindow(event.where, &win); 260 WindowRef win;
256 /* Support switching between the SIOUX console 261 short area;
257 and SDL_Window by clicking in the window. 262
258 */ 263 area = FindWindow (event.where, &win);
259 if ( win && (win != FrontWindow()) ) { 264 /* Support switching between the SIOUX console
260 SelectWindow(win); 265 and SDL_Window by clicking in the window.
261 } 266 */
262 switch (area) { 267 if (win && (win != FrontWindow ())) {
263 case inMenuBar: /* Only the apple menu exists */ 268 SelectWindow (win);
264 Mac_DoAppleMenu(this, MenuSelect(event.where)); 269 }
265 HiliteMenu(0); 270 switch (area) {
266 break; 271 case inMenuBar: /* Only the apple menu exists */
267 case inDrag: 272 Mac_DoAppleMenu (this, MenuSelect (event.where));
268 #if TARGET_API_MAC_CARBON 273 HiliteMenu (0);
269 DragWindow(win, event.where, NULL); 274 break;
275 case inDrag:
276 #if TARGET_API_MAC_CARBON
277 DragWindow (win, event.where, NULL);
270 #else 278 #else
271 DragWindow(win, event.where, &theQD->screenBits.bounds); 279 DragWindow (win, event.where, &theQD->screenBits.bounds);
272 #endif 280 #endif
273 break; 281 break;
274 case inGoAway: 282 case inGoAway:
275 if ( TrackGoAway(win, event.where) ) { 283 if (TrackGoAway (win, event.where)) {
276 SDL_PrivateQuit(); 284 SDL_PrivateQuit ();
277 } 285 }
278 break; 286 break;
279 case inContent: 287 case inContent:
280 myGlobalToLocal(this, &event.where); 288 myGlobalToLocal (this, &event.where);
281 /* Treat command-click as right mouse button */ 289 /* Treat command-click as right mouse button */
282 if ( event.modifiers & optionKey ) { 290 if (event.modifiers & optionKey) {
283 mouse_button = 2; 291 mouse_button = 2;
284 } else if ( event.modifiers & cmdKey ) { 292 } else if (event.modifiers & cmdKey) {
285 mouse_button = 3; 293 mouse_button = 3;
286 } else { 294 } else {
287 mouse_button = 1; 295 mouse_button = 1;
288 } 296 }
289 SDL_PrivateMouseButton(SDL_PRESSED, 297 SDL_PrivateMouseButton (SDL_PRESSED,
290 mouse_button, event.where.h, event.where.v); 298 mouse_button, event.where.h,
291 break; 299 event.where.v);
292 case inGrow: { 300 break;
293 int newSize; 301 case inGrow:
294 302 {
295 /* Don't allow resize if video mode isn't resizable */ 303 int newSize;
296 if ( ! SDL_PublicSurface || 304
297 ! (SDL_PublicSurface->flags & SDL_RESIZABLE) ) { 305 /* Don't allow resize if video mode isn't resizable */
298 break; 306 if (!SDL_PublicSurface ||
299 } 307 !(SDL_PublicSurface->flags & SDL_RESIZABLE)) {
300 #if TARGET_API_MAC_CARBON 308 break;
301 newSize = GrowWindow(win, event.where, NULL); 309 }
310 #if TARGET_API_MAC_CARBON
311 newSize = GrowWindow (win, event.where, NULL);
302 #else 312 #else
303 newSize = GrowWindow(win, event.where, &theQD->screenBits.bounds); 313 newSize =
304 #endif 314 GrowWindow (win, event.where,
305 if ( newSize ) { 315 &theQD->screenBits.bounds);
316 #endif
317 if (newSize) {
306 #if !TARGET_API_MAC_CARBON 318 #if !TARGET_API_MAC_CARBON
307 EraseRect ( &theQD->screenBits.bounds ); 319 EraseRect (&theQD->screenBits.bounds);
308 #endif 320 #endif
309 SizeWindow ( win, LoWord (newSize), HiWord (newSize), 1 ); 321 SizeWindow (win, LoWord (newSize),
310 SDL_PrivateResize ( LoWord (newSize), HiWord (newSize) ); 322 HiWord (newSize), 1);
311 } 323 SDL_PrivateResize (LoWord (newSize),
312 } break; 324 HiWord (newSize));
313 case inZoomIn: 325 }
314 case inZoomOut: 326 }
315 if ( TrackBox (win, event.where, area )) { 327 break;
316 Rect rect; 328 case inZoomIn:
329 case inZoomOut:
330 if (TrackBox (win, event.where, area)) {
331 Rect rect;
317 #if !TARGET_API_MAC_CARBON 332 #if !TARGET_API_MAC_CARBON
318 EraseRect ( &theQD->screenBits.bounds ); 333 EraseRect (&theQD->screenBits.bounds);
319 #endif 334 #endif
320 ZoomWindow ( win, area, 0); 335 ZoomWindow (win, area, 0);
321 if ( area == inZoomIn ) { 336 if (area == inZoomIn) {
322 GetWindowUserState(SDL_Window, &rect); 337 GetWindowUserState (SDL_Window, &rect);
323 } else { 338 } else {
324 GetWindowStandardState(SDL_Window, &rect); 339 GetWindowStandardState (SDL_Window, &rect);
325 } 340 }
326 SDL_PrivateResize (rect.right-rect.left, 341 SDL_PrivateResize (rect.right - rect.left,
327 rect.bottom-rect.top); 342 rect.bottom - rect.top);
328 } 343 }
329 break; 344 break;
330 #if TARGET_API_MAC_CARBON 345 #if TARGET_API_MAC_CARBON
331 case inCollapseBox: 346 case inCollapseBox:
332 if ( TrackBox (win, event.where, area )) { 347 if (TrackBox (win, event.where, area)) {
333 if ( IsWindowCollapsable(win) ) { 348 if (IsWindowCollapsable (win)) {
334 CollapseWindow (win, !IsWindowCollapsed(win)); 349 CollapseWindow (win, !IsWindowCollapsed (win));
335 /* There should be something done like in inGrow case, but... */ 350 /* There should be something done like in inGrow case, but... */
336 } 351 }
337 } 352 }
338 break; 353 break;
339 #endif /* TARGET_API_MAC_CARBON */ 354 #endif /* TARGET_API_MAC_CARBON */
340 case inSysWindow: 355 case inSysWindow:
341 #if TARGET_API_MAC_CARBON 356 #if TARGET_API_MAC_CARBON
342 /* Never happens in Carbon? */ 357 /* Never happens in Carbon? */
343 #else 358 #else
344 SystemClick(&event, win); 359 SystemClick (&event, win);
345 #endif 360 #endif
346 break; 361 break;
347 default: 362 default:
348 break; 363 break;
349 } 364 }
350 } 365 }
351 break; 366 break;
352 case mouseUp: { 367 case mouseUp:
353 myGlobalToLocal(this, &event.where); 368 {
354 /* Release the mouse button we simulated in the last press. 369 myGlobalToLocal (this, &event.where);
355 The drawback of this methos is we cannot press more than 370 /* Release the mouse button we simulated in the last press.
356 one button. However, this doesn't matter, since there is 371 The drawback of this methos is we cannot press more than
357 only a single logical mouse button, even if you have a 372 one button. However, this doesn't matter, since there is
358 multi-button mouse, this doesn't matter at all. 373 only a single logical mouse button, even if you have a
359 */ 374 multi-button mouse, this doesn't matter at all.
360 SDL_PrivateMouseButton(SDL_RELEASED, 375 */
361 mouse_button, event.where.h, event.where.v); 376 SDL_PrivateMouseButton (SDL_RELEASED,
362 } 377 mouse_button, event.where.h,
363 break; 378 event.where.v);
364 #if 0 /* Handled above the switch statement */ 379 }
365 case keyDown: { 380 break;
366 SDL_keysym keysym; 381 #if 0 /* Handled above the switch statement */
367 382 case keyDown:
368 SDL_PrivateKeyboard(SDL_PRESSED, 383 {
369 TranslateKey((event.message&keyCodeMask)>>8 384 SDL_keysym keysym;
370 event.modifiers, &keysym, 1)); 385
371 } 386 SDL_PrivateKeyboard (SDL_PRESSED,
372 break; 387 TranslateKey ((event.
373 case keyUp: { 388 message & keyCodeMask) >> 8
374 SDL_keysym keysym; 389 event.modifiers, &keysym, 1));
375 390 }
376 SDL_PrivateKeyboard(SDL_RELEASED, 391 break;
377 TranslateKey((event.message&keyCodeMask)>>8 392 case keyUp:
378 event.modifiers, &keysym, 0)); 393 {
379 } 394 SDL_keysym keysym;
380 break; 395
381 #endif 396 SDL_PrivateKeyboard (SDL_RELEASED,
382 case updateEvt: { 397 TranslateKey ((event.
383 BeginUpdate(SDL_Window); 398 message & keyCodeMask) >> 8
384 #if SDL_VIDEO_OPENGL 399 event.modifiers, &keysym, 0));
385 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) 400 }
386 SDL_GL_SwapBuffers(); 401 break;
387 else 402 #endif
388 #endif 403 case updateEvt:
389 if ( (SDL_VideoSurface->flags & SDL_HWSURFACE) == 404 {
390 SDL_SWSURFACE ) { 405 BeginUpdate (SDL_Window);
391 SDL_UpdateRect(SDL_VideoSurface, 0, 0, 0, 0); 406 #if SDL_VIDEO_OPENGL
392 } 407 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL)
393 EndUpdate(SDL_Window); 408 SDL_GL_SwapBuffers ();
394 } 409 else
395 /* If this was an update event for the SIOUX console, we return 0 410 #endif
396 in order to stop an endless series of updates being triggered. 411 if ((SDL_VideoSurface->flags & SDL_HWSURFACE) == SDL_SWSURFACE) {
397 */ 412 SDL_UpdateRect (SDL_VideoSurface, 0, 0, 0, 0);
398 if ( (WindowRef) event.message != SDL_Window ) { 413 }
399 return 0; 414 EndUpdate (SDL_Window);
400 } 415 }
401 break; 416 /* If this was an update event for the SIOUX console, we return 0
402 case activateEvt: { 417 in order to stop an endless series of updates being triggered.
403 Mac_HandleActivate(!!(event.modifiers & activeFlag)); 418 */
404 } 419 if ((WindowRef) event.message != SDL_Window) {
405 break; 420 return 0;
406 case diskEvt: { 421 }
407 #if TARGET_API_MAC_CARBON 422 break;
408 /* What are we supposed to do? */; 423 case activateEvt:
424 {
425 Mac_HandleActivate (!!(event.modifiers & activeFlag));
426 }
427 break;
428 case diskEvt:
429 {
430 #if TARGET_API_MAC_CARBON
431 /* What are we supposed to do? */ ;
409 #else 432 #else
410 if ( ((event.message>>16)&0xFFFF) != noErr ) { 433 if (((event.message >> 16) & 0xFFFF) != noErr) {
411 Point spot; 434 Point spot;
412 SetPt(&spot, 0x0070, 0x0050); 435 SetPt (&spot, 0x0070, 0x0050);
413 DIBadMount(spot, event.message); 436 DIBadMount (spot, event.message);
414 } 437 }
415 #endif 438 #endif
416 } 439 }
417 break; 440 break;
418 case osEvt: { 441 case osEvt:
419 switch ((event.message>>24) & 0xFF) { 442 {
420 #if 0 /* Handled above the switch statement */ 443 switch ((event.message >> 24) & 0xFF) {
421 case mouseMovedMessage: { 444 #if 0 /* Handled above the switch statement */
422 myGlobalToLocal(this, &event.where); 445 case mouseMovedMessage:
423 SDL_PrivateMouseMotion(0, 0, 446 {
424 event.where.h, event.where.v); 447 myGlobalToLocal (this, &event.where);
425 } 448 SDL_PrivateMouseMotion (0, 0,
426 break; 449 event.where.h, event.where.v);
450 }
451 break;
427 #endif /* 0 */ 452 #endif /* 0 */
428 case suspendResumeMessage: { 453 case suspendResumeMessage:
429 Mac_HandleActivate(!!(event.message & resumeFlag)); 454 {
430 } 455 Mac_HandleActivate (!!(event.message & resumeFlag));
431 break; 456 }
432 } 457 break;
433 } 458 }
434 break; 459 }
435 default: { 460 break;
436 ; 461 default:
437 } 462 {
438 break; 463 ;
439 } 464 }
440 return (event.what != nullEvent); 465 break;
441 } 466 }
442 467 return (event.what != nullEvent);
443 468 }
444 void Mac_PumpEvents(_THIS) 469
445 { 470
446 /* Process pending MacOS events */ 471 void
447 while ( Mac_HandleEvents(this, 0) ) { 472 Mac_PumpEvents (_THIS)
448 /* Loop and check again */; 473 {
449 } 474 /* Process pending MacOS events */
450 } 475 while (Mac_HandleEvents (this, 0)) {
451 476 /* Loop and check again */ ;
452 void Mac_InitOSKeymap(_THIS) 477 }
453 { 478 }
454 const void *KCHRPtr; 479
455 UInt32 state; 480 void
456 UInt32 value; 481 Mac_InitOSKeymap (_THIS)
457 int i; 482 {
458 int world = SDLK_WORLD_0; 483 const void *KCHRPtr;
459 484 UInt32 state;
460 /* Map the MAC keysyms */ 485 UInt32 value;
461 for ( i=0; i<SDL_arraysize(MAC_keymap); ++i ) 486 int i;
462 MAC_keymap[i] = SDLK_UNKNOWN; 487 int world = SDLK_WORLD_0;
463 488
464 /* Defined MAC_* constants */ 489 /* Map the MAC keysyms */
465 MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE; 490 for (i = 0; i < SDL_arraysize (MAC_keymap); ++i)
466 MAC_keymap[MK_F1] = SDLK_F1; 491 MAC_keymap[i] = SDLK_UNKNOWN;
467 MAC_keymap[MK_F2] = SDLK_F2; 492
468 MAC_keymap[MK_F3] = SDLK_F3; 493 /* Defined MAC_* constants */
469 MAC_keymap[MK_F4] = SDLK_F4; 494 MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE;
470 MAC_keymap[MK_F5] = SDLK_F5; 495 MAC_keymap[MK_F1] = SDLK_F1;
471 MAC_keymap[MK_F6] = SDLK_F6; 496 MAC_keymap[MK_F2] = SDLK_F2;
472 MAC_keymap[MK_F7] = SDLK_F7; 497 MAC_keymap[MK_F3] = SDLK_F3;
473 MAC_keymap[MK_F8] = SDLK_F8; 498 MAC_keymap[MK_F4] = SDLK_F4;
474 MAC_keymap[MK_F9] = SDLK_F9; 499 MAC_keymap[MK_F5] = SDLK_F5;
475 MAC_keymap[MK_F10] = SDLK_F10; 500 MAC_keymap[MK_F6] = SDLK_F6;
476 MAC_keymap[MK_F11] = SDLK_F11; 501 MAC_keymap[MK_F7] = SDLK_F7;
477 MAC_keymap[MK_F12] = SDLK_F12; 502 MAC_keymap[MK_F8] = SDLK_F8;
478 MAC_keymap[MK_PRINT] = SDLK_PRINT; 503 MAC_keymap[MK_F9] = SDLK_F9;
479 MAC_keymap[MK_SCROLLOCK] = SDLK_SCROLLOCK; 504 MAC_keymap[MK_F10] = SDLK_F10;
480 MAC_keymap[MK_PAUSE] = SDLK_PAUSE; 505 MAC_keymap[MK_F11] = SDLK_F11;
481 MAC_keymap[MK_POWER] = SDLK_POWER; 506 MAC_keymap[MK_F12] = SDLK_F12;
482 MAC_keymap[MK_BACKQUOTE] = SDLK_BACKQUOTE; 507 MAC_keymap[MK_PRINT] = SDLK_PRINT;
483 MAC_keymap[MK_1] = SDLK_1; 508 MAC_keymap[MK_SCROLLOCK] = SDLK_SCROLLOCK;
484 MAC_keymap[MK_2] = SDLK_2; 509 MAC_keymap[MK_PAUSE] = SDLK_PAUSE;
485 MAC_keymap[MK_3] = SDLK_3; 510 MAC_keymap[MK_POWER] = SDLK_POWER;
486 MAC_keymap[MK_4] = SDLK_4; 511 MAC_keymap[MK_BACKQUOTE] = SDLK_BACKQUOTE;
487 MAC_keymap[MK_5] = SDLK_5; 512 MAC_keymap[MK_1] = SDLK_1;
488 MAC_keymap[MK_6] = SDLK_6; 513 MAC_keymap[MK_2] = SDLK_2;
489 MAC_keymap[MK_7] = SDLK_7; 514 MAC_keymap[MK_3] = SDLK_3;
490 MAC_keymap[MK_8] = SDLK_8; 515 MAC_keymap[MK_4] = SDLK_4;
491 MAC_keymap[MK_9] = SDLK_9; 516 MAC_keymap[MK_5] = SDLK_5;
492 MAC_keymap[MK_0] = SDLK_0; 517 MAC_keymap[MK_6] = SDLK_6;
493 MAC_keymap[MK_MINUS] = SDLK_MINUS; 518 MAC_keymap[MK_7] = SDLK_7;
494 MAC_keymap[MK_EQUALS] = SDLK_EQUALS; 519 MAC_keymap[MK_8] = SDLK_8;
495 MAC_keymap[MK_BACKSPACE] = SDLK_BACKSPACE; 520 MAC_keymap[MK_9] = SDLK_9;
496 MAC_keymap[MK_INSERT] = SDLK_INSERT; 521 MAC_keymap[MK_0] = SDLK_0;
497 MAC_keymap[MK_HOME] = SDLK_HOME; 522 MAC_keymap[MK_MINUS] = SDLK_MINUS;
498 MAC_keymap[MK_PAGEUP] = SDLK_PAGEUP; 523 MAC_keymap[MK_EQUALS] = SDLK_EQUALS;
499 MAC_keymap[MK_NUMLOCK] = SDLK_NUMLOCK; 524 MAC_keymap[MK_BACKSPACE] = SDLK_BACKSPACE;
500 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; 525 MAC_keymap[MK_INSERT] = SDLK_INSERT;
501 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; 526 MAC_keymap[MK_HOME] = SDLK_HOME;
502 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; 527 MAC_keymap[MK_PAGEUP] = SDLK_PAGEUP;
503 MAC_keymap[MK_TAB] = SDLK_TAB; 528 MAC_keymap[MK_NUMLOCK] = SDLK_NUMLOCK;
504 MAC_keymap[MK_q] = SDLK_q; 529 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS;
505 MAC_keymap[MK_w] = SDLK_w; 530 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE;
506 MAC_keymap[MK_e] = SDLK_e; 531 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
507 MAC_keymap[MK_r] = SDLK_r; 532 MAC_keymap[MK_TAB] = SDLK_TAB;
508 MAC_keymap[MK_t] = SDLK_t; 533 MAC_keymap[MK_q] = SDLK_q;
509 MAC_keymap[MK_y] = SDLK_y; 534 MAC_keymap[MK_w] = SDLK_w;
510 MAC_keymap[MK_u] = SDLK_u; 535 MAC_keymap[MK_e] = SDLK_e;
511 MAC_keymap[MK_i] = SDLK_i; 536 MAC_keymap[MK_r] = SDLK_r;
512 MAC_keymap[MK_o] = SDLK_o; 537 MAC_keymap[MK_t] = SDLK_t;
513 MAC_keymap[MK_p] = SDLK_p; 538 MAC_keymap[MK_y] = SDLK_y;
514 MAC_keymap[MK_LEFTBRACKET] = SDLK_LEFTBRACKET; 539 MAC_keymap[MK_u] = SDLK_u;
515 MAC_keymap[MK_RIGHTBRACKET] = SDLK_RIGHTBRACKET; 540 MAC_keymap[MK_i] = SDLK_i;
516 MAC_keymap[MK_BACKSLASH] = SDLK_BACKSLASH; 541 MAC_keymap[MK_o] = SDLK_o;
517 MAC_keymap[MK_DELETE] = SDLK_DELETE; 542 MAC_keymap[MK_p] = SDLK_p;
518 MAC_keymap[MK_END] = SDLK_END; 543 MAC_keymap[MK_LEFTBRACKET] = SDLK_LEFTBRACKET;
519 MAC_keymap[MK_PAGEDOWN] = SDLK_PAGEDOWN; 544 MAC_keymap[MK_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
520 MAC_keymap[MK_KP7] = SDLK_KP7; 545 MAC_keymap[MK_BACKSLASH] = SDLK_BACKSLASH;
521 MAC_keymap[MK_KP8] = SDLK_KP8; 546 MAC_keymap[MK_DELETE] = SDLK_DELETE;
522 MAC_keymap[MK_KP9] = SDLK_KP9; 547 MAC_keymap[MK_END] = SDLK_END;
523 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; 548 MAC_keymap[MK_PAGEDOWN] = SDLK_PAGEDOWN;
524 MAC_keymap[MK_CAPSLOCK] = SDLK_CAPSLOCK; 549 MAC_keymap[MK_KP7] = SDLK_KP7;
525 MAC_keymap[MK_a] = SDLK_a; 550 MAC_keymap[MK_KP8] = SDLK_KP8;
526 MAC_keymap[MK_s] = SDLK_s; 551 MAC_keymap[MK_KP9] = SDLK_KP9;
527 MAC_keymap[MK_d] = SDLK_d; 552 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS;
528 MAC_keymap[MK_f] = SDLK_f; 553 MAC_keymap[MK_CAPSLOCK] = SDLK_CAPSLOCK;
529 MAC_keymap[MK_g] = SDLK_g; 554 MAC_keymap[MK_a] = SDLK_a;
530 MAC_keymap[MK_h] = SDLK_h; 555 MAC_keymap[MK_s] = SDLK_s;
531 MAC_keymap[MK_j] = SDLK_j; 556 MAC_keymap[MK_d] = SDLK_d;
532 MAC_keymap[MK_k] = SDLK_k; 557 MAC_keymap[MK_f] = SDLK_f;
533 MAC_keymap[MK_l] = SDLK_l; 558 MAC_keymap[MK_g] = SDLK_g;
534 MAC_keymap[MK_SEMICOLON] = SDLK_SEMICOLON; 559 MAC_keymap[MK_h] = SDLK_h;
535 MAC_keymap[MK_QUOTE] = SDLK_QUOTE; 560 MAC_keymap[MK_j] = SDLK_j;
536 MAC_keymap[MK_RETURN] = SDLK_RETURN; 561 MAC_keymap[MK_k] = SDLK_k;
537 MAC_keymap[MK_KP4] = SDLK_KP4; 562 MAC_keymap[MK_l] = SDLK_l;
538 MAC_keymap[MK_KP5] = SDLK_KP5; 563 MAC_keymap[MK_SEMICOLON] = SDLK_SEMICOLON;
539 MAC_keymap[MK_KP6] = SDLK_KP6; 564 MAC_keymap[MK_QUOTE] = SDLK_QUOTE;
540 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; 565 MAC_keymap[MK_RETURN] = SDLK_RETURN;
541 MAC_keymap[MK_LSHIFT] = SDLK_LSHIFT; 566 MAC_keymap[MK_KP4] = SDLK_KP4;
542 MAC_keymap[MK_z] = SDLK_z; 567 MAC_keymap[MK_KP5] = SDLK_KP5;
543 MAC_keymap[MK_x] = SDLK_x; 568 MAC_keymap[MK_KP6] = SDLK_KP6;
544 MAC_keymap[MK_c] = SDLK_c; 569 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS;
545 MAC_keymap[MK_v] = SDLK_v; 570 MAC_keymap[MK_LSHIFT] = SDLK_LSHIFT;
546 MAC_keymap[MK_b] = SDLK_b; 571 MAC_keymap[MK_z] = SDLK_z;
547 MAC_keymap[MK_n] = SDLK_n; 572 MAC_keymap[MK_x] = SDLK_x;
548 MAC_keymap[MK_m] = SDLK_m; 573 MAC_keymap[MK_c] = SDLK_c;
549 MAC_keymap[MK_COMMA] = SDLK_COMMA; 574 MAC_keymap[MK_v] = SDLK_v;
550 MAC_keymap[MK_PERIOD] = SDLK_PERIOD; 575 MAC_keymap[MK_b] = SDLK_b;
551 MAC_keymap[MK_SLASH] = SDLK_SLASH; 576 MAC_keymap[MK_n] = SDLK_n;
552 #if 0 /* These are the same as the left versions - use left by default */ 577 MAC_keymap[MK_m] = SDLK_m;
553 MAC_keymap[MK_RSHIFT] = SDLK_RSHIFT; 578 MAC_keymap[MK_COMMA] = SDLK_COMMA;
554 #endif 579 MAC_keymap[MK_PERIOD] = SDLK_PERIOD;
555 MAC_keymap[MK_UP] = SDLK_UP; 580 MAC_keymap[MK_SLASH] = SDLK_SLASH;
556 MAC_keymap[MK_KP1] = SDLK_KP1; 581 #if 0 /* These are the same as the left versions - use left by default */
557 MAC_keymap[MK_KP2] = SDLK_KP2; 582 MAC_keymap[MK_RSHIFT] = SDLK_RSHIFT;
558 MAC_keymap[MK_KP3] = SDLK_KP3; 583 #endif
559 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; 584 MAC_keymap[MK_UP] = SDLK_UP;
560 MAC_keymap[MK_LCTRL] = SDLK_LCTRL; 585 MAC_keymap[MK_KP1] = SDLK_KP1;
561 MAC_keymap[MK_LALT] = SDLK_LALT; 586 MAC_keymap[MK_KP2] = SDLK_KP2;
562 MAC_keymap[MK_LMETA] = SDLK_LMETA; 587 MAC_keymap[MK_KP3] = SDLK_KP3;
563 MAC_keymap[MK_SPACE] = SDLK_SPACE; 588 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER;
564 #if 0 /* These are the same as the left versions - use left by default */ 589 MAC_keymap[MK_LCTRL] = SDLK_LCTRL;
565 MAC_keymap[MK_RMETA] = SDLK_RMETA; 590 MAC_keymap[MK_LALT] = SDLK_LALT;
566 MAC_keymap[MK_RALT] = SDLK_RALT; 591 MAC_keymap[MK_LMETA] = SDLK_LMETA;
567 MAC_keymap[MK_RCTRL] = SDLK_RCTRL; 592 MAC_keymap[MK_SPACE] = SDLK_SPACE;
568 #endif 593 #if 0 /* These are the same as the left versions - use left by default */
569 MAC_keymap[MK_LEFT] = SDLK_LEFT; 594 MAC_keymap[MK_RMETA] = SDLK_RMETA;
570 MAC_keymap[MK_DOWN] = SDLK_DOWN; 595 MAC_keymap[MK_RALT] = SDLK_RALT;
571 MAC_keymap[MK_RIGHT] = SDLK_RIGHT; 596 MAC_keymap[MK_RCTRL] = SDLK_RCTRL;
572 MAC_keymap[MK_KP0] = SDLK_KP0; 597 #endif
573 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; 598 MAC_keymap[MK_LEFT] = SDLK_LEFT;
599 MAC_keymap[MK_DOWN] = SDLK_DOWN;
600 MAC_keymap[MK_RIGHT] = SDLK_RIGHT;
601 MAC_keymap[MK_KP0] = SDLK_KP0;
602 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD;
574 603
575 #if defined(__APPLE__) && defined(__MACH__) 604 #if defined(__APPLE__) && defined(__MACH__)
576 /* Wierd, these keys are on my iBook under Mac OS X 605 /* Wierd, these keys are on my iBook under Mac OS X
577 Note that the left arrow keysym is the same as left ctrl!? 606 Note that the left arrow keysym is the same as left ctrl!?
578 */ 607 */
579 MAC_keymap[MK_IBOOK_ENTER] = SDLK_KP_ENTER; 608 MAC_keymap[MK_IBOOK_ENTER] = SDLK_KP_ENTER;
580 MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT; 609 MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT;
581 MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN; 610 MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN;
582 MAC_keymap[MK_IBOOK_UP] = SDLK_UP; 611 MAC_keymap[MK_IBOOK_UP] = SDLK_UP;
583 MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT; 612 MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT;
584 #endif /* Mac OS X */ 613 #endif /* Mac OS X */
585 614
586 /* Up there we setup a static scancode->keysym map. However, it will not 615 /* Up there we setup a static scancode->keysym map. However, it will not
587 * work very well on international keyboard. Hence we now query MacOS 616 * work very well on international keyboard. Hence we now query MacOS
588 * for its own keymap to adjust our own mapping table. However, this is 617 * for its own keymap to adjust our own mapping table. However, this is
589 * bascially only useful for ascii char keys. This is also the reason 618 * bascially only useful for ascii char keys. This is also the reason
590 * why we keep the static table, too. 619 * why we keep the static table, too.
591 */ 620 */
592 621
593 /* Get a pointer to the systems cached KCHR */ 622 /* Get a pointer to the systems cached KCHR */
594 KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache); 623 KCHRPtr = (void *) GetScriptManagerVariable (smKCHRCache);
595 if (KCHRPtr) 624 if (KCHRPtr) {
596 { 625 /* Loop over all 127 possible scan codes */
597 /* Loop over all 127 possible scan codes */ 626 for (i = 0; i < 0x7F; i++) {
598 for (i = 0; i < 0x7F; i++) 627 /* We pretend a clean start to begin with (i.e. no dead keys active */
599 { 628 state = 0;
600 /* We pretend a clean start to begin with (i.e. no dead keys active */ 629
601 state = 0; 630 /* Now translate the key code to a key value */
602 631 value = KeyTranslate (KCHRPtr, i, &state) & 0xff;
603 /* Now translate the key code to a key value */ 632
604 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; 633 /* If the state become 0, it was a dead key. We need to translate again,
605 634 passing in the new state, to get the actual key value */
606 /* If the state become 0, it was a dead key. We need to translate again, 635 if (state != 0)
607 passing in the new state, to get the actual key value */ 636 value = KeyTranslate (KCHRPtr, i, &state) & 0xff;
608 if (state != 0) 637
609 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; 638 /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
610 639 if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */
611 /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */ 640 MAC_keymap[i] = world++;
612 if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */ 641 else if (value >= 32) /* non-control ASCII char */
613 MAC_keymap[i] = world++; 642 MAC_keymap[i] = value;
614 else if (value >= 32) /* non-control ASCII char */ 643 }
615 MAC_keymap[i] = value; 644 }
616 } 645
617 } 646 /* The keypad codes are re-setup here, because the loop above cannot
618 647 * distinguish between a key on the keypad and a regular key. We maybe
619 /* The keypad codes are re-setup here, because the loop above cannot 648 * could get around this problem in another fashion: NSEvent's flags
620 * distinguish between a key on the keypad and a regular key. We maybe 649 * include a "NSNumericPadKeyMask" bit; we could check that and modify
621 * could get around this problem in another fashion: NSEvent's flags 650 * the symbol we return on the fly. However, this flag seems to exhibit
622 * include a "NSNumericPadKeyMask" bit; we could check that and modify 651 * some weird behaviour related to the num lock key
623 * the symbol we return on the fly. However, this flag seems to exhibit 652 */
624 * some weird behaviour related to the num lock key 653 MAC_keymap[MK_KP0] = SDLK_KP0;
625 */ 654 MAC_keymap[MK_KP1] = SDLK_KP1;
626 MAC_keymap[MK_KP0] = SDLK_KP0; 655 MAC_keymap[MK_KP2] = SDLK_KP2;
627 MAC_keymap[MK_KP1] = SDLK_KP1; 656 MAC_keymap[MK_KP3] = SDLK_KP3;
628 MAC_keymap[MK_KP2] = SDLK_KP2; 657 MAC_keymap[MK_KP4] = SDLK_KP4;
629 MAC_keymap[MK_KP3] = SDLK_KP3; 658 MAC_keymap[MK_KP5] = SDLK_KP5;
630 MAC_keymap[MK_KP4] = SDLK_KP4; 659 MAC_keymap[MK_KP6] = SDLK_KP6;
631 MAC_keymap[MK_KP5] = SDLK_KP5; 660 MAC_keymap[MK_KP7] = SDLK_KP7;
632 MAC_keymap[MK_KP6] = SDLK_KP6; 661 MAC_keymap[MK_KP8] = SDLK_KP8;
633 MAC_keymap[MK_KP7] = SDLK_KP7; 662 MAC_keymap[MK_KP9] = SDLK_KP9;
634 MAC_keymap[MK_KP8] = SDLK_KP8; 663 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS;
635 MAC_keymap[MK_KP9] = SDLK_KP9; 664 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS;
636 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; 665 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD;
637 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; 666 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS;
638 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; 667 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE;
639 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; 668 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
640 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; 669 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER;
641 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; 670 }
642 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; 671
643 } 672 static SDL_keysym *
644 673 TranslateKey (int scancode, int modifiers, SDL_keysym * keysym, int pressed)
645 static SDL_keysym *TranslateKey(int scancode, int modifiers, 674 {
646 SDL_keysym *keysym, int pressed) 675 /* Set the keysym information */
647 { 676 keysym->scancode = scancode;
648 /* Set the keysym information */ 677 keysym->sym = MAC_keymap[keysym->scancode];
649 keysym->scancode = scancode; 678 keysym->mod = KMOD_NONE;
650 keysym->sym = MAC_keymap[keysym->scancode]; 679 keysym->unicode = 0;
651 keysym->mod = KMOD_NONE; 680 if (pressed && SDL_TranslateUNICODE) {
652 keysym->unicode = 0; 681 static unsigned long state = 0;
653 if ( pressed && SDL_TranslateUNICODE ) { 682 static Ptr keymap = nil;
654 static unsigned long state = 0; 683 Ptr new_keymap;
655 static Ptr keymap = nil; 684
656 Ptr new_keymap; 685 /* Get the current keyboard map resource */
657 686 new_keymap = (Ptr) GetScriptManagerVariable (smKCHRCache);
658 /* Get the current keyboard map resource */ 687 if (new_keymap != keymap) {
659 new_keymap = (Ptr)GetScriptManagerVariable(smKCHRCache); 688 keymap = new_keymap;
660 if ( new_keymap != keymap ) { 689 state = 0;
661 keymap = new_keymap; 690 }
662 state = 0; 691 keysym->unicode = KeyTranslate (keymap,
663 } 692 keysym->scancode | modifiers,
664 keysym->unicode = KeyTranslate(keymap, 693 &state) & 0xFFFF;
665 keysym->scancode|modifiers, &state) & 0xFFFF; 694 }
666 } 695 return (keysym);
667 return(keysym); 696 }
668 } 697
669 698 void
670 void Mac_InitEvents(_THIS) 699 Mac_InitEvents (_THIS)
671 { 700 {
672 /* Create apple menu bar */ 701 /* Create apple menu bar */
673 apple_menu = GetMenu(mApple); 702 apple_menu = GetMenu (mApple);
674 if ( apple_menu != nil ) { 703 if (apple_menu != nil) {
675 AppendResMenu(apple_menu, 'DRVR'); 704 AppendResMenu (apple_menu, 'DRVR');
676 InsertMenu(apple_menu, 0); 705 InsertMenu (apple_menu, 0);
677 } 706 }
678 DrawMenuBar(); 707 DrawMenuBar ();
679 708
680 /* Get rid of spurious events at startup */ 709 /* Get rid of spurious events at startup */
681 FlushEvents(everyEvent, 0); 710 FlushEvents (everyEvent, 0);
682 711
683 /* Allow every event but keyrepeat */ 712 /* Allow every event but keyrepeat */
684 SetEventMask(everyEvent & ~autoKeyMask); 713 SetEventMask (everyEvent & ~autoKeyMask);
685 } 714 }
686 715
687 void Mac_QuitEvents(_THIS) 716 void
688 { 717 Mac_QuitEvents (_THIS)
689 ClearMenuBar(); 718 {
690 if ( apple_menu != nil ) { 719 ClearMenuBar ();
691 ReleaseResource((char **)apple_menu); 720 if (apple_menu != nil) {
692 } 721 ReleaseResource ((char **) apple_menu);
693 722 }
694 /* Clean up pending events */ 723
695 FlushEvents(everyEvent, 0); 724 /* Clean up pending events */
696 } 725 FlushEvents (everyEvent, 0);
697 726 }
698 static void Mac_DoAppleMenu(_THIS, long choice) 727
699 { 728 static void
700 #if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */ 729 Mac_DoAppleMenu (_THIS, long choice)
701 short menu, item; 730 {
702 731 #if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */
703 item = (choice&0xFFFF); 732 short menu, item;
704 choice >>= 16; 733
705 menu = (choice&0xFFFF); 734 item = (choice & 0xFFFF);
706 735 choice >>= 16;
707 switch (menu) { 736 menu = (choice & 0xFFFF);
708 case mApple: { 737
709 switch (item) { 738 switch (menu) {
710 case iAbout: { 739 case mApple:
711 /* Run the about box */; 740 {
712 } 741 switch (item) {
713 break; 742 case iAbout:
714 default: { 743 {
715 Str255 name; 744 /* Run the about box */ ;
716 745 }
717 GetMenuItemText(apple_menu, item, name); 746 break;
718 OpenDeskAcc(name); 747 default:
719 } 748 {
720 break; 749 Str255 name;
721 } 750
722 } 751 GetMenuItemText (apple_menu, item, name);
723 break; 752 OpenDeskAcc (name);
724 default: { 753 }
725 /* Ignore other menus */; 754 break;
726 } 755 }
727 } 756 }
757 break;
758 default:
759 {
760 /* Ignore other menus */ ;
761 }
762 }
728 #endif /* !TARGET_API_MAC_CARBON */ 763 #endif /* !TARGET_API_MAC_CARBON */
729 } 764 }
730 765
731 #if !TARGET_API_MAC_CARBON 766 #if !TARGET_API_MAC_CARBON
732 /* Since we don't initialize QuickDraw, we need to get a pointer to qd */ 767 /* Since we don't initialize QuickDraw, we need to get a pointer to qd */
733 QDGlobals *theQD = NULL; 768 QDGlobals *theQD = NULL;
734 #endif 769 #endif
735 770
736 /* Exported to the macmain code */ 771 /* Exported to the macmain code */
737 void SDL_InitQuickDraw(struct QDGlobals *the_qd) 772 void
773 SDL_InitQuickDraw (struct QDGlobals *the_qd)
738 { 774 {
739 #if !TARGET_API_MAC_CARBON 775 #if !TARGET_API_MAC_CARBON
740 theQD = the_qd; 776 theQD = the_qd;
741 #endif 777 #endif
742 } 778 }
779
780 /* vi: set ts=4 sw=4 expandtab: */