diff src/video/cocoa/SDL_cocoakeyboard.m @ 3127:da6cbfa5b5f2 gsoc2009_IME

Get basic text input support working for Cocoa
author Jiang Jiang <gzjjgod@gmail.com>
date Mon, 25 May 2009 02:42:45 +0000
parents 99210400e8b9
children e42873b9c6f1
line wrap: on
line diff
--- a/src/video/cocoa/SDL_cocoakeyboard.m	Sat May 23 22:48:40 2009 +0000
+++ b/src/video/cocoa/SDL_cocoakeyboard.m	Mon May 25 02:42:45 2009 +0000
@@ -61,7 +61,26 @@
 @end
 
 @implementation SDLTranslatorResponder
-- (void) doCommandBySelector:(SEL) myselector {}
+
+- (void) insertText:(id) aString
+{
+    const char *str;
+
+    NSLog(@"insertText: %@", aString);
+
+    if ([aString isKindOfClass: [NSAttributedString class]])
+        str = [[aString string] UTF8String];
+    else
+        str = [aString UTF8String];
+
+    SDL_SendKeyboardText(0, str);
+}
+
+- (void) doCommandBySelector:(SEL) myselector
+{
+    NSLog(@"doCommandBySelector, passed down");
+    [super doCommandBySelector: myselector];
+}
 @end
 
 /* This is the original behavior, before support was added for 
@@ -510,12 +529,22 @@
         }
         if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
             /* 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. */
+            NSLog(@"interpretKeyEvents");
+            if (! [[data->fieldEdit superview] isEqual: [[event window] contentView]])
+            {
+                NSLog(@"add fieldEdit to window contentView");
+                [data->fieldEdit removeFromSuperview];
+                [[[event window] contentView] addSubview: data->fieldEdit];
+                [[event window] makeFirstResponder: data->fieldEdit];
+            }
             [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
+#if 0
             text = [[event characters] UTF8String];
             if(text && *text) {
                 SDL_SendKeyboardText(data->keyboard, text);
                 [data->fieldEdit setString:@""];
             }
+#endif
         }
         break;
     case NSKeyUp: