4 * Copyright 1993 Alexandre Julliard
14 #include "wine/wingdi16.h"
20 /* GDI objects magic numbers */
21 #define PEN_MAGIC 0x4f47
22 #define BRUSH_MAGIC 0x4f48
23 #define FONT_MAGIC 0x4f49
24 #define PALETTE_MAGIC 0x4f4a
25 #define BITMAP_MAGIC 0x4f4b
26 #define REGION_MAGIC 0x4f4c
27 #define DC_MAGIC 0x4f4d
28 #define DISABLED_DC_MAGIC 0x4f4e
29 #define META_DC_MAGIC 0x4f4f
30 #define METAFILE_MAGIC 0x4f50
31 #define METAFILE_DC_MAGIC 0x4f51
32 #define ENHMETAFILE_MAGIC 0x4f52
33 #define ENHMETAFILE_DC_MAGIC 0x4f53
35 #define MAGIC_DONTCARE 0xffff
37 typedef struct tagGDIOBJHDR
45 typedef struct tagDeviceCaps
47 WORD version; /* 0: driver version */
48 WORD technology; /* 2: device technology */
49 WORD horzSize; /* 4: width of display in mm */
50 WORD vertSize; /* 6: height of display in mm */
51 WORD horzRes; /* 8: width of display in pixels */
52 WORD vertRes; /* 10: width of display in pixels */
53 WORD bitsPixel; /* 12: bits per pixel */
54 WORD planes; /* 14: color planes */
55 WORD numBrushes; /* 16: device-specific brushes */
56 WORD numPens; /* 18: device-specific pens */
57 WORD numMarkers; /* 20: device-specific markers */
58 WORD numFonts; /* 22: device-specific fonts */
59 WORD numColors; /* 24: size of color table */
60 WORD pdeviceSize; /* 26: size of PDEVICE structure */
61 WORD curveCaps; /* 28: curve capabilities */
62 WORD lineCaps; /* 30: line capabilities */
63 WORD polygonalCaps; /* 32: polygon capabilities */
64 WORD textCaps; /* 34: text capabilities */
65 WORD clipCaps; /* 36: clipping capabilities */
66 WORD rasterCaps; /* 38: raster capabilities */
67 WORD aspectX; /* 40: relative width of device pixel */
68 WORD aspectY; /* 42: relative height of device pixel */
69 WORD aspectXY; /* 44: relative diagonal width of device pixel */
70 WORD pad1[21]; /* 46-86: reserved */
71 WORD logPixelsX; /* 88: pixels / logical X inch */
72 WORD logPixelsY; /* 90: pixels / logical Y inch */
73 WORD pad2[6]; /* 92-102: reserved */
74 WORD sizePalette; /* 104: entries in system palette */
75 WORD numReserved; /* 106: reserved entries */
76 WORD colorRes; /* 108: color resolution */
79 typedef struct tagGDI_DRIVER
81 BOOL (*pInitialize)(void);
82 void (*pFinalize)(void);
85 extern GDI_DRIVER *GDI_Driver;
87 /* Device independent DC information */
91 const DeviceCaps *devCaps;
93 HRGN16 hClipRgn; /* Clip region (may be 0) */
94 HRGN16 hVisRgn; /* Visible region (must never be 0) */
95 HRGN16 hGCClipRgn; /* GC clip region (ClipRgn AND VisRgn) */
100 HBITMAP16 hFirstBitmap; /* Bitmap selected at creation of the DC */
111 COLORREF backgroundColor;
116 WORD textAlign; /* Text alignment from SetTextAlign() */
117 short charExtra; /* Spacing from SetTextCharacterExtra() */
118 short breakTotalExtra; /* Total extra space for justification */
119 short breakCount; /* Break char. count */
120 short breakExtra; /* breakTotalExtra / breakCount */
121 short breakRem; /* breakTotalExtra % breakCount */
127 INT GraphicsMode; /* Graphics mode */
128 INT DCOrgX; /* DC origin */
130 FARPROC16 spfnPrint; /* 16bit AbortProc for Printing */
131 ABORTPROC lpfnPrint; /* 32bit AbortProc for Printing */
132 INT CursPosX; /* Current position */
135 XFORM xformWorld2Wnd; /* World-to-window transformation */
136 XFORM xformWorld2Vport; /* World-to-viewport transformation */
137 XFORM xformVport2World; /* Inverse of the above transformation */
138 BOOL vport2WorldValid; /* Is xformVport2World valid? */
144 HDC hSelf; /* Handle to this DC */
145 const struct tagDC_FUNCS *funcs; /* DC function table */
146 void *physDev; /* Physical device (driver-specific) */
151 INT wndOrgX; /* Window origin */
153 INT wndExtX; /* Window extent */
155 INT vportOrgX; /* Viewport origin */
157 INT vportExtX; /* Viewport extent */
163 /* Device functions for the Wine driver interface */
165 typedef INT (*DEVICEFONTENUMPROC)(LPENUMLOGFONT16,LPNEWTEXTMETRIC16,UINT16,LPARAM);
167 typedef struct tagDC_FUNCS
169 INT (*pAbortDoc)(DC*);
170 BOOL (*pArc)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
171 BOOL (*pBitBlt)(DC*,INT,INT,INT,INT,DC*,INT,INT,DWORD);
172 LONG (*pBitmapBits)(HBITMAP,void*,LONG,WORD);
173 BOOL (*pChord)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
174 BOOL (*pCreateBitmap)(HBITMAP);
175 BOOL (*pCreateDC)(DC*,LPCSTR,LPCSTR,LPCSTR,const DEVMODEA*);
176 HBITMAP (*pCreateDIBSection)(DC *,BITMAPINFO *,UINT,LPVOID *,HANDLE,
178 HBITMAP16 (*pCreateDIBSection16)(DC *,BITMAPINFO *,UINT16,SEGPTR *,HANDLE,
180 BOOL (*pDeleteDC)(DC*);
181 BOOL (*pDeleteObject)(HGDIOBJ);
182 DWORD (*pDeviceCapabilities)(LPCSTR,LPCSTR,WORD,LPSTR,LPDEVMODEA);
183 BOOL (*pEllipse)(DC*,INT,INT,INT,INT);
185 INT (*pEndPage)(DC*);
186 BOOL (*pEnumDeviceFonts)(DC*,LPLOGFONT16,DEVICEFONTENUMPROC,LPARAM);
187 INT (*pEscape)(DC*,INT,INT,SEGPTR,SEGPTR);
188 INT (*pExcludeClipRect)(DC*,INT,INT,INT,INT);
189 INT (*pExtDeviceMode)(HWND,LPDEVMODEA,LPSTR,LPSTR,LPDEVMODEA,LPSTR,
191 BOOL (*pExtFloodFill)(DC*,INT,INT,COLORREF,UINT);
192 BOOL (*pExtTextOut)(DC*,INT,INT,UINT,const RECT*,LPCSTR,UINT,
194 BOOL (*pFillRgn)(DC*,HRGN,HBRUSH);
195 BOOL (*pFrameRgn)(DC*,HRGN,HBRUSH,INT,INT);
196 BOOL (*pGetCharWidth)(DC*,UINT,UINT,LPINT);
197 COLORREF (*pGetPixel)(DC*,INT,INT);
198 BOOL (*pGetTextExtentPoint)(DC*,LPCSTR,INT,LPSIZE);
199 BOOL (*pGetTextMetrics)(DC*,TEXTMETRICA*);
200 INT (*pIntersectClipRect)(DC*,INT,INT,INT,INT);
201 BOOL (*pInvertRgn)(DC*,HRGN);
202 BOOL (*pLineTo)(DC*,INT,INT);
203 HANDLE (*pLoadOEMResource)(WORD,WORD);
204 BOOL (*pMoveToEx)(DC*,INT,INT,LPPOINT);
205 INT (*pOffsetClipRgn)(DC*,INT,INT);
206 BOOL (*pOffsetViewportOrg)(DC*,INT,INT);
207 BOOL (*pOffsetWindowOrg)(DC*,INT,INT);
208 BOOL (*pPaintRgn)(DC*,HRGN);
209 BOOL (*pPatBlt)(DC*,INT,INT,INT,INT,DWORD);
210 BOOL (*pPie)(DC*,INT,INT,INT,INT,INT,INT,INT,INT);
211 BOOL (*pPolyPolygon)(DC*,const POINT*,const INT*,UINT);
212 BOOL (*pPolyPolyline)(DC*,const POINT*,const DWORD*,DWORD);
213 BOOL (*pPolygon)(DC*,const POINT*,INT);
214 BOOL (*pPolyline)(DC*,const POINT*,INT);
215 BOOL (*pPolyBezier)(DC*,POINT, const POINT*,DWORD);
216 UINT (*pRealizePalette)(DC*);
217 BOOL (*pRectangle)(DC*,INT,INT,INT,INT);
218 BOOL (*pRestoreDC)(DC*,INT);
219 BOOL (*pRoundRect)(DC*,INT,INT,INT,INT,INT,INT);
221 BOOL (*pScaleViewportExt)(DC*,INT,INT,INT,INT);
222 BOOL (*pScaleWindowExt)(DC*,INT,INT,INT,INT);
223 INT (*pSelectClipRgn)(DC*,HRGN);
224 HANDLE (*pSelectObject)(DC*,HANDLE);
225 HPALETTE (*pSelectPalette)(DC*,HPALETTE,BOOL);
226 COLORREF (*pSetBkColor)(DC*,COLORREF);
227 INT (*pSetBkMode)(DC*,INT);
228 VOID (*pSetDeviceClipping)(DC*);
229 INT (*pSetDIBitsToDevice)(DC*,INT,INT,DWORD,DWORD,INT,INT,UINT,UINT,
230 LPCVOID,const BITMAPINFO*,UINT);
231 INT (*pSetMapMode)(DC*,INT);
232 DWORD (*pSetMapperFlags)(DC*,DWORD);
233 COLORREF (*pSetPixel)(DC*,INT,INT,COLORREF);
234 INT (*pSetPolyFillMode)(DC*,INT);
235 INT (*pSetROP2)(DC*,INT);
236 INT (*pSetRelAbs)(DC*,INT);
237 INT (*pSetStretchBltMode)(DC*,INT);
238 UINT (*pSetTextAlign)(DC*,UINT);
239 INT (*pSetTextCharacterExtra)(DC*,INT);
240 DWORD (*pSetTextColor)(DC*,DWORD);
241 INT (*pSetTextJustification)(DC*,INT,INT);
242 BOOL (*pSetViewportExt)(DC*,INT,INT);
243 BOOL (*pSetViewportOrg)(DC*,INT,INT);
244 BOOL (*pSetWindowExt)(DC*,INT,INT);
245 BOOL (*pSetWindowOrg)(DC*,INT,INT);
246 INT (*pStartDoc)(DC*,const DOCINFOA*);
247 INT (*pStartPage)(DC*);
248 BOOL (*pStretchBlt)(DC*,INT,INT,INT,INT,DC*,INT,INT,INT,INT,DWORD);
249 INT (*pStretchDIBits)(DC*,INT,INT,INT,INT,INT,INT,INT,INT,
250 const void *,const BITMAPINFO *,UINT,DWORD);
253 /* LoadOEMResource types */
259 #define DCHC_INVALIDVISRGN 0x0001
260 #define DCHC_DELETEDC 0x0002
262 #define DCHF_INVALIDATEVISRGN 0x0001
263 #define DCHF_VALIDATEVISRGN 0x0002
266 #define DC_MEMORY 0x0001 /* It is a memory DC */
267 #define DC_SAVED 0x0002 /* It is a saved DC */
268 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
269 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
271 /* Last 32 bytes are reserved for stock object handles */
272 #define GDI_HEAP_SIZE 0xffe0
274 /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
275 #define FIRST_STOCK_HANDLE GDI_HEAP_SIZE
277 /* Stock objects handles */
279 #define NB_STOCK_OBJECTS (DEFAULT_GUI_FONT + 1)
281 #define STOCK_WHITE_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
282 #define STOCK_LTGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
283 #define STOCK_GRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
284 #define STOCK_DKGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
285 #define STOCK_BLACK_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
286 #define STOCK_NULL_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+NULL_BRUSH))
287 #define STOCK_HOLLOW_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
288 #define STOCK_WHITE_PEN ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
289 #define STOCK_BLACK_PEN ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
290 #define STOCK_NULL_PEN ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
291 #define STOCK_OEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
292 #define STOCK_ANSI_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
293 #define STOCK_ANSI_VAR_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
294 #define STOCK_SYSTEM_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
295 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
296 #define STOCK_DEFAULT_PALETTE ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
297 #define STOCK_SYSTEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
298 #define STOCK_DEFAULT_GUI_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEFAULT_GUI_FONT))
300 #define FIRST_STOCK_FONT STOCK_OEM_FIXED_FONT
301 #define LAST_STOCK_FONT STOCK_DEFAULT_GUI_FONT
303 #define LAST_STOCK_HANDLE ((DWORD)STOCK_DEFAULT_GUI_FONT)
305 /* Device <-> logical coords conversion */
307 /* A floating point version of the POINT structure */
308 typedef struct tagFLOAT_POINT
313 /* Rounds a floating point number to integer. The world-to-viewport
314 * transformation process is done in floating point internally. This function
315 * is then used to round these coordinates to integer values.
317 static inline INT WINE_UNUSED GDI_ROUND(FLOAT val)
319 return (int)floor(val + 0.5);
322 /* Performs a viewport-to-world transformation on the specified point (which
323 * is in floating point format). Returns TRUE if successful, else FALSE.
325 static inline BOOL WINE_UNUSED INTERNAL_DPTOLP_FLOAT(DC *dc, FLOAT_POINT *point)
329 /* Check that the viewport-to-world transformation is valid */
330 if (!dc->w.vport2WorldValid)
333 /* Perform the transformation */
336 point->x = x * dc->w.xformVport2World.eM11 +
337 y * dc->w.xformVport2World.eM21 +
338 dc->w.xformVport2World.eDx;
339 point->y = x * dc->w.xformVport2World.eM12 +
340 y * dc->w.xformVport2World.eM22 +
341 dc->w.xformVport2World.eDy;
346 /* Performs a viewport-to-world transformation on the specified point (which
347 * is in integer format). Returns TRUE if successful, else FALSE.
349 static inline BOOL WINE_UNUSED INTERNAL_DPTOLP(DC *dc, LPPOINT point)
351 FLOAT_POINT floatPoint;
353 /* Perform operation with floating point */
354 floatPoint.x=(FLOAT)point->x;
355 floatPoint.y=(FLOAT)point->y;
356 if (!INTERNAL_DPTOLP_FLOAT(dc, &floatPoint))
359 /* Round to integers */
360 point->x = GDI_ROUND(floatPoint.x);
361 point->y = GDI_ROUND(floatPoint.y);
366 /* Performs a world-to-viewport transformation on the specified point (which
367 * is in floating point format).
369 static inline void WINE_UNUSED INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
373 /* Perform the transformation */
376 point->x = x * dc->w.xformWorld2Vport.eM11 +
377 y * dc->w.xformWorld2Vport.eM21 +
378 dc->w.xformWorld2Vport.eDx;
379 point->y = x * dc->w.xformWorld2Vport.eM12 +
380 y * dc->w.xformWorld2Vport.eM22 +
381 dc->w.xformWorld2Vport.eDy;
384 /* Performs a world-to-viewport transformation on the specified point (which
385 * is in integer format).
387 static inline void WINE_UNUSED INTERNAL_LPTODP(DC *dc, LPPOINT point)
389 FLOAT_POINT floatPoint;
391 /* Perform operation with floating point */
392 floatPoint.x=(FLOAT)point->x;
393 floatPoint.y=(FLOAT)point->y;
394 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
396 /* Round to integers */
397 point->x = GDI_ROUND(floatPoint.x);
398 point->y = GDI_ROUND(floatPoint.y);
401 #define XDPTOLP(dc,x) \
402 (((x)-(dc)->vportOrgX) * (dc)->wndExtX / (dc)->vportExtX+(dc)->wndOrgX)
403 #define YDPTOLP(dc,y) \
404 (((y)-(dc)->vportOrgY) * (dc)->wndExtY / (dc)->vportExtY+(dc)->wndOrgY)
405 #define XLPTODP(dc,x) \
406 (((x)-(dc)->wndOrgX) * (dc)->vportExtX / (dc)->wndExtX+(dc)->vportOrgX)
407 #define YLPTODP(dc,y) \
408 (((y)-(dc)->wndOrgY) * (dc)->vportExtY / (dc)->wndExtY+(dc)->vportOrgY)
410 /* Device <-> logical size conversion */
412 #define XDSTOLS(dc,x) \
413 ((x) * (dc)->wndExtX / (dc)->vportExtX)
414 #define YDSTOLS(dc,y) \
415 ((y) * (dc)->wndExtY / (dc)->vportExtY)
416 #define XLSTODS(dc,x) \
417 ((x) * (dc)->vportExtX / (dc)->wndExtX)
418 #define YLSTODS(dc,y) \
419 ((y) * (dc)->vportExtY / (dc)->wndExtY)
423 extern WORD GDI_HeapSel;
425 #define GDI_HEAP_ALLOC(size) \
426 LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
427 #define GDI_HEAP_ALLOC_MOVEABLE(size) \
428 LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, (size) )
429 #define GDI_HEAP_REALLOC(handle,size) \
430 LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
431 #define GDI_HEAP_FREE(handle) \
432 LOCAL_Free( GDI_HeapSel, (handle) )
434 #define GDI_HEAP_LOCK(handle) \
435 LOCAL_Lock( GDI_HeapSel, (handle) )
436 #define GDI_HEAP_LOCK_SEGPTR(handle) \
437 LOCAL_LockSegptr( GDI_HeapSel, (handle) )
438 #define GDI_HEAP_UNLOCK(handle) \
439 ((((HGDIOBJ16)(handle) >= FIRST_STOCK_HANDLE) && \
440 ((HGDIOBJ16)(handle)<=LAST_STOCK_HANDLE)) ? \
441 0 : LOCAL_Unlock( GDI_HeapSel, (handle) ))
443 extern BOOL GDI_Init(void);
444 extern HGDIOBJ16 GDI_AllocObject( WORD, WORD );
445 extern BOOL GDI_FreeObject( HGDIOBJ16 );
446 extern GDIOBJHDR * GDI_GetObjPtr( HGDIOBJ16, WORD );
448 extern BOOL DRIVER_RegisterDriver( LPCSTR name, const DC_FUNCTIONS *funcs );
449 extern const DC_FUNCTIONS *DRIVER_FindDriver( LPCSTR name );
450 extern BOOL DRIVER_UnregisterDriver( LPCSTR name );
451 extern BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size );
452 #endif /* __WINE_GDI_H */