Release 980201
[wine/multimedia.git] / graphics / metafiledrv / init.c
blob58587f04df034d0527d965af831eb993a94190e7
1 /*
2 * Metafile driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include "metafiledrv.h"
8 #include "dc.h"
9 #include "heap.h"
10 #include "global.h"
11 #include "metafile.h"
12 #include "stddebug.h"
13 #include "debug.h"
15 static const DC_FUNCTIONS MFDRV_Funcs =
17 MFDRV_Arc, /* pArc */
18 MFDRV_BitBlt, /* pBitBlt */
19 MFDRV_Chord, /* pChord */
20 NULL, /* no implementation */ /* pCreateDC */
21 NULL, /* no implementation */ /* pDeleteDC */
22 NULL, /* pDeleteObject */
23 MFDRV_Ellipse, /* pEllipse */
24 NULL, /* pEnumDeviceFonts */
25 NULL, /* pEscape */
26 NULL, /* pExcludeClipRect */
27 NULL, /* pExcludeVisRect */
28 MFDRV_ExtFloodFill, /* pExtFloodFill */
29 MFDRV_ExtTextOut, /* pExtTextOut */
30 NULL, /* pGetCharWidth */
31 NULL, /* no implementation */ /* pGetPixel */
32 NULL, /* pGetTextExtentPoint */
33 NULL, /* pGetTextMetrics */
34 NULL, /* pIntersectClipRect */
35 NULL, /* pIntersectVisRect */
36 MFDRV_LineTo, /* pLineTo */
37 MFDRV_MoveToEx, /* pMoveToEx */
38 NULL, /* pOffsetClipRgn */
39 MFDRV_OffsetViewportOrg, /* pOffsetViewportOrg */
40 MFDRV_OffsetWindowOrg, /* pOffsetWindowOrg */
41 MFDRV_PaintRgn, /* pPaintRgn */
42 MFDRV_PatBlt, /* pPatBlt */
43 MFDRV_Pie, /* pPie */
44 MFDRV_PolyPolygon, /* pPolyPolygon */
45 MFDRV_Polygon, /* pPolygon */
46 MFDRV_Polyline, /* pPolyline */
47 NULL, /* pRealizePalette */
48 MFDRV_Rectangle, /* pRectangle */
49 NULL, /* pRestoreDC */
50 MFDRV_RoundRect, /* pRoundRect */
51 NULL, /* pSaveDC */
52 MFDRV_ScaleViewportExt, /* pScaleViewportExt */
53 MFDRV_ScaleWindowExt, /* pScaleWindowExt */
54 NULL, /* pSelectClipRgn */
55 MFDRV_SelectObject, /* pSelectObject */
56 NULL, /* pSelectPalette */
57 NULL, /* pSetBkColor */
58 NULL, /* pSetBkMode */
59 NULL, /* pSetDeviceClipping */
60 NULL, /* pSetDIBitsToDevice */
61 MFDRV_SetMapMode, /* pSetMapMode */
62 NULL, /* pSetMapperFlags */
63 MFDRV_SetPixel, /* pSetPixel */
64 NULL, /* pSetPolyFillMode */
65 NULL, /* pSetROP2 */
66 NULL, /* pSetRelAbs */
67 NULL, /* pSetStretchBltMode */
68 NULL, /* pSetTextAlign */
69 NULL, /* pSetTextCharacterExtra */
70 NULL, /* pSetTextColor */
71 NULL, /* pSetTextJustification */
72 MFDRV_SetViewportExt, /* pSetViewportExt */
73 MFDRV_SetViewportOrg, /* pSetViewportOrg */
74 MFDRV_SetWindowExt, /* pSetWindowExt */
75 MFDRV_SetWindowOrg, /* pSetWindowOrg */
76 MFDRV_StretchBlt, /* pStretchBlt */
77 NULL /* pStretchDIBits */
82 /**********************************************************************
83 * MFDRV_AllocMetaFile
85 static DC *MFDRV_AllocMetaFile(void)
87 DC *dc;
88 METAFILEDRV_PDEVICE *physDev;
90 if (!(dc = DC_AllocDC( &MFDRV_Funcs ))) return NULL;
91 dc->header.wMagic = METAFILE_DC_MAGIC;
93 physDev = (METAFILEDRV_PDEVICE *)HeapAlloc(SystemHeap,0,sizeof(*physDev));
94 if (!physDev)
96 GDI_HEAP_FREE( dc->hSelf );
97 return NULL;
99 dc->physDev = physDev;
101 if (!(physDev->mh = HeapAlloc( SystemHeap, 0, sizeof(*physDev->mh) )))
103 HeapFree( SystemHeap, 0, physDev );
104 GDI_HEAP_FREE( dc->hSelf );
105 return NULL;
108 physDev->nextHandle = 0;
110 physDev->mh->mtHeaderSize = sizeof(METAHEADER) / sizeof(WORD);
111 physDev->mh->mtVersion = 0x0300;
112 physDev->mh->mtSize = physDev->mh->mtHeaderSize;
113 physDev->mh->mtNoObjects = 0;
114 physDev->mh->mtMaxRecord = 0;
115 physDev->mh->mtNoParameters = 0;
117 /* DC_InitDC( dc ); */
118 return dc;
122 /**********************************************************************
123 * MFDRV_DeleteDC
125 static BOOL32 MFDRV_DeleteDC( DC *dc )
127 METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
129 if (physDev->mh) HeapFree( SystemHeap, 0, physDev->mh );
130 HeapFree( SystemHeap, 0, physDev );
131 dc->physDev = NULL;
132 GDI_FreeObject(dc->hSelf);
133 return TRUE;
137 /**********************************************************************
138 * CreateMetaFile16 (GDI.125)
140 * Create a new DC and associate it with a metafile. Pass a filename
141 * to create a disk-based metafile, NULL to create a memory metafile.
143 * RETURNS
144 * A handle to the metafile DC if successful, NULL on failure.
146 HDC16 WINAPI CreateMetaFile16(
147 LPCSTR filename /* Filename of disk metafile */
150 DC *dc;
151 METAFILEDRV_PDEVICE *physDev;
152 HFILE32 hFile;
154 dprintf_metafile( stddeb, "CreateMetaFile16: '%s'\n", filename );
156 if (!(dc = MFDRV_AllocMetaFile())) return 0;
157 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
159 if (filename) /* disk based metafile */
161 physDev->mh->mtType = METAFILE_DISK;
162 if ((hFile = _lcreat32( filename, 0 )) == HFILE_ERROR32)
164 MFDRV_DeleteDC( dc );
165 return 0;
167 if (_lwrite32( hFile, (LPSTR)physDev->mh,
168 sizeof(*physDev->mh)) == HFILE_ERROR32)
170 MFDRV_DeleteDC( dc );
171 return 0;
173 physDev->mh->mtNoParameters = hFile; /* store file descriptor here */
174 /* windows probably uses this too*/
176 else /* memory based metafile */
177 physDev->mh->mtType = METAFILE_MEMORY;
179 dprintf_metafile( stddeb, "CreateMetaFile16: returning %04x\n", dc->hSelf);
180 return dc->hSelf;
184 /******************************************************************
185 * CloseMetaFile16 (GDI.126)
187 * Stop recording graphics operations in metafile associated with
188 * hdc and retrieve metafile.
190 * RETURNS
191 * Handle of newly created metafile on success, NULL on failure.
193 HMETAFILE16 WINAPI CloseMetaFile16(
194 HDC16 hdc /* Metafile DC to close */
197 DC *dc;
198 HMETAFILE16 hmf;
199 HFILE32 hFile;
200 METAFILEDRV_PDEVICE *physDev;
202 dprintf_metafile( stddeb, "CloseMetaFile(%04x)\n", hdc );
204 if (!(dc = (DC *) GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC ))) return 0;
205 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
207 /* Construct the end of metafile record - this is documented
208 * in SDK Knowledgebase Q99334.
211 if (!MF_MetaParam0(dc, META_EOF))
213 MFDRV_DeleteDC( dc );
214 return 0;
217 if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */
219 hFile = physDev->mh->mtNoParameters;
220 physDev->mh->mtNoParameters = 0;
221 if (_llseek32(hFile, 0L, 0) == HFILE_ERROR32)
223 MFDRV_DeleteDC( dc );
224 return 0;
226 if (_lwrite32( hFile, (LPSTR)physDev->mh,
227 sizeof(*physDev->mh)) == HFILE_ERROR32)
229 MFDRV_DeleteDC( dc );
230 return 0;
232 _lclose32(hFile);
235 /* Now allocate a global handle for the metafile */
237 hmf = GLOBAL_CreateBlock( GMEM_MOVEABLE, physDev->mh,
238 physDev->mh->mtSize * sizeof(WORD),
239 GetCurrentPDB(), FALSE, FALSE, FALSE, NULL );
240 physDev->mh = NULL; /* So it won't be deleted */
241 MFDRV_DeleteDC( dc );
242 return hmf;
246 /******************************************************************
247 * DeleteMetaFile16 (GDI.127)
249 * Delete a memory-based metafile.
252 BOOL16 WINAPI DeleteMetaFile16(
253 HMETAFILE16 hmf
254 /* Handle of memory metafile to delete */
257 return !GlobalFree16( hmf );