Re: NSTextView Drag and Drop (Colors)
Re: NSTextView Drag and Drop (Colors)
- Subject: Re: NSTextView Drag and Drop (Colors)
- From: Satoshi Matsumoto <email@hidden>
- Date: Sat, 03 Jun 2006 07:55:38 +0900
- Thread-topic: NSTextView Drag and Drop (Colors)
on 06.06.3 4:52 AM, Seth Willits at email@hidden wrote:
> I'm dragging a color from the standard color panel into a NSTextView
> and having it drop the hex rgb equivalent. What's the right way of
> getting the insertion point to move around while dragging and stay
> unchanged if the drag is aborted?
In order to get the character index of the dropped location, override the
method performDragOperation: as below:
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPoint draggingLocation = [sender draggingLocation];
draggingLocation = [self convertPoint:draggingLocation fromView:nil];
unsigned int characterIndex = [self characterIndexOfPoint:draggingLocation];
........ your code .........
}
- (unsigned int)characterIndexOfPoint:(NSPoint)aPoint
{
unsigned int glyphIndex;
NSLayoutManager *layoutManager = [self layoutManager];
float fraction;
NSRange range;
range = [layoutManager glyphRangeForTextContainer:[self textContainer]];
aPoint.x -= [self textContainerOrigin].x;
aPoint.y -= [self textContainerOrigin].y;
glyphIndex = [layoutManager glyphIndexForPoint:aPoint
inTextContainer:[self textContainer]
fractionOfDistanceThroughGlyph:&fraction];
if( fraction > 0.5 ) glyphIndex++;
if( glyphIndex == NSMaxRange(range) ) return [[self textStorage]
length];
else return [layoutManager characterIndexForGlyphAtIndex:glyphIndex];
}
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
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