4 * Copyright 1993 Alexandre Julliard
14 #include "wine/wingdi16.h"
18 /* GDI objects magic numbers */
19 #define FIRST_MAGIC 0x4f47
20 #define PEN_MAGIC 0x4f47
21 #define BRUSH_MAGIC 0x4f48
22 #define FONT_MAGIC 0x4f49
23 #define PALETTE_MAGIC 0x4f4a
24 #define BITMAP_MAGIC 0x4f4b
25 #define REGION_MAGIC 0x4f4c
26 #define DC_MAGIC 0x4f4d
27 #define DISABLED_DC_MAGIC 0x4f4e
28 #define META_DC_MAGIC 0x4f4f
29 #define METAFILE_MAGIC 0x4f50
30 #define METAFILE_DC_MAGIC 0x4f51
31 #define ENHMETAFILE_MAGIC 0x4f52
32 #define ENHMETAFILE_DC_MAGIC 0x4f53
33 #define LAST_MAGIC 0x4f53
35 #define MAGIC_DONTCARE 0xffff
37 /* GDI constants for making objects private/system (naming undoc. !) */
38 #define OBJECT_PRIVATE 0x2000
39 #define OBJECT_NOSYSTEM 0x8000
41 #define GDIMAGIC(magic) ((magic) & ~(OBJECT_PRIVATE|OBJECT_NOSYSTEM))
43 typedef struct tagGDIOBJHDR
51 typedef struct tagDeviceCaps
53 WORD version
; /* 0: driver version */
54 WORD technology
; /* 2: device technology */
55 WORD horzSize
; /* 4: width of display in mm */
56 WORD vertSize
; /* 6: height of display in mm */
57 WORD horzRes
; /* 8: width of display in pixels */
58 WORD vertRes
; /* 10: width of display in pixels */
59 WORD bitsPixel
; /* 12: bits per pixel */
60 WORD planes
; /* 14: color planes */
61 WORD numBrushes
; /* 16: device-specific brushes */
62 WORD numPens
; /* 18: device-specific pens */
63 WORD numMarkers
; /* 20: device-specific markers */
64 WORD numFonts
; /* 22: device-specific fonts */
65 WORD numColors
; /* 24: size of color table */
66 WORD pdeviceSize
; /* 26: size of PDEVICE structure */
67 WORD curveCaps
; /* 28: curve capabilities */
68 WORD lineCaps
; /* 30: line capabilities */
69 WORD polygonalCaps
; /* 32: polygon capabilities */
70 WORD textCaps
; /* 34: text capabilities */
71 WORD clipCaps
; /* 36: clipping capabilities */
72 WORD rasterCaps
; /* 38: raster capabilities */
73 WORD aspectX
; /* 40: relative width of device pixel */
74 WORD aspectY
; /* 42: relative height of device pixel */
75 WORD aspectXY
; /* 44: relative diagonal width of device pixel */
76 WORD pad1
[21]; /* 46-86: reserved */
77 WORD logPixelsX
; /* 88: pixels / logical X inch */
78 WORD logPixelsY
; /* 90: pixels / logical Y inch */
79 WORD pad2
[6]; /* 92-102: reserved */
80 WORD sizePalette
; /* 104: entries in system palette */
81 WORD numReserved
; /* 106: reserved entries */
82 WORD colorRes
; /* 108: color resolution */
85 typedef BOOL16
CALLBACK (*DCHOOKPROC
)(HDC16
,WORD
,DWORD
,LPARAM
);
90 HDC hSelf
; /* Handle to this DC */
91 const struct tagDC_FUNCS
*funcs
; /* DC function table */
92 void *physDev
; /* Physical device (driver-specific) */
95 FARPROC16 hookProc
; /* the original SEGPTR ... */
96 DCHOOKPROC hookThunk
; /* ... and the thunk to call it */
98 INT wndOrgX
; /* Window origin */
100 INT wndExtX
; /* Window extent */
102 INT vportOrgX
; /* Viewport origin */
104 INT vportExtX
; /* Viewport extent */
108 const DeviceCaps
*devCaps
;
110 HRGN16 hClipRgn
; /* Clip region (may be 0) */
111 HRGN16 hVisRgn
; /* Visible region (must never be 0) */
112 HRGN16 hGCClipRgn
; /* GC clip region (ClipRgn AND VisRgn) */
127 COLORREF backgroundColor
;
132 WORD textAlign
; /* Text alignment from SetTextAlign() */
133 short charExtra
; /* Spacing from SetTextCharacterExtra() */
134 short breakTotalExtra
; /* Total extra space for justification */
135 short breakCount
; /* Break char. count */
136 short breakExtra
; /* breakTotalExtra / breakCount */
137 short breakRem
; /* breakTotalExtra % breakCount */
143 INT GraphicsMode
; /* Graphics mode */
144 INT DCOrgX
; /* DC origin */
146 ABORTPROC pAbortProc
; /* AbortProc for Printing */
147 INT CursPosX
; /* Current position */
150 XFORM xformWorld2Wnd
; /* World-to-window transformation */
151 XFORM xformWorld2Vport
; /* World-to-viewport transformation */
152 XFORM xformVport2World
; /* Inverse of the above transformation */
153 BOOL vport2WorldValid
; /* Is xformVport2World valid? */
156 /* Device functions for the Wine driver interface */
158 typedef INT (*DEVICEFONTENUMPROC
)(LPENUMLOGFONTEX16
,LPNEWTEXTMETRIC16
,UINT16
,LPARAM
);
160 typedef struct tagDC_FUNCS
162 INT (*pAbortDoc
)(DC
*);
163 BOOL (*pAbortPath
)(DC
*);
164 BOOL (*pAngleArc
)(DC
*,INT
,INT
,DWORD
,FLOAT
,FLOAT
);
165 BOOL (*pArc
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
166 BOOL (*pArcTo
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
167 BOOL (*pBeginPath
)(DC
*);
168 BOOL (*pBitBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,DWORD
);
169 LONG (*pBitmapBits
)(HBITMAP
,void*,LONG
,WORD
);
170 INT (*pChoosePixelFormat
)(DC
*,const PIXELFORMATDESCRIPTOR
*);
171 BOOL (*pChord
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
172 BOOL (*pCloseFigure
)(DC
*);
173 BOOL (*pCreateBitmap
)(HBITMAP
);
174 BOOL (*pCreateDC
)(DC
*,LPCSTR
,LPCSTR
,LPCSTR
,const DEVMODEA
*);
175 HBITMAP (*pCreateDIBSection
)(DC
*,BITMAPINFO
*,UINT
,LPVOID
*,HANDLE
,
177 HBITMAP16 (*pCreateDIBSection16
)(DC
*,BITMAPINFO
*,UINT16
,SEGPTR
*,HANDLE
,
179 BOOL (*pDeleteDC
)(DC
*);
180 BOOL (*pDeleteObject
)(HGDIOBJ
);
181 INT (*pDescribePixelFormat
)(DC
*,INT
,UINT
,PIXELFORMATDESCRIPTOR
*);
182 DWORD (*pDeviceCapabilities
)(LPSTR
,LPCSTR
,LPCSTR
,WORD
,LPSTR
,LPDEVMODEA
);
183 BOOL (*pEllipse
)(DC
*,INT
,INT
,INT
,INT
);
185 INT (*pEndPage
)(DC
*);
186 BOOL (*pEndPath
)(DC
*);
187 BOOL (*pEnumDeviceFonts
)(HDC
,LPLOGFONT16
,DEVICEFONTENUMPROC
,LPARAM
);
188 INT (*pEscape
)(DC
*,INT
,INT
,SEGPTR
,SEGPTR
);
189 INT (*pExcludeClipRect
)(DC
*,INT
,INT
,INT
,INT
);
190 INT (*pExtDeviceMode
)(LPSTR
,HWND
,LPDEVMODEA
,LPSTR
,LPSTR
,LPDEVMODEA
,
192 BOOL (*pExtFloodFill
)(DC
*,INT
,INT
,COLORREF
,UINT
);
193 BOOL (*pExtTextOut
)(DC
*,INT
,INT
,UINT
,const RECT
*,LPCWSTR
,UINT
,
195 BOOL (*pFillPath
)(DC
*);
196 BOOL (*pFillRgn
)(DC
*,HRGN
,HBRUSH
);
197 BOOL (*pFlattenPath
)(DC
*);
198 BOOL (*pFrameRgn
)(DC
*,HRGN
,HBRUSH
,INT
,INT
);
199 BOOL (*pGetCharWidth
)(DC
*,UINT
,UINT
,LPINT
);
200 BOOL (*pGetDCOrgEx
)(DC
*,LPPOINT
);
201 COLORREF (*pGetPixel
)(DC
*,INT
,INT
);
202 INT (*pGetPixelFormat
)(DC
*);
203 BOOL (*pGetTextExtentPoint
)(DC
*,LPCWSTR
,INT
,LPSIZE
);
204 BOOL (*pGetTextMetrics
)(DC
*,TEXTMETRICA
*);
205 INT (*pIntersectClipRect
)(DC
*,INT
,INT
,INT
,INT
);
206 BOOL (*pInvertRgn
)(DC
*,HRGN
);
207 BOOL (*pLineTo
)(DC
*,INT
,INT
);
208 BOOL (*pMoveTo
)(DC
*,INT
,INT
);
209 INT (*pOffsetClipRgn
)(DC
*,INT
,INT
);
210 BOOL (*pOffsetViewportOrg
)(DC
*,INT
,INT
);
211 BOOL (*pOffsetWindowOrg
)(DC
*,INT
,INT
);
212 BOOL (*pPaintRgn
)(DC
*,HRGN
);
213 BOOL (*pPatBlt
)(DC
*,INT
,INT
,INT
,INT
,DWORD
);
214 BOOL (*pPie
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
215 BOOL (*pPolyBezier
)(DC
*,const POINT
*,DWORD
);
216 BOOL (*pPolyBezierTo
)(DC
*,const POINT
*,DWORD
);
217 BOOL (*pPolyDraw
)(DC
*,const POINT
*,const BYTE
*,DWORD
);
218 BOOL (*pPolyPolygon
)(DC
*,const POINT
*,const INT
*,UINT
);
219 BOOL (*pPolyPolyline
)(DC
*,const POINT
*,const DWORD
*,DWORD
);
220 BOOL (*pPolygon
)(DC
*,const POINT
*,INT
);
221 BOOL (*pPolyline
)(DC
*,const POINT
*,INT
);
222 BOOL (*pPolylineTo
)(DC
*,const POINT
*,INT
);
223 UINT (*pRealizePalette
)(DC
*);
224 BOOL (*pRectangle
)(DC
*,INT
,INT
,INT
,INT
);
225 BOOL (*pRestoreDC
)(DC
*,INT
);
226 BOOL (*pRoundRect
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
);
228 BOOL (*pScaleViewportExt
)(DC
*,INT
,INT
,INT
,INT
);
229 BOOL (*pScaleWindowExt
)(DC
*,INT
,INT
,INT
,INT
);
230 BOOL (*pSelectClipPath
)(DC
*,INT
);
231 INT (*pSelectClipRgn
)(DC
*,HRGN
);
232 HANDLE (*pSelectObject
)(DC
*,HANDLE
);
233 HPALETTE (*pSelectPalette
)(DC
*,HPALETTE
,BOOL
);
234 COLORREF (*pSetBkColor
)(DC
*,COLORREF
);
235 INT (*pSetBkMode
)(DC
*,INT
);
236 VOID (*pSetDeviceClipping
)(DC
*);
237 INT (*pSetDIBitsToDevice
)(DC
*,INT
,INT
,DWORD
,DWORD
,INT
,INT
,UINT
,UINT
,
238 LPCVOID
,const BITMAPINFO
*,UINT
);
239 INT (*pSetMapMode
)(DC
*,INT
);
240 DWORD (*pSetMapperFlags
)(DC
*,DWORD
);
241 COLORREF (*pSetPixel
)(DC
*,INT
,INT
,COLORREF
);
242 BOOL (*pSetPixelFormat
)(DC
*,INT
,const PIXELFORMATDESCRIPTOR
*);
243 INT (*pSetPolyFillMode
)(DC
*,INT
);
244 INT (*pSetROP2
)(DC
*,INT
);
245 INT (*pSetRelAbs
)(DC
*,INT
);
246 INT (*pSetStretchBltMode
)(DC
*,INT
);
247 UINT (*pSetTextAlign
)(DC
*,UINT
);
248 INT (*pSetTextCharacterExtra
)(DC
*,INT
);
249 DWORD (*pSetTextColor
)(DC
*,DWORD
);
250 INT (*pSetTextJustification
)(DC
*,INT
,INT
);
251 BOOL (*pSetViewportExt
)(DC
*,INT
,INT
);
252 BOOL (*pSetViewportOrg
)(DC
*,INT
,INT
);
253 BOOL (*pSetWindowExt
)(DC
*,INT
,INT
);
254 BOOL (*pSetWindowOrg
)(DC
*,INT
,INT
);
255 INT (*pStartDoc
)(DC
*,const DOCINFOA
*);
256 INT (*pStartPage
)(DC
*);
257 BOOL (*pStretchBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,INT
,INT
,DWORD
);
258 INT (*pStretchDIBits
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,
259 const void *,const BITMAPINFO
*,UINT
,DWORD
);
260 BOOL (*pStrokeAndFillPath
)(DC
*);
261 BOOL (*pStrokePath
)(DC
*);
262 BOOL (*pSwapBuffers
)(DC
*);
263 BOOL (*pWidenPath
)(DC
*);
266 /* LoadOEMResource types */
272 #define DCHC_INVALIDVISRGN 0x0001
273 #define DCHC_DELETEDC 0x0002
275 #define DCHF_INVALIDATEVISRGN 0x0001
276 #define DCHF_VALIDATEVISRGN 0x0002
279 #define DC_MEMORY 0x0001 /* It is a memory DC */
280 #define DC_SAVED 0x0002 /* It is a saved DC */
281 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
282 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
284 /* Last 32 bytes are reserved for stock object handles */
285 #define GDI_HEAP_SIZE 0xffe0
287 /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
288 #define FIRST_STOCK_HANDLE GDI_HEAP_SIZE
290 /* Stock objects handles */
292 #define NB_STOCK_OBJECTS (DEFAULT_GUI_FONT + 1)
294 #define STOCK_WHITE_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
295 #define STOCK_LTGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
296 #define STOCK_GRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
297 #define STOCK_DKGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
298 #define STOCK_BLACK_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
299 #define STOCK_NULL_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+NULL_BRUSH))
300 #define STOCK_HOLLOW_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
301 #define STOCK_WHITE_PEN ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
302 #define STOCK_BLACK_PEN ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
303 #define STOCK_NULL_PEN ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
304 #define STOCK_OEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
305 #define STOCK_ANSI_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
306 #define STOCK_ANSI_VAR_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
307 #define STOCK_SYSTEM_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
308 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
309 #define STOCK_DEFAULT_PALETTE ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
310 #define STOCK_SYSTEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
311 #define STOCK_DEFAULT_GUI_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEFAULT_GUI_FONT))
313 #define FIRST_STOCK_FONT STOCK_OEM_FIXED_FONT
314 #define LAST_STOCK_FONT STOCK_DEFAULT_GUI_FONT
316 #define LAST_STOCK_HANDLE ((DWORD)STOCK_DEFAULT_GUI_FONT)
318 extern HBITMAP hPseudoStockBitmap
;
320 /* Device <-> logical coords conversion */
322 /* A floating point version of the POINT structure */
323 typedef struct tagFLOAT_POINT
328 /* Rounds a floating point number to integer. The world-to-viewport
329 * transformation process is done in floating point internally. This function
330 * is then used to round these coordinates to integer values.
332 static inline INT WINE_UNUSED
GDI_ROUND(FLOAT val
)
334 return (int)floor(val
+ 0.5);
337 /* Performs a viewport-to-world transformation on the specified point (which
338 * is in floating point format). Returns TRUE if successful, else FALSE.
340 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
344 /* Check that the viewport-to-world transformation is valid */
345 if (!dc
->vport2WorldValid
)
348 /* Perform the transformation */
351 point
->x
= x
* dc
->xformVport2World
.eM11
+
352 y
* dc
->xformVport2World
.eM21
+
353 dc
->xformVport2World
.eDx
;
354 point
->y
= x
* dc
->xformVport2World
.eM12
+
355 y
* dc
->xformVport2World
.eM22
+
356 dc
->xformVport2World
.eDy
;
361 /* Performs a viewport-to-world transformation on the specified point (which
362 * is in integer format). Returns TRUE if successful, else FALSE.
364 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP(DC
*dc
, LPPOINT point
)
366 FLOAT_POINT floatPoint
;
368 /* Perform operation with floating point */
369 floatPoint
.x
=(FLOAT
)point
->x
;
370 floatPoint
.y
=(FLOAT
)point
->y
;
371 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
374 /* Round to integers */
375 point
->x
= GDI_ROUND(floatPoint
.x
);
376 point
->y
= GDI_ROUND(floatPoint
.y
);
381 /* Performs a world-to-viewport transformation on the specified point (which
382 * is in floating point format).
384 static inline void WINE_UNUSED
INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
388 /* Perform the transformation */
391 point
->x
= x
* dc
->xformWorld2Vport
.eM11
+
392 y
* dc
->xformWorld2Vport
.eM21
+
393 dc
->xformWorld2Vport
.eDx
;
394 point
->y
= x
* dc
->xformWorld2Vport
.eM12
+
395 y
* dc
->xformWorld2Vport
.eM22
+
396 dc
->xformWorld2Vport
.eDy
;
399 /* Performs a world-to-viewport transformation on the specified point (which
400 * is in integer format).
402 static inline void WINE_UNUSED
INTERNAL_LPTODP(DC
*dc
, LPPOINT point
)
404 FLOAT_POINT floatPoint
;
406 /* Perform operation with floating point */
407 floatPoint
.x
=(FLOAT
)point
->x
;
408 floatPoint
.y
=(FLOAT
)point
->y
;
409 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
411 /* Round to integers */
412 point
->x
= GDI_ROUND(floatPoint
.x
);
413 point
->y
= GDI_ROUND(floatPoint
.y
);
416 #define XDPTOLP(dc,x) \
417 (MulDiv(((x)-(dc)->vportOrgX), (dc)->wndExtX, (dc)->vportExtX) + (dc)->wndOrgX)
418 #define YDPTOLP(dc,y) \
419 (MulDiv(((y)-(dc)->vportOrgY), (dc)->wndExtY, (dc)->vportExtY) + (dc)->wndOrgY)
420 #define XLPTODP(dc,x) \
421 (MulDiv(((x)-(dc)->wndOrgX), (dc)->vportExtX, (dc)->wndExtX) + (dc)->vportOrgX)
422 #define YLPTODP(dc,y) \
423 (MulDiv(((y)-(dc)->wndOrgY), (dc)->vportExtY, (dc)->wndExtY) + (dc)->vportOrgY)
425 /* Device <-> logical size conversion */
427 #define XDSTOLS(dc,x) \
428 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
429 #define YDSTOLS(dc,y) \
430 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
431 #define XLSTODS(dc,x) \
432 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
433 #define YLSTODS(dc,y) \
434 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
438 extern BOOL
GDI_Init(void);
439 extern void *GDI_AllocObject( WORD
, WORD
, HGDIOBJ
* );
440 extern void *GDI_ReallocObject( WORD
, HGDIOBJ
, void *obj
);
441 extern BOOL
GDI_FreeObject( HGDIOBJ
, void *obj
);
442 extern void *GDI_GetObjPtr( HGDIOBJ
, WORD
);
443 extern void GDI_ReleaseObj( HGDIOBJ
);
445 extern BOOL
DRIVER_RegisterDriver( LPCSTR name
, const DC_FUNCTIONS
*funcs
);
446 extern const DC_FUNCTIONS
*DRIVER_FindDriver( LPCSTR name
);
447 extern BOOL
DRIVER_UnregisterDriver( LPCSTR name
);
448 extern BOOL
DRIVER_GetDriverName( LPCSTR device
, LPSTR driver
, DWORD size
);
450 extern POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
);
452 extern DC
* DC_AllocDC( const DC_FUNCTIONS
*funcs
);
453 extern DC
* DC_GetDCPtr( HDC hdc
);
454 extern DC
* DC_GetDCUpdate( HDC hdc
);
455 extern void DC_InitDC( DC
* dc
);
456 extern void DC_UpdateXforms( DC
* dc
);
459 #define CLIP_INTERSECT 0x0001
460 #define CLIP_EXCLUDE 0x0002
461 #define CLIP_KEEPRGN 0x0004
463 /* objects/clipping.c */
464 INT
CLIPPING_IntersectClipRect( DC
* dc
, INT left
, INT top
,
465 INT right
, INT bottom
, UINT flags
);
466 INT
CLIPPING_IntersectVisRect( DC
* dc
, INT left
, INT top
,
467 INT right
, INT bottom
, BOOL exclude
);
468 extern void CLIPPING_UpdateGCRegion( DC
* dc
);
470 #endif /* __WINE_GDI_H */