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