4 * Copyright 1993 Alexandre Julliard
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 ENHMETAFILE_MAGIC 0x4f52
30 #define ENHMETAFILE_DC_MAGIC 0x4f53
32 #define MAGIC_DONTCARE 0xffff
34 typedef struct tagGDIOBJHDR
42 typedef struct tagDeviceCaps
44 WORD version; /* 0: driver version */
45 WORD technology; /* 2: device technology */
46 WORD horzSize; /* 4: width of display in mm */
47 WORD vertSize; /* 6: height of display in mm */
48 WORD horzRes; /* 8: width of display in pixels */
49 WORD vertRes; /* 10: width of display in pixels */
50 WORD bitsPixel; /* 12: bits per pixel */
51 WORD planes; /* 14: color planes */
52 WORD numBrushes; /* 16: device-specific brushes */
53 WORD numPens; /* 18: device-specific pens */
54 WORD numMarkers; /* 20: device-specific markers */
55 WORD numFonts; /* 22: device-specific fonts */
56 WORD numColors; /* 24: size of color table */
57 WORD pdeviceSize; /* 26: size of PDEVICE structure */
58 WORD curveCaps; /* 28: curve capabilities */
59 WORD lineCaps; /* 30: line capabilities */
60 WORD polygonalCaps; /* 32: polygon capabilities */
61 WORD textCaps; /* 34: text capabilities */
62 WORD clipCaps; /* 36: clipping capabilities */
63 WORD rasterCaps; /* 38: raster capabilities */
64 WORD aspectX; /* 40: relative width of device pixel */
65 WORD aspectY; /* 42: relative height of device pixel */
66 WORD aspectXY; /* 44: relative diagonal width of device pixel */
67 WORD pad1[21]; /* 46-86: reserved */
68 WORD logPixelsX; /* 88: pixels / logical X inch */
69 WORD logPixelsY; /* 90: pixels / logical Y inch */
70 WORD pad2[6]; /* 92-102: reserved */
71 WORD sizePalette; /* 104: entries in system palette */
72 WORD numReserved; /* 106: reserved entries */
73 WORD colorRes; /* 108: color resolution */
76 typedef struct tagGDI_DRIVER
78 BOOL (*pInitialize)(void);
79 void (*pFinalize)(void);
82 extern GDI_DRIVER *GDI_Driver;
84 /* Device independent DC information */
88 const DeviceCaps *devCaps;
90 HRGN16 hClipRgn; /* Clip region (may be 0) */
91 HRGN16 hVisRgn; /* Visible region (must never be 0) */
92 HRGN16 hGCClipRgn; /* GC clip region (ClipRgn AND VisRgn) */
97 HBITMAP16 hFirstBitmap; /* Bitmap selected at creation of the DC */
108 COLORREF backgroundColor;
113 WORD textAlign; /* Text alignment from SetTextAlign() */
114 short charExtra; /* Spacing from SetTextCharacterExtra() */
115 short breakTotalExtra; /* Total extra space for justification */
116 short breakCount; /* Break char. count */
117 short breakExtra; /* breakTotalExtra / breakCount */
118 short breakRem; /* breakTotalExtra % breakCount */
124 INT GraphicsMode; /* Graphics mode */
125 INT DCOrgX; /* DC origin */
127 FARPROC16 lpfnPrint; /* AbortProc for Printing */
128 INT CursPosX; /* Current position */
131 XFORM xformWorld2Wnd; /* World-to-window transformation */
132 XFORM xformWorld2Vport; /* World-to-viewport transformation */
133 XFORM xformVport2World; /* Inverse of the above transformation */
134 BOOL vport2WorldValid; /* Is xformVport2World valid? */
140 HDC hSelf; /* Handle to this DC */
141 const struct tagDC_FUNCS *funcs; /* DC function table */
142 void *physDev; /* Physical device (driver-specific) */
147 INT wndOrgX; /* Window origin */
149 INT wndExtX; /* Window extent */
151 INT vportOrgX; /* Viewport origin */
153 INT vportExtX; /* Viewport extent */
159 /* Device functions for the Wine driver interface */
161 typedef INT (*DEVICEFONTENUMPROC)(LPENUMLOGFONT16,LPNEWTEXTMETRIC16,UINT16,LPARAM);
163 typedef struct tagDC_FUNCS
165 BOOL (*pArc)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
166 BOOL (*pBitBlt)(DC*,INT,INT,INT,INT,DC*,INT,INT,DWORD);
167 LONG (*pBitmapBits)(HBITMAP,void*,LONG,WORD);
168 BOOL (*pChord)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
169 BOOL (*pCreateBitmap)(HBITMAP);
170 BOOL (*pCreateDC)(DC*,LPCSTR,LPCSTR,LPCSTR,const DEVMODE16*);
171 BOOL (*pDeleteDC)(DC*);
172 HBITMAP (*pCreateDIBSection)(DC *,BITMAPINFO *,UINT,LPVOID *,HANDLE,
174 HBITMAP16 (*pCreateDIBSection16)(DC *,BITMAPINFO *,UINT16,SEGPTR *,HANDLE,
176 BOOL (*pDeleteObject)(HGDIOBJ);
177 BOOL (*pEllipse)(DC*,INT,INT,INT,INT);
178 BOOL (*pEnumDeviceFonts)(DC*,LPLOGFONT16,DEVICEFONTENUMPROC,LPARAM);
179 INT (*pEscape)(DC*,INT,INT,SEGPTR,SEGPTR);
180 INT (*pExcludeClipRect)(DC*,INT,INT,INT,INT);
181 BOOL (*pExtFloodFill)(DC*,INT,INT,COLORREF,UINT);
182 BOOL (*pExtTextOut)(DC*,INT,INT,UINT,const RECT*,LPCSTR,UINT,
184 BOOL (*pFillRgn)(DC*,HRGN,HBRUSH);
185 BOOL (*pFrameRgn)(DC*,HRGN,HBRUSH,INT,INT);
186 BOOL (*pGetCharWidth)(DC*,UINT,UINT,LPINT);
187 COLORREF (*pGetPixel)(DC*,INT,INT);
188 BOOL (*pGetTextExtentPoint)(DC*,LPCSTR,INT,LPSIZE);
189 BOOL (*pGetTextMetrics)(DC*,TEXTMETRICA*);
190 INT (*pIntersectClipRect)(DC*,INT,INT,INT,INT);
191 BOOL (*pInvertRgn)(DC*,HRGN);
192 BOOL (*pLineTo)(DC*,INT,INT);
193 HANDLE (*pLoadOEMResource)(WORD,WORD);
194 BOOL (*pMoveToEx)(DC*,INT,INT,LPPOINT);
195 INT (*pOffsetClipRgn)(DC*,INT,INT);
196 BOOL (*pOffsetViewportOrg)(DC*,INT,INT);
197 BOOL (*pOffsetWindowOrg)(DC*,INT,INT);
198 BOOL (*pPaintRgn)(DC*,HRGN);
199 BOOL (*pPatBlt)(DC*,INT,INT,INT,INT,DWORD);
200 BOOL (*pPie)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
201 BOOL (*pPolyPolygon)(DC*,const POINT*,const INT*,UINT);
202 BOOL (*pPolyPolyline)(DC*,const POINT*,const DWORD*,DWORD);
203 BOOL (*pPolygon)(DC*,const POINT*,INT);
204 BOOL (*pPolyline)(DC*,const POINT*,INT);
205 BOOL (*pPolyBezier)(DC*,POINT, const POINT*,DWORD);
206 UINT (*pRealizePalette)(DC*);
207 BOOL (*pRectangle)(DC*,INT,INT,INT,INT);
208 BOOL (*pRestoreDC)(DC*,INT);
209 BOOL (*pRoundRect)(DC*,INT,INT,INT,INT,INT,INT);
211 BOOL (*pScaleViewportExt)(DC*,INT,INT,INT,INT);
212 BOOL (*pScaleWindowExt)(DC*,INT,INT,INT,INT);
213 INT (*pSelectClipRgn)(DC*,HRGN);
214 HANDLE (*pSelectObject)(DC*,HANDLE);
215 HPALETTE (*pSelectPalette)(DC*,HPALETTE,BOOL);
216 COLORREF (*pSetBkColor)(DC*,COLORREF);
217 INT (*pSetBkMode)(DC*,INT);
218 VOID (*pSetDeviceClipping)(DC*);
219 INT (*pSetDIBitsToDevice)(DC*,INT,INT,DWORD,DWORD,INT,INT,UINT,UINT,
220 LPCVOID,const BITMAPINFO*,UINT);
221 INT (*pSetMapMode)(DC*,INT);
222 DWORD (*pSetMapperFlags)(DC*,DWORD);
223 COLORREF (*pSetPixel)(DC*,INT,INT,COLORREF);
224 INT (*pSetPolyFillMode)(DC*,INT);
225 INT (*pSetROP2)(DC*,INT);
226 INT (*pSetRelAbs)(DC*,INT);
227 INT (*pSetStretchBltMode)(DC*,INT);
228 UINT (*pSetTextAlign)(DC*,UINT);
229 INT (*pSetTextCharacterExtra)(DC*,INT);
230 DWORD (*pSetTextColor)(DC*,DWORD);
231 INT (*pSetTextJustification)(DC*,INT,INT);
232 BOOL (*pSetViewportExt)(DC*,INT,INT);
233 BOOL (*pSetViewportOrg)(DC*,INT,INT);
234 BOOL (*pSetWindowExt)(DC*,INT,INT);
235 BOOL (*pSetWindowOrg)(DC*,INT,INT);
236 BOOL (*pStretchBlt)(DC*,INT,INT,INT,INT,DC*,INT,INT,INT,INT,DWORD);
237 INT (*pStretchDIBits)(DC*,INT,INT,INT,INT,INT,INT,INT,INT,
238 const void *,const BITMAPINFO *,UINT,DWORD);
241 /* LoadOEMResource types */
247 #define DCHC_INVALIDVISRGN 0x0001
248 #define DCHC_DELETEDC 0x0002
250 #define DCHF_INVALIDATEVISRGN 0x0001
251 #define DCHF_VALIDATEVISRGN 0x0002
254 #define DC_MEMORY 0x0001 /* It is a memory DC */
255 #define DC_SAVED 0x0002 /* It is a saved DC */
256 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
257 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
259 /* Last 32 bytes are reserved for stock object handles */
260 #define GDI_HEAP_SIZE 0xffe0
262 /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
263 #define FIRST_STOCK_HANDLE GDI_HEAP_SIZE
265 /* Stock objects handles */
267 #define NB_STOCK_OBJECTS (DEFAULT_GUI_FONT + 1)
269 #define STOCK_WHITE_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
270 #define STOCK_LTGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
271 #define STOCK_GRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
272 #define STOCK_DKGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
273 #define STOCK_BLACK_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
274 #define STOCK_NULL_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+NULL_BRUSH))
275 #define STOCK_HOLLOW_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
276 #define STOCK_WHITE_PEN ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
277 #define STOCK_BLACK_PEN ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
278 #define STOCK_NULL_PEN ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
279 #define STOCK_OEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
280 #define STOCK_ANSI_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
281 #define STOCK_ANSI_VAR_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
282 #define STOCK_SYSTEM_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
283 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
284 #define STOCK_DEFAULT_PALETTE ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
285 #define STOCK_SYSTEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
286 #define STOCK_DEFAULT_GUI_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEFAULT_GUI_FONT))
288 #define FIRST_STOCK_FONT STOCK_OEM_FIXED_FONT
289 #define LAST_STOCK_FONT STOCK_DEFAULT_GUI_FONT
291 #define LAST_STOCK_HANDLE ((DWORD)STOCK_DEFAULT_GUI_FONT)
293 /* Device <-> logical coords conversion */
295 /* A floating point version of the POINT structure */
296 typedef struct tagFLOAT_POINT
301 /* Rounds a floating point number to integer. The world-to-viewport
302 * transformation process is done in floating point internally. This function
303 * is then used to round these coordinates to integer values.
305 static __inline__ INT WINE_UNUSED GDI_ROUND(FLOAT val)
307 return (int)floor(val + 0.5);
310 /* Performs a viewport-to-world transformation on the specified point (which
311 * is in floating point format). Returns TRUE if successful, else FALSE.
313 static __inline__ BOOL WINE_UNUSED INTERNAL_DPTOLP_FLOAT(DC *dc, FLOAT_POINT *point)
317 /* Check that the viewport-to-world transformation is valid */
318 if (!dc->w.vport2WorldValid)
321 /* Perform the transformation */
324 point->x = x * dc->w.xformVport2World.eM11 +
325 y * dc->w.xformVport2World.eM21 +
326 dc->w.xformVport2World.eDx;
327 point->y = x * dc->w.xformVport2World.eM12 +
328 y * dc->w.xformVport2World.eM22 +
329 dc->w.xformVport2World.eDy;
334 /* Performs a viewport-to-world transformation on the specified point (which
335 * is in integer format). Returns TRUE if successful, else FALSE.
337 static __inline__ BOOL WINE_UNUSED INTERNAL_DPTOLP(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 if (!INTERNAL_DPTOLP_FLOAT(dc, &floatPoint))
347 /* Round to integers */
348 point->x = GDI_ROUND(floatPoint.x);
349 point->y = GDI_ROUND(floatPoint.y);
354 /* Performs a world-to-viewport transformation on the specified point (which
355 * is in floating point format).
357 static __inline__ void WINE_UNUSED INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
361 /* Perform the transformation */
364 point->x = x * dc->w.xformWorld2Vport.eM11 +
365 y * dc->w.xformWorld2Vport.eM21 +
366 dc->w.xformWorld2Vport.eDx;
367 point->y = x * dc->w.xformWorld2Vport.eM12 +
368 y * dc->w.xformWorld2Vport.eM22 +
369 dc->w.xformWorld2Vport.eDy;
372 /* Performs a world-to-viewport transformation on the specified point (which
373 * is in integer format).
375 static __inline__ void WINE_UNUSED INTERNAL_LPTODP(DC *dc, LPPOINT point)
377 FLOAT_POINT floatPoint;
379 /* Perform operation with floating point */
380 floatPoint.x=(FLOAT)point->x;
381 floatPoint.y=(FLOAT)point->y;
382 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
384 /* Round to integers */
385 point->x = GDI_ROUND(floatPoint.x);
386 point->y = GDI_ROUND(floatPoint.y);
389 #define XDPTOLP(dc,x) \
390 (((x)-(dc)->vportOrgX) * (dc)->wndExtX / (dc)->vportExtX+(dc)->wndOrgX)
391 #define YDPTOLP(dc,y) \
392 (((y)-(dc)->vportOrgY) * (dc)->wndExtY / (dc)->vportExtY+(dc)->wndOrgY)
393 #define XLPTODP(dc,x) \
394 (((x)-(dc)->wndOrgX) * (dc)->vportExtX / (dc)->wndExtX+(dc)->vportOrgX)
395 #define YLPTODP(dc,y) \
396 (((y)-(dc)->wndOrgY) * (dc)->vportExtY / (dc)->wndExtY+(dc)->vportOrgY)
398 /* Device <-> logical size conversion */
400 #define XDSTOLS(dc,x) \
401 ((x) * (dc)->wndExtX / (dc)->vportExtX)
402 #define YDSTOLS(dc,y) \
403 ((y) * (dc)->wndExtY / (dc)->vportExtY)
404 #define XLSTODS(dc,x) \
405 ((x) * (dc)->vportExtX / (dc)->wndExtX)
406 #define YLSTODS(dc,y) \
407 ((y) * (dc)->vportExtY / (dc)->wndExtY)
411 extern WORD GDI_HeapSel;
413 #define GDI_HEAP_ALLOC(size) \
414 LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
415 #define GDI_HEAP_ALLOC_MOVEABLE(size) \
416 LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, (size) )
417 #define GDI_HEAP_REALLOC(handle,size) \
418 LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
419 #define GDI_HEAP_FREE(handle) \
420 LOCAL_Free( GDI_HeapSel, (handle) )
422 #define GDI_HEAP_LOCK(handle) \
423 LOCAL_Lock( GDI_HeapSel, (handle) )
424 #define GDI_HEAP_LOCK_SEGPTR(handle) \
425 LOCAL_LockSegptr( GDI_HeapSel, (handle) )
426 #define GDI_HEAP_UNLOCK(handle) \
427 ((((HGDIOBJ16)(handle) >= FIRST_STOCK_HANDLE) && \
428 ((HGDIOBJ16)(handle)<=LAST_STOCK_HANDLE)) ? \
429 0 : LOCAL_Unlock( GDI_HeapSel, (handle) ))
431 extern BOOL GDI_Init(void);
432 extern HGDIOBJ16 GDI_AllocObject( WORD, WORD );
433 extern BOOL GDI_FreeObject( HGDIOBJ16 );
434 extern GDIOBJHDR * GDI_GetObjPtr( HGDIOBJ16, WORD );
436 extern BOOL DRIVER_RegisterDriver( LPCSTR name, const DC_FUNCTIONS *funcs );
437 extern const DC_FUNCTIONS *DRIVER_FindDriver( LPCSTR name );
438 extern BOOL DRIVER_UnregisterDriver( LPCSTR name );
440 #endif /* __WINE_GDI_H */