/* # Created by Matteo Rattotti on 13/03/06. # Copyright (c) 2006 - 2007 Shiny Frog. All rights reserved. # Contact matteo.rattotti@shinyfrog.net for any problem # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import "DropView.h" #import "img2icsnController.h" @implementation DropView - (id)initWithFrame:(NSRect)frameRect { if ((self = [super initWithFrame:frameRect]) != nil) { [self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, nil]]; dropImg = nil; //dropImg = [NSImage imageNamed:@"drop"]; //dropImgGlow = [NSImage imageNamed:@"dropGlow"]; dragStatus = 0; } return self; } - (void) setImage:(NSImage*)image{ if(dropImg != nil){ [dropImg release]; dropImg = nil; } dropImg = image; } - (NSDragOperation)draggingEntered:(id )sender { dragStatus = 1; [self setNeedsDisplay:YES]; NSPasteboard *pboard; NSDragOperation sourceDragMask; sourceDragMask = [sender draggingSourceOperationMask]; pboard = [sender draggingPasteboard]; if ( [[pboard types] containsObject:NSFilenamesPboardType] ) { if (sourceDragMask & NSDragOperationLink) { //return NSDragOperationLink; return NSDragOperationCopy; } else if (sourceDragMask & NSDragOperationCopy) { return NSDragOperationCopy; } } return NSDragOperationNone; } -(void) draggingExited:(id )sender{ dragStatus = 0; [self setNeedsDisplay:YES]; } -(void) concludeDragOperation:(id )sender{ dragStatus = 0; [self setNeedsDisplay:YES]; } - (BOOL)performDragOperation:(id )sender { NSPasteboard *pboard; NSDragOperation sourceDragMask; sourceDragMask = [sender draggingSourceOperationMask]; pboard = [sender draggingPasteboard]; if ( [[pboard types] containsObject:NSFilenamesPboardType] ) { NSArray *files = [pboard propertyListForType:NSFilenamesPboardType]; // Depending on the dragging source and modifier keys, // the file data may be copied or linked if (sourceDragMask & NSDragOperationCopy /*NSDragOperationLink*/) { [[NSApp delegate] convert:files]; } else { NSLog(@"Somethings has gone wrong... =P", files); } } return YES; } - (void)drawRect:(NSRect)rect { NSColor *bColor; //NSLog(@"cicia"); if(!dragStatus) //[dropImg compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver]; bColor = [NSColor grayColor]; else //bColor = [NSColor redColor]; bColor = [NSColor colorWithCalibratedRed:0.38 green:0.56 blue:0.67 alpha:1.0]; float borderWidth = 4.0; NSColor *bgColor = [NSColor colorWithCalibratedWhite:0.90 alpha:1]; //NSColor *bgColor = [NSColor colorWithCalibratedWhite:0.0 alpha:0.35]; //NSRect bgRect = rect; NSRect boxRect = [self bounds]; NSRect bgRect = boxRect; bgRect = NSInsetRect(boxRect, borderWidth / 2.0, borderWidth / 2.0); bgRect = NSIntegralRect(bgRect); bgRect.origin.x += 0.5; bgRect.origin.y += 0.5; int minX = NSMinX(bgRect); int midX = NSMidX(bgRect); int maxX = NSMaxX(bgRect); int minY = NSMinY(bgRect); int midY = NSMidY(bgRect); int maxY = NSMaxY(bgRect); float radius = 25.0; // correct value to duplicate Panther's App Switcher NSBezierPath *bgPath = [NSBezierPath bezierPath]; // Bottom edge and bottom-right curve [bgPath moveToPoint:NSMakePoint(midX, minY)]; [bgPath appendBezierPathWithArcFromPoint:NSMakePoint(maxX, minY) toPoint:NSMakePoint(maxX, midY) radius:radius]; // Right edge and top-right curve [bgPath appendBezierPathWithArcFromPoint:NSMakePoint(maxX, maxY) toPoint:NSMakePoint(midX, maxY) radius:radius]; // Top edge and top-left curve [bgPath appendBezierPathWithArcFromPoint:NSMakePoint(minX, maxY) toPoint:NSMakePoint(minX, midY) radius:radius]; // Left edge and bottom-left curve [bgPath appendBezierPathWithArcFromPoint:bgRect.origin toPoint:NSMakePoint(midX, minY) radius:radius]; [bgPath closePath]; [bgColor set]; [bgPath fill]; [bColor set]; [bgPath setLineWidth:borderWidth]; float arr[2]; arr[0] = 30.0; arr[1] = 15.0; [bgPath setLineDash:arr count:2 phase:-8.0]; [bgPath setLineCapStyle:NSRoundLineCapStyle]; [bgPath stroke]; if(dropImg != nil){ NSRect viewSize = [self bounds]; NSSize imageSize = [dropImg size]; NSPoint orig; orig.x = (viewSize.size.width - imageSize.width) / 2; orig.y = (viewSize.size.height - imageSize.height) / 2; //[dropImg compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver]; [dropImg compositeToPoint:orig operation:NSCompositeSourceOver]; } //else // [dropImgGlow compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver]; //[[NSColor blackColor] set]; //NSRectFill(rect); } @end