Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drag and Drop with the + cursor (again)



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




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.