Mercurial > sdl-ios-xcode
comparison src/video/maccommon/SDL_macevents.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | f12379c41042 |
children |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
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), HiWord(newSize), 1); |
310 SDL_PrivateResize ( LoWord (newSize), HiWord (newSize) ); | 322 SDL_PrivateResize(LoWord(newSize), HiWord(newSize)); |
311 } | 323 } |
312 } break; | 324 } |
313 case inZoomIn: | 325 break; |
314 case inZoomOut: | 326 case inZoomIn: |
315 if ( TrackBox (win, event.where, area )) { | 327 case inZoomOut: |
316 Rect rect; | 328 if (TrackBox(win, event.where, area)) { |
329 Rect rect; | |
317 #if !TARGET_API_MAC_CARBON | 330 #if !TARGET_API_MAC_CARBON |
318 EraseRect ( &theQD->screenBits.bounds ); | 331 EraseRect(&theQD->screenBits.bounds); |
319 #endif | 332 #endif |
320 ZoomWindow ( win, area, 0); | 333 ZoomWindow(win, area, 0); |
321 if ( area == inZoomIn ) { | 334 if (area == inZoomIn) { |
322 GetWindowUserState(SDL_Window, &rect); | 335 GetWindowUserState(SDL_Window, &rect); |
323 } else { | 336 } else { |
324 GetWindowStandardState(SDL_Window, &rect); | 337 GetWindowStandardState(SDL_Window, &rect); |
325 } | 338 } |
326 SDL_PrivateResize (rect.right-rect.left, | 339 SDL_PrivateResize(rect.right - rect.left, |
327 rect.bottom-rect.top); | 340 rect.bottom - rect.top); |
328 } | 341 } |
329 break; | 342 break; |
330 #if TARGET_API_MAC_CARBON | 343 #if TARGET_API_MAC_CARBON |
331 case inCollapseBox: | 344 case inCollapseBox: |
332 if ( TrackBox (win, event.where, area )) { | 345 if (TrackBox(win, event.where, area)) { |
333 if ( IsWindowCollapsable(win) ) { | 346 if (IsWindowCollapsable(win)) { |
334 CollapseWindow (win, !IsWindowCollapsed(win)); | 347 CollapseWindow(win, !IsWindowCollapsed(win)); |
335 /* There should be something done like in inGrow case, but... */ | 348 /* There should be something done like in inGrow case, but... */ |
336 } | 349 } |
337 } | 350 } |
338 break; | 351 break; |
339 #endif /* TARGET_API_MAC_CARBON */ | 352 #endif /* TARGET_API_MAC_CARBON */ |
340 case inSysWindow: | 353 case inSysWindow: |
341 #if TARGET_API_MAC_CARBON | 354 #if TARGET_API_MAC_CARBON |
342 /* Never happens in Carbon? */ | 355 /* Never happens in Carbon? */ |
343 #else | 356 #else |
344 SystemClick(&event, win); | 357 SystemClick(&event, win); |
345 #endif | 358 #endif |
346 break; | 359 break; |
347 default: | 360 default: |
348 break; | 361 break; |
349 } | 362 } |
350 } | 363 } |
351 break; | 364 break; |
352 case mouseUp: { | 365 case mouseUp: |
353 myGlobalToLocal(this, &event.where); | 366 { |
354 /* Release the mouse button we simulated in the last press. | 367 myGlobalToLocal(this, &event.where); |
355 The drawback of this methos is we cannot press more than | 368 /* Release the mouse button we simulated in the last press. |
356 one button. However, this doesn't matter, since there is | 369 The drawback of this methos is we cannot press more than |
357 only a single logical mouse button, even if you have a | 370 one button. However, this doesn't matter, since there is |
358 multi-button mouse, this doesn't matter at all. | 371 only a single logical mouse button, even if you have a |
359 */ | 372 multi-button mouse, this doesn't matter at all. |
360 SDL_PrivateMouseButton(SDL_RELEASED, | 373 */ |
361 mouse_button, event.where.h, event.where.v); | 374 SDL_PrivateMouseButton(SDL_RELEASED, |
362 } | 375 mouse_button, event.where.h, |
363 break; | 376 event.where.v); |
364 #if 0 /* Handled above the switch statement */ | 377 } |
365 case keyDown: { | 378 break; |
366 SDL_keysym keysym; | 379 #if 0 /* Handled above the switch statement */ |
367 | 380 case keyDown: |
368 SDL_PrivateKeyboard(SDL_PRESSED, | 381 { |
369 TranslateKey((event.message&keyCodeMask)>>8 | 382 SDL_keysym keysym; |
370 event.modifiers, &keysym, 1)); | 383 |
371 } | 384 SDL_PrivateKeyboard(SDL_PRESSED, |
372 break; | 385 TranslateKey((event. |
373 case keyUp: { | 386 message & keyCodeMask) >> 8 |
374 SDL_keysym keysym; | 387 event.modifiers, &keysym, 1)); |
375 | 388 } |
376 SDL_PrivateKeyboard(SDL_RELEASED, | 389 break; |
377 TranslateKey((event.message&keyCodeMask)>>8 | 390 case keyUp: |
378 event.modifiers, &keysym, 0)); | 391 { |
379 } | 392 SDL_keysym keysym; |
380 break; | 393 |
381 #endif | 394 SDL_PrivateKeyboard(SDL_RELEASED, |
382 case updateEvt: { | 395 TranslateKey((event. |
383 BeginUpdate(SDL_Window); | 396 message & keyCodeMask) >> 8 |
384 #if SDL_VIDEO_OPENGL | 397 event.modifiers, &keysym, 0)); |
385 if (SDL_VideoSurface->flags & SDL_OPENGL) | 398 } |
386 SDL_GL_SwapBuffers(); | 399 break; |
387 else | 400 #endif |
388 #endif | 401 case updateEvt: |
389 if ( (SDL_VideoSurface->flags & SDL_HWSURFACE) == | 402 { |
390 SDL_SWSURFACE ) { | 403 BeginUpdate(SDL_Window); |
391 SDL_UpdateRect(SDL_VideoSurface, 0, 0, 0, 0); | 404 #if SDL_VIDEO_OPENGL |
392 } | 405 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) |
393 EndUpdate(SDL_Window); | 406 SDL_GL_SwapBuffers(); |
394 } | 407 else |
395 /* If this was an update event for the SIOUX console, we return 0 | 408 #endif |
396 in order to stop an endless series of updates being triggered. | 409 if ((SDL_VideoSurface->flags & SDL_HWSURFACE) == SDL_SWSURFACE) { |
397 */ | 410 SDL_UpdateRect(SDL_VideoSurface, 0, 0, 0, 0); |
398 if ( (WindowRef) event.message != SDL_Window ) { | 411 } |
399 return 0; | 412 EndUpdate(SDL_Window); |
400 } | 413 } |
401 break; | 414 /* If this was an update event for the SIOUX console, we return 0 |
402 case activateEvt: { | 415 in order to stop an endless series of updates being triggered. |
403 Mac_HandleActivate(!!(event.modifiers & activeFlag)); | 416 */ |
404 } | 417 if ((WindowRef) event.message != SDL_Window) { |
405 break; | 418 return 0; |
406 case diskEvt: { | 419 } |
407 #if TARGET_API_MAC_CARBON | 420 break; |
408 /* What are we supposed to do? */; | 421 case activateEvt: |
422 { | |
423 Mac_HandleActivate(!!(event.modifiers & activeFlag)); | |
424 } | |
425 break; | |
426 case diskEvt: | |
427 { | |
428 #if TARGET_API_MAC_CARBON | |
429 /* What are we supposed to do? */ ; | |
409 #else | 430 #else |
410 if ( ((event.message>>16)&0xFFFF) != noErr ) { | 431 if (((event.message >> 16) & 0xFFFF) != noErr) { |
411 Point spot; | 432 Point spot; |
412 SetPt(&spot, 0x0070, 0x0050); | 433 SetPt(&spot, 0x0070, 0x0050); |
413 DIBadMount(spot, event.message); | 434 DIBadMount(spot, event.message); |
414 } | 435 } |
415 #endif | 436 #endif |
416 } | 437 } |
417 break; | 438 break; |
418 case osEvt: { | 439 case osEvt: |
419 switch ((event.message>>24) & 0xFF) { | 440 { |
420 #if 0 /* Handled above the switch statement */ | 441 switch ((event.message >> 24) & 0xFF) { |
421 case mouseMovedMessage: { | 442 #if 0 /* Handled above the switch statement */ |
422 myGlobalToLocal(this, &event.where); | 443 case mouseMovedMessage: |
423 SDL_PrivateMouseMotion(0, 0, | 444 { |
424 event.where.h, event.where.v); | 445 myGlobalToLocal(this, &event.where); |
425 } | 446 SDL_PrivateMouseMotion(0, 0, |
426 break; | 447 event.where.h, event.where.v); |
448 } | |
449 break; | |
427 #endif /* 0 */ | 450 #endif /* 0 */ |
428 case suspendResumeMessage: { | 451 case suspendResumeMessage: |
429 Mac_HandleActivate(!!(event.message & resumeFlag)); | 452 { |
430 } | 453 Mac_HandleActivate(!!(event.message & resumeFlag)); |
431 break; | 454 } |
432 } | 455 break; |
433 } | 456 } |
434 break; | 457 } |
435 default: { | 458 break; |
436 ; | 459 default: |
437 } | 460 { |
438 break; | 461 ; |
439 } | 462 } |
440 return (event.what != nullEvent); | 463 break; |
441 } | 464 } |
442 | 465 return (event.what != nullEvent); |
443 | 466 } |
444 void Mac_PumpEvents(_THIS) | 467 |
445 { | 468 |
446 /* Process pending MacOS events */ | 469 void |
447 while ( Mac_HandleEvents(this, 0) ) { | 470 Mac_PumpEvents(_THIS) |
448 /* Loop and check again */; | 471 { |
449 } | 472 /* Process pending MacOS events */ |
450 } | 473 while (Mac_HandleEvents(this, 0)) { |
451 | 474 /* Loop and check again */ ; |
452 void Mac_InitOSKeymap(_THIS) | 475 } |
453 { | 476 } |
454 const void *KCHRPtr; | 477 |
455 UInt32 state; | 478 void |
456 UInt32 value; | 479 Mac_InitOSKeymap(_THIS) |
457 int i; | 480 { |
458 int world = SDLK_WORLD_0; | 481 const void *KCHRPtr; |
459 | 482 UInt32 state; |
460 /* Map the MAC keysyms */ | 483 UInt32 value; |
461 for ( i=0; i<SDL_arraysize(MAC_keymap); ++i ) | 484 int i; |
462 MAC_keymap[i] = SDLK_UNKNOWN; | 485 int world = SDLK_WORLD_0; |
463 | 486 |
464 /* Defined MAC_* constants */ | 487 /* Map the MAC keysyms */ |
465 MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE; | 488 for (i = 0; i < SDL_arraysize(MAC_keymap); ++i) |
466 MAC_keymap[MK_F1] = SDLK_F1; | 489 MAC_keymap[i] = SDLK_UNKNOWN; |
467 MAC_keymap[MK_F2] = SDLK_F2; | 490 |
468 MAC_keymap[MK_F3] = SDLK_F3; | 491 /* Defined MAC_* constants */ |
469 MAC_keymap[MK_F4] = SDLK_F4; | 492 MAC_keymap[MK_ESCAPE] = SDLK_ESCAPE; |
470 MAC_keymap[MK_F5] = SDLK_F5; | 493 MAC_keymap[MK_F1] = SDLK_F1; |
471 MAC_keymap[MK_F6] = SDLK_F6; | 494 MAC_keymap[MK_F2] = SDLK_F2; |
472 MAC_keymap[MK_F7] = SDLK_F7; | 495 MAC_keymap[MK_F3] = SDLK_F3; |
473 MAC_keymap[MK_F8] = SDLK_F8; | 496 MAC_keymap[MK_F4] = SDLK_F4; |
474 MAC_keymap[MK_F9] = SDLK_F9; | 497 MAC_keymap[MK_F5] = SDLK_F5; |
475 MAC_keymap[MK_F10] = SDLK_F10; | 498 MAC_keymap[MK_F6] = SDLK_F6; |
476 MAC_keymap[MK_F11] = SDLK_F11; | 499 MAC_keymap[MK_F7] = SDLK_F7; |
477 MAC_keymap[MK_F12] = SDLK_F12; | 500 MAC_keymap[MK_F8] = SDLK_F8; |
478 MAC_keymap[MK_PRINT] = SDLK_PRINT; | 501 MAC_keymap[MK_F9] = SDLK_F9; |
479 MAC_keymap[MK_SCROLLOCK] = SDLK_SCROLLOCK; | 502 MAC_keymap[MK_F10] = SDLK_F10; |
480 MAC_keymap[MK_PAUSE] = SDLK_PAUSE; | 503 MAC_keymap[MK_F11] = SDLK_F11; |
481 MAC_keymap[MK_POWER] = SDLK_POWER; | 504 MAC_keymap[MK_F12] = SDLK_F12; |
482 MAC_keymap[MK_BACKQUOTE] = SDLK_BACKQUOTE; | 505 MAC_keymap[MK_PRINT] = SDLK_PRINT; |
483 MAC_keymap[MK_1] = SDLK_1; | 506 MAC_keymap[MK_SCROLLOCK] = SDLK_SCROLLOCK; |
484 MAC_keymap[MK_2] = SDLK_2; | 507 MAC_keymap[MK_PAUSE] = SDLK_PAUSE; |
485 MAC_keymap[MK_3] = SDLK_3; | 508 MAC_keymap[MK_POWER] = SDLK_POWER; |
486 MAC_keymap[MK_4] = SDLK_4; | 509 MAC_keymap[MK_BACKQUOTE] = SDLK_BACKQUOTE; |
487 MAC_keymap[MK_5] = SDLK_5; | 510 MAC_keymap[MK_1] = SDLK_1; |
488 MAC_keymap[MK_6] = SDLK_6; | 511 MAC_keymap[MK_2] = SDLK_2; |
489 MAC_keymap[MK_7] = SDLK_7; | 512 MAC_keymap[MK_3] = SDLK_3; |
490 MAC_keymap[MK_8] = SDLK_8; | 513 MAC_keymap[MK_4] = SDLK_4; |
491 MAC_keymap[MK_9] = SDLK_9; | 514 MAC_keymap[MK_5] = SDLK_5; |
492 MAC_keymap[MK_0] = SDLK_0; | 515 MAC_keymap[MK_6] = SDLK_6; |
493 MAC_keymap[MK_MINUS] = SDLK_MINUS; | 516 MAC_keymap[MK_7] = SDLK_7; |
494 MAC_keymap[MK_EQUALS] = SDLK_EQUALS; | 517 MAC_keymap[MK_8] = SDLK_8; |
495 MAC_keymap[MK_BACKSPACE] = SDLK_BACKSPACE; | 518 MAC_keymap[MK_9] = SDLK_9; |
496 MAC_keymap[MK_INSERT] = SDLK_INSERT; | 519 MAC_keymap[MK_0] = SDLK_0; |
497 MAC_keymap[MK_HOME] = SDLK_HOME; | 520 MAC_keymap[MK_MINUS] = SDLK_MINUS; |
498 MAC_keymap[MK_PAGEUP] = SDLK_PAGEUP; | 521 MAC_keymap[MK_EQUALS] = SDLK_EQUALS; |
499 MAC_keymap[MK_NUMLOCK] = SDLK_NUMLOCK; | 522 MAC_keymap[MK_BACKSPACE] = SDLK_BACKSPACE; |
500 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; | 523 MAC_keymap[MK_INSERT] = SDLK_INSERT; |
501 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; | 524 MAC_keymap[MK_HOME] = SDLK_HOME; |
502 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; | 525 MAC_keymap[MK_PAGEUP] = SDLK_PAGEUP; |
503 MAC_keymap[MK_TAB] = SDLK_TAB; | 526 MAC_keymap[MK_NUMLOCK] = SDLK_NUMLOCK; |
504 MAC_keymap[MK_q] = SDLK_q; | 527 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; |
505 MAC_keymap[MK_w] = SDLK_w; | 528 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; |
506 MAC_keymap[MK_e] = SDLK_e; | 529 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; |
507 MAC_keymap[MK_r] = SDLK_r; | 530 MAC_keymap[MK_TAB] = SDLK_TAB; |
508 MAC_keymap[MK_t] = SDLK_t; | 531 MAC_keymap[MK_q] = SDLK_q; |
509 MAC_keymap[MK_y] = SDLK_y; | 532 MAC_keymap[MK_w] = SDLK_w; |
510 MAC_keymap[MK_u] = SDLK_u; | 533 MAC_keymap[MK_e] = SDLK_e; |
511 MAC_keymap[MK_i] = SDLK_i; | 534 MAC_keymap[MK_r] = SDLK_r; |
512 MAC_keymap[MK_o] = SDLK_o; | 535 MAC_keymap[MK_t] = SDLK_t; |
513 MAC_keymap[MK_p] = SDLK_p; | 536 MAC_keymap[MK_y] = SDLK_y; |
514 MAC_keymap[MK_LEFTBRACKET] = SDLK_LEFTBRACKET; | 537 MAC_keymap[MK_u] = SDLK_u; |
515 MAC_keymap[MK_RIGHTBRACKET] = SDLK_RIGHTBRACKET; | 538 MAC_keymap[MK_i] = SDLK_i; |
516 MAC_keymap[MK_BACKSLASH] = SDLK_BACKSLASH; | 539 MAC_keymap[MK_o] = SDLK_o; |
517 MAC_keymap[MK_DELETE] = SDLK_DELETE; | 540 MAC_keymap[MK_p] = SDLK_p; |
518 MAC_keymap[MK_END] = SDLK_END; | 541 MAC_keymap[MK_LEFTBRACKET] = SDLK_LEFTBRACKET; |
519 MAC_keymap[MK_PAGEDOWN] = SDLK_PAGEDOWN; | 542 MAC_keymap[MK_RIGHTBRACKET] = SDLK_RIGHTBRACKET; |
520 MAC_keymap[MK_KP7] = SDLK_KP7; | 543 MAC_keymap[MK_BACKSLASH] = SDLK_BACKSLASH; |
521 MAC_keymap[MK_KP8] = SDLK_KP8; | 544 MAC_keymap[MK_DELETE] = SDLK_DELETE; |
522 MAC_keymap[MK_KP9] = SDLK_KP9; | 545 MAC_keymap[MK_END] = SDLK_END; |
523 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; | 546 MAC_keymap[MK_PAGEDOWN] = SDLK_PAGEDOWN; |
524 MAC_keymap[MK_CAPSLOCK] = SDLK_CAPSLOCK; | 547 MAC_keymap[MK_KP7] = SDLK_KP7; |
525 MAC_keymap[MK_a] = SDLK_a; | 548 MAC_keymap[MK_KP8] = SDLK_KP8; |
526 MAC_keymap[MK_s] = SDLK_s; | 549 MAC_keymap[MK_KP9] = SDLK_KP9; |
527 MAC_keymap[MK_d] = SDLK_d; | 550 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; |
528 MAC_keymap[MK_f] = SDLK_f; | 551 MAC_keymap[MK_CAPSLOCK] = SDLK_CAPSLOCK; |
529 MAC_keymap[MK_g] = SDLK_g; | 552 MAC_keymap[MK_a] = SDLK_a; |
530 MAC_keymap[MK_h] = SDLK_h; | 553 MAC_keymap[MK_s] = SDLK_s; |
531 MAC_keymap[MK_j] = SDLK_j; | 554 MAC_keymap[MK_d] = SDLK_d; |
532 MAC_keymap[MK_k] = SDLK_k; | 555 MAC_keymap[MK_f] = SDLK_f; |
533 MAC_keymap[MK_l] = SDLK_l; | 556 MAC_keymap[MK_g] = SDLK_g; |
534 MAC_keymap[MK_SEMICOLON] = SDLK_SEMICOLON; | 557 MAC_keymap[MK_h] = SDLK_h; |
535 MAC_keymap[MK_QUOTE] = SDLK_QUOTE; | 558 MAC_keymap[MK_j] = SDLK_j; |
536 MAC_keymap[MK_RETURN] = SDLK_RETURN; | 559 MAC_keymap[MK_k] = SDLK_k; |
537 MAC_keymap[MK_KP4] = SDLK_KP4; | 560 MAC_keymap[MK_l] = SDLK_l; |
538 MAC_keymap[MK_KP5] = SDLK_KP5; | 561 MAC_keymap[MK_SEMICOLON] = SDLK_SEMICOLON; |
539 MAC_keymap[MK_KP6] = SDLK_KP6; | 562 MAC_keymap[MK_QUOTE] = SDLK_QUOTE; |
540 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; | 563 MAC_keymap[MK_RETURN] = SDLK_RETURN; |
541 MAC_keymap[MK_LSHIFT] = SDLK_LSHIFT; | 564 MAC_keymap[MK_KP4] = SDLK_KP4; |
542 MAC_keymap[MK_z] = SDLK_z; | 565 MAC_keymap[MK_KP5] = SDLK_KP5; |
543 MAC_keymap[MK_x] = SDLK_x; | 566 MAC_keymap[MK_KP6] = SDLK_KP6; |
544 MAC_keymap[MK_c] = SDLK_c; | 567 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; |
545 MAC_keymap[MK_v] = SDLK_v; | 568 MAC_keymap[MK_LSHIFT] = SDLK_LSHIFT; |
546 MAC_keymap[MK_b] = SDLK_b; | 569 MAC_keymap[MK_z] = SDLK_z; |
547 MAC_keymap[MK_n] = SDLK_n; | 570 MAC_keymap[MK_x] = SDLK_x; |
548 MAC_keymap[MK_m] = SDLK_m; | 571 MAC_keymap[MK_c] = SDLK_c; |
549 MAC_keymap[MK_COMMA] = SDLK_COMMA; | 572 MAC_keymap[MK_v] = SDLK_v; |
550 MAC_keymap[MK_PERIOD] = SDLK_PERIOD; | 573 MAC_keymap[MK_b] = SDLK_b; |
551 MAC_keymap[MK_SLASH] = SDLK_SLASH; | 574 MAC_keymap[MK_n] = SDLK_n; |
552 #if 0 /* These are the same as the left versions - use left by default */ | 575 MAC_keymap[MK_m] = SDLK_m; |
553 MAC_keymap[MK_RSHIFT] = SDLK_RSHIFT; | 576 MAC_keymap[MK_COMMA] = SDLK_COMMA; |
554 #endif | 577 MAC_keymap[MK_PERIOD] = SDLK_PERIOD; |
555 MAC_keymap[MK_UP] = SDLK_UP; | 578 MAC_keymap[MK_SLASH] = SDLK_SLASH; |
556 MAC_keymap[MK_KP1] = SDLK_KP1; | 579 #if 0 /* These are the same as the left versions - use left by default */ |
557 MAC_keymap[MK_KP2] = SDLK_KP2; | 580 MAC_keymap[MK_RSHIFT] = SDLK_RSHIFT; |
558 MAC_keymap[MK_KP3] = SDLK_KP3; | 581 #endif |
559 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; | 582 MAC_keymap[MK_UP] = SDLK_UP; |
560 MAC_keymap[MK_LCTRL] = SDLK_LCTRL; | 583 MAC_keymap[MK_KP1] = SDLK_KP1; |
561 MAC_keymap[MK_LALT] = SDLK_LALT; | 584 MAC_keymap[MK_KP2] = SDLK_KP2; |
562 MAC_keymap[MK_LMETA] = SDLK_LMETA; | 585 MAC_keymap[MK_KP3] = SDLK_KP3; |
563 MAC_keymap[MK_SPACE] = SDLK_SPACE; | 586 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; |
564 #if 0 /* These are the same as the left versions - use left by default */ | 587 MAC_keymap[MK_LCTRL] = SDLK_LCTRL; |
565 MAC_keymap[MK_RMETA] = SDLK_RMETA; | 588 MAC_keymap[MK_LALT] = SDLK_LALT; |
566 MAC_keymap[MK_RALT] = SDLK_RALT; | 589 MAC_keymap[MK_LMETA] = SDLK_LMETA; |
567 MAC_keymap[MK_RCTRL] = SDLK_RCTRL; | 590 MAC_keymap[MK_SPACE] = SDLK_SPACE; |
568 #endif | 591 #if 0 /* These are the same as the left versions - use left by default */ |
569 MAC_keymap[MK_LEFT] = SDLK_LEFT; | 592 MAC_keymap[MK_RMETA] = SDLK_RMETA; |
570 MAC_keymap[MK_DOWN] = SDLK_DOWN; | 593 MAC_keymap[MK_RALT] = SDLK_RALT; |
571 MAC_keymap[MK_RIGHT] = SDLK_RIGHT; | 594 MAC_keymap[MK_RCTRL] = SDLK_RCTRL; |
572 MAC_keymap[MK_KP0] = SDLK_KP0; | 595 #endif |
573 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; | 596 MAC_keymap[MK_LEFT] = SDLK_LEFT; |
597 MAC_keymap[MK_DOWN] = SDLK_DOWN; | |
598 MAC_keymap[MK_RIGHT] = SDLK_RIGHT; | |
599 MAC_keymap[MK_KP0] = SDLK_KP0; | |
600 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; | |
574 | 601 |
575 #if defined(__APPLE__) && defined(__MACH__) | 602 #if defined(__APPLE__) && defined(__MACH__) |
576 /* Wierd, these keys are on my iBook under Mac OS X | 603 /* Wierd, these keys are on my iBook under Mac OS X |
577 Note that the left arrow keysym is the same as left ctrl!? | 604 Note that the left arrow keysym is the same as left ctrl!? |
578 */ | 605 */ |
579 MAC_keymap[MK_IBOOK_ENTER] = SDLK_KP_ENTER; | 606 MAC_keymap[MK_IBOOK_ENTER] = SDLK_KP_ENTER; |
580 MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT; | 607 MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT; |
581 MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN; | 608 MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN; |
582 MAC_keymap[MK_IBOOK_UP] = SDLK_UP; | 609 MAC_keymap[MK_IBOOK_UP] = SDLK_UP; |
583 MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT; | 610 MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT; |
584 #endif /* Mac OS X */ | 611 #endif /* Mac OS X */ |
585 | 612 |
586 /* Up there we setup a static scancode->keysym map. However, it will not | 613 /* 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 | 614 * 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 | 615 * 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 | 616 * bascially only useful for ascii char keys. This is also the reason |
590 * why we keep the static table, too. | 617 * why we keep the static table, too. |
591 */ | 618 */ |
592 | 619 |
593 /* Get a pointer to the systems cached KCHR */ | 620 /* Get a pointer to the systems cached KCHR */ |
594 KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache); | 621 KCHRPtr = (void *) GetScriptManagerVariable(smKCHRCache); |
595 if (KCHRPtr) | 622 if (KCHRPtr) { |
596 { | 623 /* Loop over all 127 possible scan codes */ |
597 /* Loop over all 127 possible scan codes */ | 624 for (i = 0; i < 0x7F; i++) { |
598 for (i = 0; i < 0x7F; i++) | 625 /* We pretend a clean start to begin with (i.e. no dead keys active */ |
599 { | 626 state = 0; |
600 /* We pretend a clean start to begin with (i.e. no dead keys active */ | 627 |
601 state = 0; | 628 /* Now translate the key code to a key value */ |
602 | 629 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; |
603 /* Now translate the key code to a key value */ | 630 |
604 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; | 631 /* If the state become 0, it was a dead key. We need to translate again, |
605 | 632 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, | 633 if (state != 0) |
607 passing in the new state, to get the actual key value */ | 634 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; |
608 if (state != 0) | 635 |
609 value = KeyTranslate(KCHRPtr, i, &state) & 0xff; | 636 /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */ |
610 | 637 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 */ | 638 MAC_keymap[i] = world++; |
612 if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */ | 639 else if (value >= 32) /* non-control ASCII char */ |
613 MAC_keymap[i] = world++; | 640 MAC_keymap[i] = value; |
614 else if (value >= 32) /* non-control ASCII char */ | 641 } |
615 MAC_keymap[i] = value; | 642 } |
616 } | 643 |
617 } | 644 /* The keypad codes are re-setup here, because the loop above cannot |
618 | 645 * 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 | 646 * 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 | 647 * include a "NSNumericPadKeyMask" bit; we could check that and modify |
621 * could get around this problem in another fashion: NSEvent's flags | 648 * the symbol we return on the fly. However, this flag seems to exhibit |
622 * include a "NSNumericPadKeyMask" bit; we could check that and modify | 649 * some weird behaviour related to the num lock key |
623 * the symbol we return on the fly. However, this flag seems to exhibit | 650 */ |
624 * some weird behaviour related to the num lock key | 651 MAC_keymap[MK_KP0] = SDLK_KP0; |
625 */ | 652 MAC_keymap[MK_KP1] = SDLK_KP1; |
626 MAC_keymap[MK_KP0] = SDLK_KP0; | 653 MAC_keymap[MK_KP2] = SDLK_KP2; |
627 MAC_keymap[MK_KP1] = SDLK_KP1; | 654 MAC_keymap[MK_KP3] = SDLK_KP3; |
628 MAC_keymap[MK_KP2] = SDLK_KP2; | 655 MAC_keymap[MK_KP4] = SDLK_KP4; |
629 MAC_keymap[MK_KP3] = SDLK_KP3; | 656 MAC_keymap[MK_KP5] = SDLK_KP5; |
630 MAC_keymap[MK_KP4] = SDLK_KP4; | 657 MAC_keymap[MK_KP6] = SDLK_KP6; |
631 MAC_keymap[MK_KP5] = SDLK_KP5; | 658 MAC_keymap[MK_KP7] = SDLK_KP7; |
632 MAC_keymap[MK_KP6] = SDLK_KP6; | 659 MAC_keymap[MK_KP8] = SDLK_KP8; |
633 MAC_keymap[MK_KP7] = SDLK_KP7; | 660 MAC_keymap[MK_KP9] = SDLK_KP9; |
634 MAC_keymap[MK_KP8] = SDLK_KP8; | 661 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; |
635 MAC_keymap[MK_KP9] = SDLK_KP9; | 662 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; |
636 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS; | 663 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; |
637 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS; | 664 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; |
638 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD; | 665 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; |
639 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS; | 666 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; |
640 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE; | 667 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; |
641 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY; | 668 } |
642 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER; | 669 |
643 } | 670 static SDL_keysym * |
644 | 671 TranslateKey(int scancode, int modifiers, SDL_keysym * keysym, int pressed) |
645 static SDL_keysym *TranslateKey(int scancode, int modifiers, | 672 { |
646 SDL_keysym *keysym, int pressed) | 673 /* Set the keysym information */ |
647 { | 674 keysym->scancode = scancode; |
648 /* Set the keysym information */ | 675 keysym->sym = MAC_keymap[keysym->scancode]; |
649 keysym->scancode = scancode; | 676 keysym->mod = KMOD_NONE; |
650 keysym->sym = MAC_keymap[keysym->scancode]; | 677 keysym->unicode = 0; |
651 keysym->mod = KMOD_NONE; | 678 if (pressed && SDL_TranslateUNICODE) { |
652 keysym->unicode = 0; | 679 static unsigned long state = 0; |
653 if ( pressed && SDL_TranslateUNICODE ) { | 680 static Ptr keymap = nil; |
654 static unsigned long state = 0; | 681 Ptr new_keymap; |
655 static Ptr keymap = nil; | 682 |
656 Ptr new_keymap; | 683 /* Get the current keyboard map resource */ |
657 | 684 new_keymap = (Ptr) GetScriptManagerVariable(smKCHRCache); |
658 /* Get the current keyboard map resource */ | 685 if (new_keymap != keymap) { |
659 new_keymap = (Ptr)GetScriptManagerVariable(smKCHRCache); | 686 keymap = new_keymap; |
660 if ( new_keymap != keymap ) { | 687 state = 0; |
661 keymap = new_keymap; | 688 } |
662 state = 0; | 689 keysym->unicode = KeyTranslate(keymap, |
663 } | 690 keysym->scancode | modifiers, |
664 keysym->unicode = KeyTranslate(keymap, | 691 &state) & 0xFFFF; |
665 keysym->scancode|modifiers, &state) & 0xFFFF; | 692 } |
666 } | 693 return (keysym); |
667 return(keysym); | 694 } |
668 } | 695 |
669 | 696 void |
670 void Mac_InitEvents(_THIS) | 697 Mac_InitEvents(_THIS) |
671 { | 698 { |
672 /* Create apple menu bar */ | 699 /* Create apple menu bar */ |
673 apple_menu = GetMenu(mApple); | 700 apple_menu = GetMenu(mApple); |
674 if ( apple_menu != nil ) { | 701 if (apple_menu != nil) { |
675 AppendResMenu(apple_menu, 'DRVR'); | 702 AppendResMenu(apple_menu, 'DRVR'); |
676 InsertMenu(apple_menu, 0); | 703 InsertMenu(apple_menu, 0); |
677 } | 704 } |
678 DrawMenuBar(); | 705 DrawMenuBar(); |
679 | 706 |
680 /* Get rid of spurious events at startup */ | 707 /* Get rid of spurious events at startup */ |
681 FlushEvents(everyEvent, 0); | 708 FlushEvents(everyEvent, 0); |
682 | 709 |
683 /* Allow every event but keyrepeat */ | 710 /* Allow every event but keyrepeat */ |
684 SetEventMask(everyEvent & ~autoKeyMask); | 711 SetEventMask(everyEvent & ~autoKeyMask); |
685 } | 712 } |
686 | 713 |
687 void Mac_QuitEvents(_THIS) | 714 void |
688 { | 715 Mac_QuitEvents(_THIS) |
689 ClearMenuBar(); | 716 { |
690 if ( apple_menu != nil ) { | 717 ClearMenuBar(); |
691 ReleaseResource((char **)apple_menu); | 718 if (apple_menu != nil) { |
692 } | 719 ReleaseResource((char **) apple_menu); |
693 | 720 } |
694 /* Clean up pending events */ | 721 |
695 FlushEvents(everyEvent, 0); | 722 /* Clean up pending events */ |
696 } | 723 FlushEvents(everyEvent, 0); |
697 | 724 } |
698 static void Mac_DoAppleMenu(_THIS, long choice) | 725 |
699 { | 726 static void |
700 #if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */ | 727 Mac_DoAppleMenu(_THIS, long choice) |
701 short menu, item; | 728 { |
702 | 729 #if !TARGET_API_MAC_CARBON /* No Apple menu in OS X */ |
703 item = (choice&0xFFFF); | 730 short menu, item; |
704 choice >>= 16; | 731 |
705 menu = (choice&0xFFFF); | 732 item = (choice & 0xFFFF); |
706 | 733 choice >>= 16; |
707 switch (menu) { | 734 menu = (choice & 0xFFFF); |
708 case mApple: { | 735 |
709 switch (item) { | 736 switch (menu) { |
710 case iAbout: { | 737 case mApple: |
711 /* Run the about box */; | 738 { |
712 } | 739 switch (item) { |
713 break; | 740 case iAbout: |
714 default: { | 741 { |
715 Str255 name; | 742 /* Run the about box */ ; |
716 | 743 } |
717 GetMenuItemText(apple_menu, item, name); | 744 break; |
718 OpenDeskAcc(name); | 745 default: |
719 } | 746 { |
720 break; | 747 Str255 name; |
721 } | 748 |
722 } | 749 GetMenuItemText(apple_menu, item, name); |
723 break; | 750 OpenDeskAcc(name); |
724 default: { | 751 } |
725 /* Ignore other menus */; | 752 break; |
726 } | 753 } |
727 } | 754 } |
755 break; | |
756 default: | |
757 { | |
758 /* Ignore other menus */ ; | |
759 } | |
760 } | |
728 #endif /* !TARGET_API_MAC_CARBON */ | 761 #endif /* !TARGET_API_MAC_CARBON */ |
729 } | 762 } |
730 | 763 |
731 #if !TARGET_API_MAC_CARBON | 764 #if !TARGET_API_MAC_CARBON |
732 /* Since we don't initialize QuickDraw, we need to get a pointer to qd */ | 765 /* Since we don't initialize QuickDraw, we need to get a pointer to qd */ |
733 QDGlobals *theQD = NULL; | 766 QDGlobals *theQD = NULL; |
734 #endif | 767 #endif |
735 | 768 |
736 /* Exported to the macmain code */ | 769 /* Exported to the macmain code */ |
737 void SDL_InitQuickDraw(struct QDGlobals *the_qd) | 770 void |
771 SDL_InitQuickDraw(struct QDGlobals *the_qd) | |
738 { | 772 { |
739 #if !TARGET_API_MAC_CARBON | 773 #if !TARGET_API_MAC_CARBON |
740 theQD = the_qd; | 774 theQD = the_qd; |
741 #endif | 775 #endif |
742 } | 776 } |
777 | |
778 /* vi: set ts=4 sw=4 expandtab: */ |