home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / p / prbgi097.zip / C.ZIP / TVPRTF.CPP < prev    next >
Text File  |  1992-12-15  |  5KB  |  164 lines

  1. #define Uses_TRect
  2. #define Uses_TView
  3. #define Uses_TStaticText
  4. #define Uses_TWindowInit
  5. #define Uses_TDialog
  6. #define Uses_TButton
  7. #define Uses_TSystemError
  8. #define Uses_TEventQueue
  9. #define Uses_TScreen
  10. #define Uses_TApplication
  11. #define Uses_TDeskTop
  12. #define Uses_TStatusLine
  13.  
  14. #include <graphics.h>
  15. #include <stdlib.h>
  16. #include <dos.h>
  17. #include <conio.h>
  18.  
  19. #include <tv.h>
  20.  
  21. #include "TVBGI.H"
  22. #include "scroll.h"
  23. #include "PRTgraph.h"
  24. #include "OUTMSG.H"
  25.  
  26. extern int ScreenPreview;
  27.  
  28. /*----------------------------*/
  29. class TPrDialog: public TDialog
  30. /*----------------------------*/
  31. {
  32.    PRT__handleT far *handlePPtr;
  33.    virtual void handleEvent(TEvent& event);
  34.    public:
  35.    TPrDialog ( const TRect& bound, const char *aTitle, PRT__handleT far *hPPtr ):
  36.                 TDialog(bound, aTitle),
  37.                 TWindowInit( &TDialog::initFrame )
  38.                 { handlePPtr = hPPtr; };
  39. };
  40.  
  41.  
  42. /*----------------------------*/
  43. void TPrDialog::handleEvent(TEvent& event)
  44. /*----------------------------*/
  45. {
  46.    if ( event.what==evCommand && event.message.command==cmOK )
  47.    {
  48.       TStaticText *pt = new TStaticText( TRect(3,5,37,6), "Printing");
  49.       insert(pt);
  50.       redraw();
  51.       helpCtx = hcGraphPrint;
  52.       TProgram::application->statusLine->update();
  53.       TEventQueue::suspend();
  54.       int  ReturnCode =  PRT_PrintBuffer(handlePPtr);
  55.       TEventQueue::resume();
  56.    }
  57.    TDialog::handleEvent(event);
  58. };
  59.  
  60.  
  61. /*----------------------------*/
  62. int _PRT__pascal TVUserPrtFunc( void far* UserPtr,
  63.                                 PRT__handleT   *handlePPtr,
  64.                                 const char far* BGIpath )
  65. /*----------------------------*/
  66. {  int  graphdriver=DETECT,graphmode=0;
  67.    int  Scrn_x1,Scrn_y1,dx,dy,buf_x,buf_y,Scrn_width,Scrn_height;
  68.    int  deltaX,deltaY;
  69.    int  c;
  70.    int  ReturnCode=0;
  71.    struct viewporttype ts;
  72.  
  73.  
  74.      if ( ScreenPreview && PRT_PreviewPossible(0) )
  75.       {
  76.          // bgiApp. suspend();
  77.          // TSystemError::suspend();
  78.          TEventQueue::suspend();
  79.          TScreen::suspend();
  80.  
  81.          // If you didn't use BGI_initgraph before PRT_PrintBGI you must
  82.          // initiate graphic mode using either initgraph or BGI_initgraph
  83.          // function
  84.              BGI_initgraph(&graphdriver,&graphmode,BGIpath,Scrn_BGIgroup);
  85.              if ( graphresult() ) return 16;
  86.  
  87.          getviewsettings(&ts);
  88.          Scrn_x1=0; Scrn_y1=16;
  89.  
  90.          /* Draw message at the top of the screen */
  91.          setviewport ( 0,0, getmaxx()+1,Scrn_y1-1, 1);
  92.          if ( getmaxcolor()>1 )
  93.             setcolor(getmaxcolor());
  94.          else
  95.             setcolor(0);
  96.          setfillstyle(SOLID_FILL,1);
  97.          bar(0,0,getmaxx(),Scrn_y1-1);
  98.          settextjustify(CENTER_TEXT, TOP_TEXT);
  99.          outtextxy(getmaxx()/2,1,"Use \x18 \x19 \x1a \x1b to scroll" );
  100.                                     // "   
  101.          Scrn_width=getmaxx()+1-Scrn_x1; Scrn_height=getmaxy()+1-Scrn_y1;
  102.          setviewport ( Scrn_x1,Scrn_y1,
  103.                        Scrn_x1+Scrn_width-1,Scrn_y1+Scrn_height-1,1);
  104.          clearviewport();
  105.  
  106.          Scrn_x1=(Scrn_x1+15)&(-16);    Scrn_y1=(Scrn_y1+15)&(-16);
  107.          if ( Scrn_x1+Scrn_width  > getmaxx()+1 ) Scrn_width= (getmaxx()-Scrn_x1+1);
  108.          if ( Scrn_y1+Scrn_height > getmaxy()+1 ) Scrn_height=(getmaxy()-Scrn_y1+1);
  109.          Scrn_width &= (-16);
  110.  
  111.          deltaX = (Scrn_width/5+15) & (-16);
  112.          deltaY = (Scrn_height/5+15) & (-16);
  113.  
  114.          buf_x=buf_y=0;
  115.          //
  116.          // Note that all values passed to PRT_MoveToScrn and PRT_ScrollScrn
  117.          // functions should be evenly divided by 16.
  118.          //
  119.          PRT_MoveToScrn (buf_x,buf_y, Scrn_x1,Scrn_y1,Scrn_width,Scrn_height);
  120.  
  121.          do
  122.          {
  123.             if (!kbhit()) { sound(650);delay(5);nosound(); }
  124.             dx=dy=0;
  125.             if ( (c=getch())==0)
  126.             {
  127.                switch (c=getch())
  128.                {
  129.                   case 0x4b: dx=-deltaX; c=0;  break;  // left
  130.                   case 0x4d: dx=deltaX;  c=0;  break;  // right
  131.                   case 0x50: dy=deltaY;  c=0;  break;  // down
  132.                   case 0x48: dy=-deltaY; c=0;  break;  // up
  133.                   default: ;
  134.                }
  135.             }
  136.             PRT_ScrollScrn ( &dx, &dy );
  137.             // buf_x += dx; buf_y += dy;  // you may uncomment it if you need
  138.          } while (c==0);
  139.          BGI_closegraph();
  140.          // bgiApp.resume();
  141.          // TSystemError::resume();
  142.          TEventQueue::resume();
  143.          TScreen::resume();
  144.          TProgram::application->redraw();
  145.       }
  146.  
  147.  
  148.       if ( c!=0x1b ) // do not print if Esc key pressed
  149.       {
  150.          TPrDialog *d = new TPrDialog(TRect(0,0,42,10), "About to Print",handlePPtr);
  151.          d->options |= ofCentered;
  152.          d->insert(new TStaticText( TRect(3,2,37,3), "If you want to print press OK button"));
  153.          d->insert(new TStaticText( TRect(3,3,37,4), "otherwise press Cancel"));
  154.          //  Buttons
  155.          d->insert(new TButton( TRect(27,7,36,9), "~C~ancel", cmCancel, bfNormal) );
  156.          d->insert(new TButton( TRect(10,7,19,9),"O~K~", cmOK, bfDefault) );
  157.          TProgram::deskTop->execView(d);
  158.          TProgram::deskTop->destroy(d);
  159.       }
  160.       else ReturnCode=PRT_USER_INTERRUPT;
  161.  
  162.    return ReturnCode;
  163. }
  164.