home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc095.zip / ckmpri.c < prev    next >
C/C++ Source or Header  |  1989-08-22  |  8KB  |  219 lines

  1. /*
  2.  * file ckmpri.c
  3.  *
  4.  * Module of mackermit containing code for handling printing.  This code was
  5.  * originally put into ckmusr by John A. Oberschelp of Emory U.
  6.  *
  7.  */
  8.  
  9. /*
  10.  Copyright (C) 1989, Trustees of Columbia University in the City of New York.
  11.  Permission is granted to any individual or institution to use, copy, or
  12.  redistribute this software so long as it is not sold for profit, provided this
  13.  copyright notice is retained.
  14. */
  15.  
  16. #include "ckcdeb.h"
  17. #include "ckcker.h"
  18.  
  19. #define    __SEG__ ckmpri
  20. #include <desk.h>
  21. #include <files.h>
  22. #include <windows.h>
  23. #include <events.h>
  24. #include <dialogs.h>
  25. #include <fonts.h>
  26. #include <menus.h>
  27. #include <toolutils.h>
  28. #include <serial.h>
  29. #include <textedit.h>
  30. #include <segload.h>
  31. #include <ctype.h>
  32.  
  33. #include <printing.h>    /*JAO*/
  34.  
  35. /* here is what is different */
  36. #ifndef __QUICKDRAW__
  37. #include <QuickDraw.h>
  38. #endif
  39. #include <osutils.h>
  40. /* PWP: put the #include for the script manager here! */
  41.  
  42. #include "ckmdef.h"        /* General Mac defs */
  43. #include "ckmres.h"        /* Mac resource equates */
  44. #include "ckmasm.h"        /* new A8 and A9 traps */
  45. #include "ckmcon.h"        /* for fonts */
  46.  
  47.  
  48. int        to_printer = FALSE;                /*JAO*/
  49. int        to_screen = TRUE;                /*JAO*/
  50. int        printer_is_on_line_num;                /*JAO*/
  51. Handle    hPrintBuffer = 0L;                    /*JAO*/
  52. long    lPrintBufferSize;                    /*JAO*/
  53. long    lPrintBufferChars;                    /*JAO*/
  54. long    lPrintBufferAt;                        /*JAO*/
  55.  
  56. extern    MenuHandle menus[];    /* handle on our menus */  /*JAO*/
  57.  
  58. DialogPtr    printingDialog;                    /*JAO*/
  59. DialogPtr    bufferingDialog;                /*JAO*/
  60. DialogPtr    overflowingDialog;                /*JAO*/
  61. DialogPtr    overflowedDialog;                /*JAO*/
  62. DialogPtr    pauseDialog;                    /*JAO*/
  63.  
  64. #define MIN(a,b) ((a)<(b))?(a):(b)                                        /*JAO*/
  65. #define MAX(a,b) ((a)>(b))?(a):(b)                                        /*JAO*/
  66.  
  67. void
  68. now_print()
  69. {
  70.     short    itemhit;                                                /*JAO*/
  71.     long    lPrintBufferIndex;                                        /*JAO*/
  72.     char    PrintBufferChar;                                        /*JAO*/
  73.     CursHandle    watchcurs;                                                /*JAO*/
  74.     int        typeOfDriver;                                            /*JAO*/
  75.     int        chrExtra;                                                /*JAO*/
  76.     int        leftMargin;                                                /*JAO*/
  77.     int        pe;                                                        /*JAO*/
  78.     GrafPtr    oldPort;
  79.     int        temp;
  80.     TPPrPort    myPrPort;
  81.     THPrint    PrintStuff;
  82.     TPrStatus    myStRec;
  83.                                                                                 /*JAO*/
  84.     if (lPrintBufferChars >= lPrintBufferSize) {
  85.         overflowedDialog = GetNewDialog(OVERFLOWEDBOXID, NILPTR, (WindowPtr) - 1);    /*JAO*/
  86.         circleOK(overflowedDialog);                                                /*JAO*/
  87.                                                                                 /*JAO*/
  88.         ModalDialog (NILPROC, &itemhit);                                        /*JAO*/
  89.         DisposDialog(overflowedDialog);                                            /*JAO*/
  90.         if (itemhit == 2) return;    /* Cancel */                                                /*JAO*/
  91.         if (itemhit == 3) {                                                        /*JAO*/
  92.             DisableItem(menus[PRNT_MENU], 0);                                    /*JAO*/
  93.             DrawMenuBar();                                                        /*JAO*/
  94.             DisposHandle(hPrintBuffer);                                            /*JAO*/
  95.             hPrintBuffer = 0L;                                                    /*JAO*/
  96.             return;                                                                /*JAO*/
  97.         }                                                                        /*JAO*/
  98.                                                                                 /*JAO*/
  99.     }                                                                              /*JAO*/
  100.                                                                                 /*JAO*/
  101.     PrintStuff = (THPrint)NewHandle(sizeof(TPrint));                            /*JAO*/
  102.     GetPort(&oldPort);                                                            /*JAO*/
  103.     PrOpen();                                                                    /*JAO*/
  104.     if (PrError() == noErr) {                                                    /*JAO*/
  105.         temp = PrValidate(PrintStuff);                                            /*JAO*/
  106.         temp = PrJobDialog(PrintStuff);                                            /*JAO*/
  107.         if (!temp) {                                                             /*JAO*/
  108.             PrClose();                                                            /*JAO*/
  109.             SetPort(oldPort);                                                    /*JAO*/
  110.             return;                                                                /*JAO*/
  111.         }                                                                        /*JAO*/
  112.         printingDialog = GetNewDialog(PRINTINGBOXID, NILPTR, (WindowPtr) - 1);    /*JAO*/
  113.         DrawDialog (printingDialog);                                            /*JAO*/
  114.         watchcurs = GetCursor(watchCursor);                                        /*JAO*/
  115.         SetCursor(*watchcurs);                                                    /*JAO*/
  116.                                                                                 /*JAO*/
  117.         myPrPort = PrOpenDoc(PrintStuff, nil, nil);                                /*JAO*/
  118.         typeOfDriver = ((*PrintStuff)->prStl.wDev) >> 8;                        /*JAO*/
  119.         if (typeOfDriver == 3) { /*laser*/                                        /*JAO*/
  120.             TextFont(courier);                                                    /*JAO*/
  121.             TextSize(10);                                                        /*JAO*/
  122.             chrExtra = 0;                                                        /*JAO*/
  123.             leftMargin = 36;                                                    /*JAO*/
  124.         } else {                                                                /*JAO*/
  125.             TextFont(VT100FONT);                                                /*JAO*/
  126.             TextSize(9);                                                        /*JAO*/
  127.             chrExtra = 1;                                                        /*JAO*/
  128.             leftMargin = 36;                                                    /*JAO*/
  129.         }                                                                        /*JAO*/
  130.         printer_is_on_line_num = 1;                                                /*JAO*/
  131.         lPrintBufferIndex = (lPrintBufferChars > lPrintBufferSize)                /*JAO*/
  132.                               ? lPrintBufferAt : 0L;                                /*JAO*/
  133.         PrOpenPage(myPrPort, nil);                                                /*JAO*/
  134.         MoveTo(leftMargin, 1 * 12);                                                /*JAO*/
  135.         do {                                                                    /*JAO*/
  136.             if (PrError() != noErr) break;                                        /*JAO*/
  137.             PrintBufferChar = (*hPrintBuffer)[lPrintBufferIndex];                /*JAO*/
  138.             switch (PrintBufferChar) {                                            /*JAO*/
  139.               case 13:                                                            /*JAO*/
  140.                 if (++printer_is_on_line_num > 60) {                            /*JAO*/
  141.                     PrClosePage(myPrPort);                                        /*JAO*/
  142.                     PrOpenPage(myPrPort, nil);                                    /*JAO*/
  143.                     printer_is_on_line_num = 1;                                    /*JAO*/
  144.                 }                                                                /*JAO*/
  145.                 MoveTo(leftMargin, printer_is_on_line_num * 12);                /*JAO*/
  146.               break;                                                            /*JAO*/
  147.                                                                                 /*JAO*/
  148.               case 14:                                                            /*JAO*/
  149.                 if (printer_is_on_line_num != 1) {                                /*JAO*/
  150.                     PrClosePage(myPrPort);                                        /*JAO*/
  151.                     PrOpenPage(myPrPort, nil);                                    /*JAO*/
  152.                     printer_is_on_line_num = 1;                                    /*JAO*/
  153.                 }                                                                /*JAO*/
  154.                 MoveTo(leftMargin, printer_is_on_line_num * 12);                /*JAO*/
  155.               break;                                                            /*JAO*/
  156.                                                                                 /*JAO*/
  157.               default:                                                            /*JAO*/
  158.                 DrawChar(PrintBufferChar);                                        /*JAO*/
  159.                 Move(chrExtra, 0);                                                /*JAO*/
  160.               break;                                                            /*JAO*/
  161.             }                                                                    /*JAO*/
  162.                                                                                 /*JAO*/
  163.             if (++lPrintBufferIndex == lPrintBufferSize) {                        /*JAO*/
  164.                 lPrintBufferIndex = 0L;                                            /*JAO*/
  165.             }                                                                    /*JAO*/
  166.                                                                                 /*JAO*/
  167.         } while (lPrintBufferIndex != lPrintBufferAt);                             /*JAO*/
  168.         PrClosePage(myPrPort);                                                    /*JAO*/
  169.                                                                                 /*JAO*/
  170.         PrCloseDoc(myPrPort);                                                    /*JAO*/
  171.         if ((PrError() == noErr) &&                                                /*JAO*/
  172.             ((**PrintStuff).prJob.bJDocLoop == bSpoolLoop))                        /*JAO*/
  173.             PrPicFile(PrintStuff, nil, nil, nil, &myStRec);                        /*JAO*/
  174.         if ((PrError() != noErr) && (PrError() != 128)) {                        /*JAO*/
  175.             printerr ("Printer error: ", pe);                                    /*JAO*/
  176.         }                                                                        /*JAO*/
  177.                                                                                 /*JAO*/
  178.         DisposDialog(printingDialog);                                            /*JAO*/
  179.     }                                                                            /*JAO*/
  180.     PrClose();                                                                    /*JAO*/
  181.     SetPort(oldPort);                                                            /*JAO*/
  182.     InitCursor();                                                                /*JAO*/
  183.     DisableItem(menus[PRNT_MENU], 0);                                            /*JAO*/
  184.     DrawMenuBar();                                                                /*JAO*/
  185.     DisposHandle(hPrintBuffer);                                                    /*JAO*/
  186.     hPrintBuffer = 0L;                                                            /*JAO*/
  187. }                                                                                /*JAO*/
  188.  
  189. void
  190. pr_stat()
  191. {
  192.     DialogPtr    printDialog;                    /*JAO*/
  193.     char    arg1[256], arg2[256], arg3[256];                        /*JAO*/
  194.     short    itemhit;                                                /*JAO*/
  195.  
  196.  
  197.     printDialog = GetNewDialog(PRINTBOXID, NILPTR, (WindowPtr) - 1);            /*JAO*/
  198.     circleOK(printDialog);                                                        /*JAO*/
  199.                                                                                 /*JAO*/
  200.     NumToString(MAX(lPrintBufferChars - lPrintBufferSize, 0L), arg1);            /*JAO*/
  201.     NumToString(MIN(lPrintBufferSize, lPrintBufferChars), arg2);                /*JAO*/
  202.     NumToString(lPrintBufferSize, arg3);                                        /*JAO*/
  203.     ParamText (arg1, arg2, arg3, "");                                            /*JAO*/
  204.                                                                                 /*JAO*/
  205.     do {                                                                        /*JAO*/
  206.     ModalDialog (NILPROC, &itemhit);                                        /*JAO*/
  207.                                                                                 /*JAO*/
  208.     switch (itemhit) {                                                        /*JAO*/
  209.       case 1:                                                                /*JAO*/
  210.       case 2:                                                                /*JAO*/
  211.       case 3:                                                                /*JAO*/
  212.       break;                                                            /*JAO*/
  213.                                                                                 /*JAO*/
  214.     }                                                                        /*JAO*/
  215.     } while (itemhit > 3);                                                        /*JAO*/
  216.                                                                                  /*JAO*/
  217.     DisposDialog(printDialog);                                                    /*JAO*/
  218. }
  219.