annotate src/video/cocoa/SDL_cocoakeyboard.m @ 4927:d716dff4b13e

Fixed touch events on Mac OS X 10.6
author Sam Lantinga <slouken@libsdl.org>
date Thu, 02 Dec 2010 11:56:23 -0800
parents 514f811a4887
children 25d4feb7c127
rev   line source
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
4498
3d91e31fcf71 I missed the Objective C files when updating the copyright date...
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_cocoavideo.h"
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include "../../events/SDL_keyboard_c.h"
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
27 #include "../../events/scancodes_darwin.h"
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
29 #include <Carbon/Carbon.h>
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
30
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
31 //#define DEBUG_IME NSLog
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
32 #define DEBUG_IME
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
33
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
34 #ifndef NX_DEVICERCTLKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
35 #define NX_DEVICELCTLKEYMASK 0x00000001
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
36 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
37 #ifndef NX_DEVICELSHIFTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
38 #define NX_DEVICELSHIFTKEYMASK 0x00000002
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
39 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
40 #ifndef NX_DEVICERSHIFTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
41 #define NX_DEVICERSHIFTKEYMASK 0x00000004
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
42 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
43 #ifndef NX_DEVICELCMDKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
44 #define NX_DEVICELCMDKEYMASK 0x00000008
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
45 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
46 #ifndef NX_DEVICERCMDKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
47 #define NX_DEVICERCMDKEYMASK 0x00000010
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
48 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
49 #ifndef NX_DEVICELALTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
50 #define NX_DEVICELALTKEYMASK 0x00000020
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
51 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
52 #ifndef NX_DEVICERALTKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
53 #define NX_DEVICERALTKEYMASK 0x00000040
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
54 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
55 #ifndef NX_DEVICERCTLKEYMASK
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
56 #define NX_DEVICERCTLKEYMASK 0x00002000
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
57 #endif
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
58
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
59 @interface SDLTranslatorResponder : NSView <NSTextInput>
2289
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
60 {
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
61 NSString *_markedText;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
62 NSRange _markedRange;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
63 NSRange _selectedRange;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
64 SDL_Rect _inputRect;
2289
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
65 }
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
66 - (void) doCommandBySelector:(SEL)myselector;
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
67 - (void) setInputRect:(SDL_Rect *) rect;
2289
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
68 @end
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
69
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
70 @implementation SDLTranslatorResponder
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
71
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
72 - (void) setInputRect:(SDL_Rect *) rect
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
73 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
74 _inputRect = *rect;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
75 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
76
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
77 - (void) insertText:(id) aString
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
78 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
79 const char *str;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
80
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
81 DEBUG_IME(@"insertText: %@", aString);
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
82
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
83 /* Could be NSString or NSAttributedString, so we have
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
84 * to test and convert it before return as SDL event */
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
85 if ([aString isKindOfClass: [NSAttributedString class]])
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
86 str = [[aString string] UTF8String];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
87 else
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
88 str = [aString UTF8String];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
89
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
90 SDL_SendKeyboardText(str);
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
91 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
92
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
93 - (void) doCommandBySelector:(SEL) myselector
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
94 {
3683
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
95 // No need to do anything since we are not using Cocoa
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
96 // selectors to handle special keys, instead we use SDL
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
97 // key events to do the same job.
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
98 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
99
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
100 - (BOOL) hasMarkedText
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
101 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
102 return _markedText != nil;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
103 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
104
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
105 - (NSRange) markedRange
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
106 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
107 return _markedRange;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
108 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
109
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
110 - (NSRange) selectedRange
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
111 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
112 return _selectedRange;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
113 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
114
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
115 - (void) setMarkedText:(id) aString
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
116 selectedRange:(NSRange) selRange
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
117 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
118 if ([aString isKindOfClass: [NSAttributedString class]])
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
119 aString = [aString string];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
120
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
121 if ([aString length] == 0)
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
122 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
123 [self unmarkText];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
124 return;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
125 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
126
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
127 if (_markedText != aString)
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
128 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
129 [_markedText release];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
130 _markedText = [aString retain];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
131 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
132
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
133 _selectedRange = selRange;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
134 _markedRange = NSMakeRange(0, [aString length]);
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
135
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
136 SDL_SendEditingText([aString UTF8String],
4434
5c64052fb476 changeset: 4433:25667ea797fa
Sam Lantinga <slouken@libsdl.org>
parents: 3683
diff changeset
137 selRange.location, selRange.length);
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
138
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
139 DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText,
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
140 selRange.location, selRange.length);
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
141 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
142
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
143 - (void) unmarkText
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
144 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
145 [_markedText release];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
146 _markedText = nil;
4637
8c229370ddba Fix for deleting the last uncommit character
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4565
diff changeset
147
8c229370ddba Fix for deleting the last uncommit character
Jjgod Jiang <gzjjgod@gmail.com>
parents: 4565
diff changeset
148 SDL_SendEditingText("", 0, 0);
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
149 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
150
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
151 - (NSRect) firstRectForCharacterRange: (NSRange) theRange
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
152 {
4436
d3c193100522 changeset: 4434:4e5dd7dc58cd
Sam Lantinga <slouken@libsdl.org>
parents: 4435
diff changeset
153 NSWindow *window = [self window];
d3c193100522 changeset: 4434:4e5dd7dc58cd
Sam Lantinga <slouken@libsdl.org>
parents: 4435
diff changeset
154 NSRect contentRect = [window contentRectForFrameRect: [window frame]];
d3c193100522 changeset: 4434:4e5dd7dc58cd
Sam Lantinga <slouken@libsdl.org>
parents: 4435
diff changeset
155 float windowHeight = contentRect.size.height;
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
156 NSRect rect = NSMakeRect(_inputRect.x, windowHeight - _inputRect.y - _inputRect.h,
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
157 _inputRect.w, _inputRect.h);
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
158
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
159 DEBUG_IME(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
160 theRange.location, theRange.length, windowHeight,
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
161 NSStringFromRect(rect));
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
162 rect.origin = [[self window] convertBaseToScreen: rect.origin];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
163
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
164 return rect;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
165 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
166
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
167 - (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
168 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
169 DEBUG_IME(@"attributedSubstringFromRange: (%d, %d)", theRange.location, theRange.length);
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
170 return nil;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
171 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
172
3525
455a6c47d2c6 Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents: 3286
diff changeset
173 /* Needs long instead of NSInteger for compilation on Mac OS X 10.4 */
4925
514f811a4887 Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 4694
diff changeset
174 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
3525
455a6c47d2c6 Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents: 3286
diff changeset
175 - (long) conversationIdentifier
4925
514f811a4887 Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 4694
diff changeset
176 #else
514f811a4887 Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 4694
diff changeset
177 - (NSInteger) conversationIdentifier
514f811a4887 Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 4694
diff changeset
178 #endif
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
179 {
3525
455a6c47d2c6 Fixed compilation on Mac OS X 10.4
Sam Lantinga <slouken@libsdl.org>
parents: 3286
diff changeset
180 return (long) self;
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
181 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
182
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
183 // This method returns the index for character that is
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
184 // nearest to thePoint. thPoint is in screen coordinate system.
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
185 - (NSUInteger) characterIndexForPoint:(NSPoint) thePoint
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
186 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
187 DEBUG_IME(@"characterIndexForPoint: (%g, %g)", thePoint.x, thePoint.y);
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
188 return 0;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
189 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
190
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
191 // This method is the key to attribute extension.
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
192 // We could add new attributes through this method.
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
193 // NSInputServer examines the return value of this
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
194 // method & constructs appropriate attributed string.
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
195 - (NSArray *) validAttributesForMarkedText
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
196 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
197 return [NSArray array];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
198 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
199
2289
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
200 @end
f629d566ec6b Merged fix for bug #508 from SDL 1.2 revision 3495
Sam Lantinga <slouken@libsdl.org>
parents: 2273
diff changeset
201
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
202 /* This is the original behavior, before support was added for
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
203 * differentiating between left and right versions of the keys.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
204 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
205 static void
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
206 DoUnsidedModifiers(unsigned short scancode,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
207 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
208 {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
209 const int mapping[] = {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
210 SDL_SCANCODE_CAPSLOCK,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
211 SDL_SCANCODE_LSHIFT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
212 SDL_SCANCODE_LCTRL,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
213 SDL_SCANCODE_LALT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
214 SDL_SCANCODE_LGUI
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
215 };
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
216 unsigned int i, bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
217
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
218 /* Iterate through the bits, testing each against the current modifiers */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
219 for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
220 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
221
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
222 oldMask = oldMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
223 newMask = newMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
224
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
225 if (oldMask && oldMask != newMask) { /* modifier up event */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
226 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
227 if (bit == NSAlphaShiftKeyMask) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
228 SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
229 }
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
230 SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
231 } else if (newMask && oldMask != newMask) { /* modifier down event */
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
232 SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
233 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
234 if (bit == NSAlphaShiftKeyMask) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
235 SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
236 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
237 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
238 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
239 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
240
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
241 /* This is a helper function for HandleModifierSide. This
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
242 * function reverts back to behavior before the distinction between
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
243 * sides was made.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
244 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
245 static void
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
246 HandleNonDeviceModifier(unsigned int device_independent_mask,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
247 unsigned int oldMods,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
248 unsigned int newMods,
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
249 SDL_scancode scancode)
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
250 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
251 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
252
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
253 /* Isolate just the bits we care about in the depedent bits so we can
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
254 * figure out what changed
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
255 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
256 oldMask = oldMods & device_independent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
257 newMask = newMods & device_independent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
258
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
259 if (oldMask && oldMask != newMask) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
260 SDL_SendKeyboardKey(SDL_RELEASED, scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
261 } else if (newMask && oldMask != newMask) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
262 SDL_SendKeyboardKey(SDL_PRESSED, scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
263 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
264 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
265
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
266 /* This is a helper function for HandleModifierSide.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
267 * This function sets the actual SDL_PrivateKeyboard event.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
268 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
269 static void
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
270 HandleModifierOneSide(unsigned int oldMods, unsigned int newMods,
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
271 SDL_scancode scancode,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
272 unsigned int sided_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
273 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
274 unsigned int old_dep_mask, new_dep_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
275
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
276 /* Isolate just the bits we care about in the depedent bits so we can
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
277 * figure out what changed
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
278 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
279 old_dep_mask = oldMods & sided_device_dependent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
280 new_dep_mask = newMods & sided_device_dependent_mask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
281
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
282 /* We now know that this side bit flipped. But we don't know if
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
283 * it went pressed to released or released to pressed, so we must
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
284 * find out which it is.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
285 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
286 if (new_dep_mask && old_dep_mask != new_dep_mask) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
287 SDL_SendKeyboardKey(SDL_PRESSED, scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
288 } else {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
289 SDL_SendKeyboardKey(SDL_RELEASED, scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
290 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
291 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
292
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
293 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
294 * This function will figure out if the modifier key is the left or right side,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
295 * e.g. left-shift vs right-shift.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
296 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
297 static void
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
298 HandleModifierSide(int device_independent_mask,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
299 unsigned int oldMods, unsigned int newMods,
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
300 SDL_scancode left_scancode,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
301 SDL_scancode right_scancode,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
302 unsigned int left_device_dependent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
303 unsigned int right_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
304 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
305 unsigned int device_dependent_mask = (left_device_dependent_mask |
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
306 right_device_dependent_mask);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
307 unsigned int diff_mod;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
308
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
309 /* On the basis that the device independent mask is set, but there are
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
310 * no device dependent flags set, we'll assume that we can't detect this
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
311 * keyboard and revert to the unsided behavior.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
312 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
313 if ((device_dependent_mask & newMods) == 0) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
314 /* Revert to the old behavior */
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
315 HandleNonDeviceModifier(device_independent_mask, oldMods, newMods, left_scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
316 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
317 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
318
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
319 /* XOR the previous state against the new state to see if there's a change */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
320 diff_mod = (device_dependent_mask & oldMods) ^
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
321 (device_dependent_mask & newMods);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
322 if (diff_mod) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
323 /* A change in state was found. Isolate the left and right bits
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
324 * to handle them separately just in case the values can simulataneously
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
325 * change or if the bits don't both exist.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
326 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
327 if (left_device_dependent_mask & diff_mod) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
328 HandleModifierOneSide(oldMods, newMods, left_scancode, left_device_dependent_mask);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
329 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
330 if (right_device_dependent_mask & diff_mod) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
331 HandleModifierOneSide(oldMods, newMods, right_scancode, right_device_dependent_mask);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
332 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
333 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
334 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
335
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
336 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
337 * This function will release a key press in the case that
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
338 * it is clear that the modifier has been released (i.e. one side
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
339 * can't still be down).
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
340 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
341 static void
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
342 ReleaseModifierSide(unsigned int device_independent_mask,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
343 unsigned int oldMods, unsigned int newMods,
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
344 SDL_scancode left_scancode,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
345 SDL_scancode right_scancode,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
346 unsigned int left_device_dependent_mask,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
347 unsigned int right_device_dependent_mask)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
348 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
349 unsigned int device_dependent_mask = (left_device_dependent_mask |
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
350 right_device_dependent_mask);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
351
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
352 /* On the basis that the device independent mask is set, but there are
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
353 * no device dependent flags set, we'll assume that we can't detect this
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
354 * keyboard and revert to the unsided behavior.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
355 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
356 if ((device_dependent_mask & oldMods) == 0) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
357 /* In this case, we can't detect the keyboard, so use the left side
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
358 * to represent both, and release it.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
359 */
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
360 SDL_SendKeyboardKey(SDL_RELEASED, left_scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
361 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
362 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
363
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
364 /*
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
365 * This could have been done in an if-else case because at this point,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
366 * we know that all keys have been released when calling this function.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
367 * But I'm being paranoid so I want to handle each separately,
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
368 * so I hope this doesn't cause other problems.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
369 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
370 if ( left_device_dependent_mask & oldMods ) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
371 SDL_SendKeyboardKey(SDL_RELEASED, left_scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
372 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
373 if ( right_device_dependent_mask & oldMods ) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
374 SDL_SendKeyboardKey(SDL_RELEASED, right_scancode);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
375 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
376 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
377
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
378 /* This is a helper function for DoSidedModifiers.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
379 * This function handles the CapsLock case.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
380 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
381 static void
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
382 HandleCapsLock(unsigned short scancode,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
383 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
384 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
385 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
386
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
387 oldMask = oldMods & NSAlphaShiftKeyMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
388 newMask = newMods & NSAlphaShiftKeyMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
389
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
390 if (oldMask != newMask) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
391 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
392 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
393 }
1960
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
394
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
395 oldMask = oldMods & NSNumericPadKeyMask;
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
396 newMask = newMods & NSNumericPadKeyMask;
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
397
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
398 if (oldMask != newMask) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
399 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR);
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
400 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR);
1960
118daa3a24cc Added numlock support
Sam Lantinga <slouken@libsdl.org>
parents: 1959
diff changeset
401 }
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
402 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
403
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
404 /* This function will handle the modifier keys and also determine the
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
405 * correct side of the key.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
406 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
407 static void
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
408 DoSidedModifiers(unsigned short scancode,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
409 unsigned int oldMods, unsigned int newMods)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
410 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
411 /* Set up arrays for the key syms for the left and right side. */
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
412 const SDL_scancode left_mapping[] = {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
413 SDL_SCANCODE_LSHIFT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
414 SDL_SCANCODE_LCTRL,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
415 SDL_SCANCODE_LALT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
416 SDL_SCANCODE_LGUI
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
417 };
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
418 const SDL_scancode right_mapping[] = {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
419 SDL_SCANCODE_RSHIFT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
420 SDL_SCANCODE_RCTRL,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
421 SDL_SCANCODE_RALT,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
422 SDL_SCANCODE_RGUI
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
423 };
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
424 /* Set up arrays for the device dependent masks with indices that
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
425 * correspond to the _mapping arrays
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
426 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
427 const unsigned int left_device_mapping[] = { NX_DEVICELSHIFTKEYMASK, NX_DEVICELCTLKEYMASK, NX_DEVICELALTKEYMASK, NX_DEVICELCMDKEYMASK };
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
428 const unsigned int right_device_mapping[] = { NX_DEVICERSHIFTKEYMASK, NX_DEVICERCTLKEYMASK, NX_DEVICERALTKEYMASK, NX_DEVICERCMDKEYMASK };
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
429
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
430 unsigned int i, bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
431
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
432 /* Handle CAPSLOCK separately because it doesn't have a left/right side */
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
433 HandleCapsLock(scancode, oldMods, newMods);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
434
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
435 /* Iterate through the bits, testing each against the old modifiers */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
436 for (i = 0, bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
437 unsigned int oldMask, newMask;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
438
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
439 oldMask = oldMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
440 newMask = newMods & bit;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
441
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
442 /* If the bit is set, we must always examine it because the left
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
443 * and right side keys may alternate or both may be pressed.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
444 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
445 if (newMask) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
446 HandleModifierSide(bit, oldMods, newMods,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
447 left_mapping[i], right_mapping[i],
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
448 left_device_mapping[i], right_device_mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
449 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
450 /* If the state changed from pressed to unpressed, we must examine
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
451 * the device dependent bits to release the correct keys.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
452 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
453 else if (oldMask && oldMask != newMask) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
454 ReleaseModifierSide(bit, oldMods, newMods,
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
455 left_mapping[i], right_mapping[i],
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
456 left_device_mapping[i], right_device_mapping[i]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
457 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
458 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
459 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
460
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
461 static void
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
462 HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
463 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
464 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
465
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
466 if (modifierFlags == data->modifierFlags) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
467 return;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
468 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
469
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
470 /*
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
471 * Starting with Panther (10.3.0), the ability to distinguish between
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
472 * left side and right side modifiers is available.
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
473 */
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
474 if (data->osversion >= 0x1030) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
475 DoSidedModifiers(scancode, data->modifierFlags, modifierFlags);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
476 } else {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
477 DoUnsidedModifiers(scancode, data->modifierFlags, modifierFlags);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
478 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
479 data->modifierFlags = modifierFlags;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
480 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
481
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
482 static void
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
483 UpdateKeymap(SDL_VideoData *data)
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
484 {
4925
514f811a4887 Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 4694
diff changeset
485 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
3247
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
486 TISInputSourceRef key_layout;
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
487 #else
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
488 KeyboardLayoutRef key_layout;
3247
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
489 #endif
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
490 const void *chr_data;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
491 int i;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
492 SDL_scancode scancode;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
493 SDLKey keymap[SDL_NUM_SCANCODES];
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
494
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
495 /* See if the keymap needs to be updated */
4925
514f811a4887 Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 4694
diff changeset
496 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
3247
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
497 key_layout = TISCopyCurrentKeyboardLayoutInputSource();
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
498 #else
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
499 KLGetCurrentKeyboardLayout(&key_layout);
3247
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
500 #endif
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
501 if (key_layout == data->key_layout) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
502 return;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
503 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
504 data->key_layout = key_layout;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
505
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
506 SDL_GetDefaultKeymap(keymap);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
507
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
508 /* Try Unicode data first (preferred as of Mac OS X 10.5) */
4925
514f811a4887 Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 4694
diff changeset
509 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
3247
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
510 CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
511 if (uchrDataRef)
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
512 chr_data = CFDataGetBytePtr(uchrDataRef);
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
513 else
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
514 goto cleanup;
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
515 #else
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
516 KLGetKeyboardLayoutProperty(key_layout, kKLuchrData, &chr_data);
3247
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
517 #endif
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
518 if (chr_data) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
519 UInt32 keyboard_type = LMGetKbdType();
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
520 OSStatus err;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
521
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
522 for (i = 0; i < SDL_arraysize(darwin_scancode_table); i++) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
523 UniChar s[8];
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
524 UniCharCount len;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
525 UInt32 dead_key_state;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
526
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
527 /* Make sure this scancode is a valid character scancode */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
528 scancode = darwin_scancode_table[i];
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
529 if (scancode == SDL_SCANCODE_UNKNOWN ||
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
530 (keymap[scancode] & SDLK_SCANCODE_MASK)) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
531 continue;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
532 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
533
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
534 dead_key_state = 0;
3247
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
535 err = UCKeyTranslate ((UCKeyboardLayout *) chr_data,
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
536 i, kUCKeyActionDown,
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
537 0, keyboard_type,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
538 kUCKeyTranslateNoDeadKeysMask,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
539 &dead_key_state, 8, &len, s);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
540 if (err != noErr)
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
541 continue;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
542
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
543 if (len > 0 && s[0] != 0x10) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
544 keymap[scancode] = s[0];
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
545 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
546 }
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
547 SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
548 return;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
549 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
550
4925
514f811a4887 Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents: 4694
diff changeset
551 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
3247
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
552 cleanup:
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
553 CFRelease(key_layout);
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
554 #else
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
555 /* Fall back to older style key map data */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
556 KLGetKeyboardLayoutProperty(key_layout, kKLKCHRData, &chr_data);
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
557 if (chr_data) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
558 for (i = 0; i < 128; i++) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
559 UInt32 c, state = 0;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
560
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
561 /* Make sure this scancode is a valid character scancode */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
562 scancode = darwin_scancode_table[i];
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
563 if (scancode == SDL_SCANCODE_UNKNOWN ||
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
564 (keymap[scancode] & SDLK_SCANCODE_MASK)) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
565 continue;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
566 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
567
2304
50f58ce12497 Christian's comment:
Sam Lantinga <slouken@libsdl.org>
parents: 2303
diff changeset
568 c = KeyTranslate (chr_data, i, &state) & 255;
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
569 if (state) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
570 /* Dead key, process key up */
2304
50f58ce12497 Christian's comment:
Sam Lantinga <slouken@libsdl.org>
parents: 2303
diff changeset
571 c = KeyTranslate (chr_data, i | 128, &state) & 255;
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
572 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
573
2304
50f58ce12497 Christian's comment:
Sam Lantinga <slouken@libsdl.org>
parents: 2303
diff changeset
574 if (c != 0 && c != 0x10) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
575 /* MacRoman to Unicode table, taken from X.org sources */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
576 static const unsigned short macroman_table[128] = {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
577 0xc4, 0xc5, 0xc7, 0xc9, 0xd1, 0xd6, 0xdc, 0xe1,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
578 0xe0, 0xe2, 0xe4, 0xe3, 0xe5, 0xe7, 0xe9, 0xe8,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
579 0xea, 0xeb, 0xed, 0xec, 0xee, 0xef, 0xf1, 0xf3,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
580 0xf2, 0xf4, 0xf6, 0xf5, 0xfa, 0xf9, 0xfb, 0xfc,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
581 0x2020, 0xb0, 0xa2, 0xa3, 0xa7, 0x2022, 0xb6, 0xdf,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
582 0xae, 0xa9, 0x2122, 0xb4, 0xa8, 0x2260, 0xc6, 0xd8,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
583 0x221e, 0xb1, 0x2264, 0x2265, 0xa5, 0xb5, 0x2202, 0x2211,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
584 0x220f, 0x3c0, 0x222b, 0xaa, 0xba, 0x3a9, 0xe6, 0xf8,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
585 0xbf, 0xa1, 0xac, 0x221a, 0x192, 0x2248, 0x2206, 0xab,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
586 0xbb, 0x2026, 0xa0, 0xc0, 0xc3, 0xd5, 0x152, 0x153,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
587 0x2013, 0x2014, 0x201c, 0x201d, 0x2018, 0x2019, 0xf7, 0x25ca,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
588 0xff, 0x178, 0x2044, 0x20ac, 0x2039, 0x203a, 0xfb01, 0xfb02,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
589 0x2021, 0xb7, 0x201a, 0x201e, 0x2030, 0xc2, 0xca, 0xc1,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
590 0xcb, 0xc8, 0xcd, 0xce, 0xcf, 0xcc, 0xd3, 0xd4,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
591 0xf8ff, 0xd2, 0xda, 0xdb, 0xd9, 0x131, 0x2c6, 0x2dc,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
592 0xaf, 0x2d8, 0x2d9, 0x2da, 0xb8, 0x2dd, 0x2db, 0x2c7,
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
593 };
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
594
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
595 if (c >= 128) {
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
596 c = macroman_table[c - 128];
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
597 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
598 keymap[scancode] = c;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
599 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
600 }
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
601 SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
602 return;
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
603 }
3247
2dcfb4e07a57 From: Jjgod Jiang <gzjjgod@gmail.com>
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
604 #endif
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
605 }
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
606
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 void
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 Cocoa_InitKeyboard(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
612 UpdateKeymap(data);
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
613
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
614 /* Set our own names for the platform-dependent but layout-independent keys */
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
615 /* This key is NumLock on the MacBook keyboard. :) */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
616 /*SDL_SetScancodeName(SDL_SCANCODE_NUMLOCKCLEAR, "Clear");*/
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
617 SDL_SetScancodeName(SDL_SCANCODE_LALT, "Left Option");
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
618 SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Command");
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
619 SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option");
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
620 SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 void
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
624 Cocoa_StartTextInput(_THIS)
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
625 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
626 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
627 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
628 NSView *parentView = [[NSApp keyWindow] contentView];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
629
4434
5c64052fb476 changeset: 4433:25667ea797fa
Sam Lantinga <slouken@libsdl.org>
parents: 3683
diff changeset
630 /* We only keep one field editor per process, since only the front most
5c64052fb476 changeset: 4433:25667ea797fa
Sam Lantinga <slouken@libsdl.org>
parents: 3683
diff changeset
631 * window can receive text input events, so it make no sense to keep more
5c64052fb476 changeset: 4433:25667ea797fa
Sam Lantinga <slouken@libsdl.org>
parents: 3683
diff changeset
632 * than one copy. When we switched to another window and requesting for
5c64052fb476 changeset: 4433:25667ea797fa
Sam Lantinga <slouken@libsdl.org>
parents: 3683
diff changeset
633 * text input, simply remove the field editor from its superview then add
5c64052fb476 changeset: 4433:25667ea797fa
Sam Lantinga <slouken@libsdl.org>
parents: 3683
diff changeset
634 * it to the front most window's content view */
4435
e953700da4ca Minor cleanup on Jiang's patch
Sam Lantinga <slouken@libsdl.org>
parents: 4434
diff changeset
635 if (!data->fieldEdit) {
4434
5c64052fb476 changeset: 4433:25667ea797fa
Sam Lantinga <slouken@libsdl.org>
parents: 3683
diff changeset
636 data->fieldEdit =
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4671
diff changeset
637 [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
4435
e953700da4ca Minor cleanup on Jiang's patch
Sam Lantinga <slouken@libsdl.org>
parents: 4434
diff changeset
638 }
4434
5c64052fb476 changeset: 4433:25667ea797fa
Sam Lantinga <slouken@libsdl.org>
parents: 3683
diff changeset
639
4435
e953700da4ca Minor cleanup on Jiang's patch
Sam Lantinga <slouken@libsdl.org>
parents: 4434
diff changeset
640 if (![[data->fieldEdit superview] isEqual: parentView])
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
641 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
642 // DEBUG_IME(@"add fieldEdit to window contentView");
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4671
diff changeset
643 [data->fieldEdit removeFromSuperview];
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
644 [parentView addSubview: data->fieldEdit];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
645 [[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
646 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
647
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
648 [pool release];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
649 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
650
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
651 void
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
652 Cocoa_StopTextInput(_THIS)
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
653 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
654 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
655
3683
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
656 if (data && data->fieldEdit) {
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
657 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
658 [data->fieldEdit removeFromSuperview];
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
659 [data->fieldEdit release];
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
660 data->fieldEdit = nil;
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
661 [pool release];
4c5ab6841fdc From: Jjgod Jiang
Sam Lantinga <slouken@libsdl.org>
parents: 3676
diff changeset
662 }
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
663 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
664
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
665 void
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
666 Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
667 {
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
668 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
669
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
670 [data->fieldEdit setInputRect: rect];
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
671 }
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
672
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
673 void
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
674 Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
675 {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
676 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
677 unsigned short scancode = [event keyCode];
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
678 SDL_scancode code;
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
679 #if 0
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
680 const char *text;
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
681 #endif
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
682
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
683 if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
684 /* see comments in SDL_cocoakeys.h */
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
685 scancode = 60 - scancode;
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
686 }
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
687 if (scancode < SDL_arraysize(darwin_scancode_table)) {
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2304
diff changeset
688 code = darwin_scancode_table[scancode];
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
689 }
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
690 else {
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
691 /* Hmm, does this ever happen? If so, need to extend the keymap... */
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
692 code = SDL_SCANCODE_UNKNOWN;
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
693 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
694
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
695 switch ([event type]) {
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
696 case NSKeyDown:
2129
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
697 if (![event isARepeat]) {
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
698 /* See if we need to rebuild the keyboard layout */
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
699 UpdateKeymap(data);
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4671
diff changeset
700 }
2303
d87417504c75 First pass implementation of new SDL scancode concept, as discussed with
Sam Lantinga <slouken@libsdl.org>
parents: 2289
diff changeset
701
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4671
diff changeset
702 SDL_SendKeyboardKey(SDL_PRESSED, code);
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
703 #if 1
4673
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4671
diff changeset
704 if (code == SDL_SCANCODE_UNKNOWN) {
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4671
diff changeset
705 fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode);
c17ac64abb70 Fixed the code so we receive Cocoa touch events
Sam Lantinga <slouken@libsdl.org>
parents: 4671
diff changeset
706 }
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
707 #endif
2129
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
708 if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
709 /* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */
2169
13cf2d5eda86 Added key composition support, courtesy of Kuon
Sam Lantinga <slouken@libsdl.org>
parents: 2129
diff changeset
710 [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
711 #if 0
2129
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
712 text = [[event characters] UTF8String];
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
713 if(text && *text) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
714 SDL_SendKeyboardText(text);
2273
a25bc0f79557 Fixed bug #471
Sam Lantinga <slouken@libsdl.org>
parents: 2270
diff changeset
715 [data->fieldEdit setString:@""];
2129
047245361002 Key repeat is handled by the OS, since text input is now decoupled from physical key events.
Sam Lantinga <slouken@libsdl.org>
parents: 2090
diff changeset
716 }
3280
00cace2d9080 Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents: 3247
diff changeset
717 #endif
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
718 }
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
719 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
720 case NSKeyUp:
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4436
diff changeset
721 SDL_SendKeyboardKey(SDL_RELEASED, code);
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
722 break;
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
723 case NSFlagsChanged:
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
724 /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
725 HandleModifiers(_this, scancode, [event modifierFlags]);
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
726 break;
2268
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
727 default: /* just to avoid compiler warnings */
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
728 break;
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
729 }
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
730 }
4baee598306d Date: Thu, 05 Jul 2007 14:02:33 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 2170
diff changeset
731
1959
25d6537feea4 Implemented Cocoa key event handling.
Sam Lantinga <slouken@libsdl.org>
parents: 1931
diff changeset
732 void
1931
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
733 Cocoa_QuitKeyboard(_THIS)
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
734 {
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
735 }
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
736
103c6fec2a60 The Mac OS X Cocoa video driver is under construction...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
737 /* vi: set ts=4 sw=4 expandtab: */