comparison src/video/cocoa/SDL_cocoakeyboard.m @ 3129:e42873b9c6f1 gsoc2009_IME

Basic marked text handling
author Jiang Jiang <gzjjgod@gmail.com>
date Sun, 31 May 2009 16:57:29 +0000
parents da6cbfa5b5f2
children fef1a835af43
comparison
equal deleted inserted replaced
3128:05d83835f41b 3129:e42873b9c6f1
54 #define NX_DEVICERCTLKEYMASK 0x00002000 54 #define NX_DEVICERCTLKEYMASK 0x00002000
55 #endif 55 #endif
56 56
57 @interface SDLTranslatorResponder : NSTextView 57 @interface SDLTranslatorResponder : NSTextView
58 { 58 {
59 NSString *_markedText;
60 NSRange _markedRange;
61 NSRange _selectedRange;
59 } 62 }
60 - (void) doCommandBySelector:(SEL)myselector; 63 - (void) doCommandBySelector:(SEL)myselector;
61 @end 64 @end
62 65
63 @implementation SDLTranslatorResponder 66 @implementation SDLTranslatorResponder
66 { 69 {
67 const char *str; 70 const char *str;
68 71
69 NSLog(@"insertText: %@", aString); 72 NSLog(@"insertText: %@", aString);
70 73
74 /* Could be NSString or NSAttributedString, so we have
75 * to test and convert it before return as SDL event */
71 if ([aString isKindOfClass: [NSAttributedString class]]) 76 if ([aString isKindOfClass: [NSAttributedString class]])
72 str = [[aString string] UTF8String]; 77 str = [[aString string] UTF8String];
73 else 78 else
74 str = [aString UTF8String]; 79 str = [aString UTF8String];
75 80
79 - (void) doCommandBySelector:(SEL) myselector 84 - (void) doCommandBySelector:(SEL) myselector
80 { 85 {
81 NSLog(@"doCommandBySelector, passed down"); 86 NSLog(@"doCommandBySelector, passed down");
82 [super doCommandBySelector: myselector]; 87 [super doCommandBySelector: myselector];
83 } 88 }
89
90 - (BOOL) hasMarkedText
91 {
92 return _markedText != nil;
93 }
94
95 - (NSRange) markedRange
96 {
97 return _markedRange;
98 }
99
100 - (NSRange) selectedRange
101 {
102 return _selectedRange;
103 }
104
105 - (void) setMarkedText:(id) aString
106 selectedRange:(NSRange) selRange
107 {
108 if ([aString isKindOfClass: [NSAttributedString class]])
109 aString = [aString string];
110
111 if ([aString length] == 0)
112 {
113 [self unmarkText];
114 return;
115 }
116
117 if (_markedText != aString)
118 {
119 [_markedText release];
120 _markedText = [aString retain];
121 }
122
123 _selectedRange = selRange;
124 _markedRange = NSMakeRange(0, [aString length]);
125
126 NSLog(@"setMarkedText: %@, (%d, %d)", _markedText,
127 selRange.location, selRange.length);
128 }
129
130 - (void) unmarkText
131 {
132 [_markedText release];
133 _markedText = nil;
134 }
135
136 - (NSRect) firstRectForCharacterRange: (NSRange) theRange
137 {
138 return NSMakeRect(0, 0, 0, 0);
139 }
140
141 - (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange
142 {
143 return nil;
144 }
145
146 - (NSInteger) conversationIdentifier
147 {
148 return (NSInteger) self;
149 }
150
151 // This method returns the index for character that is
152 // nearest to thePoint. thPoint is in screen coordinate system.
153 - (NSUInteger) characterIndexForPoint:(NSPoint) thePoint
154 {
155 return 0;
156 }
157
158 // This method is the key to attribute extension.
159 // We could add new attributes through this method.
160 // NSInputServer examines the return value of this
161 // method & constructs appropriate attributed string.
162 - (NSArray *) validAttributesForMarkedText
163 {
164 return [NSArray array];
165 }
166
84 @end 167 @end
85 168
86 /* This is the original behavior, before support was added for 169 /* This is the original behavior, before support was added for
87 * differentiating between left and right versions of the keys. 170 * differentiating between left and right versions of the keys.
88 */ 171 */