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 BOOL16
CALLBACK (*DCHOOKPROC
)(HDC16
,WORD
,DWORD
,LPARAM
);
53 typedef struct tagGdiFont
*GdiFont
;
58 HDC hSelf
; /* Handle to this DC */
59 const struct tagDC_FUNCS
*funcs
; /* DC function table */
60 void *physDev
; /* Physical device (driver-specific) */
63 FARPROC16 hookProc
; /* the original SEGPTR ... */
64 DCHOOKPROC hookThunk
; /* ... and the thunk to call it */
66 INT wndOrgX
; /* Window origin */
68 INT wndExtX
; /* Window extent */
70 INT vportOrgX
; /* Viewport origin */
72 INT vportExtX
; /* Viewport extent */
76 HRGN16 hClipRgn
; /* Clip region (may be 0) */
77 HRGN16 hVisRgn
; /* Visible region (must never be 0) */
78 HRGN16 hGCClipRgn
; /* GC clip region (ClipRgn AND VisRgn) */
94 COLORREF backgroundColor
;
99 WORD textAlign
; /* Text alignment from SetTextAlign() */
100 short charExtra
; /* Spacing from SetTextCharacterExtra() */
101 short breakTotalExtra
; /* Total extra space for justification */
102 short breakCount
; /* Break char. count */
103 short breakExtra
; /* breakTotalExtra / breakCount */
104 short breakRem
; /* breakTotalExtra % breakCount */
110 INT GraphicsMode
; /* Graphics mode */
111 INT DCOrgX
; /* DC origin */
113 ABORTPROC pAbortProc
; /* AbortProc for Printing */
114 INT CursPosX
; /* Current position */
117 XFORM xformWorld2Wnd
; /* World-to-window transformation */
118 XFORM xformWorld2Vport
; /* World-to-viewport transformation */
119 XFORM xformVport2World
; /* Inverse of the above transformation */
120 BOOL vport2WorldValid
; /* Is xformVport2World valid? */
123 /* Device functions for the Wine driver interface */
125 typedef INT (*DEVICEFONTENUMPROC
)(LPENUMLOGFONTEXW
,LPNEWTEXTMETRICEXW
,DWORD
,
128 typedef struct tagDC_FUNCS
130 INT (*pAbortDoc
)(DC
*);
131 BOOL (*pAbortPath
)(DC
*);
132 BOOL (*pAngleArc
)(DC
*,INT
,INT
,DWORD
,FLOAT
,FLOAT
);
133 BOOL (*pArc
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
134 BOOL (*pArcTo
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
135 BOOL (*pBeginPath
)(DC
*);
136 BOOL (*pBitBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,DWORD
);
137 LONG (*pBitmapBits
)(HBITMAP
,void*,LONG
,WORD
);
138 INT (*pChoosePixelFormat
)(DC
*,const PIXELFORMATDESCRIPTOR
*);
139 BOOL (*pChord
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
140 BOOL (*pCloseFigure
)(DC
*);
141 BOOL (*pCreateBitmap
)(HBITMAP
);
142 BOOL (*pCreateDC
)(DC
*,LPCSTR
,LPCSTR
,LPCSTR
,const DEVMODEA
*);
143 HBITMAP (*pCreateDIBSection
)(DC
*,BITMAPINFO
*,UINT
,LPVOID
*,HANDLE
,
145 BOOL (*pDeleteDC
)(DC
*);
146 BOOL (*pDeleteObject
)(HGDIOBJ
);
147 INT (*pDescribePixelFormat
)(DC
*,INT
,UINT
,PIXELFORMATDESCRIPTOR
*);
148 DWORD (*pDeviceCapabilities
)(LPSTR
,LPCSTR
,LPCSTR
,WORD
,LPSTR
,LPDEVMODEA
);
149 BOOL (*pEllipse
)(DC
*,INT
,INT
,INT
,INT
);
151 INT (*pEndPage
)(DC
*);
152 BOOL (*pEndPath
)(DC
*);
153 BOOL (*pEnumDeviceFonts
)(HDC
,LPLOGFONTW
,DEVICEFONTENUMPROC
,LPARAM
);
154 INT (*pExcludeClipRect
)(DC
*,INT
,INT
,INT
,INT
);
155 INT (*pExtDeviceMode
)(LPSTR
,HWND
,LPDEVMODEA
,LPSTR
,LPSTR
,LPDEVMODEA
,LPSTR
,DWORD
);
156 INT (*pExtEscape
)(DC
*,INT
,INT
,LPCVOID
,INT
,LPVOID
);
157 BOOL (*pExtFloodFill
)(DC
*,INT
,INT
,COLORREF
,UINT
);
158 BOOL (*pExtTextOut
)(DC
*,INT
,INT
,UINT
,const RECT
*,LPCWSTR
,UINT
,
160 BOOL (*pFillPath
)(DC
*);
161 BOOL (*pFillRgn
)(DC
*,HRGN
,HBRUSH
);
162 BOOL (*pFlattenPath
)(DC
*);
163 BOOL (*pFrameRgn
)(DC
*,HRGN
,HBRUSH
,INT
,INT
);
164 BOOL (*pGetCharWidth
)(DC
*,UINT
,UINT
,LPINT
);
165 BOOL (*pGetDCOrgEx
)(DC
*,LPPOINT
);
166 INT (*pGetDeviceCaps
)(DC
*,INT
);
167 BOOL (*pGetDeviceGammaRamp
)(DC
*,LPVOID
);
168 COLORREF (*pGetPixel
)(DC
*,INT
,INT
);
169 INT (*pGetPixelFormat
)(DC
*);
170 BOOL (*pGetTextExtentPoint
)(DC
*,LPCWSTR
,INT
,LPSIZE
);
171 BOOL (*pGetTextMetrics
)(DC
*,TEXTMETRICW
*);
172 INT (*pIntersectClipRect
)(DC
*,INT
,INT
,INT
,INT
);
173 BOOL (*pInvertRgn
)(DC
*,HRGN
);
174 BOOL (*pLineTo
)(DC
*,INT
,INT
);
175 BOOL (*pMoveTo
)(DC
*,INT
,INT
);
176 INT (*pOffsetClipRgn
)(DC
*,INT
,INT
);
177 BOOL (*pOffsetViewportOrg
)(DC
*,INT
,INT
);
178 BOOL (*pOffsetWindowOrg
)(DC
*,INT
,INT
);
179 BOOL (*pPaintRgn
)(DC
*,HRGN
);
180 BOOL (*pPatBlt
)(DC
*,INT
,INT
,INT
,INT
,DWORD
);
181 BOOL (*pPie
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
182 BOOL (*pPolyBezier
)(DC
*,const POINT
*,DWORD
);
183 BOOL (*pPolyBezierTo
)(DC
*,const POINT
*,DWORD
);
184 BOOL (*pPolyDraw
)(DC
*,const POINT
*,const BYTE
*,DWORD
);
185 BOOL (*pPolyPolygon
)(DC
*,const POINT
*,const INT
*,UINT
);
186 BOOL (*pPolyPolyline
)(DC
*,const POINT
*,const DWORD
*,DWORD
);
187 BOOL (*pPolygon
)(DC
*,const POINT
*,INT
);
188 BOOL (*pPolyline
)(DC
*,const POINT
*,INT
);
189 BOOL (*pPolylineTo
)(DC
*,const POINT
*,INT
);
190 UINT (*pRealizePalette
)(DC
*);
191 BOOL (*pRectangle
)(DC
*,INT
,INT
,INT
,INT
);
192 BOOL (*pRestoreDC
)(DC
*,INT
);
193 BOOL (*pRoundRect
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
);
195 BOOL (*pScaleViewportExt
)(DC
*,INT
,INT
,INT
,INT
);
196 BOOL (*pScaleWindowExt
)(DC
*,INT
,INT
,INT
,INT
);
197 BOOL (*pSelectClipPath
)(DC
*,INT
);
198 INT (*pSelectClipRgn
)(DC
*,HRGN
);
199 HANDLE (*pSelectObject
)(DC
*,HANDLE
);
200 HPALETTE (*pSelectPalette
)(DC
*,HPALETTE
,BOOL
);
201 COLORREF (*pSetBkColor
)(DC
*,COLORREF
);
202 INT (*pSetBkMode
)(DC
*,INT
);
203 VOID (*pSetDeviceClipping
)(DC
*);
204 BOOL (*pSetDeviceGammaRamp
)(DC
*,LPVOID
);
205 INT (*pSetDIBitsToDevice
)(DC
*,INT
,INT
,DWORD
,DWORD
,INT
,INT
,UINT
,UINT
,
206 LPCVOID
,const BITMAPINFO
*,UINT
);
207 INT (*pSetMapMode
)(DC
*,INT
);
208 DWORD (*pSetMapperFlags
)(DC
*,DWORD
);
209 COLORREF (*pSetPixel
)(DC
*,INT
,INT
,COLORREF
);
210 BOOL (*pSetPixelFormat
)(DC
*,INT
,const PIXELFORMATDESCRIPTOR
*);
211 INT (*pSetPolyFillMode
)(DC
*,INT
);
212 INT (*pSetROP2
)(DC
*,INT
);
213 INT (*pSetRelAbs
)(DC
*,INT
);
214 INT (*pSetStretchBltMode
)(DC
*,INT
);
215 UINT (*pSetTextAlign
)(DC
*,UINT
);
216 INT (*pSetTextCharacterExtra
)(DC
*,INT
);
217 DWORD (*pSetTextColor
)(DC
*,DWORD
);
218 INT (*pSetTextJustification
)(DC
*,INT
,INT
);
219 BOOL (*pSetViewportExt
)(DC
*,INT
,INT
);
220 BOOL (*pSetViewportOrg
)(DC
*,INT
,INT
);
221 BOOL (*pSetWindowExt
)(DC
*,INT
,INT
);
222 BOOL (*pSetWindowOrg
)(DC
*,INT
,INT
);
223 INT (*pStartDoc
)(DC
*,const DOCINFOA
*);
224 INT (*pStartPage
)(DC
*);
225 BOOL (*pStretchBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,INT
,INT
,DWORD
);
226 INT (*pStretchDIBits
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,
227 const void *,const BITMAPINFO
*,UINT
,DWORD
);
228 BOOL (*pStrokeAndFillPath
)(DC
*);
229 BOOL (*pStrokePath
)(DC
*);
230 BOOL (*pSwapBuffers
)(DC
*);
231 BOOL (*pWidenPath
)(DC
*);
234 /* LoadOEMResource types */
240 #define DCHC_INVALIDVISRGN 0x0001
241 #define DCHC_DELETEDC 0x0002
243 #define DCHF_INVALIDATEVISRGN 0x0001
244 #define DCHF_VALIDATEVISRGN 0x0002
247 #define DC_MEMORY 0x0001 /* It is a memory DC */
248 #define DC_SAVED 0x0002 /* It is a saved DC */
249 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
250 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
252 #define GDI_HEAP_SIZE 0xffe0
254 /* extra stock object: default 1x1 bitmap for memory DCs */
255 #define DEFAULT_BITMAP (STOCK_LAST+1)
257 /* Device <-> logical coords conversion */
259 /* A floating point version of the POINT structure */
260 typedef struct tagFLOAT_POINT
265 /* Rounds a floating point number to integer. The world-to-viewport
266 * transformation process is done in floating point internally. This function
267 * is then used to round these coordinates to integer values.
269 static inline INT WINE_UNUSED
GDI_ROUND(FLOAT val
)
271 return (int)floor(val
+ 0.5);
274 /* Performs a viewport-to-world transformation on the specified point (which
275 * is in floating point format). Returns TRUE if successful, else FALSE.
277 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
281 /* Check that the viewport-to-world transformation is valid */
282 if (!dc
->vport2WorldValid
)
285 /* Perform the transformation */
288 point
->x
= x
* dc
->xformVport2World
.eM11
+
289 y
* dc
->xformVport2World
.eM21
+
290 dc
->xformVport2World
.eDx
;
291 point
->y
= x
* dc
->xformVport2World
.eM12
+
292 y
* dc
->xformVport2World
.eM22
+
293 dc
->xformVport2World
.eDy
;
298 /* Performs a viewport-to-world transformation on the specified point (which
299 * is in integer format). Returns TRUE if successful, else FALSE.
301 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP(DC
*dc
, LPPOINT point
)
303 FLOAT_POINT floatPoint
;
305 /* Perform operation with floating point */
306 floatPoint
.x
=(FLOAT
)point
->x
;
307 floatPoint
.y
=(FLOAT
)point
->y
;
308 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
311 /* Round to integers */
312 point
->x
= GDI_ROUND(floatPoint
.x
);
313 point
->y
= GDI_ROUND(floatPoint
.y
);
318 /* Performs a world-to-viewport transformation on the specified point (which
319 * is in floating point format).
321 static inline void WINE_UNUSED
INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
325 /* Perform the transformation */
328 point
->x
= x
* dc
->xformWorld2Vport
.eM11
+
329 y
* dc
->xformWorld2Vport
.eM21
+
330 dc
->xformWorld2Vport
.eDx
;
331 point
->y
= x
* dc
->xformWorld2Vport
.eM12
+
332 y
* dc
->xformWorld2Vport
.eM22
+
333 dc
->xformWorld2Vport
.eDy
;
336 /* Performs a world-to-viewport transformation on the specified point (which
337 * is in integer format).
339 static inline void WINE_UNUSED
INTERNAL_LPTODP(DC
*dc
, LPPOINT point
)
341 FLOAT_POINT floatPoint
;
343 /* Perform operation with floating point */
344 floatPoint
.x
=(FLOAT
)point
->x
;
345 floatPoint
.y
=(FLOAT
)point
->y
;
346 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
348 /* Round to integers */
349 point
->x
= GDI_ROUND(floatPoint
.x
);
350 point
->y
= GDI_ROUND(floatPoint
.y
);
354 /* Performs a world-to-viewport transformation on the specified point (which
355 * is in integer format).
357 static inline INT WINE_UNUSED
INTERNAL_XWPTODP(DC
*dc
, INT x
, INT y
)
359 FLOAT_POINT floatPoint
;
361 /* Perform operation with floating point */
362 floatPoint
.x
=(FLOAT
)x
;
363 floatPoint
.y
=(FLOAT
)y
;
364 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
366 /* Round to integers */
367 return GDI_ROUND(floatPoint
.x
);
370 /* Performs a world-to-viewport transformation on the specified point (which
371 * is in integer format).
373 static inline INT WINE_UNUSED
INTERNAL_YWPTODP(DC
*dc
, INT x
, INT y
)
375 FLOAT_POINT floatPoint
;
377 /* Perform operation with floating point */
378 floatPoint
.x
=(FLOAT
)x
;
379 floatPoint
.y
=(FLOAT
)y
;
380 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
382 /* Round to integers */
383 return GDI_ROUND(floatPoint
.y
);
387 /* Performs a viewport-to-world transformation on the specified point (which
388 * is in integer format).
390 static inline INT WINE_UNUSED
INTERNAL_XDPTOWP(DC
*dc
, INT x
, INT y
)
392 FLOAT_POINT floatPoint
;
394 /* Perform operation with floating point */
395 floatPoint
.x
=(FLOAT
)x
;
396 floatPoint
.y
=(FLOAT
)y
;
397 INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
);
399 /* Round to integers */
400 return GDI_ROUND(floatPoint
.x
);
403 /* Performs a viewport-to-world transformation on the specified point (which
404 * is in integer format).
406 static inline INT WINE_UNUSED
INTERNAL_YDPTOWP(DC
*dc
, INT x
, INT y
)
408 FLOAT_POINT floatPoint
;
410 /* Perform operation with floating point */
411 floatPoint
.x
=(FLOAT
)x
;
412 floatPoint
.y
=(FLOAT
)y
;
413 INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
);
415 /* Round to integers */
416 return GDI_ROUND(floatPoint
.y
);
420 #define XDPTOLP(dc,x) \
421 (MulDiv(((x)-(dc)->vportOrgX), (dc)->wndExtX, (dc)->vportExtX) + (dc)->wndOrgX)
422 #define YDPTOLP(dc,y) \
423 (MulDiv(((y)-(dc)->vportOrgY), (dc)->wndExtY, (dc)->vportExtY) + (dc)->wndOrgY)
424 #define XLPTODP(dc,x) \
425 (MulDiv(((x)-(dc)->wndOrgX), (dc)->vportExtX, (dc)->wndExtX) + (dc)->vportOrgX)
426 #define YLPTODP(dc,y) \
427 (MulDiv(((y)-(dc)->wndOrgY), (dc)->vportExtY, (dc)->wndExtY) + (dc)->vportOrgY)
431 /* World -> Device size conversion */
433 /* Performs a world-to-viewport transformation on the specified width (which
434 * is in floating point format).
436 static inline void WINE_UNUSED
INTERNAL_XWSTODS_FLOAT(DC
*dc
, FLOAT
*width
)
438 /* Perform the transformation */
439 *width
= *width
* dc
->xformWorld2Vport
.eM11
;
442 /* Performs a world-to-viewport transformation on the specified width (which
443 * is in integer format).
445 static inline INT WINE_UNUSED
INTERNAL_XWSTODS(DC
*dc
, INT width
)
449 /* Perform operation with floating point */
450 floatWidth
= (FLOAT
)width
;
451 INTERNAL_XWSTODS_FLOAT(dc
, &floatWidth
);
453 /* Round to integers */
454 return GDI_ROUND(floatWidth
);
458 /* Performs a world-to-viewport transformation on the specified size (which
459 * is in floating point format).
461 static inline void WINE_UNUSED
INTERNAL_YWSTODS_FLOAT(DC
*dc
, FLOAT
*height
)
463 /* Perform the transformation */
464 *height
= *height
* dc
->xformWorld2Vport
.eM22
;
467 /* Performs a world-to-viewport transformation on the specified size (which
468 * is in integer format).
470 static inline INT WINE_UNUSED
INTERNAL_YWSTODS(DC
*dc
, INT height
)
474 /* Perform operation with floating point */
475 floatHeight
= (FLOAT
)height
;
476 INTERNAL_YWSTODS_FLOAT(dc
, &floatHeight
);
478 /* Round to integers */
479 return GDI_ROUND(floatHeight
);
483 /* Device <-> logical size conversion */
485 #define XDSTOLS(dc,x) \
486 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
487 #define YDSTOLS(dc,y) \
488 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
489 #define XLSTODS(dc,x) \
490 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
491 #define YLSTODS(dc,y) \
492 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
496 extern BOOL
GDI_Init(void);
497 extern void *GDI_AllocObject( WORD
, WORD
, HGDIOBJ
* );
498 extern void *GDI_ReallocObject( WORD
, HGDIOBJ
, void *obj
);
499 extern BOOL
GDI_FreeObject( HGDIOBJ
, void *obj
);
500 extern void *GDI_GetObjPtr( HGDIOBJ
, WORD
);
501 extern void GDI_ReleaseObj( HGDIOBJ
);
502 extern void GDI_CheckNotLock(void);
504 extern const DC_FUNCTIONS
*DRIVER_load_driver( LPCSTR name
);
505 extern const DC_FUNCTIONS
*DRIVER_get_driver( const DC_FUNCTIONS
*funcs
);
506 extern void DRIVER_release_driver( const DC_FUNCTIONS
*funcs
);
507 extern BOOL
DRIVER_GetDriverName( LPCSTR device
, LPSTR driver
, DWORD size
);
509 extern POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
);
511 extern DC
* DC_AllocDC( const DC_FUNCTIONS
*funcs
);
512 extern DC
* DC_GetDCPtr( HDC hdc
);
513 extern DC
* DC_GetDCUpdate( HDC hdc
);
514 extern void DC_InitDC( DC
* dc
);
515 extern void DC_UpdateXforms( DC
* dc
);
518 #define CLIP_INTERSECT 0x0001
519 #define CLIP_EXCLUDE 0x0002
520 #define CLIP_KEEPRGN 0x0004
522 /* objects/clipping.c */
523 INT
CLIPPING_IntersectClipRect( DC
* dc
, INT left
, INT top
,
524 INT right
, INT bottom
, UINT flags
);
525 INT
CLIPPING_IntersectVisRect( DC
* dc
, INT left
, INT top
,
526 INT right
, INT bottom
, BOOL exclude
);
527 extern void CLIPPING_UpdateGCRegion( DC
* dc
);
529 /* objects/enhmetafile.c */
530 extern HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, BOOL on_disk
);
532 #endif /* __WINE_GDI_H */