void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps) { Q_Q(QMacPrintEngine); QSizeF newSize = qt_paperSizeToQSizeF(ps); QCFType<CFArrayRef> formats; PMPrinter printer; if (PMSessionGetCurrentPrinter(session, &printer) == noErr && PMSessionCreatePageFormatList(session, printer, &formats) == noErr) { CFIndex total = CFArrayGetCount(formats); PMPageFormat tmp; PMRect paper; for (CFIndex idx = 0; idx < total; ++idx) { tmp = static_cast<PMPageFormat>( const_cast<void *>(CFArrayGetValueAtIndex(formats, idx))); PMGetUnadjustedPaperRect(tmp, &paper); int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5); int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5); if (newSize.width() == wMM && newSize.height() == hMM) { PMCopyPageFormat(tmp, format); // reset the orientation and resolution as they are lost in the copy. q->setProperty(QPrintEngine::PPK_Orientation, orient); if (PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) != noErr) { // Don't know, warn for the moment. qWarning("QMacPrintEngine, problem setting format and resolution for this page size"); } break; } } } }
// --------------------------------------------------------------------------- // // ------------ static OSStatus DoPageSetupDialog(PMPrintSession ps, PMPageFormat* pf){ OSStatus status=noErr; if(*pf==kPMNoPageFormat){ status=PMCreatePageFormat(pf); if((status==noErr)&&(*pf!=kPMNoPageFormat)){ status=PMSessionDefaultPageFormat(ps,*pf); } } else{ status=PMSessionValidatePageFormat(ps,*pf,kPMDontWantBoolean); } if(status==noErr){ status=NSRunPageLayout(*pf); if(status==cNSOKButton){ NSCopyPageFormat(*pf); if(*pf!=kPMNoPageFormat){ status=noErr; } else{ status=kPMCancel; } } else{ status=kPMCancel; } } return(status); }
//----------------------------------------------------------------------------------------------------------------------- // (Borrowed from /Developer/Examples/Printing/App/) static OSStatus DoPageSetupDialog(PMPrintSession printSession, PMPageFormat* pageFormat, CFDataRef* flattenedPageFormat) { OSStatus status = noErr; if (*pageFormat == kPMNoPageFormat) // Set up a valid PageFormat object { MyCreatePageFormat(printSession, pageFormat); } else { status = PMSessionValidatePageFormat(printSession, *pageFormat, kPMDontWantBoolean); } if (status == noErr) // Display the Page Setup dialog { Boolean accepted; status = PMSessionPageSetupDialog(printSession, *pageFormat, &accepted); if (status == noErr && !accepted) status = kPMCancel; // user clicked Cancel button } // If the user did not cancel, flatten and save the PageFormat object with our document if ((status == noErr) && (flattenedPageFormat != NULL)) { status = PMFlattenPageFormatToCFData(*pageFormat, flattenedPageFormat); } return status; } // DoPageSetupDialog
OSStatus OpenPrinterAndValidate(void) { OSStatus err = noErr; #if TARGET_API_MAC_CARBON ///////////////////////////////////////////////// err = PMCreateSession(&gPrintSession); if(err) return err; // get and validate the page formatting if (gPageFormat == kPMNoPageFormat) { // Set up a valid PageFormat object err = PMCreatePageFormat(&gPageFormat); // Note that PMPageFormat is not session-specific, but calling // PMSessionDefaultPageFormat assigns values specific to the printer // associated with the current printing session. if ((err == noErr) && (gPageFormat != kPMNoPageFormat)) err = PMSessionDefaultPageFormat(gPrintSession, gPageFormat); } else{ err = PMSessionValidatePageFormat(gPrintSession, gPageFormat, kPMDontWantBoolean); } if(err) return err; ///////////////////////////////////////////////// // let's also get and validate the print settings if (gPrintSettings == kPMNoPrintSettings) { err = PMCreatePrintSettings(&gPrintSettings); // Note that PMPrintSettings is not session-specific, but calling // PMSessionDefaultPrintSettings assigns values specific to the printer // associated with the current printing session. if ((err == noErr) && (gPrintSettings != kPMNoPrintSettings)) err = PMSessionDefaultPrintSettings(gPrintSession, gPrintSettings); } else { err = PMSessionValidatePrintSettings(gPrintSession, gPrintSettings, kPMDontWantBoolean); } return err; #else //// MACB4CARBON //////////////////////////////////////// ///////////////////////////////////////////////// PrOpen(); err = PrError(); if(err) return err; // always use the global if(gPrRecHdl == nil){ gPrRecHdl = (THPrint)_NewHandleClear(sizeof(TPrint)); if(!gPrRecHdl)return memFullErr; PrintDefault(gPrRecHdl); } PrValidate(gPrRecHdl); // We ignore the returned value return(noErr); #endif }
void QPrinter::interpret(PMPageFormat *f) { //get values PMOrientation o; if (PMGetOrientation(*f, &o) == noErr) setOrientation(o == kPMPortrait ? Portrait : Landscape); //Finally we update the scale so the resolution is effected by it PMSessionValidatePageFormat(psession, *f, kPMDontWantBoolean); setPageSize(carbonSize2QPrinterSize(*f)); }
bool QPrinter::cmd(int c, QPainter *, QPDevCmdParam *) { if (!psession && PMCreateSession(&psession) != noErr) return FALSE; if (c == PdcBegin) { // begin; start printing if (state != PST_IDLE) { qDebug("Qt: internal: printer: two PdcBegin(s)."); return FALSE; } //just to be sure they've been setup prepare(&pformat); prepare(&psettings); //validate the settings if (PMSessionValidatePrintSettings(psession, psettings, kPMDontWantBoolean) != noErr) return FALSE; if (PMSessionValidatePageFormat(psession, pformat, kPMDontWantBoolean) != noErr) return FALSE; if (PMSessionBeginDocument(psession, psettings, pformat) != noErr) //begin the document return FALSE; if (PMSessionBeginPage(psession, pformat, 0) != noErr) //begin the page return FALSE; if (PMSessionGetGraphicsContext(psession, kPMGraphicsContextQuickdraw, &hd) != noErr) //get the gworld return FALSE; state = PST_ACTIVE; if (fullPage()) { uint top, left, bottom, right; qt_get_margins(pformat, &top, &left, &bottom, &right); QMacSavedPortInfo mp(this); SetOrigin(top, left); } else { QMacSavedPortInfo mp(this); SetOrigin(0, 0); } } else if (c == PdcEnd) { if (hd && state != PST_IDLE) { PMSessionEndPage(psession); PMSessionEndDocument(psession); hd = NULL; } state = PST_IDLE; } else { // all other commands... if (state == PST_ABORTED || ((state == PST_ACTIVE || state == PST_ERROR) && PMSessionError(psession) != noErr)) return FALSE; } return TRUE; }
void wxMacCarbonPrintData::ValidateOrCreate() { OSStatus err = noErr ; if ( m_macPrintSession == kPMNoReference ) { err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ; } // Set up a valid PageFormat object. if ( m_macPageFormat == kPMNoPageFormat) { err = PMCreatePageFormat((PMPageFormat *) &m_macPageFormat); // Note that PMPageFormat is not session-specific, but calling // PMSessionDefaultPageFormat assigns values specific to the printer // associated with the current printing session. if ((err == noErr) && ( m_macPageFormat != kPMNoPageFormat)) { err = PMSessionDefaultPageFormat((PMPrintSession) m_macPrintSession, (PMPageFormat) m_macPageFormat); } } else { err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession, (PMPageFormat) m_macPageFormat, kPMDontWantBoolean); } // Set up a valid PrintSettings object. if ( m_macPrintSettings == kPMNoPrintSettings) { err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings); // Note that PMPrintSettings is not session-specific, but calling // PMSessionDefaultPrintSettings assigns values specific to the printer // associated with the current printing session. if ((err == noErr) && ( m_macPrintSettings != kPMNoPrintSettings)) { err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession, (PMPrintSettings) m_macPrintSettings); } } else { err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession, (PMPrintSettings) m_macPrintSettings, kPMDontWantBoolean); } }
bool QMacPrintEngine::begin(QPaintDevice *dev) { Q_D(QMacPrintEngine); if (d->state == QPrinter::Idle && d->session == 0) // Need to reinitialize d->initialize(); d->paintEngine->state = state; d->paintEngine->begin(dev); Q_ASSERT_X(d->state == QPrinter::Idle, "QMacPrintEngine", "printer already active"); if (PMSessionValidatePrintSettings(d->session, d->settings, kPMDontWantBoolean) != noErr || PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean) != noErr) { d->state = QPrinter::Error; return false; } if (!d->outputFilename.isEmpty()) { QCFType<CFURLRef> outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, QCFString(d->outputFilename), kCFURLPOSIXPathStyle, false); if (PMSessionSetDestination(d->session, d->settings, kPMDestinationFile, kPMDocumentFormatPDF, outFile) != noErr) { qWarning("QMacPrintEngine::begin: Problem setting file [%s]", d->outputFilename.toUtf8().constData()); return false; } } OSStatus status = noErr; #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { status = d->shouldSuppressStatus() ? PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format) : PMSessionBeginCGDocument(d->session, d->settings, d->format); } else #endif { #ifndef Q_OS_MAC64 status = d->shouldSuppressStatus() ? PMSessionBeginDocumentNoDialog(d->session, d->settings, d->format) : PMSessionBeginDocument(d->session, d->settings, d->format); #endif } if (status != noErr) { d->state = QPrinter::Error; return false; } d->state = QPrinter::Active; setActive(true); d->newPage_helper(); return true; }
// ----------------------------------------------------------------- OSStatus DoPageSetup(WindowRef window, void *docDataP) { OSStatus err = noErr; if(docDataP){ PMPrintSession printSession; err = PMCreateSession(&printSession); if(!err){ Boolean accepted; static PMSheetDoneUPP myPageSetupDoneProc = NULL; if(!myPageSetupDoneProc){ myPageSetupDoneProc = NewPMSheetDoneUPP(MyPageSetupDoneProc); if(!myPageSetupDoneProc){ err = memFullErr; } } if(!err) // validate the page format we're going to pass to the dialog code err = PMSessionValidatePageFormat(printSession, GetPageFormatFromPrivateData(docDataP), kPMDontWantBoolean); if(!err){ Boolean sheetsAreAvailable = true; err = PMSessionUseSheets(printSession, window, myPageSetupDoneProc); if(err == kPMNotImplemented){ // sheets are not available (aka, Mac OS 8/9) err = noErr; sheetsAreAvailable = false; } if(!err){ err = PMSessionPageSetupDialog(printSession, GetPageFormatFromPrivateData(docDataP), &accepted); /* when using sheets, the value of 'accepted' returned here is irrelevant since it is our sheet done proc that is called when the dialog is dismissed. Our dialog done proc will be called when the sheet is dismissed. If sheets are NOT implemented then WE call our DialogDone proc here to complete the dialog. */ if(err == noErr && !sheetsAreAvailable) MyPageSetupDoneProc(printSession, window, accepted); } } if(err){ // only if there is an error do we release the session, // otherwise we'll do that in our sheet done proc (void)PMRelease(printSession); } } } DoErrorAlert(err, kMyPrintErrorFormatStrKey); return err; } // DoPageSetup
static boolean carbonSessionDefaultPageAndSettingValidate(void) { #if TARGET_API_MAC_CARBON == 1 OSStatus theErr; Boolean f; theErr = PMSessionDefaultPageFormat( shellprintinfo.printhandle, shellprintinfo.pageformat); if(theErr != noErr) goto error; theErr = PMSessionValidatePageFormat( shellprintinfo.printhandle, shellprintinfo.pageformat, &f); if(theErr != noErr) goto error; theErr = PMSessionDefaultPrintSettings( shellprintinfo.printhandle, shellprintinfo.printsettings); if(theErr != noErr) goto error; theErr = PMSessionValidatePrintSettings( shellprintinfo.printhandle, shellprintinfo.printsettings, &f); if(theErr != noErr) goto error; return (true); error: carbonKillPrintVars(); #endif return false; }
/*------------------------------------------------------------------------------ Allow the user define the page setup for printing to current printer Parameters: printSession - current printing session pageFormat - a PageFormat object addr Description: If the caller passes in an empty PageFormat object, create a new one, otherwise validate the one provided by the caller. Invokes the Page Setup dialog and checks for Cancel. Flattens the PageFormat object so it can be saved with the document. Note that the PageFormat object is modified by this function. ------------------------------------------------------------------------------*/ static void _doPageSetupDialog(PMPageFormat* pageFormat) { OSStatus status; Boolean accepted; PMPrintSession printSession; status = PMCreateSession(&printSession); if ( noErr != status ) { PostPrintingErrors(status); return; } // Set up a valid PageFormat object. if (*pageFormat == kPMNoPageFormat) { status = PMCreatePageFormat(pageFormat); // Note that PMPageFormat is not session-specific, but calling // PMSessionDefaultPageFormat assigns values specific to the printer // associated with the current printing session. if ((status == noErr) && (*pageFormat != kPMNoPageFormat)) status = PMSessionDefaultPageFormat(printSession, *pageFormat); } else { status = PMSessionValidatePageFormat(printSession, *pageFormat, kPMDontWantBoolean); } // Display the Page Setup dialog. if (status == noErr) { status = PMSessionPageSetupDialog(printSession, *pageFormat, &accepted); if (!accepted) { status = kPMCancel; // user clicked Cancel button } } status = PMRelease(printSession); return; }
bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) { TransferPrinterNameFrom(data); TransferPaperInfoFrom(data); TransferResolutionFrom(data); // after setting the new resolution the format has to be updated, otherwise the page rect remains // at the 'old' scaling PMSessionValidatePageFormat(m_macPrintSession, m_macPageFormat, kPMDontWantBoolean); PMSessionValidatePrintSettings(m_macPrintSession, m_macPrintSettings, kPMDontWantBoolean); #if wxOSX_USE_COCOA UpdateFromPMState(); #endif return true ; }
static void initPrinter () { Boolean result; PMResolution res300 = { 300, 300 }, res600 = { 600, 600 }; if (! theMacPrintSettings) { // once PMCreateSession (& theMacPrintSession); // initialize the Printing Manager PMCreatePageFormat (& theMacPageFormat); PMCreatePrintSettings (& theMacPrintSettings); PMSessionDefaultPageFormat (theMacPrintSession, theMacPageFormat); PMSessionDefaultPrintSettings (theMacPrintSession, theMacPrintSettings); } PMSessionValidatePageFormat (theMacPrintSession, theMacPageFormat, & result); PMSessionValidatePrintSettings (theMacPrintSession, theMacPrintSettings, & result); /* * BUG. * If we now ask for the available printer resolutions, * we may get the answer that there's only 300 dpi (perhaps PostScript drivers say so?). * So we don't rely on that and have a buggy assumption instead. */ PMSetResolution (theMacPageFormat, & res300); // perhaps all printers have this... PMSetResolution (theMacPageFormat, & res600); // ... but this is preferred }
// -------------------------------------------------------------------------------------------------------------- static OSStatus MySetupPageFormatForPrinting(PMPrintSession printSession, void *docDataP, PMPageFormat *pageFormatP) { OSStatus status = noErr; PMPageFormat pageFormat = GetPageFormatFromPrivateData(docDataP); if (!pageFormat) { status = PMCreatePageFormat(&pageFormat); if(status == noErr) { status = PMSessionDefaultPageFormat(printSession, pageFormat); if(status == noErr){ PMResolution appDrawingResolution; // for illustrative purposes, this sample will draw at 300,300 dpi resolution appDrawingResolution.hRes = appDrawingResolution.vRes = 300.; status = PMSetResolution(pageFormat, &appDrawingResolution); } if (status == noErr) SetPageFormatOnPrivateData(docDataP, pageFormat); else{ (void)PMRelease(pageFormat); pageFormat = NULL; } } }else{ // we already have a page format so we'll validate it status = PMSessionValidatePageFormat(printSession, pageFormat, kPMDontWantBoolean); if(status){ // if validate failed! SetPageFormatOnPrivateData(docDataP, NULL); (void)PMRelease(pageFormat); pageFormat = NULL; } } DoErrorAlert(status, kMyPrintErrorFormatStrKey); *pageFormatP = pageFormat; return status; }
bool QPrinter::prepare(PMPageFormat *f) { if (!psession && PMCreateSession(&psession) != noErr) return FALSE; if (*f == kPMNoPageFormat) { if (PMCreatePageFormat(f) != noErr) return FALSE; if (PMSessionDefaultPageFormat(psession, *f) != noErr) return FALSE; } else { if (PMSessionValidatePageFormat(psession, *f, kPMDontWantBoolean) != noErr) return FALSE; } if (page_size != carbonSize2QPrinterSize(*f)) qprinterSize2CarbonSize(page_size, *f, psession); PMSetOrientation(*f, orientation() == Portrait ? kPMPortrait : kPMLandscape, TRUE); PMResolution pres; pres.hRes = res; pres.vRes = res; PMSetResolution(*f, &pres); return TRUE; }
OSStatus MakePDFDocument(WindowRef parentWindow, void *documentDataP, CFURLRef saveURL) { #pragma unused (parentWindow) OSStatus err = noErr, tempErr; PMPrintSettings printSettings = NULL; PMPrintSession printSession; err = PMCreateSession(&printSession); if(err == noErr){ // validate the page format we're going to use err = PMSessionValidatePageFormat(printSession, GetPageFormatFromPrivateData(documentDataP), kPMDontWantBoolean); if (err == noErr) { err = PMCreatePrintSettings(&printSettings); if(err == noErr) { err = PMSessionDefaultPrintSettings(printSession, printSettings); if(err == noErr){ CFStringRef myDocumentNameRef; err = CopyDocumentName(documentDataP, &myDocumentNameRef); if(err == noErr) { // set the job name err = PMSetJobNameCFString (printSettings, myDocumentNameRef); CFRelease(myDocumentNameRef); // release our reference to the document name } } if (err == noErr) err = PMSetPageRange(printSettings, 1, MyGetDocumentNumPagesInDoc(documentDataP)); // set our destination to be our target URL and the format to be PDF if(err == noErr){ // this API exists ONLY in MacOS X 10.1 and later only if(!err) err = Call_PMSessionSetDestination(printSession, printSettings, kPMDestinationFile, kPMDocumentFormatPDF, saveURL); } #if !NO_SAVE_STATUS_DIALOG /* It looks a bit odd to call PMSessionUseSheets when we aren't even using the print dialog BUT the reason we are doing so is so that the printing status narration will use sheets and not a modal dialog. NOTE: this is only called when this code is built with !NO_SAVE_STATUS_DIALOG is true, i.e. we want status narration of the save to PDF process. */ if(err == noErr){ err = PMSessionUseSheets(printSession, parentWindow, NULL); } #endif } if (err == noErr) { err = MyDoPrintLoop(printSession, GetPageFormatFromPrivateData(documentDataP), printSettings, documentDataP, #if NO_SAVE_STATUS_DIALOG &gMyPrintingProcsNoStatusDialog #else &gMyPrintingProcsWithStatusDialog #endif ); } } if(printSettings){ tempErr = PMRelease(printSettings); if(err == noErr) err = tempErr; } tempErr = PMRelease(printSession); if(err == noErr) err = tempErr; } DoErrorAlert(err, kMySaveAsPDFErrorFormatStrKey); return err; }
void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) { Q_D(QMacPrintEngine); d->valueCache.insert(key, value); if (!d->session) return; switch (key) { case PPK_CollateCopies: break; case PPK_ColorMode: break; case PPK_Creator: break; case PPK_DocumentName: break; case PPK_PageOrder: break; case PPK_PaperSource: break; case PPK_SelectionOption: break; case PPK_Resolution: { PMPrinter printer; UInt32 count; if (PMSessionGetCurrentPrinter(d->session, &printer) != noErr) break; if (PMPrinterGetPrinterResolutionCount(printer, &count) != noErr) break; PMResolution resolution = { 0.0, 0.0 }; PMResolution bestResolution = { 0.0, 0.0 }; int dpi = value.toInt(); int bestDistance = INT_MAX; for (UInt32 i = 1; i <= count; ++i) { // Yes, it starts at 1 if (PMPrinterGetIndexedPrinterResolution(printer, i, &resolution) == noErr) { if (dpi == int(resolution.hRes)) { bestResolution = resolution; break; } else { int distance = qAbs(dpi - int(resolution.hRes)); if (distance < bestDistance) { bestDistance = distance; bestResolution = resolution; } } } } PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean); break; } case PPK_FullPage: d->fullPage = value.toBool(); break; case PPK_NumberOfCopies: PMSetCopies(d->settings, value.toInt(), false); break; case PPK_Orientation: { if (d->state == QPrinter::Active) { qWarning("QMacPrintEngine::setOrientation: Orientation cannot be changed during a print job, ignoring change"); } else { QPrinter::Orientation newOrientation = QPrinter::Orientation(value.toInt()); if (d->hasCustomPaperSize && (d->orient != newOrientation)) d->customSize = QSizeF(d->customSize.height(), d->customSize.width()); d->orient = newOrientation; PMOrientation o = d->orient == QPrinter::Portrait ? kPMPortrait : kPMLandscape; PMSetOrientation(d->format, o, false); PMSessionValidatePageFormat(d->session, d->format, kPMDontWantBoolean); } break; } case PPK_OutputFileName: d->outputFilename = value.toString(); break; case PPK_PaperSize: d->setPaperSize(QPrinter::PaperSize(value.toInt())); break; case PPK_PrinterName: { OSStatus status = noErr; QCFType<CFArrayRef> printerList; status = PMServerCreatePrinterList(kPMServerLocal, &printerList); if (status == noErr) { CFIndex count = CFArrayGetCount(printerList); for (CFIndex i=0; i<count; ++i) { PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i))); QString name = QCFString::toQString(PMPrinterGetName(printer)); if (name == value.toString()) { status = PMSessionSetCurrentPMPrinter(d->session, printer); break; } } } if (status != noErr) qWarning("QMacPrintEngine::setPrinterName: Error setting printer: %ld", long(status)); break; } case PPK_SuppressSystemPrintStatus: d->suppressStatus = value.toBool(); break; case PPK_CustomPaperSize: { PMOrientation orientation; PMGetOrientation(d->format, &orientation); d->hasCustomPaperSize = true; d->customSize = value.toSizeF(); if (orientation != kPMPortrait) d->customSize = QSizeF(d->customSize.height(), d->customSize.width()); break; } case PPK_PageMargins: { QList<QVariant> margins(value.toList()); Q_ASSERT(margins.size() == 4); d->leftMargin = margins.at(0).toDouble(); d->topMargin = margins.at(1).toDouble(); d->rightMargin = margins.at(2).toDouble(); d->bottomMargin = margins.at(3).toDouble(); d->hasCustomPageMargins = true; break; } default: break; } }
bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) { PMPrinter printer; PMSessionGetCurrentPrinter(m_macPrintSession, &printer); wxSize papersize = wxDefaultSize; const wxPaperSize paperId = data.GetPaperId(); if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase ) { papersize = wxThePrintPaperDatabase->GetSize(paperId); if ( papersize != wxDefaultSize ) { papersize.x /= 10; papersize.y /= 10; } } else { papersize = data.GetPaperSize(); } if ( papersize != wxDefaultSize ) { papersize.x = (wxInt32) (papersize.x * mm2pt); papersize.y = (wxInt32) (papersize.y * mm2pt); double height, width; PMPaperGetHeight(m_macPaper, &height); PMPaperGetWidth(m_macPaper, &width); if ( fabs( width - papersize.x ) >= 5 || fabs( height - papersize.y ) >= 5 ) { // we have to change the current paper CFArrayRef paperlist = 0 ; if ( PMPrinterGetPaperList( printer, &paperlist ) == noErr ) { PMPaper bestPaper = kPMNoData ; CFIndex top = CFArrayGetCount(paperlist); for ( CFIndex i = 0 ; i < top ; ++ i ) { PMPaper paper = (PMPaper) CFArrayGetValueAtIndex( paperlist, i ); PMPaperGetHeight(paper, &height); PMPaperGetWidth(paper, &width); if ( fabs( width - papersize.x ) < 5 && fabs( height - papersize.y ) < 5 ) { // TODO test for duplicate hits and use additional // criteria for best match bestPaper = paper; } } PMPaper paper = kPMNoData; if ( bestPaper == kPMNoData ) { const PMPaperMargins margins = { 0.0, 0.0, 0.0, 0.0 }; wxString id, name(_T("Custom paper")); id.Printf(_T("wxPaperCustom%dx%d"), papersize.x, papersize.y); #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 if ( PMPaperCreateCustom != NULL) { PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ), papersize.x, papersize.y, &margins, &paper); } #endif #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 if ( paper == kPMNoData ) { PMPaperCreate(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ), papersize.x, papersize.y, &margins, &paper); } #endif } if ( bestPaper != kPMNoData ) { PMPageFormat pageFormat; PMCreatePageFormatWithPMPaper(&pageFormat, bestPaper); PMCopyPageFormat( pageFormat, m_macPageFormat ); PMRelease(pageFormat); PMGetPageFormatPaper(m_macPageFormat, &m_macPaper); } PMRelease(paper); } } } CFArrayRef printerList; CFIndex index, count; CFStringRef name; if (PMServerCreatePrinterList(kPMServerLocal, &printerList) == noErr) { count = CFArrayGetCount(printerList); for (index = 0; index < count; index++) { printer = (PMPrinter)CFArrayGetValueAtIndex(printerList, index); if ((data.GetPrinterName().empty()) && (PMPrinterIsDefault(printer))) break; else { name = PMPrinterGetName(printer); CFRetain(name); if (data.GetPrinterName() == wxCFStringRef(name).AsString()) break; } } if (index < count) PMSessionSetCurrentPMPrinter(m_macPrintSession, printer); CFRelease(printerList); } PMSetCopies( m_macPrintSettings , data.GetNoCopies() , false ) ; PMSetCollate(m_macPrintSettings, data.GetCollate()); if ( data.IsOrientationReversed() ) PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? kPMReverseLandscape : kPMReversePortrait , false ) ; else PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? kPMLandscape : kPMPortrait , false ) ; PMDuplexMode mode = 0 ; switch( data.GetDuplex() ) { case wxDUPLEX_HORIZONTAL : mode = kPMDuplexNoTumble ; break ; case wxDUPLEX_VERTICAL : mode = kPMDuplexTumble ; break ; case wxDUPLEX_SIMPLEX : default : mode = kPMDuplexNone ; break ; } PMSetDuplex( m_macPrintSettings, mode ) ; // PMQualityMode not yet accessible via API if ( data.IsOrientationReversed() ) PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? kPMReverseLandscape : kPMReversePortrait , false ) ; else PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? kPMLandscape : kPMPortrait , false ) ; #ifndef __LP64__ // PMQualityMode not accessible via API // TODO: use our quality property to determine optimal resolution PMResolution res; PMTag tag = kPMMaxSquareResolution; PMPrinterGetPrinterResolution(printer, tag, &res); PMSetResolution( m_macPageFormat, &res); #endif // after setting the new resolution the format has to be updated, otherwise the page rect remains // at the 'old' scaling PMSessionValidatePageFormat(m_macPrintSession, m_macPageFormat, kPMDontWantBoolean); PMSessionValidatePrintSettings(m_macPrintSession, m_macPrintSettings, kPMDontWantBoolean); #if wxOSX_USE_COCOA UpdateFromPMState(); #endif return true ; }
static void shellcopyprintinfo (void) { /* set up our printing rect according to the print manager's rects. we'll use the smaller of the printable area (rPage) and the physical paper (rPaper) with 1/2 inch margins 5.0.1 dmb: measure in pixels (1/72 inch) for Win */ Rect rpage, rpaper; //typrintinfo *dbgprintinfo = &shellprintinfo; #ifdef MACVERSION # if TARGET_API_MAC_CARBON == 1 static int firstTime = 1; OSErr theErr; boolean fl; PMRect dRect; if (1 == firstTime) { carbonSessionPrintSession(); carbonCreateFormatAndSetting(); carbonSessionDefaultPageAndSettingValidate(); } theErr = PMSessionValidatePageFormat( shellprintinfo.printhandle, shellprintinfo.pageformat, &fl); if(theErr != noErr) // || !fl) // why should i kill this if nothing has changed??? oserror(theErr); theErr = PMGetAdjustedPageRect(shellprintinfo.pageformat, &dRect); shellprintinfo.pagerect = dRect; theErr = PMGetAdjustedPaperRect(shellprintinfo.pageformat, &dRect); rect2rect(dRect, shellprintinfo.paperrect); rect2rect(shellprintinfo.pagerect, rpage); rpaper = shellprintinfo.paperrect; # else rpage = (**shellprintinfo.printhandle).prInfo.rPage; rpaper = (**shellprintinfo.printhandle).rPaper; # endif #endif #ifdef WIN95VERSION long res = 72L; pushport (hwndMDIClient); res = GetDeviceCaps(getcurrentDC (), LOGPIXELSX); popport (); rpaper.left = 0; rpaper.top = 0; rpaper.right = shellprintinfo.pagesetupinfo.ptPaperSize.x * res / 1000L; rpaper.bottom = shellprintinfo.pagesetupinfo.ptPaperSize.y * res / 1000L; rpage.left = rpaper.left + (shellprintinfo.pagesetupinfo.rtMinMargin.left * res / 1000L); rpage.top = rpaper.top + (shellprintinfo.pagesetupinfo.rtMinMargin.top * res / 1000L); rpage.right = rpaper.right - (shellprintinfo.pagesetupinfo.rtMinMargin.right * res / 1000L); rpage.bottom = rpaper.bottom - (shellprintinfo.pagesetupinfo.rtMinMargin.bottom * res / 1000L); shellprintinfo.margins.left = shellprintinfo.pagesetupinfo.rtMargin.left * res / 1000L; shellprintinfo.margins.top = shellprintinfo.pagesetupinfo.rtMargin.top * res / 1000L; shellprintinfo.margins.right = shellprintinfo.pagesetupinfo.rtMargin.right * res / 1000L; shellprintinfo.margins.bottom = shellprintinfo.pagesetupinfo.rtMargin.bottom * res / 1000L; #endif shellprintinfo.paperrect.top = max (rpage.top, rpaper.top + shellprintinfo.margins.top); shellprintinfo.paperrect.left = max (rpage.left, rpaper.left + shellprintinfo.margins.left); shellprintinfo.paperrect.bottom = min (rpage.bottom, rpaper.bottom - shellprintinfo.margins.bottom); shellprintinfo.paperrect.right = min (rpage.right, rpaper.right - shellprintinfo.margins.right); } /*shellcopyprintinfo*/
bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data ) { ValidateOrCreate() ; PMSetCopies( (PMPrintSettings) m_macPrintSettings , data.GetNoCopies() , false ) ; if ( data.IsOrientationReversed() ) PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? kPMReverseLandscape : kPMReversePortrait , false ) ; else PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? kPMLandscape : kPMPortrait , false ) ; // collate cannot be set #if 0 // not yet tested if ( !m_printerName.empty() ) PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ; #endif #ifndef __LP64__ PMColorMode color ; PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ; if ( data.GetColour() ) { if ( color == kPMBlackAndWhite ) PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ; } else PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ; #endif #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 if ( &PMSetDuplex!=NULL ) { PMDuplexMode mode = 0 ; switch( data.GetDuplex() ) { case wxDUPLEX_HORIZONTAL : mode = kPMDuplexNoTumble ; break ; case wxDUPLEX_VERTICAL : mode = kPMDuplexTumble ; break ; case wxDUPLEX_SIMPLEX : default : mode = kPMDuplexNone ; break ; } PMSetDuplex( (PMPrintSettings) m_macPrintSettings, mode ) ; } #endif // PMQualityMode not yet accessible via API // todo paperSize PMResolution res; PMPrinter printer; PMSessionGetCurrentPrinter(m_macPrintSession, &printer); #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 PMPrinterGetOutputResolution( printer, (PMPrintSettings) m_macPrintSettings, &res) ; // TODO transfer ? into page format ? #else PMTag tag = kPMMaxSquareResolution; PMPrinterGetPrinterResolution(printer, tag, &res); PMSetResolution((PMPageFormat) m_macPageFormat, &res); #endif // after setting the new resolution the format has to be updated, otherwise the page rect remains // at the 'old' scaling PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession, (PMPageFormat) m_macPageFormat, kPMDontWantBoolean) ; return true ; }
void QMacPrintEnginePrivate::initialize() { Q_ASSERT(!session); Q_Q(QMacPrintEngine); if (!paintEngine) paintEngine = new QCoreGraphicsPaintEngine(); q->gccaps = paintEngine->gccaps; fullPage = false; if (PMCreateSession(&session) != noErr) session = 0; PMPrinter printer; if (session && PMSessionGetCurrentPrinter(session, &printer) == noErr) { QList<QVariant> resolutions = supportedResolutions(); if (!resolutions.isEmpty() && mode != QPrinter::ScreenResolution) { if (resolutions.count() > 1 && mode == QPrinter::HighResolution) { int max = 0; for (int i = 0; i < resolutions.count(); ++i) { int value = resolutions.at(i).toInt(); if (value > max) max = value; } resolution.hRes = resolution.vRes = max; } else { resolution.hRes = resolution.vRes = resolutions.at(0).toInt(); } if(resolution.hRes == 0) resolution.hRes = resolution.vRes = 600; } else { resolution.hRes = resolution.vRes = qt_defaultDpi(); } } bool settingsInitialized = (settings != 0); bool settingsOK = !settingsInitialized ? PMCreatePrintSettings(&settings) == noErr : true; if (settingsOK && !settingsInitialized) settingsOK = PMSessionDefaultPrintSettings(session, settings) == noErr; bool formatInitialized = (format != 0); bool formatOK = !formatInitialized ? PMCreatePageFormat(&format) == noErr : true; if (formatOK) { if (!formatInitialized) { formatOK = PMSessionDefaultPageFormat(session, format) == noErr; } formatOK = PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) == noErr; } #ifndef Q_OS_MAC64 # if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_4) # endif { if(paintEngine->type() == QPaintEngine::CoreGraphics) { CFStringRef strings[1] = { kPMGraphicsContextCoreGraphics }; QCFType<CFArrayRef> contextArray = CFArrayCreate(kCFAllocatorDefault, reinterpret_cast<const void **>(strings), 1, &kCFTypeArrayCallBacks); OSStatus err = PMSessionSetDocumentFormatGeneration(session, kPMDocumentFormatPDF, contextArray, 0); if(err != noErr) { qWarning("QMacPrintEngine::initialize: Cannot set format generation to PDF: %ld", err); state = QPrinter::Error; } } } #endif if (!settingsOK || !formatOK) { qWarning("QMacPrintEngine::initialize: Unable to initialize QPainter"); state = QPrinter::Error; } QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant>::const_iterator propC; for (propC = valueCache.constBegin(); propC != valueCache.constEnd(); propC++) { q->setProperty(propC.key(), propC.value()); } }
int Printer_print (void (*draw) (void *boss, Graphics g), void *boss) { #if defined (UNIX) structMelderFile tempFile = { 0 }; char tempPath_utf8 [] = "/tmp/picXXXXXX"; close (mkstemp (tempPath_utf8)); Melder_pathToFile (Melder_peekUtf8ToWcs (tempPath_utf8), & tempFile); thePrinter. graphics = Graphics_create_postscriptjob (& tempFile, thePrinter. resolution, thePrinter. spots, thePrinter. paperSize, thePrinter. orientation, thePrinter. magnification); if (! thePrinter. graphics) return Melder_error1 (L"Cannot create temporary PostScript file for printing."); draw (boss, thePrinter. graphics); forget (thePrinter. graphics); char command [500]; sprintf (command, Melder_peekWcsToUtf8 (Site_getPrintCommand ()), tempPath_utf8); system (command); MelderFile_delete (& tempFile); #elif defined (_WIN32) int postScriptCode = POSTSCRIPT_PASSTHROUGH; DOCINFO docInfo; DEVMODE *devMode; initPrinter (); if (! theWinPrint. hDevMode) { memset (& theWinPrint, 0, sizeof (PRINTDLG)); theWinPrint. lStructSize = sizeof (PRINTDLG); theWinPrint. Flags = PD_RETURNDEFAULT; if (! PrintDlg (& theWinPrint)) return Melder_error1 (L"Cannot initialize printer."); } if (Melder_backgrounding) { theWinPrint. Flags = PD_RETURNDEFAULT | PD_RETURNDC; if (! PrintDlg (& theWinPrint) || theWinPrint. hDC == NULL) { return Melder_error1 (L"Cannot print from a script on this computer."); } } else { theWinPrint. Flags &= ~ PD_RETURNDEFAULT; theWinPrint. Flags |= PD_RETURNDC; if (! PrintDlg (& theWinPrint)) return 1; } theWinDC = theWinPrint. hDC; thePrinter. postScript = thePrinter. allowDirectPostScript && Escape (theWinDC, QUERYESCSUPPORT, sizeof (int), (LPSTR) & postScriptCode, NULL); /* * The HP colour inkjet printer returns in dmFields: * 0, 1, 8, 9, 10, 11, 12, 13, 14, 15, 23, 24, 25, 26 = DM_ORIENTATION | * DM_PAPERSIZE | DM_COPIES | DM_DEFAULTSOURCE | DM_PRINTQUALITY | * DM_COLOR | DM_DUPLEX | DM_YRESOLUTION | DM_TTOPTION | DM_COLLATE | * DM_ICMMETHOD | DM_ICMINTENT | DM_MEDIATYPE | DM_DITHERTYPE */ devMode = * (DEVMODE **) theWinPrint. hDevMode; thePrinter. resolution = devMode -> dmFields & DM_YRESOLUTION ? devMode -> dmYResolution : devMode -> dmFields & DM_PRINTQUALITY ? ( devMode -> dmPrintQuality > 0 ? devMode -> dmPrintQuality : 300 ) : 300; if (devMode -> dmFields & DM_PAPERWIDTH) { thePrinter. paperWidth = devMode -> dmPaperWidth * thePrinter. resolution / 254; thePrinter. paperHeight = devMode -> dmPaperLength * thePrinter. resolution / 254; } else if (devMode -> dmFields & DM_PAPERSIZE) { static struct { float width, height; } sizes [] = { { 0, 0 }, { 8.5, 11 }, { 8.5, 11 }, { 11, 17 }, { 17, 11 }, { 8.5, 14 }, { 5.5, 8.5 }, { 7.25, 10.5 }, { 297/25.4, 420/25.4 }, { 210/25.4, 297/25.4 }, { 210/25.4, 297/25.4 }, { 148.5/25.4, 210/25.4 }, { 250/25.4, 354/25.4 }, { 182/25.4, 257/25.4 }, { 8.5, 13 }, { 215/25.4, 275/25.4 }, { 10, 14 }, { 11, 17 }, { 8.5, 11 }, { 3.875, 8.875 }, { 4.125, 9.5 }, { 4.5, 10.375 } }; int paperSize = devMode -> dmPaperSize; if (paperSize <= 0 || paperSize > 21) paperSize = 1; thePrinter. paperWidth = sizes [paperSize]. width * thePrinter. resolution; thePrinter. paperHeight = sizes [paperSize]. height * thePrinter. resolution; if (devMode -> dmOrientation == DMORIENT_LANDSCAPE) { long dummy = thePrinter. paperWidth; thePrinter. paperWidth = thePrinter. paperHeight; thePrinter. paperHeight = dummy; } } else { thePrinter. paperWidth = 1000; thePrinter. paperHeight = 1000; } EnableWindow ((HWND) XtWindow (theCurrentPraatApplication -> topShell), FALSE); SetAbortProc (theWinDC, AbortFunc); memset (& docInfo, 0, sizeof (DOCINFO)); docInfo. cbSize = sizeof (DOCINFO); docInfo. lpszDocName = L"Praatjes"; docInfo. lpszOutput = NULL; if (thePrinter. postScript) { StartDoc (theWinDC, & docInfo); StartPage (theWinDC); initPostScriptPage (); thePrinter. graphics = Graphics_create_postscriptprinter (); if (! thePrinter. graphics) return Melder_error1 (L"Cannot open printer."); draw (boss, thePrinter. graphics); forget (thePrinter. graphics); exitPostScriptPage (); EndPage (theWinDC); EndDoc (theWinDC); } else { StartDoc (theWinDC, & docInfo); StartPage (theWinDC); thePrinter. graphics = Graphics_create_screenPrinter (NULL, (unsigned long) theWinDC); if (! thePrinter. graphics) return Melder_error1 (L"Cannot open printer."); draw (boss, thePrinter. graphics); forget (thePrinter. graphics); if (EndPage (theWinDC) < 0) { Melder_error1 (L"Cannot print page."); } else { EndDoc (theWinDC); } } EnableWindow ((HWND) XtWindow (theCurrentPraatApplication -> topShell), TRUE); DeleteDC (theWinDC), theWinDC = NULL; #elif defined (macintosh) Boolean result; initPrinter (); if (Melder_backgrounding) { PMSessionValidatePageFormat (theMacPrintSession, theMacPageFormat, & result); PMSessionValidatePrintSettings (theMacPrintSession, theMacPrintSettings, & result); } else { Boolean accepted; PMSessionPrintDialog (theMacPrintSession, theMacPrintSettings, theMacPageFormat, & accepted); if (! accepted) return 1; /* Normal cancelled return. */ } PMSessionValidatePageFormat (theMacPrintSession, theMacPageFormat, & result); PMSessionValidatePrintSettings (theMacPrintSession, theMacPrintSettings, & result); PMResolution res; PMGetResolution (theMacPageFormat, & res); thePrinter. resolution = res. hRes; PMGetAdjustedPaperRect (theMacPageFormat, & paperSize); thePrinter. paperWidth = paperSize. right - paperSize. left; thePrinter. paperHeight = paperSize. bottom - paperSize. top; Boolean isPostScriptDriver = FALSE; //PMSessionIsDocumentFormatSupported (theMacPrintSession, // kPMDocumentFormatPICTPS, & isPostScriptDriver); CFArrayRef supportedFormats; PMSessionGetDocumentFormatGeneration (theMacPrintSession, & supportedFormats); CFIndex numberOfSupportedFormats = CFArrayGetCount (supportedFormats); if (Melder_debug == 21) { MelderInfo_open (); MelderInfo_writeLine1 (L"Supported document formats:"); } for (CFIndex i = 0; i < numberOfSupportedFormats; i ++) { CFStringRef supportedFormat = CFArrayGetValueAtIndex (supportedFormats, i); if (CFStringCompare (supportedFormat, kPMDocumentFormatPICTPS, 0) == 0) { isPostScriptDriver = TRUE; } if (Melder_debug == 21) { MelderInfo_writeLine3 (Melder_integer (i), L": ", Melder_peekUtf8ToWcs (CFStringGetCStringPtr (supportedFormat, kCFStringEncodingUTF8))); } } if (Melder_debug == 21) { MelderInfo_close (); } CFRelease (supportedFormats); isPostScriptDriver = FALSE; // OVERRIDE, because from 10.4 on we have something better: we'll be sending PDF thePrinter. postScript = thePrinter. allowDirectPostScript && isPostScriptDriver; if (thePrinter. postScript) { CFStringRef strings [1]; strings [0] = kPMGraphicsContextQuickdraw; CFArrayRef array = CFArrayCreate (kCFAllocatorDefault, (const void **) strings, 1, & kCFTypeArrayCallBacks); OSStatus err = PMSessionSetDocumentFormatGeneration (theMacPrintSession, kPMDocumentFormatPICTPS, array, NULL); CFRelease (array); if (err != 0) { return Melder_error2 (L"PMSessionSetDocumentFormatGeneration: error ", Melder_integer (err)); } } PMOrientation orientation; PMGetOrientation (theMacPageFormat, & orientation); thePrinter. orientation = orientation == kPMLandscape || orientation == kPMReverseLandscape ? kGraphicsPostscript_orientation_LANDSCAPE : kGraphicsPostscript_orientation_PORTRAIT; PMSessionBeginDocument (theMacPrintSession, theMacPrintSettings, theMacPageFormat); PMSessionBeginPage (theMacPrintSession, theMacPageFormat, NULL); PMSessionGetGraphicsContext (theMacPrintSession, kPMGraphicsContextQuickdraw, (void **) & theMacPort); /* * On PostScript, the point (0, 0) is the bottom left corner of the paper, which is fine. * On the screen, however, the point (0, 0) is the top left corner of the writable page. * Since we want paper-related margins, not writable-page-related margins, * we require that this point gets the coordinates (250, 258) or so, * so that the top left corner of the paper gets coordinates (0, 0). * The "left" and "top" attributes of rPaper are negative values (e.g. -250 and -258), * so multiply them by -1. * * Under Carbon, the port has to be set inside the page. */ SetPort (theMacPort); if (! thePrinter. postScript) SetOrigin (- paperSize. left, - paperSize. top); if (thePrinter. postScript) { if (! openPostScript ()) error1 (L"Cannot print PostScript.") thePrinter. graphics = Graphics_create_postscriptprinter (); if (! thePrinter. graphics) goto end; draw (boss, thePrinter. graphics); forget (thePrinter. graphics); closePostScript (); } else { thePrinter. graphics = Graphics_create_screenPrinter (NULL, (unsigned long) theMacPort); draw (boss, thePrinter. graphics); forget (thePrinter. graphics); } end: if (theMacPort) { PMSessionEndPage (theMacPrintSession); PMSessionEndDocument (theMacPrintSession); theMacPort = NULL; } #endif iferror return 0; return 1; }
// ------------------------------------------------------------------------------- OSStatus DoPrint(WindowRef parentWindow, void *documentDataP, Boolean printOne) { OSStatus err = noErr; PMPrintSettings printSettings = NULL; UInt32 minPage = 1, maxPage; PMPrintSession printSession; err = PMCreateSession(&printSession); if(err == noErr){ // validate the page format we're going to use err = PMSessionValidatePageFormat(printSession, GetPageFormatFromPrivateData(documentDataP), kPMDontWantBoolean); if (err == noErr) { err = PMCreatePrintSettings(&printSettings); if(err == noErr) { err = PMSessionDefaultPrintSettings(printSession, printSettings); if(err == noErr){ CFStringRef myDocumentNameRef; err = CopyDocumentName(documentDataP, &myDocumentNameRef); if(err == noErr) { // set the job name before displaying the print dialog err = PMSetJobNameCFString (printSettings, myDocumentNameRef); CFRelease(myDocumentNameRef); // release our reference to the document name } } } if (err == noErr) { /* On Mac OS X, calling PMSetPageRange has the following benefits: (a) sets the From/To settings in the print dialog to the range of pages in the document AND (b) the print dialog code enforces this so that users can't enter values outside this range. */ maxPage = MyGetDocumentNumPagesInDoc(documentDataP); err = PMSetPageRange(printSettings, minPage, maxPage); } if (err == noErr) { Boolean accepted; static PMSheetDoneUPP myPrintDialogDoneProc = NULL; if(!myPrintDialogDoneProc){ myPrintDialogDoneProc = NewPMSheetDoneUPP(MyPrintDialogDoneProc); if(!myPrintDialogDoneProc) err = memFullErr; } if(!err){ Boolean sheetsAreAvailable = true; err = SetPrintSettingsOnPrivateData(documentDataP, printSettings); if(!err){ err = PMSessionUseSheets(printSession, parentWindow, myPrintDialogDoneProc); if(err == kPMNotImplemented){ // we get here if sheets are not available, i.e. Mac OS 8/9 err = noErr; sheetsAreAvailable = false; } if(err == noErr && !printOne){ err = PMSessionPrintDialog(printSession, printSettings, GetPageFormatFromPrivateData(documentDataP), &accepted); /* when using sheets, the value of 'accepted' returned here is irrelevant since it is our sheet done proc that is called when the dialog is dismissed. Our dialog done proc will be called when the sheet is dismissed. If sheets are NOT implemented then WE call our DialogDone proc here to complete the dialog. */ if(err == noErr && !sheetsAreAvailable) MyPrintDialogDoneProc(printSession, parentWindow, accepted); }else{ // if we are doing print one we have no dialog, therefore // we have to call our dialog done proc since there is no // dialog to do so for us if(err == noErr) MyPrintDialogDoneProc(printSession, parentWindow, true); } } } } } // need to release the print settings this function created. if(printSettings){ OSStatus tempErr = PMRelease(printSettings); if(err == noErr) err = tempErr; printSettings = NULL; } if(err != noErr){ /* normally the printSettings set in the Private Data and printSession would be released by our dialog done proc but if we got an error and therefore got to this point in our code, the dialog done proc was NOT called and therefore we need to release the printSession here */ if(printSettings){ // this releases any print settings already stored on our private data (void)SetPrintSettingsOnPrivateData(documentDataP, NULL); } (void)PMRelease(printSession); // ignoring error since we already have one } } DoErrorAlert(err, kMyPrintErrorFormatStrKey); return err; }
/*------------------------------------------------------------------------------ Function: DoPageSetupDialog Parameters: Description: If the caller passes in an empty PageFormat object, DoPageSetupDialog creates a new one, otherwise it validates the one provided by the caller. It then invokes the Page Setup dialog and checks for Cancel. Finally it flattens the PageFormat object so it can be saved with the document. Note that the PageFormat object is modified by this function. ------------------------------------------------------------------------------*/ OSStatus DoPageSetupDialog(PrintingLogicPtr printJob) { OSStatus status = noErr; Boolean accepted; // Set up a valid PageFormat object. if (printJob->pageFormat == kPMNoPageFormat) { status = PMCreatePageFormat(&printJob->pageFormat); // Note that PMPageFormat is not session-specific, but calling // PMSessionDefaultPageFormat assigns values specific to the printer // associated with the current printing session. if ((status == noErr) && (printJob->pageFormat != kPMNoPageFormat)) status = PMSessionDefaultPageFormat(printJob->printSession, printJob->pageFormat); } else status = PMSessionValidatePageFormat(printJob->printSession, printJob->pageFormat, kPMDontWantBoolean); /* This is broken fn = interpreterProxy->ioLoadFunctionFrom("getSTWindow", ""); if (fn != 0) { WindowPtr windowRef; windowRef = (WindowPtr) ((int (*) ()) fn)(); PMSessionUseSheets(printJob->printSession,windowRef,NULL); } */ // Display the Page Setup dialog. if (status == noErr) { void * giLocker; giLocker = interpreterProxy->ioLoadFunctionFrom("getUIToLock", ""); if (giLocker != 0) { long *foo; foo = malloc(sizeof(long)*6); foo[0] = 3; foo[1] = (long) PMSessionPageSetupDialog; foo[2] = (long)printJob->printSession; foo[3] = (long)printJob->pageFormat; foo[4] = (long)&accepted; foo[5] = 0; ((int (*) (void *)) giLocker)(foo); status = foo[5]; free(foo); } else status = PMSessionPageSetupDialog(printJob->printSession, printJob->pageFormat, &accepted); if (status == noErr && !accepted) status = kPMCancel; // user clicked Cancel button } // If the user did not cancel, flatten and save the PageFormat object // with our document. if (status == noErr) status = FlattenAndSavePageFormat(printJob); return status; } // DoPageSetupDialog