home *** CD-ROM | disk | FTP | other *** search
- /*
- File: support.c
-
- Contains: supporting routines for surfer
-
- Written by: Mary Chan
-
- Copyright: © 1990 by Apple Computer, Inc., all rights reserved.
-
- */
-
-
- #pragma load <header.dump>
- #include "TMIntf.h"
- #include "globals.h"
-
- short curindex = 0; /* index into the cache buffer */
- short curVertValue = 0; /* current vertical scrollbar value */
- short curHoriValue = 0; /* current horizontal scrollbar value */
- short maxVCtl = 0; /* max vertical scroll */
- short maxHCtl = 0; /* max vertical scroll */
- Rect visCacheRect = {0,0,0,0}; /* visible cache area */
- Point oldpoint; /* old mouse point */
- Point anchorpoint; /* selection's anchorpoint */
- Point mycellSize = {0,0}; /* current cellsize */
- Point myslop = {0,0}; /* current slop area */
- short oldAuxTop = 0; /* current top aux area */
- short oldAuxBottom = 0; /* current bottom aux area */
- short oldAuxLeft = 0; /* current left aux area */
- short oldAuxRight = 0; /* current right aux area */
- short maxcol = 0; /* current max column */
- short totalCache = 0; /* total number of cache */
- short offset = 0; /* circular buffer offset */
- short curindex = 0; /* current index into the circular buffer */
- TermEnvironRec termEnvironment; /* current terminal env */
- Boolean clikWasInTermArea; /* was mouse click in the terminal area */
- Boolean clikWasInCacheArea; /* was mouse click in the cache area */
- Boolean firstClickInCache; /* was the first mouse down/click in the cache area */
- Boolean isActive = false; /* is the cache selection being inverted or just framed */
-
-
- Point GetCell( Point anchorpoint, Point cellsize);
- Point GetCellPoint( Point anchorpoint, Point cellsize );
-
- /*******************************************************************
- * MyClickProc - handle mouse tracking in the cache area
- *
- * refcon - term record's reference constant
- *
- **********************************************************************/
- pascal Boolean MyClickProc( long refcon )
- {
- #pragma unused(refcon)
- Boolean PtInCache = false;
- Point where;
- short scrollVamt;
- short scrollHamt;
- Rect cliprect;
-
- cliprect = visCacheRect;
- cliprect.bottom -= CACHBOTTOMSLOP;
- ClipRect( &cliprect ); /* set clipping area to the cache area */
- where = *((Point*)&((**_GTERM).reserved1)); /* get the mouse location set by the tool */
- if ( PtInRect( where, &visCacheRect ) )
- {
- /* mouse down is in the cache area */
- Cellboundary( &where ); /* set point at the cell boundary */
- if ( clikWasInTermArea && !firstClickInCache)
- { /* pin the anchor point the cache area's bottom right */
- anchorpoint.v = _CACHEDESTRECT.bottom - mycellSize.v - CACHBOTTOMSLOP;
- anchorpoint.h = _CACHEDESTRECT.right - myslop.h;
- }
- else if ( anchorpoint.v == -1 && anchorpoint.h == -1)
- {
- /* pin anchor point to the first mouse down location */
- anchorpoint = where;
- }
- clikWasInCacheArea = true;
-
- /* the mouse point has change, do selection */
- if ( where != oldpoint )
- {
- GetRegion( _NEWRGN, anchorpoint, where ); /* get new selection area */
- CombineNewOldrgn( _NEWRGN, _OLDRGN ); /* hilite the diff between the old and new selection */
- CopyRgn( _NEWRGN, _OLDRGN );
- SetEmptyRgn(_NEWRGN);
- oldpoint = where;
- }
- clikWasInTermArea = false;
- PtInCache = true;
- }
- else if ( PtInRect( where, &_TERMVISRECT) )
- {
- if ( clikWasInCacheArea )
- {
- /* extend the selection from cache to term area */
- /* hilite selection till the bottom right of the cache area */
- where.v = _CACHEDESTRECT.bottom - mycellSize.v - CACHBOTTOMSLOP;
- where.h = _CACHEDESTRECT.right - myslop.h;
- GetRegion( _NEWRGN, anchorpoint, where );
- CombineNewOldrgn( _NEWRGN, _OLDRGN );
- CopyRgn( _NEWRGN, _OLDRGN );
- SetEmptyRgn(_NEWRGN);
- oldpoint = where;
- clikWasInCacheArea = false;
- } /* if ( !PintoBottom )*/
- clikWasInTermArea = true;
- } /* if ( PtInRect( where, _TERMVISRECT) )*/
- else
- {
- scrollVamt = 0;
- scrollHamt = 0;
- /* auto scrolling -- scroll the rect */
- if ( where.v < 0 )
- scrollVamt = mycellSize.v;
- else if ( where.v > (_PORTRECT.bottom - 15 ) )
- scrollVamt = -mycellSize.v;
-
- if ( where.h < 0 )
- scrollHamt = mycellSize.h;
- else if ( where.h > (_PORTRECT.right - 15 ) )
- scrollHamt = -mycellSize.h;
-
- /* reset the clip area before calling the scroll rect */
- SetClip( _SAVECLIP );
- ScrollCache( &scrollHamt, &scrollVamt, true ) ;
- ClipRect( &visCacheRect );
-
- Cellboundary( &where ); /* set mouse down at cell boundary */
-
- if ( anchorpoint.v == -1 && anchorpoint.h == -1)
- {
- /* init anchor points */
- anchorpoint.v = _CACHEDESTRECT.bottom - mycellSize.v - CACHBOTTOMSLOP;
- anchorpoint.h = _CACHEDESTRECT.right - myslop.h;
- }
- else
- {
- /* offset my points after scrolling */
- anchorpoint.h += scrollHamt;
- anchorpoint.v += scrollVamt;
- }
-
- oldpoint.h += scrollHamt;
- oldpoint.v += scrollVamt;
- if ( oldpoint != where )
- {
- /* hilite the newly exposed area */
- GetRegion( _NEWRGN, anchorpoint, where );
- CombineNewOldrgn( _NEWRGN, _OLDRGN );
- CopyRgn( _NEWRGN, _OLDRGN );
- SetEmptyRgn(_NEWRGN);
- }
- oldpoint = where;
- }
- return PtInCache;
- }
-
-
-
- /*******************************************************************
- * MyCacheProc - handle scroll back caching
- *
- * refcon - term record's reference constant
- * TermDataBlock - pointer to the terminal data block
- *
- **********************************************************************/
- pascal long MyCacheProc( long refcon, TermDataBlock *theTermData )
- {
- #pragma unused(refcon)
-
- linePtr curline;
- Rect theRect;
-
- if ( !theTermData->theData )
- /* nil data handle, return error */
- return ( -1 );
-
- /* dehilite the cache selection */
- DeSelection();
- /* are we at the cache limit yet? points to the head of buffer if so */
- if ( curindex == MAXCACHELINE )
- {
- curindex = 0; /* buffer wraps around */
- offset = 1;
- }
- else if ( totalCache != MAXCACHELINE ) /* grow the cache destination rect (cach area ) */
- {
- if ( EmptyRect(&_CACHEDESTRECT) )
- {
- _CACHEDESTRECT.top -= CACHBOTTOMSLOP;
- maxVCtl += CACHBOTTOMSLOP; /* reset max scroll control value */
- curVertValue += CACHBOTTOMSLOP; /* increment current scroll control value */
- SetCtlMax( _VERTSCROLLHDL, maxVCtl);
- }
- _CACHEDESTRECT.top -= mycellSize.v;
- /* update the scroll max and current scroll value */
- ++totalCache;
- maxVCtl += mycellSize.v; /* reset max scroll control value */
- curVertValue += mycellSize.v; /* increment current scroll control value */
- SetCtlMax( _VERTSCROLLHDL, maxVCtl);
- SetCtlValue( _VERTSCROLLHDL, curVertValue);
- }
- else
- {
- offset++;
- }
-
- /* copy the data */
- HLock( theTermData->theData );
- HLock( _MYDATAHANDLE );
- curline = ((linePtr) *_MYDATAHANDLE) + curindex++; /* get pointer to the circular buffer */
- _MYDATASIZE = GetHandleSize( theTermData->theData ); /* get data size */
- BlockMove(*(theTermData->theData), (char*)curline, _MYDATASIZE); /* copy data to my buffer */
- if ( _MYDATASIZE < MAXCACHECOL )
- {
- /* fill the extra with spaces since the cache always has 132 column */
- BlockMove( _BLANKLINE, ((char*)curline)+_MYDATASIZE, MAXCACHECOL-_MYDATASIZE);
- }
-
- /* is the cache area visible? scroll the cache area if it is */
- if ( !EmptyRect( &visCacheRect ) )
- {
- theRect = visCacheRect;
- theRect.bottom--; /* don't want to scroll the dividing line */
- /* scroll the cache area up a line */
- ScrollRect( &theRect, 0, -mycellSize.v, _UPDATERGN );
- UpdateCache( _UPDATERGN );
- }
- return 0;
- }
-
-
- /*******************************************************************
- * scrollProc - scroll proc call by TrackControl
- *
- * theControl - which control is active
- * partCode - which part of the control is active
- *
- **********************************************************************/
- pascal void scrollProc( ControlHandle theControl, short partCode )
- {
- short scrollHamount = 0;
- short scrollVamount = 0;
-
- if ( !partCode ) /* partcode == 0, just return to caller */
- return;
-
- if ( partCode == inUpButton || partCode == inDownButton)
- {
- if ( partCode == inUpButton )
- {
- if ( theControl == _VERTSCROLLHDL )
- scrollVamount = mycellSize.v;
- else
- scrollHamount = mycellSize.h;
- }
- else
- {
- if ( theControl == _VERTSCROLLHDL )
- scrollVamount = -mycellSize.v;
- else
- scrollHamount = -mycellSize.h;
- }
- ScrollCache( &scrollHamount, &scrollVamount, true );
- } /* if ( partCode == inUpButton || partCode == inDownButton)*/
-
-
- }
-
-
- /*******************************************************************
- * HandleMouseDown - handle mouse down in window's content
- *
- * window - which window does the mouse down occurs
- * event - event record
- *
- **********************************************************************/
- HandleMouseDown( window, event )
- WindowPtr window;
- EventRecord *event;
- {
- Point where;
- ControlHandle whichcontrol;
- short value;
- short partcode;
- Rect theRect;
-
- SetPort( window );
- where = event->where; /* get the mouse down location */
- /* convert global mouse point into local coordinate */
- GlobalToLocal( &where );
- partcode = FindControl( where, window , &whichcontrol);
- switch ( partcode )
- {
- case 0:
- /* mouse down not in the active control area */
- theRect = _PORTRECT;
- theRect.right -= 15;
- theRect.bottom -= 15;
- /* is mouse down in the inactive control area or in the content? */
- if ( PtInRect( where, &theRect) )
- {
- DeSelection(); /* get rid of old selection */
- clikWasInCacheArea = false; /* init some var */
- clikWasInTermArea = false;
- /* is the first mouse click in the cache area */
- if ( PtInRect( where, &visCacheRect ) )
- {
- firstClickInCache = true;
- }
- else
- {
- firstClickInCache = false;
- }
- /* set clipping region to the cache area */
- GetClip( _SAVECLIP );
- TMClick( _GTERM, event );
- SetClip( _SAVECLIP );
- } /* if ( PtInRect( where, theRect) ) */
- break;
- case inUpButton:
- case inDownButton:
- /* do mouse tracking */
- value = TrackControl(whichcontrol, where, (ProcPtr)&scrollProc);
- } /* switch */
- }
-
-
- /*******************************************************************
- * UpdateCache - update the cache area
- *
- * _UPDATERGN - the update region
- *
- **********************************************************************/
- UpdateCache( _UPDATERGN )
- RgnHandle _UPDATERGN;
- {
- linePtr curline;
- linePtr bufferstart;
- short top;
- short i;
- TermDataBlock theTermData;
- short datasize=MAXCACHECOL;
- Rect theRect;
- Ptr dataptr;
- RgnHandle cache_UPDATERGN;
- short wraparound;
- short bottom;
- short right;
- short rgntop;
- short rgnleft;
- Ptr srcptr;
- RgnHandle savergn;
- short updatelinestart;
- short updatecolstart;
-
- cache_UPDATERGN = NewRgn();
- savergn = NewRgn();
-
- /* we don't want to deal with the terminal area */
- /* get it out of the update region */
- RectRgn( cache_UPDATERGN, &_TERMVISRECT);
- DiffRgn( _UPDATERGN, cache_UPDATERGN, cache_UPDATERGN);
- /* erase the update region which is not in the term area */
- EraseRgn( cache_UPDATERGN );
-
- RectRgn( cache_UPDATERGN, &visCacheRect);
- /* get the intersection of my cache area and the update region */
- SectRgn( cache_UPDATERGN, _UPDATERGN, cache_UPDATERGN);
-
- /* Does any part of the cache area need to be updated? */
- if ( !EmptyRgn( cache_UPDATERGN ) )
- {
- /* the cache area needs to be updated */
- GetClip( savergn );
- SetClip( cache_UPDATERGN );
-
- /* erase the update area */
- EraseRgn( cache_UPDATERGN );
- theRect = _CACHEDESTRECT;
-
- right = _CACHEDESTRECT.left + myslop.h;
- rgnleft = (**cache_UPDATERGN).rgnBBox.left;
-
- /* figure out which column should I start painting from */
- for ( updatecolstart=0; updatecolstart < MAXCACHECOL; updatecolstart++ )
- {
- right += mycellSize.h;
- if ( right > rgnleft )
- break;
- }
- // debugstr("get updatecolstart");
- datasize -= updatecolstart;
- theRect.left = right - mycellSize.h;
-
- /* figure out where row I should starting painting from */
- bottom = top = _CACHEDESTRECT.top;
- rgntop = (**cache_UPDATERGN).rgnBBox.top;
-
- for ( updatelinestart=0; updatelinestart < totalCache; updatelinestart++ )
- {
- bottom += mycellSize.v;
- if ( bottom > rgntop )
- break;
- }
- top = bottom - mycellSize.v;
- theRect.top = top;
-
- HLock( _MYDATAHANDLE); /* lock my circular buffer */
- bufferstart = ((linePtr) *_MYDATAHANDLE);
- curline = bufferstart + updatelinestart + offset; /* pointer to the buffer */
- wraparound = MAXCACHELINE - offset;
-
- HLock( _MYDATAHDL ); /* lock the one line data handle */
- dataptr = *_MYDATAHDL;
-
- theTermData.theData = _MYDATAHDL;
- theTermData.flags = tmTextTerminal;
- theTermData.auxData = nil;
-
- for ( i = updatelinestart; i < totalCache ; i++ )
- {
- if ( i >= wraparound )
- {
- curline = bufferstart+i-wraparound; /* starts from the starting of buffer */
- wraparound = totalCache+1;
- }
- srcptr = ( (Ptr)curline++) + updatecolstart;
- BlockMove( srcptr, dataptr , datasize); /* copy from the cir. buffer to the one line buffer handle */
- /* paint the cached line, calling tool's routine TMPaint for each cached line */
- TMPaint( _GTERM, &theTermData, &theRect);
- theRect.top += mycellSize.v;;
- }
-
- /* draw the cache/terminal dividing line */
- MoveTo( _PORTRECT.left, _CACHEDESTRECT.bottom-1);
- LineTo( _PORTRECT.right, _CACHEDESTRECT.bottom-1);
-
- /* update the selection area */
- DoSelection();
-
- SetClip( savergn );
- DisposeRgn( savergn );
- HUnlock(_MYDATAHDL);
- HUnlock(_MYDATAHANDLE);
- } /* if EmptyRgn( ) */
- DisposeRgn( cache_UPDATERGN );
- }
-
- /*******************************************************************
- * InvalGrowBox - invalidate the grow box area
- *
- **********************************************************************/
- InvalGrowBox( )
- {
- Rect _GROWRECT;
-
- _GROWRECT = _PORTRECT;
- _GROWRECT.left = _GROWRECT.right - GROWBOXSIZE-1;
- _GROWRECT.top = _GROWRECT.bottom - GROWBOXSIZE -1;
- InvalRect( &_GROWRECT );
- }
-
- /*******************************************************************
- * DoSizeWindow - resize the window
- *
- * window - window pointer
- * event - event record
- *
- **********************************************************************/
- DoSizeWindow( window, event )
- WindowPtr window;
- EventRecord *event;
- {
- long result ;
- short bottom;
- short right;
- short top;
- Rect newTermRect;
- short diffV;
- short diffH;
-
- result = GrowWindow( window, event->where, &_GROWRECT );
- InvalRect( &(**_VERTSCROLLHDL).contrlRect );
- InvalRect( &(**_HORISCROLLHDL).contrlRect );
- InvalGrowBox();
- SizeWindow(window, LoWord(result), HiWord(result), true);
-
- /* move and resize the control */
- newTermRect = _PORTRECT = window->portRect;
- /* get new the terminal area */
- newTermRect.bottom -= 15;
- newTermRect.right -= 15;
- SectRect( &_CACHEDESTRECT, &newTermRect, &visCacheRect );
-
- right = _PORTRECT.right;
- bottom = _PORTRECT.bottom;
- top = _PORTRECT.top;
-
- MoveControl( _VERTSCROLLHDL, right -15, -1 );
- SizeControl( _VERTSCROLLHDL, 16, bottom-top-GROWBOXSIZE );
-
- MoveControl( _HORISCROLLHDL, -1, bottom -15 );
- SizeControl( _HORISCROLLHDL, right-_PORTRECT.left-GROWBOXSIZE, 16 );
-
- /* resize the terminal area */
- TMResize( _GTERM, &newTermRect );
-
- /* readjust the cache and terminal area */
- if ( (diffV = _PORTRECT.bottom - 15 - (**_GTERM).viewRect.bottom) < 0 )
- diffV = 0;
- if ( (diffH = _PORTRECT.right - 15 - _CACHEDESTRECT.right ) < 0 )
- diffH = 0;
-
- if ( diffV || diffH )
- {
- /* pin the last row and last column to the bottom right of the window */
- ScrollCache( &diffH, &diffV, false ) ;
- }
-
- /* get new control scroll value */
- SetVScrollMax();
- SetHScrollMax();
- InvalRect( &(**_VERTSCROLLHDL).contrlRect );
- InvalRect( &(**_HORISCROLLHDL).contrlRect );
- InvalGrowBox( window );
-
- /* get new visible term area */
- SectRect( &(**_GTERM).viewRect, &(**_GTERM).termRect, &_TERMVISRECT);
-
- }
-
- /*******************************************************************
- * SetHScrollMax - reset the max of the hori scroll bar
- *
- **********************************************************************/
- SetHScrollMax()
- {
- short totalspace;
- short totalvis;
-
- totalspace = (_CACHEDESTRECT.right - _CACHEDESTRECT.left );
-
- totalvis = _PORTRECT.right - _PORTRECT.left - 15; /* remember that hori scroll bar */
- if ( totalvis >= totalspace )
- maxHCtl = 0;
- else
- maxHCtl = totalspace-totalvis;
- SetCtlMax( _HORISCROLLHDL, maxHCtl);
- }
-
-
- /*******************************************************************
- * SetVScrollMax - reset the max of the vertical scroll bar
- *
- **********************************************************************/
- SetVScrollMax()
- {
- short totalspace;
- short totalvis;
-
- totalspace = (_CACHEDESTRECT.bottom - _CACHEDESTRECT.top )
- + (**_GTERM).viewRect.bottom - (**_GTERM).viewRect.top;
-
- totalvis = _PORTRECT.bottom - _PORTRECT.top - 15; /* remember that hori scroll bar */
- if ( totalvis >= totalspace )
- maxVCtl = 0;
- else
- maxVCtl = totalspace-totalvis;
- SetCtlMax( _VERTSCROLLHDL, maxVCtl);
- }
-
- /*******************************************************************
- * CheckTermEnv - get new tool environment from tool if the tool's
- * environment has changed
- *
- * Getit - always get new environment if true
- *
- **********************************************************************/
- CheckTermEnv( Getit)
- Boolean Getit;
- {
- OSErr err;
- GrafPtr curport;
- Rect cur_PORTRECT;
- short bottom;
- short diffV;
- short diffH;
- short scrollH = 0;
- short scrollV = 0;
- short newvalue;
- Point oldcell1;
- Point oldcell2;
- Point oldcellsize;
- Boolean repaint = false;
-
- /* has the environment changed? */
- /* tmEnvironsChanged was defined to be 2 in the 1.1 CommToolBox interface */
- /* it wasn't defined in the 1.0 CommToolBox interface */
- if ( ((**_GTERM).errCode == tmEnvironsChanged) || Getit )
- {
- /* get new terminal environment */
- termEnvironment.version = 0; /* must set the right version number before getting environ */
- err = TMGetTermEnvirons(_GTERM, &termEnvironment);
- cur_PORTRECT = _PORTRECT;
- cur_PORTRECT.right -= 15;
- cur_PORTRECT.bottom -= 15;
- if ( err == noErr ) /* no error from getting the term environ */
- {
- myslop = termEnvironment.slop;
- if ( termEnvironment.cellSize != mycellSize ) /* the cell size has changed */
- {
- oldcellsize = mycellSize;
- mycellSize = termEnvironment.cellSize;
- /* get _CACHEDESTRECT dimension for setting up the hori scroll value */
- _CACHEDESTRECT.right = _CACHEDESTRECT.left + mycellSize.h * MAXCACHECOL + myslop.h * 2;
- /* if not emtpy cacheRect */
- if ( !EmptyRect( &_CACHEDESTRECT ) )
- {
- if ( !EmptyRgn( _OLDRGN) )
- {
- SwapPoint( &oldpoint, &anchorpoint );
- oldcell1 = GetCell( oldpoint , oldcellsize );
- oldcell2 = GetCell( anchorpoint, oldcellsize);
- if ( oldcell2.h == oldcell1.h )
- oldcell2.v++;
- }
- /* readjust the cacheRect */
- bottom = _CACHEDESTRECT.bottom;
- _CACHEDESTRECT.bottom = _CACHEDESTRECT.top + mycellSize.v * totalCache + CACHBOTTOMSLOP;
- _CACHEDESTRECT.right = _CACHEDESTRECT.left + mycellSize.h * MAXCACHECOL + myslop.h * 2;
-
- TMScroll( _GTERM, 0, -(bottom-_CACHEDESTRECT.bottom) );
- /* readjust the visible part of the cache area */
- SectRect( &_CACHEDESTRECT, &cur_PORTRECT, &visCacheRect );
-
- if ( !EmptyRect( &visCacheRect ) )
- {
- if ( curVertValue )
- {
- newvalue = mycellSize.v * (curVertValue / oldcellsize.v);
- scrollV = curVertValue-newvalue;
- SetCtlValue( _VERTSCROLLHDL, curVertValue = newvalue);
- }
- }
-
- /* readjust the selection if there's any */
- if ( !EmptyRgn( _OLDRGN ) )
- {
- /* reset selection according to new cellsize */
- oldpoint = GetCellPoint( oldcell1, mycellSize );
- anchorpoint = GetCellPoint( oldcell2, mycellSize );
- GetRegion( _OLDRGN, anchorpoint, oldpoint ); /* get new selection area */
- }
- } /* if ( !EmptyRect( &_CACHEDESTRECT ) ) */
-
- /* readjust the scroll bar value */
- SetVScrollMax();
- SetHScrollMax();
-
- /* pin rect to the top left corner */
- if ( curHoriValue)
- {
- newvalue = mycellSize.h * (curHoriValue/oldcellsize.h);
- scrollH = curHoriValue-newvalue;
- SetCtlValue( _HORISCROLLHDL, curHoriValue = newvalue);
- }
- if (scrollH || scrollV )
- {
- TMScroll( _GTERM, scrollH, scrollV);
- /* offset the cache area */
- OffsetRect( &_CACHEDESTRECT, scrollH, scrollV);
- /* offset the selection */
- OffsetRgn( _OLDRGN, scrollH, scrollV );
- anchorpoint.h += scrollH;
- anchorpoint.v += scrollV;
- oldpoint.h += scrollH;
- oldpoint.v += scrollV;
- /* get the new visible term area */
- SectRect( &(**_GTERM).viewRect, &(**_GTERM).termRect, &_TERMVISRECT);
- SectRect( &_CACHEDESTRECT, &cur_PORTRECT, &visCacheRect );
- /* update the cache area */
- }
- repaint = true;
- } /* if ( mycellSize != oldcellsize ) */
-
- /* has the aux area changed */
- if ( oldAuxTop != termEnvironment.auxSpace.top ||
- oldAuxBottom != termEnvironment.auxSpace.bottom
- ) /* Has the aux area changed ?*/
- {
- /* readjust the control max */
- SetVScrollMax();
- oldAuxTop = termEnvironment.auxSpace.top;
- oldAuxBottom = termEnvironment.auxSpace.bottom;
- /* get new vis term area and validate it */
- SectRect( &(**_GTERM).viewRect, &(**_GTERM).termRect, &_TERMVISRECT);
- InvalRect( &_TERMVISRECT );
- repaint = true;
- }
-
- if ( oldAuxRight != termEnvironment.auxSpace.right ||
- oldAuxLeft != termEnvironment.auxSpace.left
- ) /* Has the aux area changed ?*/
- {
- /* readjust the control max */
- SetHScrollMax();
- oldAuxLeft = termEnvironment.auxSpace.left;
- oldAuxRight = termEnvironment.auxSpace.right;
- SectRect( &(**_GTERM).viewRect, &(**_GTERM).termRect, &_TERMVISRECT);
- InvalRect( &_TERMVISRECT );
- repaint = true;
- }
-
- if ( maxcol != termEnvironment.textCols)
- {
- maxcol = termEnvironment.textCols;
- SectRect( &(**_GTERM).viewRect, &(**_GTERM).termRect, &_TERMVISRECT);
- InvalRect( &_TERMVISRECT );
- repaint = true;
- } /* if ( maxcol <> textCols) */
- /* pin the bottom right of the terminal area to the bottom right of the _PORTRECT if neccessary */
- /* readjust the cache and terminal area */
- if ( (diffV = _PORTRECT.bottom - 15 - (**_GTERM).viewRect.bottom) < 0 )
- diffV = 0;
- if ( (diffH = _PORTRECT.right - 15 - _CACHEDESTRECT.right ) < 0 )
- diffH = 0;
-
- if ( diffV || diffH )
- {
- /* pin the last row and last column to the bottom right of the window */
- ScrollCache( &diffH, &diffV, false ) ;
- repaint = true;
- }
- if ( repaint )
- {
- /* repaint the cache area */
- GetPort( &curport );
- EraseRgn( curport->visRgn); /* erase the old viewRect, should be fixed in the tool */
- InvalRgn( curport->visRgn); /* repaint the current port */
- }
- } /* if ( err = noErr )*/
- } /* if ( ((**_GTERM).errCode ) || Getit )*/
- }
-
- /*******************************************************************
- * DoSelection - hilite the selection
- *
- **********************************************************************/
- DoSelection( )
- {
-
- if ( !EmptyRgn( _OLDRGN ) )
- {
- BitClr( (Ptr) HiliteMode, pHiliteBit ) ;
- if ( isActive )
- InvertRgn(_OLDRGN);
- else
- FrameRgn( _OLDRGN );
- }
- }
-
-
- /*******************************************************************
- * DeSelection - dehilite the selection
- *
- **********************************************************************/
- DeSelection()
- {
- PenState penn;
-
- GetClip( _SAVECLIP );
- ClipRect( &visCacheRect );
-
- if ( !EmptyRgn( _OLDRGN ) )
- {
- BitClr( (Ptr) HiliteMode, pHiliteBit ) ;
- if ( isActive )
- InvertRgn(_OLDRGN); /* invert old selection */
- else
- {
- GetPenState(&penn);
- PenMode(patXor); /* invert old selection frame */
- FrameRgn( _OLDRGN );
- SetPenState(&penn);
- }
- SetEmptyRgn(_OLDRGN );
- }
- SetPt( &oldpoint, -1, -1 ); /* init some points */
- SetPt( &anchorpoint, -1, -1 );
- SetClip( _SAVECLIP );
- }
-
- /*******************************************************************
- * ScrollCache - scroll the cache area
- *
- * scrollHamt - pointer to how much to scroll horizontally
- * scrollVamt - pointer to how much to scroll vertically
- * updatenow - update the area right a way if true, else
- * invalidate the area for later update
- *
- **********************************************************************/
- ScrollCache( scrollHamt, scrollVamt, updatenow )
- short *scrollHamt;
- short *scrollVamt;
- Boolean updatenow;
- {
- Rect cur_PORTRECT;
- Rect scrollrect;
- short locScrollHamt;
- short locScrollVamt;
-
- cur_PORTRECT = _PORTRECT;
- cur_PORTRECT.right -= 15;
- cur_PORTRECT.bottom -= 15;
-
- locScrollVamt = *scrollVamt;
- locScrollHamt = *scrollHamt;
- if ( locScrollHamt)
- {
- if ( locScrollHamt > 0 )
- {
- if ( curHoriValue)
- {
- if ( curHoriValue < locScrollHamt )
- {
- locScrollHamt = *scrollHamt = curHoriValue;
- curHoriValue = 0;
- }
- else
- {
- curHoriValue -= locScrollHamt;
- }
- SetCtlValue( _HORISCROLLHDL, curHoriValue);
- } /* if ( curHoriValue)*/
- else
- *scrollHamt = locScrollHamt = 0;
-
- } /* if ( scrollHamt < 0 )*/
- else
- {
- if ( curHoriValue < maxHCtl)
- {
- if ( (curHoriValue - locScrollHamt) > maxHCtl)
- {
- locScrollHamt = *scrollHamt = curHoriValue-maxHCtl;
- curHoriValue = maxHCtl;
- }
- else
- {
- curHoriValue -= locScrollHamt;
- }
- SetCtlValue( _HORISCROLLHDL, curHoriValue);
- } /* if ( curHoriValue < maxHCtl) */
- else
- *scrollHamt = locScrollHamt = 0;
- } /* else if ( locScrollHamt < 0 ) */
- } /* if ( locScrollHamt)*/
-
- if ( locScrollVamt )
- {
- if ( locScrollVamt > 0 )
- {
- if ( curVertValue)
- {
- if ( curVertValue < locScrollVamt )
- {
- locScrollVamt = *scrollVamt = curVertValue;
- curVertValue = 0;
- }
- else
- curVertValue -= locScrollVamt;
- SetCtlValue( _VERTSCROLLHDL, curVertValue);
- } /* if ( curVertValue ) */
- else
- *scrollVamt = locScrollVamt = 0;
- }
- else
- {
- if ( curVertValue < maxVCtl )
- {
- if ( (curVertValue - locScrollVamt) > maxVCtl)
- {
- locScrollVamt = *scrollVamt = curVertValue-maxVCtl;
- curVertValue = maxVCtl;
- }
- else
- {
- curVertValue -= locScrollVamt;
- }
- SetCtlValue( _VERTSCROLLHDL, curVertValue);
- } /* if ( curVertValue < maxVCtl ) */
- else
- *scrollVamt = locScrollVamt = 0;
- } /* else if ( locScrollVamt < 0 ) */
- } /* if (locScrollVamt) */
-
-
- if (locScrollVamt || locScrollHamt )
- {
- if ( locScrollVamt > 0 )
- {
- /* scroll the terminal area first */
- TMScroll( _GTERM, locScrollHamt, locScrollVamt);
- /* offset and scroll the cache area */
- OffsetRect( &_CACHEDESTRECT, locScrollHamt, locScrollVamt);
- GetScrollRect( &scrollrect );
- ScrollRect( &scrollrect, locScrollHamt, locScrollVamt, _UPDATERGN );
- }
- else
- {
- GetScrollRect( &scrollrect );
- /* scroll the cache area */
- ScrollRect( &scrollrect, locScrollHamt, locScrollVamt, _UPDATERGN );
- /* offset the area */
- OffsetRect( &_CACHEDESTRECT, locScrollHamt, locScrollVamt);
- /* scroll the terminal area */
- TMScroll( _GTERM, locScrollHamt, locScrollVamt);
- }
- /* offset the selection */
- OffsetRgn( _OLDRGN, locScrollHamt, locScrollVamt);
- anchorpoint.h += locScrollHamt;
- anchorpoint.v += locScrollVamt;
- oldpoint.h += locScrollHamt;
- oldpoint.v += locScrollVamt;
- /* get the new visible term area */
- SectRect( &(**_GTERM).viewRect, &(**_GTERM).termRect, &_TERMVISRECT);
- SectRect( &_CACHEDESTRECT, &cur_PORTRECT, &visCacheRect );
- /* update the cache area */
- if ( updatenow )
- UpdateCache( _UPDATERGN );
- else
- InvalRgn( _UPDATERGN );
- }
- }
-
- /*******************************************************************
- * GetScrollRect - get the rect to be scrolled
- *
- * scrollrect - where to return the scroll rect
- *
- **********************************************************************/
- GetScrollRect( scrollrect )
- Rect *scrollrect;
- {
- *scrollrect = _CACHEDESTRECT;
- scrollrect->right = _PORTRECT.right - 15;
- scrollrect->left = _PORTRECT.left;
- if ( scrollrect->bottom > _PORTRECT.bottom - 15)
- scrollrect->bottom = _PORTRECT.bottom - 15;
- }
-
- /*******************************************************************
- * CacheActivate - de/activate the cache area
- *
- * activate - activate if true, else deactivate
- *
- **********************************************************************/
- CacheActivate( window, activate )
- WindowPtr window;
- Boolean activate;
- {
- RgnHandle oldclip;
- PenState penn;
-
- if ( activate )
- {
- /* hilite the scroll bars */
- HiliteControl( _VERTSCROLLHDL, 0 );
- HiliteControl( _HORISCROLLHDL, 0 );
- /* draw the control area */
- InvalRect( &((**_VERTSCROLLHDL).contrlRect) );
- InvalRect( &((**_HORISCROLLHDL).contrlRect) );
- /* redraw the grow box */
- InvalGrowBox();
- }
- else
- {
- HiliteControl( _VERTSCROLLHDL, 255 );
- HiliteControl( _HORISCROLLHDL, 255 );
- DrawGrowIcon(window);
- }
- if ( !EmptyRgn( _OLDRGN ) )
- {
- oldclip = NewRgn();
- GetClip( oldclip ); /* save old clipping region */
- ClipRect( &visCacheRect ); /* set new clip area to cache area */
- GetPenState(&penn);
- PenMode(patXor); /* set up the appro. pen mode for erasing */
- if ( activate && !isActive )
- {
- /* window isn't active, activate it */
- /* acitivate (hilite) the selection */
- BitClr( (Ptr) HiliteMode, pHiliteBit );
- FrameRgn( _OLDRGN); /* erase the framed selection */
- BitClr( (Ptr) HiliteMode, pHiliteBit ); /* hilite selection */
- InvertRgn( _OLDRGN );
- }
- else if ( isActive && !activate )
- {
- /* deactivate the selection */
- BitClr( (Ptr) HiliteMode, pHiliteBit ) ;
- InvertRgn( _OLDRGN ); /* erase old selection */
- BitClr( (Ptr) HiliteMode, pHiliteBit ) ;
- FrameRgn( _OLDRGN); /* frame the area */
- }
- SetClip( oldclip );
- DisposeRgn( oldclip );
- SetPenState(&penn);
- }
- isActive = activate;
- }
-
-