Re: drag-n-drop ( getting desperate / someone please help )
Re: drag-n-drop ( getting desperate / someone please help )
- Subject: Re: drag-n-drop ( getting desperate / someone please help )
- From: Ryan Stevens <email@hidden>
- Date: Thu, 16 Jun 2005 18:52:54 -0700
On Jun 16, 2005, at 5:07 PM, Chase wrote:
do i need to specify filetyes i'm interested in in info.plist ?
or is calling registerForDraggedTypes: enough?
- chase
On Jun 16, 2005, at 4:14 PM, Chase wrote:
i posted this late, late last night. i think i'll have better
chances of someone who knows what i'm doing wrong actually seeing
this if i post agin now in the middle of the day. also, i'm now
including **all** relevant code, so there's no confusion about
what i'm doing on this end:
the problem is that i'm simply trying to implement drag-n-drop of
files from the finder into an nswindow. none of the
NSDraggingDestination methods that i'm implementing are getting
called when i drop a file into the window from the finder.
here's the entire code i've got so far for the window subclass:
#import <Cocoa/Cocoa.h>
@interface testwinclass : NSWindow { }
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
- (void)draggingExited:(id <NSDraggingInfo>)sender;
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
@end
@implementation testwinclass
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned
int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)
flag {
self = [super initWithContentRect:contentRect
styleMask:styleMask backing:backingType defer:flag];
if (self) {
[self registerForDraggedTypes:[NSArray
arrayWithObjects:NSFilenamesPboardType, nil]];
}
return self;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
NSLog(@"draggingEntered");
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
if (sourceDragMask & NSDragOperationLink) {
return NSDragOperationLink;
} else if (sourceDragMask & NSDragOperationCopy) {
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender {
NSLog(@"draggingUpdated");
return NSDragOperationCopy;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {
NSLog(@"draggingExited");
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
NSLog(@"prepareForDragOperation");
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSPasteboard *pboard = [sender draggingPasteboard];
NSLog(@"performDragOperation");
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
NSArray *files = [pboard
propertyListForType:NSFilenamesPboardType];
int numberOfFiles = [files count];
if (numberOfFiles>0) {
NSLog(@"%d file(s) : %@", numberOfFiles, [files
objectAtIndex:0]);
}
}
return YES;
}
@end
in my controller class, i'm instantiating the window with:
t_win = [[testwinclass alloc] initWithContentRect:(NSRect)
{200, 200, 200, 200}
t_win = [[testwinclass alloc] initWithContentRect:NSMakeRect(200,
200, 200, 200)
yes, no?
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered
defer:NO];
please, someone take a minute or two to look at this and tell me
what i'm missing or doing wrong. i'm sure it's something simple.
thanks.
- chase
_______________________________________________
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