From 1fa7c75d6940d650180c9ffbc63cb646b04014e0 Mon Sep 17 00:00:00 2001 From: rti Date: Thu, 3 Jun 2010 02:15:45 +0200 Subject: [PATCH] Changed: #947 dead key support --- .../src/3d/driver/opengl/mac/cocoa_adapter.mm | 9 +- .../3d/driver/opengl/mac/cocoa_opengl_view.h | 26 ++++- .../3d/driver/opengl/mac/cocoa_opengl_view.m | 101 +++++++++++++++++- 3 files changed, 122 insertions(+), 14 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm index 02b90c589..a4eb72077 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm @@ -319,7 +319,7 @@ bool isTextKeyEvent(NSEvent* event) /* TODO check why iswprint(character) does not solve it. - it always returns false, even for π é ... + it always returns false, even for π, é, ... */ // > 127 but not printable if( nelKey == NLMISC::KeyF1 || nelKey == NLMISC::KeyF2 || @@ -408,13 +408,6 @@ void submitEvents(NLMISC::CEventServer& server, case NSMouseEntered:break; case NSMouseExited:break; case NSKeyDown: - /* - TODO dead keys - http://developer.apple.com/mac/library/documentation/Carbon/Reference/ - Unicode_Utilities_Ref/Reference/reference.html#//apple_ref/c/func/ - UCKeyTranslate - */ - // push the key press event to the new event server server.postEvent(new NLMISC::CEventKeyDown( virtualKeycodeToNelKey([event keyCode]), diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.h b/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.h index db1eb5323..6557128e1 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.h +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.h @@ -21,12 +21,36 @@ /** * derived to configure the NSOpenGLView */ -@interface CocoaOpenGLView : NSOpenGLView +@interface CocoaOpenGLView : NSOpenGLView { + NSMutableAttributedString* backingStore; + NSRange markedRange; } +-(id)initWithFrame:(NSRect)frame; +-(void)dealloc; + -(BOOL)acceptsFirstResponder; -(BOOL)needsPanelToBecomeKey; -(void)keyDown:(NSEvent*)event; +/******************************************************************************/ +/* NSTextInputClient Protocol */ + +-(BOOL)hasMarkedText; +-(NSRange)markedRange; +-(NSRange)selectedRange; +-(void)setMarkedText:(id)aString + selectedRange:(NSRange)newSelection + replacementRange:(NSRange)replacementRange; +-(void)unmarkText; +-(NSArray*)validAttributesForMarkedText; +-(NSAttributedString*)attributedSubstringForProposedRange:(NSRange)aRange + actualRange:(NSRangePointer)actualRange; +-(void)insertText:(id)aString replacementRange:(NSRange)replacementRange; +-(NSUInteger)characterIndexForPoint:(NSPoint)aPoint; +-(NSRect)firstRectForCharacterRange:(NSRange)aRange + actualRange:(NSRangePointer)actualRange; +-(void)doCommandBySelector:(SEL)aSelector; + @end diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.m b/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.m index 954c9c89e..0c816a4d4 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.m +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.m @@ -20,6 +20,21 @@ @implementation CocoaOpenGLView +- (id)initWithFrame:(NSRect)frame +{ + if(self = [super initWithFrame:frame]) + { + backingStore = [[NSMutableAttributedString alloc] initWithString:@""]; + return self; + } + return nil; +} + +- (void)dealloc +{ + [backingStore release]; + [super dealloc]; +} -(BOOL)acceptsFirstResponder { return YES; @@ -32,11 +47,87 @@ -(void)keyDown:(NSEvent*)event { - // we handle the key here, so os x does not make a sound :) - /* - TODO do it in the event emitter? eg do not forward key down? - does command+q / command+m still work then? - */ + [[self inputContext] handleEvent:event]; +} + +/******************************************************************************/ +/* NSTextInputClient Protocol */ + +-(BOOL)hasMarkedText +{ + return (markedRange.location == NSNotFound ? NO : YES); +} + +-(NSRange)markedRange +{ + return markedRange; +} + +-(NSRange)selectedRange +{ + return NSMakeRange(NSNotFound, 0); +} + +-(void)setMarkedText:(id)aString + selectedRange:(NSRange)newSelection + replacementRange:(NSRange)replacementRange +{ + if(replacementRange.location == NSNotFound) + replacementRange = markedRange; + + if([aString length] == 0) + { + [backingStore deleteCharactersInRange:replacementRange]; + [self unmarkText]; + } + else + { + markedRange = NSMakeRange(replacementRange.location, [aString length]); + [backingStore replaceCharactersInRange:replacementRange withString:aString]; + } +} + +-(void)unmarkText +{ + markedRange = NSMakeRange(NSNotFound, 0); + [[self inputContext] discardMarkedText]; +} + +-(NSArray*)validAttributesForMarkedText +{ + return [NSArray arrayWithObjects: + NSMarkedClauseSegmentAttributeName, NSGlyphInfoAttributeName, nil]; +} + +-(NSAttributedString*)attributedSubstringForProposedRange:(NSRange)aRange + actualRange:(NSRangePointer)actualRange +{ + return [backingStore attributedSubstringFromRange:aRange]; +} + +-(void)insertText:(id)aString + replacementRange:(NSRange)replacementRange +{ + if(replacementRange.location == NSNotFound) + replacementRange = markedRange; + + [backingStore replaceCharactersInRange:replacementRange withString:aString]; +} + +-(NSUInteger)characterIndexForPoint:(NSPoint)aPoint +{ + return 0; +} + +-(NSRect)firstRectForCharacterRange:(NSRange)aRange + actualRange:(NSRangePointer)actualRange +{ + return NSMakeRect(0, 0, 0, 0); +} + +-(void)doCommandBySelector:(SEL)aSelector +{ + [super doCommandBySelector:aSelector]; } @end