4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/wingdi16.h"
30 /* GDI objects magic numbers */
31 #define FIRST_MAGIC 0x4f47
32 #define PEN_MAGIC 0x4f47
33 #define BRUSH_MAGIC 0x4f48
34 #define FONT_MAGIC 0x4f49
35 #define PALETTE_MAGIC 0x4f4a
36 #define BITMAP_MAGIC 0x4f4b
37 #define REGION_MAGIC 0x4f4c
38 #define DC_MAGIC 0x4f4d
39 #define DISABLED_DC_MAGIC 0x4f4e
40 #define META_DC_MAGIC 0x4f4f
41 #define METAFILE_MAGIC 0x4f50
42 #define METAFILE_DC_MAGIC 0x4f51
43 #define ENHMETAFILE_MAGIC 0x4f52
44 #define ENHMETAFILE_DC_MAGIC 0x4f53
45 #define LAST_MAGIC 0x4f53
47 #define MAGIC_DONTCARE 0xffff
49 /* GDI constants for making objects private/system (naming undoc. !) */
50 #define OBJECT_PRIVATE 0x2000
51 #define OBJECT_NOSYSTEM 0x8000
53 #define GDIMAGIC(magic) ((magic) & ~(OBJECT_PRIVATE|OBJECT_NOSYSTEM))
57 HGDIOBJ (*pSelectObject
)( HGDIOBJ handle
, void *obj
, HDC hdc
);
58 INT (*pGetObject16
)( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
59 INT (*pGetObjectA
)( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
60 INT (*pGetObjectW
)( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
61 BOOL (*pUnrealizeObject
)( HGDIOBJ handle
, void *obj
);
62 BOOL (*pDeleteObject
)( HGDIOBJ handle
, void *obj
);
65 typedef struct tagGDIOBJHDR
70 const struct gdi_obj_funcs
*funcs
;
74 typedef struct tagGdiFont
*GdiFont
;
76 typedef struct { int opaque
; } *PHYSDEV
; /* PHYSDEV is an opaque pointer */
81 HDC hSelf
; /* Handle to this DC */
82 const struct tagDC_FUNCS
*funcs
; /* DC function table */
83 PHYSDEV physDev
; /* Physical device (driver-specific) */
86 FARPROC16 hookProc
; /* the original SEGPTR ... */
87 DCHOOKPROC hookThunk
; /* ... and the thunk to call it */
89 INT wndOrgX
; /* Window origin */
91 INT wndExtX
; /* Window extent */
93 INT vportOrgX
; /* Viewport origin */
95 INT vportExtX
; /* Viewport extent */
99 HRGN hClipRgn
; /* Clip region (may be 0) */
100 HRGN hVisRgn
; /* Visible region (must never be 0) */
101 HRGN hGCClipRgn
; /* GC clip region (ClipRgn AND VisRgn) */
117 COLORREF backgroundColor
;
122 WORD textAlign
; /* Text alignment from SetTextAlign() */
123 short charExtra
; /* Spacing from SetTextCharacterExtra() */
124 short breakTotalExtra
; /* Total extra space for justification */
125 short breakCount
; /* Break char. count */
126 short breakExtra
; /* breakTotalExtra / breakCount */
127 short breakRem
; /* breakTotalExtra % breakCount */
133 INT GraphicsMode
; /* Graphics mode */
134 ABORTPROC pAbortProc
; /* AbortProc for Printing */
135 ABORTPROC16 pAbortProc16
;
136 INT CursPosX
; /* Current position */
139 XFORM xformWorld2Wnd
; /* World-to-window transformation */
140 XFORM xformWorld2Vport
; /* World-to-viewport transformation */
141 XFORM xformVport2World
; /* Inverse of the above transformation */
142 BOOL vport2WorldValid
; /* Is xformVport2World valid? */
145 /* Device functions for the Wine driver interface */
147 typedef INT (*DEVICEFONTENUMPROC
)(LPENUMLOGFONTEXW
,LPNEWTEXTMETRICEXW
,DWORD
,
150 typedef struct tagDC_FUNCS
152 INT (*pAbortDoc
)(PHYSDEV
);
153 BOOL (*pAbortPath
)(PHYSDEV
);
154 BOOL (*pAngleArc
)(PHYSDEV
,INT
,INT
,DWORD
,FLOAT
,FLOAT
);
155 BOOL (*pArc
)(PHYSDEV
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
156 BOOL (*pArcTo
)(PHYSDEV
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
157 BOOL (*pBeginPath
)(PHYSDEV
);
158 BOOL (*pBitBlt
)(PHYSDEV
,INT
,INT
,INT
,INT
,PHYSDEV
,INT
,INT
,DWORD
);
159 INT (*pChoosePixelFormat
)(PHYSDEV
,const PIXELFORMATDESCRIPTOR
*);
160 BOOL (*pChord
)(PHYSDEV
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
161 BOOL (*pCloseFigure
)(PHYSDEV
);
162 BOOL (*pCreateBitmap
)(PHYSDEV
,HBITMAP
);
163 BOOL (*pCreateDC
)(DC
*,PHYSDEV
*,LPCSTR
,LPCSTR
,LPCSTR
,const DEVMODEA
*);
164 HBITMAP (*pCreateDIBSection
)(PHYSDEV
,BITMAPINFO
*,UINT
,LPVOID
*,HANDLE
,DWORD
,DWORD
);
165 BOOL (*pDeleteBitmap
)(HBITMAP
);
166 BOOL (*pDeleteDC
)(PHYSDEV
);
167 INT (*pDescribePixelFormat
)(PHYSDEV
,INT
,UINT
,PIXELFORMATDESCRIPTOR
*);
168 DWORD (*pDeviceCapabilities
)(LPSTR
,LPCSTR
,LPCSTR
,WORD
,LPSTR
,LPDEVMODEA
);
169 BOOL (*pEllipse
)(PHYSDEV
,INT
,INT
,INT
,INT
);
170 INT (*pEndDoc
)(PHYSDEV
);
171 INT (*pEndPage
)(PHYSDEV
);
172 BOOL (*pEndPath
)(PHYSDEV
);
173 BOOL (*pEnumDeviceFonts
)(PHYSDEV
,LPLOGFONTW
,DEVICEFONTENUMPROC
,LPARAM
);
174 INT (*pExcludeClipRect
)(PHYSDEV
,INT
,INT
,INT
,INT
);
175 INT (*pExtDeviceMode
)(LPSTR
,HWND
,LPDEVMODEA
,LPSTR
,LPSTR
,LPDEVMODEA
,LPSTR
,DWORD
);
176 INT (*pExtEscape
)(PHYSDEV
,INT
,INT
,LPCVOID
,INT
,LPVOID
);
177 BOOL (*pExtFloodFill
)(PHYSDEV
,INT
,INT
,COLORREF
,UINT
);
178 INT (*pExtSelectClipRgn
)(PHYSDEV
,HRGN
,INT
);
179 BOOL (*pExtTextOut
)(PHYSDEV
,INT
,INT
,UINT
,const RECT
*,LPCWSTR
,UINT
,const INT
*);
180 BOOL (*pFillPath
)(PHYSDEV
);
181 BOOL (*pFillRgn
)(PHYSDEV
,HRGN
,HBRUSH
);
182 BOOL (*pFlattenPath
)(PHYSDEV
);
183 BOOL (*pFrameRgn
)(PHYSDEV
,HRGN
,HBRUSH
,INT
,INT
);
184 LONG (*pGetBitmapBits
)(HBITMAP
,void*,LONG
);
185 BOOL (*pGetCharWidth
)(PHYSDEV
,UINT
,UINT
,LPINT
);
186 BOOL (*pGetDCOrgEx
)(PHYSDEV
,LPPOINT
);
187 UINT (*pGetDIBColorTable
)(PHYSDEV
,UINT
,UINT
,RGBQUAD
*);
188 INT (*pGetDIBits
)(PHYSDEV
,HBITMAP
,UINT
,UINT
,LPVOID
,BITMAPINFO
*,UINT
);
189 INT (*pGetDeviceCaps
)(PHYSDEV
,INT
);
190 BOOL (*pGetDeviceGammaRamp
)(PHYSDEV
,LPVOID
);
191 COLORREF (*pGetNearestColor
)(PHYSDEV
,COLORREF
);
192 COLORREF (*pGetPixel
)(PHYSDEV
,INT
,INT
);
193 INT (*pGetPixelFormat
)(PHYSDEV
);
194 UINT (*pGetSystemPaletteEntries
)(PHYSDEV
,UINT
,UINT
,LPPALETTEENTRY
);
195 BOOL (*pGetTextExtentPoint
)(PHYSDEV
,LPCWSTR
,INT
,LPSIZE
);
196 BOOL (*pGetTextMetrics
)(PHYSDEV
,TEXTMETRICW
*);
197 INT (*pIntersectClipRect
)(PHYSDEV
,INT
,INT
,INT
,INT
);
198 BOOL (*pInvertRgn
)(PHYSDEV
,HRGN
);
199 BOOL (*pLineTo
)(PHYSDEV
,INT
,INT
);
200 BOOL (*pMoveTo
)(PHYSDEV
,INT
,INT
);
201 INT (*pOffsetClipRgn
)(PHYSDEV
,INT
,INT
);
202 INT (*pOffsetViewportOrg
)(PHYSDEV
,INT
,INT
);
203 INT (*pOffsetWindowOrg
)(PHYSDEV
,INT
,INT
);
204 BOOL (*pPaintRgn
)(PHYSDEV
,HRGN
);
205 BOOL (*pPatBlt
)(PHYSDEV
,INT
,INT
,INT
,INT
,DWORD
);
206 BOOL (*pPie
)(PHYSDEV
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
);
207 BOOL (*pPolyBezier
)(PHYSDEV
,const POINT
*,DWORD
);
208 BOOL (*pPolyBezierTo
)(PHYSDEV
,const POINT
*,DWORD
);
209 BOOL (*pPolyDraw
)(PHYSDEV
,const POINT
*,const BYTE
*,DWORD
);
210 BOOL (*pPolyPolygon
)(PHYSDEV
,const POINT
*,const INT
*,UINT
);
211 BOOL (*pPolyPolyline
)(PHYSDEV
,const POINT
*,const DWORD
*,DWORD
);
212 BOOL (*pPolygon
)(PHYSDEV
,const POINT
*,INT
);
213 BOOL (*pPolyline
)(PHYSDEV
,const POINT
*,INT
);
214 BOOL (*pPolylineTo
)(PHYSDEV
,const POINT
*,INT
);
215 UINT (*pRealizeDefaultPalette
)(PHYSDEV
);
216 UINT (*pRealizePalette
)(PHYSDEV
,HPALETTE
,BOOL
);
217 BOOL (*pRectangle
)(PHYSDEV
,INT
,INT
,INT
,INT
);
218 HDC (*pResetDC
)(PHYSDEV
,const DEVMODEA
*);
219 BOOL (*pRestoreDC
)(PHYSDEV
,INT
);
220 BOOL (*pRoundRect
)(PHYSDEV
,INT
,INT
,INT
,INT
,INT
,INT
);
221 INT (*pSaveDC
)(PHYSDEV
);
222 INT (*pScaleViewportExt
)(PHYSDEV
,INT
,INT
,INT
,INT
);
223 INT (*pScaleWindowExt
)(PHYSDEV
,INT
,INT
,INT
,INT
);
224 HBITMAP (*pSelectBitmap
)(PHYSDEV
,HBITMAP
);
225 HBRUSH (*pSelectBrush
)(PHYSDEV
,HBRUSH
);
226 BOOL (*pSelectClipPath
)(PHYSDEV
,INT
);
227 HFONT (*pSelectFont
)(PHYSDEV
,HFONT
);
228 HPALETTE (*pSelectPalette
)(PHYSDEV
,HPALETTE
,BOOL
);
229 HPEN (*pSelectPen
)(PHYSDEV
,HPEN
);
230 LONG (*pSetBitmapBits
)(HBITMAP
,const void*,LONG
);
231 COLORREF (*pSetBkColor
)(PHYSDEV
,COLORREF
);
232 INT (*pSetBkMode
)(PHYSDEV
,INT
);
233 DWORD (*pSetDCOrg
)(PHYSDEV
,INT
,INT
);
234 UINT (*pSetDIBColorTable
)(PHYSDEV
,UINT
,UINT
,const RGBQUAD
*);
235 INT (*pSetDIBits
)(PHYSDEV
,HBITMAP
,UINT
,UINT
,LPCVOID
,const BITMAPINFO
*,UINT
);
236 INT (*pSetDIBitsToDevice
)(PHYSDEV
,INT
,INT
,DWORD
,DWORD
,INT
,INT
,UINT
,UINT
,LPCVOID
,
237 const BITMAPINFO
*,UINT
);
238 VOID (*pSetDeviceClipping
)(PHYSDEV
,HRGN
);
239 BOOL (*pSetDeviceGammaRamp
)(PHYSDEV
,LPVOID
);
240 INT (*pSetMapMode
)(PHYSDEV
,INT
);
241 DWORD (*pSetMapperFlags
)(PHYSDEV
,DWORD
);
242 COLORREF (*pSetPixel
)(PHYSDEV
,INT
,INT
,COLORREF
);
243 BOOL (*pSetPixelFormat
)(PHYSDEV
,INT
,const PIXELFORMATDESCRIPTOR
*);
244 INT (*pSetPolyFillMode
)(PHYSDEV
,INT
);
245 INT (*pSetROP2
)(PHYSDEV
,INT
);
246 INT (*pSetRelAbs
)(PHYSDEV
,INT
);
247 INT (*pSetStretchBltMode
)(PHYSDEV
,INT
);
248 UINT (*pSetTextAlign
)(PHYSDEV
,UINT
);
249 INT (*pSetTextCharacterExtra
)(PHYSDEV
,INT
);
250 DWORD (*pSetTextColor
)(PHYSDEV
,DWORD
);
251 INT (*pSetTextJustification
)(PHYSDEV
,INT
,INT
);
252 INT (*pSetViewportExt
)(PHYSDEV
,INT
,INT
);
253 INT (*pSetViewportOrg
)(PHYSDEV
,INT
,INT
);
254 INT (*pSetWindowExt
)(PHYSDEV
,INT
,INT
);
255 INT (*pSetWindowOrg
)(PHYSDEV
,INT
,INT
);
256 INT (*pStartDoc
)(PHYSDEV
,const DOCINFOA
*);
257 INT (*pStartPage
)(PHYSDEV
);
258 BOOL (*pStretchBlt
)(PHYSDEV
,INT
,INT
,INT
,INT
,PHYSDEV
,INT
,INT
,INT
,INT
,DWORD
);
259 INT (*pStretchDIBits
)(PHYSDEV
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,INT
,const void *,
260 const BITMAPINFO
*,UINT
,DWORD
);
261 BOOL (*pStrokeAndFillPath
)(PHYSDEV
);
262 BOOL (*pStrokePath
)(PHYSDEV
);
263 BOOL (*pSwapBuffers
)(PHYSDEV
);
264 BOOL (*pWidenPath
)(PHYSDEV
);
267 /* Certain functions will do no further processing if the driver returns this.
268 Used by mfdrv for example. */
269 #define GDI_NO_MORE_WORK 2
272 #define DCHC_INVALIDVISRGN 0x0001
273 #define DCHC_DELETEDC 0x0002
275 #define DCHF_INVALIDATEVISRGN 0x0001
276 #define DCHF_VALIDATEVISRGN 0x0002
279 #define DC_MEMORY 0x0001 /* It is a memory DC */
280 #define DC_SAVED 0x0002 /* It is a saved DC */
281 #define DC_DIRTY 0x0004 /* hVisRgn has to be updated */
282 #define DC_THUNKHOOK 0x0008 /* DC hook is in the 16-bit code */
284 #define GDI_HEAP_SIZE 0xffe0
286 /* extra stock object: default 1x1 bitmap for memory DCs */
287 #define DEFAULT_BITMAP (STOCK_LAST+1)
289 /* Metafile defines */
291 #define META_EOF 0x0000
292 /* values of mtType in METAHEADER. Note however that the disk image of a disk
293 based metafile has mtType == 1 */
294 #define METAFILE_MEMORY 1
295 #define METAFILE_DISK 2
297 /* Rounds a floating point number to integer. The world-to-viewport
298 * transformation process is done in floating point internally. This function
299 * is then used to round these coordinates to integer values.
301 static inline INT WINE_UNUSED
GDI_ROUND(FLOAT val
)
303 return (int)floor(val
+ 0.5);
306 /* World -> Device size conversion */
308 /* Performs a world-to-viewport transformation on the specified width (which
309 * is in floating point format).
311 static inline void WINE_UNUSED
INTERNAL_XWSTODS_FLOAT(DC
*dc
, FLOAT
*width
)
313 /* Perform the transformation */
314 *width
= *width
* dc
->xformWorld2Vport
.eM11
;
317 /* Performs a world-to-viewport transformation on the specified width (which
318 * is in integer format).
320 static inline INT WINE_UNUSED
INTERNAL_XWSTODS(DC
*dc
, INT width
)
324 /* Perform operation with floating point */
325 floatWidth
= (FLOAT
)width
;
326 INTERNAL_XWSTODS_FLOAT(dc
, &floatWidth
);
328 /* Round to integers */
329 return GDI_ROUND(floatWidth
);
333 /* Performs a world-to-viewport transformation on the specified size (which
334 * is in floating point format).
336 static inline void WINE_UNUSED
INTERNAL_YWSTODS_FLOAT(DC
*dc
, FLOAT
*height
)
338 /* Perform the transformation */
339 *height
= *height
* dc
->xformWorld2Vport
.eM22
;
342 /* Performs a world-to-viewport transformation on the specified size (which
343 * is in integer format).
345 static inline INT WINE_UNUSED
INTERNAL_YWSTODS(DC
*dc
, INT height
)
349 /* Perform operation with floating point */
350 floatHeight
= (FLOAT
)height
;
351 INTERNAL_YWSTODS_FLOAT(dc
, &floatHeight
);
353 /* Round to integers */
354 return GDI_ROUND(floatHeight
);
358 /* Device -> World size conversion */
360 /* Performs a device to world transformation on the specified width (which
361 * is in floating point format).
363 static inline void INTERNAL_XDSTOWS_FLOAT(DC
*dc
, FLOAT
*width
)
365 /* Perform the transformation */
366 *width
= *width
* dc
->xformVport2World
.eM11
;
369 /* Performs a device to world transformation on the specified width (which
370 * is in integer format).
372 static inline INT
INTERNAL_XDSTOWS(DC
*dc
, INT width
)
376 /* Perform operation with floating point */
377 floatWidth
= (FLOAT
)width
;
378 INTERNAL_XDSTOWS_FLOAT(dc
, &floatWidth
);
380 /* Round to integers */
381 return GDI_ROUND(floatWidth
);
385 /* Performs a device to world transformation on the specified size (which
386 * is in floating point format).
388 static inline void INTERNAL_YDSTOWS_FLOAT(DC
*dc
, FLOAT
*height
)
390 /* Perform the transformation */
391 *height
= *height
* dc
->xformVport2World
.eM22
;
394 /* Performs a device to world transformation on the specified size (which
395 * is in integer format).
397 static inline INT
INTERNAL_YDSTOWS(DC
*dc
, INT height
)
401 /* Perform operation with floating point */
402 floatHeight
= (FLOAT
)height
;
403 INTERNAL_YDSTOWS_FLOAT(dc
, &floatHeight
);
405 /* Round to integers */
406 return GDI_ROUND(floatHeight
);
410 /* Device <-> logical size conversion */
412 #define XDSTOLS(dc,x) \
413 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
414 #define YDSTOLS(dc,y) \
415 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
416 #define XLSTODS(dc,x) \
417 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
418 #define YLSTODS(dc,y) \
419 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
423 extern BOOL
GDI_Init(void);
424 extern void *GDI_AllocObject( WORD
, WORD
, HGDIOBJ
*, const struct gdi_obj_funcs
*funcs
);
425 extern void *GDI_ReallocObject( WORD
, HGDIOBJ
, void *obj
);
426 extern BOOL
GDI_FreeObject( HGDIOBJ
, void *obj
);
427 extern void *GDI_GetObjPtr( HGDIOBJ
, WORD
);
428 extern void GDI_ReleaseObj( HGDIOBJ
);
429 extern void GDI_CheckNotLock(void);
431 extern const DC_FUNCTIONS
*DRIVER_load_driver( LPCSTR name
);
432 extern const DC_FUNCTIONS
*DRIVER_get_driver( const DC_FUNCTIONS
*funcs
);
433 extern void DRIVER_release_driver( const DC_FUNCTIONS
*funcs
);
434 extern BOOL
DRIVER_GetDriverName( LPCSTR device
, LPSTR driver
, DWORD size
);
436 extern POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
);
438 extern DC
* DC_AllocDC( const DC_FUNCTIONS
*funcs
);
439 extern DC
* DC_GetDCPtr( HDC hdc
);
440 extern DC
* DC_GetDCUpdate( HDC hdc
);
441 extern void DC_InitDC( DC
* dc
);
442 extern void DC_UpdateXforms( DC
* dc
);
445 extern void CLIPPING_UpdateGCRegion( DC
* dc
);
448 extern HENHMETAFILE
EMF_Create_HENHMETAFILE(ENHMETAHEADER
*emh
, BOOL on_disk
);
451 extern HMETAFILE
MF_Create_HMETAFILE(METAHEADER
*mh
);
452 extern HMETAFILE16
MF_Create_HMETAFILE16(METAHEADER
*mh
);
453 extern METAHEADER
*MF_CreateMetaHeaderDisk(METAHEADER
*mr
, LPCSTR filename
);
456 extern BOOL
REGION_FrameRgn( HRGN dest
, HRGN src
, INT x
, INT y
);
459 extern HPALETTE WINAPI
GDISelectPalette( HDC hdc
, HPALETTE hpal
, WORD wBkg
);
460 extern UINT WINAPI
GDIRealizePalette( HDC hdc
);
462 #define WINE_GGO_GRAY16_BITMAP 0x7f
464 #endif /* __WINE_GDI_H */