| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 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.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qpagesetupdialog.h"
|
|---|
| 43 |
|
|---|
| 44 | #ifndef QT_NO_PRINTDIALOG
|
|---|
| 45 | #include <qapplication.h>
|
|---|
| 46 |
|
|---|
| 47 | #include <private/qprintengine_win_p.h>
|
|---|
| 48 | #include <private/qabstractpagesetupdialog_p.h>
|
|---|
| 49 |
|
|---|
| 50 | QT_BEGIN_NAMESPACE
|
|---|
| 51 |
|
|---|
| 52 | class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate
|
|---|
| 53 | {
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
|
|---|
| 57 | : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent)
|
|---|
| 58 | {
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | QPageSetupDialog::QPageSetupDialog(QWidget *parent)
|
|---|
| 62 | : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), 0, parent)
|
|---|
| 63 | {
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | int QPageSetupDialog::exec()
|
|---|
| 67 | {
|
|---|
| 68 | Q_D(QPageSetupDialog);
|
|---|
| 69 |
|
|---|
| 70 | if (d->printer->outputFormat() != QPrinter::NativeFormat)
|
|---|
| 71 | return Rejected;
|
|---|
| 72 |
|
|---|
| 73 | QWin32PrintEngine *engine = static_cast<QWin32PrintEngine*>(d->printer->paintEngine());
|
|---|
| 74 | QWin32PrintEnginePrivate *ep = static_cast<QWin32PrintEnginePrivate *>(engine->d_ptr);
|
|---|
| 75 |
|
|---|
| 76 | PAGESETUPDLG psd;
|
|---|
| 77 | memset(&psd, 0, sizeof(PAGESETUPDLG));
|
|---|
| 78 | psd.lStructSize = sizeof(PAGESETUPDLG);
|
|---|
| 79 |
|
|---|
| 80 | // we need a temp DEVMODE struct if we don't have a global DEVMODE
|
|---|
| 81 | HGLOBAL hDevMode;
|
|---|
| 82 | int devModeSize;
|
|---|
| 83 | if (!ep->globalDevMode) {
|
|---|
| 84 | QT_WA( { devModeSize = sizeof(DEVMODEW) + ((DEVMODEW *) ep->devMode)->dmDriverExtra; },
|
|---|
| 85 | { devModeSize = sizeof(DEVMODEA) + ((DEVMODEA *) ep->devMode)->dmDriverExtra; });
|
|---|
| 86 | hDevMode = GlobalAlloc(GHND, devModeSize);
|
|---|
| 87 | if (hDevMode) {
|
|---|
| 88 | void *dest = GlobalLock(hDevMode);
|
|---|
| 89 | memcpy(dest, ep->devMode, devModeSize);
|
|---|
| 90 | GlobalUnlock(hDevMode);
|
|---|
| 91 | }
|
|---|
| 92 | psd.hDevMode = hDevMode;
|
|---|
| 93 | } else {
|
|---|
| 94 | psd.hDevMode = ep->devMode;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | HGLOBAL *tempDevNames = ep->createDevNames();
|
|---|
| 98 | psd.hDevNames = tempDevNames;
|
|---|
| 99 |
|
|---|
| 100 | QWidget *parent = parentWidget();
|
|---|
| 101 | parent = parent ? parent->window() : qApp->activeWindow();
|
|---|
| 102 | Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));
|
|---|
| 103 | psd.hwndOwner = parent ? parent->winId() : 0;
|
|---|
| 104 |
|
|---|
| 105 | QRect paperRect = d->printer->paperRect();
|
|---|
| 106 | QRect pageRect = d->printer->pageRect();
|
|---|
| 107 |
|
|---|
| 108 | psd.Flags = PSD_MARGINS;
|
|---|
| 109 | double multiplier = 1;
|
|---|
| 110 | switch (QLocale::system().measurementSystem()) {
|
|---|
| 111 | case QLocale::MetricSystem:
|
|---|
| 112 | psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
|
|---|
| 113 | multiplier = 1;
|
|---|
| 114 | break;
|
|---|
| 115 | case QLocale::ImperialSystem:
|
|---|
| 116 | psd.Flags |= PSD_INTHOUSANDTHSOFINCHES;
|
|---|
| 117 | multiplier = 25.4/10;
|
|---|
| 118 | break;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | QRect marginRect = ep->getPageMargins();
|
|---|
| 122 | psd.rtMargin.left = marginRect.left() / multiplier;
|
|---|
| 123 | psd.rtMargin.top = marginRect.top() / multiplier;
|
|---|
| 124 | psd.rtMargin.right = marginRect.width() / multiplier;;
|
|---|
| 125 | psd.rtMargin.bottom = marginRect.height() / multiplier;;
|
|---|
| 126 |
|
|---|
| 127 | bool result = PageSetupDlg(&psd);
|
|---|
| 128 | if (result) {
|
|---|
| 129 | ep->readDevnames(psd.hDevNames);
|
|---|
| 130 | ep->readDevmode(psd.hDevMode);
|
|---|
| 131 |
|
|---|
| 132 | QRect theseMargins = QRect(psd.rtMargin.left * multiplier,
|
|---|
| 133 | psd.rtMargin.top * multiplier,
|
|---|
| 134 | psd.rtMargin.right * multiplier,
|
|---|
| 135 | psd.rtMargin.bottom * multiplier);
|
|---|
| 136 |
|
|---|
| 137 | if (theseMargins != marginRect) {
|
|---|
| 138 | ep->setPageMargins(psd.rtMargin.left * multiplier,
|
|---|
| 139 | psd.rtMargin.top * multiplier,
|
|---|
| 140 | psd.rtMargin.right * multiplier,
|
|---|
| 141 | psd.rtMargin.bottom * multiplier);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | ep->updateCustomPaperSize();
|
|---|
| 145 |
|
|---|
| 146 | // copy from our temp DEVMODE struct
|
|---|
| 147 | if (!ep->globalDevMode && hDevMode) {
|
|---|
| 148 | void *src = GlobalLock(hDevMode);
|
|---|
| 149 | memcpy(ep->devMode, src, devModeSize);
|
|---|
| 150 | GlobalUnlock(hDevMode);
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | if (!ep->globalDevMode && hDevMode)
|
|---|
| 155 | GlobalFree(hDevMode);
|
|---|
| 156 | GlobalFree(tempDevNames);
|
|---|
| 157 | done(result);
|
|---|
| 158 | return result;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | void QPageSetupDialog::setVisible(bool visible)
|
|---|
| 162 | {
|
|---|
| 163 | if (!visible)
|
|---|
| 164 | return;
|
|---|
| 165 | exec();
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | QT_END_NAMESPACE
|
|---|
| 169 | #endif
|
|---|