Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/painting/qprintengine_mac.mm

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    6262{
    6363    Q_D(QMacPrintEngine);
     64
     65    Q_ASSERT(dev && dev->devType() == QInternal::Printer);
     66    if (!static_cast<QPrinter *>(dev)->isValid())
     67        return false;
    6468
    6569    if (d->state == QPrinter::Idle && !d->isPrintSessionInitialized()) // Need to reinitialize
     
    8993    OSStatus status = noErr;
    9094#ifndef QT_MAC_USE_COCOA
    91 #  if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    92     if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    93         status = d->shouldSuppressStatus() ? PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format)
    94                                            : PMSessionBeginCGDocument(d->session, d->settings, d->format);
    95     } else
    96 #  endif
    97     {
    98         status = d->shouldSuppressStatus() ? PMSessionBeginDocumentNoDialog(d->session, d->settings, d->format)
    99                                            : PMSessionBeginDocument(d->session, d->settings, d->format);
    100     }
     95    status = d->shouldSuppressStatus() ? PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format)
     96                                       : PMSessionBeginCGDocument(d->session, d->settings, d->format);
    10197#else
    10298    status = PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format);
     
    122118        static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->hd = 0;
    123119    d->paintEngine->end();
    124     if (d->state != QPrinter::Idle) {
    125 #ifndef QT_MAC_USE_COCOA
    126         if (d->shouldSuppressStatus()) {
    127             PMSessionEndPageNoDialog(d->session);
    128             PMSessionEndDocumentNoDialog(d->session);
    129         } else {
    130             PMSessionEndPage(d->session);
    131             PMSessionEndDocument(d->session);
    132         }
    133         PMRelease(d->session);
    134 #else
    135         PMSessionEndPageNoDialog(d->session);
    136         PMSessionEndDocumentNoDialog(d->session);
    137         [d->printInfo release];
    138 #endif
    139         d->printInfo = 0;
    140         d->session = 0;
    141     }
     120    if (d->state != QPrinter::Idle)
     121        d->releaseSession();
    142122    d->state  = QPrinter::Idle;
    143123    return true;
     
    481461
    482462#ifndef QT_MAC_USE_COCOA
    483 # if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    484     if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_4)
    485 # endif
    486     {
    487         if(paintEngine->type() == QPaintEngine::CoreGraphics) {
    488             CFStringRef strings[1] = { kPMGraphicsContextCoreGraphics };
    489             QCFType<CFArrayRef> contextArray = CFArrayCreate(kCFAllocatorDefault,
    490                     reinterpret_cast<const void **>(strings),
    491                     1, &kCFTypeArrayCallBacks);
    492             OSStatus err = PMSessionSetDocumentFormatGeneration(session, kPMDocumentFormatPDF,
    493                     contextArray, 0);
    494             if(err != noErr) {
    495                 qWarning("QMacPrintEngine::initialize: Cannot set format generation to PDF: %ld", err);
    496                 state = QPrinter::Error;
    497             }
    498         }
    499     }
    500463    if (!settingsOK || !formatOK) {
    501464        qWarning("QMacPrintEngine::initialize: Unable to initialize QPainter");
     
    508471        q->setProperty(propC.key(), propC.value());
    509472    }
     473}
     474
     475void QMacPrintEnginePrivate::releaseSession()
     476{
     477#ifndef QT_MAC_USE_COCOA
     478    if (shouldSuppressStatus()) {
     479        PMSessionEndPageNoDialog(session);
     480        PMSessionEndDocumentNoDialog(session);
     481    } else {
     482        PMSessionEndPage(session);
     483        PMSessionEndDocument(session);
     484    }
     485    PMRelease(session);
     486#else
     487    PMSessionEndPageNoDialog(session);
     488    PMSessionEndDocumentNoDialog(session);
     489    [printInfo release];
     490#endif
     491    printInfo = 0;
     492    session = 0;
    510493}
    511494
     
    544527    CGContextRef cgContext;
    545528    OSStatus err = noErr;
    546 #ifndef QT_MAC_USE_COCOA
    547 #  if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    548     if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    549         err = PMSessionGetCGGraphicsContext(session, &cgContext);
    550     } else
    551 #  endif
    552     {
    553         err = PMSessionGetGraphicsContext(session, kPMGraphicsContextCoreGraphics,
    554                                           reinterpret_cast<void **>(&cgContext));
    555     }
    556 #else
    557529    err = PMSessionGetCGGraphicsContext(session, &cgContext);
    558 #endif
    559530    if(err != noErr) {
    560531        qWarning("QMacPrintEngine::newPage: Cannot retrieve CoreGraphics context: %ld", long(err));
     
    738709        break;
    739710    case PPK_PrinterName: {
     711        bool printerNameSet = false;
    740712        OSStatus status = noErr;
    741713        QCFType<CFArrayRef> printerList;
     
    748720                if (name == value.toString()) {
    749721                    status = PMSessionSetCurrentPMPrinter(d->session, printer);
     722                    printerNameSet = true;
    750723                    break;
    751724                }
     
    754727        if (status != noErr)
    755728            qWarning("QMacPrintEngine::setPrinterName: Error setting printer: %ld", long(status));
     729        if (!printerNameSet) {
     730            qWarning("QMacPrintEngine::setPrinterName: Failed to set printer named '%s'.", qPrintable(value.toString()));
     731            d->releaseSession();
     732            d->state = QPrinter::Idle;
     733        }
    756734        break; }
    757735    case PPK_SuppressSystemPrintStatus:
     
    877855        break; }
    878856    case PPK_PrinterName: {
    879         CFIndex currIndex;
    880         PMPrinter unused;
    881         QCFType<CFArrayRef> printerList;
    882         OSStatus status = PMSessionCreatePrinterList(d->session, &printerList, &currIndex, &unused);
     857        PMPrinter printer;
     858        OSStatus status = PMSessionGetCurrentPrinter(d->session, &printer);
    883859        if (status != noErr)
    884             qWarning("QMacPrintEngine::printerName: Problem getting list of printers: %ld", long(status));
    885         if (currIndex != -1 && printerList && currIndex < CFArrayGetCount(printerList)) {
    886             const CFStringRef name = static_cast<CFStringRef>(CFArrayGetValueAtIndex(printerList, currIndex));
    887             if (name)
    888                 ret = QCFString::toQString(name);
    889         }
     860            qWarning("QMacPrintEngine::printerName: Failed getting current PMPrinter: %ld", long(status));
     861        if (printer)
     862            ret = QCFString::toQString(PMPrinterGetName(printer));
    890863        break; }
    891864    case PPK_Resolution: {
Note: See TracChangeset for help on using the changeset viewer.