Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Get basic text input support working for Cocoa

  • Loading branch information
jjgod committed May 25, 2009
1 parent 24f5230 commit 1d7b4fd8a01c3251b8007cc6d6c8a972f2055a15
Showing with 33 additions and 1 deletion.
  1. +3 −0 build-scripts/showrev.sh
  2. +30 −1 src/video/cocoa/SDL_cocoakeyboard.m
@@ -9,4 +9,7 @@ if [ -d $srcdir/.svn ]; then
(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
@@ -61,7 +61,26 @@ - (void) doCommandBySelector:(SEL)myselector;
@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 @@ - (void) doCommandBySelector:(SEL) myselector {}
}
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:

0 comments on commit 1d7b4fd

Please sign in to comment.