diff options
author | Sven Weidauer <sven.weidauer@gmail.com> | 2011-03-07 09:01:42 +0000 |
---|---|---|
committer | Sven Weidauer <sven.weidauer@gmail.com> | 2011-03-07 09:01:42 +0000 |
commit | fc6125f79adfa07dcd1316c70618a5baebc8da12 (patch) | |
tree | 85e30c493958003cd9419f51926d255b7eacaae2 | |
parent | b925439a14ac8c8787034f30631ad60dd626a299 (diff) | |
download | netsurf-fc6125f79adfa07dcd1316c70618a5baebc8da12.tar.gz netsurf-fc6125f79adfa07dcd1316c70618a5baebc8da12.tar.bz2 |
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
-rw-r--r-- | cocoa/BrowserView.h | 4 | ||||
-rw-r--r-- | cocoa/BrowserView.m | 63 |
2 files changed, 66 insertions, 1 deletions
diff --git a/cocoa/BrowserView.h b/cocoa/BrowserView.h index 5b3d3b577..c626c8c5b 100644 --- a/cocoa/BrowserView.h +++ b/cocoa/BrowserView.h @@ -22,7 +22,7 @@ @class LocalHistoryController; -@interface BrowserView : ScrollableView { +@interface BrowserView : ScrollableView <NSTextInput> { struct browser_window *browser; NSPoint caretPoint; @@ -36,6 +36,8 @@ BOOL historyVisible; LocalHistoryController *history; + + NSString *markedText; } @property (readwrite, assign, nonatomic) struct browser_window *browser; 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 |