Re: Cursor tracking rects
Re: Cursor tracking rects
- Subject: Re: Cursor tracking rects
- From: Rainer Brockerhoff <email@hidden>
- Date: Sat, 29 Dec 2001 11:22:02 -0200
>
Date: Fri, 28 Dec 2001 19:28:23 -0500
>
From: Bill Bumgarner <email@hidden>
>
>
J o a r's code snippet will only work if the entire contents of the text
>
view are visible. If the text view is in a scroll view, it will set up
>
tracking rects for links that are not currently visible-- something that
>
is expressly forbidden according to the documentation.
>
>
So, if the text view is in a scroll view or is otherwise clipped, you need
>
to ensure that the tracking rects are only created for currently visible
>
links. Since the tracking rects are recalculated anytime the text object'
>
s layout changes-- including scroll events-- it is also helpful to only
>
scan the range of characters that are currently visible. For a
>
particularly long hunk of text, recalculating the cursor rects for the
>
entire body of text when only 2% is visible is both time consuming and
>
extremely ineffecient.
That's what stumped me, then, when I tried to do it. I thought it so obvious that the cursor rects should be calculated once for the whole view, and that the scroll view would automatically clip and compensate for that, that I refused to consider any other alternative :-)
Shouldn't we file a bug on that? Recalculating the rects after every scroll is inefficient and inconsistent with other behavior (for text inside a scroll view).
>
Thanks to J o a r for posting the original hunk of code. Xmanview now
>
properly changes the cursor when it is over a link-- well, almost. I'm
>
having a hard time triggering the initial calculation of cursor rects
>
after the first display. Not sure why.
I think it may be that at the time of the first display, the text view isn't fully laid out yet, so calling glyphRangeForBoundingRect will return invalid data. (I ran into this several times when trying to scroll to someplace in the middle). You need to figure out some call to lay out the whole view first, if it isn't already. I forget what I used, but I didn't like it.
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"Originality is the art of concealing your sources."
http://www.brockerhoff.net/ (updated Dec. 2001)