Text field drags limited to copy operations
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Some facts of interest to the problem: - (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal { if (isLocal) return (NSDragOperationMove | NSDragOperationCopy); return (NSDragOperationCopy | NSDragOperationDelete); } Any insight/help with this problem would be greatly appreciated. Thanks _______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/site_archiver%40lists.apple... I have a document application that makes use of Cocoa bindings and has an inspector window with some text fields that need to support drag-n-drop between one another as well as from outside sources. To accomplish this goal, I have created a custom text field (subclass of NSTextField) and a custom field editor (subclass of NSTextView) to support drag-n-drop. Also, the window controller for the inspector window returns the custom field editor for these fields. Everything works nicely except for one major problem: all drag operations are copies--even within the same text field. However, the drag operations returned by the destination methods is always NSDragOperationMove when the source was not from another window. I am hoping to get an explanation or guess as to what my problem is with this system--and how to fix it. My search of the archives did not result in any answers. a) If I don't force the destination field to become the responder, I get the proper drag operations. Unfortunantly, I need the destination field to become the responder to comply with interface guidelines for drag destination feedback. The code in my custom text field to force the drag destination to become the responder is: - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { if ([[sender draggingSource] delegate] != self) { [[self window] makeFirstResponder:self]; [[self currentEditor] setSelectedRange:NSMakeRange (NSNotFound, 0)]; [self setNeedsDisplay:YES]; } NSPasteboard* pb = [sender draggingPasteboard]; NSDragOperation sourceDragMask = [sender draggingSourceOperationMask]; if ([[pb types] containsObject:NSStringPboardType]) { if (sourceDragMask & NSDragOperationMove) return NSDragOperationMove; else if (sourceDragMask & NSDragOperationCopy) return NSDragOperationCopy; else if (sourceDragMask & NSDragOperationDelete) return NSDragOperationDelete; } return [super draggingEntered:sender]; } b) If I set a break point to log the call stack in - draggingSourceOperationMaskForLocal:, I see that it is called twice-- first with isLocal as YES and second with isLocal as NO. Why is this? (This is true even of drags within the same field.) The log output is: #0 -[MyFieldEditor draggingSourceOperationMaskForLocal:] (self=0x4c1c4c0, _cmd=0x909fdd68, isLocal=1 '\001') at /Volumes/blah/ blah/MyProject/MyFieldEditor.m:43 #1 0x938958cc in -[NSCoreDragManager _dragUntilMouseUp:accepted:] () #2 0x93895248 in -[NSCoreDragManager dragImage:fromWindow:at:offset:event:pasteboard:source:slideBack:] () #3 0x93894dd4 in -[NSWindow(NSDrag) dragImage:at:offset:event:pasteboard:source:slideBack:] () #4 0x93894d38 in -[NSView(NSDrag) dragImage:at:offset:event:pasteboard:source:slideBack:] () #5 0x93a41fe8 in -[NSTextView(NSDragging) dragSelectionWithEvent:offset:slideBack:] () #6 0x93759388 in -[NSTextView mouseDown:] () #7 0x9368d9c8 in -[NSWindow sendEvent:] () #8 0x93636bfc in -[NSApplication sendEvent:] () #9 0x9362e090 in -[NSApplication run] () #10 0x9371e8bc in NSApplicationMain () #11 0x00026870 in main (argc=1, argv=0xbffff8c4) at /Volumes/Litter Box/Users/stodd/Documents/Software Projects/XGrader/main.m:13 #0 -[MyFieldEditor draggingSourceOperationMaskForLocal:] (self=0x4c1c4c0, _cmd=0x909fdd68, isLocal=0 '\000') at /Volumes/blah/ blah/MyProject/MyFieldEditor.m:43 #1 0x938958e0 in -[NSCoreDragManager _dragUntilMouseUp:accepted:] () #2 0x93895248 in -[NSCoreDragManager dragImage:fromWindow:at:offset:event:pasteboard:source:slideBack:] () #3 0x93894dd4 in -[NSWindow(NSDrag) dragImage:at:offset:event:pasteboard:source:slideBack:] () #4 0x93894d38 in -[NSView(NSDrag) dragImage:at:offset:event:pasteboard:source:slideBack:] () #5 0x93a41fe8 in -[NSTextView(NSDragging) dragSelectionWithEvent:offset:slideBack:] () #6 0x93759388 in -[NSTextView mouseDown:] () #7 0x9368d9c8 in -[NSWindow sendEvent:] () #8 0x93636bfc in -[NSApplication sendEvent:] () #9 0x9362e090 in -[NSApplication run] () #10 0x9371e8bc in NSApplicationMain () #11 0x00026870 in main (argc=1, argv=0xbffff8c4) at /Volumes/blah/ blah/MyProject/main.m:13 (gdb) c) My implementation of -draggingSourceOperationMaskForLocal: for the custom field editor is: This email sent to site_archiver@lists.apple.com
participants (1)
-
Sean Todd