From fc6125f79adfa07dcd1316c70618a5baebc8da12 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Mon, 7 Mar 2011 09:01:42 +0000 Subject: Minimal implementation of NSTextInput protocol. Allows accented characters to be typed. Might not work with other, more complex input methods (chinese, ...) svn path=/trunk/netsurf/; revision=11930 --- cocoa/BrowserView.m | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'cocoa/BrowserView.m') diff --git a/cocoa/BrowserView.m b/cocoa/BrowserView.m index bc6e598b5..ba83c3470 100644 --- a/cocoa/BrowserView.m +++ b/cocoa/BrowserView.m @@ -32,6 +32,8 @@ @interface BrowserView () +@property (readwrite, copy, nonatomic) NSString *markedText; + - (void) scrollHorizontal: (CGFloat) amount; - (void) scrollVertical: (CGFloat) amount; - (CGFloat) pageScroll; @@ -54,6 +56,7 @@ @synthesize browser; @synthesize caretTimer; +@synthesize markedText; static const CGFloat CaretWidth = 1.0; static const NSTimeInterval CaretBlinkTime = 0.8; @@ -72,6 +75,7 @@ static NSMutableArray *cocoa_reformat_pending = nil; - (void) dealloc; { [self setCaretTimer: nil]; + [self setMarkedText: nil]; [history release]; [super dealloc]; @@ -300,6 +304,7 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) break; } } + [self setMarkedText: nil]; } - (void) moveLeft: (id)sender; @@ -623,5 +628,63 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) return YES; } +// MARK: - +// MARK: NSTextInput protocol implementation + +- (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange +{ + [markedText release]; + markedText = [aString isEqualToString: @""] ? nil : [aString copy]; +} + +- (void) unmarkText +{ + [self setMarkedText: nil]; +} + +- (BOOL) hasMarkedText +{ + return markedText != nil; +} + +- (NSInteger) conversationIdentifier +{ + return (NSInteger)self; +} + +- (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange +{ + return [[[NSAttributedString alloc] initWithString: @""] autorelease]; +} + +- (NSRange) markedRange +{ + return NSMakeRange( NSNotFound, 0 ); +} + +- (NSRange) selectedRange +{ + return NSMakeRange( NSNotFound, 0 ); +} + +- (NSRect) firstRectForCharacterRange: (NSRange) theRange +{ + return NSZeroRect; +} + +- (NSUInteger) characterIndexForPoint: (NSPoint) thePoint +{ + return 0; +} + +- (NSArray *) validAttributesForMarkedText +{ + return [NSArray array]; +} + +- (void) doCommandBySelector: (SEL) sel; +{ + [super doCommandBySelector: sel]; +} @end -- cgit v1.2.3