ftp.nice.ch/pub/next/text/tex/apps/TeXview-kp0.25.s.tar.gz#/HyperTeXview/SheetView.m

This is SheetView.m in view mode; [Download] [Up]

/* Generated by tgr */

#import "PageView.h"
#import "SheetView.h"
#import <dpsclient/wraps.h>
#import "TVWindow.h"
#import "dviAccessors.h"
#import <appkit/NXCursor.h>
#import <appkit/Application.h>
#import "TeXviewSwitchBoard.h"

@implementation SheetView

extern TeXviewSwitchBoard *myTeXviewSwitchBoard ;

extern shalfword hh, vv ;
extern shalfword hhoffset, vvoffset ;
extern shalfword hhmin, hhmax, vvmin, vvmax ;
extern shalfword hhsize, vvsize ;
extern shalfword rhhsize, rvvsize ;
extern shalfword hhmarg, vvmarg ;
extern Boolean orientationset ;
extern Boolean landscape ;
extern Boolean dualpage ;
extern FILE *dvifile ;
extern integer pagenum, seq ;
extern fontdesctype *curfnt ;
extern char realname[] ;
extern int curpsfont ;
Boolean pagedrawn ;

extern id fpageinit() ;
extern void makeraster(), outline() ;
extern void dopage(), error() ;
extern void free(), pagereport() ;
extern void tolandscape() ;
extern void reportname() ;
extern void TPSinit(), TPSselfont(), TPSshow(), TPSQshow(), TPSmoveto() ;
extern void TPShmove(), TPSxshow() ;
extern void fixalertbug() ;
static int offset = 0 ;
extern id makenewdoc() ;
extern void fdrawrule();


- initFrame:(const NXRect *)theFrame
{
   NXSize nxs ;
   self = [super initFrame:theFrame];
   nxs.width = mhhsize = 1036 ;
   nxs.height = mvvsize = 1336 ;
   cache = [NXImage newSize:&nxs] ;
   [cache setFlipped:YES] ;
   return self ;
}
/* moved to TeXSwitchBoard
id makenewdoc(hsize, vsize)
int hsize, vsize ;
{
   return [myView makeNewDoc:hsize:vsize] ;
}
*/
- makeNewDoc:(int)hsize:(int)vsize
{
   if (hsize == ohhsize && vsize == ovvsize)
      return 0 ;
   ohhsize = hsize ;
   ovvsize = vsize ;
   [myTeXviewSwitchBoard noScrollUpdates] ;
   [myTeXviewSwitchBoard cachePosition:hsize:vsize] ;

   if (hsize > mhhsize || vsize > mvvsize) {
      NXSize nxs ;
      if (hsize > mhhsize)
         mhhsize = hsize ;
      if (vsize > mvvsize)
         mvvsize = vsize ;
      nxs.width = mhhsize ;
      nxs.height = mvvsize ;
      [cache setSize:&nxs] ;
   }
   offset = mvvsize - vsize ;
   [self sizeTo:hsize:vsize] ;
   [myTeXviewSwitchBoard unCachePosition:hsize:vsize] ;
   [myTeXviewSwitchBoard scrollUpdates] ;

   return self ;
}

- update
{
   if ([self needsDisplay])
      [self display] ;
   return(self) ;
}

static int dontbother ;
/* moved to TeXSwitchBoard
void display()
{  
   dontbother = 1 ;
   (void)fpageinit() ;
   dontbother = 0 ;
   [myView display] ;
}
*/

- drawSelf:(NXRect *)rects :(int)rectCount
{
    NXRect r ;
  
   if (dontbother)
       return self ;
    if ((! pagedrawn)) {
       [cache lockFocus] ;
/*   offset = mvvsize - vsize ; should always be true? */
       PStranslate(0, mvvsize - rvvsize) ;
/*     PSsetgray(1.0) ; */
       NX_WIDTH(&r) = rhhsize ;
       NX_HEIGHT(&r) = rvvsize ;
       NX_X(&r) = 0 ;
       NX_Y(&r) = 0 ;
       NXEraseRect(&r) ;
/*     PSclippath() ;
       PSfill() ; */
       outline() ;
       if (dvifile != NULL)
         dopage((int)self) ;
       [myTeXviewSwitchBoard saveCurrentContext] ;
       PSflush() ;
       [cache unlockFocus] ;    
#ifdef TRACKCACHE
       { int bsize, bmax, msize ;
         PScachestatus(&bsize, &bmax, &msize) ;
         printf("bsize=%d bmax=%d msize=%d\n", bsize, bmax, msize) ;
       }
       { int used, max, level ;
         PSvmstatus(&level, &used, &max) ;
         printf("vmused=%d\n", used) ;
       }
#endif
    }
    PSflush() ;
// [self lockFocus] ; 
   [cache composite:NX_COPY fromRect:rects toPoint:&rects->origin];
//  [self unlockFocus] ; 
    return self;
}

- free
{
   if (cache) [cache free];
   return [super free];
}

#define SHOWBUFSIZE (2000)
static char showbuf[SHOWBUFSIZE] ;
static char *showbufp = showbuf ;
static int showx[SHOWBUFSIZE] ;
static int *showxp = showx ;
static int rhh = -3200, rvv = -3200 ;

void strflush() {

   if (showx[0] && showbufp > showbuf)
      TPShmove(showx[0]) ;
   if (showbufp > showbuf) {
      if (rhh > -3000) {
         *showxp++ = hh - rhh ;
         rhh = hh ;
      } else
         *showxp++ = 0 ;
      TPSxshow(showbuf, &(showx[1]), showbufp - showbuf) ;
/*    TPSshow(showbuf, showbufp - showbuf) ; */
      showbufp = showbuf ;
      showxp = showx ;
   }
}

void texflush() {
   strflush() ;
   rhh = -3200 ;
   rvv = -3200 ;
   curpsfont = -1 ;
}
/* moved to TeXSwitchBoard
void fdrawrule(xx, yy)
halfword xx, yy ;
{
   register shalfword hmin, hmax, vmin, vmax ;

   if (xx>0 && yy>0) {
      hmin = hh+hhoffset ;
      hmax = hmin + xx - 1 ;
      vmax = vv+vvoffset ;
      vmin = vmax - yy + 1 ;
      [myView drawRule:xx:yy] ;
   }
}
*/
- drawRule:(int)x:(int)y
{
   PSrectfill(hh + hhoffset, vv + vvoffset - y, x, y) ;
   return(self) ;
}
@end

void hvpos() {
   texflush() ;
   TPSmoveto(hh + hhoffset, vv + vvoffset) ;
   rhh = hh ;
   rvv = vv ;
}

void fdrawchar(c, e)
char c ;
int e ;
{
   if (rvv == vv) {
/*    if (rhh != hh) {
         if (showbufp > showbuf) {
            TPSQshow(showbuf, showbufp-showbuf, hh-rhh) ;
            showbufp = showbuf ;
         } else
            TPSmoveto(hh + hhoffset, vv + vvoffset) ;
         rhh = hh ;
      } */
      if (rhh < -3000)
         hvpos() ;
   } else {
      strflush() ;
      TPSmoveto(hh + hhoffset, vv + vvoffset) ;
      rhh = hh ;
      rvv = vv ;
   }
   *showbufp++ = c ;
   *showxp++ = hh - rhh ;
   rhh = hh ;
}
/*
 *   Set things up for a new page, including calculating the number of
 *   raster rows we have in the buffer.  Everything must be 16-bit
 *   aligned.
 */
id fpageinit() {
   if (landscape && !orientationset)
      tolandscape() ;
   return makenewdoc(rhhsize, rvvsize) ;
}

void outline() {
   int safehh, safevv ;
   pagereport(pagenum, seq) ;
   safehh = hh ; safevv = vv ;
   hh = - hhmarg - 2 ; vv = - vvmarg - 1 ;
   fdrawrule(hhsize + 4, 2) ;
   vv = vvsize - vvmarg ;
   fdrawrule(2, vvsize + 2) ;
   fdrawrule(hhsize + 4, 2) ;
   hh = hhsize - hhmarg ;
   fdrawrule(2, vvsize + 2) ;
   if (dualpage) {
      hh = hhsize / 2 - hhmarg - 1 ;
      fdrawrule(2, vvsize + 2) ;
   }
   hh = safehh ;
   vv = safevv ;
   orientationset = 1 ;
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.