From dffe0c9ea6eaccd527cb66e81c4f5ee86d128adb Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 10 Mar 2008 15:13:09 -0400 Subject: [PATCH] Making progress on our -[mouseDown:] event handler, but it's not quite working * Source/BSLineNumberView.m: ([BSLineNumberView mouseDown:]): New method * Source/BSSourceView.h: New delegate prop-ivar * Source/BSSourceView.m: Synthesizing the delegate ivar --- Source/BSLineNumberView.m | 34 +++++++++++++++++++++++++++++++++- Source/BSSourceView.h | 3 +++ Source/BSSourceView.m | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Source/BSLineNumberView.m b/Source/BSLineNumberView.m index 34952c2..003a6f6 100644 --- a/Source/BSLineNumberView.m +++ b/Source/BSLineNumberView.m @@ -81,5 +81,37 @@ line++; } } - + +/** + * Handles the mouse down event (which is adding, deleting, and toggling breakpoints) + */ +- (void)mouseDown:(NSEvent *)event +{ + NSLog(@"mouse down!"); + NSRange visible = [[[sourceView textView] layoutManager] glyphRangeForBoundingRect:[[sourceView scrollView] documentVisibleRect] inTextContainer:[[sourceView textView] textContainer]]; + unsigned line = 1; + unsigned i = 0; + NSPoint p = [self convertPoint:[event locationInWindow] fromView:nil]; + float adjust = (int)([[sourceView scrollView] documentVisibleRect].size.height + [[sourceView scrollView] documentVisibleRect].origin.y) % (int)[self bounds].size.height; + p.y += adjust; + while (i < [[[sourceView textView] layoutManager] numberOfGlyphs]) + { + NSRange fragRange; + NSRect fragRect = [[[sourceView textView] layoutManager] lineFragmentRectForGlyphAtIndex:i effectiveRange:&fragRange]; + fragRect.size.width = [self bounds].size.width; + int hLV = [self bounds].size.height; + int hVR = [[sourceView scrollView] documentVisibleRect].size.height + [[sourceView scrollView] documentVisibleRect].origin.y; + fragRect.origin.y += hVR % hLV; + if (i >= visible.location && NSPointInRect(p, fragRect)) + { + NSLog(@"clicked in %i", line); + break; + } + + i += fragRange.length; + //p.y += fragRect.size.height; + line++; + } +} + @end diff --git a/Source/BSSourceView.h b/Source/BSSourceView.h index 28193f5..da26f82 100644 --- a/Source/BSSourceView.h +++ b/Source/BSSourceView.h @@ -25,12 +25,15 @@ NSScrollView *scrollView; int markedLine; + + id delegate; } @property(readwrite, assign) BSLineNumberView *numberView; @property(readwrite, assign) BSSourceViewTextView *textView; @property(readwrite, assign) NSScrollView *scrollView; @property(readwrite, assign) int markedLine; +@property(readwrite, assign) id delegate; - (void)scrollToLine:(int)line; diff --git a/Source/BSSourceView.m b/Source/BSSourceView.m index a3278c2..6aef6b2 100644 --- a/Source/BSSourceView.m +++ b/Source/BSSourceView.m @@ -22,7 +22,7 @@ @implementation BSSourceView -@synthesize numberView, textView, scrollView, markedLine; +@synthesize numberView, textView, scrollView, markedLine, delegate; /** * Initializes the source view with the path of a file -- 2.22.5