Re: Getting an image path from NSImageView
Re: Getting an image path from NSImageView
- Subject: Re: Getting an image path from NSImageView
- From: Ian was here <email@hidden>
- Date: Sun, 20 Mar 2005 13:15:38 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
OK, so basically I have to do the drag and drop
manually in order to get the path, rather than
allowing it to happen automatically.
Thanks
--- Stéphane Sudre <email@hidden> wrote:
>
> 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 you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
_______________________________________________
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