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 INT (*pChoosePixelFormat
)(DC
*,const PIXELFORMATDESCRIPTOR
*);
180 BOOL (*pChord
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
181 BOOL (*pCloseFigure
)(DC
*);
182 BOOL (*pCreateBitmap
)(HBITMAP
);
183 BOOL (*pCreateDC
)(DC
*,LPCSTR
,LPCSTR
,LPCSTR
,const DEVMODEA
*);
184 HBITMAP (*pCreateDIBSection
)(DC
*,BITMAPINFO
*,UINT
,LPVOID
*,HANDLE
,
186 HBITMAP16 (*pCreateDIBSection16
)(DC
*,BITMAPINFO
*,UINT16
,SEGPTR
*,HANDLE
,
188 BOOL (*pDeleteDC
)(DC
*);
189 BOOL (*pDeleteObject
)(HGDIOBJ
);
190 INT (*pDescribePixelFormat
)(DC
*,INT
,UINT
,PIXELFORMATDESCRIPTOR
*);
191 DWORD (*pDeviceCapabilities
)(LPSTR
,LPCSTR
,LPCSTR
,WORD
,LPSTR
,LPDEVMODEA
);
192 BOOL (*pEllipse
)(DC
*,INT
,INT
,INT
,INT
);
194 INT (*pEndPage
)(DC
*);
195 BOOL (*pEndPath
)(DC
*);
196 BOOL (*pEnumDeviceFonts
)(DC
*,LPLOGFONT16
,DEVICEFONTENUMPROC
,LPARAM
);
197 INT (*pEscape
)(DC
*,INT
,INT
,SEGPTR
,SEGPTR
);
198 INT (*pExcludeClipRect
)(DC
*,INT
,INT
,INT
,INT
);
199 INT (*pExtDeviceMode
)(LPSTR
,HWND
,LPDEVMODEA
,LPSTR
,LPSTR
,LPDEVMODEA
,
201 BOOL (*pExtFloodFill
)(DC
*,INT
,INT
,COLORREF
,UINT
);
202 BOOL (*pExtTextOut
)(DC
*,INT
,INT
,UINT
,const RECT
*,LPCWSTR
,UINT
,
204 BOOL (*pFillPath
)(DC
*);
205 BOOL (*pFillRgn
)(DC
*,HRGN
,HBRUSH
);
206 BOOL (*pFlattenPath
)(DC
*);
207 BOOL (*pFrameRgn
)(DC
*,HRGN
,HBRUSH
,INT
,INT
);
208 BOOL (*pGetCharWidth
)(DC
*,UINT
,UINT
,LPINT
);
209 BOOL (*pGetDCOrgEx
)(DC
*,LPPOINT
);
210 COLORREF (*pGetPixel
)(DC
*,INT
,INT
);
211 INT (*pGetPixelFormat
)(DC
*);
212 BOOL (*pGetTextExtentPoint
)(DC
*,LPCWSTR
,INT
,LPSIZE
);
213 BOOL (*pGetTextMetrics
)(DC
*,TEXTMETRICA
*);
214 INT (*pIntersectClipRect
)(DC
*,INT
,INT
,INT
,INT
);
215 BOOL (*pInvertRgn
)(DC
*,HRGN
);
216 BOOL (*pLineTo
)(DC
*,INT
,INT
);
217 HANDLE (*pLoadOEMResource
)(WORD
,WORD
);
218 BOOL (*pMoveToEx
)(DC
*,INT
,INT
,LPPOINT
);
219 INT (*pOffsetClipRgn
)(DC
*,INT
,INT
);
220 BOOL (*pOffsetViewportOrg
)(DC
*,INT
,INT
);
221 BOOL (*pOffsetWindowOrg
)(DC
*,INT
,INT
);
222 BOOL (*pPaintRgn
)(DC
*,HRGN
);
223 BOOL (*pPatBlt
)(DC
*,INT
,INT
,INT
,INT
,DWORD
);
224 BOOL (*pPie
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
225 BOOL (*pPolyBezier
)(DC
*,const POINT
*,DWORD
);
226 BOOL (*pPolyBezierTo
)(DC
*,const POINT
*,DWORD
);
227 BOOL (*pPolyDraw
)(DC
*,const POINT
*,const BYTE
*,DWORD
);
228 BOOL (*pPolyPolygon
)(DC
*,const POINT
*,const INT
*,UINT
);
229 BOOL (*pPolyPolyline
)(DC
*,const POINT
*,const DWORD
*,DWORD
);
230 BOOL (*pPolygon
)(DC
*,const POINT
*,INT
);
231 BOOL (*pPolyline
)(DC
*,const POINT
*,INT
);
232 BOOL (*pPolylineTo
)(DC
*,const POINT
*,INT
);
233 UINT (*pRealizePalette
)(DC
*);
234 BOOL (*pRectangle
)(DC
*,INT
,INT
,INT
,INT
);
235 BOOL (*pRestoreDC
)(DC
*,INT
);
236 BOOL (*pRoundRect
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
);
238 BOOL (*pScaleViewportExt
)(DC
*,INT
,INT
,INT
,INT
);
239 BOOL (*pScaleWindowExt
)(DC
*,INT
,INT
,INT
,INT
);
240 BOOL (*pSelectClipPath
)(DC
*,INT
);
241 INT (*pSelectClipRgn
)(DC
*,HRGN
);
242 HANDLE (*pSelectObject
)(DC
*,HANDLE
);
243 HPALETTE (*pSelectPalette
)(DC
*,HPALETTE
,BOOL
);
244 COLORREF (*pSetBkColor
)(DC
*,COLORREF
);
245 INT (*pSetBkMode
)(DC
*,INT
);
246 VOID (*pSetDeviceClipping
)(DC
*);
247 INT (*pSetDIBitsToDevice
)(DC
*,INT
,INT
,DWORD
,DWORD
,INT
,INT
,UINT
,UINT
,
248 LPCVOID
,const BITMAPINFO
*,UINT
);
249 INT (*pSetMapMode
)(DC
*,INT
);
250 DWORD (*pSetMapperFlags
)(DC
*,DWORD
);
251 COLORREF (*pSetPixel
)(DC
*,INT
,INT
,COLORREF
);
252 BOOL (*pSetPixelFormat
)(DC
*,INT
,const PIXELFORMATDESCRIPTOR
*);
253 INT (*pSetPolyFillMode
)(DC
*,INT
);
254 INT (*pSetROP2
)(DC
*,INT
);
255 INT (*pSetRelAbs
)(DC
*,INT
);
256 INT (*pSetStretchBltMode
)(DC
*,INT
);
257 UINT (*pSetTextAlign
)(DC
*,UINT
);
258 INT (*pSetTextCharacterExtra
)(DC
*,INT
);
259 DWORD (*pSetTextColor
)(DC
*,DWORD
);
260 INT (*pSetTextJustification
)(DC
*,INT
,INT
);
261 BOOL (*pSetViewportExt
)(DC
*,INT
,INT
);
262 BOOL (*pSetViewportOrg
)(DC
*,INT
,INT
);
263 BOOL (*pSetWindowExt
)(DC
*,INT
,INT
);
264 BOOL (*pSetWindowOrg
)(DC
*,INT
,INT
);
265 INT (*pStartDoc
)(DC
*,const DOCINFOA
*);
266 INT (*pStartPage
)(DC
*);
267 BOOL (*pStretchBlt
)(DC
*,INT
,INT
,INT
,INT
,DC
*,INT
,INT
,INT
,INT
,DWORD
);
268 INT (*pStretchDIBits
)(DC
*,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,
269 const void *,const BITMAPINFO
*,UINT
,DWORD
);
270 BOOL (*pStrokeAndFillPath
)(DC
*);
271 BOOL (*pStrokePath
)(DC
*);
272 BOOL (*pSwapBuffers
)(DC
*);
273 BOOL (*pWidenPath
)(DC
*);
276 /* LoadOEMResource types */
282 #define DCHC_INVALIDVISRGN 0x0001
283 #define DCHC_DELETEDC 0x0002
285 #define DCHF_INVALIDATEVISRGN 0x0001
286 #define DCHF_VALIDATEVISRGN 0x0002
289 #define DC_MEMORY 0x0001 /* It is a memory DC */
290 #define DC_SAVED 0x0002 /* It is a saved DC */
291 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
292 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
294 /* Last 32 bytes are reserved for stock object handles */
295 #define GDI_HEAP_SIZE 0xffe0
297 /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
298 #define FIRST_STOCK_HANDLE GDI_HEAP_SIZE
300 /* Stock objects handles */
302 #define NB_STOCK_OBJECTS (DEFAULT_GUI_FONT + 1)
304 #define STOCK_WHITE_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
305 #define STOCK_LTGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
306 #define STOCK_GRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
307 #define STOCK_DKGRAY_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
308 #define STOCK_BLACK_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
309 #define STOCK_NULL_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+NULL_BRUSH))
310 #define STOCK_HOLLOW_BRUSH ((HBRUSH16)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
311 #define STOCK_WHITE_PEN ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
312 #define STOCK_BLACK_PEN ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
313 #define STOCK_NULL_PEN ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
314 #define STOCK_OEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
315 #define STOCK_ANSI_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
316 #define STOCK_ANSI_VAR_FONT ((HFONT16)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
317 #define STOCK_SYSTEM_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
318 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
319 #define STOCK_DEFAULT_PALETTE ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
320 #define STOCK_SYSTEM_FIXED_FONT ((HFONT16)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
321 #define STOCK_DEFAULT_GUI_FONT ((HFONT16)(FIRST_STOCK_HANDLE+DEFAULT_GUI_FONT))
323 #define FIRST_STOCK_FONT STOCK_OEM_FIXED_FONT
324 #define LAST_STOCK_FONT STOCK_DEFAULT_GUI_FONT
326 #define LAST_STOCK_HANDLE ((DWORD)STOCK_DEFAULT_GUI_FONT)
328 extern HBITMAP hPseudoStockBitmap
;
330 /* Device <-> logical coords conversion */
332 /* A floating point version of the POINT structure */
333 typedef struct tagFLOAT_POINT
338 /* Rounds a floating point number to integer. The world-to-viewport
339 * transformation process is done in floating point internally. This function
340 * is then used to round these coordinates to integer values.
342 static inline INT WINE_UNUSED
GDI_ROUND(FLOAT val
)
344 return (int)floor(val
+ 0.5);
347 /* Performs a viewport-to-world transformation on the specified point (which
348 * is in floating point format). Returns TRUE if successful, else FALSE.
350 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
354 /* Check that the viewport-to-world transformation is valid */
355 if (!dc
->w
.vport2WorldValid
)
358 /* Perform the transformation */
361 point
->x
= x
* dc
->w
.xformVport2World
.eM11
+
362 y
* dc
->w
.xformVport2World
.eM21
+
363 dc
->w
.xformVport2World
.eDx
;
364 point
->y
= x
* dc
->w
.xformVport2World
.eM12
+
365 y
* dc
->w
.xformVport2World
.eM22
+
366 dc
->w
.xformVport2World
.eDy
;
371 /* Performs a viewport-to-world transformation on the specified point (which
372 * is in integer format). Returns TRUE if successful, else FALSE.
374 static inline BOOL WINE_UNUSED
INTERNAL_DPTOLP(DC
*dc
, LPPOINT point
)
376 FLOAT_POINT floatPoint
;
378 /* Perform operation with floating point */
379 floatPoint
.x
=(FLOAT
)point
->x
;
380 floatPoint
.y
=(FLOAT
)point
->y
;
381 if (!INTERNAL_DPTOLP_FLOAT(dc
, &floatPoint
))
384 /* Round to integers */
385 point
->x
= GDI_ROUND(floatPoint
.x
);
386 point
->y
= GDI_ROUND(floatPoint
.y
);
391 /* Performs a world-to-viewport transformation on the specified point (which
392 * is in floating point format).
394 static inline void WINE_UNUSED
INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
398 /* Perform the transformation */
401 point
->x
= x
* dc
->w
.xformWorld2Vport
.eM11
+
402 y
* dc
->w
.xformWorld2Vport
.eM21
+
403 dc
->w
.xformWorld2Vport
.eDx
;
404 point
->y
= x
* dc
->w
.xformWorld2Vport
.eM12
+
405 y
* dc
->w
.xformWorld2Vport
.eM22
+
406 dc
->w
.xformWorld2Vport
.eDy
;
409 /* Performs a world-to-viewport transformation on the specified point (which
410 * is in integer format).
412 static inline void WINE_UNUSED
INTERNAL_LPTODP(DC
*dc
, LPPOINT point
)
414 FLOAT_POINT floatPoint
;
416 /* Perform operation with floating point */
417 floatPoint
.x
=(FLOAT
)point
->x
;
418 floatPoint
.y
=(FLOAT
)point
->y
;
419 INTERNAL_LPTODP_FLOAT(dc
, &floatPoint
);
421 /* Round to integers */
422 point
->x
= GDI_ROUND(floatPoint
.x
);
423 point
->y
= GDI_ROUND(floatPoint
.y
);
426 #define XDPTOLP(dc,x) \
427 (MulDiv(((x)-(dc)->vportOrgX), (dc)->wndExtX, (dc)->vportExtX) + (dc)->wndOrgX)
428 #define YDPTOLP(dc,y) \
429 (MulDiv(((y)-(dc)->vportOrgY), (dc)->wndExtY, (dc)->vportExtY) + (dc)->wndOrgY)
430 #define XLPTODP(dc,x) \
431 (MulDiv(((x)-(dc)->wndOrgX), (dc)->vportExtX, (dc)->wndExtX) + (dc)->vportOrgX)
432 #define YLPTODP(dc,y) \
433 (MulDiv(((y)-(dc)->wndOrgY), (dc)->vportExtY, (dc)->wndExtY) + (dc)->vportOrgY)
435 /* Device <-> logical size conversion */
437 #define XDSTOLS(dc,x) \
438 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
439 #define YDSTOLS(dc,y) \
440 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
441 #define XLSTODS(dc,x) \
442 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
443 #define YLSTODS(dc,y) \
444 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
448 extern WORD GDI_HeapSel
;
450 #define GDI_HEAP_ALLOC(size) \
451 LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
452 #define GDI_HEAP_ALLOC_MOVEABLE(size) \
453 LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, (size) )
454 #define GDI_HEAP_REALLOC(handle,size) \
455 LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
456 #define GDI_HEAP_FREE(handle) \
457 LOCAL_Free( GDI_HeapSel, (handle) )
459 #define GDI_HEAP_LOCK(handle) \
460 LOCAL_Lock( GDI_HeapSel, (handle) )
461 #define GDI_HEAP_LOCK_SEGPTR(handle) \
462 LOCAL_LockSegptr( GDI_HeapSel, (handle) )
463 #define GDI_HEAP_UNLOCK(handle) \
464 ((((HGDIOBJ16)(handle) >= FIRST_STOCK_HANDLE) && \
465 ((HGDIOBJ16)(handle)<=LAST_STOCK_HANDLE)) ? \
466 0 : LOCAL_Unlock( GDI_HeapSel, (handle) ))
468 extern BOOL
GDI_Init(void);
469 extern HGDIOBJ
GDI_AllocObject( WORD
, WORD
);
470 extern BOOL
GDI_FreeObject( HGDIOBJ
);
471 extern GDIOBJHDR
* GDI_GetObjPtr( HGDIOBJ
, WORD
);
473 extern BOOL
DRIVER_RegisterDriver( LPCSTR name
, const DC_FUNCTIONS
*funcs
);
474 extern const DC_FUNCTIONS
*DRIVER_FindDriver( LPCSTR name
);
475 extern BOOL
DRIVER_UnregisterDriver( LPCSTR name
);
476 extern BOOL
DRIVER_GetDriverName( LPCSTR device
, LPSTR driver
, DWORD size
);
478 extern POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
);
481 #endif /* __WINE_GDI_H */