1
/****************************************************************************
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the QtGui module of the Qt Toolkit.
9
** $QT_BEGIN_LICENSE:LGPL$
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file. Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
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.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
40
****************************************************************************/
42
#include "qpagesetupdialog.h"
44
#ifndef QT_NO_PRINTDIALOG
45
#include <qapplication.h>
47
#include <private/qprintengine_win_p.h>
48
#include <private/qabstractpagesetupdialog_p.h>
52
class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate
56
QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
57
: QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent)
61
QPageSetupDialog::QPageSetupDialog(QWidget *parent)
62
: QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), 0, parent)
66
int QPageSetupDialog::exec()
68
Q_D(QPageSetupDialog);
70
if (d->printer->outputFormat() != QPrinter::NativeFormat)
73
QWin32PrintEngine *engine = static_cast<QWin32PrintEngine*>(d->printer->paintEngine());
74
QWin32PrintEnginePrivate *ep = static_cast<QWin32PrintEnginePrivate *>(engine->d_ptr.data());
77
memset(&psd, 0, sizeof(PAGESETUPDLG));
78
psd.lStructSize = sizeof(PAGESETUPDLG);
80
// we need a temp DEVMODE struct if we don't have a global DEVMODE
83
if (!ep->globalDevMode) {
84
devModeSize = sizeof(DEVMODE) + ep->devMode->dmDriverExtra;
85
hDevMode = GlobalAlloc(GHND, devModeSize);
87
void *dest = GlobalLock(hDevMode);
88
memcpy(dest, ep->devMode, devModeSize);
89
GlobalUnlock(hDevMode);
91
psd.hDevMode = hDevMode;
93
psd.hDevMode = ep->devMode;
96
HGLOBAL *tempDevNames = ep->createDevNames();
97
psd.hDevNames = tempDevNames;
99
QWidget *parent = parentWidget();
100
parent = parent ? parent->window() : QApplication::activeWindow();
101
Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));
102
psd.hwndOwner = parent ? parent->winId() : 0;
104
QRect paperRect = d->printer->paperRect();
105
QRect pageRect = d->printer->pageRect();
107
psd.Flags = PSD_MARGINS;
108
double multiplier = 1;
109
switch (QLocale::system().measurementSystem()) {
110
case QLocale::MetricSystem:
111
psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
114
case QLocale::ImperialSystem:
115
psd.Flags |= PSD_INTHOUSANDTHSOFINCHES;
116
multiplier = 25.4/10;
120
QRect marginRect = ep->getPageMargins();
121
psd.rtMargin.left = marginRect.left() / multiplier;
122
psd.rtMargin.top = marginRect.top() / multiplier;
123
psd.rtMargin.right = marginRect.width() / multiplier;;
124
psd.rtMargin.bottom = marginRect.height() / multiplier;;
126
bool result = PageSetupDlg(&psd);
128
ep->readDevnames(psd.hDevNames);
129
ep->readDevmode(psd.hDevMode);
131
QRect theseMargins = QRect(psd.rtMargin.left * multiplier,
132
psd.rtMargin.top * multiplier,
133
psd.rtMargin.right * multiplier,
134
psd.rtMargin.bottom * multiplier);
136
if (theseMargins != marginRect) {
137
ep->setPageMargins(psd.rtMargin.left * multiplier,
138
psd.rtMargin.top * multiplier,
139
psd.rtMargin.right * multiplier,
140
psd.rtMargin.bottom * multiplier);
143
ep->updateCustomPaperSize();
145
// copy from our temp DEVMODE struct
146
if (!ep->globalDevMode && hDevMode) {
147
void *src = GlobalLock(hDevMode);
148
memcpy(ep->devMode, src, devModeSize);
149
GlobalUnlock(hDevMode);
153
if (!ep->globalDevMode && hDevMode)
154
GlobalFree(hDevMode);
155
GlobalFree(tempDevNames);
160
void QPageSetupDialog::setVisible(bool visible)