Re: getting visible character range
Re: getting visible character range
- Subject: Re: getting visible character range
- From: Keith Blount <email@hidden>
- Date: Mon, 6 Feb 2006 10:51:38 -0800 (PST)
Hi,
This is based on code that Douglas posted on this list
some time ago for something similar to what you want:
// Returns the range of characters that are contained
within the given rect (can be called
// for [self visibleRect], for instance). Thanks to
Douglas Davidson for posting this code
// on the Cocoa dev lists).
- (NSRange)characterRangeForRect:(NSRect)aRect
{
NSRange glyphRange, charRange;
NSLayoutManager *layoutManager = [self
layoutManager];
NSTextContainer *textContainer = [self
textContainer];
NSPoint containerOrigin = [self
textContainerOrigin];
// Convert from view coordinates to container
coordinates
aRect = NSOffsetRect(aRect, -containerOrigin.x,
-containerOrigin.y);
glyphRange = [layoutManager
glyphRangeForBoundingRect:aRect
inTextContainer:textContainer];
charRange = [layoutManager
characterRangeForGlyphRange:glyphRange
actualGlyphRange:NULL];
return charRange;
}
(This is in assuming you are putting the method in an
NSTextView subclass - obviously you would just replace
the references to "self" to your text view if not.)
Just call [textView characterRangeForRect:[textView
visibleRect]] to get the range of characters that are
visible.
Hope that helps.
Cheers,
Keith
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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