Revision: 2392
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2392&view=rev
Author:   hofman
Date:     2007-06-29 14:52:57 -0700 (Fri, 29 Jun 2007)

Log Message:
-----------
Implement dragging destination for color and line styles on notes.

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

Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h   2007-06-29 19:17:07 UTC (rev 2391)
+++ trunk/SKPDFView.h   2007-06-29 21:52:57 UTC (rev 2392)
@@ -87,6 +87,7 @@
     SKReadingBar *readingBar;
     
        PDFAnnotation *activeAnnotation;
+       PDFAnnotation *highlightAnnotation;
        PDFAnnotationTextWidget *editAnnotation;
     PDFSelection *wasSelection;
        NSRect wasBounds;

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2007-06-29 19:17:07 UTC (rev 2391)
+++ trunk/SKPDFView.m   2007-06-29 21:52:57 UTC (rev 2392)
@@ -52,6 +52,7 @@
 #import "SKPDFSynchronizer.h"
 #import "PDFSelection_SKExtensions.h"
 #import "NSBezierPath_BDSKExtensions.h"
+#import "SKLineWell.h"
 #import <Carbon/Carbon.h>
 
 NSString *SKPDFViewToolModeChangedNotification = 
@"SKPDFViewToolModeChangedNotification";
@@ -180,6 +181,8 @@
     
     trackingRect = 0;
     
+    [self registerForDraggedTypes:[NSArray arrayWithObjects:NSColorPboardType, 
SKLineStylePboardType, nil]];
+    
     [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleAnnotationWillChangeNotification:) 
                                                  
name:SKAnnotationWillChangeNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleAnnotationDidChangeNotification:) 
@@ -284,6 +287,13 @@
                 }
             }
         }
+        if (highlightAnnotation && [[highlightAnnotation page] 
isEqual:pdfPage]) {
+            float color[4] = { 0.0, 0.0, 0.0, 1.0 };
+            NSRect bounds = [highlightAnnotation bounds];
+            NSRect rect = NSInsetRect(NSIntegralRect(bounds), 0.5, 0.5);
+            CGContextSetStrokeColor(context, color);
+            CGContextStrokeRectWithWidth(context, *(CGRect *)&rect, 1.0);
+        }
                 
     }
     
@@ -1185,6 +1195,106 @@
     trackingRect = [self addTrackingRect:[self bounds] owner:self 
userData:NULL assumeInside:NO];
 }
 
+#pragma mark NSDraggingDestination protocol
+
+- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
+    NSDragOperation dragOp = NSDragOperationNone;
+    NSPasteboard *pboard = [sender draggingPasteboard];
+    NSString *pboardType = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:NSColorPboardType, SKLineStylePboardType, nil]];
+    if (pboardType) {
+        return [self draggingUpdated:sender];
+    } else if ([[self superclass] instancesRespondToSelector:_cmd]) {
+        dragOp = [super draggingEntered:sender];
+    }
+    return dragOp;
+}
+
+- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender {
+    NSDragOperation dragOp = NSDragOperationNone;
+    NSPasteboard *pboard = [sender draggingPasteboard];
+    NSString *pboardType = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:NSColorPboardType, SKLineStylePboardType, nil]];
+    if (pboardType) {
+        NSPoint location = [self convertPoint:[sender draggingLocation] 
fromView:nil];
+        PDFPage *page = [self pageForPoint:location nearest:NO];
+        if (page) {
+            NSArray *annotations = [page annotations];
+            PDFAnnotation *annotation = nil;
+            int i = [annotations count];
+            location = [self convertPoint:location toPage:page];
+            while (i-- > 0) {
+                annotation = [annotations objectAtIndex:i];
+                NSString *type = [annotation type];
+                if ([annotation isNoteAnnotation] && [annotation 
hitTest:location] && 
+                    ([pboardType isEqualToString:NSColorPboardType] || [type 
isEqualToString:@"Text"] || [type isEqualToString:@"Circle"] || [type 
isEqualToString:@"Square"] || [type isEqualToString:@"Line"])) {
+                    if ([annotation isEqual:highlightAnnotation] == NO) {
+                        if (highlightAnnotation)
+                            [self 
setNeedsDisplayForAnnotation:highlightAnnotation];
+                        highlightAnnotation = annotation;
+                        [self 
setNeedsDisplayForAnnotation:highlightAnnotation];
+                    }
+                    dragOp = NSDragOperationEvery;
+                    break;
+                }
+            }
+        }
+        if (dragOp == NSDragOperationNone && highlightAnnotation) {
+            [self setNeedsDisplayForAnnotation:highlightAnnotation];
+            highlightAnnotation = nil;
+        }
+    } else if ([[self superclass] instancesRespondToSelector:_cmd]) {
+        dragOp = [super draggingUpdated:sender];
+    }
+    return dragOp;
+}
+
+- (void)draggingExited:(id <NSDraggingInfo>)sender {
+    NSPasteboard *pboard = [sender draggingPasteboard];
+    NSString *pboardType = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:NSColorPboardType, SKLineStylePboardType, nil]];
+    if (pboardType) {
+        if (highlightAnnotation) {
+            [self setNeedsDisplayForAnnotation:highlightAnnotation];
+            highlightAnnotation = nil;
+        }
+    } else if ([[self superclass] instancesRespondToSelector:_cmd]) {
+        [super draggingExited:sender];
+    }
+}
+
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
+    BOOL performedDrag = NO;
+    NSPasteboard *pboard = [sender draggingPasteboard];
+    NSString *pboardType = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:NSColorPboardType, SKLineStylePboardType, nil]];
+    if (pboardType) {
+        if (highlightAnnotation) {
+            NSString *type = [highlightAnnotation type];
+            if ([pboardType isEqualToString:NSColorPboardType]) {
+                [highlightAnnotation setColor:[NSColor 
colorFromPasteboard:pboard]];
+                performedDrag = YES;
+            } else if ([type isEqualToString:@"Text"] || [type 
isEqualToString:@"Circle"] || [type isEqualToString:@"Square"] || [type 
isEqualToString:@"Line"]) {
+                NSDictionary *dict = [pboard 
propertyListForType:SKLineStylePboardType];
+                NSNumber *number;
+                if (number = [dict objectForKey:@"lineWidth"])
+                    [highlightAnnotation setLineWidth:[number floatValue]];
+                if (number = [dict objectForKey:@"style"])
+                    [highlightAnnotation setBorderStyle:[number intValue]];
+                [highlightAnnotation setDashPattern:[dict 
objectForKey:@"dashPattern"]];
+                if ([type isEqualToString:@"Line"]) {
+                    if (number = [dict objectForKey:@"startLineStyle"])
+                        [(SKPDFAnnotationLine *)highlightAnnotation 
setStartLineStyle:[number intValue]];
+                    if (number = [dict objectForKey:@"endLineStyle"])
+                        [(SKPDFAnnotationLine *)highlightAnnotation 
setEndLineStyle:[number intValue]];
+                }
+                performedDrag = YES;
+            }
+            [self setNeedsDisplayForAnnotation:highlightAnnotation];
+            highlightAnnotation = nil;
+        }
+    } else if ([[self superclass] instancesRespondToSelector:_cmd]) {
+        performedDrag = [super performDragOperation:sender];
+    }
+    return performedDrag;
+}
+
 #pragma mark UndoManager
 
 - (NSUndoManager *)undoManager {


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

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to