Allow owner to be the desktop window.
[wine/wine-kai.git] / include / gdi.h
blobfeff4adfbc6519a7cfa3f6410f4101a051a6013e
1 /*
2 * GDI definitions
4 * Copyright 1993 Alexandre Julliard
5 */
7 #ifndef __WINE_GDI_H
8 #define __WINE_GDI_H
10 #include "config.h"
12 #include "windef.h"
13 #include "wingdi.h"
14 #include "wine/wingdi16.h"
15 #include "path.h"
16 #include <math.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
45 HANDLE16 hNext;
46 WORD wMagic;
47 DWORD dwCount;
48 } GDIOBJHDR;
51 typedef BOOL16 CALLBACK (*DCHOOKPROC)(HDC16,WORD,DWORD,LPARAM);
53 typedef struct tagGdiFont *GdiFont;
55 typedef struct tagDC
57 GDIOBJHDR header;
58 HDC hSelf; /* Handle to this DC */
59 const struct tagDC_FUNCS *funcs; /* DC function table */
60 void *physDev; /* Physical device (driver-specific) */
61 INT saveLevel;
62 DWORD dwHookData;
63 FARPROC16 hookProc; /* the original SEGPTR ... */
64 DCHOOKPROC hookThunk; /* ... and the thunk to call it */
66 INT wndOrgX; /* Window origin */
67 INT wndOrgY;
68 INT wndExtX; /* Window extent */
69 INT wndExtY;
70 INT vportOrgX; /* Viewport origin */
71 INT vportOrgY;
72 INT vportExtX; /* Viewport extent */
73 INT vportExtY;
75 int flags;
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) */
79 HPEN16 hPen;
80 HBRUSH16 hBrush;
81 HFONT16 hFont;
82 HBITMAP16 hBitmap;
83 HANDLE16 hDevice;
84 HPALETTE16 hPalette;
86 GdiFont gdiFont;
87 GdiPath path;
89 WORD ROPmode;
90 WORD polyFillMode;
91 WORD stretchBltMode;
92 WORD relAbsMode;
93 WORD backgroundMode;
94 COLORREF backgroundColor;
95 COLORREF textColor;
96 short brushOrgX;
97 short brushOrgY;
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 */
106 RECT totalExtent;
107 BYTE bitsPerPixel;
109 INT MapMode;
110 INT GraphicsMode; /* Graphics mode */
111 INT DCOrgX; /* DC origin */
112 INT DCOrgY;
113 ABORTPROC pAbortProc; /* AbortProc for Printing */
114 INT CursPosX; /* Current position */
115 INT CursPosY;
116 INT ArcDirection;
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? */
121 } DC;
123 /* Device functions for the Wine driver interface */
125 typedef INT (*DEVICEFONTENUMPROC)(LPENUMLOGFONTEXW,LPNEWTEXTMETRICEXW,DWORD,
126 LPARAM);
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,
144 DWORD,DWORD);
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);
150 INT (*pEndDoc)(DC*);
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,
159 const INT*);
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);
194 INT (*pSaveDC)(DC*);
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*);
232 } DC_FUNCTIONS;
234 /* LoadOEMResource types */
235 #define OEM_BITMAP 1
236 #define OEM_CURSOR 2
237 #define OEM_ICON 3
239 /* DC hook codes */
240 #define DCHC_INVALIDVISRGN 0x0001
241 #define DCHC_DELETEDC 0x0002
243 #define DCHF_INVALIDATEVISRGN 0x0001
244 #define DCHF_VALIDATEVISRGN 0x0002
246 /* DC flags */
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
262 FLOAT x, y;
263 } FLOAT_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)
279 FLOAT x, y;
281 /* Check that the viewport-to-world transformation is valid */
282 if (!dc->vport2WorldValid)
283 return FALSE;
285 /* Perform the transformation */
286 x = point->x;
287 y = point->y;
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;
295 return TRUE;
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))
309 return FALSE;
311 /* Round to integers */
312 point->x = GDI_ROUND(floatPoint.x);
313 point->y = GDI_ROUND(floatPoint.y);
315 return TRUE;
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)
323 FLOAT x, y;
325 /* Perform the transformation */
326 x = point->x;
327 y = point->y;
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)
447 FLOAT floatWidth;
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)
472 FLOAT floatHeight;
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)
494 /* GDI local heap */
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 */