Re: Drag and Drop with the + cursor (again)
Re: Drag and Drop with the + cursor (again)
- Subject: Re: Drag and Drop with the + cursor (again)
- From: Tom Waters <email@hidden>
- Date: Sat, 21 Jul 2001 11:59:57 -0700
I got a private reply on this that lead me to notice some new
information.
If this sample application is the active (key/front) window while the
drag is happening, then the cursor changes to properly display the +
sign. e.g. You can drag an attachment from a mail message, since
mail.app doesn't force itself to the front when you are merely dragging.
If the some other app requires that it is key/front in order to initiate
a drag (like Finder), then my code doesn't display the + sign.
Is this specified someplace in the HIG that I haven't seen?
or is it a bug?
On Friday, July 20, 2001, at 06:26 PM, Tom Waters wrote:
I saw several messages on this topic in the omni archives, but no
solution that I can reproduce.
Does anyone know what you have to do to make a view cause the drag
cursor to show the plus sign?
I return NSDragOperationCopy from draggingEntered: and draggingUpdated:
and yet the cursor never changes...
I also am curious about the modifier keys and how they are to be
interpreted.
I find that a drag with no modifiers down has ALL of the source
operation mask bits set.
Copy Link Generic Private Move Delete
If you press Ctrl, (which presumably means Link), it masks out Copy and
Generic, leaving
Link Private Move Delete
If you press Option, (which means copy), it masks out Link and Generic,
leaving
Copy Private Move Delete
If you press Command (which means generic, although I have no idea what
generic means), it masks out Link and Copy, leaving
Generic Private Move Delete
Mainly, I want to differentiate between Copy and Move... but the two
nominal states, a) with no modifiers down and b) with option down, BOTH
have Copy and Move bits in the source! Plus I'd like to see the plus
cursor when I am going to do a copy.
Any wisdom out there for me?
As usual, I've got source... (I've learned not to assert things on this
list without it!)
Throw this in a custom view and drag a file from Finder over it...
#import <Cocoa/Cocoa.h>
@interface DragDestView : NSView
{
NSArray *files;
NSDragOperation mask;
NSPoint p;
}
@end
@implementation DragDestView
- (id)initWithFrame:(NSRect)r
{
[self registerForDraggedTypes: [NSArray arrayWithObject:
NSFilenamesPboardType]];
return [super initWithFrame:r];
}
- (NSString *)opString:(NSDragOperation)op
{
NSString *ret = @"";
if (op == NSDragOperationNone)
return @"None";
if (op & NSDragOperationCopy)
ret = [ret stringByAppendingString: @"Copy "];
if (op & NSDragOperationLink)
ret = [ret stringByAppendingString: @"Link "];
if (op & NSDragOperationGeneric)
ret = [ret stringByAppendingString: @"Generic "];
if (op & NSDragOperationPrivate)
ret = [ret stringByAppendingString: @"Private "];
if (op & NSDragOperationMove)
ret = [ret stringByAppendingString: @"Move "];
if (op & NSDragOperationDelete)
ret = [ret stringByAppendingString: @"Delete "];
return ret;
}
- (void)drawRect:(NSRect)r
{
[[NSColor whiteColor] set];
NSRectFill(r);
[[NSColor blackColor] set];
[[NSString stringWithFormat:@"%@", files] drawAtPoint:p
withAttributes:nil];
[[self opString: mask] drawAtPoint:NSMakePoint(p.x, p.y-12)
withAttributes:nil];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
{
return NSDragOperationCopy;
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
{
p = [self convertPoint: [sender draggingLocation] fromView: nil];
mask = [sender draggingSourceOperationMask];
[files release];
files = [[sender draggingPasteboard] propertyListForType:
NSFilenamesPboardType];
[files retain];
[self setNeedsDisplay:YES];
return NSDragOperationCopy;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender;
{
mask = 0;
p = NSMakePoint(NSMidX([self bounds]), NSMidY([self bounds]));
[files release];
files = nil;
[self setNeedsDisplay:YES];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender;
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
{
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender;
{
}
@end
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev