gf0c+@andrew.cmu.edu (Gregory S. Fox) (05/15/89)
A question about TextEdit: The manager seems non-orthogonal in terms of interchangability of parameters. Specifically, if I want to scroll text with the updated manager, I need to know the size of the lines I'm scrolling off & on. TEGetStyle only returns the height & ascent for the style on a line, not the max values for the line. TEGetHeight would work, and there's the line height table, but no way to convert an offset into a line number. What am I missing here? Any suggestions on how to do this conversion efficiently? Thanks in advance for the help!!! -Greg
perry@key.COM (Peter Kiehtreiber) (05/18/89)
In article <kYPie6y00Xc48=ynJq@andrew.cmu.edu> gf0c+@andrew.cmu.edu (Gregory S. Fox) writes: > A question about TextEdit: > The manager seems non-orthogonal in terms of interchangability of > parameters. Specifically, if I want to scroll text with the updated > manager, I need to know the size of the lines I'm scrolling off & on. > TEGetStyle only returns the height & ascent for the style on a line, > not the max values for the line. TEGetHeight would work, and there's > the line height table, but no way to convert an offset into a line number. > What am I missing here? Any suggestions on how to do this conversion > efficiently? > Thanks in advance for the help!!! > -Greg Welcome to the club. I haven't found any trap for it either. Now, you don't really need one, because the information is all there in the *lineStarts* array (at the end of the TERec). This array contains the offsets of the line starts. Simply do a search of that array. With a binary search (the offsets are of course strictly ascending) you'll only need a maximum of 15 passes through the search loop (for 32767 newlines :-). Linear search is possible but might be a tad slow. And yes, I think there should be a trap for it. (If there is, please somebody tell me!) Note that the lineStarts array ends with a dummy entry containing the total number of characters in the record (i.e., the highest valid offset). The nLines field of the TERec tells you how many entries lineStarts has, *not* counting that sentinel. And yes, TEGetHeight is the one that allows you to get the number of pixels to scroll by. Note that with varying line heights, you'll end up having partial lines at the bottom or the top (or both), so you might want to adjust things a bit. Also, TEGetHeight seems to want its line number arguments to be one-based (first line = 1). *lineStarts* in IM I is clearly declared to be zero-based. Ah well. I hope that answers your question. If you need sample code, send me mail. -- perry -- ------------------------------------------------------------------------ Perry The Cynic (Peter Kiehtreiber) perry@arkon.key.com ** What good signature isn't taken yet? ** ...!pacbell!key!perry