1 | /****************************************************************************
|
---|
2 | ** $Id: qpaintdevice.h 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Definition of QPaintDevice class
|
---|
5 | **
|
---|
6 | ** Created : 940721
|
---|
7 | **
|
---|
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
---|
9 | **
|
---|
10 | ** This file is part of the kernel module of the Qt GUI Toolkit.
|
---|
11 | **
|
---|
12 | ** This file may be distributed under the terms of the Q Public License
|
---|
13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
15 | **
|
---|
16 | ** This file may be distributed and/or modified under the terms of the
|
---|
17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
19 | ** packaging of this file.
|
---|
20 | **
|
---|
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
22 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
23 | ** Agreement provided with the Software.
|
---|
24 | **
|
---|
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
27 | **
|
---|
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
29 | ** information about Qt Commercial License Agreements.
|
---|
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
32 | **
|
---|
33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
34 | ** not clear to you.
|
---|
35 | **
|
---|
36 | **********************************************************************/
|
---|
37 |
|
---|
38 | #ifndef QPAINTDEVICE_H
|
---|
39 | #define QPAINTDEVICE_H
|
---|
40 |
|
---|
41 | #ifndef QT_H
|
---|
42 | #include "qwindowdefs.h"
|
---|
43 | #include "qrect.h"
|
---|
44 | #endif // QT_H
|
---|
45 |
|
---|
46 | #if defined(Q_WS_QWS)
|
---|
47 | class QWSDisplay;
|
---|
48 | class QGfx;
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | class QIODevice;
|
---|
52 | class QString;
|
---|
53 | class QTextItem;
|
---|
54 |
|
---|
55 |
|
---|
56 | #if defined(Q_WS_X11)
|
---|
57 | struct QPaintDeviceX11Data;
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | union QPDevCmdParam {
|
---|
61 | int ival;
|
---|
62 | int *ivec;
|
---|
63 | QString *str;
|
---|
64 | const QPoint *point;
|
---|
65 | const QRect *rect;
|
---|
66 | const QPointArray *ptarr;
|
---|
67 | const QPixmap *pixmap;
|
---|
68 | const QImage *image;
|
---|
69 | const QColor *color;
|
---|
70 | const QFont *font;
|
---|
71 | const QPen *pen;
|
---|
72 | const QBrush *brush;
|
---|
73 | const QRegion *rgn;
|
---|
74 | const QWMatrix *matrix;
|
---|
75 | const QTextItem *textItem;
|
---|
76 | QIODevice *device;
|
---|
77 | };
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 | class Q_EXPORT QPaintDevice // device for QPainter
|
---|
82 | {
|
---|
83 | public:
|
---|
84 | virtual ~QPaintDevice();
|
---|
85 |
|
---|
86 | int devType() const;
|
---|
87 | bool isExtDev() const;
|
---|
88 | bool paintingActive() const;
|
---|
89 |
|
---|
90 | virtual void setResolution( int );
|
---|
91 | virtual int resolution() const;
|
---|
92 |
|
---|
93 | // Windows: get device context
|
---|
94 | // X-Windows: get drawable
|
---|
95 | #if defined(Q_WS_WIN)
|
---|
96 | virtual HDC handle() const;
|
---|
97 | #elif defined(Q_WS_X11)
|
---|
98 | virtual Qt::HANDLE handle() const;
|
---|
99 | virtual Qt::HANDLE x11RenderHandle() const;
|
---|
100 | #elif defined(Q_WS_MAC)
|
---|
101 | virtual Qt::HANDLE handle() const;
|
---|
102 | #elif defined(Q_WS_QWS)
|
---|
103 | virtual Qt::HANDLE handle() const;
|
---|
104 | #endif
|
---|
105 |
|
---|
106 | #if defined(Q_WS_X11)
|
---|
107 | Display *x11Display() const;
|
---|
108 | int x11Screen() const;
|
---|
109 | int x11Depth() const;
|
---|
110 | int x11Cells() const;
|
---|
111 | Qt::HANDLE x11Colormap() const;
|
---|
112 | bool x11DefaultColormap() const;
|
---|
113 | void *x11Visual() const;
|
---|
114 | bool x11DefaultVisual() const;
|
---|
115 |
|
---|
116 | static Display *x11AppDisplay();
|
---|
117 | static int x11AppScreen();
|
---|
118 |
|
---|
119 | static int x11AppDpiX();
|
---|
120 | static int x11AppDpiY();
|
---|
121 | static void x11SetAppDpiX(int);
|
---|
122 | static void x11SetAppDpiY(int);
|
---|
123 | static int x11AppDepth();
|
---|
124 | static int x11AppCells();
|
---|
125 | static Qt::HANDLE x11AppRootWindow();
|
---|
126 | static Qt::HANDLE x11AppColormap();
|
---|
127 | static bool x11AppDefaultColormap();
|
---|
128 | static void *x11AppVisual();
|
---|
129 | static bool x11AppDefaultVisual();
|
---|
130 |
|
---|
131 | // ### in 4.0, the above need to go away, the below needs to take a -1 default
|
---|
132 | // argument, signifying the default screen...
|
---|
133 | static int x11AppDepth( int screen );
|
---|
134 | static int x11AppCells( int screen );
|
---|
135 | static Qt::HANDLE x11AppRootWindow( int screen );
|
---|
136 | static Qt::HANDLE x11AppColormap( int screen );
|
---|
137 | static void *x11AppVisual( int screen );
|
---|
138 | static bool x11AppDefaultColormap( int screen );
|
---|
139 | static bool x11AppDefaultVisual( int screen );
|
---|
140 | static int x11AppDpiX( int );
|
---|
141 | static int x11AppDpiY( int );
|
---|
142 | static void x11SetAppDpiX( int, int );
|
---|
143 | static void x11SetAppDpiY( int, int );
|
---|
144 | #endif
|
---|
145 |
|
---|
146 | #if defined(Q_WS_QWS)
|
---|
147 | static QWSDisplay *qwsDisplay();
|
---|
148 | virtual unsigned char * scanLine(int) const;
|
---|
149 | virtual int bytesPerLine() const;
|
---|
150 | virtual QGfx * graphicsContext(bool clip_children=TRUE) const;
|
---|
151 | #endif
|
---|
152 |
|
---|
153 | enum PDevCmd {
|
---|
154 | PdcNOP = 0, // <void>
|
---|
155 | PdcDrawPoint = 1, // point
|
---|
156 | PdcDrawFirst = PdcDrawPoint,
|
---|
157 | PdcMoveTo = 2, // point
|
---|
158 | PdcLineTo = 3, // point
|
---|
159 | PdcDrawLine = 4, // point,point
|
---|
160 | PdcDrawRect = 5, // rect
|
---|
161 | PdcDrawRoundRect = 6, // rect,ival,ival
|
---|
162 | PdcDrawEllipse = 7, // rect
|
---|
163 | PdcDrawArc = 8, // rect,ival,ival
|
---|
164 | PdcDrawPie = 9, // rect,ival,ival
|
---|
165 | PdcDrawChord = 10, // rect,ival,ival
|
---|
166 | PdcDrawLineSegments = 11, // ptarr
|
---|
167 | PdcDrawPolyline = 12, // ptarr
|
---|
168 | PdcDrawPolygon = 13, // ptarr,ival
|
---|
169 | PdcDrawCubicBezier = 14, // ptarr
|
---|
170 | PdcDrawText = 15, // point,str
|
---|
171 | PdcDrawTextFormatted = 16, // rect,ival,str
|
---|
172 | PdcDrawPixmap = 17, // rect,pixmap
|
---|
173 | PdcDrawImage = 18, // rect,image
|
---|
174 | PdcDrawText2 = 19, // point,str
|
---|
175 | PdcDrawText2Formatted = 20, // rect,ival,str
|
---|
176 | PdcDrawTextItem = 21,
|
---|
177 | PdcDrawLast = PdcDrawTextItem,
|
---|
178 |
|
---|
179 | // no painting commands below PdcDrawLast.
|
---|
180 |
|
---|
181 | PdcBegin = 30, // <void>
|
---|
182 | PdcEnd = 31, // <void>
|
---|
183 | PdcSave = 32, // <void>
|
---|
184 | PdcRestore = 33, // <void>
|
---|
185 | PdcSetdev = 34, // device - PRIVATE
|
---|
186 | PdcSetBkColor = 40, // color
|
---|
187 | PdcSetBkMode = 41, // ival
|
---|
188 | PdcSetROP = 42, // ival
|
---|
189 | PdcSetBrushOrigin = 43, // point
|
---|
190 | PdcSetFont = 45, // font
|
---|
191 | PdcSetPen = 46, // pen
|
---|
192 | PdcSetBrush = 47, // brush
|
---|
193 | PdcSetTabStops = 48, // ival
|
---|
194 | PdcSetTabArray = 49, // ival,ivec
|
---|
195 | PdcSetUnit = 50, // ival
|
---|
196 | PdcSetVXform = 51, // ival
|
---|
197 | PdcSetWindow = 52, // rect
|
---|
198 | PdcSetViewport = 53, // rect
|
---|
199 | PdcSetWXform = 54, // ival
|
---|
200 | PdcSetWMatrix = 55, // matrix,ival
|
---|
201 | PdcSaveWMatrix = 56,
|
---|
202 | PdcRestoreWMatrix = 57,
|
---|
203 | PdcSetClip = 60, // ival
|
---|
204 | PdcSetClipRegion = 61, // rgn
|
---|
205 |
|
---|
206 | PdcReservedStart = 0, // codes 0-199 are reserved
|
---|
207 | PdcReservedStop = 199 // for Qt
|
---|
208 | };
|
---|
209 |
|
---|
210 | protected:
|
---|
211 | QPaintDevice( uint devflags );
|
---|
212 |
|
---|
213 | #if defined(Q_WS_WIN)
|
---|
214 | HDC hdc; // device context
|
---|
215 | #elif defined(Q_WS_X11)
|
---|
216 | Qt::HANDLE hd; // handle to drawable
|
---|
217 | Qt::HANDLE rendhd; // handle to RENDER pict
|
---|
218 |
|
---|
219 | void copyX11Data( const QPaintDevice * );
|
---|
220 | void cloneX11Data( const QPaintDevice * );
|
---|
221 | virtual void setX11Data( const QPaintDeviceX11Data* );
|
---|
222 | QPaintDeviceX11Data* getX11Data( bool def=FALSE ) const;
|
---|
223 | #elif defined(Q_WS_MAC)
|
---|
224 | #if !defined( QMAC_NO_QUARTZ )
|
---|
225 | CGContextRef ctx;
|
---|
226 | #endif
|
---|
227 | void * hd;
|
---|
228 | #elif defined(Q_WS_QWS)
|
---|
229 | Qt::HANDLE hd;
|
---|
230 | #endif
|
---|
231 |
|
---|
232 | virtual bool cmd( int, QPainter *, QPDevCmdParam * );
|
---|
233 | virtual int metric( int ) const;
|
---|
234 | virtual int fontMet( QFont *, int, const char * = 0, int = 0 ) const;
|
---|
235 | virtual int fontInf( QFont *, int ) const;
|
---|
236 |
|
---|
237 | ushort devFlags; // device flags
|
---|
238 | ushort painters; // refcount
|
---|
239 |
|
---|
240 | friend class QPainter;
|
---|
241 | friend class QPaintDeviceMetrics;
|
---|
242 | #if defined(Q_WS_MAC)
|
---|
243 | #ifndef QMAC_NO_QUARTZ
|
---|
244 | virtual CGContextRef macCGContext(bool clipped=TRUE) const;
|
---|
245 | #endif
|
---|
246 | friend Q_EXPORT void unclippedScaledBitBlt( QPaintDevice *, int, int, int, int,
|
---|
247 | const QPaintDevice *, int, int, int, int, Qt::RasterOp, bool, bool );
|
---|
248 | #else
|
---|
249 | friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
|
---|
250 | const QPaintDevice *,
|
---|
251 | int, int, int, int, Qt::RasterOp, bool );
|
---|
252 | #endif
|
---|
253 | #if defined(Q_WS_X11)
|
---|
254 | friend void qt_init_internal( int *, char **, Display *, Qt::HANDLE, Qt::HANDLE );
|
---|
255 | friend void qt_cleanup();
|
---|
256 | #endif
|
---|
257 |
|
---|
258 | private:
|
---|
259 | #if defined(Q_WS_X11)
|
---|
260 | static Display *x_appdisplay;
|
---|
261 | static int x_appscreen;
|
---|
262 |
|
---|
263 | static int x_appdepth;
|
---|
264 | static int x_appcells;
|
---|
265 | static Qt::HANDLE x_approotwindow;
|
---|
266 | static Qt::HANDLE x_appcolormap;
|
---|
267 | static bool x_appdefcolormap;
|
---|
268 | static void *x_appvisual;
|
---|
269 | static bool x_appdefvisual;
|
---|
270 |
|
---|
271 | // ### in 4.0, remove the above, and replace with the below
|
---|
272 | static int *x_appdepth_arr;
|
---|
273 | static int *x_appcells_arr;
|
---|
274 | static Qt::HANDLE *x_approotwindow_arr;
|
---|
275 | static Qt::HANDLE *x_appcolormap_arr;
|
---|
276 | static bool *x_appdefcolormap_arr;
|
---|
277 | static void **x_appvisual_arr;
|
---|
278 | static bool *x_appdefvisual_arr;
|
---|
279 |
|
---|
280 | QPaintDeviceX11Data* x11Data;
|
---|
281 | #endif
|
---|
282 |
|
---|
283 | private: // Disabled copy constructor and operator=
|
---|
284 | #if defined(Q_DISABLE_COPY)
|
---|
285 | QPaintDevice( const QPaintDevice & );
|
---|
286 | QPaintDevice &operator=( const QPaintDevice & );
|
---|
287 | #endif
|
---|
288 | };
|
---|
289 |
|
---|
290 |
|
---|
291 | Q_EXPORT
|
---|
292 | void bitBlt( QPaintDevice *dst, int dx, int dy,
|
---|
293 | const QPaintDevice *src, int sx=0, int sy=0, int sw=-1, int sh=-1,
|
---|
294 | Qt::RasterOp = Qt::CopyROP, bool ignoreMask=FALSE );
|
---|
295 |
|
---|
296 | Q_EXPORT
|
---|
297 | void bitBlt( QPaintDevice *dst, int dx, int dy,
|
---|
298 | const QImage *src, int sx=0, int sy=0, int sw=-1, int sh=-1,
|
---|
299 | int conversion_flags=0 );
|
---|
300 |
|
---|
301 |
|
---|
302 | #if defined(Q_WS_X11)
|
---|
303 |
|
---|
304 | struct Q_EXPORT QPaintDeviceX11Data : public QShared {
|
---|
305 | Display* x_display;
|
---|
306 | int x_screen;
|
---|
307 | int x_depth;
|
---|
308 | int x_cells;
|
---|
309 | Qt::HANDLE x_colormap;
|
---|
310 | bool x_defcolormap;
|
---|
311 | void* x_visual;
|
---|
312 | bool x_defvisual;
|
---|
313 | };
|
---|
314 |
|
---|
315 | #endif
|
---|
316 |
|
---|
317 | /*****************************************************************************
|
---|
318 | Inline functions
|
---|
319 | *****************************************************************************/
|
---|
320 |
|
---|
321 | inline int QPaintDevice::devType() const
|
---|
322 | { return devFlags & QInternal::DeviceTypeMask; }
|
---|
323 |
|
---|
324 | inline bool QPaintDevice::isExtDev() const
|
---|
325 | { return (devFlags & QInternal::ExternalDevice) != 0; }
|
---|
326 |
|
---|
327 | inline bool QPaintDevice::paintingActive() const
|
---|
328 | { return painters != 0; }
|
---|
329 |
|
---|
330 | #if defined(Q_WS_X11)
|
---|
331 | inline Display *QPaintDevice::x11Display() const
|
---|
332 | { return x11Data ? x11Data->x_display : x_appdisplay; }
|
---|
333 |
|
---|
334 | inline int QPaintDevice::x11Screen() const
|
---|
335 | { return x11Data ? x11Data->x_screen : x_appscreen; }
|
---|
336 |
|
---|
337 | inline int QPaintDevice::x11Depth() const
|
---|
338 | { return x11Data ? x11Data->x_depth : x_appdepth; }
|
---|
339 |
|
---|
340 | inline int QPaintDevice::x11Cells() const
|
---|
341 | { return x11Data ? x11Data->x_cells : x_appcells; }
|
---|
342 |
|
---|
343 | inline Qt::HANDLE QPaintDevice::x11Colormap() const
|
---|
344 | { return x11Data ? x11Data->x_colormap : x_appcolormap; }
|
---|
345 |
|
---|
346 | inline bool QPaintDevice::x11DefaultColormap() const
|
---|
347 | { return x11Data ? x11Data->x_defcolormap : x_appdefcolormap; }
|
---|
348 |
|
---|
349 | inline void *QPaintDevice::x11Visual() const
|
---|
350 | { return x11Data ? x11Data->x_visual : x_appvisual; }
|
---|
351 |
|
---|
352 | inline bool QPaintDevice::x11DefaultVisual() const
|
---|
353 | { return x11Data ? x11Data->x_defvisual : x_appdefvisual; }
|
---|
354 |
|
---|
355 | inline Display *QPaintDevice::x11AppDisplay()
|
---|
356 | { return x_appdisplay; }
|
---|
357 |
|
---|
358 | inline int QPaintDevice::x11AppScreen()
|
---|
359 | { return x_appscreen; }
|
---|
360 |
|
---|
361 | inline int QPaintDevice::x11AppDepth( int screen )
|
---|
362 | { return x_appdepth_arr[ screen == -1 ? x_appscreen : screen ]; }
|
---|
363 |
|
---|
364 | inline int QPaintDevice::x11AppCells( int screen )
|
---|
365 | { return x_appcells_arr[ screen == -1 ? x_appscreen : screen ]; }
|
---|
366 |
|
---|
367 | inline Qt::HANDLE QPaintDevice::x11AppRootWindow( int screen )
|
---|
368 | { return x_approotwindow_arr[ screen == -1 ? x_appscreen : screen ]; }
|
---|
369 |
|
---|
370 | inline Qt::HANDLE QPaintDevice::x11AppColormap( int screen )
|
---|
371 | { return x_appcolormap_arr[ screen == -1 ? x_appscreen : screen ]; }
|
---|
372 |
|
---|
373 | inline bool QPaintDevice::x11AppDefaultColormap( int screen )
|
---|
374 | { return x_appdefcolormap_arr[ screen == -1 ? x_appscreen : screen ]; }
|
---|
375 |
|
---|
376 | inline void *QPaintDevice::x11AppVisual( int screen )
|
---|
377 | { return x_appvisual_arr[ screen == -1 ? x_appscreen : screen ]; }
|
---|
378 |
|
---|
379 | inline bool QPaintDevice::x11AppDefaultVisual( int screen )
|
---|
380 | { return x_appdefvisual_arr[ screen == -1 ? x_appscreen : screen ]; }
|
---|
381 |
|
---|
382 | inline int QPaintDevice::x11AppDepth()
|
---|
383 | { return x_appdepth; }
|
---|
384 |
|
---|
385 | inline int QPaintDevice::x11AppCells()
|
---|
386 | { return x_appcells; }
|
---|
387 |
|
---|
388 | inline Qt::HANDLE QPaintDevice::x11AppRootWindow()
|
---|
389 | { return x_approotwindow; }
|
---|
390 |
|
---|
391 | inline Qt::HANDLE QPaintDevice::x11AppColormap()
|
---|
392 | { return x_appcolormap; }
|
---|
393 |
|
---|
394 | inline bool QPaintDevice::x11AppDefaultColormap()
|
---|
395 | { return x_appdefcolormap; }
|
---|
396 |
|
---|
397 | inline void *QPaintDevice::x11AppVisual()
|
---|
398 | { return x_appvisual; }
|
---|
399 |
|
---|
400 | inline bool QPaintDevice::x11AppDefaultVisual()
|
---|
401 | { return x_appdefvisual; }
|
---|
402 |
|
---|
403 | #endif // Q_WS_X11
|
---|
404 |
|
---|
405 |
|
---|
406 | Q_EXPORT
|
---|
407 | inline void bitBlt( QPaintDevice *dst, const QPoint &dp,
|
---|
408 | const QPaintDevice *src, const QRect &sr =QRect(0,0,-1,-1),
|
---|
409 | Qt::RasterOp rop=Qt::CopyROP, bool ignoreMask=FALSE )
|
---|
410 | {
|
---|
411 | bitBlt( dst, dp.x(), dp.y(), src, sr.x(), sr.y(), sr.width(), sr.height(),
|
---|
412 | rop, ignoreMask );
|
---|
413 | }
|
---|
414 |
|
---|
415 |
|
---|
416 |
|
---|
417 |
|
---|
418 | #endif // QPAINTDEVICE_H
|
---|