Revision: 3623
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3623&view=rev
Author:   hofman
Date:     2008-04-04 13:30:32 -0700 (Fri, 04 Apr 2008)

Log Message:
-----------
Event loop for custom text selection, for click-through of transparent 
annotations. Can remove some ivars.

Modified Paths:
--------------
    trunk/SKPDFView.h
    trunk/SKPDFView.m

Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h   2008-04-04 19:18:48 UTC (rev 3622)
+++ trunk/SKPDFView.h   2008-04-04 20:30:32 UTC (rev 3623)
@@ -96,7 +96,6 @@
        PDFAnnotation *activeAnnotation;
        PDFAnnotation *highlightAnnotation;
     NSTextField *editField;
-    PDFSelection *wasSelection;
        NSRect wasBounds;
     NSPoint wasStartPoint;
     NSPoint wasEndPoint;
@@ -106,8 +105,6 @@
     float magnification;
     BOOL didDrag;
     BOOL mouseDownInAnnotation;
-    BOOL extendSelection;
-    BOOL rectSelection;
     int dragMask;
     
     int trackingRect;

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2008-04-04 19:18:48 UTC (rev 3622)
+++ trunk/SKPDFView.m   2008-04-04 20:30:32 UTC (rev 3623)
@@ -207,7 +207,6 @@
     readingBar = nil;
     
     activeAnnotation = nil;
-    wasSelection = nil;
     wasBounds = NSZeroRect;
     wasStartPoint = NSZeroPoint;
     wasEndPoint = NSZeroPoint;
@@ -217,8 +216,6 @@
     magnification = 0.0;
     didDrag = NO;
     mouseDownInAnnotation = NO;
-    extendSelection = NO;
-    rectSelection = NO;
     
     trackingRect = 0;
     hoverRects = CFArrayCreateMutable(NULL, 0, NULL);
