src/video/cocoa/SDL_cocoakeyboard.m
branchgsoc2009_IME
changeset 3127 da6cbfa5b5f2
parent 2859 99210400e8b9
child 3129 e42873b9c6f1
equal deleted inserted replaced
3126:395e0c7a78a3 3127:da6cbfa5b5f2
    59 }
    59 }
    60 - (void) doCommandBySelector:(SEL)myselector;
    60 - (void) doCommandBySelector:(SEL)myselector;
    61 @end
    61 @end
    62 
    62 
    63 @implementation SDLTranslatorResponder
    63 @implementation SDLTranslatorResponder
    64 - (void) doCommandBySelector:(SEL) myselector {}
    64 
       
    65 - (void) insertText:(id) aString
       
    66 {
       
    67     const char *str;
       
    68 
       
    69     NSLog(@"insertText: %@", aString);
       
    70 
       
    71     if ([aString isKindOfClass: [NSAttributedString class]])
       
    72         str = [[aString string] UTF8String];
       
    73     else
       
    74         str = [aString UTF8String];
       
    75 
       
    76     SDL_SendKeyboardText(0, str);
       
    77 }
       
    78 
       
    79 - (void) doCommandBySelector:(SEL) myselector
       
    80 {
       
    81     NSLog(@"doCommandBySelector, passed down");
       
    82     [super doCommandBySelector: myselector];
       
    83 }
    65 @end
    84 @end
    66 
    85 
    67 /* This is the original behavior, before support was added for 
    86 /* This is the original behavior, before support was added for 
    68  * differentiating between left and right versions of the keys.
    87  * differentiating between left and right versions of the keys.
    69  */
    88  */
   508             }
   527             }
   509 #endif
   528 #endif
   510         }
   529         }
   511         if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
   530         if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
   512             /* 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. */
   531             /* 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. */
       
   532             NSLog(@"interpretKeyEvents");
       
   533             if (! [[data->fieldEdit superview] isEqual: [[event window] contentView]])
       
   534             {
       
   535                 NSLog(@"add fieldEdit to window contentView");
       
   536                 [data->fieldEdit removeFromSuperview];
       
   537                 [[[event window] contentView] addSubview: data->fieldEdit];
       
   538                 [[event window] makeFirstResponder: data->fieldEdit];
       
   539             }
   513             [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
   540             [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
       
   541 #if 0
   514             text = [[event characters] UTF8String];
   542             text = [[event characters] UTF8String];
   515             if(text && *text) {
   543             if(text && *text) {
   516                 SDL_SendKeyboardText(data->keyboard, text);
   544                 SDL_SendKeyboardText(data->keyboard, text);
   517                 [data->fieldEdit setString:@""];
   545                 [data->fieldEdit setString:@""];
   518             }
   546             }
       
   547 #endif
   519         }
   548         }
   520         break;
   549         break;
   521     case NSKeyUp:
   550     case NSKeyUp:
   522         SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, code);
   551         SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, code);
   523         break;
   552         break;