• 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: Screen location of cursor in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Screen location of cursor in NSTextView


  • Subject: Re: Screen location of cursor in NSTextView
  • From: Douglas Davidson <email@hidden>
  • Date: Tue, 25 Mar 2003 10:20:06 -0800

On Monday, March 24, 2003, at 10:40 AM, Joel Dudley wrote:

Is it possible to get the screen position for a cursor in NSTextView as text is being entered (as an NSPoint)? Basicly I want to place an NSComboBox at the end of the text as it is being entered and the contents will change depending on what text is being entered. With NSComboBox I have been using SetRect but am still looking for a way to get the screen location of the cursor as text is being entered. Currently I am looking at NSLayoutManager methods but I am stumped. Thanks.

By cursor here are you referring to the flashing vertical bar that NSTextView uses to indicate the insertion point? It is actually a rectangle rather than a single point; it is the degenerate case of the selection region, for a zero-length selection, and exists only if there is a zero-length selection. It can be determined as follows.

If you have more than one text container/text view pair, you must first determine which one the insertion point lies in; the layout manager will tell you that (let me know if you have problems with this). Then you can call rectArrayForCharacterRange:withinSelectedCharacterRange:inTextContainer: rectCount: with the first two arguments being the (zero-length) selected range. The result of this method in general is a list of rects, but for this case rectCount should be 1, and the first rect on the list should be the rect of interest, in text container coordinates. To convert to view coordinates, you must add the text view's textContainerOrigin as an offset to the origin of the rect.

Douglas Davidson
_______________________________________________
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.

References: 
 >Screen location of cursor in NSTextView (From: Joel Dudley <email@hidden>)

  • Prev by Date: RE: [1/2OT] CVS gui client for Xs
  • Next by Date: Formatter for a matrix of edit fields. Minor questions.
  • Previous by thread: Screen location of cursor in NSTextView
  • Next by thread: Correct way to locate 'Application Support' folder?
  • Index(es):
    • Date
    • Thread