[comp.sys.mac.programmer] Question about "Mac Revealed" TextEdit example

gsbrob1@apcvxa.uchicago.edu (11/20/88)

I have a very elementary programming question.  I've moved far beyond this
stage,  but it just keeps bugging me.  I've asked a couple of other Mac hackers
here, but they too are not sure.

In Chernicoff's "Macintosh Revealed" Vol 2., p.296-297, he discusses how to
write a routine that readjusts a window's text rectangle when the window is
resized.  Nothing complicated at all, right?  Basically, yes.  But here's some
of the code:


CONST
SBarWidth=16;
TextMargin=4;

VAR
TheText:TEHandle;

HLock(handle(TheText)):
WITH theText^^ DO

	BEGIN

	viewRect:=TheWindow^.portRect;
	WITH viewRect DO
       		BEGIN
		right:=right-(SBarWidth-1); {exclude scroll bar, allowing}
					    {one pixel overlap}
		bottom:=bottom-(SBarWidth-1);
{*}		bottom:=(bottom DIV lineHeight) * lineHeight;
				{TRUNCATE TO A WHOLE NUMBER OF LINES}
		END;

	destRect:=viewRect;                       {wrap to same rect}
{**}	InsetRect(destRect,TextMargin,TextMargin); {inset by text margin}

	TECalText(TheText);


and so on...


My question is this: in the line marked with the {*}, he adjusts the height of
viewRect so that it has a height which is a whole multiple of lineHeight,
insuring that lines of text are not "cut off" at the bottom of viewRect.  But
in the line marked with {**} he insets destRect by TextMargin, both
horizontally and vertically.  Doesn't the vertical displacement of destRect.top
by TextMargin throw the lines of text off so that they can now be "cut off" at
the bottom edge of viewRect?  I guess if TextMargin is small enough, it perhaps
wouldn't make a difference, but you shouldn't have to worry about what
TextMargin is, I believe.

Admittedly this is not the programming question of the ages, but I want to make
sure I'm not missing something about TextEdit routines.  Other people I've
shown this to agree that there seems to be an error in the book.  When I do it
his way, my text gets cut off; when I don't inset destRect vertically, all
works fine.  Are we missing something?  Please just e-mail any answers, since I
don't think this needs to tie up the net.

Thanks,

Robert 
gsbrob1@apcvxa.uchicago.edu
ra_robert@gsbacd.uchicago.edu

  ............................................................................
  . generic disclaimer:  all opinions here expressed are mine and mine alone .
  ............................................................................