• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTextView Drag and Drop (Colors)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSTextView Drag and Drop (Colors)
      • From: Seth Willits <email@hidden>
References: 
 >NSTextView Drag and Drop (Colors) (From: Seth Willits <email@hidden>)

  • Prev by Date: Re: NSDocument with fixed/auto-generated filename
  • Next by Date: NSTextView doesn't remember font when unarchived from nib?
  • Previous by thread: NSTextView Drag and Drop (Colors)
  • Next by thread: Re: NSTextView Drag and Drop (Colors)
  • Index(es):
    • Date
    • Thread