Adapted to cursor/icon handling changes.
[wine/multimedia.git] / include / gdi.h
blob5ec178d9030c46e76e49007ef5f2be070e746f47
1 /*
2 * GDI definitions
4 * Copyright 1993 Alexandre Julliard
5 */
7 #ifndef __WINE_GDI_H
8 #define __WINE_GDI_H
10 #include "wintypes.h"
11 #include "wingdi.h"
12 #include "ldt.h"
13 #include "local.h"
14 #include "path.h"
15 #include <math.h>
17 /* GDI objects magic numbers */
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 MAGIC_DONTCARE 0xffff
31 typedef struct tagGDIOBJHDR
33 HANDLE16 hNext;
34 WORD wMagic;
35 DWORD dwCount;
36 } GDIOBJHDR;
39 typedef struct tagDeviceCaps
41 WORD version; /* 0: driver version */
42 WORD technology; /* 2: device technology */
43 WORD horzSize; /* 4: width of display in mm */
44 WORD vertSize; /* 6: height of display in mm */
45 WORD horzRes; /* 8: width of display in pixels */
46 WORD vertRes; /* 10: width of display in pixels */
47 WORD bitsPixel; /* 12: bits per pixel */
48 WORD planes; /* 14: color planes */
49 WORD numBrushes; /* 16: device-specific brushes */
50 WORD numPens; /* 18: device-specific pens */
51 WORD numMarkers; /* 20: device-specific markers */
52 WORD numFonts; /* 22: device-specific fonts */
53 WORD numColors; /* 24: size of color table */
54 WORD pdeviceSize; /* 26: size of PDEVICE structure */
55 WORD curveCaps; /* 28: curve capabilities */
56 WORD lineCaps; /* 30: line capabilities */
57 WORD polygonalCaps; /* 32: polygon capabilities */
58 WORD textCaps; /* 34: text capabilities */
59 WORD clipCaps; /* 36: clipping capabilities */
60 WORD rasterCaps; /* 38: raster capabilities */
61 WORD aspectX; /* 40: relative width of device pixel */
62 WORD aspectY; /* 42: relative height of device pixel */
63 WORD aspectXY; /* 44: relative diagonal width of device pixel */
64 WORD pad1[21]; /* 46-86: reserved */
65 WORD logPixelsX; /* 88: pixels / logical X inch */
66 WORD logPixelsY; /* 90: pixels / logical Y inch */
67 WORD pad2[6]; /* 92-102: reserved */
68 WORD sizePalette; /* 104: entries in system palette */
69 WORD numReserved; /* 106: reserved entries */
70 WORD colorRes; /* 108: color resolution */
71 } DeviceCaps;
74 /* Device independent DC information */
75 typedef struct
77 int flags;
78 const DeviceCaps *devCaps;
80 HRGN16 hClipRgn; /* Clip region (may be 0) */
81 HRGN16 hVisRgn; /* Visible region (must never be 0) */
82 HRGN16 hGCClipRgn; /* GC clip region (ClipRgn AND VisRgn) */
83 HPEN16 hPen;
84 HBRUSH16 hBrush;
85 HFONT16 hFont;
86 HBITMAP16 hBitmap;
87 HBITMAP16 hFirstBitmap; /* Bitmap selected at creation of the DC */
88 HANDLE16 hDevice;
89 HPALETTE16 hPalette;
91 GdiPath path;
93 WORD ROPmode;
94 WORD polyFillMode;
95 WORD stretchBltMode;
96 WORD relAbsMode;
97 WORD backgroundMode;
98 COLORREF backgroundColor;
99 COLORREF textColor;
100 short brushOrgX;
101 short brushOrgY;
103 WORD textAlign; /* Text alignment from SetTextAlign() */
104 short charExtra; /* Spacing from SetTextCharacterExtra() */
105 short breakTotalExtra; /* Total extra space for justification */
106 short breakCount; /* Break char. count */
107 short breakExtra; /* breakTotalExtra / breakCount */
108 short breakRem; /* breakTotalExtra % breakCount */
110 RECT totalExtent;
111 BYTE bitsPerPixel;
113 INT MapMode;
114 INT GraphicsMode; /* Graphics mode */
115 INT DCOrgX; /* DC origin */
116 INT DCOrgY;
117 FARPROC16 lpfnPrint; /* AbortProc for Printing */
118 INT CursPosX; /* Current position */
119 INT CursPosY;
120 INT ArcDirection;
121 XFORM xformWorld2Wnd; /* World-to-window transformation */
122 XFORM xformWorld2Vport; /* World-to-viewport transformation */
123 XFORM xformVport2World; /* Inverse of the above transformation */
124 BOOL vport2WorldValid; /* Is xformVport2World valid? */
125 } WIN_DC_INFO;
127 typedef struct tagDC
129 GDIOBJHDR header;
130 HDC hSelf; /* Handle to this DC */
131 const struct tagDC_FUNCS *funcs; /* DC function table */
132 void *physDev; /* Physical device (driver-specific) */
133 INT saveLevel;
134 DWORD dwHookData;
135 FARPROC16 hookProc;
137 INT wndOrgX; /* Window origin */
138 INT wndOrgY;
139 INT wndExtX; /* Window extent */
140 INT wndExtY;
141 INT vportOrgX; /* Viewport origin */
142 INT vportOrgY;
143 INT vportExtX; /* Viewport extent */
144 INT vportExtY;
146 WIN_DC_INFO w;
147 } DC;
149 /* Device functions for the Wine driver interface */
151 typedef INT (*DEVICEFONTENUMPROC)(LPENUMLOGFONT16,LPNEWTEXTMETRIC16,UINT16,LPARAM);
153 typedef struct tagDC_FUNCS
155 BOOL (*pArc)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
156 BOOL (*pBitBlt)(DC*,INT,INT,INT,INT,DC*,INT,INT,DWORD);
157 LONG (*pBitmapBits)(HBITMAP,void*,LONG,WORD);
158 BOOL (*pChord)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
159 BOOL (*pCreateBitmap)(HBITMAP);
160 BOOL (*pCreateDC)(DC*,LPCSTR,LPCSTR,LPCSTR,const DEVMODE16*);
161 BOOL (*pDeleteDC)(DC*);
162 BOOL (*pDeleteObject)(HGDIOBJ);
163 BOOL (*pEllipse)(DC*,INT,INT,INT,INT);
164 BOOL (*pEnumDeviceFonts)(DC*,LPLOGFONT16,DEVICEFONTENUMPROC,LPARAM);
165 INT (*pEscape)(DC*,INT,INT,SEGPTR,SEGPTR);
166 INT (*pExcludeClipRect)(DC*,INT,INT,INT,INT);
167 INT (*pExcludeVisRect)(DC*,INT,INT,INT,INT);
168 BOOL (*pExtFloodFill)(DC*,INT,INT,COLORREF,UINT);
169 BOOL (*pExtTextOut)(DC*,INT,INT,UINT,const RECT*,LPCSTR,UINT,const INT*);
170 BOOL (*pGetCharWidth)(DC*,UINT,UINT,LPINT);
171 COLORREF (*pGetPixel)(DC*,INT,INT);
172 BOOL (*pGetTextExtentPoint)(DC*,LPCSTR,INT,LPSIZE);
173 BOOL (*pGetTextMetrics)(DC*,TEXTMETRICA*);
174 INT (*pIntersectClipRect)(DC*,INT,INT,INT,INT);
175 INT (*pIntersectVisRect)(DC*,INT,INT,INT,INT);
176 BOOL (*pLineTo)(DC*,INT,INT);
177 HANDLE (*pLoadOEMResource)(WORD,WORD);
178 BOOL (*pMoveToEx)(DC*,INT,INT,LPPOINT);
179 INT (*pOffsetClipRgn)(DC*,INT,INT);
180 BOOL (*pOffsetViewportOrg)(DC*,INT,INT);
181 BOOL (*pOffsetWindowOrg)(DC*,INT,INT);
182 BOOL (*pPaintRgn)(DC*,HRGN);
183 BOOL (*pPatBlt)(DC*,INT,INT,INT,INT,DWORD);
184 BOOL (*pPie)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
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 (*pPolyBezier)(DC*,POINT, const POINT*,DWORD);
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 INT (*pSelectClipRgn)(DC*,HRGN);
198 HANDLE (*pSelectObject)(DC*,HANDLE);
199 HPALETTE (*pSelectPalette)(DC*,HPALETTE,BOOL);
200 COLORREF (*pSetBkColor)(DC*,COLORREF);
201 WORD (*pSetBkMode)(DC*,WORD);
202 VOID (*pSetDeviceClipping)(DC*);
203 INT (*pSetDIBitsToDevice)(DC*,INT,INT,DWORD,DWORD,INT,INT,UINT,UINT,LPCVOID,const BITMAPINFO*,UINT);
204 INT (*pSetMapMode)(DC*,INT);
205 DWORD (*pSetMapperFlags)(DC*,DWORD);
206 COLORREF (*pSetPixel)(DC*,INT,INT,COLORREF);
207 WORD (*pSetPolyFillMode)(DC*,WORD);
208 WORD (*pSetROP2)(DC*,WORD);
209 WORD (*pSetRelAbs)(DC*,WORD);
210 WORD (*pSetStretchBltMode)(DC*,WORD);
211 WORD (*pSetTextAlign)(DC*,WORD);
212 INT (*pSetTextCharacterExtra)(DC*,INT);
213 DWORD (*pSetTextColor)(DC*,DWORD);
214 INT (*pSetTextJustification)(DC*,INT,INT);
215 BOOL (*pSetViewportExt)(DC*,INT,INT);
216 BOOL (*pSetViewportOrg)(DC*,INT,INT);
217 BOOL (*pSetWindowExt)(DC*,INT,INT);
218 BOOL (*pSetWindowOrg)(DC*,INT,INT);
219 BOOL (*pStretchBlt)(DC*,INT,INT,INT,INT,DC*,INT,INT,INT,INT,DWORD);
220 INT (*pStretchDIBits)(DC*,INT,INT,INT,INT,INT,INT,INT,INT,const void *,const BITMAPINFO *,UINT,DWORD);
221 } DC_FUNCTIONS;
223 /* LoadOEMResource types */
224 #define OEM_BITMAP 1
225 #define OEM_CURSOR 2
226 #define OEM_ICON 3
228 /* DC hook codes */
229 #define DCHC_INVALIDVISRGN 0x0001
230 #define DCHC_DELETEDC 0x0002
232 #define DCHF_INVALIDATEVISRGN 0x0001
233 #define DCHF_VALIDATEVISRGN 0x0002
235 /* DC flags */
236 #define DC_MEMORY 0x0001 /* It is a memory DC */
237 #define DC_SAVED 0x0002 /* It is a saved DC */
238 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
239 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
241 /* Last 32 bytes are reserved for stock object handles */
242 #define GDI_HEAP_SIZE 0xffe0
244 /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
245 #define FIRST_STOCK_HANDLE GDI_HEAP_SIZE
247 /* Stock objects handles */
249 #define NB_STOCK_OBJECTS (DEFAULT_GUI_FONT + 1)
251 #define STOCK_WHITE_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
252 #define STOCK_LTGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
253 #define STOCK_GRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
254 #define STOCK_DKGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
255 #define STOCK_BLACK_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
256 #define STOCK_NULL_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+NULL_BRUSH))
257 #define STOCK_HOLLOW_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
258 #define STOCK_WHITE_PEN ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
259 #define STOCK_BLACK_PEN ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
260 #define STOCK_NULL_PEN ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
261 #define STOCK_OEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
262 #define STOCK_ANSI_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
263 #define STOCK_ANSI_VAR_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
264 #define STOCK_SYSTEM_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
265 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
266 #define STOCK_DEFAULT_PALETTE ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
267 #define STOCK_SYSTEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
268 #define STOCK_DEFAULT_GUI_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEFAULT_GUI_FONT))
270 #define FIRST_STOCK_FONT STOCK_OEM_FIXED_FONT
271 #define LAST_STOCK_FONT STOCK_DEFAULT_GUI_FONT
273 #define LAST_STOCK_HANDLE ((DWORD)STOCK_DEFAULT_GUI_FONT)
275 /* Device <-> logical coords conversion */
277 /* A floating point version of the POINT structure */
278 typedef struct tagFLOAT_POINT
280 FLOAT x, y;
281 } FLOAT_POINT;
283 /* Rounds a floating point number to integer. The world-to-viewport
284 * transformation process is done in floating point internally. This function
285 * is then used to round these coordinates to integer values.
287 static __inline__ INT WINE_UNUSED GDI_ROUND(FLOAT val)
289 return (int)floor(val + 0.5);
292 /* Performs a viewport-to-world transformation on the specified point (which
293 * is in floating point format). Returns TRUE if successful, else FALSE.
295 static __inline__ BOOL WINE_UNUSED INTERNAL_DPTOLP_FLOAT(DC *dc, FLOAT_POINT *point)
297 FLOAT x, y;
299 /* Check that the viewport-to-world transformation is valid */
300 if (!dc->w.vport2WorldValid)
301 return FALSE;
303 /* Perform the transformation */
304 x = point->x;
305 y = point->y;
306 point->x = x * dc->w.xformVport2World.eM11 +
307 y * dc->w.xformVport2World.eM21 +
308 dc->w.xformVport2World.eDx;
309 point->y = x * dc->w.xformVport2World.eM12 +
310 y * dc->w.xformVport2World.eM22 +
311 dc->w.xformVport2World.eDy;
313 return TRUE;
316 /* Performs a viewport-to-world transformation on the specified point (which
317 * is in integer format). Returns TRUE if successful, else FALSE.
319 static __inline__ BOOL WINE_UNUSED INTERNAL_DPTOLP(DC *dc, LPPOINT point)
321 FLOAT_POINT floatPoint;
323 /* Perform operation with floating point */
324 floatPoint.x=(FLOAT)point->x;
325 floatPoint.y=(FLOAT)point->y;
326 if (!INTERNAL_DPTOLP_FLOAT(dc, &floatPoint))
327 return FALSE;
329 /* Round to integers */
330 point->x = GDI_ROUND(floatPoint.x);
331 point->y = GDI_ROUND(floatPoint.y);
333 return TRUE;
336 /* Performs a world-to-viewport transformation on the specified point (which
337 * is in floating point format).
339 static __inline__ void WINE_UNUSED INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
341 FLOAT x, y;
343 /* Perform the transformation */
344 x = point->x;
345 y = point->y;
346 point->x = x * dc->w.xformWorld2Vport.eM11 +
347 y * dc->w.xformWorld2Vport.eM21 +
348 dc->w.xformWorld2Vport.eDx;
349 point->y = x * dc->w.xformWorld2Vport.eM12 +
350 y * dc->w.xformWorld2Vport.eM22 +
351 dc->w.xformWorld2Vport.eDy;
354 /* Performs a world-to-viewport transformation on the specified point (which
355 * is in integer format).
357 static __inline__ void WINE_UNUSED INTERNAL_LPTODP(DC *dc, LPPOINT point)
359 FLOAT_POINT floatPoint;
361 /* Perform operation with floating point */
362 floatPoint.x=(FLOAT)point->x;
363 floatPoint.y=(FLOAT)point->y;
364 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
366 /* Round to integers */
367 point->x = GDI_ROUND(floatPoint.x);
368 point->y = GDI_ROUND(floatPoint.y);
371 #define XDPTOLP(dc,x) \
372 (((x)-(dc)->vportOrgX) * (dc)->wndExtX / (dc)->vportExtX+(dc)->wndOrgX)
373 #define YDPTOLP(dc,y) \
374 (((y)-(dc)->vportOrgY) * (dc)->wndExtY / (dc)->vportExtY+(dc)->wndOrgY)
375 #define XLPTODP(dc,x) \
376 (((x)-(dc)->wndOrgX) * (dc)->vportExtX / (dc)->wndExtX+(dc)->vportOrgX)
377 #define YLPTODP(dc,y) \
378 (((y)-(dc)->wndOrgY) * (dc)->vportExtY / (dc)->wndExtY+(dc)->vportOrgY)
380 /* Device <-> logical size conversion */
382 #define XDSTOLS(dc,x) \
383 ((x) * (dc)->wndExtX / (dc)->vportExtX)
384 #define YDSTOLS(dc,y) \
385 ((y) * (dc)->wndExtY / (dc)->vportExtY)
386 #define XLSTODS(dc,x) \
387 ((x) * (dc)->vportExtX / (dc)->wndExtX)
388 #define YLSTODS(dc,y) \
389 ((y) * (dc)->vportExtY / (dc)->wndExtY)
391 /* GDI local heap */
393 extern WORD GDI_HeapSel;
395 #define GDI_HEAP_ALLOC(size) \
396 LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
397 #define GDI_HEAP_ALLOC_MOVEABLE(size) \
398 LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, (size) )
399 #define GDI_HEAP_REALLOC(handle,size) \
400 LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
401 #define GDI_HEAP_FREE(handle) \
402 LOCAL_Free( GDI_HeapSel, (handle) )
404 #define GDI_HEAP_LOCK(handle) \
405 LOCAL_Lock( GDI_HeapSel, (handle) )
406 #define GDI_HEAP_LOCK_SEGPTR(handle) \
407 LOCAL_LockSegptr( GDI_HeapSel, (handle) )
408 #define GDI_HEAP_UNLOCK(handle) \
409 ((((HGDIOBJ16)(handle) >= FIRST_STOCK_HANDLE) && \
410 ((HGDIOBJ16)(handle)<=LAST_STOCK_HANDLE)) ? \
411 0 : LOCAL_Unlock( GDI_HeapSel, (handle) ))
413 extern BOOL GDI_Init(void);
414 extern HGDIOBJ16 GDI_AllocObject( WORD, WORD );
415 extern BOOL GDI_FreeObject( HGDIOBJ16 );
416 extern GDIOBJHDR * GDI_GetObjPtr( HGDIOBJ16, WORD );
418 extern BOOL DRIVER_RegisterDriver( LPCSTR name, const DC_FUNCTIONS *funcs );
419 extern const DC_FUNCTIONS *DRIVER_FindDriver( LPCSTR name );
420 extern BOOL DRIVER_UnregisterDriver( LPCSTR name );
422 #endif /* __WINE_GDI_H */