Replace 'i < len-1 && func(i+1)' by 'i+1 < len && func(i+1)'
[profile/ivi/qtbase.git] / src / gui / painting / qprintengine_win_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
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 };
112
113 class QWin32PrintEnginePrivate : public QAlphaPaintEnginePrivate
114 {
115     Q_DECLARE_PUBLIC(QWin32PrintEngine)
116 public:
117     QWin32PrintEnginePrivate() :
118         hPrinter(0),
119         globalDevMode(0),
120         devMode(0),
121         pInfo(0),
122         hdc(0),
123         mode(QPrinter::ScreenResolution),
124         state(QPrinter::Idle),
125         resolution(0),
126         pageMarginsSet(false),
127         num_copies(1),
128         printToFile(false),
129         fullPage(false),
130         reinit(false),
131         has_custom_paper_size(false)
132     {
133     }
134
135     ~QWin32PrintEnginePrivate();
136
137
138     /* Reads the default printer name and its driver (printerProgram) into
139        the engines private data. */
140     void queryDefault();
141
142     /* Initializes the printer data based on the current printer name. This
143        function creates a DEVMODE struct, HDC and a printer handle. If these
144        structures are already in use, they are freed using release
145     */
146     void initialize();
147
148     /* Initializes data in the print engine whenever the HDC has been renewed
149     */
150     void initHDC();
151
152     /* Releases all the handles the printer currently holds, HDC, DEVMODE,
153        etc and resets the corresponding members to 0. */
154     void release();
155
156     /* Queries the resolutions for the current printer, and returns them
157        in a list. */
158     QList<QVariant> queryResolutions() const;
159
160     /* Resets the DC with changes in devmode. If the printer is active
161        this function only sets the reinit variable to true so it
162        is handled in the next begin or newpage. */
163     void doReinit();
164
165     /* Used by print/page setup dialogs */
166     HGLOBAL *createDevNames();
167
168     void readDevmode(HGLOBAL globalDevmode);
169     void readDevnames(HGLOBAL globalDevnames);
170
171     inline bool resetDC() {
172         hdc = ResetDC(hdc, devMode);
173         return hdc != 0;
174     }
175
176     void strokePath(const QPainterPath &path, const QColor &color);
177     void fillPath(const QPainterPath &path, const QColor &color);
178
179     void composeGdiPath(const QPainterPath &path);
180     void fillPath_dev(const QPainterPath &path, const QColor &color);
181     void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width);
182
183     void updateOrigin();
184
185     void initDevRects();
186     void setPageMargins(int margin_left, int margin_top, int margin_right, int margin_bottom);
187     QRect getPageMargins() const;
188     void updateCustomPaperSize();
189
190     // Windows GDI printer references.
191     HANDLE hPrinter;
192
193     HGLOBAL globalDevMode;
194     DEVMODE *devMode;
195     PRINTER_INFO_2 *pInfo;
196     HGLOBAL hMem;
197
198     HDC hdc;
199
200     QPrinter::PrinterMode mode;
201
202     // Printer info
203     QString name;
204     QString program;
205     QString port;
206
207     // Document info
208     QString docName;
209     QString fileName;
210
211     QPrinter::PrinterState state;
212     int resolution;
213
214     // This QRect is used to store the exact values
215     // entered into the PageSetup Dialog because those are
216     // entered in mm but are since converted to device coordinates.
217     // If they were to be converted back when displaying the dialog
218     // again, there would be inaccuracies so when the user entered 10
219     // it may show up as 9.99 the next time the dialog is opened.
220     // We don't want that confusion.
221     QRect previousDialogMargins;
222
223     bool pageMarginsSet;
224     QRect devPageRect;
225     QRect devPhysicalPageRect;
226     QRect devPaperRect;
227     qreal stretch_x;
228     qreal stretch_y;
229     int origin_x;
230     int origin_y;
231
232     int dpi_x;
233     int dpi_y;
234     int dpi_display;
235     int num_copies;
236
237     uint printToFile : 1;
238     uint fullPage : 1;
239     uint reinit : 1;
240
241     uint complex_xform : 1;
242     uint has_pen : 1;
243     uint has_brush : 1;
244     uint has_custom_paper_size : 1;
245
246     uint txop;
247
248     QColor brush_color;
249     QPen pen;
250     QColor pen_color;
251     QSizeF paper_size;
252
253     QTransform painterMatrix;
254     QTransform matrix;
255 };
256
257 QT_END_NAMESPACE
258
259 #endif // QT_NO_PRINTER
260
261 #endif // QPRINTENGINE_WIN_P_H