From 8fe6d1a56642ba21bd0a972cbfa2a98067d89649 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 26 Feb 2011 13:49:01 -0500 Subject: [PATCH] Add BSSourceViewTextView (again). --- MacGDBp.xcodeproj/project.pbxproj | 6 ++++ Source/BSSourceView.h | 3 +- Source/BSSourceView.mm | 6 ++-- Source/BSSourceViewTextView.h | 30 +++++++++++++++++++ Source/BSSourceViewTextView.m | 48 +++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 Source/BSSourceViewTextView.h create mode 100644 Source/BSSourceViewTextView.m diff --git a/MacGDBp.xcodeproj/project.pbxproj b/MacGDBp.xcodeproj/project.pbxproj index 7a1b78a..39d1e55 100644 --- a/MacGDBp.xcodeproj/project.pbxproj +++ b/MacGDBp.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 1E02C5710C610158006F1752 /* DebuggerBackEnd.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C5700C610158006F1752 /* DebuggerBackEnd.m */; }; 1E02C5F60C610724006F1752 /* DebuggerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C5F50C610724006F1752 /* DebuggerController.m */; }; 1E0AFBB90FC2518700C67031 /* HUDIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 1E0AFBB80FC2518700C67031 /* HUDIcon.png */; }; + 1E11814A1319805E003BFEF1 /* BSSourceViewTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E1181491319805E003BFEF1 /* BSSourceViewTextView.m */; }; 1E1E53030DF9B89800D334F9 /* Breakpoints.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E1E53010DF9B89800D334F9 /* Breakpoints.xib */; }; 1E2F0A6912D5371C00EBF675 /* Stop.png in Resources */ = {isa = PBXBuildFile; fileRef = 1E2F0A6812D5371B00EBF675 /* Stop.png */; }; 1E35FC760C6579CA0030F527 /* NSXMLElementAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E35FC750C6579CA0030F527 /* NSXMLElementAdditions.m */; }; @@ -77,6 +78,8 @@ 1E02C5F50C610724006F1752 /* DebuggerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DebuggerController.m; path = Source/DebuggerController.m; sourceTree = ""; }; 1E0724E111B47BCC0017AD3C /* NetworkConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkConnection.h; path = Source/NetworkConnection.h; sourceTree = ""; }; 1E0AFBB80FC2518700C67031 /* HUDIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = HUDIcon.png; path = Icons/HUDIcon.png; sourceTree = ""; }; + 1E1181481319805E003BFEF1 /* BSSourceViewTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BSSourceViewTextView.h; path = Source/BSSourceViewTextView.h; sourceTree = ""; }; + 1E1181491319805E003BFEF1 /* BSSourceViewTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BSSourceViewTextView.m; path = Source/BSSourceViewTextView.m; sourceTree = ""; }; 1E1E53020DF9B89800D334F9 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/Breakpoints.xib; sourceTree = ""; }; 1E2F0A6812D5371B00EBF675 /* Stop.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Stop.png; path = Icons/Stop.png; sourceTree = ""; }; 1E35FC750C6579CA0030F527 /* NSXMLElementAdditions.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = NSXMLElementAdditions.m; path = Source/NSXMLElementAdditions.m; sourceTree = ""; }; @@ -252,6 +255,8 @@ 1E7188650D839F6300969277 /* BSSourceView.mm */, 1EDA9CF612DD13B300596211 /* BSLineNumberRulerView.h */, 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.mm */, + 1E1181481319805E003BFEF1 /* BSSourceViewTextView.h */, + 1E1181491319805E003BFEF1 /* BSSourceViewTextView.m */, ); name = "Source View"; sourceTree = ""; @@ -456,6 +461,7 @@ 1EFBE63012C515C200F96D6E /* NetworkConnection.mm in Sources */, 1EFBE66B12C51E3900F96D6E /* NetworkCallbackController.mm in Sources */, 1EDA9CF812DD13B300596211 /* BSLineNumberRulerView.mm in Sources */, + 1E11814A1319805E003BFEF1 /* BSSourceViewTextView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/BSSourceView.h b/Source/BSSourceView.h index 672ae64..4f72483 100644 --- a/Source/BSSourceView.h +++ b/Source/BSSourceView.h @@ -18,6 +18,7 @@ @class BSLineNumberRulerView; @protocol BSSourceViewDelegate; +@class BSSourceViewTextView; // A BSSourceView is a view that contains an NSTextView that also has a line // number ruler. This class wraps synchronization management between the text @@ -28,7 +29,7 @@ @interface BSSourceView : NSView { @private - NSTextView* textView_; + BSSourceViewTextView* textView_; BSLineNumberRulerView* ruler_; NSScrollView* scrollView_; diff --git a/Source/BSSourceView.mm b/Source/BSSourceView.mm index a6f329b..3728cc8 100644 --- a/Source/BSSourceView.mm +++ b/Source/BSSourceView.mm @@ -16,7 +16,8 @@ #import "BSSourceView.h" -#include "BSLineNumberRulerView.h" +#import "BSLineNumberRulerView.h" +#import "BSSourceViewTextView.h" @interface BSSourceView (Private) - (void)setupViews; @@ -201,7 +202,8 @@ NSRect textFrame; textFrame.origin = NSMakePoint(0.0, 0.0); textFrame.size = [scrollView_ contentSize]; - textView_ = [[[NSTextView alloc] initWithFrame:textFrame] autorelease]; + textView_ = [[[BSSourceViewTextView alloc] initWithFrame:textFrame] autorelease]; + [textView_ setSourceView:self]; [textView_ setEditable:NO]; [textView_ setFont:[NSFont fontWithName:@"Monaco" size:10.0]]; [textView_ setHorizontallyResizable:YES]; diff --git a/Source/BSSourceViewTextView.h b/Source/BSSourceViewTextView.h new file mode 100644 index 0000000..0fd27ba --- /dev/null +++ b/Source/BSSourceViewTextView.h @@ -0,0 +1,30 @@ +/* + * MacGDBp + * Copyright (c) 2007 - 2011, Blue Static + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#import + +@class BSSourceView; + +// This custom subclass of NSTextView simply draws a red rectangle over the text +// for the current value of BSSourceView.markedLine. +@interface BSSourceViewTextView : NSTextView { + @private + BSSourceView* sourceView_; // weak +} + +@property (nonatomic, assign) BSSourceView* sourceView; + +@end diff --git a/Source/BSSourceViewTextView.m b/Source/BSSourceViewTextView.m new file mode 100644 index 0000000..9a7370e --- /dev/null +++ b/Source/BSSourceViewTextView.m @@ -0,0 +1,48 @@ +/* + * MacGDBp + * Copyright (c) 2007 - 2011, Blue Static + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#import "BSSourceViewTextView.h" + +#import "BSSourceView.h" + +@implementation BSSourceViewTextView + +@synthesize sourceView = sourceView_; + +- (void)drawRect:(NSRect)rect +{ + [super drawRect:rect]; + + NSLayoutManager* layoutManager = [self layoutManager]; + NSUInteger i = 0, line = 1; + while (i < [layoutManager numberOfGlyphs]) { + NSRange fragRange; + NSRect fragRect = [layoutManager lineFragmentRectForGlyphAtIndex:i + effectiveRange:&fragRange]; + if ([sourceView_ markedLine] == line) { + fragRect = [self convertRect:fragRect fromView:self]; + fragRect.origin.x = rect.origin.x; // Flush all the way to the edge. + [[[NSColor redColor] colorWithAlphaComponent:0.25] set]; + [NSBezierPath fillRect:fragRect]; + break; + } + + i += fragRange.length; + ++line; + } +} + +@end -- 2.43.5