Ejemplo n.º 1
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);
}
Ejemplo n.º 2
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;
}