| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 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 [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QPRINTENGINE_WIN_P_H
|
|---|
| 43 | #define QPRINTENGINE_WIN_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. It exists for the convenience
|
|---|
| 50 | // of other Qt classes. This header file may change from version to
|
|---|
| 51 | // version without notice, or even be removed.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #ifndef QT_NO_PRINTER
|
|---|
| 57 |
|
|---|
| 58 | #include "QtGui/qprinter.h"
|
|---|
| 59 | #include "QtGui/qprintengine.h"
|
|---|
| 60 | #include "QtGui/qpaintengine.h"
|
|---|
| 61 | #include "QtCore/qt_windows.h"
|
|---|
| 62 | #include "private/qpaintengine_alpha_p.h"
|
|---|
| 63 |
|
|---|
| 64 | QT_BEGIN_NAMESPACE
|
|---|
| 65 |
|
|---|
| 66 | class QWin32PrintEnginePrivate;
|
|---|
| 67 | class QPrinterPrivate;
|
|---|
| 68 | class QPainterState;
|
|---|
| 69 |
|
|---|
| 70 | class QWin32PrintEngine : public QAlphaPaintEngine, public QPrintEngine
|
|---|
| 71 | {
|
|---|
| 72 | Q_DECLARE_PRIVATE(QWin32PrintEngine)
|
|---|
| 73 | public:
|
|---|
| 74 | QWin32PrintEngine(QPrinter::PrinterMode mode);
|
|---|
| 75 |
|
|---|
| 76 | // override QWin32PaintEngine
|
|---|
| 77 | bool begin(QPaintDevice *dev);
|
|---|
| 78 | bool end();
|
|---|
| 79 |
|
|---|
| 80 | void updateState(const QPaintEngineState &state);
|
|---|
| 81 |
|
|---|
| 82 | void updateMatrix(const QTransform &matrix);
|
|---|
| 83 | void updateClipPath(const QPainterPath &clip, Qt::ClipOperation op);
|
|---|
| 84 |
|
|---|
| 85 | void drawPath(const QPainterPath &path);
|
|---|
| 86 | void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
|
|---|
| 87 | void drawTextItem(const QPointF &p, const QTextItem &textItem);
|
|---|
| 88 |
|
|---|
| 89 | void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
|
|---|
| 90 | void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p);
|
|---|
| 91 | void setProperty(PrintEnginePropertyKey key, const QVariant &value);
|
|---|
| 92 | QVariant property(PrintEnginePropertyKey key) const;
|
|---|
| 93 |
|
|---|
| 94 | bool newPage();
|
|---|
| 95 | bool abort();
|
|---|
| 96 | int metric(QPaintDevice::PaintDeviceMetric) const;
|
|---|
| 97 |
|
|---|
| 98 | QPrinter::PrinterState printerState() const;
|
|---|
| 99 |
|
|---|
| 100 | QPaintEngine::Type type() const { return Windows; }
|
|---|
| 101 |
|
|---|
| 102 | HDC getDC() const;
|
|---|
| 103 | void releaseDC(HDC) const;
|
|---|
| 104 |
|
|---|
| 105 | HDC getPrinterDC() const { return getDC(); }
|
|---|
| 106 | void releasePrinterDC(HDC dc) const { releaseDC(dc); }
|
|---|
| 107 |
|
|---|
| 108 | private:
|
|---|
| 109 | friend class QPrintDialog;
|
|---|
| 110 | friend class QPageSetupDialog;
|
|---|
| 111 | friend int qt_printerRealNumCopies(QPaintEngine *);
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 | class QWin32PrintEnginePrivate : public QAlphaPaintEnginePrivate
|
|---|
| 115 | {
|
|---|
| 116 | Q_DECLARE_PUBLIC(QWin32PrintEngine)
|
|---|
| 117 | public:
|
|---|
| 118 | QWin32PrintEnginePrivate() :
|
|---|
| 119 | hPrinter(0),
|
|---|
| 120 | globalDevMode(0),
|
|---|
| 121 | devMode(0),
|
|---|
| 122 | pInfo(0),
|
|---|
| 123 | hdc(0),
|
|---|
| 124 | mode(QPrinter::ScreenResolution),
|
|---|
| 125 | state(QPrinter::Idle),
|
|---|
| 126 | resolution(0),
|
|---|
| 127 | pageMarginsSet(false),
|
|---|
| 128 | num_copies(1),
|
|---|
| 129 | printToFile(false),
|
|---|
| 130 | fullPage(false),
|
|---|
| 131 | reinit(false),
|
|---|
| 132 | has_custom_paper_size(false)
|
|---|
| 133 | {
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | ~QWin32PrintEnginePrivate();
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 | /* Reads the default printer name and its driver (printerProgram) into
|
|---|
| 140 | the engines private data. */
|
|---|
| 141 | void queryDefault();
|
|---|
| 142 |
|
|---|
| 143 | /* Initializes the printer data based on the current printer name. This
|
|---|
| 144 | function creates a DEVMODE struct, HDC and a printer handle. If these
|
|---|
| 145 | structures are already in use, they are freed using release
|
|---|
| 146 | */
|
|---|
| 147 | void initialize();
|
|---|
| 148 |
|
|---|
| 149 | /* Initializes data in the print engine whenever the HDC has been renewed
|
|---|
| 150 | */
|
|---|
| 151 | void initHDC();
|
|---|
| 152 |
|
|---|
| 153 | /* Releases all the handles the printer currently holds, HDC, DEVMODE,
|
|---|
| 154 | etc and resets the corresponding members to 0. */
|
|---|
| 155 | void release();
|
|---|
| 156 |
|
|---|
| 157 | /* Queries the resolutions for the current printer, and returns them
|
|---|
| 158 | in a list. */
|
|---|
| 159 | QList<QVariant> queryResolutions() const;
|
|---|
| 160 |
|
|---|
| 161 | /* Resets the DC with changes in devmode. If the printer is active
|
|---|
| 162 | this function only sets the reinit variable to true so it
|
|---|
| 163 | is handled in the next begin or newpage. */
|
|---|
| 164 | void doReinit();
|
|---|
| 165 |
|
|---|
| 166 | /* Used by print/page setup dialogs */
|
|---|
| 167 | HGLOBAL *createDevNames();
|
|---|
| 168 |
|
|---|
| 169 | void readDevmode(HGLOBAL globalDevmode);
|
|---|
| 170 | void readDevnames(HGLOBAL globalDevnames);
|
|---|
| 171 |
|
|---|
| 172 | inline DEVMODEW *devModeW() const { return (DEVMODEW*) devMode; }
|
|---|
| 173 | inline DEVMODEA *devModeA() const { return (DEVMODEA*) devMode; }
|
|---|
| 174 |
|
|---|
| 175 | inline PRINTER_INFO_2W *pInfoW() { return (PRINTER_INFO_2W*) pInfo; };
|
|---|
| 176 | inline PRINTER_INFO_2A *pInfoA() { return (PRINTER_INFO_2A*) pInfo; };
|
|---|
| 177 |
|
|---|
| 178 | inline bool resetDC() {
|
|---|
| 179 | QT_WA( {
|
|---|
| 180 | hdc = ResetDCW(hdc, devModeW());
|
|---|
| 181 | }, {
|
|---|
| 182 | hdc = ResetDCA(hdc, devModeA());
|
|---|
| 183 | } );
|
|---|
| 184 | return hdc != 0;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | void strokePath(const QPainterPath &path, const QColor &color);
|
|---|
| 188 | void fillPath(const QPainterPath &path, const QColor &color);
|
|---|
| 189 |
|
|---|
| 190 | void composeGdiPath(const QPainterPath &path);
|
|---|
| 191 | void fillPath_dev(const QPainterPath &path, const QColor &color);
|
|---|
| 192 | void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width);
|
|---|
| 193 |
|
|---|
| 194 | void updateOrigin();
|
|---|
| 195 |
|
|---|
| 196 | void initDevRects();
|
|---|
| 197 | void setPageMargins(int margin_left, int margin_top, int margin_right, int margin_bottom);
|
|---|
| 198 | QRect getPageMargins() const;
|
|---|
| 199 | void updateCustomPaperSize();
|
|---|
| 200 |
|
|---|
| 201 | // Windows GDI printer references.
|
|---|
| 202 | HANDLE hPrinter;
|
|---|
| 203 |
|
|---|
| 204 | HGLOBAL globalDevMode;
|
|---|
| 205 | void *devMode;
|
|---|
| 206 | void *pInfo;
|
|---|
| 207 | HGLOBAL hMem;
|
|---|
| 208 |
|
|---|
| 209 | HDC hdc;
|
|---|
| 210 |
|
|---|
| 211 | QPrinter::PrinterMode mode;
|
|---|
| 212 |
|
|---|
| 213 | // Printer info
|
|---|
| 214 | QString name;
|
|---|
| 215 | QString program;
|
|---|
| 216 | QString port;
|
|---|
| 217 |
|
|---|
| 218 | // Document info
|
|---|
| 219 | QString docName;
|
|---|
| 220 | QString fileName;
|
|---|
| 221 |
|
|---|
| 222 | QPrinter::PrinterState state;
|
|---|
| 223 | int resolution;
|
|---|
| 224 |
|
|---|
| 225 | // This QRect is used to store the exact values
|
|---|
| 226 | // entered into the PageSetup Dialog because those are
|
|---|
| 227 | // entered in mm but are since converted to device coordinates.
|
|---|
| 228 | // If they were to be converted back when displaying the dialog
|
|---|
| 229 | // again, there would be inaccuracies so when the user entered 10
|
|---|
| 230 | // it may show up as 9.99 the next time the dialog is opened.
|
|---|
| 231 | // We don't want that confusion.
|
|---|
| 232 | QRect previousDialogMargins;
|
|---|
| 233 |
|
|---|
| 234 | bool pageMarginsSet;
|
|---|
| 235 | QRect devPageRect;
|
|---|
| 236 | QRect devPhysicalPageRect;
|
|---|
| 237 | QRect devPaperRect;
|
|---|
| 238 | qreal stretch_x;
|
|---|
| 239 | qreal stretch_y;
|
|---|
| 240 | int origin_x;
|
|---|
| 241 | int origin_y;
|
|---|
| 242 |
|
|---|
| 243 | int dpi_x;
|
|---|
| 244 | int dpi_y;
|
|---|
| 245 | int dpi_display;
|
|---|
| 246 | int num_copies;
|
|---|
| 247 |
|
|---|
| 248 | uint printToFile : 1;
|
|---|
| 249 | uint fullPage : 1;
|
|---|
| 250 | uint reinit : 1;
|
|---|
| 251 |
|
|---|
| 252 | uint complex_xform : 1;
|
|---|
| 253 | uint has_pen : 1;
|
|---|
| 254 | uint has_brush : 1;
|
|---|
| 255 | uint has_custom_paper_size : 1;
|
|---|
| 256 |
|
|---|
| 257 | uint txop;
|
|---|
| 258 |
|
|---|
| 259 | QColor brush_color;
|
|---|
| 260 | QPen pen;
|
|---|
| 261 | QColor pen_color;
|
|---|
| 262 | QSizeF paper_size;
|
|---|
| 263 |
|
|---|
| 264 | QTransform painterMatrix;
|
|---|
| 265 | QTransform matrix;
|
|---|
| 266 | };
|
|---|
| 267 |
|
|---|
| 268 | QT_END_NAMESPACE
|
|---|
| 269 |
|
|---|
| 270 | #endif // QT_NO_PRINTER
|
|---|
| 271 |
|
|---|
| 272 | #endif // QPRINTENGINE_WIN_P_H
|
|---|