• 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
dragging from a view to editors and the finder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dragging from a view to editors and the finder


  • Subject: dragging from a view to editors and the finder
  • From: Nestor Cardozo <email@hidden>
  • Date: Mon, 18 Apr 2005 13:00:22 +0200

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 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)
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

<x-tad-bigger>- (BOOL)dragPromisedFilesOfTypes:(</x-tad-bigger><x-tad-bigger>NSArray</x-tad-bigger><x-tad-bigger> *)</x-tad-bigger><x-tad-bigger>typeArray</x-tad-bigger><x-tad-bigger> fromRect:(</x-tad-bigger><x-tad-bigger>NSRect</x-tad-bigger><x-tad-bigger>)</x-tad-bigger><x-tad-bigger>aRect</x-tad-bigger><x-tad-bigger> source:(id)</x-tad-bigger><x-tad-bigger>sourceObject</x-tad-bigger><x-tad-bigger> slideBack:(BOOL)</x-tad-bigger><x-tad-bigger>slideBack</x-tad-bigger><x-tad-bigger> event:(</x-tad-bigger><x-tad-bigger>NSEvent</x-tad-bigger><x-tad-bigger> *)</x-tad-bigger><x-tad-bigger>theEvent


</x-tad-bigger>
and

<x-tad-bigger>- (</x-tad-bigger><x-tad-bigger>NSArray</x-tad-bigger><x-tad-bigger> *)namesOfPromisedFilesDroppedAtDestination:(</x-tad-bigger><x-tad-bigger>NSURL</x-tad-bigger><x-tad-bigger> *)</x-tad-bigger><x-tad-bigger>dropDestination

</x-tad-bigger>
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
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: dragging from a view to editors and the finder
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: indeterminate progress bar animation problem
  • Next by Date: Re: Localized nib file does not get loaded
  • Previous by thread: Re: Error inserting object at arranged index
  • Next by thread: Re: dragging from a view to editors and the finder
  • Index(es):
    • Date
    • Thread