Large-scale renaming of all Win32 functions and types to use the
[wine/multimedia.git] / graphics / metafiledrv / init.c
blob197d5d5bf779c0184db8835c9bb9dc36faa0c6c5
1 /*
2 * Metafile driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include "windef.h"
8 #include "wine/winbase16.h"
9 #include "dc.h"
10 #include "heap.h"
11 #include "global.h"
12 #include "metafile.h"
13 #include "metafiledrv.h"
14 #include "debug.h"
16 #include <string.h>
18 static const DC_FUNCTIONS MFDRV_Funcs =
20 MFDRV_Arc, /* pArc */
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 */
30 NULL, /* pEscape */
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 */
49 MFDRV_Pie, /* pPie */
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 */
59 NULL, /* pSaveDC */
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 */
73 NULL, /* pSetROP2 */
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 /**********************************************************************
91 * MFDRV_AllocMetaFile
93 static DC *MFDRV_AllocMetaFile(void)
95 DC *dc;
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));
102 if (!physDev)
104 GDI_HEAP_FREE( dc->hSelf );
105 return NULL;
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 );
113 return NULL;
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 ); */
126 return dc;
130 /**********************************************************************
131 * MFDRV_DeleteDC
133 static BOOL 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 );
139 dc->physDev = NULL;
140 GDI_FreeObject(dc->hSelf);
141 return TRUE;
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.
151 * RETURNS
152 * A handle to the metafile DC if successful, NULL on failure.
154 HDC16 WINAPI CreateMetaFile16(
155 LPCSTR filename /* Filename of disk metafile */
158 DC *dc;
159 METAFILEDRV_PDEVICE *physDev;
160 HFILE hFile;
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 = _lcreat( filename, 0 )) == HFILE_ERROR)
172 MFDRV_DeleteDC( dc );
173 return 0;
175 if (_lwrite( hFile, (LPSTR)physDev->mh,
176 sizeof(*physDev->mh)) == HFILE_ERROR)
178 MFDRV_DeleteDC( dc );
179 return 0;
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);
188 return dc->hSelf;
191 /**********************************************************************
192 * CreateMetaFile32A (GDI32.51)
194 HDC WINAPI CreateMetaFileA(
195 LPCSTR filename /* Filename of disk metafile */
198 return CreateMetaFile16( filename );
201 /**********************************************************************
202 * CreateMetaFile32W (GDI32.52)
204 HDC WINAPI CreateMetaFileW(LPCWSTR filename)
206 LPSTR filenameA;
207 HDC hReturnDC;
209 filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
211 hReturnDC = CreateMetaFileA(filenameA);
213 HeapFree( GetProcessHeap(), 0, filenameA );
215 return hReturnDC;
218 static DC *METAFILE_CloseMetaFile( HDC hdc )
220 DC *dc;
221 HFILE hFile;
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 );
236 return 0;
239 if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */
241 hFile = physDev->mh->mtNoParameters;
242 physDev->mh->mtNoParameters = 0;
243 if (_llseek(hFile, 0L, 0) == HFILE_ERROR)
245 MFDRV_DeleteDC( dc );
246 return 0;
248 if (_lwrite( hFile, (LPSTR)physDev->mh,
249 sizeof(*physDev->mh)) == HFILE_ERROR)
251 MFDRV_DeleteDC( dc );
252 return 0;
254 _lclose(hFile);
257 return dc;
260 /******************************************************************
261 * CloseMetaFile16 (GDI.126)
263 HMETAFILE16 WINAPI CloseMetaFile16(
264 HDC16 hdc /* Metafile DC to close */
267 HMETAFILE16 hmf;
268 METAFILEDRV_PDEVICE *physDev;
269 DC *dc = METAFILE_CloseMetaFile(hdc);
270 if (!dc) return 0;
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 GetCurrentPDB16(), FALSE, FALSE, FALSE, NULL );
278 physDev->mh = NULL; /* So it won't be deleted */
279 MFDRV_DeleteDC( dc );
280 return hmf;
283 /******************************************************************
284 * CloseMetaFile32 (GDI32.17)
286 * Stop recording graphics operations in metafile associated with
287 * hdc and retrieve metafile.
289 * RETURNS
290 * Handle of newly created metafile on success, NULL on failure.
292 HMETAFILE WINAPI CloseMetaFile(
293 HDC hdc /* Metafile DC to close */
296 return CloseMetaFile16(hdc);
300 /******************************************************************
301 * DeleteMetaFile16 (GDI.127)
303 BOOL16 WINAPI DeleteMetaFile16(
304 HMETAFILE16 hmf
305 /* Handle of memory metafile to delete */
308 return !GlobalFree16( hmf );
311 /******************************************************************
312 * DeleteMetaFile32 (GDI32.69)
314 * Delete a memory-based metafile.
317 BOOL WINAPI DeleteMetaFile(
318 HMETAFILE hmf
320 return !GlobalFree16( hmf );
323 /********************************************************************
325 Enhanced Metafile driver initializations
327 This possibly should be moved to their own file/directory
328 at some point.
330 **********************************************************************/
332 /**********************************************************************
333 * CreateEnhMetaFile32A (GDI32.41)
335 HDC WINAPI CreateEnhMetaFileA(
336 HDC hdc, /* optional reference DC */
337 LPCSTR filename, /* optional filename for disk metafiles */
338 const RECT *rect, /* optional bounding rectangle */
339 LPCSTR description /* optional description */
342 #if 0
343 DC *dc;
344 METAFILEDRV_PDEVICE *physDev;
345 HFILE hFile;
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 = _lcreat( filename, 0 )) == HFILE_ERROR)
355 MFDRV_DeleteDC( dc );
356 return 0;
358 if (_lwrite( hFile, (LPSTR)physDev->mh,
359 sizeof(*physDev->mh)) == HFILE_ERROR)
361 MFDRV_DeleteDC( dc );
362 return 0;
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);
371 return dc->hSelf;
372 #endif
374 FIXME(metafile, "(0x%lx,%s,%p,%s): stub\n",
375 (DWORD)hdc, filename, rect, description);
377 return 0;
380 /**********************************************************************
381 * CreateEnhMetaFile32W (GDI32.42)
383 HDC WINAPI CreateEnhMetaFileW(
384 HDC hdc, /* optional reference DC */
385 LPCWSTR filename, /* optional filename for disk metafiles */
386 const RECT* rect, /* optional bounding rectangle */
387 LPCWSTR description /* optional description */
390 LPSTR filenameA;
391 LPSTR descriptionA;
392 HDC hReturnDC;
394 filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
395 descriptionA = HEAP_strdupWtoA( GetProcessHeap(), 0, description );
397 hReturnDC = CreateEnhMetaFileA(hdc,
398 filenameA,
399 rect,
400 descriptionA);
402 HeapFree( GetProcessHeap(), 0, filenameA );
403 HeapFree( GetProcessHeap(), 0, descriptionA );
405 return hReturnDC;
408 HENHMETAFILE WINAPI CloseEnhMetaFile( HDC hdc /* metafile DC */ )
410 /* write EMR_EOF(0x0, 0x10, 0x14) */
411 return 0;