• 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
SOLVED: The position of the insertion point in an NSTextView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SOLVED: The position of the insertion point in an NSTextView?


  • Subject: SOLVED: The position of the insertion point in an NSTextView?
  • From: Ondra Cada <email@hidden>
  • Date: Wed, 5 May 2004 14:50:05 +0200

Hi all,

On 5.5.2004, at 3:13, Ondra Cada wrote:

> before I dive into all those containers and layout managers and
> whatever... is there a simple way to find the screen position of the
> insertion point for a known NSTextView (which happens to have focus)?

Well, so I've dived. Happens anybody to need that, it seems

NSTextView *tv=...
NSRange rr=[tv selectedRange]; rr.length=0; // interested in the
beginning of a selection
NSTextContainer *tc=[tv textContainer];
NSLayoutManager *lm=[tc layoutManager];
rr=[lm glyphRangeForCharacterRange:rr actualCharacterRange:NULL];
NSRect gr=[lm boundingRectForGlyphRange:rr inTextContainer:tc];
NSPoint insertionPoint=[tv convertPoint:gr.origin toView:nil];

works quite well.
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.


  • Follow-Ups:
    • Re: SOLVED: The position of the insertion point in an NSTextView?
      • From: Douglas Davidson <email@hidden>
References: 
 >The position of the insertion point in an NSTextView? (From: Ondra Cada <email@hidden>)

  • Prev by Date: Custom canRemove binding
  • Next by Date: Re: Custom canRemove binding
  • Previous by thread: The position of the insertion point in an NSTextView?
  • Next by thread: Re: SOLVED: The position of the insertion point in an NSTextView?
  • Index(es):
    • Date
    • Thread