Пример #1
0
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);
    }
}
Пример #2
0
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);
        }
    }
}
Пример #3
0
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;
	
}
Пример #4
0
	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
	}
Пример #5
0
bool
QPrinter::prepare(PMPrintSettings *s)
{
  if (!psession && PMCreateSession(&psession) != noErr)
    return FALSE;
  if (*s == kPMNoPrintSettings) {
    if (PMCreatePrintSettings(s) != noErr)
      return FALSE;
    if (PMSessionDefaultPrintSettings(psession, *s) != noErr)
      return FALSE;
  } else {
    if (PMSessionValidatePrintSettings(psession, *s, kPMDontWantBoolean) != noErr)
      return FALSE;
  }
  if (minPage() != 0 || maxPage() != 0)
    PMSetPageRange(*s, minPage(), maxPage());
  if (d->printRange != AllPages) {
    PMSetFirstPage(*s, fromPage(), TRUE);
    PMSetLastPage(*s, toPage(), TRUE);
  }
  PMSetColorMode(*s, colorMode() == GrayScale ? kPMGray : kPMColor);
  PMSetCopies(*s, numCopies(), TRUE);
  if (outputToFile()) {
    CFStringRef cfstring = qstring2cfstring(outputFileName());
    CFURLRef outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, cfstring,
                                                     kCFURLPOSIXPathStyle, false);
    PMSessionSetDestination(psession, *s, kPMDestinationFile, kPMDocumentFormatPDF, outFile);
    CFRelease(outFile);
    CFRelease(cfstring);
  }

  QString printName = printerName();
  if (!printName.isEmpty()) {
    CFStringRef pname = qstring2cfstring(printName);
    PMSessionSetCurrentPrinter(psession, pname);
    CFRelease(pname);
  }
  return TRUE;
}
Пример #6
0
/*------------------------------------------------------------------------------
	Function:	DoPrintDialog
		
	Parameters:
			
	Description:
		If the caller passes an empty PrintSettings object, DoPrintDialog creates
		a new one, otherwise it validates the one provided by the caller.
		It then invokes the Print dialog and checks for Cancel.
		Note that the PrintSettings object is modified by this function.
		
------------------------------------------------------------------------------*/
OSStatus 	DoPrintDialog(PrintingLogicPtr printJob)
{
	OSStatus	status = noErr;
	Boolean		accepted;
	UInt32		realNumberOfPagesinDoc;
	
	//	In this sample code the caller provides a valid PageFormat reference but in
	//	your application you may want to load and unflatten the PageFormat object
	//	that was saved at PageSetup time.  See LoadAndUnflattenPageFormat below.
	
	//	Set up a valid PrintSettings object.
	if (printJob->printSettings == kPMNoPrintSettings)
            {
            status = PMCreatePrintSettings(&printJob->printSettings);	

            //	Note that PMPrintSettings is not session-specific, but calling
            //	PMSessionDefaultPrintSettings assigns values specific to the printer
            //	associated with the current printing session.
            if ((status == noErr) && (printJob->printSettings != kPMNoPrintSettings))
                status = PMSessionDefaultPrintSettings(printJob->printSession, printJob->printSettings);
            }
	else
            status = PMSessionValidatePrintSettings(printJob->printSession, printJob->printSettings, kPMDontWantBoolean);
	
	//	Before displaying the Print dialog, we calculate the number of pages in the
	//	document.  On Mac OS X this is useful because we can prime the Print dialog
	//	with the actual page range of the document and prevent the user from entering
	//	out-of-range numbers.  This is not possible on Mac OS 8 and 9 because the driver,
	//	not the printing manager, controls the page range fields in the Print dialog.

	//	Calculate the number of pages required to print the entire document.
	if (status == noErr)
            status = DetermineNumberOfPagesInDoc(&realNumberOfPagesinDoc,printJob);

	//	Set a valid page range before displaying the Print dialog
	if (status == noErr)
            status = PMSetPageRange(printJob->printSettings, 1, realNumberOfPagesinDoc);

	//	Display the Print dialog.
	if (status == noErr)
            {
            void * giLocker;
            giLocker = interpreterProxy->ioLoadFunctionFrom("getUIToLock", "");
            if (giLocker != 0) {
                long *foo;
                foo = malloc(sizeof(long)*7);
                foo[0] = 4;
                foo[1] =  (long)PMSessionPrintDialog;
                foo[2] =  (long)printJob->printSession;
                foo[3] =  (long)printJob->printSettings;
                foo[4] =  (long)printJob->pageFormat;
                foo[5] =  (long)&accepted;
                foo[6] = 0;
                ((int (*) (void *)) giLocker)(foo);
                status = foo[6];
                free(foo);
            } else
                status = PMSessionPrintDialog(printJob->printSession, printJob->printSettings,
                        printJob->pageFormat, &accepted);
            if (status == noErr && !accepted)
                status = kPMCancel;		// user clicked Cancel button
            }
		
	return status;
	
}	//	DoPrintDialog
Пример #7
0
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;
}
Пример #8
0
// -------------------------------------------------------------------------------
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;
}
Пример #9
0
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());
    }
}