4 * Copyright 1993 Alexandre Julliard
12 #include "wine/wingdi16.h"
16 /* GDI objects magic numbers */
17 #define FIRST_MAGIC 0x4f47
18 #define PEN_MAGIC 0x4f47
19 #define BRUSH_MAGIC 0x4f48
20 #define FONT_MAGIC 0x4f49
21 #define PALETTE_MAGIC 0x4f4a
22 #define BITMAP_MAGIC 0x4f4b
23 #define REGION_MAGIC 0x4f4c
24 #define DC_MAGIC 0x4f4d
25 #define DISABLED_DC_MAGIC 0x4f4e
26 #define META_DC_MAGIC 0x4f4f
27 #define METAFILE_MAGIC 0x4f50
28 #define METAFILE_DC_MAGIC 0x4f51
29 #define ENHMETAFILE_MAGIC 0x4f52
30 #define ENHMETAFILE_DC_MAGIC 0x4f53
31 #define LAST_MAGIC 0x4f53
33 #define MAGIC_DONTCARE 0xffff
35 /* GDI constants for making objects private/system (naming undoc. !) */
36 #define OBJECT_PRIVATE 0x2000
37 #define OBJECT_NOSYSTEM 0x8000
39 #define GDIMAGIC(magic) ((magic) & ~(OBJECT_PRIVATE|OBJECT_NOSYSTEM))
41 typedef struct tagGDIOBJHDR
49 typedef struct tagGdiFont
*GdiFont
;
54 HDC hSelf
; /* Handle to this DC */
55 const struct tagDC_FUNCS
*funcs
; /* DC function table */
56 void *physDev
; /* Physical device (driver-specific) */
59 FARPROC16 hookProc
; /* the original SEGPTR ... */
60 DCHOOKPROC hookThunk
; /* ... and the thunk to call it */
62 INT wndOrgX
; /* Window origin */
64 INT wndExtX
; /* Window extent */
66 INT vportOrgX
; /* Viewport origin */
68 INT vportExtX
; /* Viewport extent */
72 HRGN16 hClipRgn
; /* Clip region (may be 0) */
73 HRGN16 hVisRgn
; /* Visible region (must never be 0) */
74 HRGN16 hGCClipRgn
; /* GC clip region (ClipRgn AND VisRgn) */
90 COLORREF backgroundColor
;
95 WORD textAlign
; /* Text alignment from SetTextAlign() */
96 short charExtra
; /* Spacing from SetTextCharacterExtra() */
97 short breakTotalExtra
; /* Total extra space for justification */
98 short breakCount
; /* Break char. count */
99 short breakExtra
; /* breakTotalExtra / breakCount */
100 short breakRem
; /* breakTotalExtra % breakCount */
106 INT GraphicsMode
; /* Graphics mode */
107 INT DCOrgX
; /* DC origin */
109 ABORTPROC pAbortProc
; /* AbortProc for Printing */
110 ABORTPROC16 pAbortProc16
;
111 INT CursPosX
; /* Current position */
114 XFORM xformWorld2Wnd
; /* World-to-window transformation */
115 XFORM xformWorld2Vport
; /* World-to-viewport transformation */
116 XFORM xformVport2World
; /* Inverse of the above transformation */
117 BOOL vport2WorldValid
; /* Is xformVport2World valid? */
120 /* Device functions for the Wine driver interface */
122 typedef INT (*DEVICEFONTENUMPROC
)(LPENUMLOGFONTEXW
,LPNEWTEXTMETRICEXW
,DWORD
,
125 typedef struct tagDC_FUNCS
127 INT (*pAbortDoc
)(DC
*);
128 BOOL (*pAbortPath
)(DC
*);
129 BOOL (*pAngleArc
)(DC
*,INT
,INT
,DWORD
,FLOAT
,FLOAT
);
130 BOOL (*pArc
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
131 BOOL (*pArcTo
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
132 BOOL (*pBeginPath
)(DC
*);
133 BOOL (*pBitBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,DWORD
);
134 LONG (*pBitmapBits
)(HBITMAP
,void*,LONG
,WORD
);
135 INT (*pChoosePixelFormat
)(DC
*,const PIXELFORMATDESCRIPTOR
*);
136 BOOL (*pChord
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
137 BOOL (*pCloseFigure
)(DC
*);
138 BOOL (*pCreateBitmap
)(HBITMAP
);
139 BOOL (*pCreateDC
)(DC
*,LPCSTR
,LPCSTR
,LPCSTR
,const DEVMODEA
*);
140 HBITMAP (*pCreateDIBSection
)(DC
*,BITMAPINFO
*,UINT
,LPVOID
*,HANDLE
,
142 BOOL (*pDeleteDC
)(DC
*);
143 BOOL (*pDeleteObject
)(HGDIOBJ
);
144 INT (*pDescribePixelFormat
)(DC
*,INT
,UINT
,PIXELFORMATDESCRIPTOR
*);
145 DWORD (*pDeviceCapabilities
)(LPSTR
,LPCSTR
,LPCSTR
,WORD
,LPSTR
,LPDEVMODEA
);
146 BOOL (*pEllipse
)(DC
*,INT
,INT
,INT
,INT
);
148 INT (*pEndPage
)(DC
*);
149 BOOL (*pEndPath
)(DC
*);
150 BOOL (*pEnumDeviceFonts
)(HDC
,LPLOGFONTW
,DEVICEFONTENUMPROC
,LPARAM
);
151 INT (*pExcludeClipRect
)(DC
*,INT
,INT
,INT
,INT
);
152 INT (*pExtDeviceMode
)(LPSTR
,HWND
,LPDEVMODEA
,LPSTR
,LPSTR
,LPDEVMODEA
,LPSTR
,DWORD
);
153 INT (*pExtEscape
)(DC
*,INT
,INT
,LPCVOID
,INT
,LPVOID
);
154 BOOL (*pExtFloodFill
)(DC
*,INT
,INT
,COLORREF
,UINT
);
155 BOOL (*pExtTextOut
)(DC
*,INT
,INT
,UINT
,const RECT
*,LPCWSTR
,UINT
,
157 BOOL (*pFillPath
)(DC
*);
158 BOOL (*pFillRgn
)(DC
*,HRGN
,HBRUSH
);
159 BOOL (*pFlattenPath
)(DC
*);
160 BOOL (*pFrameRgn
)(DC
*,HRGN
,HBRUSH
,INT
,INT
);
161 BOOL (*pGetCharWidth
)(DC
*,UINT
,UINT
,LPINT
);
162 BOOL (*pGetDCOrgEx
)(DC
*,LPPOINT
);
163 INT (*pGetDeviceCaps
)(DC
*,INT
);
164 BOOL (*pGetDeviceGammaRamp
)(DC
*,LPVOID
);
165 COLORREF (*pGetPixel
)(DC
*,INT
,INT
);
166 INT (*pGetPixelFormat
)(DC
*);
167 BOOL (*pGetTextExtentPoint
)(DC
*,LPCWSTR
,INT
,LPSIZE
);
168 BOOL (*pGetTextMetrics
)(DC
*,TEXTMETRICW
*);
169 INT (*pIntersectClipRect
)(DC
*,INT
,INT
,INT
,INT
);
170 BOOL (*pInvertRgn
)(DC
*,HRGN
);
171 BOOL (*pLineTo
)(DC
*,INT
,INT
);
172 BOOL (*pMoveTo
)(DC
*,INT
,INT
);
173 INT (*pOffsetClipRgn
)(DC
*,INT
,INT
);
174 BOOL (*pOffsetViewportOrg
)(DC
*,INT
,INT
);
175 BOOL (*pOffsetWindowOrg
)(DC
*,INT
,INT
);
176 BOOL (*pPaintRgn
)(DC
*,HRGN
);
177 BOOL (*pPatBlt
)(DC
*,INT
,INT
,INT
,INT
,DWORD
);
178 BOOL (*pPie
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
179 BOOL (*pPolyBezier
)(DC
*,const POINT
*,DWORD
);
180 BOOL (*pPolyBezierTo
)(DC
*,const POINT
*,DWORD
);
181 BOOL (*pPolyDraw
)(DC
*,const POINT
*,const BYTE
*,DWORD
);
182 BOOL (*pPolyPolygon
)(DC
*,const POINT
*,const INT
*,UINT
);
183 BOOL (*pPolyPolyline
)(DC
*,const POINT
*,const DWORD
*,DWORD
);
184 BOOL (*pPolygon
)(DC
*,const POINT
*,INT
);
185 BOOL (*pPolyline
)(DC
*,const POINT
*,INT
);
186 BOOL (*pPolylineTo
)(DC
*,const POINT
*,INT
);
187 UINT (*pRealizePalette
)(DC
*);
188 BOOL (*pRectangle
)(DC
*,INT
,INT
,INT
,INT
);
189 BOOL (*pRestoreDC
)(DC
*,INT
);
190 BOOL (*pRoundRect
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
);
192 BOOL (*pScaleViewportExt
)(DC
*,INT
,INT
,INT
,INT
);
193 BOOL (*pScaleWindowExt
)(DC
*,INT
,INT
,INT
,INT
);
194 BOOL (*pSelectClipPath
)(DC
*,INT
);
195 INT (*pSelectClipRgn
)(DC
*,HRGN
);
196 HANDLE (*pSelectObject
)(DC
*,HANDLE
);
197 HPALETTE (*pSelectPalette
)(DC
*,HPALETTE
,BOOL
);
198 COLORREF (*pSetBkColor
)(DC
*,COLORREF
);
199 INT (*pSetBkMode
)(DC
*,INT
);
200 VOID (*pSetDeviceClipping
)(DC
*);
201 BOOL (*pSetDeviceGammaRamp
)(DC
*,LPVOID
);
202 INT (*pSetDIBitsToDevice
)(DC
*,INT
,INT
,DWORD
,DWORD
,INT
,INT
,UINT
,UINT
,
203 LPCVOID
,const BITMAPINFO
*,UINT
);
204 INT (*pSetMapMode
)(DC
*,INT
);
205 DWORD (*pSetMapperFlags
)(DC
*,DWORD
);
206 COLORREF (*pSetPixel
)(DC
*,INT
,INT
,COLORREF
);
207 BOOL (*pSetPixelFormat
)(DC
*,INT
,const PIXELFORMATDESCRIPTOR
*);
208 INT (*pSetPolyFillMode
)(DC
*,INT
);
209 INT (*pSetROP2
)(DC
*,INT
);
210 INT (*pSetRelAbs
)(DC
*,INT
);
211 INT (*pSetStretchBltMode
)(DC
*,INT
);
212 UINT (*pSetTextAlign
)(DC
*,UINT
);
213 INT (*pSetTextCharacterExtra
)(DC
*,INT
);
214 DWORD (*pSetTextColor
)(DC
*,DWORD
);
215 INT (*pSetTextJustification
)(DC
*,INT
,INT
);
216 BOOL (*pSetViewportExt
)(DC
*,INT
,INT
);
217 BOOL (*pSetViewportOrg
)(DC
*,INT
,INT
);
218 BOOL (*pSetWindowExt
)(DC
*,INT
,INT
);
219 BOOL (*pSetWindowOrg
)(DC
*,INT
,INT
);
220 INT (*pStartDoc
)(DC
*,const DOCINFOA
*);
221 INT (*pStartPage
)(DC
*);
222 BOOL (*pStretchBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,INT
,INT
,DWORD
);
223 INT (*pStretchDIBits
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,
224 const void *,const BITMAPINFO
*,UINT
,DWORD
);
225 BOOL (*pStrokeAndFillPath
)(DC
*);
226 BOOL (*pStrokePath
)(DC
*);
227 BOOL (*pSwapBuffers
)(DC
*);
228 BOOL (*pWidenPath
)(DC
*);
231 /* LoadOEMResource types */
237 #define DCHC_INVALIDVISRGN 0x0001
238 #define DCHC_DELETEDC 0x0002
240 #define DCHF_INVALIDATEVISRGN 0x0001
241 #define DCHF_VALIDATEVISRGN 0x0002
244 #define DC_MEMORY 0x0001 /* It is a memory DC */
245 #define DC_SAVED 0x0002 /* It is a saved DC */
246 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
247 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
249 #define GDI_HEAP_SIZE 0xffe0
251 /* extra stock object: default 1x1 bitmap for memory DCs */
252 #define DEFAULT_BITMAP (STOCK_LAST+1)
254 /* Device <-> logical coords conversion */
256 /* A floating point version of the POINT structure */
257 typedef struct tagFLOAT_POINT
262 /* Rounds a floating point number to integer. The world-to-viewport
263 * transformation process is done in floating point internally. This function
264 * is then used to round these coordinates to integer values.
266 static inline INT WINE_UNUSED
GDI_ROUND(FLOAT val
)
268 return (int)floor(val
+ 0.5);
271 /* Performs a viewport-to-world transformation on the specified point (which
272 * is in floating point format). Returns TRUE if successful, else FALSE.
274 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
278 /* Check that the viewport-to-world transformation is valid */
279 if (!dc
->vport2WorldValid
)
282 /* Perform the transformation */
285 point
->x
= x
* dc
->xformVport2World
.eM11
+
286 y
* dc
->xformVport2World
.eM21
+
287 dc
->xformVport2World
.eDx
;
288 point
->y
= x
* dc
->xformVport2World
.eM12
+
289 y
* dc
->xformVport2World
.eM22
+
290 dc
->xformVport2World
.eDy
;
295 /* Performs a viewport-to-world transformation on the specified point (which
296 * is in integer format). Returns TRUE if successful, else FALSE.
298 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP(DC
*dc
, LPPOINT point
)
300 FLOAT_POINT floatPoint
;
302 /* Perform operation with floating point */
303 floatPoint
.x
=(FLOAT
)point
->x
;
304 floatPoint
.y
=(FLOAT
)point
->y
;
305 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
308 /* Round to integers */
309 point
->x
= GDI_ROUND(floatPoint
.x
);
310 point
->y
= GDI_ROUND(floatPoint
.y
);
315 /* Performs a world-to-viewport transformation on the specified point (which
316 * is in floating point format).
318 static inline void WINE_UNUSED
INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
322 /* Perform the transformation */
325 point
->x
= x
* dc
->xformWorld2Vport
.eM11
+
326 y
* dc
->xformWorld2Vport
.eM21
+
327 dc
->xformWorld2Vport
.eDx
;
328 point
->y
= x
* dc
->xformWorld2Vport
.eM12
+
329 y
* dc
->xformWorld2Vport
.eM22
+
330 dc
->xformWorld2Vport
.eDy
;
333 /* Performs a world-to-viewport transformation on the specified point (which
334 * is in integer format).
336 static inline void WINE_UNUSED
INTERNAL_LPTODP(DC
*dc
, LPPOINT point
)
338 FLOAT_POINT floatPoint
;
340 /* Perform operation with floating point */
341 floatPoint
.x
=(FLOAT
)point
->x
;
342 floatPoint
.y
=(FLOAT
)point
->y
;
343 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
345 /* Round to integers */
346 point
->x
= GDI_ROUND(floatPoint
.x
);
347 point
->y
= GDI_ROUND(floatPoint
.y
);
351 /* Performs a world-to-viewport transformation on the specified point (which
352 * is in integer format).
354 static inline INT WINE_UNUSED
INTERNAL_XWPTODP(DC
*dc
, INT x
, INT y
)
356 FLOAT_POINT floatPoint
;
358 /* Perform operation with floating point */
359 floatPoint
.x
=(FLOAT
)x
;
360 floatPoint
.y
=(FLOAT
)y
;
361 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
363 /* Round to integers */
364 return GDI_ROUND(floatPoint
.x
);
367 /* Performs a world-to-viewport transformation on the specified point (which
368 * is in integer format).
370 static inline INT WINE_UNUSED
INTERNAL_YWPTODP(DC
*dc
, INT x
, INT y
)
372 FLOAT_POINT floatPoint
;
374 /* Perform operation with floating point */
375 floatPoint
.x
=(FLOAT
)x
;
376 floatPoint
.y
=(FLOAT
)y
;
377 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
379 /* Round to integers */
380 return GDI_ROUND(floatPoint
.y
);
384 /* Performs a viewport-to-world transformation on the specified point (which
385 * is in integer format).
387 static inline INT WINE_UNUSED
INTERNAL_XDPTOWP(DC
*dc
, INT x
, INT y
)
389 FLOAT_POINT floatPoint
;
391 /* Perform operation with floating point */
392 floatPoint
.x
=(FLOAT
)x
;
393 floatPoint
.y
=(FLOAT
)y
;
394 INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
);
396 /* Round to integers */
397 return GDI_ROUND(floatPoint
.x
);
400 /* Performs a viewport-to-world transformation on the specified point (which
401 * is in integer format).
403 static inline INT WINE_UNUSED
INTERNAL_YDPTOWP(DC
*dc
, INT x
, INT y
)
405 FLOAT_POINT floatPoint
;
407 /* Perform operation with floating point */
408 floatPoint
.x
=(FLOAT
)x
;
409 floatPoint
.y
=(FLOAT
)y
;
410 INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
);
412 /* Round to integers */
413 return GDI_ROUND(floatPoint
.y
);
417 #define XDPTOLP(dc,x) \
418 (MulDiv(((x)-(dc)->vportOrgX), (dc)->wndExtX, (dc)->vportExtX) + (dc)->wndOrgX)
419 #define YDPTOLP(dc,y) \
420 (MulDiv(((y)-(dc)->vportOrgY), (dc)->wndExtY, (dc)->vportExtY) + (dc)->wndOrgY)
421 #define XLPTODP(dc,x) \
422 (MulDiv(((x)-(dc)->wndOrgX), (dc)->vportExtX, (dc)->wndExtX) + (dc)->vportOrgX)
423 #define YLPTODP(dc,y) \
424 (MulDiv(((y)-(dc)->wndOrgY), (dc)->vportExtY, (dc)->wndExtY) + (dc)->vportOrgY)
428 /* World -> Device size conversion */
430 /* Performs a world-to-viewport transformation on the specified width (which
431 * is in floating point format).
433 static inline void WINE_UNUSED
INTERNAL_XWSTODS_FLOAT(DC
*dc
, FLOAT
*width
)
435 /* Perform the transformation */
436 *width
= *width
* dc
->xformWorld2Vport
.eM11
;
439 /* Performs a world-to-viewport transformation on the specified width (which
440 * is in integer format).
442 static inline INT WINE_UNUSED
INTERNAL_XWSTODS(DC
*dc
, INT width
)
446 /* Perform operation with floating point */
447 floatWidth
= (FLOAT
)width
;
448 INTERNAL_XWSTODS_FLOAT(dc
, &floatWidth
);
450 /* Round to integers */
451 return GDI_ROUND(floatWidth
);
455 /* Performs a world-to-viewport transformation on the specified size (which
456 * is in floating point format).
458 static inline void WINE_UNUSED
INTERNAL_YWSTODS_FLOAT(DC
*dc
, FLOAT
*height
)
460 /* Perform the transformation */
461 *height
= *height
* dc
->xformWorld2Vport
.eM22
;
464 /* Performs a world-to-viewport transformation on the specified size (which
465 * is in integer format).
467 static inline INT WINE_UNUSED
INTERNAL_YWSTODS(DC
*dc
, INT height
)
471 /* Perform operation with floating point */
472 floatHeight
= (FLOAT
)height
;
473 INTERNAL_YWSTODS_FLOAT(dc
, &floatHeight
);
475 /* Round to integers */
476 return GDI_ROUND(floatHeight
);
480 /* Device <-> logical size conversion */
482 #define XDSTOLS(dc,x) \
483 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
484 #define YDSTOLS(dc,y) \
485 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
486 #define XLSTODS(dc,x) \
487 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
488 #define YLSTODS(dc,y) \
489 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
493 extern BOOL
GDI_Init(void);
494 extern void *GDI_AllocObject( WORD
, WORD
, HGDIOBJ
* );
495 extern void *GDI_ReallocObject( WORD
, HGDIOBJ
, void *obj
);
496 extern BOOL
GDI_FreeObject( HGDIOBJ
, void *obj
);
497 extern void *GDI_GetObjPtr( HGDIOBJ
, WORD
);
498 extern void GDI_ReleaseObj( HGDIOBJ
);
499 extern void GDI_CheckNotLock(void);
501 extern const DC_FUNCTIONS
*DRIVER_load_driver( LPCSTR name
);
502 extern const DC_FUNCTIONS
*DRIVER_get_driver( const DC_FUNCTIONS
*funcs
);
503 extern void DRIVER_release_driver( const DC_FUNCTIONS
*funcs
);
504 extern BOOL
DRIVER_GetDriverName( LPCSTR device
, LPSTR driver
, DWORD size
);
506 extern POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
);
508 extern DC
* DC_AllocDC( const DC_FUNCTIONS
*funcs
);
509 extern DC
* DC_GetDCPtr( HDC hdc
);
510 extern DC
* DC_GetDCUpdate( HDC hdc
);
511 extern void DC_InitDC( DC
* dc
);
512 extern void DC_UpdateXforms( DC
* dc
);
515 #define CLIP_INTERSECT 0x0001
516 #define CLIP_EXCLUDE 0x0002
517 #define CLIP_KEEPRGN 0x0004
519 /* objects/clipping.c */
520 INT
CLIPPING_IntersectClipRect( DC
* dc
, INT left
, INT top
,
521 INT right
, INT bottom
, UINT flags
);
522 INT
CLIPPING_IntersectVisRect( DC
* dc
, INT left
, INT top
,
523 INT right
, INT bottom
, BOOL exclude
);
524 extern void CLIPPING_UpdateGCRegion( DC
* dc
);
526 /* objects/enhmetafile.c */
527 extern HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, BOOL on_disk
);
529 #endif /* __WINE_GDI_H */