src/video/cocoa/SDL_cocoakeyboard.m
branchgsoc2009_IME
changeset 3127 da6cbfa5b5f2
parent 2859 99210400e8b9
child 3129 e42873b9c6f1
     1.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Sat May 23 22:48:40 2009 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Mon May 25 02:42:45 2009 +0000
     1.3 @@ -61,7 +61,26 @@
     1.4  @end
     1.5  
     1.6  @implementation SDLTranslatorResponder
     1.7 -- (void) doCommandBySelector:(SEL) myselector {}
     1.8 +
     1.9 +- (void) insertText:(id) aString
    1.10 +{
    1.11 +    const char *str;
    1.12 +
    1.13 +    NSLog(@"insertText: %@", aString);
    1.14 +
    1.15 +    if ([aString isKindOfClass: [NSAttributedString class]])
    1.16 +        str = [[aString string] UTF8String];
    1.17 +    else
    1.18 +        str = [aString UTF8String];
    1.19 +
    1.20 +    SDL_SendKeyboardText(0, str);
    1.21 +}
    1.22 +
    1.23 +- (void) doCommandBySelector:(SEL) myselector
    1.24 +{
    1.25 +    NSLog(@"doCommandBySelector, passed down");
    1.26 +    [super doCommandBySelector: myselector];
    1.27 +}
    1.28  @end
    1.29  
    1.30  /* This is the original behavior, before support was added for 
    1.31 @@ -510,12 +529,22 @@
    1.32          }
    1.33          if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
    1.34              /* 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. */
    1.35 +            NSLog(@"interpretKeyEvents");
    1.36 +            if (! [[data->fieldEdit superview] isEqual: [[event window] contentView]])
    1.37 +            {
    1.38 +                NSLog(@"add fieldEdit to window contentView");
    1.39 +                [data->fieldEdit removeFromSuperview];
    1.40 +                [[[event window] contentView] addSubview: data->fieldEdit];
    1.41 +                [[event window] makeFirstResponder: data->fieldEdit];
    1.42 +            }
    1.43              [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
    1.44 +#if 0
    1.45              text = [[event characters] UTF8String];
    1.46              if(text && *text) {
    1.47                  SDL_SendKeyboardText(data->keyboard, text);
    1.48                  [data->fieldEdit setString:@""];
    1.49              }
    1.50 +#endif
    1.51          }
    1.52          break;
    1.53      case NSKeyUp: