# HG changeset patch # User Jiang Jiang # Date 1243789049 0 # Node ID e42873b9c6f155b0fef6c24c3fce2aec05f18338 # Parent 05d83835f41b2d2d464fd618b270444e01d699a9 Basic marked text handling diff -r 05d83835f41b -r e42873b9c6f1 src/video/cocoa/SDL_cocoaevents.m --- a/src/video/cocoa/SDL_cocoaevents.m Mon May 25 11:09:29 2009 +0000 +++ b/src/video/cocoa/SDL_cocoaevents.m Sun May 31 16:57:29 2009 +0000 @@ -195,7 +195,7 @@ /* FIXME: Find a way to stop the beeping, using delegate */ /* Add to support system-wide keyboard shortcuts like CMD+Space */ - if ([event modifierFlags] & NSCommandKeyMask) + if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged) [NSApp sendEvent: event]; break; default: diff -r 05d83835f41b -r e42873b9c6f1 src/video/cocoa/SDL_cocoakeyboard.m --- a/src/video/cocoa/SDL_cocoakeyboard.m Mon May 25 11:09:29 2009 +0000 +++ b/src/video/cocoa/SDL_cocoakeyboard.m Sun May 31 16:57:29 2009 +0000 @@ -56,6 +56,9 @@ @interface SDLTranslatorResponder : NSTextView { + NSString *_markedText; + NSRange _markedRange; + NSRange _selectedRange; } - (void) doCommandBySelector:(SEL)myselector; @end @@ -68,6 +71,8 @@ NSLog(@"insertText: %@", aString); + /* Could be NSString or NSAttributedString, so we have + * to test and convert it before return as SDL event */ if ([aString isKindOfClass: [NSAttributedString class]]) str = [[aString string] UTF8String]; else @@ -81,6 +86,84 @@ NSLog(@"doCommandBySelector, passed down"); [super doCommandBySelector: myselector]; } + +- (BOOL) hasMarkedText +{ + return _markedText != nil; +} + +- (NSRange) markedRange +{ + return _markedRange; +} + +- (NSRange) selectedRange +{ + return _selectedRange; +} + +- (void) setMarkedText:(id) aString + selectedRange:(NSRange) selRange +{ + if ([aString isKindOfClass: [NSAttributedString class]]) + aString = [aString string]; + + if ([aString length] == 0) + { + [self unmarkText]; + return; + } + + if (_markedText != aString) + { + [_markedText release]; + _markedText = [aString retain]; + } + + _selectedRange = selRange; + _markedRange = NSMakeRange(0, [aString length]); + + NSLog(@"setMarkedText: %@, (%d, %d)", _markedText, + selRange.location, selRange.length); +} + +- (void) unmarkText +{ + [_markedText release]; + _markedText = nil; +} + +- (NSRect) firstRectForCharacterRange: (NSRange) theRange +{ + return NSMakeRect(0, 0, 0, 0); +} + +- (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange +{ + return nil; +} + +- (NSInteger) conversationIdentifier +{ + return (NSInteger) self; +} + +// This method returns the index for character that is +// nearest to thePoint. thPoint is in screen coordinate system. +- (NSUInteger) characterIndexForPoint:(NSPoint) thePoint +{ + return 0; +} + +// This method is the key to attribute extension. +// We could add new attributes through this method. +// NSInputServer examines the return value of this +// method & constructs appropriate attributed string. +- (NSArray *) validAttributesForMarkedText +{ + return [NSArray array]; +} + @end /* This is the original behavior, before support was added for