diff --git a/src/plugins/printsupport/windows/qwindowsprintersupport.cpp b/src/plugins/printsupport/windows/qwindowsprintersupport.cpp index 2905063c51..c5c60ae5cc 100644 --- a/src/plugins/printsupport/windows/qwindowsprintersupport.cpp +++ b/src/plugins/printsupport/windows/qwindowsprintersupport.cpp @@ -58,12 +58,13 @@ QWindowsPrinterSupport::QWindowsPrinterSupport() LPBYTE buffer = new BYTE[needed]; if (EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, buffer, needed, &needed, &returned)) { PPRINTER_INFO_4 infoList = reinterpret_cast(buffer); - QPrinterInfo defPrn = defaultPrinter(); + QString defaultPrinterName; + QWin32PrintEngine::queryDefaultPrinter(defaultPrinterName, QString(), QString()); for (uint i = 0; i < returned; ++i) { QString printerName(QString::fromWCharArray(infoList[i].pPrinterName)); QPrinterInfo printerInfo(printerName); - if (printerInfo.printerName() == defPrn.printerName()) + if (printerInfo.printerName() == defaultPrinterName) printerInfo.d_ptr->isDefault = true; mPrinterList.append(printerInfo); } diff --git a/src/printsupport/kernel/qprintengine.h b/src/printsupport/kernel/qprintengine.h index eb7797b5e0..563af895c1 100644 --- a/src/printsupport/kernel/qprintengine.h +++ b/src/printsupport/kernel/qprintengine.h @@ -101,12 +101,6 @@ public: virtual int metric(QPaintDevice::PaintDeviceMetric) const = 0; virtual QPrinter::PrinterState printerState() const = 0; - -#ifdef Q_WS_WIN - virtual HDC getPrinterDC() const { return 0; } - virtual void releasePrinterDC(HDC) const { } -#endif - }; #endif // QT_NO_PRINTER diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 171ebbce17..37d2b27d15 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -966,28 +966,7 @@ void QWin32PrintEngine::drawPolygon(const QPointF *points, int pointCount, Polyg void QWin32PrintEnginePrivate::queryDefault() { - /* Read the default printer name, driver and port with the intuitive function - * Strings "windows" and "device" are specified in the MSDN under EnumPrinters() - */ - QString noPrinters(QLatin1String("qt_no_printers")); - wchar_t buffer[256]; - GetProfileString(L"windows", L"device", - reinterpret_cast(noPrinters.utf16()), - buffer, 256); - QString output = QString::fromWCharArray(buffer); - if (output.isEmpty() || output == noPrinters) // no printers - return; - - QStringList info = output.split(QLatin1Char(',')); - int infoSize = info.size(); - if (infoSize > 0) { - if (name.isEmpty()) - name = info.at(0); - if (program.isEmpty() && infoSize > 1) - program = info.at(1); - if (port.isEmpty() && infoSize > 2) - port = info.at(2); - } + QWin32PrintEngine::queryDefaultPrinter(name, program, port); } QWin32PrintEnginePrivate::~QWin32PrintEnginePrivate() @@ -1601,6 +1580,32 @@ QList QWin32PrintEngine::supportedPaperSizes(const QPrinter return returnList; } +void QWin32PrintEngine::queryDefaultPrinter(QString &name, QString &program, QString &port) +{ + /* Read the default printer name, driver and port with the intuitive function + * Strings "windows" and "device" are specified in the MSDN under EnumPrinters() + */ + QString noPrinters(QLatin1String("qt_no_printers")); + wchar_t buffer[256]; + GetProfileString(L"windows", L"device", + reinterpret_cast(noPrinters.utf16()), + buffer, 256); + QString output = QString::fromWCharArray(buffer); + if (output.isEmpty() || output == noPrinters) // no printers + return; + + QStringList info = output.split(QLatin1Char(',')); + int infoSize = info.size(); + if (infoSize > 0) { + if (name.isEmpty()) + name = info.at(0); + if (program.isEmpty() && infoSize > 1) + program = info.at(1); + if (port.isEmpty() && infoSize > 2) + port = info.at(2); + } +} + HGLOBAL *QWin32PrintEnginePrivate::createDevNames() { int size = sizeof(DEVNAMES) diff --git a/src/printsupport/kernel/qprintengine_win_p.h b/src/printsupport/kernel/qprintengine_win_p.h index c267c1057f..8da6f32268 100644 --- a/src/printsupport/kernel/qprintengine_win_p.h +++ b/src/printsupport/kernel/qprintengine_win_p.h @@ -103,10 +103,8 @@ public: HDC getDC() const; void releaseDC(HDC) const; - HDC getPrinterDC() const { return getDC(); } - void releasePrinterDC(HDC dc) const { releaseDC(dc); } - static QList supportedPaperSizes(const QPrinterInfo &printerInfo); + static void queryDefaultPrinter(QString &name, QString &program, QString &port); private: friend class QPrintDialog; diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp index 404f45d509..d713639dcc 100644 --- a/src/printsupport/kernel/qprinter.cpp +++ b/src/printsupport/kernel/qprinter.cpp @@ -56,10 +56,6 @@ #include #include -#if defined (Q_WS_WIN) -#include -#endif - #if defined(Q_WS_X11) #include #endif @@ -1722,7 +1718,7 @@ QPrintEngine *QPrinter::printEngine() const return d->printEngine; } -#if defined (Q_WS_WIN) +#if defined (Q_OS_WIN) /*! Sets the page size to be used by the printer under Windows to \a pageSize. @@ -1753,7 +1749,7 @@ int QPrinter::winPageSize() const Q_D(const QPrinter); return d->printEngine->property(QPrintEngine::PPK_WindowsPageSize).toInt(); } -#endif // Q_WS_WIN +#endif // Q_OS_WIN /*! Returns a list of the resolutions (a list of dots-per-inch @@ -1864,25 +1860,7 @@ QPrinter::PrinterState QPrinter::printerState() const Use printerState() == QPrinter::Aborted instead. */ -#ifdef Q_WS_WIN -/*! - \internal -*/ -HDC QPrinter::getDC() const -{ - Q_D(const QPrinter); - return d->printEngine->getPrinterDC(); -} - -/*! - \internal -*/ -void QPrinter::releaseDC(HDC hdc) const -{ - Q_D(const QPrinter); - d->printEngine->releasePrinterDC(hdc); -} - +#ifdef Q_OS_WIN /*! Returns the supported paper sizes for this printer. @@ -1907,7 +1885,7 @@ QList QPrinter::supportedPaperSources() const return int_list; } -#endif +#endif // Q_OS_WIN /*! \fn QString QPrinter::printerSelectionOption() const @@ -1941,7 +1919,7 @@ QList QPrinter::supportedPaperSources() const \sa printerSelectionOption() */ -#ifndef Q_WS_WIN +#ifndef Q_OS_WIN QString QPrinter::printerSelectionOption() const { Q_D(const QPrinter); @@ -2207,16 +2185,6 @@ QPrinter::PrintRange QPrinter::printRange() const Returns the current state of the printer being used by the print engine. */ -/*! - \fn HDC QPrintEngine::getPrinterDC() const - \internal -*/ - -/*! - \fn void QPrintEngine::releasePrinterDC(HDC) const - \internal -*/ - /* Returns the dimensions for the given paper size, \a size, in millimeters. */ diff --git a/src/printsupport/kernel/qprinter.h b/src/printsupport/kernel/qprinter.h index 17b125bbf8..23c7ccc40c 100644 --- a/src/printsupport/kernel/qprinter.h +++ b/src/printsupport/kernel/qprinter.h @@ -200,7 +200,7 @@ public: QList supportedResolutions() const; -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN QList supportedPaperSources() const; #endif @@ -210,7 +210,7 @@ public: void setDoubleSidedPrinting(bool enable); bool doubleSidedPrinting() const; -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN void setWinPageSize(int winPageSize); int winPageSize() const; #endif @@ -220,7 +220,7 @@ public: QRectF paperRect(Unit) const; QRectF pageRect(Unit) const; -#if !defined(Q_WS_WIN) || defined(qdoc) +#if !defined(Q_OS_WIN) || defined(qdoc) QString printerSelectionOption() const; void setPrinterSelectionOption(const QString &); #endif @@ -233,11 +233,6 @@ public: QPaintEngine *paintEngine() const; QPrintEngine *printEngine() const; -#ifdef Q_WS_WIN - HDC getDC() const; - void releaseDC(HDC hdc) const; -#endif - void setFromTo(int fromPage, int toPage); int fromPage() const; int toPage() const; diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp index 3460ad702b..7b862c6653 100644 --- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp +++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp @@ -235,8 +235,8 @@ void tst_QPrinter::testPageSetupDialog() void tst_QPrinter::testPageSize() { -#if 1 - QSKIP("QPrinter::winPageSize(): Windows only and currently not implemented / QTBUG-22927"); +#ifndef Q_OS_WIN + QSKIP("QPrinter::winPageSize(): Windows only."); #else QPrinter prn; @@ -255,7 +255,7 @@ void tst_QPrinter::testPageSize() prn.setWinPageSize(DMPAPER_A4); MYCOMPARE(prn.winPageSize(), DMPAPER_A4); MYCOMPARE(prn.pageSize(), QPrinter::A4); -#endif +#endif // Q_OS_WIN } void tst_QPrinter::testPageRectAndPaperRect_data() @@ -625,7 +625,25 @@ void tst_QPrinter::valuePreservation() QPrinter::OutputFormat oldFormat = QPrinter::PdfFormat; QPrinter::OutputFormat newFormat = QPrinter::NativeFormat; // TODO: Correct? - { + // Some properties are documented to only be supported by NativeFormat in X11 environment + bool doX11Tests = QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive) == 0; + bool windowsPlatform = QGuiApplication::platformName().compare(QLatin1String("windows"), Qt::CaseInsensitive) == 0; + bool manualSourceSupported = true; + +#ifdef Q_OS_WIN + // QPrinter::supportedPaperSources() is only available on Windows, so just assuming manual is supported on others. + QPrinter printer; + printer.setOutputFormat(newFormat); + QList sources = printer.supportedPaperSources(); + if (!sources.contains(QPrinter::Manual)) { + manualSourceSupported = false; + qWarning() << "Manual paper source not supported by native printer, skipping related test."; + } +#endif // Q_OS_WIN + + // Querying PPK_CollateCopies is hardcoded to return false with Windows native print engine, + // so skip testing that in Windows. + if (!windowsPlatform) { QPrinter printer; printer.setOutputFormat(oldFormat); bool status = printer.collateCopies(); @@ -653,7 +671,7 @@ void tst_QPrinter::valuePreservation() printer.setOutputFormat(oldFormat); QCOMPARE(printer.colorMode(), QPrinter::ColorMode(!status)); } - { + if (doX11Tests) { QPrinter printer; printer.setOutputFormat(oldFormat); QString status = printer.creator(); @@ -683,7 +701,7 @@ void tst_QPrinter::valuePreservation() printer.setOutputFormat(oldFormat); QCOMPARE(printer.docName(), status); } - { + if (doX11Tests) { QPrinter printer; printer.setOutputFormat(oldFormat); bool status = printer.doubleSidedPrinting(); @@ -697,7 +715,7 @@ void tst_QPrinter::valuePreservation() printer.setOutputFormat(oldFormat); QCOMPARE(printer.doubleSidedPrinting(), !status); } - { + if (doX11Tests) { QPrinter printer; printer.setOutputFormat(oldFormat); bool status = printer.fontEmbeddingEnabled(); @@ -754,7 +772,7 @@ void tst_QPrinter::valuePreservation() printer.setOutputFormat(oldFormat); QCOMPARE(printer.outputFileName(), status); } - { + if (doX11Tests) { QPrinter printer; printer.setOutputFormat(oldFormat); QPrinter::PageOrder status = printer.pageOrder(); @@ -782,7 +800,7 @@ void tst_QPrinter::valuePreservation() printer.setOutputFormat(oldFormat); QCOMPARE(printer.pageSize(), QPrinter::B5); } - { + if (manualSourceSupported) { QPrinter printer; printer.setOutputFormat(oldFormat); QPrinter::PaperSource status = printer.paperSource(); @@ -796,7 +814,7 @@ void tst_QPrinter::valuePreservation() printer.setOutputFormat(oldFormat); QCOMPARE(printer.paperSource(), QPrinter::Manual); } - { + if (doX11Tests) { QPrinter printer; printer.setOutputFormat(oldFormat); QString status = printer.printProgram(); @@ -840,6 +858,7 @@ void tst_QPrinter::valuePreservation() printer.setOutputFormat(oldFormat); QCOMPARE(printer.printerName(), status); } + // QPrinter::printerSelectionOption is explicitly documented not to be available on Windows. #ifndef Q_OS_WIN { QPrinter printer; @@ -856,7 +875,7 @@ void tst_QPrinter::valuePreservation() printer.setOutputFormat(oldFormat); QCOMPARE(printer.printerSelectionOption(), status); } -#endif +#endif // Q_OS_WIN { QPrinter printer; printer.setOutputFormat(oldFormat);