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