Added the possibility (it is optional for backward compability) to
[wine.git] / include / gdi.h
blob5daf3d052aafe53e03c34f36743927f2eff35ccd
1 /*
2 * GDI definitions
4 * Copyright 1993 Alexandre Julliard
5 */
7 #ifndef __WINE_GDI_H
8 #define __WINE_GDI_H
10 #include "windef.h"
11 #include "wingdi.h"
12 #include "wine/wingdi16.h"
13 #include "path.h"
14 #include <math.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
43 HANDLE16 hNext;
44 WORD wMagic;
45 DWORD dwCount;
46 } GDIOBJHDR;
49 typedef struct tagGdiFont *GdiFont;
51 typedef struct tagDC
53 GDIOBJHDR header;
54 HDC hSelf; /* Handle to this DC */
55 const struct tagDC_FUNCS *funcs; /* DC function table */
56 void *physDev; /* Physical device (driver-specific) */
57 INT saveLevel;
58 DWORD dwHookData;
59 FARPROC16 hookProc; /* the original SEGPTR ... */
60 DCHOOKPROC hookThunk; /* ... and the thunk to call it */
62 INT wndOrgX; /* Window origin */
63 INT wndOrgY;
64 INT wndExtX; /* Window extent */
65 INT wndExtY;
66 INT vportOrgX; /* Viewport origin */
67 INT vportOrgY;
68 INT vportExtX; /* Viewport extent */
69 INT vportExtY;
71 int flags;
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) */
75 HPEN16 hPen;
76 HBRUSH16 hBrush;
77 HFONT16 hFont;
78 HBITMAP16 hBitmap;
79 HANDLE16 hDevice;
80 HPALETTE16 hPalette;
82 GdiFont gdiFont;
83 GdiPath path;
85 WORD ROPmode;
86 WORD polyFillMode;
87 WORD stretchBltMode;
88 WORD relAbsMode;
89 WORD backgroundMode;
90 COLORREF backgroundColor;
91 COLORREF textColor;
92 short brushOrgX;
93 short brushOrgY;
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 */
102 RECT totalExtent;
103 BYTE bitsPerPixel;
105 INT MapMode;
106 INT GraphicsMode; /* Graphics mode */
107 INT DCOrgX; /* DC origin */
108 INT DCOrgY;
109 ABORTPROC pAbortProc; /* AbortProc for Printing */
110 ABORTPROC16 pAbortProc16;
111 INT CursPosX; /* Current position */
112 INT CursPosY;
113 INT ArcDirection;
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? */
118 } DC;
120 /* Device functions for the Wine driver interface */
122 typedef INT (*DEVICEFONTENUMPROC)(LPENUMLOGFONTEXW,LPNEWTEXTMETRICEXW,DWORD,
123 LPARAM);
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,
141 DWORD,DWORD);
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);
147 INT (*pEndDoc)(DC*);
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,
156 const INT*);
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);
191 INT (*pSaveDC)(DC*);
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*);
229 } DC_FUNCTIONS;
231 /* DC hook codes */
232 #define DCHC_INVALIDVISRGN 0x0001
233 #define DCHC_DELETEDC 0x0002
235 #define DCHF_INVALIDATEVISRGN 0x0001
236 #define DCHF_VALIDATEVISRGN 0x0002
238 /* DC flags */
239 #define DC_MEMORY 0x0001 /* It is a memory DC */
240 #define DC_SAVED 0x0002 /* It is a saved DC */
241 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
242 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
244 #define GDI_HEAP_SIZE 0xffe0
246 /* extra stock object: default 1x1 bitmap for memory DCs */
247 #define DEFAULT_BITMAP (STOCK_LAST+1)
249 /* Device <-> logical coords conversion */
251 /* A floating point version of the POINT structure */
252 typedef struct tagFLOAT_POINT
254 FLOAT x, y;
255 } FLOAT_POINT;
257 /* Rounds a floating point number to integer. The world-to-viewport
258 * transformation process is done in floating point internally. This function
259 * is then used to round these coordinates to integer values.
261 static inline INT WINE_UNUSED GDI_ROUND(FLOAT val)
263 return (int)floor(val + 0.5);
266 /* Performs a viewport-to-world transformation on the specified point (which
267 * is in floating point format). Returns TRUE if successful, else FALSE.
269 static inline BOOL WINE_UNUSED INTERNAL_DPTOLP_FLOAT(DC *dc, FLOAT_POINT *point)
271 FLOAT x, y;
273 /* Check that the viewport-to-world transformation is valid */
274 if (!dc->vport2WorldValid)
275 return FALSE;
277 /* Perform the transformation */
278 x = point->x;
279 y = point->y;
280 point->x = x * dc->xformVport2World.eM11 +
281 y * dc->xformVport2World.eM21 +
282 dc->xformVport2World.eDx;
283 point->y = x * dc->xformVport2World.eM12 +
284 y * dc->xformVport2World.eM22 +
285 dc->xformVport2World.eDy;
287 return TRUE;
290 /* Performs a viewport-to-world transformation on the specified point (which
291 * is in integer format). Returns TRUE if successful, else FALSE.
293 static inline BOOL WINE_UNUSED INTERNAL_DPTOLP(DC *dc, LPPOINT point)
295 FLOAT_POINT floatPoint;
297 /* Perform operation with floating point */
298 floatPoint.x=(FLOAT)point->x;
299 floatPoint.y=(FLOAT)point->y;
300 if (!INTERNAL_DPTOLP_FLOAT(dc, &floatPoint))
301 return FALSE;
303 /* Round to integers */
304 point->x = GDI_ROUND(floatPoint.x);
305 point->y = GDI_ROUND(floatPoint.y);
307 return TRUE;
310 /* Performs a world-to-viewport transformation on the specified point (which
311 * is in floating point format).
313 static inline void WINE_UNUSED INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
315 FLOAT x, y;
317 /* Perform the transformation */
318 x = point->x;
319 y = point->y;
320 point->x = x * dc->xformWorld2Vport.eM11 +
321 y * dc->xformWorld2Vport.eM21 +
322 dc->xformWorld2Vport.eDx;
323 point->y = x * dc->xformWorld2Vport.eM12 +
324 y * dc->xformWorld2Vport.eM22 +
325 dc->xformWorld2Vport.eDy;
328 /* Performs a world-to-viewport transformation on the specified point (which
329 * is in integer format).
331 static inline void WINE_UNUSED INTERNAL_LPTODP(DC *dc, LPPOINT point)
333 FLOAT_POINT floatPoint;
335 /* Perform operation with floating point */
336 floatPoint.x=(FLOAT)point->x;
337 floatPoint.y=(FLOAT)point->y;
338 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
340 /* Round to integers */
341 point->x = GDI_ROUND(floatPoint.x);
342 point->y = GDI_ROUND(floatPoint.y);
346 /* Performs a world-to-viewport transformation on the specified point (which
347 * is in integer format).
349 static inline INT WINE_UNUSED INTERNAL_XWPTODP(DC *dc, INT x, INT y)
351 FLOAT_POINT floatPoint;
353 /* Perform operation with floating point */
354 floatPoint.x=(FLOAT)x;
355 floatPoint.y=(FLOAT)y;
356 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
358 /* Round to integers */
359 return GDI_ROUND(floatPoint.x);
362 /* Performs a world-to-viewport transformation on the specified point (which
363 * is in integer format).
365 static inline INT WINE_UNUSED INTERNAL_YWPTODP(DC *dc, INT x, INT y)
367 FLOAT_POINT floatPoint;
369 /* Perform operation with floating point */
370 floatPoint.x=(FLOAT)x;
371 floatPoint.y=(FLOAT)y;
372 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
374 /* Round to integers */
375 return GDI_ROUND(floatPoint.y);
379 /* Performs a viewport-to-world transformation on the specified point (which
380 * is in integer format).
382 static inline INT WINE_UNUSED INTERNAL_XDPTOWP(DC *dc, INT x, INT y)
384 FLOAT_POINT floatPoint;
386 /* Perform operation with floating point */
387 floatPoint.x=(FLOAT)x;
388 floatPoint.y=(FLOAT)y;
389 INTERNAL_DPTOLP_FLOAT(dc, &floatPoint);
391 /* Round to integers */
392 return GDI_ROUND(floatPoint.x);
395 /* Performs a viewport-to-world transformation on the specified point (which
396 * is in integer format).
398 static inline INT WINE_UNUSED INTERNAL_YDPTOWP(DC *dc, INT x, INT y)
400 FLOAT_POINT floatPoint;
402 /* Perform operation with floating point */
403 floatPoint.x=(FLOAT)x;
404 floatPoint.y=(FLOAT)y;
405 INTERNAL_DPTOLP_FLOAT(dc, &floatPoint);
407 /* Round to integers */
408 return GDI_ROUND(floatPoint.y);
412 #define XDPTOLP(dc,x) \
413 (MulDiv(((x)-(dc)->vportOrgX), (dc)->wndExtX, (dc)->vportExtX) + (dc)->wndOrgX)
414 #define YDPTOLP(dc,y) \
415 (MulDiv(((y)-(dc)->vportOrgY), (dc)->wndExtY, (dc)->vportExtY) + (dc)->wndOrgY)
416 #define XLPTODP(dc,x) \
417 (MulDiv(((x)-(dc)->wndOrgX), (dc)->vportExtX, (dc)->wndExtX) + (dc)->vportOrgX)
418 #define YLPTODP(dc,y) \
419 (MulDiv(((y)-(dc)->wndOrgY), (dc)->vportExtY, (dc)->wndExtY) + (dc)->vportOrgY)
423 /* World -> Device size conversion */
425 /* Performs a world-to-viewport transformation on the specified width (which
426 * is in floating point format).
428 static inline void WINE_UNUSED INTERNAL_XWSTODS_FLOAT(DC *dc, FLOAT *width)
430 /* Perform the transformation */
431 *width = *width * dc->xformWorld2Vport.eM11;
434 /* Performs a world-to-viewport transformation on the specified width (which
435 * is in integer format).
437 static inline INT WINE_UNUSED INTERNAL_XWSTODS(DC *dc, INT width)
439 FLOAT floatWidth;
441 /* Perform operation with floating point */
442 floatWidth = (FLOAT)width;
443 INTERNAL_XWSTODS_FLOAT(dc, &floatWidth);
445 /* Round to integers */
446 return GDI_ROUND(floatWidth);
450 /* Performs a world-to-viewport transformation on the specified size (which
451 * is in floating point format).
453 static inline void WINE_UNUSED INTERNAL_YWSTODS_FLOAT(DC *dc, FLOAT *height)
455 /* Perform the transformation */
456 *height = *height * dc->xformWorld2Vport.eM22;
459 /* Performs a world-to-viewport transformation on the specified size (which
460 * is in integer format).
462 static inline INT WINE_UNUSED INTERNAL_YWSTODS(DC *dc, INT height)
464 FLOAT floatHeight;
466 /* Perform operation with floating point */
467 floatHeight = (FLOAT)height;
468 INTERNAL_YWSTODS_FLOAT(dc, &floatHeight);
470 /* Round to integers */
471 return GDI_ROUND(floatHeight);
475 /* Device <-> logical size conversion */
477 #define XDSTOLS(dc,x) \
478 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
479 #define YDSTOLS(dc,y) \
480 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
481 #define XLSTODS(dc,x) \
482 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
483 #define YLSTODS(dc,y) \
484 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
486 /* GDI local heap */
488 extern BOOL GDI_Init(void);
489 extern void *GDI_AllocObject( WORD, WORD, HGDIOBJ * );
490 extern void *GDI_ReallocObject( WORD, HGDIOBJ, void *obj );
491 extern BOOL GDI_FreeObject( HGDIOBJ, void *obj );
492 extern void *GDI_GetObjPtr( HGDIOBJ, WORD );
493 extern void GDI_ReleaseObj( HGDIOBJ );
494 extern void GDI_CheckNotLock(void);
496 extern const DC_FUNCTIONS *DRIVER_load_driver( LPCSTR name );
497 extern const DC_FUNCTIONS *DRIVER_get_driver( const DC_FUNCTIONS *funcs );
498 extern void DRIVER_release_driver( const DC_FUNCTIONS *funcs );
499 extern BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size );
501 extern POINT *GDI_Bezier( const POINT *Points, INT count, INT *nPtsOut );
503 extern DC * DC_AllocDC( const DC_FUNCTIONS *funcs );
504 extern DC * DC_GetDCPtr( HDC hdc );
505 extern DC * DC_GetDCUpdate( HDC hdc );
506 extern void DC_InitDC( DC * dc );
507 extern void DC_UpdateXforms( DC * dc );
510 #define CLIP_INTERSECT 0x0001
511 #define CLIP_EXCLUDE 0x0002
512 #define CLIP_KEEPRGN 0x0004
514 /* objects/clipping.c */
515 INT CLIPPING_IntersectClipRect( DC * dc, INT left, INT top,
516 INT right, INT bottom, UINT flags );
517 INT CLIPPING_IntersectVisRect( DC * dc, INT left, INT top,
518 INT right, INT bottom, BOOL exclude );
519 extern void CLIPPING_UpdateGCRegion( DC * dc );
521 /* objects/enhmetafile.c */
522 extern HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk );
524 #endif /* __WINE_GDI_H */