diff options
Diffstat (limited to 'src/printsupport/dialogs/qprintdialog_win.cpp')
-rw-r--r-- | src/printsupport/dialogs/qprintdialog_win.cpp | 94 |
1 files changed, 34 insertions, 60 deletions
diff --git a/src/printsupport/dialogs/qprintdialog_win.cpp b/src/printsupport/dialogs/qprintdialog_win.cpp index 4f2ee83f62..6d8c2d0f4d 100644 --- a/src/printsupport/dialogs/qprintdialog_win.cpp +++ b/src/printsupport/dialogs/qprintdialog_win.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <QtPrintSupport/qtprintsupportglobal.h> @@ -59,6 +23,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + //extern void qt_win_eatMouseMove(); class QPrintDialogPrivate : public QAbstractPrintDialogPrivate @@ -76,7 +42,7 @@ public: QWin32PrintEnginePrivate *ep; }; -static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent, +static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWindow *parentWindow, QPrintDialog *pdlg, QPrintDialogPrivate *d, HGLOBAL *tempDevNames) { @@ -135,9 +101,12 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent, if (d->ep->printToFile) pd->Flags |= PD_PRINTTOFILE; - Q_ASSERT(parent); - QWindow *parentWindow = parent->windowHandle(); - pd->hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0; + + WId wId = parentWindow ? parentWindow->winId() : 0; + //QTBUG-118899 PrintDlg needs valid window handle in hwndOwner + //So in case there is no valid handle in the application, + //use the desktop as valid handle. + pd->hwndOwner = wId != 0 ? HWND(wId) : GetDesktopWindow(); pd->lpPageRanges[0].nFromPage = qMax(pdlg->fromPage(), pdlg->minPage()); pd->lpPageRanges[0].nToPage = (pdlg->toPage() > 0) ? qMin(pdlg->toPage(), pdlg->maxPage()) : 1; pd->nCopies = d->printer->copyCount(); @@ -147,16 +116,16 @@ static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPri { if (pd->Flags & PD_SELECTION) { pdlg->setPrintRange(QPrintDialog::Selection); - pdlg->setFromTo(0, 0); + pdlg->printer()->setPageRanges(QPageRanges()); } else if (pd->Flags & PD_PAGENUMS) { pdlg->setPrintRange(QPrintDialog::PageRange); pdlg->setFromTo(pd->lpPageRanges[0].nFromPage, pd->lpPageRanges[0].nToPage); } else if (pd->Flags & PD_CURRENTPAGE) { pdlg->setPrintRange(QPrintDialog::CurrentPage); - pdlg->setFromTo(0, 0); + pdlg->printer()->setPageRanges(QPageRanges()); } else { // PD_ALLPAGES pdlg->setPrintRange(QPrintDialog::AllPages); - pdlg->setFromTo(0, 0); + pdlg->printer()->setPageRanges(QPageRanges()); } d->ep->printToFile = (pd->Flags & PD_PRINTTOFILE) != 0; @@ -164,8 +133,8 @@ static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPri d->engine->setGlobalDevMode(pd->hDevNames, pd->hDevMode); if (d->ep->printToFile && d->ep->fileName.isEmpty()) - d->ep->fileName = QLatin1String("FILE:"); - else if (!d->ep->printToFile && d->ep->fileName == QLatin1String("FILE:")) + d->ep->fileName = "FILE:"_L1; + else if (!d->ep->printToFile && d->ep->fileName == "FILE:"_L1) d->ep->fileName.clear(); } @@ -216,15 +185,20 @@ int QPrintDialog::exec() int QPrintDialogPrivate::openWindowsPrintDialogModally() { Q_Q(QPrintDialog); - QWidget *parent = q->parentWidget(); - if (parent) - parent = parent->window(); - else - parent = QApplication::activeWindow(); - - // If there is no window, fall back to the print dialog itself - if (parent == 0) - parent = q; + QWindow *parentWindow = q->windowHandle() ? q->windowHandle()->transientParent() : nullptr; + if (!parentWindow) { + QWidget *parent = q->parentWidget(); + if (parent) + parent = parent->window(); + else + parent = QApplication::activeWindow(); + + // If there is no window, fall back to the print dialog itself + if (!parent) + parent = q; + + parentWindow = parent->windowHandle(); + } q->QDialog::setVisible(true); @@ -239,7 +213,7 @@ int QPrintDialogPrivate::openWindowsPrintDialogModally() memset(&pd, 0, sizeof(PRINTDLGEX)); pd.lStructSize = sizeof(PRINTDLGEX); pd.lpPageRanges = &pageRange; - qt_win_setup_PRINTDLGEX(&pd, parent, q, this, tempDevNames); + qt_win_setup_PRINTDLGEX(&pd, parentWindow, q, this, tempDevNames); do { done = true; @@ -261,9 +235,9 @@ int QPrintDialogPrivate::openWindowsPrintDialogModally() } if (!done) { - QMessageBox::warning(0, QPrintDialog::tr("Print"), - QPrintDialog::tr("The 'From' value cannot be greater than the 'To' value."), - QPrintDialog::tr("OK")); + QMessageBox::warning(nullptr, + QPrintDialog::tr("Print"), + QPrintDialog::tr("The 'From' value cannot be greater than the 'To' value.")); } } while (!done); |