// --------------------------------------------------------------------------- // // ------------ 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); }
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 }
//----------------------------------------------------------------------------------------------------------------------- static OSStatus MyCreatePageFormat(PMPrintSession printSession, PMPageFormat *pageFormat) { OSStatus 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); return status; }
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); } }
wxOSXCarbonPrintData::wxOSXCarbonPrintData() { if ( PMCreateSession( &m_macPrintSession ) == noErr ) { if ( PMCreatePageFormat(&m_macPageFormat) == noErr ) { PMSessionDefaultPageFormat(m_macPrintSession, m_macPageFormat); PMGetPageFormatPaper(m_macPageFormat, &m_macPaper); } if ( PMCreatePrintSettings(&m_macPrintSettings) == noErr ) { PMSessionDefaultPrintSettings(m_macPrintSession, m_macPrintSettings); } } }
/*------------------------------------------------------------------------------ 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; }
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; }
static boolean carbonCreateFormatAndSetting(void) { #if TARGET_API_MAC_CARBON == 1 OSStatus theErr; theErr = PMCreatePageFormat(&shellprintinfo.pageformat); if(theErr != noErr || (shellprintinfo.pageformat == kPMNoPageFormat)) goto error; theErr = PMCreatePrintSettings(&shellprintinfo.printsettings); if(theErr != noErr) goto error; return (true); error: carbonKillPrintVars(); #endif return false; }
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 CreateDefaultPageFormatForDocument(void *docDataP) { OSStatus err = noErr, tempErr; PMPrintSession printSession; err = PMCreateSession(&printSession); if(!err){ PMPageFormat pageFormat; err = PMCreatePageFormat(&pageFormat); // we own a reference to this page format if(err == noErr) { err = PMSessionDefaultPageFormat(printSession, pageFormat); if (err == noErr){ // this routine will keep its own reference to the pageFormat err = SetPageFormatOnPrivateData(docDataP, pageFormat); } tempErr = PMRelease(pageFormat);// release our reference obtained from PMCreatePageFormat if(!err)err = tempErr; } tempErr = PMRelease(printSession); if(!err)err = tempErr; } return err; }
QPrinter::QPrinter(PrinterMode m) : QPaintDevice(QInternal::Printer | QInternal::ExternalDevice) { d = new QPrinterPrivate; if (PMCreateSession(&psession) != noErr) psession = NULL; switch (m) { case Compatible: devFlags |= QInternal::CompatibilityMode; // fall through case PrinterResolution: case HighResolution: { bool found = FALSE; PMPrinter printer = 0; if (psession && PMSessionGetCurrentPrinter(psession, &printer) == noErr) { PMResolution pres; UInt32 count = 0, maxRes = 0; if (PMPrinterGetPrinterResolutionCount(printer, &count) == noErr && count) for (; count > 0; --count) if (PMPrinterGetIndexedPrinterResolution(printer, count, &pres) == noErr) { found = TRUE; maxRes = QMAX((uint)pres.vRes, maxRes); res = maxRes; } } if (!found) res = 600; //just to have something break; } case ScreenResolution: { short vr, hr; ScreenRes(&hr, &vr); res = vr; break; } } if (PMCreatePageFormat(&pformat) == noErr && PMSessionDefaultPageFormat(psession, pformat) == noErr) page_size = carbonSize2QPrinterSize(pformat); else page_size = A4; //other orient = Portrait; page_order = FirstPageFirst; paper_source = OnlyOne; color_mode = GrayScale; ncopies = 1; from_pg = to_pg = min_pg = max_pg = 0; state = PST_IDLE; output_file = FALSE; to_edge = FALSE; //mac specific pformat = kPMNoPageFormat; psettings = kPMNoPrintSettings; prepare(&pformat); prepare(&psettings); interpret(&pformat); interpret(&psettings); d->printerOptions = 0; setPrintRange(AllPages); }
/*------------------------------------------------------------------------------ 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
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()); } }