From bc5324cdff9ee5d147bab5f6014e7aebc3090db9 Mon Sep 17 00:00:00 2001 From: Jjgod Jiang Date: Fri, 9 Nov 2007 01:31:12 +0800 Subject: [PATCH] Use NSView instead of NSTextView as the base class of MMTextView. --- src/MacVim/MMTextView.h | 20 ++++- src/MacVim/MMTextView.m | 135 ++++++++++------------------ src/MacVim/MMVimView.m | 33 +------ src/MacVim/MacVim.xcodeproj/project.pbxproj | 4 +- 4 files changed, 71 insertions(+), 121 deletions(-) diff --git a/src/MacVim/MMTextView.h b/src/MacVim/MMTextView.h index 69ea8ba0..8b337bf8 100644 --- a/src/MacVim/MMTextView.h +++ b/src/MacVim/MMTextView.h @@ -9,9 +9,10 @@ */ #import +#import "MMTextStorage.h" -@interface MMTextView : NSTextView { +@interface MMTextView : NSView { BOOL shouldDrawInsertionPoint; NSEvent *lastMouseDownEvent; NSTrackingRectTag trackingRectTag; @@ -26,6 +27,10 @@ int insertionPointShape; int insertionPointFraction; NSTextField *markedTextField; + NSColor *insertionPointColor; + NSColor *backgroundColor; + MMTextStorage *textStorage; + NSSize textContainerInset; } - (NSEvent *)lastMouseDownEvent; @@ -34,4 +39,17 @@ fraction:(int)percent color:(NSColor *)color; - (void)hideMarkedTextField; +- (NSPoint)textContainerOrigin; + +- (NSColor *)insertionPointColor; +- (void)setInsertionPointColor:(NSColor *)color; + +- (MMTextStorage *)textStorage; +- (void)setTextStorage:(MMTextStorage *)aTextStorage; + +- (void)setBackgroundColor:(NSColor *)color; + +- (void)setTextContainerInset:(NSSize)inset; +- (NSSize)textContainerInset; + @end diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index 0e2399d7..9959387c 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -107,67 +107,6 @@ static NSString *MMKeypadEnterString = @"KA"; - (void)drawRect:(NSRect)rect { - [super drawRect:rect]; - - if (shouldDrawInsertionPoint) { - MMTextStorage *ts = (MMTextStorage*)[self textStorage]; - NSLayoutManager *lm = [self layoutManager]; - NSTextContainer *tc = [self textContainer]; - - // Given (row,column), calculate the bounds of the glyph at that spot. - // We use the layout manager because this gives us exactly the size and - // location of the glyph so that we can match the insertion point to - // it. - unsigned charIdx = [ts characterIndexForRow:insertionPointRow - column:insertionPointColumn]; - NSRange glyphRange = - [lm glyphRangeForCharacterRange:NSMakeRange(charIdx,1) - actualCharacterRange:NULL]; - NSRect ipRect = [lm boundingRectForGlyphRange:glyphRange - inTextContainer:tc]; - ipRect.origin.x += [self textContainerOrigin].x; - ipRect.origin.y += [self textContainerOrigin].y; - - if (MMInsertionPointHorizontal == insertionPointShape) { - int frac = ([ts cellSize].height * insertionPointFraction + 99)/100; - ipRect.origin.y += ipRect.size.height - frac; - ipRect.size.height = frac; - } else if (MMInsertionPointVertical == insertionPointShape) { - int frac = ([ts cellSize].width* insertionPointFraction + 99)/100; - ipRect.size.width = frac; - } - - [[self insertionPointColor] set]; - if (MMInsertionPointHollow == insertionPointShape) { - NSFrameRect(ipRect); - } else { - NSRectFill(ipRect); - } - - // NOTE: We only draw the cursor once and rely on Vim to say when it - // should be drawn again. - shouldDrawInsertionPoint = NO; - - //NSLog(@"%s draw insertion point %@ shape=%d color=%@", _cmd, - // NSStringFromRect(ipRect), insertionPointShape, - // [self insertionPointColor]); - } -#if 0 - // this code invalidates the shadow, so we don't - // get shifting ghost text on scroll and resize - // but makes speed unusable - MMTextStorage *ts = (MMTextStorage*)[self textStorage]; - if ([ts defaultBackgroundAlpha] < 1.0f) { - if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_1) - { - [[self window] setHasShadow:NO]; - [[self window] setHasShadow:YES]; - } - else - [[self window] invalidateShadow]; - - } -#endif } - (void)keyDown:(NSEvent *)event @@ -425,34 +364,7 @@ static NSString *MMKeypadEnterString = @"KA"; - (NSRect)firstRectForCharacterRange:(NSRange)range { - //NSLog(@"%s%@", _cmd, NSStringFromRange(range)); - - MMTextStorage *ts = (MMTextStorage*)[self textStorage]; - NSLayoutManager *lm = [self layoutManager]; - NSTextContainer *tc = [self textContainer]; - - // HACK! Since we always return marked text to have location NSNotFound, - // this method will be called with 'range.location == NSNotFound' whenever - // the input manager tries to position a popup window near the insertion - // point. For this reason we compute where the insertion point is and - // return a rect which contains it. - if (!(ts && lm && tc) || NSNotFound != range.location) - return [super firstRectForCharacterRange:range]; - - unsigned charIdx = [ts characterIndexForRow:insertionPointRow - column:insertionPointColumn]; - NSRange glyphRange = - [lm glyphRangeForCharacterRange:NSMakeRange(charIdx,1) - actualCharacterRange:NULL]; - NSRect ipRect = [lm boundingRectForGlyphRange:glyphRange - inTextContainer:tc]; - ipRect.origin.x += [self textContainerOrigin].x; - ipRect.origin.y += [self textContainerOrigin].y + [ts cellSize].height; - - ipRect.origin = [self convertPoint:ipRect.origin toView:nil]; - ipRect.origin = [[self window] convertBaseToScreen:ipRect.origin]; - - return ipRect; + return NSZeroRect; } - (void)scrollWheel:(NSEvent *)event @@ -788,6 +700,51 @@ static NSString *MMKeypadEnterString = @"KA"; [super viewDidEndLiveResize]; } +- (NSPoint)textContainerOrigin +{ + return NSMakePoint(0, 0); +} + +- (void)setInsertionPointColor:(NSColor *)color +{ + insertionPointColor = color; +} + +- (NSColor *)insertionPointColor +{ + return insertionPointColor; +} + +- (MMTextStorage *)textStorage +{ + return textStorage; +} + +- (void)setTextStorage:(MMTextStorage *)aTextStorage +{ + textStorage = aTextStorage; +} + +- (void)setBackgroundColor:(NSColor *)color +{ + backgroundColor = color; +} + +- (NSColor *)backgroundColor +{ + return backgroundColor; +} + +- (void)setTextContainerInset:(NSSize)inset +{ + textContainerInset = inset; +} + +- (NSSize)textContainerInset +{ + return textContainerInset; +} + @end // MMTextView diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index d5a1fb10..5036843e 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -80,43 +80,16 @@ enum { // Set up a complete text system. textStorage = [[MMTextStorage alloc] init]; - NSLayoutManager *lm = [[NSLayoutManager alloc] init]; - NSTextContainer *tc = [[NSTextContainer alloc] initWithContainerSize: - NSMakeSize(1.0e7,1.0e7)]; - - NSString *typesetterString = [[NSUserDefaults standardUserDefaults] - stringForKey:MMTypesetterKey]; - if (![typesetterString isEqual:@"NSTypesetter"]) { - MMTypesetter *typesetter = [[MMTypesetter alloc] init]; - [lm setTypesetter:typesetter]; - [typesetter release]; - } else { - // Only MMTypesetter supports different cell width multipliers. - [[NSUserDefaults standardUserDefaults] - setFloat:1.0 forKey:MMCellWidthMultiplierKey]; - } - - [tc setWidthTracksTextView:NO]; - [tc setHeightTracksTextView:NO]; - [tc setLineFragmentPadding:0]; - [textStorage addLayoutManager:lm]; - [lm addTextContainer:tc]; - - textView = [[MMTextView alloc] initWithFrame:frame - textContainer:tc]; + textView = [[MMTextView alloc] initWithFrame:frame]; + [textView setTextStorage:textStorage]; NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; int left = [ud integerForKey:MMTextInsetLeftKey]; int top = [ud integerForKey:MMTextInsetTopKey]; [textView setTextContainerInset:NSMakeSize(left, top)]; - [self addSubview:textView]; - - // The text storage retains the layout manager which in turn retains - // the text container. - [tc release]; - [lm release]; + // [self addSubview:textView]; // Create the tab view (which is never visible, but the tab bar control // needs it to function). diff --git a/src/MacVim/MacVim.xcodeproj/project.pbxproj b/src/MacVim/MacVim.xcodeproj/project.pbxproj index b5675b00..99837f2b 100644 --- a/src/MacVim/MacVim.xcodeproj/project.pbxproj +++ b/src/MacVim/MacVim.xcodeproj/project.pbxproj @@ -139,7 +139,7 @@ 1D1474A70C5677450038FA2B /* MMTextStorage.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MMTextStorage.h; sourceTree = ""; }; 1D1474A80C5677450038FA2B /* MMTextStorage.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MMTextStorage.m; sourceTree = ""; }; 1D1474AD0C5678370038FA2B /* MMTextView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MMTextView.h; sourceTree = ""; }; - 1D1474AE0C5678370038FA2B /* MMTextView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MMTextView.m; sourceTree = ""; }; + 1D1474AE0C5678370038FA2B /* MMTextView.m */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MMTextView.m; sourceTree = ""; tabWidth = 4; usesTabs = 0; }; 1D1474B30C56796D0038FA2B /* MMVimController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MMVimController.h; sourceTree = ""; }; 1D1474B40C56796D0038FA2B /* MMVimController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MMVimController.m; sourceTree = ""; }; 1D1474B90C567A910038FA2B /* MMWindowController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MMWindowController.h; sourceTree = ""; }; @@ -426,6 +426,7 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "MacVim" */; + compatibilityVersion = "Xcode 2.4"; hasScannedForEncodings = 1; mainGroup = 29B97314FDCFA39411CA2CEA /* MacVim */; projectDirPath = ""; @@ -435,6 +436,7 @@ ProjectRef = 1D493DB30C52533B00AB718C /* PSMTabBarControl.xcodeproj */; }, ); + projectRoot = ""; targets = ( 8D1107260486CEB800E47090 /* MacVim */, ); -- 2.11.4.GIT