Re: Using NSTextView's delegate method textView:draggedCell:inRect:event:atIndex: selectively
Re: Using NSTextView's delegate method textView:draggedCell:inRect:event:atIndex: selectively
- Subject: Re: Using NSTextView's delegate method textView:draggedCell:inRect:event:atIndex: selectively
- From: Philip Dow <email@hidden>
- Date: Fri, 2 Mar 2007 14:27:32 +0100
You're the man, Douglas. Thank you for the immediate response. Your
answer couldn't have pointed the way to a better solution.
Following the delegate paradigm, I have added a
textView:dragImageForSelectionWithEvent:origin: to my custom text
view's delegate. I call this method from
dragImageForSelectionWithEvent:origin:, and if the delegate is
writing its own pasteboard data then the delegate goes ahead an also
provides the custom image for it.
Looking back on the previous approach I had taken, I think I know
where the problem is. I had tried calling
writeSelectionToPasteboard:types: but it never put anything on the
pasteboard. I had assumed that the selection was already set, when in
fact I should have been "setting the selected range to {index, 1}" as
you mention.
-Phil
On Mar 2, 2007, at 1:46 AM, Douglas Davidson wrote:
On Mar 1, 2007, at 4:27 PM, Philip Dow wrote:
This is what I've been doing. However, it does not give me control
over the dragged image, which is something I woud like to
customize when writing my own pasteboard data.
If that's all you want, you can just override
dragImageForSelectionWithEvent:origin:.
I have tried overwriting
textView:draggedCell:inRect:event:atIndex: , and it works fine
when I'm working with my custom data. However, whenever I don't
want to handle the drag, preferring to use the default
implementation, I must still manually code that default
implementation. There is no super method to call here.
What NSTextView does here can be summarized as (a) set the selected
range to {index, 1} and (b) call dragSelectionWithEvent:event
offset:NSZeroSize slideback:YES.
Try as I might, I cannot get the same behavior as the default
implementation. I'm having a heck of a time putting the data on
the pasteboard in the right way so that the drag's receivers
behave as they would if I had never implemented this delegate
method in the first place.
Getting the data on the pastebaord is just
writeSelectionToPasteboard:[NSPasteboard
pasteboardWithName:NSDragPboard] types:[textView
writablePasteboardTypes], but there are other things that are done
in dragSelectionWithEvent:offset:slideBack: that you cannot readily
simulate. You should just call it instead.
Douglas Davidson
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden