Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
778 lines (718 loc) · 24.5 KB

SDL_macevents.c

File metadata and controls

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