Search code examples
objective-cmacoscocoansimage

"Append" the Add/Plus icon to an NSImage during dragging


I have implemented drag-n-drop in a custom Calendar view in my application, which does a good job of providing support for moving items around.

But, I would like to add visual support for copying items. I have already implemented this in the back-end (when the Option key is held down) but I would like to supplement the feature with a more context-sensitive icon.

I have an NSImage created from the event, as displayed in my Calendar. This makes it seem as though the actual item is being dragged. (Which is nice!):

NSImage *i = ...;

...

[self dragImage:i at:thePoint offset:NSZeroSize event:theEvent pasteboard:pboard source:nil slideBack:NO];

But, in a situation where the user is holding down the Option key, I'd like to superimpose the "plus" or "copy" green plus icon over the top of my NSImage so it is apparent that the drop will result in a copy.

Is there any easy way to accomplish this? Thanks!


Solution

  • You can implement draggingEntered: and/or draggingUpdated: in your view and return NSDragOperationCopy to get a green plus icon automatically.