• 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] Re: How to detect clipping of text in NSTextView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Solved] Re: How to detect clipping of text in NSTextView?


  • Subject: [Solved] Re: How to detect clipping of text in NSTextView?
  • From: Leon Starr <email@hidden>
  • Date: Wed, 27 Jun 2007 23:37:02 -0700

Thank you, Douglas!!!  Got it working perfectly.

A quick scan through the NSLayoutManager class reference for
the delegate methods led me to the magic item:

- (void) layoutManager:(NSLayoutManager *)lman
	didCompleteLayoutForTextContainer:(NSTextContainer *)container
				 atEnd:(BOOL)flag {
	if (container == nil) {
		clipped = YES;
		NSLog(@"Clipped!");
	} else {
		clipped = NO;
		NSLog(@"Complete.");
	}
}

Which didn't work, (kept reporting "Complete" even though I could see the
text was clipped. But then I remembered reading something about the container
being larger than the view and something about "tracking height" that didn't make
sense earlier... So I added...


	// Setup container
	[ [view textContainer] setHeightTracksTextView:YES ];
	[ [view textContainer] setWidthTracksTextView:YES ];

... in my text view initialization and voila!  Perfection.

I thought I had read all of the relevant text handling guides, but
your comment also led me to the Text Layout Programming Guide
and Text System Storage Guide - doh!

Much appreciated!



On Jun 27, 2007, at 9:40 AM, Douglas Davidson wrote:


On Jun 27, 2007, at 9:05 AM, Leon Starr wrote:

I have an NSTextView with a fixed width that resizes vertically
up to a maximum depth (two lines).

The user may enter a string a bit longer than what I am allowing the
text view to display. (I don't want to resize the view to accommodate
the text).


I would like to display a visual cue so that the user knows text has
been clipped.  Like a + sign or something.

Is there some notification that will tell me when the text view's container
begins to clip text?


I know that I can use -sizeWithAttributes to get a single-line bounding box
size, but that doesn't take into account line wrapping. Otherwise I could just
compare bounding box sizes on each text change. (Worst case, I suppose
I could just work out the line wrap computation myself...)

Talk to the layout manager. It will tell you, for example, which glyphs are laid out in a particular text container. If that isn't all of them, then not everything is being displayed. If you need notification, you can act as the layout manager's delegate and be notified when layout happens and/or is finished.


Douglas Davidson




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How to detect clipping of text in NSTextView? (From: Leon Starr <email@hidden>)
 >Re: How to detect clipping of text in NSTextView? (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Merging/Connecting NSBezierPaths?
  • Next by Date: Re: Creating a custom subclass of NSController
  • Previous by thread: Re: How to detect clipping of text in NSTextView?
  • Next by thread: CFBundleShortVersionString
  • Index(es):
    • Date
    • Thread