I have a subclass of NBox that I would like to drag around a canvas called dragBox. I don't understand why draggingEntered isn't being fired on the following code. I get a nice slideback image, but none of the destination delegates are getting fired. Why?
-(void) awakeFromNib
{
[[self superview] registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
}
-(void) mouseDown:(NSEvent *)theEvent
{
[self dragImage:[[NSImage alloc] initWithContentsOfFile:@"/Users/bruce/Desktop/Untitled-1.png"] at:NSMakePoint(32, 32) offset:NSMakeSize(0,0) event:theEvent pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] source:self slideBack:YES];
}
-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender // validate
{
NSLog(@"Updated");
return [sender draggingSourceOperationMask];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSLog(@"Drag Entered");
return [sender draggingSourceOperationMask];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSLog(@"Move Box");
[self setFrameOrigin:[sender draggingLocation]];
return YES;
}
-(BOOL) prepareForDragOperation:(id<NSDraggingInfo>)sender
{NSLog(@"Prepared");
return YES;
}
In your
mouseDownmethod you are not putting anything in the pasteboard before you initiate the drag operation. The documentation for NSView states you need to add your data on the pasteboard before sending it to that message.Whatever destination views you have are, or should be, registering for a certain drag type. If your pasteboard does not have any matching data for that type, the destinations will not fire any of the NSDraggingProtocol messages.