Re: Getting updated insertion point from NSDraggingInfo
Re: Getting updated insertion point from NSDraggingInfo
- Subject: Re: Getting updated insertion point from NSDraggingInfo
- From: Jeremy Dronfield <email@hidden>
- Date: Sat, 1 May 2004 11:46:40 +0100
On 30 Apr 2004, at 5:59 pm, Douglas Davidson wrote:
What the text view does is to take that point in the window's
coordinate system, convert it into the view's coordinate system, then
into the container's coordinate system, and get a glyph index for that
point; then it converts this to a character index, and sets the
selected range accordingly. We don't have all of this packaged up for
you in a single method--perhaps we should--but it can be done using
public API. (Note that we also look at the fractional distance
through the glyph, and if it's greater than 0.5, we round up.)
Douglas Davidson
Thanks Douglas - that's done it. I do have a couple of outstanding
queries. I'm not sure if I've handled the fractional distance
correctly. Also, I croaked on providing a return value, so just called
super. The implementation now works as it should, but I'm not sure it's
quite correct:
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{
float fraction;
unsigned insertion, insertionPoint;
NSPoint dragPoint = [sender draggingLocation];
dragPoint = [self convertPoint:dragPoint fromView:nil];
insertionPoint = [[self layoutManager] glyphIndexForPoint:dragPoint
inTextContainer:[self textContainer]
fractionOfDistanceThroughGlyph:&fraction];
insertion = [[self layoutManager]
characterIndexForGlyphAtIndex:insertionPoint];
[self setSelectedRange:NSMakeRange(insertion, 0)]; // simple makerange
for testing purposes
return [super draggingUpdated:sender];
}
I tried returning [sender draggingSourceOperationMask], but this
resulted in the drag image not drawing properly (a plain arrow cursor
instead of a green+) and no visual feedback on the insertion location -
although the image still dropped into the right place. Any advice, or
have I got it about right?
Regards,
-Jeremy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.