Re: Getting an image path from NSImageView
Re: Getting an image path from NSImageView
- Subject: Re: Getting an image path from NSImageView
- From: Stéphane Sudre <email@hidden>
- Date: Sun, 20 Mar 2005 19:40:29 +0100
On dimanche, mars 20, 2005, at 06:57 PM, Ian was here wrote:
I have created an application that allows a user to
add a photo to their file. There are two ways the user
can add the photo. The first is using an open file
dialog and choose an image. The second is to just drag
an image onto the image view.
The issue is this: I need the path to where the photo
came from. With the open file dialog, that's easy.
Does anyone know how to get the path to a photo that
has been dragged onto an image view?
#import <AppKit/AppKit.h>
@interface MyImageView : NSImageView
{
id delegate_;
BOOL highlighted_;
}
- (id) delegate;
- (void) setDelegate:(id) inDelegate;
@end
#import "MyImageView.h"
@implementation MyImageView
- (id) delegate
{
return delegate_;
}
- (void) setDelegate:(id) inDelegate
{
delegate_=inDelegate;
}
- (void)drawRect:(NSRect)rect
{
/*if (highlighted_==YES)
{
[[NSColor redColor] set];
NSRectFill(rect);
}
else*/
{
[super drawRect:rect];
}
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] )
{
if (sourceDragMask & NSDragOperationCopy)
{
highlighted_=YES;
[self setNeedsDisplay:YES];
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] )
{
NSArray *files = [pboard
propertyListForType:NSFilenamesPboardType];
if (delegate_!=nil)
{
if ([delegate_
respondsToSelector:@selector(loadPicture:)]==YES)
{
[delegate_ performSelector:@selector(loadPicture:)
withObject:[files objectAtIndex:0]];
}
}
}
return YES;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
highlighted_=NO;
[self setNeedsDisplay:YES];
return YES;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
highlighted_=NO;
[self setNeedsDisplay:YES];
}
@end
-----------8<----------8<------------8<------------
Anything else?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden