home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
lang
/
skel_azt.sha
/
teadjdest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-07-08
|
4KB
|
123 lines
/*
* teadjdest.c -- adjust the textedit destination rectangle to match
* the size of the text that hText contains, and
* adjust the scrollbar control values to match also
*/
#include <quickdraw.h>
#include <control.h>
#include <event.h>
#include <textedit.h>
#include <window.h>
#include "def.h"
void
teadjdest()
{
extern TEHandle hTE;
extern ControlHandle hscroll[NWINDOWS];
int i;
extern long lastTEadj;
int ls; /* line start */
int mll; /* maximum line length */
extern int scrollTEstart; /* keep track of insertion point
* character index
*/
Rect sel;
int tll; /* this line length */
extern Point tlp[NWINDOWS];
extern ControlHandle vscroll[NWINDOWS];
extern Boolean wantTEadj;
extern WindowPtr wp[NWINDOWS];
/* If typing is occurring, don't slow down the scrolling by doing
* all these calculations for every key-stroke.
* This method is a little jumpy, but better than nothing.
* If the typing stops, the main event loop will make the final
* (well, temporarily final) call of teadjdest.
*/
if (TickCount() - lastTEadj < 60) {
wantTEadj = TRUE;
return;
};
wantTEadj = FALSE;
lastTEadj = TickCount();
ls = (*hTE)->lineStarts[0];
HLock((*hTE)->hText);
if ((*hTE)->nLines < 2)
mll = TextWidth(*(*hTE)->hText, 0, (*hTE)->teLength);
else {
mll = 1;
for (i = 1; i <= (*hTE)->nLines; i++) {
/* search for the longest line */
tll = -ls;
ls = (*hTE)->lineStarts[i];
tll += ls;
tll = TextWidth(*(*hTE)->hText, ls - tll, tll);
if (tll > mll)
mll = tll;
};
};
(*hTE)->destRect.right = mll + (*hTE)->destRect.left + 8 +
(*hTE)->lineHeight * 5; /* room for typing at right margin */
(*hTE)->destRect.bottom = ((*hTE)->nLines + 1) * (*hTE)->lineHeight +
(*hTE)->destRect.top + 8;
/* We use the selRect field of the TE structure to determine
* whether there is a caret insertion point and where that point
* is. Unfortunately, Apple hasn't been able to document selRect
* yet, as it hasn't been around enough years yet! So we do
* some guessing about it based on observing it with MacsBug.
*/
BlockMove(&(*hTE)->selRect, &sel, (long)sizeof(Rect));
if (sel.left == 0x8002) /* some special value ?? Anyway, it's
* what's there when an empty line is
* selected as the insertion point by
* TEClick
*/
sel.left = (*hTE)->destRect.left + 4;
if (sel.right == -0x8002) /* some special value ?? Anyway, it's
* what's there when the caret is off
* the left side of the window after
* TEClick selects the insertion point
*/
sel.right = sel.left + 1;
if (sel.right - sel.left == 1 &&
sel.bottom - sel.top == (*hTE)->lineHeight &&
(*hTE)->selStart != scrollTEstart) {
/* make sure the insertion point caret is in the window */
scrollTEstart = (*hTE)->selStart;
if (sel.top + tlp[1].v + (*hTE)->destRect.top <
wp[1]->portRect.top)
SetCtlValue(vscroll[1], sel.top + tlp[1].v);
if (sel.bottom + tlp[1].v + (*hTE)->destRect.top >
wp[1]->portRect.bottom - 16) {
i = wp[1]->portRect.bottom - wp[1]->portRect.top - 16;
if (sel.top > GetCtlMax(vscroll[1]))
SetCtlMax(vscroll[1], (*hTE)->destRect.bottom - i - 5 -
(*hTE)->destRect.top);
SetCtlValue(vscroll[1], sel.bottom + tlp[1].v - i);
};
if (sel.right + tlp[1].h + (*hTE)->destRect.left <
wp[1]->portRect.left ||
sel.left + tlp[1].h + (*hTE)->destRect.left >
wp[1]->portRect.right - 16) {
i = wp[1]->portRect.right - wp[1]->portRect.left - 16;
if (sel.right > GetCtlMax(hscroll[1]))
SetCtlMax(hscroll[1], (*hTE)->destRect.right -
i - 5 - (*hTE)->destRect.left);
SetCtlValue(hscroll[1], sel.left + tlp[1].h - (i >> 1));
};
};
HUnlock((*hTE)->hText);
checkscroll(1);
} /* end of teadjdest */