Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Drag and Drop Cursor

Drag and Drop Cursor
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Jun 5, 2004, 05:03 AM
 
Hey guys,

Im using a standard drag and drop procedure on my NSTextView. When I drop a file onto the TextView, their is a small blue border inside it (as normal) but there is no green + cursor like nearly every other app. Do I have to custom do this? I couldn't find anything on mamasam relating.

Thanks
Oliver
     
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status: Offline
Reply With Quote
Jun 5, 2004, 07:41 AM
 
Read through this page and make sure you are returning NSDragOperationGeneric from the draggingEntered; method.

This page on cocoadev might help if you haven't already read it.

If you can't figure it out, post the code your using.
Luke
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Jun 5, 2004, 08:25 AM
 
Hey,

I had a look in my draggingEntered: method and it seems quite custom. I'm a bit confused as to what I should change/add, here is my dragging and dropping code in my TextView subclass:

Code:
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { if (![self dragIsFile:sender]) { return [super draggingEntered:sender]; } [self lockFocus]; [[NSColor selectedControlColor] set]; NSFrameRectWithWidth([self visibleRect], 2.5); [self unlockFocus]; [[self window] flushWindow]; return NSDragOperationGeneric; } - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender { NSRect currentRect; if (![self dragIsFile:sender]) { return [super draggingUpdated:sender]; } currentRect = [self visibleRect]; if (!NSEqualRects(currentRect, previousRect)) { previousRect = currentRect; [self setNeedsDisplay:YES]; } else { [self lockFocus]; [[NSColor selectedControlColor] set]; NSFrameRectWithWidth(currentRect, 2); [self unlockFocus]; [[self window] flushWindow]; } return NSDragOperationGeneric; } - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender { if (![self dragIsFile:sender]) { return [super prepareForDragOperation:sender]; } return YES; } - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender { NSString *filename; BOOL result; if (![self dragIsFile:sender]) { return [super performDragOperation:sender]; } filename = [self getFileForDrag:sender]; result = [[self delegate] handleDroppedFile:filename forTextView:self]; if (result == NO) { [self setNeedsDisplay:YES]; } return result; } - (void)concludeDragOperation:(id <NSDraggingInfo>)sender { if (![self dragIsFile:sender]) { [super concludeDragOperation:sender]; return; } [self setNeedsDisplay:YES]; } - (void)draggingExited:(id <NSDraggingInfo>)sender { if (![self dragIsFile:sender]) { [super draggingExited:sender]; return; } [self setNeedsDisplay:YES]; } - (BOOL)dragIsFile:(id <NSDraggingInfo>)sender { BOOL isDirectory; BOOL fileExists; NSString *dragFilename = [self getFileForDrag:sender]; if (dragFilename == nil) { return NO; } fileExists = [[NSFileManager defaultManager] fileExistsAtPath:dragFilename isDirectory:&isDirectory]; return (fileExists && (!isDirectory)); } - (NSString *)getFileForDrag:(id <NSDraggingInfo>)sender { NSPasteboard *pb = [sender draggingPasteboard]; NSString *availableType = [pb availableTypeFromArray:[NSArray arrayWithObjects:NSFilenamesPboardType, NSPDFPboardType, nil]]; NSString *availableTypeString = [pb availableTypeFromArray:[NSArray arrayWithObjects:NSStringPboardType, nil]]; NSString *dragFilename; NSArray *props; if (availableType == nil) { return nil; } if (availableTypeString != nil) { return nil; } props = [pb propertyListForType:availableType]; dragFilename = [props objectAtIndex:0]; return dragFilename; }
     
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Jun 5, 2004, 03:35 PM
 
I'm no expert, but I just found this page last night:
http://www.cocoadevcentral.com/articles/000056.php
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:34 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2