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) */
110 COLORREF backgroundColor
;
115 WORD textAlign
; /* Text alignment from SetTextAlign() */
116 short charExtra
; /* Spacing from SetTextCharacterExtra() */
117 short breakTotalExtra
; /* Total extra space for justification */
118 short breakCount
; /* Break char. count */
119 short breakExtra
; /* breakTotalExtra / breakCount */
120 short breakRem
; /* breakTotalExtra % breakCount */
126 INT GraphicsMode
; /* Graphics mode */
127 INT DCOrgX
; /* DC origin */
129 ABORTPROC pAbortProc
; /* AbortProc for Printing */
130 INT CursPosX
; /* Current position */
133 XFORM xformWorld2Wnd
; /* World-to-window transformation */
134 XFORM xformWorld2Vport
; /* World-to-viewport transformation */
135 XFORM xformVport2World
; /* Inverse of the above transformation */
136 BOOL vport2WorldValid
; /* Is xformVport2World valid? */
140 typedef BOOL16 (CALLBACK
*DCHOOKPROC
)(HDC16
,WORD
,DWORD
,LPARAM
);
145 HDC hSelf
; /* Handle to this DC */
146 const struct tagDC_FUNCS
*funcs
; /* DC function table */
147 void *physDev
; /* Physical device (driver-specific) */
150 FARPROC16 hookProc
; /* the original SEGPTR ... */
151 DCHOOKPROC hookThunk
; /* ... and the thunk to call it */
153 INT wndOrgX
; /* Window origin */
155 INT wndExtX
; /* Window extent */
157 INT vportOrgX
; /* Viewport origin */
159 INT vportExtX
; /* Viewport extent */
165 /* Device functions for the Wine driver interface */
167 typedef INT (*DEVICEFONTENUMPROC
)(LPENUMLOGFONTEX16
,LPNEWTEXTMETRIC16
,UINT16
,LPARAM
);
169 typedef struct tagDC_FUNCS
171 INT (*pAbortDoc
)(DC
*);
172 BOOL (*pAbortPath
)(DC
*);
173 BOOL (*pAngleArc
)(DC
*,INT
,INT
,DWORD
,FLOAT
,FLOAT
);
174 BOOL (*pArc
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
175 BOOL (*pArcTo
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
176 BOOL (*pBeginPath
)(DC
*);
177 BOOL (*pBitBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,DWORD
);
178 LONG (*pBitmapBits
)(HBITMAP
,void*,LONG
,WORD
);
179 BOOL (*pChord
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
180 BOOL (*pCloseFigure
)(DC
*);
181 BOOL (*pCreateBitmap
)(HBITMAP
);
182 BOOL (*pCreateDC
)(DC
*,LPCSTR
,LPCSTR
,LPCSTR
,const DEVMODEA
*);
183 HBITMAP (*pCreateDIBSection
)(DC
*,BITMAPINFO
*,UINT
,LPVOID
*,HANDLE
,
185 HBITMAP16 (*pCreateDIBSection16
)(DC
*,BITMAPINFO
*,UINT16
,SEGPTR
*,HANDLE
,
187 BOOL (*pDeleteDC
)(DC
*);
188 BOOL (*pDeleteObject
)(HGDIOBJ
);
189 DWORD (*pDeviceCapabilities
)(LPSTR
,LPCSTR
,LPCSTR
,WORD
,LPSTR
,LPDEVMODEA
);
190 BOOL (*pEllipse
)(DC
*,INT
,INT
,INT
,INT
);
192 INT (*pEndPage
)(DC
*);
193 BOOL (*pEndPath
)(DC
*);
194 BOOL (*pEnumDeviceFonts
)(DC
*,LPLOGFONT16
,DEVICEFONTENUMPROC
,LPARAM
);
195 INT (*pEscape
)(DC
*,INT
,INT
,SEGPTR
,SEGPTR
);
196 INT (*pExcludeClipRect
)(DC
*,INT
,INT
,INT
,INT
);
197 INT (*pExtDeviceMode
)(LPSTR
,HWND
,LPDEVMODEA
,LPSTR
,LPSTR
,LPDEVMODEA
,
199 BOOL (*pExtFloodFill
)(DC
*,INT
,INT
,COLORREF
,UINT
);
200 BOOL (*pExtTextOut
)(DC
*,INT
,INT
,UINT
,const RECT
*,LPCWSTR
,UINT
,
202 BOOL (*pFillPath
)(DC
*);
203 BOOL (*pFillRgn
)(DC
*,HRGN
,HBRUSH
);
204 BOOL (*pFlattenPath
)(DC
*);
205 BOOL (*pFrameRgn
)(DC
*,HRGN
,HBRUSH
,INT
,INT
);
206 BOOL (*pGetCharWidth
)(DC
*,UINT
,UINT
,LPINT
);
207 BOOL (*pGetDCOrgEx
)(DC
*,LPPOINT
);
208 COLORREF (*pGetPixel
)(DC
*,INT
,INT
);
209 BOOL (*pGetTextExtentPoint
)(DC
*,LPCWSTR
,INT
,LPSIZE
);
210 BOOL (*pGetTextMetrics
)(DC
*,TEXTMETRICA
*);
211 INT (*pIntersectClipRect
)(DC
*,INT
,INT
,INT
,INT
);
212 BOOL (*pInvertRgn
)(DC
*,HRGN
);
213 BOOL (*pLineTo
)(DC
*,INT
,INT
);
214 HANDLE (*pLoadOEMResource
)(WORD
,WORD
);
215 BOOL (*pMoveToEx
)(DC
*,INT
,INT
,LPPOINT
);
216 INT (*pOffsetClipRgn
)(DC
*,INT
,INT
);
217 BOOL (*pOffsetViewportOrg
)(DC
*,INT
,INT
);
218 BOOL (*pOffsetWindowOrg
)(DC
*,INT
,INT
);
219 BOOL (*pPaintRgn
)(DC
*,HRGN
);
220 BOOL (*pPatBlt
)(DC
*,INT
,INT
,INT
,INT
,DWORD
);
221 BOOL (*pPie
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
222 BOOL (*pPolyBezier
)(DC
*,const POINT
*,DWORD
);
223 BOOL (*pPolyBezierTo
)(DC
*,const POINT
*,DWORD
);
224 BOOL (*pPolyDraw
)(DC
*,const POINT
*,const BYTE
*,DWORD
);
225 BOOL (*pPolyPolygon
)(DC
*,const POINT
*,const INT
*,UINT
);
226 BOOL (*pPolyPolyline
)(DC
*,const POINT
*,const DWORD
*,DWORD
);
227 BOOL (*pPolygon
)(DC
*,const POINT
*,INT
);
228 BOOL (*pPolyline
)(DC
*,const POINT
*,INT
);
229 BOOL (*pPolylineTo
)(DC
*,const POINT
*,INT
);
230 UINT (*pRealizePalette
)(DC
*);
231 BOOL (*pRectangle
)(DC
*,INT
,INT
,INT
,INT
);
232 BOOL (*pRestoreDC
)(DC
*,INT
);
233 BOOL (*pRoundRect
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
);
235 BOOL (*pScaleViewportExt
)(DC
*,INT
,INT
,INT
,INT
);
236 BOOL (*pScaleWindowExt
)(DC
*,INT
,INT
,INT
,INT
);
237 BOOL (*pSelectClipPath
)(DC
*,INT
);
238 INT (*pSelectClipRgn
)(DC
*,HRGN
);
239 HANDLE (*pSelectObject
)(DC
*,HANDLE
);
240 HPALETTE (*pSelectPalette
)(DC
*,HPALETTE
,BOOL
);
241 COLORREF (*pSetBkColor
)(DC
*,COLORREF
);
242 INT (*pSetBkMode
)(DC
*,INT
);
243 VOID (*pSetDeviceClipping
)(DC
*);
244 INT (*pSetDIBitsToDevice
)(DC
*,INT
,INT
,DWORD
,DWORD
,INT
,INT
,UINT
,UINT
,
245 LPCVOID
,const BITMAPINFO
*,UINT
);
246 INT (*pSetMapMode
)(DC
*,INT
);
247 DWORD (*pSetMapperFlags
)(DC
*,DWORD
);
248 COLORREF (*pSetPixel
)(DC
*,INT
,INT
,COLORREF
);
249 INT (*pSetPolyFillMode
)(DC
*,INT
);
250 INT (*pSetROP2
)(DC
*,INT
);
251 INT (*pSetRelAbs
)(DC
*,INT
);
252 INT (*pSetStretchBltMode
)(DC
*,INT
);
253 UINT (*pSetTextAlign
)(DC
*,UINT
);
254 INT (*pSetTextCharacterExtra
)(DC
*,INT
);
255 DWORD (*pSetTextColor
)(DC
*,DWORD
);
256 INT (*pSetTextJustification
)(DC
*,INT
,INT
);
257 BOOL (*pSetViewportExt
)(DC
*,INT
,INT
);
258 BOOL (*pSetViewportOrg
)(DC
*,INT
,INT
);
259 BOOL (*pSetWindowExt
)(DC
*,INT
,INT
);
260 BOOL (*pSetWindowOrg
)(DC
*,INT
,INT
);
261 INT (*pStartDoc
)(DC
*,const DOCINFOA
*);
262 INT (*pStartPage
)(DC
*);
263 BOOL (*pStretchBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,INT
,INT
,DWORD
);
264 INT (*pStretchDIBits
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,
265 const void *,const BITMAPINFO
*,UINT
,DWORD
);
266 BOOL (*pStrokeAndFillPath
)(DC
*);
267 BOOL (*pStrokePath
)(DC
*);
268 BOOL (*pWidenPath
)(DC
*);
271 /* LoadOEMResource types */
277 #define DCHC_INVALIDVISRGN 0x0001
278 #define DCHC_DELETEDC 0x0002
280 #define DCHF_INVALIDATEVISRGN 0x0001
281 #define DCHF_VALIDATEVISRGN 0x0002
284 #define DC_MEMORY 0x0001 /* It is a memory DC */
285 #define DC_SAVED 0x0002 /* It is a saved DC */
286 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
287 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
289 /* Last 32 bytes are reserved for stock object handles */
290 #define GDI_HEAP_SIZE 0xffe0
292 /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
293 #define FIRST_STOCK_HANDLE GDI_HEAP_SIZE
295 /* Stock objects handles */
297 #define NB_STOCK_OBJECTS (DEFAULT_GUI_FONT + 1)
299 #define STOCK_WHITE_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
300 #define STOCK_LTGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
301 #define STOCK_GRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
302 #define STOCK_DKGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
303 #define STOCK_BLACK_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
304 #define STOCK_NULL_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+NULL_BRUSH))
305 #define STOCK_HOLLOW_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
306 #define STOCK_WHITE_PEN ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
307 #define STOCK_BLACK_PEN ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
308 #define STOCK_NULL_PEN ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
309 #define STOCK_OEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
310 #define STOCK_ANSI_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
311 #define STOCK_ANSI_VAR_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
312 #define STOCK_SYSTEM_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
313 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
314 #define STOCK_DEFAULT_PALETTE ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
315 #define STOCK_SYSTEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
316 #define STOCK_DEFAULT_GUI_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEFAULT_GUI_FONT))
318 #define FIRST_STOCK_FONT STOCK_OEM_FIXED_FONT
319 #define LAST_STOCK_FONT STOCK_DEFAULT_GUI_FONT
321 #define LAST_STOCK_HANDLE ((DWORD)STOCK_DEFAULT_GUI_FONT)
323 extern HBITMAP hPseudoStockBitmap
;
325 /* Device <-> logical coords conversion */
327 /* A floating point version of the POINT structure */
328 typedef struct tagFLOAT_POINT
333 /* Rounds a floating point number to integer. The world-to-viewport
334 * transformation process is done in floating point internally. This function
335 * is then used to round these coordinates to integer values.
337 static inline INT WINE_UNUSED
GDI_ROUND(FLOAT val
)
339 return (int)floor(val
+ 0.5);
342 /* Performs a viewport-to-world transformation on the specified point (which
343 * is in floating point format). Returns TRUE if successful, else FALSE.
345 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
349 /* Check that the viewport-to-world transformation is valid */
350 if (!dc
->w
.vport2WorldValid
)
353 /* Perform the transformation */
356 point
->x
= x
* dc
->w
.xformVport2World
.eM11
+
357 y
* dc
->w
.xformVport2World
.eM21
+
358 dc
->w
.xformVport2World
.eDx
;
359 point
->y
= x
* dc
->w
.xformVport2World
.eM12
+
360 y
* dc
->w
.xformVport2World
.eM22
+
361 dc
->w
.xformVport2World
.eDy
;
366 /* Performs a viewport-to-world transformation on the specified point (which
367 * is in integer format). Returns TRUE if successful, else FALSE.
369 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP(DC
*dc
, LPPOINT point
)
371 FLOAT_POINT floatPoint
;
373 /* Perform operation with floating point */
374 floatPoint
.x
=(FLOAT
)point
->x
;
375 floatPoint
.y
=(FLOAT
)point
->y
;
376 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
379 /* Round to integers */
380 point
->x
= GDI_ROUND(floatPoint
.x
);
381 point
->y
= GDI_ROUND(floatPoint
.y
);
386 /* Performs a world-to-viewport transformation on the specified point (which
387 * is in floating point format).
389 static inline void WINE_UNUSED
INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
393 /* Perform the transformation */
396 point
->x
= x
* dc
->w
.xformWorld2Vport
.eM11
+
397 y
* dc
->w
.xformWorld2Vport
.eM21
+
398 dc
->w
.xformWorld2Vport
.eDx
;
399 point
->y
= x
* dc
->w
.xformWorld2Vport
.eM12
+
400 y
* dc
->w
.xformWorld2Vport
.eM22
+
401 dc
->w
.xformWorld2Vport
.eDy
;
404 /* Performs a world-to-viewport transformation on the specified point (which
405 * is in integer format).
407 static inline void WINE_UNUSED
INTERNAL_LPTODP(DC
*dc
, LPPOINT point
)
409 FLOAT_POINT floatPoint
;
411 /* Perform operation with floating point */
412 floatPoint
.x
=(FLOAT
)point
->x
;
413 floatPoint
.y
=(FLOAT
)point
->y
;
414 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
416 /* Round to integers */
417 point
->x
= GDI_ROUND(floatPoint
.x
);
418 point
->y
= GDI_ROUND(floatPoint
.y
);
421 #define XDPTOLP(dc,x) \
422 (MulDiv(((x)-(dc)->vportOrgX), (dc)->wndExtX, (dc)->vportExtX) + (dc)->wndOrgX)
423 #define YDPTOLP(dc,y) \
424 (MulDiv(((y)-(dc)->vportOrgY), (dc)->wndExtY, (dc)->vportExtY) + (dc)->wndOrgY)
425 #define XLPTODP(dc,x) \
426 (MulDiv(((x)-(dc)->wndOrgX), (dc)->vportExtX, (dc)->wndExtX) + (dc)->vportOrgX)
427 #define YLPTODP(dc,y) \
428 (MulDiv(((y)-(dc)->wndOrgY), (dc)->vportExtY, (dc)->wndExtY) + (dc)->vportOrgY)
430 /* Device <-> logical size conversion */
432 #define XDSTOLS(dc,x) \
433 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
434 #define YDSTOLS(dc,y) \
435 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
436 #define XLSTODS(dc,x) \
437 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
438 #define YLSTODS(dc,y) \
439 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
443 extern WORD GDI_HeapSel
;
445 #define GDI_HEAP_ALLOC(size) \
446 LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
447 #define GDI_HEAP_ALLOC_MOVEABLE(size) \
448 LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, (size) )
449 #define GDI_HEAP_REALLOC(handle,size) \
450 LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
451 #define GDI_HEAP_FREE(handle) \
452 LOCAL_Free( GDI_HeapSel, (handle) )
454 #define GDI_HEAP_LOCK(handle) \
455 LOCAL_Lock( GDI_HeapSel, (handle) )
456 #define GDI_HEAP_LOCK_SEGPTR(handle) \
457 LOCAL_LockSegptr( GDI_HeapSel, (handle) )
458 #define GDI_HEAP_UNLOCK(handle) \
459 ((((HGDIOBJ16)(handle) >= FIRST_STOCK_HANDLE) && \
460 ((HGDIOBJ16)(handle)<=LAST_STOCK_HANDLE)) ? \
461 0 : LOCAL_Unlock( GDI_HeapSel, (handle) ))
463 extern BOOL
GDI_Init(void);
464 extern HGDIOBJ
GDI_AllocObject( WORD
, WORD
);
465 extern BOOL
GDI_FreeObject( HGDIOBJ
);
466 extern GDIOBJHDR
* GDI_GetObjPtr( HGDIOBJ
, WORD
);
468 extern BOOL
DRIVER_RegisterDriver( LPCSTR name
, const DC_FUNCTIONS
*funcs
);
469 extern const DC_FUNCTIONS
*DRIVER_FindDriver( LPCSTR name
);
470 extern BOOL
DRIVER_UnregisterDriver( LPCSTR name
);
471 extern BOOL
DRIVER_GetDriverName( LPCSTR device
, LPSTR driver
, DWORD size
);
473 extern POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
);
476 #endif /* __WINE_GDI_H */