comparison src/video/cocoa/SDL_cocoakeyboard.m @ 3130:fef1a835af43 gsoc2009_IME

Basic text input API
author Jiang Jiang <gzjjgod@gmail.com>
date Fri, 26 Jun 2009 10:37:57 +0000
parents e42873b9c6f1
children 88861448961f
comparison
equal deleted inserted replaced
3129:e42873b9c6f1 3130:fef1a835af43
57 @interface SDLTranslatorResponder : NSTextView 57 @interface SDLTranslatorResponder : NSTextView
58 { 58 {
59 NSString *_markedText; 59 NSString *_markedText;
60 NSRange _markedRange; 60 NSRange _markedRange;
61 NSRange _selectedRange; 61 NSRange _selectedRange;
62 SDL_Rect inputRect;
62 } 63 }
63 - (void) doCommandBySelector:(SEL)myselector; 64 - (void) doCommandBySelector:(SEL)myselector;
65 - (void) setInputRect:(SDL_Rect *) rect;
64 @end 66 @end
65 67
66 @implementation SDLTranslatorResponder 68 @implementation SDLTranslatorResponder
69
70 - (void) setInputRect:(SDL_Rect *) rect
71 {
72 inputRect = *rect;
73 }
67 74
68 - (void) insertText:(id) aString 75 - (void) insertText:(id) aString
69 { 76 {
70 const char *str; 77 const char *str;
71 78
133 _markedText = nil; 140 _markedText = nil;
134 } 141 }
135 142
136 - (NSRect) firstRectForCharacterRange: (NSRange) theRange 143 - (NSRect) firstRectForCharacterRange: (NSRange) theRange
137 { 144 {
138 return NSMakeRect(0, 0, 0, 0); 145 float windowHeight = [[self window] frame].size.height;
146 NSRect rect = NSMakeRect(inputRect.x, windowHeight - inputRect.y, inputRect.w, inputRect.h);
147
148 NSLog(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
149 theRange.location, theRange.length, windowHeight,
150 NSStringFromRect(rect));
151 rect.origin = [[self window] convertBaseToScreen: rect.origin];
152
153 return rect;
139 } 154 }
140 155
141 - (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange 156 - (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange
142 { 157 {
158 NSLog(@"attributedSubstringFromRange: (%d, %d)", theRange.location, theRange.length);
143 return nil; 159 return nil;
144 } 160 }
145 161
146 - (NSInteger) conversationIdentifier 162 - (NSInteger) conversationIdentifier
147 { 163 {
150 166
151 // This method returns the index for character that is 167 // This method returns the index for character that is
152 // nearest to thePoint. thPoint is in screen coordinate system. 168 // nearest to thePoint. thPoint is in screen coordinate system.
153 - (NSUInteger) characterIndexForPoint:(NSPoint) thePoint 169 - (NSUInteger) characterIndexForPoint:(NSPoint) thePoint
154 { 170 {
171 NSLog(@"characterIndexForPoint: (%g, %g)", thePoint.x, thePoint.y);
155 return 0; 172 return 0;
156 } 173 }
157 174
158 // This method is the key to attribute extension. 175 // This method is the key to attribute extension.
159 // We could add new attributes through this method. 176 // We could add new attributes through this method.
576 SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option"); 593 SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option");
577 SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command"); 594 SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
578 } 595 }
579 596
580 void 597 void
598 Cocoa_StartTextInput(_THIS, SDL_Rect *rect)
599 {
600 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
601
602 NSLog(@"StartTextInput: (%d, %d) (w=%d, h=%d)", rect->x, rect->y, rect->w, rect->h);
603 [data->fieldEdit setInputRect: rect];
604 }
605
606 void
581 Cocoa_HandleKeyEvent(_THIS, NSEvent *event) 607 Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
582 { 608 {
583 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 609 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
584 unsigned short scancode = [event keyCode]; 610 unsigned short scancode = [event keyCode];
585 SDL_scancode code; 611 SDL_scancode code;