Esempio n. 1
0
void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data )
{
    PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ;
    PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ;
    PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ;

    int toPage = data->GetToPage();
    if (toPage < 1)
        toPage = data->GetFromPage();
    PMSetLastPage( m_macPrintSettings , toPage , false ) ;
}
Esempio n. 2
0
void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data )
{
    PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ;
    PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ;
    PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ;

    if (data->GetAllPages() || data->GetFromPage() == 0)
        PMSetLastPage( m_macPrintSettings , (UInt32) kPMPrintAllPages, true ) ;
    else
        PMSetLastPage( m_macPrintSettings , (UInt32) data->GetToPage() , false ) ;
}
Esempio n. 3
0
void wxOSXPrintData::TransferFrom( const wxPrintDialogData* data )
{
    // Respect the value of m_printAllPages
    if ( data->GetAllPages() )
        PMSetPageRange( m_macPrintSettings , data->GetMinPage() , (UInt32) kPMPrintAllPages ) ;
    else
        PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ;
    PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ;
    PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ;

    if (data->GetAllPages() || data->GetFromPage() == 0)
        PMSetLastPage( m_macPrintSettings , (UInt32) kPMPrintAllPages, true ) ;
    else
        PMSetLastPage( m_macPrintSettings , (UInt32) data->GetToPage() , false ) ;
#if wxOSX_USE_COCOA
    UpdateFromPMState();
#endif
}
Esempio n. 4
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;
}
Esempio n. 5
0
//-----------------------------------------------------------------------------------------------------------------------
static OSStatus DoPrintLoop(DocStoragePtr docStP, PMPrintSession printSession, PMPageFormat pageFormat, PMPrintSettings printSettings)
{
    OSStatus        status = noErr, tempErr;
    CGContextRef    printingCtx;
    UInt32          realNumberOfPagesinDoc,
                    pageNumber,
                    firstPage,
                    lastPage;
    CFStringRef     jobName;    // use window title

    status = CopyWindowTitleAsCFString(docStP->ownerWindow, &jobName);

    status = PMPrintSettingsSetJobName(printSettings, jobName);
    CFRelease (jobName);

    //	Get the user's Print dialog selection for first and last pages to print.
    if (status == noErr)
    {
        status = PMGetFirstPage(printSettings, &firstPage);
        if (status == noErr)
            status = PMGetLastPage(printSettings, &lastPage);
    }

    //	Check that the selected page range does not exceed the actual number of pages in the document.
    if (status == noErr)
    {
        status = DetermineNumberOfPagesInDoc(pageFormat, &realNumberOfPagesinDoc);
        if (realNumberOfPagesinDoc < lastPage)
            lastPage = realNumberOfPagesinDoc;
    }

    //	Before executing the print loop, tell the Carbon Printing Manager which pages
    //	will be spooled so that the progress dialog can reflect an accurate page count.
	
    if (status == noErr)
        status = PMSetFirstPage(printSettings, firstPage, false);
    if (status == noErr)
        status = PMSetLastPage(printSettings, lastPage, false);
    	
    //	Note, we don't have to worry about the number of copies.  The printing
    //	manager handles this.  So we just iterate through the document from the
    //	first page to be printed, to the last.
    
    if (status == noErr)
    {
		// Now, tell the printing system that we promise never to use any Quickdraw calls:
        status = PMSessionBeginCGDocument(printSession, printSettings, pageFormat);
        check(status == noErr);
        if (status == noErr)
        {
            pageNumber = firstPage;
        
            // Note that we check PMSessionError immediately before beginning a new page.
            // This handles user cancelling appropriately. Also, if we got an error on 
            // any previous iteration of the print loop, we break out of the loop.
            while ( (pageNumber <= lastPage) && (status == noErr) && (PMSessionError(printSession) == noErr) )
            {
                status = PMSessionBeginPage(printSession, pageFormat, NULL);
                check(status == noErr);
                if (status == noErr)
                {
                    status = PMSessionGetCGGraphicsContext(printSession, &printingCtx);
                    check(status == noErr);
                    if (status == noErr) 
                    {
			DrawThePage(printingCtx, docStP);
                    }
                                    
                    tempErr = PMSessionEndPage(printSession);
                    if(status == noErr)
                        status = tempErr;
                }
                pageNumber++;
            } // end while loop
                    
            // Close the print job.  This dismisses the progress dialog on Mac OS X.
            tempErr = PMSessionEndDocument(printSession);
            if (status == noErr)
                status = tempErr;
        }
    }
            
    //	Only report a printing error once we have completed the print loop. This ensures
    //	that every PMBeginXXX call that returns no error is followed by a matching PMEndXXX
    //  call, so the Printing Manager can release all temporary memory and close properly.
    tempErr = PMSessionError(printSession);
    if(status == noErr)
        status = tempErr;
/*
    if ((status != noErr) && (status != kPMCancel))
        PostPrintingErrors(status);
*/		
    return status;
} // DoPrintLoop
Esempio n. 6
0
int ioPrintPreProcessing(PrintingLogicPtr printJob,int numberOfPages) {
    OSStatus		status = noErr;
    UInt32	realNumberOfPagesinDoc;
    
    //	Display the Print dialog.
    
    if (printJob->printSession == NULL) 
        return -1;
        
    printJob->numberOfPages = numberOfPages;
    printJob->allowPostscript = false;
    
    status = DoPrintDialog(printJob);
    
    if (status == noErr) {
	    //issues with os 9 don't do CFStringRef	jobName = CFSTR("Squeak");
        //issues with os 9 don't do status = PMSetJobNameCFString(printJob->printSettings, jobName);
    
        //	Get the user's Print dialog selection for first and last pages to print.
        if (status == noErr)
            { 
            status = PMGetFirstPage(printJob->printSettings, &printJob->firstPage);
            if (status == noErr)
                status = PMGetLastPage(printJob->printSettings, &printJob->lastPage);
            }
    
        //	Check that the selected page range does not exceed the actual number of
        //	pages in the document.
        if (status == noErr)
            {
            status = DetermineNumberOfPagesInDoc(&realNumberOfPagesinDoc,printJob);
            if (realNumberOfPagesinDoc < printJob->lastPage)
                printJob->lastPage = realNumberOfPagesinDoc;
            }
    
        //	Before executing the print loop, tell the Carbon Printing Manager which pages
        //	will be spooled so that the progress dialog can reflect an accurate page count.
        //	This is recommended on Mac OS X.  On Mac OS 8 and 9, we have no control over
        //	what the printer driver displays.
            
        if (status == noErr)
            status = PMSetFirstPage(printJob->printSettings, printJob->firstPage, false);
        if (status == noErr)
            status = PMSetLastPage(printJob->printSettings, printJob->lastPage, false);
	if (status == noErr)
            status = PMSetPageRange(printJob->printSettings, 1, printJob->lastPage-printJob->firstPage+1);
        //	Check if we can add PostScript to the spool file
        if (status == noErr) { 
			CFStringRef         strings[1];
			CFArrayRef          ourGraphicsContextsArray;
			OSErr               err = noErr;
			
            printJob->allowPostscript = true;   //IncludePostScriptInSpoolFile(printJob);
			//
			//    at this point you've already created a print session
			//
			strings[0] = kPMGraphicsContextCoreGraphics; // This is important!
			ourGraphicsContextsArray = CFArrayCreate (kCFAllocatorDefault,
								(const void **)strings,
								1, &kCFTypeArrayCallBacks);
			if (ourGraphicsContextsArray != NULL) {
					err = PMSessionSetDocumentFormatGeneration (printJob->printSession,
									kPMDocumentFormatPDF,
									ourGraphicsContextsArray, NULL);
					CFRelease (ourGraphicsContextsArray);
			}
					
			}
        
        //	Begin a new print job.
        status = PMSessionBeginDocument(printJob->printSession, printJob->printSettings, printJob->pageFormat);
        }

    return status;
}
Esempio n. 7
0
int QPrintDialog::exec()
{
    Q_D(QPrintDialog);
    QMacBlockingFunction func;
    Boolean result;

    // If someone is reusing a QPrinter object, the end released all our old
    // information. In this case, we must reinitialize.
    if (d->ep->session == 0)
        d->ep->initialize();

    // Carbon's documentation lies.
    // It seems the only way that Carbon lets you use all is if the minimum
    // for the page range is 1. This _kind of_ makes sense if you think about
    // it. However, calling _q_setFirstPage or _q_setLastPage always enforces the range.
    PMSetPageRange(d->ep->settings, minPage(), maxPage());
    if (printRange() == PageRange) {
        PMSetFirstPage(d->ep->settings, fromPage(), false);
        PMSetLastPage(d->ep->settings, toPage(), false);
    }
    { //simulate modality
	QWidget modal_widg(0, Qt::Window);
        modal_widg.setObjectName(QLatin1String(__FILE__ "__modal_dlg"));
	QApplicationPrivate::enterModal(&modal_widg);
        PMSessionPrintDialog(d->ep->session, d->ep->settings, d->ep->format, &result);
	QApplicationPrivate::leaveModal(&modal_widg);
    }
    if (result) {
        UInt32 frompage, topage;
        PMGetFirstPage(d->ep->settings, &frompage);
        PMGetLastPage(d->ep->settings, &topage);
        topage = qMin(UInt32(INT_MAX), topage);
        setFromTo(frompage, topage);

        // OK, I need to map these values back let's see
        // If from is 1 and to is INT_MAX, then print it all
        // (Apologies to the folks with more than INT_MAX pages)
        // ...that's a joke.
        if (fromPage() == 1 && toPage() == INT_MAX) {
            setPrintRange(AllPages);
            setFromTo(0,0);
        } else {
            setPrintRange(PageRange); // In a way a lie, but it shouldn't hurt.
            // Carbon hands us back a very large number here even for ALL, set it to max
            // in that case to follow the behavior of the other print dialogs.
            if (maxPage() < toPage())
                setFromTo(fromPage(), maxPage());
        }
        // Keep us in sync with file output
        PMDestinationType dest;
        PMSessionGetDestinationType(d->ep->session, d->ep->settings, &dest);
        if (dest == kPMDestinationFile) {
            QCFType<CFURLRef> file;
            PMSessionCopyDestinationLocation(d->ep->session, d->ep->settings, &file);
            UInt8 localFile[2048];  // Assuming there's a POSIX file system here.
            CFURLGetFileSystemRepresentation(file, true, localFile, sizeof(localFile));
            d->ep->outputFilename
                = QString::fromUtf8(reinterpret_cast<const char *>(localFile));
        }
    }
    return result;
}