int ioPrintPreProcessing(PrintingLogicPtr printJob,int numberOfPages) { OSStatus status = noErr; UInt32 realNumberOfPagesinDoc; if (printJob->thePrRecHdl == NULL) return -1; printJob->numberOfPages = numberOfPages; printJob->allowPostscript = false; if (!PrJobDialog(printJob->thePrRecHdl)) return -2; if (status == noErr) { // Get the user's Print dialog selection for first and last pages to print. if (status == noErr) { TPPrint foo = *printJob->thePrRecHdl; printJob->firstPage = foo->prJob.iFstPage; printJob->lastPage = foo->prJob.iLstPage; } // Check that the selected page range does not exceed the actual number of // pages in the document. if (status == noErr) { realNumberOfPagesinDoc = printJob->numberOfPages; if (realNumberOfPagesinDoc < printJob->lastPage) printJob->lastPage = realNumberOfPagesinDoc; } // Begin a new print job. printJob->thePrPort = PrOpenDoc(printJob->thePrRecHdl, nil, nil); status = PrError(); } return status; }
OSStatus DoJobPrintDialog(char * jobNameStr) { Boolean accepted = false; #if TARGET_API_MAC_CARBON OSStatus err = 0; UInt32 realNumberOfPagesinDoc; CFStringRef jobNameRef = 0; // Set the job name if(jobNameStr) { jobNameRef = CFStringCreateWithCString(NULL, jobNameStr,kCFStringEncodingMacRoman); if (jobNameRef){ (void)PMSetJobNameCFString (gPrintSettings,jobNameRef); CFRelease (jobNameRef); jobNameRef = 0; } } // Calculate the number of pages required to print the entire document. // err = DetermineNumberOfPagesInDoc(gPageFormat, &realNumberOfPagesinDoc); if(err) goto done; // Set a valid page range before displaying the Print dialog err = PMSetPageRange(gPrintSettings, 1, realNumberOfPagesinDoc); if(err) goto done; // Display the Print dialog. err = PMSessionPrintDialog(gPrintSession, gPrintSettings, gPageFormat, &accepted); #else #pragma unused(jobNameStr) accepted = PrJobDialog(gPrRecHdl); #endif done: if(!accepted) return -1; return noErr; }
boolean shellprint (WindowPtr w, boolean fldialog) { /* 9/5/90 dmb: open and close print resources each time we're called. also, make sure we close each page opened, even when errors occur 9/28/91 dmb: for exit of edit mode before printing 4/24/92 dmb: make sure bJDocLoop is bSpoolLoop before calling PrPicFile, as per IM II-155. otherwise, we can get bogus PrErrors */ // classic mac TPPrPort printport; TPrStatus printstatus; THPrint hp = shellprintinfo.printhandle; SInt32 firstPage = 1; SInt32 lastPage = 9999; short i; boolean fl = false; if (w == nil) /*defensive driving*/ return (false); PrOpen (); if (!shellcheckprinterror (true)) return (false); fl = false; /*until sucessfull print, this is return value*/ if (fldialog) { if (!PrJobDialog (hp)) goto exit; } else PrValidate (hp); setcursortype (cursoriswatch); shellupdateallnow (); /*update all windows that were dirtied by the print dialog*/ shellpushglobals (w); (*shellglobals.settextmoderoutine) (false); /*make sure editing changes are accepted*/ pushport (nil); /*save current port on stack*/ shellprintinfo.printport = printport = PrOpenDoc (hp, nil, nil); currentprintport = w; /*prepares for printing*/ (*shellglobals.beginprintroutine) (); /*fills in fields of printinfo record*/ (*shellglobals.setprintinfoproutine) (); //this only counts the number of pages. // wird in classic lastPage gesetzt? if(lastPage > shellprintinfo.ctpages) lastPage = shellprintinfo.ctpages; for (i = 1; i <= lastPage; i++) { /*print one page*/ if (PrError () != noErr) break; PrOpenPage (printport, nil); if (PrError () == noErr) { SetFractEnable (true); fl = (*shellglobals.printroutine) (i); SetFractEnable (false); } PrClosePage (printport); if (!fl) break; if (keyboardescape ()) { PrSetError (iPrAbort); } } /*for*/ PrCloseDoc (printport); if (fl) { if ( (PrError () == noErr) && ((**hp).prJob.bJDocLoop == bSpoolLoop)) { PrPicFile (hp, nil, nil, nil, &printstatus); } fl = shellcheckprinterror (false); } popport (); (*shellglobals.endprintroutine) (); shellpopglobals (); exit: PrClose (); currentprintport = NULL; return (fl); } /*shellprint*/