예제 #1
0
// --------------------------------------------------------------------------------------------------------------
OSStatus DoPageSetup(WindowRef window, void *docDataP)
{
    OSStatus		err = noErr;

    if(docDataP){
        PMPrintSession printSession;
        PMPageFormat pageFormat = NULL;
        err = PMCreateSession(&printSession);
        if(!err){
            Boolean accepted;
            err = MySetupPageFormatForPrinting(printSession, docDataP, &pageFormat);
            if(!err){
                Cursor arrow;
                SetCursor(GetQDGlobalsArrow(&arrow));
                err = PMSessionUseSheets(printSession, window, gMyPageSetupDoneProc);             
                if(!err)
                    err = PMSessionPageSetupDialog(printSession, pageFormat, &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
            }
            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
// ---------------------------------------------------------------------------
//
// ------------
bool bXMapPrintSetup::process(int msg, void* prm){
_bTrace_("bXMapPrintSetup::process",true);
PMPrintSession	ps=NULL;
PMPageFormat	pf=kPMNoPageFormat;
OSStatus		status=PMCreateSession(&ps);
    
    _gapp->printMgr()->get_page_format(&pf,kMapPageFormatName);
    for(;;){
        if(status!=noErr){
            break;
        }
        status=DoPageSetupDialog(ps,&pf);
        if(status!=noErr){
            break;
        }
        break;
    }
    if(pf!=kPMNoPageFormat){
        _gapp->printMgr()->set_page_format(pf,kMapPageFormatName);
        (void)PMRelease(pf);
    }
    if(ps){
        (void)PMRelease(ps);
    }
    return(true);
}
예제 #3
0
//-----------------------------------------------------------------------------------------------------------------------
void ProcessPrintCommand(DocStoragePtr docStP, UInt32 commandID)
{
    OSStatus err = noErr;
    PMPrintSession  printSession = NULL;
    
    if ( PMCreateSession(&printSession) == noErr )
    {
	if (commandID == kHICommandPageSetup)
	{
	    DoPageSetupDialog(printSession, &docStP->pageFormat, &docStP->flattenedPageFormat);
	}
	else if (commandID == kHICommandPrint)
	{
	    if (docStP->pageFormat == NULL)
	    {
		err = MyCreatePageFormat(printSession, &docStP->pageFormat);
	    }

	    if (DoPrintDialog(printSession, docStP->pageFormat, &docStP->printSettings) == noErr)
	    {
		DoPrintLoop(docStP, printSession, docStP->pageFormat, docStP->printSettings);
	    }
	}
	PMRelease(printSession);
    }
    else
    {
	fprintf(stderr, "PMCreateSession FAILED\n");
    }
}   // ProcessPrintCommand
예제 #4
0
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
} 
예제 #5
0
// --------------------------------------------------------------------------------------------------------------
OSStatus DoPrint(WindowRef parentWindow, void *ourDataP)
{
    OSStatus status = noErr;
    PMPrintSettings printSettings = NULL;
    PMPageFormat pageFormat = NULL;

    UInt32 minPage = 1, maxPage;
    PMPrintSession printSession;
    status = PMCreateSession(&printSession);
    if(status == noErr){
	status = MySetupPageFormatForPrinting(printSession, ourDataP, &pageFormat);
        if (status == noErr)
        {
            status = PMCreatePrintSettings(&printSettings);
            if(status == noErr)
            {
                status = PMSessionDefaultPrintSettings(printSession, printSettings);
                if(status == noErr){
                    CFStringRef windowTitleRef;
                    status = CopyWindowTitleAsCFString(parentWindow, &windowTitleRef);
                    if(status == noErr)
                    {
                        // set the job name before displaying the print dialog
                        status = PMSetJobNameCFString (printSettings, windowTitleRef);
                        CFRelease (windowTitleRef);
                    }
                }
            }
            if (status == noErr)
            {
                maxPage = MyGetDocumentNumPagesInDoc(ourDataP);
                status = PMSetPageRange(printSettings, minPage, maxPage);
            }
            if (status == noErr)
            {
                Boolean accepted;
                SetPrintSettingsOnPrivateData(ourDataP, printSettings);
                status = PMSessionUseSheets(printSession, parentWindow, gMyPrintDialogDoneProc);
                if(status == noErr)
                    status = PMSessionPrintDialog(printSession, printSettings, 
                                    pageFormat,
                                    &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
            }
        }
        if(status != noErr){
            // if we got an error our dialog done proc will not be called so we need to clean up
            if(printSettings){
                SetPrintSettingsOnPrivateData(ourDataP, NULL);
                (void)PMRelease(printSettings);
            }
            (void)PMRelease(printSession);    
        }
    }
    DoErrorAlert(status, kMyPrintErrorFormatStrKey);
    return status;
}
예제 #6
0
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;
}
예제 #7
0
파일: printmac.cpp 프로젝트: EdgarTx/wx
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);
    }
}
예제 #8
0
// -----------------------------------------------------------------
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
예제 #9
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);
        }
    }
}
예제 #10
0
static boolean
carbonSessionPrintSession()
{
#if TARGET_API_MAC_CARBON == 1
	OSStatus	theErr;

	if (nil == shellprintinfo.printhandle)
	{
		theErr = PMCreateSession(&shellprintinfo.printhandle);
		
		if(theErr != noErr)
		{
			shellprintinfo.printhandle = nil;
			return (false);
		}
	}
#endif	
	return(true);
}
예제 #11
0
파일: Menus.c 프로젝트: alx741/vexedit
/*------------------------------------------------------------------------------
    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;
}
예제 #12
0
파일: Printer.cpp 프로젝트: ffostertw/praat
	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
	}
예제 #13
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;
}
예제 #14
0
// -----------------------------------------------------------------------
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;
}
예제 #15
0
/*!
    \internal
*/
bool QPrinter::pageSetup()
{
    if(!psession && PMCreateSession(&psession) != noErr)
        return FALSE;
    QMacBlockingFunction block;
    //page format
    if(!prepare(&pformat))
        return FALSE;
    {   //simulate modality
        QWidget modal_widg(0, __FILE__ "__modal_dlg",
                           Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder);
        qt_enter_modal(&modal_widg);
        Boolean ret;
        if(PMSessionPageSetupDialog(psession, pformat, &ret) != noErr)
            ret = FALSE;
        qt_leave_modal(&modal_widg);
        if(!ret)
            return FALSE;
    }

    interpret(&pformat);
    return TRUE;
}
예제 #16
0
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;
}
예제 #17
0
/*------------------------------------------------------------------------------
 	
    Description:
        Uses PMCreateSession/PMRelease instead of PMBegin/PMEnd.  Note that the two
        printing objects, PMPageSetup and PMPrintSettings are valid outside the
        printing session.  This was not the case with PMBegin/PMEnd in the previous
        version of this sample code.  Note also that no nesting of printing sessions
        is allowed for Carbon applications running under MacOS 8 or 9.
 	
------------------------------------------------------------------------------*/
int ioPrintSetup(PrintingLogicPtr *token)
{
    OSStatus		status = noErr;
    PrintingLogicPtr printJob;
   
    printJob = *token = calloc(1,sizeof(PrintingLogic));
    printJob->printSession = NULL;
    printJob->pageFormat = kPMNoPageFormat;
    printJob->printSettings = kPMNoPrintSettings;
    printJob->flatFormatHandle = NULL;
    printJob->numberOfPages = 0;
    printJob->aGWorld = NULL;
    
    //	Initialize the printing manager and create a printing session.
    status = PMCreateSession(&printJob->printSession);
    if (status != noErr) 
        return -1;	// pointless to continue if PMCreateSession fails
    
    //	Display the Page Setup dialog.
    if (status == noErr) {
        status = DoPageSetupDialog(printJob);
    }
    return status;
}
예제 #18
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;
}
예제 #19
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;
}
예제 #20
0
bool QPrinter::setup(QWidget *)
{
  if (!psession && PMCreateSession(&psession) != noErr)
    return FALSE;
  return (printSetup() && pageSetup());
}
예제 #21
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());
    }
}
예제 #22
0
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);
}