Get basic text input support working for Cocoa gsoc2009_IME
authorJiang Jiang <gzjjgod@gmail.com>
Mon, 25 May 2009 02:42:45 +0000
branchgsoc2009_IME
changeset 3127 da6cbfa5b5f2
parent 3126 395e0c7a78a3
child 3128 05d83835f41b
Get basic text input support working for Cocoa
build-scripts/showrev.sh
src/video/cocoa/SDL_cocoakeyboard.m
--- a/build-scripts/showrev.sh	Sat May 23 22:48:40 2009 +0000
+++ b/build-scripts/showrev.sh	Mon May 25 02:42:45 2009 +0000
@@ -9,4 +9,7 @@
     (svnversion -c 2>/dev/null || svnversion .) | \
         sed -e 's,\([0-9]*\)[A-Z]*,\1,' \
             -e 's,[0-9]*:\([0-9]*\)[A-Z]*,\1,'
+else
+     cd $srcdir
+     git svn info | grep Revision | awk '{ print $2 }'
 fi
--- 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: