changeset 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 395e0c7a78a3
children 05d83835f41b
files build-scripts/showrev.sh src/video/cocoa/SDL_cocoakeyboard.m
diffstat 2 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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: