
/* Generated by Interface Builder */

#import "TVWindow.h"
#import "PageView.h"
#import "SheetView.h"
#import "TeXviewObject.h"
#import "dviAccessors.h"
#import <appkit/Application.h>
extern void display() ;
extern void reTeXit() ;
extern void textofront(), consoletofront(), previewtofront(), commandup() ;
extern void mysystem() ;

@implementation TVWindow

extern PageView *myPageView ;
extern SheetView *myView ;
extern TeXviewObject *myTeXviewObject ;
/* extern NXRect *initsizewindow() ; */

+ newContent:(const NXRect *)contentRect style:(int)aStyle
             backing:(int)bufferingType buttonMask:(int)mask
             defer:(BOOL)flag
{
   self = [super newContent:contentRect style:aStyle backing:bufferingType
                 buttonMask:mask defer:flag] ;
   return self ;
}

static NXEvent newevent ;

- keyDown:(NXEvent *)theEvent;
{
   int shiftstate = ((theEvent->flags & NX_SHIFTMASK) ? 1 : 0) +
                    ((theEvent->flags & NX_CONTROLMASK) ? 2 : 0) ;

   switch (theEvent->data.key.charCode) {
   case 174:
      if (shiftstate)
         [myPageView moveRight:shiftstate-1] ;
      else
         dviNextPage() ;
      break ;
   case 172:
      if (shiftstate)
         [myPageView moveLeft:shiftstate-1] ;
      else
         dviPrevPage() ;
      break ;
   case 173:
      [myPageView moveUp:shiftstate] ;
      break ;
   case 175:
      [myPageView moveDown:shiftstate] ;
      break ;
   case '-': case '0': case '1': case '2': case '3': case '4': case '5':
   case '6': case '7': case '8': case '9':
      [myTeXviewObject startRandom:theEvent] ;
      break ;
   case 'q':
      if (NXRunAlertPanel(NULL, "Are you sure you want to exit?",
                     "Cancel", "Exit", 0) == NX_ALERTDEFAULT)
         break ;
   case 'Q':
      [NXApp terminate:self] ;
      break ;
   case ' ':
      if (![myPageView moveDown:shiftstate]) {
       if ( [myTeXviewObject multiColumnScroll] )
         [myPageView TopLeft:1];
       else
         [myPageView Top:1] ;
         if (!dviNextPage())
            display() ;
      }
      break ;
   case 8: case 127:
      if (![myPageView moveUp:shiftstate]) {
         [myPageView Bot:1] ;
         if (!dviPrevPage())
            display() ;
      }
      break ;
   default:
      if ((theEvent->flags & NX_COMMANDMASK) == 0) {
         newevent = *theEvent ;
         newevent.flags |= NX_COMMANDMASK ;
         DPSPostEvent(&newevent, 1) ;
      }
      break ;
   }
   return self ;
}

- appDidUnhide:sender
{
   return self ;
}
@end
