home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-07 | 3.9 KB | 154 lines | [TEXT/MPCC] |
- // ----------------------------------------------------------------------------------
- // PrintLoop.c
- // ----------------------------------------------------------------------------------
- // Handles all printing
- //
- // This demo is copywrite 1994 by LexTek Internation. Feel free to use it for
- // whatever purpose you wish. The SpellWright Library may not be copied or
- // distributed, except when linked to your application that adds significant features
- // to the code. ie. you can't take the library, make a new library and sell it. You
- // can, however, use it without royalties in applications or other such projects.
- //
- // LexTek International
- // 2255 N. University Parkway, Suit 15
- // Provo, UT 84604
- // (801) 375.8332 Phone
- // (801) 375.7654 Fax
- //
- // ----------------------------------------------------------------------------------
- // History:
- // 8/26/94 Clark Goble Original (Doesn't do much right now)
- //
-
- #include "Printing.h"
-
- pascal void PrintIdleProc(void);
- void PrintWindow(void);
-
-
- // ----------------------------------------------------------------------------------
-
- extern void ErrMsgCode(Str255 msg, short code);
-
- // ----------------------------------------------------------------------------------
- // PrintIdleProc
- // ----------------------------------------------------------------------------------
- // Callback routine for printing.
-
- pascal void PrintIdleProc( void )
- {
- short err;
-
- err = PrError();
-
- // spin cursor here
-
- if(err) {
- InitCursor(); // restore cursor to arrow
-
- ErrMsgCode("\pI'm in the printing idle proc.",err);
- }
- }
-
-
- // ----------------------------------------------------------------------------------
- // PrintWindow
- // ----------------------------------------------------------------------------------
- // Prints a window. We use a goto to correctly handle printer closing. I probably
- // should clean this up later, but for now I'm just more or less copying Apple's
- // code.
-
- void PrintWindow( void )
- {
- static PrIdleUPP PrintIdleProcUPP;
- THPrint PrinterInfo;
- TPPrPort printPort;
- short err;
- TPrStatus PrinterStat;
-
- PrinterInfo = (THPrint)NewHandle(sizeof(TPrint));
-
- if(!PrinterInfo) {
- ErrMsgCode("\pAllocating TPrint failed.",0);
- return;
- }
-
- PrOpen(); // open the printer
- if((err = PrError()) != 0)
- {
- ErrMsgCode("\p PrOpen failed.",err);
- goto exit;
- }
-
- if(!PrStlDialog(PrinterInfo)) // put up page setup dialog
- goto exit;
-
- if((err = PrError()) != 0) {
- ErrMsgCode("\p PrStlDialog failed.",err);
- goto exit;
- }
-
- if(!PrJobDialog(PrinterInfo)) // put up print dialog
- goto exit;
-
- if((err = PrError()) != 0) {
- ErrMsgCode("\p PrJobDialog failed.",err);
- goto exit;
- }
-
- // Install the idle proc
- PrintIdleProcUPP = NewPrIdleProc((ProcPtr) PrintIdleProc);
- SetCursor(*GetCursor(watchCursor));
- (**PrinterInfo).prJob.pIdleProc = PrintIdleProcUPP;
-
- // Setup the print grafport
- printPort = PrOpenDoc(PrinterInfo, nil, nil);
- if((err = PrError()) != 0) {
- ErrMsgCode("\p PrOpenDoc failed.",err);
- goto exit;
- }
-
- // Loop through these for page number of times
- {
- // Print a page
- PrOpenPage(printPort, nil);
- if((err = PrError()) != 0) {
- ErrMsgCode("\p PrOpenPage failed.",err);
- goto exit;
- }
-
- /* Draw printing here Code here (draw in print port) */
-
- // Close the page
- PrClosePage(printPort);
- if((err = PrError()) != 0) {
- ErrMsgCode("\p PrClosePage failed.",err);
- goto exit;
- }
- }
-
- // Close the Printer
- PrCloseDoc(printPort);
- if((err = PrError()) != 0) {
- ErrMsgCode("\p PrCloseDoc failed.",err);
- goto exit;
- }
-
- // Physically print the spooled print job
- if( ((**PrinterInfo).prJob.bJDocLoop == bSpoolLoop))
- PrPicFile( PrinterInfo, nil, nil, nil, &PrinterStat);
-
- if((err = PrError()) != 0) {
- ErrMsgCode("\p PrPicFile failed.",err);
- goto exit;
- }
-
- exit:
- // Clean up and close the printer driver
- PrClose();
- if((err = PrError()) != 0)
- ErrMsgCode("\p PrClose failed.",err);
-
- InitCursor();
-
- } // PrintWindow