4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/wingdi16.h"
30 /* GDI objects magic numbers */
31 #define FIRST_MAGIC 0x4f47
32 #define PEN_MAGIC 0x4f47
33 #define BRUSH_MAGIC 0x4f48
34 #define FONT_MAGIC 0x4f49
35 #define PALETTE_MAGIC 0x4f4a
36 #define BITMAP_MAGIC 0x4f4b
37 #define REGION_MAGIC 0x4f4c
38 #define DC_MAGIC 0x4f4d
39 #define DISABLED_DC_MAGIC 0x4f4e
40 #define META_DC_MAGIC 0x4f4f
41 #define METAFILE_MAGIC 0x4f50
42 #define METAFILE_DC_MAGIC 0x4f51
43 #define ENHMETAFILE_MAGIC 0x4f52
44 #define ENHMETAFILE_DC_MAGIC 0x4f53
45 #define LAST_MAGIC 0x4f53
47 #define MAGIC_DONTCARE 0xffff
49 /* GDI constants for making objects private/system (naming undoc. !) */
50 #define OBJECT_PRIVATE 0x2000
51 #define OBJECT_NOSYSTEM 0x8000
53 #define GDIMAGIC(magic) ((magic) & ~(OBJECT_PRIVATE|OBJECT_NOSYSTEM))
55 typedef struct tagGDIOBJHDR
63 typedef struct tagGdiFont
*GdiFont
;
68 HDC hSelf
; /* Handle to this DC */
69 const struct tagDC_FUNCS
*funcs
; /* DC function table */
70 void *physDev
; /* Physical device (driver-specific) */
73 FARPROC16 hookProc
; /* the original SEGPTR ... */
74 DCHOOKPROC hookThunk
; /* ... and the thunk to call it */
76 INT wndOrgX
; /* Window origin */
78 INT wndExtX
; /* Window extent */
80 INT vportOrgX
; /* Viewport origin */
82 INT vportExtX
; /* Viewport extent */
86 HRGN16 hClipRgn
; /* Clip region (may be 0) */
87 HRGN16 hVisRgn
; /* Visible region (must never be 0) */
88 HRGN16 hGCClipRgn
; /* GC clip region (ClipRgn AND VisRgn) */
104 COLORREF backgroundColor
;
109 WORD textAlign
; /* Text alignment from SetTextAlign() */
110 short charExtra
; /* Spacing from SetTextCharacterExtra() */
111 short breakTotalExtra
; /* Total extra space for justification */
112 short breakCount
; /* Break char. count */
113 short breakExtra
; /* breakTotalExtra / breakCount */
114 short breakRem
; /* breakTotalExtra % breakCount */
120 INT GraphicsMode
; /* Graphics mode */
121 INT DCOrgX
; /* DC origin */
123 ABORTPROC pAbortProc
; /* AbortProc for Printing */
124 ABORTPROC16 pAbortProc16
;
125 INT CursPosX
; /* Current position */
128 XFORM xformWorld2Wnd
; /* World-to-window transformation */
129 XFORM xformWorld2Vport
; /* World-to-viewport transformation */
130 XFORM xformVport2World
; /* Inverse of the above transformation */
131 BOOL vport2WorldValid
; /* Is xformVport2World valid? */
134 /* Device functions for the Wine driver interface */
136 typedef INT (*DEVICEFONTENUMPROC
)(LPENUMLOGFONTEXW
,LPNEWTEXTMETRICEXW
,DWORD
,
139 typedef struct tagDC_FUNCS
141 INT (*pAbortDoc
)(DC
*);
142 BOOL (*pAbortPath
)(DC
*);
143 BOOL (*pAngleArc
)(DC
*,INT
,INT
,DWORD
,FLOAT
,FLOAT
);
144 BOOL (*pArc
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
145 BOOL (*pArcTo
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
146 BOOL (*pBeginPath
)(DC
*);
147 BOOL (*pBitBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,DWORD
);
148 LONG (*pBitmapBits
)(HBITMAP
,void*,LONG
,WORD
);
149 INT (*pChoosePixelFormat
)(DC
*,const PIXELFORMATDESCRIPTOR
*);
150 BOOL (*pChord
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
151 BOOL (*pCloseFigure
)(DC
*);
152 BOOL (*pCreateBitmap
)(HBITMAP
);
153 BOOL (*pCreateDC
)(DC
*,LPCSTR
,LPCSTR
,LPCSTR
,const DEVMODEA
*);
154 HBITMAP (*pCreateDIBSection
)(DC
*,BITMAPINFO
*,UINT
,LPVOID
*,HANDLE
,
156 BOOL (*pDeleteDC
)(DC
*);
157 BOOL (*pDeleteObject
)(HGDIOBJ
);
158 INT (*pDescribePixelFormat
)(DC
*,INT
,UINT
,PIXELFORMATDESCRIPTOR
*);
159 DWORD (*pDeviceCapabilities
)(LPSTR
,LPCSTR
,LPCSTR
,WORD
,LPSTR
,LPDEVMODEA
);
160 BOOL (*pEllipse
)(DC
*,INT
,INT
,INT
,INT
);
162 INT (*pEndPage
)(DC
*);
163 BOOL (*pEndPath
)(DC
*);
164 BOOL (*pEnumDeviceFonts
)(HDC
,LPLOGFONTW
,DEVICEFONTENUMPROC
,LPARAM
);
165 INT (*pExcludeClipRect
)(DC
*,INT
,INT
,INT
,INT
);
166 INT (*pExtDeviceMode
)(LPSTR
,HWND
,LPDEVMODEA
,LPSTR
,LPSTR
,LPDEVMODEA
,LPSTR
,DWORD
);
167 INT (*pExtEscape
)(DC
*,INT
,INT
,LPCVOID
,INT
,LPVOID
);
168 BOOL (*pExtFloodFill
)(DC
*,INT
,INT
,COLORREF
,UINT
);
169 BOOL (*pExtTextOut
)(DC
*,INT
,INT
,UINT
,const RECT
*,LPCWSTR
,UINT
,
171 BOOL (*pFillPath
)(DC
*);
172 BOOL (*pFillRgn
)(DC
*,HRGN
,HBRUSH
);
173 BOOL (*pFlattenPath
)(DC
*);
174 BOOL (*pFrameRgn
)(DC
*,HRGN
,HBRUSH
,INT
,INT
);
175 BOOL (*pGetCharWidth
)(DC
*,UINT
,UINT
,LPINT
);
176 BOOL (*pGetDCOrgEx
)(DC
*,LPPOINT
);
177 INT (*pGetDeviceCaps
)(DC
*,INT
);
178 BOOL (*pGetDeviceGammaRamp
)(DC
*,LPVOID
);
179 COLORREF (*pGetPixel
)(DC
*,INT
,INT
);
180 INT (*pGetPixelFormat
)(DC
*);
181 BOOL (*pGetTextExtentPoint
)(DC
*,LPCWSTR
,INT
,LPSIZE
);
182 BOOL (*pGetTextMetrics
)(DC
*,TEXTMETRICW
*);
183 INT (*pIntersectClipRect
)(DC
*,INT
,INT
,INT
,INT
);
184 BOOL (*pInvertRgn
)(DC
*,HRGN
);
185 BOOL (*pLineTo
)(DC
*,INT
,INT
);
186 BOOL (*pMoveTo
)(DC
*,INT
,INT
);
187 INT (*pOffsetClipRgn
)(DC
*,INT
,INT
);
188 BOOL (*pOffsetViewportOrg
)(DC
*,INT
,INT
);
189 BOOL (*pOffsetWindowOrg
)(DC
*,INT
,INT
);
190 BOOL (*pPaintRgn
)(DC
*,HRGN
);
191 BOOL (*pPatBlt
)(DC
*,INT
,INT
,INT
,INT
,DWORD
);
192 BOOL (*pPie
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
193 BOOL (*pPolyBezier
)(DC
*,const POINT
*,DWORD
);
194 BOOL (*pPolyBezierTo
)(DC
*,const POINT
*,DWORD
);
195 BOOL (*pPolyDraw
)(DC
*,const POINT
*,const BYTE
*,DWORD
);
196 BOOL (*pPolyPolygon
)(DC
*,const POINT
*,const INT
*,UINT
);
197 BOOL (*pPolyPolyline
)(DC
*,const POINT
*,const DWORD
*,DWORD
);
198 BOOL (*pPolygon
)(DC
*,const POINT
*,INT
);
199 BOOL (*pPolyline
)(DC
*,const POINT
*,INT
);
200 BOOL (*pPolylineTo
)(DC
*,const POINT
*,INT
);
201 UINT (*pRealizePalette
)(DC
*);
202 BOOL (*pRectangle
)(DC
*,INT
,INT
,INT
,INT
);
203 BOOL (*pRestoreDC
)(DC
*,INT
);
204 BOOL (*pRoundRect
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
);
206 BOOL (*pScaleViewportExt
)(DC
*,INT
,INT
,INT
,INT
);
207 BOOL (*pScaleWindowExt
)(DC
*,INT
,INT
,INT
,INT
);
208 BOOL (*pSelectClipPath
)(DC
*,INT
);
209 INT (*pSelectClipRgn
)(DC
*,HRGN
);
210 HANDLE (*pSelectObject
)(DC
*,HANDLE
);
211 HPALETTE (*pSelectPalette
)(DC
*,HPALETTE
,BOOL
);
212 COLORREF (*pSetBkColor
)(DC
*,COLORREF
);
213 INT (*pSetBkMode
)(DC
*,INT
);
214 VOID (*pSetDeviceClipping
)(DC
*);
215 BOOL (*pSetDeviceGammaRamp
)(DC
*,LPVOID
);
216 INT (*pSetDIBitsToDevice
)(DC
*,INT
,INT
,DWORD
,DWORD
,INT
,INT
,UINT
,UINT
,
217 LPCVOID
,const BITMAPINFO
*,UINT
);
218 INT (*pSetMapMode
)(DC
*,INT
);
219 DWORD (*pSetMapperFlags
)(DC
*,DWORD
);
220 COLORREF (*pSetPixel
)(DC
*,INT
,INT
,COLORREF
);
221 BOOL (*pSetPixelFormat
)(DC
*,INT
,const PIXELFORMATDESCRIPTOR
*);
222 INT (*pSetPolyFillMode
)(DC
*,INT
);
223 INT (*pSetROP2
)(DC
*,INT
);
224 INT (*pSetRelAbs
)(DC
*,INT
);
225 INT (*pSetStretchBltMode
)(DC
*,INT
);
226 UINT (*pSetTextAlign
)(DC
*,UINT
);
227 INT (*pSetTextCharacterExtra
)(DC
*,INT
);
228 DWORD (*pSetTextColor
)(DC
*,DWORD
);
229 INT (*pSetTextJustification
)(DC
*,INT
,INT
);
230 BOOL (*pSetViewportExt
)(DC
*,INT
,INT
);
231 BOOL (*pSetViewportOrg
)(DC
*,INT
,INT
);
232 BOOL (*pSetWindowExt
)(DC
*,INT
,INT
);
233 BOOL (*pSetWindowOrg
)(DC
*,INT
,INT
);
234 INT (*pStartDoc
)(DC
*,const DOCINFOA
*);
235 INT (*pStartPage
)(DC
*);
236 BOOL (*pStretchBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,INT
,INT
,DWORD
);
237 INT (*pStretchDIBits
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,
238 const void *,const BITMAPINFO
*,UINT
,DWORD
);
239 BOOL (*pStrokeAndFillPath
)(DC
*);
240 BOOL (*pStrokePath
)(DC
*);
241 BOOL (*pSwapBuffers
)(DC
*);
242 BOOL (*pWidenPath
)(DC
*);
246 #define DCHC_INVALIDVISRGN 0x0001
247 #define DCHC_DELETEDC 0x0002
249 #define DCHF_INVALIDATEVISRGN 0x0001
250 #define DCHF_VALIDATEVISRGN 0x0002
253 #define DC_MEMORY 0x0001 /* It is a memory DC */
254 #define DC_SAVED 0x0002 /* It is a saved DC */
255 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
256 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
258 #define GDI_HEAP_SIZE 0xffe0
260 /* extra stock object: default 1x1 bitmap for memory DCs */
261 #define DEFAULT_BITMAP (STOCK_LAST+1)
263 /* Device <-> logical coords conversion */
265 /* A floating point version of the POINT structure */
266 typedef struct tagFLOAT_POINT
271 /* Rounds a floating point number to integer. The world-to-viewport
272 * transformation process is done in floating point internally. This function
273 * is then used to round these coordinates to integer values.
275 static inline INT WINE_UNUSED
GDI_ROUND(FLOAT val
)
277 return (int)floor(val
+ 0.5);
280 /* Performs a viewport-to-world transformation on the specified point (which
281 * is in floating point format). Returns TRUE if successful, else FALSE.
283 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
287 /* Check that the viewport-to-world transformation is valid */
288 if (!dc
->vport2WorldValid
)
291 /* Perform the transformation */
294 point
->x
= x
* dc
->xformVport2World
.eM11
+
295 y
* dc
->xformVport2World
.eM21
+
296 dc
->xformVport2World
.eDx
;
297 point
->y
= x
* dc
->xformVport2World
.eM12
+
298 y
* dc
->xformVport2World
.eM22
+
299 dc
->xformVport2World
.eDy
;
304 /* Performs a viewport-to-world transformation on the specified point (which
305 * is in integer format). Returns TRUE if successful, else FALSE.
307 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP(DC
*dc
, LPPOINT point
)
309 FLOAT_POINT floatPoint
;
311 /* Perform operation with floating point */
312 floatPoint
.x
=(FLOAT
)point
->x
;
313 floatPoint
.y
=(FLOAT
)point
->y
;
314 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
317 /* Round to integers */
318 point
->x
= GDI_ROUND(floatPoint
.x
);
319 point
->y
= GDI_ROUND(floatPoint
.y
);
324 /* Performs a world-to-viewport transformation on the specified point (which
325 * is in floating point format).
327 static inline void WINE_UNUSED
INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
331 /* Perform the transformation */
334 point
->x
= x
* dc
->xformWorld2Vport
.eM11
+
335 y
* dc
->xformWorld2Vport
.eM21
+
336 dc
->xformWorld2Vport
.eDx
;
337 point
->y
= x
* dc
->xformWorld2Vport
.eM12
+
338 y
* dc
->xformWorld2Vport
.eM22
+
339 dc
->xformWorld2Vport
.eDy
;
342 /* Performs a world-to-viewport transformation on the specified point (which
343 * is in integer format).
345 static inline void WINE_UNUSED
INTERNAL_LPTODP(DC
*dc
, LPPOINT point
)
347 FLOAT_POINT floatPoint
;
349 /* Perform operation with floating point */
350 floatPoint
.x
=(FLOAT
)point
->x
;
351 floatPoint
.y
=(FLOAT
)point
->y
;
352 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
354 /* Round to integers */
355 point
->x
= GDI_ROUND(floatPoint
.x
);
356 point
->y
= GDI_ROUND(floatPoint
.y
);
360 /* Performs a world-to-viewport transformation on the specified point (which
361 * is in integer format).
363 static inline INT WINE_UNUSED
INTERNAL_XWPTODP(DC
*dc
, INT x
, INT y
)
365 FLOAT_POINT floatPoint
;
367 /* Perform operation with floating point */
368 floatPoint
.x
=(FLOAT
)x
;
369 floatPoint
.y
=(FLOAT
)y
;
370 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
372 /* Round to integers */
373 return GDI_ROUND(floatPoint
.x
);
376 /* Performs a world-to-viewport transformation on the specified point (which
377 * is in integer format).
379 static inline INT WINE_UNUSED
INTERNAL_YWPTODP(DC
*dc
, INT x
, INT y
)
381 FLOAT_POINT floatPoint
;
383 /* Perform operation with floating point */
384 floatPoint
.x
=(FLOAT
)x
;
385 floatPoint
.y
=(FLOAT
)y
;
386 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
388 /* Round to integers */
389 return GDI_ROUND(floatPoint
.y
);
393 /* Performs a viewport-to-world transformation on the specified point (which
394 * is in integer format).
396 static inline INT WINE_UNUSED
INTERNAL_XDPTOWP(DC
*dc
, INT x
, INT y
)
398 FLOAT_POINT floatPoint
;
400 /* Perform operation with floating point */
401 floatPoint
.x
=(FLOAT
)x
;
402 floatPoint
.y
=(FLOAT
)y
;
403 INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
);
405 /* Round to integers */
406 return GDI_ROUND(floatPoint
.x
);
409 /* Performs a viewport-to-world transformation on the specified point (which
410 * is in integer format).
412 static inline INT WINE_UNUSED
INTERNAL_YDPTOWP(DC
*dc
, INT x
, INT y
)
414 FLOAT_POINT floatPoint
;
416 /* Perform operation with floating point */
417 floatPoint
.x
=(FLOAT
)x
;
418 floatPoint
.y
=(FLOAT
)y
;
419 INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
);
421 /* Round to integers */
422 return GDI_ROUND(floatPoint
.y
);
426 #define XDPTOLP(dc,x) \
427 (MulDiv(((x)-(dc)->vportOrgX), (dc)->wndExtX, (dc)->vportExtX) + (dc)->wndOrgX)
428 #define YDPTOLP(dc,y) \
429 (MulDiv(((y)-(dc)->vportOrgY), (dc)->wndExtY, (dc)->vportExtY) + (dc)->wndOrgY)
430 #define XLPTODP(dc,x) \
431 (MulDiv(((x)-(dc)->wndOrgX), (dc)->vportExtX, (dc)->wndExtX) + (dc)->vportOrgX)
432 #define YLPTODP(dc,y) \
433 (MulDiv(((y)-(dc)->wndOrgY), (dc)->vportExtY, (dc)->wndExtY) + (dc)->vportOrgY)
437 /* World -> Device size conversion */
439 /* Performs a world-to-viewport transformation on the specified width (which
440 * is in floating point format).
442 static inline void WINE_UNUSED
INTERNAL_XWSTODS_FLOAT(DC
*dc
, FLOAT
*width
)
444 /* Perform the transformation */
445 *width
= *width
* dc
->xformWorld2Vport
.eM11
;
448 /* Performs a world-to-viewport transformation on the specified width (which
449 * is in integer format).
451 static inline INT WINE_UNUSED
INTERNAL_XWSTODS(DC
*dc
, INT width
)
455 /* Perform operation with floating point */
456 floatWidth
= (FLOAT
)width
;
457 INTERNAL_XWSTODS_FLOAT(dc
, &floatWidth
);
459 /* Round to integers */
460 return GDI_ROUND(floatWidth
);
464 /* Performs a world-to-viewport transformation on the specified size (which
465 * is in floating point format).
467 static inline void WINE_UNUSED
INTERNAL_YWSTODS_FLOAT(DC
*dc
, FLOAT
*height
)
469 /* Perform the transformation */
470 *height
= *height
* dc
->xformWorld2Vport
.eM22
;
473 /* Performs a world-to-viewport transformation on the specified size (which
474 * is in integer format).
476 static inline INT WINE_UNUSED
INTERNAL_YWSTODS(DC
*dc
, INT height
)
480 /* Perform operation with floating point */
481 floatHeight
= (FLOAT
)height
;
482 INTERNAL_YWSTODS_FLOAT(dc
, &floatHeight
);
484 /* Round to integers */
485 return GDI_ROUND(floatHeight
);
489 /* Device <-> logical size conversion */
491 #define XDSTOLS(dc,x) \
492 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
493 #define YDSTOLS(dc,y) \
494 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
495 #define XLSTODS(dc,x) \
496 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
497 #define YLSTODS(dc,y) \
498 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
502 extern BOOL
GDI_Init(void);
503 extern void *GDI_AllocObject( WORD
, WORD
, HGDIOBJ
* );
504 extern void *GDI_ReallocObject( WORD
, HGDIOBJ
, void *obj
);
505 extern BOOL
GDI_FreeObject( HGDIOBJ
, void *obj
);
506 extern void *GDI_GetObjPtr( HGDIOBJ
, WORD
);
507 extern void GDI_ReleaseObj( HGDIOBJ
);
508 extern void GDI_CheckNotLock(void);
510 extern const DC_FUNCTIONS
*DRIVER_load_driver( LPCSTR name
);
511 extern const DC_FUNCTIONS
*DRIVER_get_driver( const DC_FUNCTIONS
*funcs
);
512 extern void DRIVER_release_driver( const DC_FUNCTIONS
*funcs
);
513 extern BOOL
DRIVER_GetDriverName( LPCSTR device
, LPSTR driver
, DWORD size
);
515 extern POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
);
517 extern DC
* DC_AllocDC( const DC_FUNCTIONS
*funcs
);
518 extern DC
* DC_GetDCPtr( HDC hdc
);
519 extern DC
* DC_GetDCUpdate( HDC hdc
);
520 extern void DC_InitDC( DC
* dc
);
521 extern void DC_UpdateXforms( DC
* dc
);
524 #define CLIP_INTERSECT 0x0001
525 #define CLIP_EXCLUDE 0x0002
526 #define CLIP_KEEPRGN 0x0004
528 /* objects/clipping.c */
529 INT
CLIPPING_IntersectClipRect( DC
* dc
, INT left
, INT top
,
530 INT right
, INT bottom
, UINT flags
);
531 INT
CLIPPING_IntersectVisRect( DC
* dc
, INT left
, INT top
,
532 INT right
, INT bottom
, BOOL exclude
);
533 extern void CLIPPING_UpdateGCRegion( DC
* dc
);
535 /* objects/enhmetafile.c */
536 extern HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, BOOL on_disk
);
538 #define WINE_GGO_GRAY16_BITMAP 0x7f
540 #endif /* __WINE_GDI_H */