FROM : Nestor Cardozo
DATE : Mon Apr 18 13:00:22 2005
This has been discussed previously in the list, but I cannot find a
coherent solution.
I have implemented a view in my application to be a drag source.
My code looks like this:
-(unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{
return NSDragOperationCopy;
}
- (void)mouseDragged:(NSEvent *)event
{
NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSDragPboard];
[pb declareTypes:
[NSArray arrayWithObject:NSPDFPboardType]
owner:self];
NSRect r = [self bounds];
NSData *data = [self dataWithPDFInsideRect:r];
[pb setData:data forType:NSPDFPboardType];
NSImage *anImage = [[[NSImage alloc] initWithSize:[self bounds].size]
autorelease];
[anImage lockFocus];
[self drawRect:[self bounds]];
[anImage unlockFocus];
NSPoint p = [self convertPoint:[event locationInWindow] fromView:nil];
NSSize s = [anImage size];
p.x = p.x - s.width/2;
p.y = p.y - s.height/2;
[self dragImage:anImage
at:p
offset:NSMakeSize(0,0)
event:event
pasteboard:pb
source:self
slideBack:YES];
}
Currently I can drag the contents of the view and drop it to
applications such as textedit, easycrop, illustrator (but strangely not
keynote). My problem is that I cannot drag from my view to the finder.
I understand I should implement
- (BOOL)dragPromisedFilesOfTypes:(NSArray *)typeArray
fromRect:(NSRect)aRect source:(id)sourceObject
slideBack:(BOOL)slideBack event:(NSEvent *)theEvent
and
- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL
*)dropDestination
But, if I understand well these methods assume that you already have a
file. Should I create a file within my mouseDragged method? Does anyone
have an example (code) where this has been done. I have checked apple
documentation but all I can find is a couple of paragraphs on dragging
file promises.
thanks for your help
DATE : Mon Apr 18 13:00:22 2005
This has been discussed previously in the list, but I cannot find a
coherent solution.
I have implemented a view in my application to be a drag source.
My code looks like this:
-(unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{
return NSDragOperationCopy;
}
- (void)mouseDragged:(NSEvent *)event
{
NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSDragPboard];
[pb declareTypes:
[NSArray arrayWithObject:NSPDFPboardType]
owner:self];
NSRect r = [self bounds];
NSData *data = [self dataWithPDFInsideRect:r];
[pb setData:data forType:NSPDFPboardType];
NSImage *anImage = [[[NSImage alloc] initWithSize:[self bounds].size]
autorelease];
[anImage lockFocus];
[self drawRect:[self bounds]];
[anImage unlockFocus];
NSPoint p = [self convertPoint:[event locationInWindow] fromView:nil];
NSSize s = [anImage size];
p.x = p.x - s.width/2;
p.y = p.y - s.height/2;
[self dragImage:anImage
at:p
offset:NSMakeSize(0,0)
event:event
pasteboard:pb
source:self
slideBack:YES];
}
Currently I can drag the contents of the view and drop it to
applications such as textedit, easycrop, illustrator (but strangely not
keynote). My problem is that I cannot drag from my view to the finder.
I understand I should implement
- (BOOL)dragPromisedFilesOfTypes:(NSArray *)typeArray
fromRect:(NSRect)aRect source:(id)sourceObject
slideBack:(BOOL)slideBack event:(NSEvent *)theEvent
and
- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL
*)dropDestination
But, if I understand well these methods assume that you already have a
file. Should I create a file within my mouseDragged method? Does anyone
have an example (code) where this has been done. I have checked apple
documentation but all I can find is a couple of paragraphs on dragging
file promises.
thanks for your help
| Related mails | Author | Date |
|---|---|---|
| Nestor Cardozo | Apr 18, 13:00 | |
| Nick Zitzmann | Apr 18, 15:28 |






Cocoa mail archive

