|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
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 |
|
14 ** this package. |
|
15 ** |
|
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. |
|
23 ** |
|
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. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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.data()); |
|
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 = 0; |
|
82 int devModeSize = 0; |
|
83 if (!ep->globalDevMode) { |
|
84 devModeSize = sizeof(DEVMODE) + ep->devMode->dmDriverExtra; |
|
85 hDevMode = GlobalAlloc(GHND, devModeSize); |
|
86 if (hDevMode) { |
|
87 void *dest = GlobalLock(hDevMode); |
|
88 memcpy(dest, ep->devMode, devModeSize); |
|
89 GlobalUnlock(hDevMode); |
|
90 } |
|
91 psd.hDevMode = hDevMode; |
|
92 } else { |
|
93 psd.hDevMode = ep->devMode; |
|
94 } |
|
95 |
|
96 HGLOBAL *tempDevNames = ep->createDevNames(); |
|
97 psd.hDevNames = tempDevNames; |
|
98 |
|
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; |
|
103 |
|
104 QRect paperRect = d->printer->paperRect(); |
|
105 QRect pageRect = d->printer->pageRect(); |
|
106 |
|
107 psd.Flags = PSD_MARGINS; |
|
108 double multiplier = 1; |
|
109 switch (QLocale::system().measurementSystem()) { |
|
110 case QLocale::MetricSystem: |
|
111 psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; |
|
112 multiplier = 1; |
|
113 break; |
|
114 case QLocale::ImperialSystem: |
|
115 psd.Flags |= PSD_INTHOUSANDTHSOFINCHES; |
|
116 multiplier = 25.4/10; |
|
117 break; |
|
118 } |
|
119 |
|
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;; |
|
125 |
|
126 bool result = PageSetupDlg(&psd); |
|
127 if (result) { |
|
128 ep->readDevnames(psd.hDevNames); |
|
129 ep->readDevmode(psd.hDevMode); |
|
130 |
|
131 QRect theseMargins = QRect(psd.rtMargin.left * multiplier, |
|
132 psd.rtMargin.top * multiplier, |
|
133 psd.rtMargin.right * multiplier, |
|
134 psd.rtMargin.bottom * multiplier); |
|
135 |
|
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); |
|
141 } |
|
142 |
|
143 ep->updateCustomPaperSize(); |
|
144 |
|
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); |
|
150 } |
|
151 } |
|
152 |
|
153 if (!ep->globalDevMode && hDevMode) |
|
154 GlobalFree(hDevMode); |
|
155 GlobalFree(tempDevNames); |
|
156 done(result); |
|
157 return result; |
|
158 } |
|
159 |
|
160 void QPageSetupDialog::setVisible(bool visible) |
|
161 { |
|
162 if (!visible) |
|
163 return; |
|
164 exec(); |
|
165 } |
|
166 |
|
167 QT_END_NAMESPACE |
|
168 #endif |