Revision: 7533 http://skim-app.svn.sourceforge.net/skim-app/?rev=7533&view=rev Author: hofman Date: 2011-11-09 11:29:38 +0000 (Wed, 09 Nov 2011) Log Message: ----------- convenience method for common procedure of getting event location in a view
Modified Paths: -------------- trunk/NSEvent_SKExtensions.h trunk/NSEvent_SKExtensions.m trunk/SKColorSwatch.m trunk/SKDragImageView.m trunk/SKNoteOutlineView.m trunk/SKPDFView.m trunk/SKSecondaryPDFView.m trunk/SKSideWindow.m trunk/SKSnapshotPDFView.m trunk/SKStatusBar.m trunk/SKTextWithIconCell.m trunk/SKThumbnailTableView.m Modified: trunk/NSEvent_SKExtensions.h =================================================================== --- trunk/NSEvent_SKExtensions.h 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/NSEvent_SKExtensions.h 2011-11-09 11:29:38 UTC (rev 7533) @@ -43,10 +43,15 @@ }; @interface NSEvent (SKExtensions) + + (NSUInteger)standardModifierFlags; - (NSUInteger)deviceIndependentModifierFlags; - (NSUInteger)standardModifierFlags; + - (unichar)firstCharacter; + +- (NSPoint)locationInView:(NSView *)view; + @end @interface NSEvent (SKLeopardGestures) Modified: trunk/NSEvent_SKExtensions.m =================================================================== --- trunk/NSEvent_SKExtensions.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/NSEvent_SKExtensions.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -81,4 +81,8 @@ return [characters length] > 0 ? [characters characterAtIndex:0] : 0; } +- (NSPoint)locationInView:(NSView *)view { + return [view convertPoint:[self locationInWindow] fromView:nil]; +} + @end Modified: trunk/SKColorSwatch.m =================================================================== --- trunk/SKColorSwatch.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKColorSwatch.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -182,7 +182,7 @@ } - (void)mouseDown:(NSEvent *)theEvent { - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; NSInteger i = [self colorIndexAtPoint:mouseLoc]; if ([self isEnabled]) { @@ -220,7 +220,7 @@ [color drawSwatchInRect:NSInsetRect(rect, 1.0, 1.0)]; [image unlockFocus]; - mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + mouseLoc = [theEvent locationInView:self]; mouseLoc.x -= 6.0; mouseLoc.y -= 6.0; [self dragImage:image at:mouseLoc offset:NSZeroSize event:theEvent pasteboard:pboard source:self slideBack:YES]; Modified: trunk/SKDragImageView.m =================================================================== --- trunk/SKDragImageView.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKDragImageView.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -38,6 +38,7 @@ #import "SKDragImageView.h" #import "NSMenu_SKExtensions.h" +#import "NSEvent_SKExtensions.h" @implementation SKDragImageView @@ -111,7 +112,7 @@ NSPoint mouseLoc; while(keepOn){ theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask]; - mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + mouseLoc = [theEvent locationInView:self]; isInside = [self mouse:mouseLoc inRect:[self bounds]]; switch ([theEvent type]) { case NSLeftMouseDragged: Modified: trunk/SKNoteOutlineView.m =================================================================== --- trunk/SKNoteOutlineView.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKNoteOutlineView.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -57,7 +57,7 @@ - (void)resizeRow:(NSInteger)row withEvent:(NSEvent *)theEvent { id item = [self itemAtRow:row]; - NSPoint startPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint startPoint = [theEvent locationInView:self]; CGFloat startHeight = [[self delegate] outlineView:self heightOfRowByItem:item]; [[NSCursor resizeUpDownCursor] push]; @@ -65,7 +65,7 @@ while ([theEvent type] != NSLeftMouseUp) { theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask]; if ([theEvent type] == NSLeftMouseDragged) { - NSPoint currentPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint currentPoint = [theEvent locationInView:self]; CGFloat currentHeight = fmax([self rowHeight], startHeight + currentPoint.y - startPoint.y); [[self delegate] outlineView:self setHeight:currentHeight ofRowByItem:item]; @@ -77,7 +77,7 @@ - (void)mouseDown:(NSEvent *)theEvent { if ([theEvent clickCount] == 1 && [[self delegate] respondsToSelector:@selector(outlineView:canResizeRowByItem:)] && [[self delegate] respondsToSelector:@selector(outlineView:setHeight:ofRowByItem:)]) { - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; NSInteger row = [self rowAtPoint:mouseLoc]; if (row != -1 && [[self delegate] outlineView:self canResizeRowByItem:[self itemAtRow:row]]) { Modified: trunk/SKPDFView.m =================================================================== --- trunk/SKPDFView.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKPDFView.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -1125,7 +1125,7 @@ [self doPdfsyncWithEvent:theEvent]; } else { PDFAreaOfInterest area = [self areaOfInterestForMouse:theEvent]; - NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint p = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:p nearest:YES]; p = [self convertPoint:p toPage:page]; BOOL hitAnnotation = NO; @@ -1354,7 +1354,7 @@ [menu insertItem:[NSMenuItem separatorItem] atIndex:0]; - NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint point = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:point nearest:YES]; PDFAnnotation *annotation = nil; @@ -1493,7 +1493,7 @@ - (void)beginGestureWithEvent:(NSEvent *)theEvent { if ([[SKPDFView superclass] instancesRespondToSelector:_cmd]) [super beginGestureWithEvent:theEvent]; - PDFPage *page = [self pageForPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil] nearest:YES]; + PDFPage *page = [self pageForPoint:[theEvent locationInView:self] nearest:YES]; gestureRotation = 0.0; gesturePageIndex = [(page ?: [self currentPage]) pageIndex]; } @@ -2934,7 +2934,7 @@ // Move annotation. [[self documentView] autoscroll:theEvent]; - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; PDFPage *newActivePage = [self pageForPoint:mouseLoc nearest:YES]; if (newActivePage) { // newActivePage should never be nil, but just to be sure @@ -2957,7 +2957,7 @@ - (void)doResizeLineAnnotationWithEvent:(NSEvent *)theEvent fromPoint:(NSPoint)originalPagePoint originalStartPoint:(NSPoint)originalStartPoint originalEndPoint:(NSPoint)originalEndPoint resizeHandle:(SKRectEdges)resizeHandle { PDFPage *page = [activeAnnotation page]; NSRect pageBounds = [page boundsForBox:[self displayBox]]; - NSPoint currentPagePoint = [self convertPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil] toPage:page]; + NSPoint currentPagePoint = [self convertPoint:[theEvent locationInView:self] toPage:page]; NSPoint relPoint = SKSubstractPoints(currentPagePoint, originalPagePoint); NSPoint endPoint = originalEndPoint; NSPoint startPoint = originalStartPoint; @@ -3004,7 +3004,7 @@ PDFPage *page = [activeAnnotation page]; NSRect newBounds = originalBounds; NSRect pageBounds = [page boundsForBox:[self displayBox]]; - NSPoint currentPagePoint = [self convertPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil] toPage:page]; + NSPoint currentPagePoint = [self convertPoint:[theEvent locationInView:self] toPage:page]; NSPoint relPoint = SKSubstractPoints(currentPagePoint, originalPagePoint); if (NSEqualSizes(originalBounds.size, NSZeroSize)) { @@ -3112,7 +3112,7 @@ // Old (current) annotation location and click point relative to it NSRect originalBounds = [activeAnnotation bounds]; BOOL isLine = [[activeAnnotation type] isEqualToString:SKNLineString]; - NSPoint mouseDownLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseDownLoc = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:mouseDownLoc nearest:YES]; NSPoint pagePoint = [self convertPoint:mouseDownLoc toPage:page]; @@ -3182,7 +3182,7 @@ while (YES) { theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask]; - p = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + p = [theEvent locationInView:self]; page = [self pageForPoint:p nearest:NO]; if (page == annotationPage && NSPointInRect([self convertPoint:p toPage:page], bounds)) @@ -3205,7 +3205,7 @@ PDFPage *page; // Mouse in display view coordinates. - NSPoint mouseDownOnPage = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseDownOnPage = [theEvent locationInView:self]; BOOL mouseDownInAnnotation = NO; BOOL isInk = toolMode == SKNoteToolMode && annotationMode == SKInkNote; @@ -3314,7 +3314,7 @@ } - (void)doDrawFreehandNoteWithEvent:(NSEvent *)theEvent { - NSPoint mouseDownLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseDownLoc = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:mouseDownLoc nearest:YES]; BOOL didDraw = NO; @@ -3345,7 +3345,7 @@ theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask]; if ([theEvent type] == NSLeftMouseUp) break; - [bezierPath lineToPoint:[self convertPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil] toPage:page]]; + [bezierPath lineToPoint:[self convertPoint:[theEvent locationInView:self] toPage:page]]; [self setNeedsDisplayInRect:[self convertRect:NSInsetRect([bezierPath nonEmptyBounds], -8.0, -8.0) fromPage:page]]; didDraw = YES; } @@ -3413,7 +3413,7 @@ } - (void)doSelectWithEvent:(NSEvent *)theEvent { - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:mouseLoc nearest:NO]; if (page == nil) { @@ -3465,7 +3465,7 @@ NSRect newRect = initialRect; NSPoint delta; - newPoint = [self convertPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil] toPage:page]; + newPoint = [self convertPoint:[theEvent locationInView:self] toPage:page]; delta = SKSubstractPoints(newPoint, initialPoint); if (resizeHandle == 0) { @@ -3597,7 +3597,7 @@ [self setCurrentSelection:nil]; } else if ([theEvent clickCount] > 1) { extendSelection = YES; - NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint p = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:p nearest:YES]; p = [self convertPoint:p toPage:page]; if ([theEvent clickCount] == 2) @@ -3611,7 +3611,7 @@ extendSelection = YES; if ([[self currentSelection] hasCharacters]) wasSelection = [[self currentSelection] retain]; - NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint p = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:p nearest:YES]; p = [self convertPoint:p toPage:page]; [self setCurrentSelection:[[self document] selectionByExtendingSelection:wasSelection toPage:page atPoint:p]]; @@ -3635,7 +3635,7 @@ PDFPage *page1 = [self pageForPoint:p1 nearest:YES]; p1 = [self convertPoint:p1 toPage:page1]; - NSPoint p2 = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint p2 = [theEvent locationInView:self]; PDFPage *page2 = [self pageForPoint:p2 nearest:YES]; p2 = [self convertPoint:p2 toPage:page2]; @@ -3676,7 +3676,7 @@ NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:page, SKPDFViewOldPageKey, nil]; NSEvent *lastMouseEvent = theEvent; - NSPoint lastMouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint lastMouseLoc = [theEvent locationInView:self]; NSPoint point = [self convertPoint:lastMouseLoc toPage:page]; NSInteger lineOffset = SKIndexOfRectAtYInOrderedRects(point.y, lineRects, YES) - [readingBar currentLine]; NSDate *lastPageChangeDate = [NSDate distantPast]; @@ -3770,7 +3770,7 @@ break; // dragging - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; if ([[self pageForPoint:mouseLoc nearest:YES] isEqual:page] == NO) continue; @@ -4056,7 +4056,7 @@ if ([document respondsToSelector:@selector(synchronizer)]) { - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:mouseLoc nearest:YES]; NSPoint location = [self convertPoint:mouseLoc toPage:page]; NSUInteger pageIndex = [page pageIndex]; @@ -4114,7 +4114,7 @@ } - (NSCursor *)getCursorForEvent:(NSEvent *)theEvent { - NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint p = [theEvent locationInView:self]; NSCursor *cursor = nil; if ([[self document] isLocked]) { Modified: trunk/SKSecondaryPDFView.m =================================================================== --- trunk/SKSecondaryPDFView.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKSecondaryPDFView.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -560,7 +560,7 @@ [NSCursor pop]; [self performSelector:@selector(mouseMoved:) withObject:lastEvent afterDelay:0]; - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:mouseLoc nearest:YES]; NSPoint location = [self convertPoint:mouseLoc toPage:page]; [synchronizedPDFView goToDestination:[[[PDFDestination alloc] initWithPage:page atPoint:location] autorelease]]; @@ -576,7 +576,7 @@ if ([document respondsToSelector:@selector(synchronizer)]) { - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:mouseLoc nearest:YES]; NSPoint location = [self convertPoint:mouseLoc toPage:page]; NSUInteger pageIndex = [page pageIndex]; @@ -597,7 +597,7 @@ - (void)mouseMoved:(NSEvent *)theEvent { NSView *view = [self documentView]; - NSPoint mouseLoc = [view convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:view]; if (NSMouseInRect(mouseLoc, [view visibleRect], [view isFlipped])) [[NSCursor openHandCursor] set]; else Modified: trunk/SKSideWindow.m =================================================================== --- trunk/SKSideWindow.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKSideWindow.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -407,7 +407,7 @@ } - (void)mouseDown:(NSEvent *)theEvent { - if (NSMouseInRect([self convertPoint:[theEvent locationInWindow] fromView:nil], [self resizeHandleRect], [self isFlipped])) + if (NSMouseInRect([theEvent locationInView:self], [self resizeHandleRect], [self isFlipped])) [(SKSideWindow *)[self window] resizeWithEvent:theEvent]; else [super mouseDown:theEvent]; Modified: trunk/SKSnapshotPDFView.m =================================================================== --- trunk/SKSnapshotPDFView.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKSnapshotPDFView.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -431,7 +431,7 @@ if ([document respondsToSelector:@selector(synchronizer)]) { - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; PDFPage *page = [self pageForPoint:mouseLoc nearest:YES]; NSPoint location = [self convertPoint:mouseLoc toPage:page]; NSUInteger pageIndex = [page pageIndex]; @@ -448,7 +448,7 @@ - (void)mouseUp:(NSEvent *)theEvent{ [NSCursor pop]; NSView *view = [self documentView]; - NSPoint mouseLoc = [view convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:view]; if (NSMouseInRect(mouseLoc, [view visibleRect], [view isFlipped])) [[NSCursor openHandCursor] set]; else Modified: trunk/SKStatusBar.m =================================================================== --- trunk/SKStatusBar.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKStatusBar.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -39,6 +39,7 @@ #import "SKStatusBar.h" #import "NSGeometry_SKExtensions.h" #import "SKStringConstants.h" +#import "NSEvent_SKExtensions.h" #define LEFT_MARGIN 5.0 #define RIGHT_MARGIN 15.0 @@ -237,13 +238,13 @@ } - (void)mouseDown:(NSEvent *)theEvent { - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + NSPoint mouseLoc = [theEvent locationInView:self]; NSRect leftRect, rightRect; [self getLeftFrame:&leftRect rightFrame:&rightRect]; if (NSMouseInRect(mouseLoc, rightRect, [self isFlipped]) && [rightCell action]) { while ([theEvent type] != NSLeftMouseUp) theEvent = [[self window] nextEventMatchingMask: NSLeftMouseDraggedMask | NSLeftMouseUpMask]; - mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + mouseLoc = [theEvent locationInView:self]; if (NSMouseInRect(mouseLoc, rightRect, [self isFlipped])) { [rightCell setNextState]; [NSApp sendAction:[rightCell action] to:[rightCell target] from:self]; @@ -251,7 +252,7 @@ } else if (NSMouseInRect(mouseLoc, leftRect, [self isFlipped]) && [leftCell action]) { while ([theEvent type] != NSLeftMouseUp) theEvent = [[self window] nextEventMatchingMask: NSLeftMouseDraggedMask | NSLeftMouseUpMask]; - mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + mouseLoc = [theEvent locationInView:self]; if (NSMouseInRect(mouseLoc, leftRect, [self isFlipped])) { [leftCell setNextState]; [NSApp sendAction:[leftCell action] to:[leftCell target] from:self]; Modified: trunk/SKTextWithIconCell.m =================================================================== --- trunk/SKTextWithIconCell.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKTextWithIconCell.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -39,6 +39,7 @@ #import "SKTextWithIconCell.h" #import "NSImage_SKExtensions.h" #import "NSGeometry_SKExtensions.h" +#import "NSEvent_SKExtensions.h" NSString *SKTextWithIconCellStringKey = @"string"; NSString *SKTextWithIconCellImageKey = @"image"; @@ -153,7 +154,7 @@ - (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView { NSRect textRect = [self textRectForBounds:cellFrame]; - NSPoint mouseLoc = [controlView convertPoint:[event locationInWindow] fromView:nil]; + NSPoint mouseLoc = [event locationInView:controlView]; NSUInteger hit = NSCellHitNone; if (NSMouseInRect(mouseLoc, textRect, [controlView isFlipped])) hit = [super hitTestForEvent:event inRect:textRect ofView:controlView]; Modified: trunk/SKThumbnailTableView.m =================================================================== --- trunk/SKThumbnailTableView.m 2011-11-09 11:16:33 UTC (rev 7532) +++ trunk/SKThumbnailTableView.m 2011-11-09 11:29:38 UTC (rev 7533) @@ -39,6 +39,7 @@ #import "SKThumbnailTableView.h" #import "SKTypeSelectHelper.h" #import "NSColor_SKExtensions.h" +#import "NSEvent_SKExtensions.h" #define SKScrollerWillScrollNotification @"SKScrollerWillScrollNotification" #define SKScrollerDidScrollNotification @"SKScrollerDidScrollNotification" @@ -156,7 +157,7 @@ - (void)mouseDown:(NSEvent *)theEvent { if (([theEvent modifierFlags] & NSCommandKeyMask) && [[self delegate] respondsToSelector:@selector(tableView:commandSelectRow:)]) { - NSInteger row = [self rowAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]]; + NSInteger row = [self rowAtPoint:[theEvent locationInView:self]]; if (row != -1 && [[self delegate] tableView:self commandSelectRow:row]) return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ RSA(R) Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1 _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit