2 * Metafile driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
8 #include "wine/winbase16.h"
13 #include "metafiledrv.h"
18 static const DC_FUNCTIONS MFDRV_Funcs =
21 MFDRV_BitBlt, /* pBitBlt */
22 NULL, /* pBitmapBits */
23 MFDRV_Chord, /* pChord */
24 NULL, /* pCreateBitmap */
25 NULL, /* no implementation */ /* pCreateDC */
26 NULL, /* no implementation */ /* pDeleteDC */
27 NULL, /* pDeleteObject */
28 MFDRV_Ellipse, /* pEllipse */
29 NULL, /* pEnumDeviceFonts */
31 NULL, /* pExcludeClipRect */
32 NULL, /* pExcludeVisRect */
33 MFDRV_ExtFloodFill, /* pExtFloodFill */
34 MFDRV_ExtTextOut, /* pExtTextOut */
35 NULL, /* pGetCharWidth */
36 NULL, /* no implementation */ /* pGetPixel */
37 NULL, /* pGetTextExtentPoint */
38 NULL, /* pGetTextMetrics */
39 NULL, /* pIntersectClipRect */
40 NULL, /* pIntersectVisRect */
41 MFDRV_LineTo, /* pLineTo */
42 NULL, /* pLoadOEMResource */
43 MFDRV_MoveToEx, /* pMoveToEx */
44 NULL, /* pOffsetClipRgn */
45 MFDRV_OffsetViewportOrg, /* pOffsetViewportOrg */
46 MFDRV_OffsetWindowOrg, /* pOffsetWindowOrg */
47 MFDRV_PaintRgn, /* pPaintRgn */
48 MFDRV_PatBlt, /* pPatBlt */
50 MFDRV_PolyPolygon, /* pPolyPolygon */
51 NULL, /* pPolyPolyline */
52 MFDRV_Polygon, /* pPolygon */
53 MFDRV_Polyline, /* pPolyline */
54 NULL, /* pPolyBezier */
55 NULL, /* pRealizePalette */
56 MFDRV_Rectangle, /* pRectangle */
57 NULL, /* pRestoreDC */
58 MFDRV_RoundRect, /* pRoundRect */
60 MFDRV_ScaleViewportExt, /* pScaleViewportExt */
61 MFDRV_ScaleWindowExt, /* pScaleWindowExt */
62 NULL, /* pSelectClipRgn */
63 MFDRV_SelectObject, /* pSelectObject */
64 NULL, /* pSelectPalette */
65 MFDRV_SetBkColor, /* pSetBkColor */
66 NULL, /* pSetBkMode */
67 NULL, /* pSetDeviceClipping */
68 NULL, /* pSetDIBitsToDevice */
69 MFDRV_SetMapMode, /* pSetMapMode */
70 NULL, /* pSetMapperFlags */
71 MFDRV_SetPixel, /* pSetPixel */
72 NULL, /* pSetPolyFillMode */
74 NULL, /* pSetRelAbs */
75 NULL, /* pSetStretchBltMode */
76 NULL, /* pSetTextAlign */
77 NULL, /* pSetTextCharacterExtra */
78 MFDRV_SetTextColor, /* pSetTextColor */
79 NULL, /* pSetTextJustification */
80 MFDRV_SetViewportExt, /* pSetViewportExt */
81 MFDRV_SetViewportOrg, /* pSetViewportOrg */
82 MFDRV_SetWindowExt, /* pSetWindowExt */
83 MFDRV_SetWindowOrg, /* pSetWindowOrg */
84 MFDRV_StretchBlt, /* pStretchBlt */
85 NULL /* pStretchDIBits */
90 /**********************************************************************
93 static DC *MFDRV_AllocMetaFile(void)
96 METAFILEDRV_PDEVICE *physDev;
98 if (!(dc = DC_AllocDC( &MFDRV_Funcs ))) return NULL;
99 dc->header.wMagic = METAFILE_DC_MAGIC;
101 physDev = (METAFILEDRV_PDEVICE *)HeapAlloc(SystemHeap,0,sizeof(*physDev));
104 GDI_HEAP_FREE( dc->hSelf );
107 dc->physDev = physDev;
109 if (!(physDev->mh = HeapAlloc( SystemHeap, 0, sizeof(*physDev->mh) )))
111 HeapFree( SystemHeap, 0, physDev );
112 GDI_HEAP_FREE( dc->hSelf );
116 physDev->nextHandle = 0;
118 physDev->mh->mtHeaderSize = sizeof(METAHEADER) / sizeof(WORD);
119 physDev->mh->mtVersion = 0x0300;
120 physDev->mh->mtSize = physDev->mh->mtHeaderSize;
121 physDev->mh->mtNoObjects = 0;
122 physDev->mh->mtMaxRecord = 0;
123 physDev->mh->mtNoParameters = 0;
125 /* DC_InitDC( dc ); */
130 /**********************************************************************
133 static BOOL32 MFDRV_DeleteDC( DC *dc )
135 METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
137 if (physDev->mh) HeapFree( SystemHeap, 0, physDev->mh );
138 HeapFree( SystemHeap, 0, physDev );
140 GDI_FreeObject(dc->hSelf);
145 /**********************************************************************
146 * CreateMetaFile16 (GDI.125)
148 * Create a new DC and associate it with a metafile. Pass a filename
149 * to create a disk-based metafile, NULL to create a memory metafile.
152 * A handle to the metafile DC if successful, NULL on failure.
154 HDC16 WINAPI CreateMetaFile16(
155 LPCSTR filename /* Filename of disk metafile */
159 METAFILEDRV_PDEVICE *physDev;
162 TRACE(metafile, "'%s'\n", filename );
164 if (!(dc = MFDRV_AllocMetaFile())) return 0;
165 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
167 if (filename) /* disk based metafile */
169 physDev->mh->mtType = METAFILE_DISK;
170 if ((hFile = _lcreat32( filename, 0 )) == HFILE_ERROR32)
172 MFDRV_DeleteDC( dc );
175 if (_lwrite32( hFile, (LPSTR)physDev->mh,
176 sizeof(*physDev->mh)) == HFILE_ERROR32)
178 MFDRV_DeleteDC( dc );
181 physDev->mh->mtNoParameters = hFile; /* store file descriptor here */
182 /* windows probably uses this too*/
184 else /* memory based metafile */
185 physDev->mh->mtType = METAFILE_MEMORY;
187 TRACE(metafile, "returning %04x\n", dc->hSelf);
191 /**********************************************************************
192 * CreateMetaFile32A (GDI32.51)
194 HDC32 WINAPI CreateMetaFile32A(
195 LPCSTR filename /* Filename of disk metafile */
198 return CreateMetaFile16( filename );
201 /**********************************************************************
202 * CreateMetaFile32W (GDI32.52)
204 HDC32 WINAPI CreateMetaFile32W(LPCWSTR filename)
209 filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
211 hReturnDC = CreateMetaFile32A(filenameA);
213 HeapFree( GetProcessHeap(), 0, filenameA );
218 static DC *METAFILE_CloseMetaFile( HDC32 hdc )
222 METAFILEDRV_PDEVICE *physDev;
224 TRACE(metafile, "(%04x)\n", hdc );
226 if (!(dc = (DC *) GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC ))) return 0;
227 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
229 /* Construct the end of metafile record - this is documented
230 * in SDK Knowledgebase Q99334.
233 if (!MF_MetaParam0(dc, META_EOF))
235 MFDRV_DeleteDC( dc );
239 if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */
241 hFile = physDev->mh->mtNoParameters;
242 physDev->mh->mtNoParameters = 0;
243 if (_llseek32(hFile, 0L, 0) == HFILE_ERROR32)
245 MFDRV_DeleteDC( dc );
248 if (_lwrite32( hFile, (LPSTR)physDev->mh,
249 sizeof(*physDev->mh)) == HFILE_ERROR32)
251 MFDRV_DeleteDC( dc );
260 /******************************************************************
261 * CloseMetaFile16 (GDI.126)
263 HMETAFILE16 WINAPI CloseMetaFile16(
264 HDC16 hdc /* Metafile DC to close */
268 METAFILEDRV_PDEVICE *physDev;
269 DC *dc = METAFILE_CloseMetaFile(hdc);
271 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
273 /* Now allocate a global handle for the metafile */
275 hmf = GLOBAL_CreateBlock( GMEM_MOVEABLE, physDev->mh,
276 physDev->mh->mtSize * sizeof(WORD),
277 GetCurrentPDB(), FALSE, FALSE, FALSE, NULL );
278 physDev->mh = NULL; /* So it won't be deleted */
279 MFDRV_DeleteDC( dc );
283 /******************************************************************
284 * CloseMetaFile32 (GDI32.17)
286 * Stop recording graphics operations in metafile associated with
287 * hdc and retrieve metafile.
290 * Handle of newly created metafile on success, NULL on failure.
292 HMETAFILE32 WINAPI CloseMetaFile32(
293 HDC32 hdc /* Metafile DC to close */
296 return CloseMetaFile16(hdc);
300 /******************************************************************
301 * DeleteMetaFile16 (GDI.127)
303 BOOL16 WINAPI DeleteMetaFile16(
305 /* Handle of memory metafile to delete */
308 return !GlobalFree16( hmf );
311 /******************************************************************
312 * DeleteMetaFile32 (GDI32.69)
314 * Delete a memory-based metafile.
317 BOOL32 WINAPI DeleteMetaFile32(
320 return !GlobalFree16( hmf );
323 /********************************************************************
325 Enhanced Metafile driver initializations
327 This possibly should be moved to their own file/directory
330 **********************************************************************/
332 /**********************************************************************
333 * CreateEnhMetaFile32A (GDI32.41)
335 HDC32 WINAPI CreateEnhMetaFile32A(
336 HDC32 hdc, /* optional reference DC */
337 LPCSTR filename, /* optional filename for disk metafiles */
338 const RECT32 *rect, /* optional bounding rectangle */
339 LPCSTR description /* optional description */
344 METAFILEDRV_PDEVICE *physDev;
347 if (!(dc = MFDRV_AllocMetaFile())) return 0;
348 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
350 if (filename) /* disk based metafile */
352 physDev->mh->mtType = METAFILE_DISK;
353 if ((hFile = _lcreat32( filename, 0 )) == HFILE_ERROR32)
355 MFDRV_DeleteDC( dc );
358 if (_lwrite32( hFile, (LPSTR)physDev->mh,
359 sizeof(*physDev->mh)) == HFILE_ERROR32)
361 MFDRV_DeleteDC( dc );
364 physDev->mh->mtNoParameters = hFile; /* store file descriptor here */
365 /* windows probably uses this too*/
367 else /* memory based metafile */
368 physDev->mh->mtType = METAFILE_MEMORY;
370 TRACE(metafile, "returning %04x\n", dc->hSelf);
374 FIXME(metafile, "(0x%lx,%s,%p,%s): stub\n",
375 (DWORD)hdc, filename, rect, description);
380 /**********************************************************************
381 * CreateEnhMetaFile32W (GDI32.42)
383 HDC32 WINAPI CreateEnhMetaFile32W(
384 HDC32 hdc, /* optional reference DC */
385 LPCWSTR filename, /* optional filename for disk metafiles */
386 const RECT32* rect, /* optional bounding rectangle */
387 LPCWSTR description /* optional description */
394 filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
395 descriptionA = HEAP_strdupWtoA( GetProcessHeap(), 0, description );
397 hReturnDC = CreateEnhMetaFile32A(hdc,
402 HeapFree( GetProcessHeap(), 0, filenameA );
403 HeapFree( GetProcessHeap(), 0, descriptionA );
408 HENHMETAFILE32 WINAPI CloseEnhMetaFile( HDC32 hdc /* metafile DC */ )
410 /* write EMR_EOF(0x0, 0x10, 0x14) */