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 BOOL16 CALLBACK (*DCHOOKPROC)(HDC16,WORD,DWORD,LPARAM);
51 typedef struct tagGdiFont *GdiFont;
56 HDC hSelf; /* Handle to this DC */
57 const struct tagDC_FUNCS *funcs; /* DC function table */
58 void *physDev; /* Physical device (driver-specific) */
61 FARPROC16 hookProc; /* the original SEGPTR ... */
62 DCHOOKPROC hookThunk; /* ... and the thunk to call it */
64 INT wndOrgX; /* Window origin */
66 INT wndExtX; /* Window extent */
68 INT vportOrgX; /* Viewport origin */
70 INT vportExtX; /* Viewport extent */
74 HRGN16 hClipRgn; /* Clip region (may be 0) */
75 HRGN16 hVisRgn; /* Visible region (must never be 0) */
76 HRGN16 hGCClipRgn; /* GC clip region (ClipRgn AND VisRgn) */
92 COLORREF backgroundColor;
97 WORD textAlign; /* Text alignment from SetTextAlign() */
98 short charExtra; /* Spacing from SetTextCharacterExtra() */
99 short breakTotalExtra; /* Total extra space for justification */
100 short breakCount; /* Break char. count */
101 short breakExtra; /* breakTotalExtra / breakCount */
102 short breakRem; /* breakTotalExtra % breakCount */
108 INT GraphicsMode; /* Graphics mode */
109 INT DCOrgX; /* DC origin */
111 ABORTPROC pAbortProc; /* AbortProc for Printing */
112 INT CursPosX; /* Current position */
115 XFORM xformWorld2Wnd; /* World-to-window transformation */
116 XFORM xformWorld2Vport; /* World-to-viewport transformation */
117 XFORM xformVport2World; /* Inverse of the above transformation */
118 BOOL vport2WorldValid; /* Is xformVport2World valid? */
121 /* Device functions for the Wine driver interface */
123 typedef INT (*DEVICEFONTENUMPROC)(LPENUMLOGFONTEXW,LPNEWTEXTMETRICEXW,DWORD,
126 typedef struct tagDC_FUNCS
128 INT (*pAbortDoc)(DC*);
129 BOOL (*pAbortPath)(DC*);
130 BOOL (*pAngleArc)(DC*,INT,INT,DWORD,FLOAT,FLOAT);
131 BOOL (*pArc)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
132 BOOL (*pArcTo)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
133 BOOL (*pBeginPath)(DC*);
134 BOOL (*pBitBlt)(DC*,INT,INT,INT,INT,DC*,INT,INT,DWORD);
135 LONG (*pBitmapBits)(HBITMAP,void*,LONG,WORD);
136 INT (*pChoosePixelFormat)(DC*,const PIXELFORMATDESCRIPTOR *);
137 BOOL (*pChord)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
138 BOOL (*pCloseFigure)(DC*);
139 BOOL (*pCreateBitmap)(HBITMAP);
140 BOOL (*pCreateDC)(DC*,LPCSTR,LPCSTR,LPCSTR,const DEVMODEA*);
141 HBITMAP (*pCreateDIBSection)(DC *,BITMAPINFO *,UINT,LPVOID *,HANDLE,
143 BOOL (*pDeleteDC)(DC*);
144 BOOL (*pDeleteObject)(HGDIOBJ);
145 INT (*pDescribePixelFormat)(DC *,INT,UINT,PIXELFORMATDESCRIPTOR *);
146 DWORD (*pDeviceCapabilities)(LPSTR,LPCSTR,LPCSTR,WORD,LPSTR,LPDEVMODEA);
147 BOOL (*pEllipse)(DC*,INT,INT,INT,INT);
149 INT (*pEndPage)(DC*);
150 BOOL (*pEndPath)(DC*);
151 BOOL (*pEnumDeviceFonts)(HDC,LPLOGFONTW,DEVICEFONTENUMPROC,LPARAM);
152 INT (*pExcludeClipRect)(DC*,INT,INT,INT,INT);
153 INT (*pExtDeviceMode)(LPSTR,HWND,LPDEVMODEA,LPSTR,LPSTR,LPDEVMODEA,LPSTR,DWORD);
154 INT (*pExtEscape)(DC*,INT,INT,LPCVOID,INT,LPVOID);
155 BOOL (*pExtFloodFill)(DC*,INT,INT,COLORREF,UINT);
156 BOOL (*pExtTextOut)(DC*,INT,INT,UINT,const RECT*,LPCWSTR,UINT,
158 BOOL (*pFillPath)(DC*);
159 BOOL (*pFillRgn)(DC*,HRGN,HBRUSH);
160 BOOL (*pFlattenPath)(DC*);
161 BOOL (*pFrameRgn)(DC*,HRGN,HBRUSH,INT,INT);
162 BOOL (*pGetCharWidth)(DC*,UINT,UINT,LPINT);
163 BOOL (*pGetDCOrgEx)(DC*,LPPOINT);
164 INT (*pGetDeviceCaps)(DC*,INT);
165 BOOL (*pGetDeviceGammaRamp)(DC*,LPVOID);
166 COLORREF (*pGetPixel)(DC*,INT,INT);
167 INT (*pGetPixelFormat)(DC*);
168 BOOL (*pGetTextExtentPoint)(DC*,LPCWSTR,INT,LPSIZE);
169 BOOL (*pGetTextMetrics)(DC*,TEXTMETRICW*);
170 INT (*pIntersectClipRect)(DC*,INT,INT,INT,INT);
171 BOOL (*pInvertRgn)(DC*,HRGN);
172 BOOL (*pLineTo)(DC*,INT,INT);
173 BOOL (*pMoveTo)(DC*,INT,INT);
174 INT (*pOffsetClipRgn)(DC*,INT,INT);
175 BOOL (*pOffsetViewportOrg)(DC*,INT,INT);
176 BOOL (*pOffsetWindowOrg)(DC*,INT,INT);
177 BOOL (*pPaintRgn)(DC*,HRGN);
178 BOOL (*pPatBlt)(DC*,INT,INT,INT,INT,DWORD);
179 BOOL (*pPie)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
180 BOOL (*pPolyBezier)(DC*,const POINT*,DWORD);
181 BOOL (*pPolyBezierTo)(DC*,const POINT*,DWORD);
182 BOOL (*pPolyDraw)(DC*,const POINT*,const BYTE *,DWORD);
183 BOOL (*pPolyPolygon)(DC*,const POINT*,const INT*,UINT);
184 BOOL (*pPolyPolyline)(DC*,const POINT*,const DWORD*,DWORD);
185 BOOL (*pPolygon)(DC*,const POINT*,INT);
186 BOOL (*pPolyline)(DC*,const POINT*,INT);
187 BOOL (*pPolylineTo)(DC*,const POINT*,INT);
188 UINT (*pRealizePalette)(DC*);
189 BOOL (*pRectangle)(DC*,INT,INT,INT,INT);
190 BOOL (*pRestoreDC)(DC*,INT);
191 BOOL (*pRoundRect)(DC*,INT,INT,INT,INT,INT,INT);
193 BOOL (*pScaleViewportExt)(DC*,INT,INT,INT,INT);
194 BOOL (*pScaleWindowExt)(DC*,INT,INT,INT,INT);
195 BOOL (*pSelectClipPath)(DC*,INT);
196 INT (*pSelectClipRgn)(DC*,HRGN);
197 HANDLE (*pSelectObject)(DC*,HANDLE);
198 HPALETTE (*pSelectPalette)(DC*,HPALETTE,BOOL);
199 COLORREF (*pSetBkColor)(DC*,COLORREF);
200 INT (*pSetBkMode)(DC*,INT);
201 VOID (*pSetDeviceClipping)(DC*);
202 BOOL (*pSetDeviceGammaRamp)(DC*,LPVOID);
203 INT (*pSetDIBitsToDevice)(DC*,INT,INT,DWORD,DWORD,INT,INT,UINT,UINT,
204 LPCVOID,const BITMAPINFO*,UINT);
205 INT (*pSetMapMode)(DC*,INT);
206 DWORD (*pSetMapperFlags)(DC*,DWORD);
207 COLORREF (*pSetPixel)(DC*,INT,INT,COLORREF);
208 BOOL (*pSetPixelFormat)(DC*,INT,const PIXELFORMATDESCRIPTOR *);
209 INT (*pSetPolyFillMode)(DC*,INT);
210 INT (*pSetROP2)(DC*,INT);
211 INT (*pSetRelAbs)(DC*,INT);
212 INT (*pSetStretchBltMode)(DC*,INT);
213 UINT (*pSetTextAlign)(DC*,UINT);
214 INT (*pSetTextCharacterExtra)(DC*,INT);
215 DWORD (*pSetTextColor)(DC*,DWORD);
216 INT (*pSetTextJustification)(DC*,INT,INT);
217 BOOL (*pSetViewportExt)(DC*,INT,INT);
218 BOOL (*pSetViewportOrg)(DC*,INT,INT);
219 BOOL (*pSetWindowExt)(DC*,INT,INT);
220 BOOL (*pSetWindowOrg)(DC*,INT,INT);
221 INT (*pStartDoc)(DC*,const DOCINFOA*);
222 INT (*pStartPage)(DC*);
223 BOOL (*pStretchBlt)(DC*,INT,INT,INT,INT,DC*,INT,INT,INT,INT,DWORD);
224 INT (*pStretchDIBits)(DC*,INT,INT,INT,INT,INT,INT,INT,INT,
225 const void *,const BITMAPINFO *,UINT,DWORD);
226 BOOL (*pStrokeAndFillPath)(DC*);
227 BOOL (*pStrokePath)(DC*);
228 BOOL (*pSwapBuffers)(DC*);
229 BOOL (*pWidenPath)(DC*);
232 /* LoadOEMResource types */
238 #define DCHC_INVALIDVISRGN 0x0001
239 #define DCHC_DELETEDC 0x0002
241 #define DCHF_INVALIDATEVISRGN 0x0001
242 #define DCHF_VALIDATEVISRGN 0x0002
245 #define DC_MEMORY 0x0001 /* It is a memory DC */
246 #define DC_SAVED 0x0002 /* It is a saved DC */
247 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
248 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
250 #define GDI_HEAP_SIZE 0xffe0
252 /* extra stock object: default 1x1 bitmap for memory DCs */
253 #define DEFAULT_BITMAP (STOCK_LAST+1)
255 /* Device <-> logical coords conversion */
257 /* A floating point version of the POINT structure */
258 typedef struct tagFLOAT_POINT
263 /* Rounds a floating point number to integer. The world-to-viewport
264 * transformation process is done in floating point internally. This function
265 * is then used to round these coordinates to integer values.
267 static inline INT WINE_UNUSED GDI_ROUND(FLOAT val)
269 return (int)floor(val + 0.5);
272 /* Performs a viewport-to-world transformation on the specified point (which
273 * is in floating point format). Returns TRUE if successful, else FALSE.
275 static inline BOOL WINE_UNUSED INTERNAL_DPTOLP_FLOAT(DC *dc, FLOAT_POINT *point)
279 /* Check that the viewport-to-world transformation is valid */
280 if (!dc->vport2WorldValid)
283 /* Perform the transformation */
286 point->x = x * dc->xformVport2World.eM11 +
287 y * dc->xformVport2World.eM21 +
288 dc->xformVport2World.eDx;
289 point->y = x * dc->xformVport2World.eM12 +
290 y * dc->xformVport2World.eM22 +
291 dc->xformVport2World.eDy;
296 /* Performs a viewport-to-world transformation on the specified point (which
297 * is in integer format). Returns TRUE if successful, else FALSE.
299 static inline BOOL WINE_UNUSED INTERNAL_DPTOLP(DC *dc, LPPOINT point)
301 FLOAT_POINT floatPoint;
303 /* Perform operation with floating point */
304 floatPoint.x=(FLOAT)point->x;
305 floatPoint.y=(FLOAT)point->y;
306 if (!INTERNAL_DPTOLP_FLOAT(dc, &floatPoint))
309 /* Round to integers */
310 point->x = GDI_ROUND(floatPoint.x);
311 point->y = GDI_ROUND(floatPoint.y);
316 /* Performs a world-to-viewport transformation on the specified point (which
317 * is in floating point format).
319 static inline void WINE_UNUSED INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
323 /* Perform the transformation */
326 point->x = x * dc->xformWorld2Vport.eM11 +
327 y * dc->xformWorld2Vport.eM21 +
328 dc->xformWorld2Vport.eDx;
329 point->y = x * dc->xformWorld2Vport.eM12 +
330 y * dc->xformWorld2Vport.eM22 +
331 dc->xformWorld2Vport.eDy;
334 /* Performs a world-to-viewport transformation on the specified point (which
335 * is in integer format).
337 static inline void WINE_UNUSED INTERNAL_LPTODP(DC *dc, LPPOINT point)
339 FLOAT_POINT floatPoint;
341 /* Perform operation with floating point */
342 floatPoint.x=(FLOAT)point->x;
343 floatPoint.y=(FLOAT)point->y;
344 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
346 /* Round to integers */
347 point->x = GDI_ROUND(floatPoint.x);
348 point->y = GDI_ROUND(floatPoint.y);
352 /* Performs a world-to-viewport transformation on the specified point (which
353 * is in integer format).
355 static inline INT WINE_UNUSED INTERNAL_XWPTODP(DC *dc, INT x, INT y)
357 FLOAT_POINT floatPoint;
359 /* Perform operation with floating point */
360 floatPoint.x=(FLOAT)x;
361 floatPoint.y=(FLOAT)y;
362 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
364 /* Round to integers */
365 return GDI_ROUND(floatPoint.x);
368 /* Performs a world-to-viewport transformation on the specified point (which
369 * is in integer format).
371 static inline INT WINE_UNUSED INTERNAL_YWPTODP(DC *dc, INT x, INT y)
373 FLOAT_POINT floatPoint;
375 /* Perform operation with floating point */
376 floatPoint.x=(FLOAT)x;
377 floatPoint.y=(FLOAT)y;
378 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
380 /* Round to integers */
381 return GDI_ROUND(floatPoint.y);
385 /* Performs a viewport-to-world transformation on the specified point (which
386 * is in integer format).
388 static inline INT WINE_UNUSED INTERNAL_XDPTOWP(DC *dc, INT x, INT y)
390 FLOAT_POINT floatPoint;
392 /* Perform operation with floating point */
393 floatPoint.x=(FLOAT)x;
394 floatPoint.y=(FLOAT)y;
395 INTERNAL_DPTOLP_FLOAT(dc, &floatPoint);
397 /* Round to integers */
398 return GDI_ROUND(floatPoint.x);
401 /* Performs a viewport-to-world transformation on the specified point (which
402 * is in integer format).
404 static inline INT WINE_UNUSED INTERNAL_YDPTOWP(DC *dc, INT x, INT y)
406 FLOAT_POINT floatPoint;
408 /* Perform operation with floating point */
409 floatPoint.x=(FLOAT)x;
410 floatPoint.y=(FLOAT)y;
411 INTERNAL_DPTOLP_FLOAT(dc, &floatPoint);
413 /* Round to integers */
414 return 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)
429 /* World -> Device size conversion */
431 /* Performs a world-to-viewport transformation on the specified width (which
432 * is in floating point format).
434 static inline void WINE_UNUSED INTERNAL_XWSTODS_FLOAT(DC *dc, FLOAT *width)
436 /* Perform the transformation */
437 *width = *width * dc->xformWorld2Vport.eM11;
440 /* Performs a world-to-viewport transformation on the specified width (which
441 * is in integer format).
443 static inline INT WINE_UNUSED INTERNAL_XWSTODS(DC *dc, INT width)
447 /* Perform operation with floating point */
448 floatWidth = (FLOAT)width;
449 INTERNAL_XWSTODS_FLOAT(dc, &floatWidth);
451 /* Round to integers */
452 return GDI_ROUND(floatWidth);
456 /* Performs a world-to-viewport transformation on the specified size (which
457 * is in floating point format).
459 static inline void WINE_UNUSED INTERNAL_YWSTODS_FLOAT(DC *dc, FLOAT *height)
461 /* Perform the transformation */
462 *height = *height * dc->xformWorld2Vport.eM22;
465 /* Performs a world-to-viewport transformation on the specified size (which
466 * is in integer format).
468 static inline INT WINE_UNUSED INTERNAL_YWSTODS(DC *dc, INT height)
472 /* Perform operation with floating point */
473 floatHeight = (FLOAT)height;
474 INTERNAL_YWSTODS_FLOAT(dc, &floatHeight);
476 /* Round to integers */
477 return GDI_ROUND(floatHeight);
481 /* Device <-> logical size conversion */
483 #define XDSTOLS(dc,x) \
484 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
485 #define YDSTOLS(dc,y) \
486 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
487 #define XLSTODS(dc,x) \
488 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
489 #define YLSTODS(dc,y) \
490 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
494 extern BOOL GDI_Init(void);
495 extern void *GDI_AllocObject( WORD, WORD, HGDIOBJ * );
496 extern void *GDI_ReallocObject( WORD, HGDIOBJ, void *obj );
497 extern BOOL GDI_FreeObject( HGDIOBJ, void *obj );
498 extern void *GDI_GetObjPtr( HGDIOBJ, WORD );
499 extern void GDI_ReleaseObj( HGDIOBJ );
500 extern void GDI_CheckNotLock(void);
502 extern const DC_FUNCTIONS *DRIVER_load_driver( LPCSTR name );
503 extern const DC_FUNCTIONS *DRIVER_get_driver( const DC_FUNCTIONS *funcs );
504 extern void DRIVER_release_driver( const DC_FUNCTIONS *funcs );
505 extern BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size );
507 extern POINT *GDI_Bezier( const POINT *Points, INT count, INT *nPtsOut );
509 extern DC * DC_AllocDC( const DC_FUNCTIONS *funcs );
510 extern DC * DC_GetDCPtr( HDC hdc );
511 extern DC * DC_GetDCUpdate( HDC hdc );
512 extern void DC_InitDC( DC * dc );
513 extern void DC_UpdateXforms( DC * dc );
516 #define CLIP_INTERSECT 0x0001
517 #define CLIP_EXCLUDE 0x0002
518 #define CLIP_KEEPRGN 0x0004
520 /* objects/clipping.c */
521 INT CLIPPING_IntersectClipRect( DC * dc, INT left, INT top,
522 INT right, INT bottom, UINT flags );
523 INT CLIPPING_IntersectVisRect( DC * dc, INT left, INT top,
524 INT right, INT bottom, BOOL exclude );
525 extern void CLIPPING_UpdateGCRegion( DC * dc );
527 /* objects/enhmetafile.c */
528 extern HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk );
530 #endif /* __WINE_GDI_H */