@@ -1021,6 +1018,7 @@
                             [self dragWithEvent:theEvent];
                         } else if (nil == activeAnnotation && 
mouseDownInAnnotation) {
                             [self selectTextWithEvent:theEvent];
+                            mouseDownInAnnotation = NO;         
                         } else {
                             [super mouseDown:theEvent];
                             if (floor(NSAppKitVersionNumber) > 
NSAppKitVersionNumber10_4 && toolMode == SKNoteToolMode && hideNotes == NO && 
[self currentSelection] && (annotationMode == SKHighlightNote || annotationMode 
== SKUnderlineNote || annotationMode == SKStrikeOutNote)) {
@@ -1070,8 +1068,6 @@
                          [self setActiveAnnotation:nil];        
                  }      
                  mouseDownInAnnotation = NO;    
-                 [wasSelection release];        
-                 wasSelection = nil;    
                  dragMask = 0;          
             }
             if (toolMode == SKNoteToolMode && hideNotes == NO && [self 
currentSelection] && (annotationMode == SKHighlightNote || annotationMode == 
SKUnderlineNote || annotationMode == SKStrikeOutNote)) {
@@ -1101,13 +1097,9 @@
     switch (toolMode) {
         case SKTextToolMode:
         case SKNoteToolMode:
-            if (nil == activeAnnotation) {
-                if (mouseDownInAnnotation)
-                    // reimplement text selection behavior so we can select 
text inside markup annotation bounds rectangles (and have a highlight and 
strikeout on the same line, for instance), but don't select inside an existing 
markup annotation
-                    [self selectTextWithEvent:theEvent];
-                else
-                    [super mouseDragged:theEvent];
-            }
+            // is this check still necessary?
+            if (nil == activeAnnotation)
+                [super mouseDragged:theEvent];
             break;
         case SKMoveToolMode:
             [super mouseDragged:theEvent];
@@ -3216,44 +3208,44 @@
 }
 
 - (void)selectTextWithEvent:(NSEvent *)theEvent {
-    if ([theEvent type] == NSLeftMouseDown) {
+    // reimplement text selection behavior so we can select text inside markup 
annotation bounds rectangles (and have a highlight and strikeout on the same 
line, for instance), but don't select inside an existing markup annotation
+    PDFSelection *wasSelection = nil;
+    unsigned int modifiers = [theEvent modifierFlags] & 
NSDeviceIndependentModifierFlagsMask;
+    BOOL rectSelection = (modifiers & NSAlternateKeyMask) != 0;
+    BOOL extendSelection = NO;
+    
+    if (rectSelection) {
+        [self setCurrentSelection:nil];
+    } else if ([theEvent clickCount] > 1) {
+        extendSelection = YES;
+        NSPoint p = [self convertPoint:[theEvent locationInWindow] 
fromView:nil];
+        PDFPage *page = [self pageForPoint:p nearest:YES];
+        p = [self convertPoint:p toPage:page];
+        if ([theEvent clickCount] == 2)
+            wasSelection = [[page selectionForWordAtPoint:p] retain];
+        else if ([theEvent clickCount] == 3)
+            wasSelection = [[page selectionForLineAtPoint:p] retain];
+        else
+            wasSelection = nil;
+        [self setCurrentSelection:wasSelection];
+    } else if (modifiers & NSShiftKeyMask) {
+        extendSelection = YES;
+        wasSelection = [[self currentSelection] retain];
+        NSPoint p = [self convertPoint:[theEvent locationInWindow] 
fromView:nil];
+        PDFPage *page = [self pageForPoint:p nearest:YES];
+        p = [self convertPoint:p toPage:page];
+        [self setCurrentSelection:[[self document] 
selectionByExtendingSelection:wasSelection toPage:page atPoint:p]];
+    } else {
+        [self setCurrentSelection:nil];
+    }
+    
+    while (YES) {
+               
+        theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask | 
NSLeftMouseDraggedMask];
+               if ([theEvent type] == NSLeftMouseUp)
+            break;
         
-        unsigned int modifiers = [theEvent modifierFlags] & 
NSDeviceIndependentModifierFlagsMask;
-        
-        if (modifiers & NSAlternateKeyMask) {
-            rectSelection = YES;
-            extendSelection = NO;
-            [self setCurrentSelection:nil];
-        } else if ([theEvent clickCount] > 1) {
-            rectSelection = NO;
-            extendSelection = YES;
-            NSPoint p = [self convertPoint:[theEvent locationInWindow] 
fromView:nil];
-            PDFPage *page = [self pageForPoint:p nearest:YES];
-            p = [self convertPoint:p toPage:page];
-            if ([theEvent clickCount] == 2)
-                wasSelection = [[page selectionForWordAtPoint:p] retain];
-            else if ([theEvent clickCount] == 3)
-                wasSelection = [[page selectionForLineAtPoint:p] retain];
-            else
-                wasSelection = nil;
-            [self setCurrentSelection:wasSelection];
-        } else if (modifiers & NSShiftKeyMask) {
-            rectSelection = NO;
-            extendSelection = YES;
-            wasSelection = [[self currentSelection] retain];
-            NSPoint p = [self convertPoint:[theEvent locationInWindow] 
fromView:nil];
-            PDFPage *page = [self pageForPoint:p nearest:YES];
-            p = [self convertPoint:p toPage:page];
-            [self setCurrentSelection:[[self document] 
selectionByExtendingSelection:wasSelection toPage:page atPoint:p]];
-        } else {
-            rectSelection = NO;
-            extendSelection = NO;
-            [self setCurrentSelection:nil];
-        }
-        
-    } else if ([theEvent type] == NSLeftMouseDragged) {
-        // reimplement text selection behavior so we can select text inside 
markup annotation bounds rectangles (and have a highlight and strikeout on the 
same line, for instance), but don't select inside an existing markup annotation
-
+        // dragging
         // if we autoscroll, the mouseDownLoc is no longer correct as a 
starting point
         NSPoint mouseDownLocInDoc = [[self documentView] 
convertPoint:mouseDownLoc fromView:nil];
         if ([[self documentView] autoscroll:theEvent])
@@ -3287,6 +3279,11 @@
         [self setCurrentSelection:sel];
         
     }
+    
+    if (toolMode == SKNoteToolMode && hideNotes == NO && [self 
currentSelection] && (annotationMode == SKHighlightNote || annotationMode == 
SKUnderlineNote || annotationMode == SKStrikeOutNote)) {
+        [self addAnnotationWithType:annotationMode];
+        [self setCurrentSelection:nil];
+    }
 }
 
 - (void)dragReadingBarWithEvent:(NSEvent *)theEvent {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to