Revision: 2675
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2675&view=rev
Author:   hofman
Date:     2007-08-17 07:49:07 -0700 (Fri, 17 Aug 2007)

Log Message:
-----------
Implement dragging image from note window. Use cell interior as default drag 
image. Update keyboard focus ring when dragging into image view.

Modified Paths:
--------------
    trunk/BDSKDragImageView.m
    trunk/SKNoteWindowController.m

Modified: trunk/BDSKDragImageView.m
===================================================================
--- trunk/BDSKDragImageView.m   2007-08-17 10:18:26 UTC (rev 2674)
+++ trunk/BDSKDragImageView.m   2007-08-17 14:49:07 UTC (rev 2675)
@@ -71,6 +71,7 @@
                dragOp = [delegate dragImageView:self validateDrop:sender];
        if (dragOp != NSDragOperationNone) {
                highlight = YES;
+        [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
                [self setNeedsDisplay:YES];
        }
        return dragOp;
@@ -78,11 +79,13 @@
 
 - (void)draggingExited:(id <NSDraggingInfo>)sender{
     highlight = NO;
+    [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
        [self setNeedsDisplay:YES];
 }
 
 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
     highlight = NO;
+    [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
        [self setNeedsDisplay:YES];
        if ([delegate respondsToSelector:@selector(dragImageView:acceptDrop:)])
                return [delegate dragImageView:self acceptDrop:sender];
@@ -106,22 +109,33 @@
                                        if ([delegate 
respondsToSelector:@selector(dragImageView:writeDataToPasteboard:)] &&
                                                [delegate dragImageView:self 
writeDataToPasteboard:pboard]) {
                    
-                                               NSImage *image;
-                                               NSImage *dragImage;
-                                               NSSize imageSize;
-                                               if ([delegate 
respondsToSelector:@selector(dragImageForDragImageView:)])
-                                                       image = [delegate 
dragImageForDragImageView:self];
-                                               else
-                                                       image = [self image];
-                                               imageSize = [image size];
-                                               
-                                               dragImage = [[NSImage alloc] 
initWithSize:imageSize];
-                                               [dragImage lockFocus];
-                                               [image 
compositeToPoint:NSZeroPoint operation:NSCompositeCopy fraction:0.7];
-                                               [dragImage unlockFocus];
+                                               NSImage *dragImage = nil;
+                        NSPoint dragPoint = mouseLoc;
+                                               if ([delegate 
respondsToSelector:@selector(dragImageForDragImageView:)]) {
+                                                       dragImage = [delegate 
dragImageForDragImageView:self];
+                            NSSize imageSize = [dragImage size];
+                            dragPoint.x -= floorf(0.5 * imageSize.width);
+                            dragPoint.y -= floorf(0.5 * imageSize.height);
+                                               }
+                        if (dragImage == nil) {
+                            NSRect rect = [self bounds];
+                            
+                            dragPoint = rect.origin;
+                            rect.origin = NSZeroPoint;
+                            
+                            NSImage *image = [[NSImage alloc] 
initWithSize:rect.size];
 
-                                               [self dragImage:dragImage 
at:NSMakePoint(mouseLoc.x - 0.5f * imageSize.width, mouseLoc.y - 0.5f * 
imageSize.height) offset:NSZeroSize event:theEvent pasteboard:pboard 
source:self slideBack:YES]; 
-                                               [dragImage release];
+                            [image lockFocus];
+                            [[self cell] drawInteriorWithFrame:rect 
inView:self];
+                            [image lockFocus];
+                            
+                            dragImage = [[[NSImage alloc] 
initWithSize:rect.size] autorelease];
+                            [dragImage lockFocus];
+                            [image compositeToPoint:NSZeroPoint 
operation:NSCompositeCopy fraction:0.7];
+                            [dragImage unlockFocus];
+                            [image release];
+                        }
+                        [self dragImage:dragImage at:dragPoint 
offset:NSZeroSize event:theEvent pasteboard:pboard source:self slideBack:YES]; 
                     }
                                        keepOn = NO;
                     break;

Modified: trunk/SKNoteWindowController.m
===================================================================
--- trunk/SKNoteWindowController.m      2007-08-17 10:18:26 UTC (rev 2674)
+++ trunk/SKNoteWindowController.m      2007-08-17 14:49:07 UTC (rev 2675)
@@ -189,6 +189,37 @@
     } else return NO;
 }
 
+- (BOOL)dragImageView:(BDSKDragImageView *)view 
writeDataToPasteboard:(NSPasteboard *)pasteboard {
+    NSImage *image = [self isNoteType] ? [(SKPDFAnnotationNote *)note image] : 
nil;
+    if (image) {
+        NSString *name = [note contents];
+        if ([name length] == 0)
+            name = @"NoteImage";
+        [pasteboard declareTypes:[NSArray 
arrayWithObjects:NSFilesPromisePboardType, NSTIFFPboardType, nil] owner:nil];
+        [pasteboard setPropertyList:[NSArray arrayWithObjects:[name 
stringByAppendingPathExtension:@"tiff"], nil] forType:NSFilesPromisePboardType];
+        [pasteboard setData:[image TIFFRepresentation] 
forType:NSTIFFPboardType];
+        return YES;
+    } else return NO;
+}
+
+- (NSArray *)dragImageView:(BDSKDragImageView *)view 
namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination {
+    NSImage *image = [self isNoteType] ? [(SKPDFAnnotationNote *)note image] : 
nil;
+    if (image) {
+        NSString *name = [note contents];
+        if ([name length] == 0)
+            name = @"NoteImage";
+        NSString *basePath = [[dropDestination path] 
stringByAppendingPathComponent:[note contents]];
+        NSString *path = [basePath stringByAppendingPathExtension:@"tiff"];
+        int i = 0;
+        NSFileManager *fm = [NSFileManager defaultManager];
+        while ([fm fileExistsAtPath:path])
+            path = [[basePath stringByAppendingFormat:@"-%i", ++i] 
stringByAppendingPathExtension:@"tiff"];
+        if ([[image TIFFRepresentation] writeToFile:path atomically:YES])
+            return [NSArray arrayWithObjects:[path lastPathComponent], nil];
+    }
+    return nil;
+}
+
 @end
 
 


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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to