Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Get basic text input support working for Cocoa
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgod committed May 25, 2009
1 parent 24f5230 commit 1d7b4fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions build-scripts/showrev.sh
Expand Up @@ -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
31 changes: 30 additions & 1 deletion src/video/cocoa/SDL_cocoakeyboard.m
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1d7b4fd

Please sign in to comment.