• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSImageView as a drag source - how?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImageView as a drag source - how?


  • Subject: Re: NSImageView as a drag source - how?
  • From: mmalcolm crawford <email@hidden>
  • Date: Fri, 7 Jun 2002 00:49:42 -0700

On Thursday, June 6, 2002, at 01:09 PM, Jeff LaMarche wrote:

I hit exactly the same predicament a few weeks. I don't know why, but starting your drag from mouseDragged: doesn't work when subclassing NSImageView. If you start your drag from mouseDown, I bet it will start to work.

There's a coincidence -- I've been working on a similar thing recently.

Here's part of my implementation so far -- dragging works reliably from mouseDragged for me...
Please excuse the rather nasty category :-)

The thing that's plaguing me at the moment is how to provide the image as a file. Finder in particular seems to want an NSFilenamesPboardType, but writing the image to a temporary file doesn't always work -- Finder complains that it can't find the file, even when it is there...

mmalc




#import "DraggableImageView.h"


@implementation NSImageCell (DraggableImageView)
- (NSImage *)_scaledImage {
return _scaledImage;
}
@end


@implementation DraggableImageView


- (void)startDrag:(NSEvent *)event
{
NSPasteboard *pb = [NSPasteboard pasteboardWithName: NSDragPboard];
NSImage *dragImage;
NSImage *scaledImage = [[self cell] _scaledImage];
NSPoint dragPoint;

dragPoint = NSMakePoint(
([self bounds].size.width - [scaledImage size].width) / 2,
([self bounds].size.height - [scaledImage size].height) / 2);


[pb declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType] owner: self];


dragImage = [[[NSImage alloc] initWithSize: [scaledImage size]] autorelease];
[dragImage lockFocus];
[[[self cell] _scaledImage] dissolveToPoint: NSMakePoint(0,0) fraction: .5];
[dragImage unlockFocus];

[self dragImage: dragImage
at: dragPoint
offset: NSMakeSize(0,0)
event:event
pasteboard:pb
source: self
slideBack: YES];
}

- (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent *)event
{
// maybe make more discerning?!
return YES;
}

- (BOOL)acceptsFirstMouse:(NSEvent *)event
{
return YES;
}

- (void)mouseDown:(NSEvent *)event
{
[self setDownEvent:event];
}

- (void)mouseDragged:(NSEvent *)event
{
if ([self image]) {
[self startDrag:downEvent];
}
[self setDownEvent:nil];
}


- (NSEvent *)downEvent
{
return downEvent;
}
- (void)setDownEvent:(NSEvent *)event
{
[downEvent autorelease];
downEvent = [event retain];
}

@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSImageView as a drag source - how?
      • From: David Remahl <email@hidden>
References: 
 >Re: NSImageView as a drag source - how? (From: Jeff LaMarche <email@hidden>)

  • Prev by Date: Changing the height of NSTableHeaderView
  • Next by Date: Re: NSImageView as a drag source - how?
  • Previous by thread: Re: NSImageView as a drag source - how?
  • Next by thread: Re: NSImageView as a drag source - how?
  • Index(es):
    • Date
    • Thread