Here is my FN getFieldScrollInfo. I don't know whether it's an improvement on what you've already done--it "almost works" too. Actually, it's pretty solid, except that it still doesn't always reflect accurately whether there is any text showing from a partial line at the bottom of the field. It doesn't seem to miss by more than a couple of pixels, though, so maybe it's close enough for you to use.
I figured it based on the line height and the font ascent stored in the teStyleH& lineheight table, and assumed that the difference between them should be blank space at the top, while the lower font-Ascent pixels should have the character image. If someone else can describe or demonstrate a better approach, I'd like to see it. BTW, it's possible the problem is a simple logical error, but I've worked through it enough times that I'm a little dubious about that.
The one other difficulty I have found is that it gets a bit confused if the height of one line is greater than the height of the field.
BTW, I am aware of the toolbox call FN TEGETHEIGHT, and used it for a while, but found direct access to the lineheight table to be more efficient and easier (for me) to understand.
'-----------------------------------------
'textH& handle to _styled_ edit field. (non-styled will crash)
'(a) (var%) the LINE-number of the top LINE currently visible in the
FIELD,
'(b) (var%) the LINE-number of the bottom LINE that IS _fully_ visible,
'(c) (var%) the height of the EDIT FIELD through the LINE found in (b),
'(d) (var%) pixels showing of any partially-visible LINE at the bottom.
' (Not precise--depends on font, size, and text)
'The var%'s will be filled with values when the FN is called. You need
'to provide only the edit-field handle.
'
'CALL IT THIS WAY:
'FN getFieldScrollInfo(textH&,firstLine,lastLine,linesHeight,remPix)
'-----------------------------------------
LOCAL MODE
CLEAR LOCAL FN getFieldScrollInfo(textH&,@a&,@b&,@c&,@d&)
stylH& = textH&..teStylesH& 'get styles hndl
lhTabH& = stylH&..lhTab& 'get line height table hndl
XREF@ lhTabH(1,1) 'array to view line height table
LONG IF textH&..teNLines% 'any text here?
'Find first line
firstLine = 1
hidHeight = textH&..teViewRect.top% - textH&..teDestRect.top%
WHILE lineTop < hidHeight
lineTop = lineTop + lhTabH(firstLine-1,0)
INC (firstLine)
WEND
'Find last line
lastHeight = textH&..teViewRect.bottom% - textH&..teDestRect.top%
lastLine = firstLine - 1
lineBot = lineTop
WHILE lineBot + lhTabH(lastLine,0) + done <= lastHeight
lineBot = lineBot + lhTabH(lastLine,0)
LONG IF lastLine > textH&..teNLines%'check for end of text
done = lastHeight 'no more lines: exit loop
DEC (lastLine)
XELSE
INC(lastLine)
END IF
WEND
END IF
'calculate height of full lines
linesHeight = lineBot - lineTop
'calculate pixels showing in partial last line
LONG IF done = 0 AND lastHeight - lineBot'anything to show?
leadSpace = lhTabH(lastLine+1,0) - lhTabH(lastLine+1,1)
visHeight = lastHeight - lineBot - leadSpace + 2
IF visHeight < 0 THEN visHeight = 0
END IF
'Poke info into short int vars
% a&, firstLine
% b&, lastLine
% c&, linesHeight
% d&, visHeight
END FN
'-----------------------------------------