Release 970415
[wine/multimedia.git] / graphics / metafiledrv / init.c
bloba5ffa69976f8c2c7444279eb0b74d2e2a2ff64ad
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 BOOL32 MFDRV_DeleteDC( DC *dc );
17 static const DC_FUNCTIONS MFDRV_Funcs =
19 MFDRV_Arc, /* pArc */
20 MFDRV_BitBlt, /* pBitBlt */
21 MFDRV_Chord, /* pChord */
22 NULL, /* pCreateDC */
23 MFDRV_DeleteDC, /* pDeleteDC */
24 NULL, /* pDeleteObject */
25 MFDRV_Ellipse, /* pEllipse */
26 NULL, /* pEnumDeviceFonts */
27 NULL, /* pEscape */
28 NULL, /* pExcludeClipRect */
29 NULL, /* pExcludeVisRect */
30 MFDRV_ExtFloodFill, /* pExtFloodFill */
31 MFDRV_ExtTextOut, /* pExtTextOut */
32 NULL, /* pGetCharWidth */
33 NULL /* no implementation */, /* pGetPixel */
34 NULL, /* pGetTextExtentPoint */
35 NULL, /* pGetTextMetrics */
36 NULL, /* pIntersectClipRect */
37 NULL, /* pIntersectVisRect */
38 MFDRV_LineTo, /* pLineTo */
39 MFDRV_MoveToEx, /* pMoveToEx */
40 NULL, /* pOffsetClipRgn */
41 MFDRV_OffsetViewportOrg, /* pOffsetViewportOrg */
42 MFDRV_OffsetWindowOrg, /* pOffsetWindowOrg */
43 NULL, /* pPaintRgn */
44 MFDRV_PatBlt, /* pPatBlt */
45 MFDRV_Pie, /* pPie */
46 MFDRV_PolyPolygon, /* pPolyPolygon */
47 MFDRV_Polygon, /* pPolygon */
48 MFDRV_Polyline, /* pPolyline */
49 NULL, /* pRealizePalette */
50 MFDRV_Rectangle, /* pRectangle */
51 NULL, /* pRestoreDC */
52 MFDRV_RoundRect, /* pRoundRect */
53 NULL, /* pSaveDC */
54 MFDRV_ScaleViewportExt, /* pScaleViewportExt */
55 MFDRV_ScaleWindowExt, /* pScaleWindowExt */
56 NULL, /* pSelectClipRgn */
57 MFDRV_SelectObject, /* pSelectObject */
58 NULL, /* pSelectPalette */
59 NULL, /* pSetBkColor */
60 NULL, /* pSetBkMode */
61 NULL, /* pSetDeviceClipping */
62 NULL, /* pSetDIBitsToDevice */
63 MFDRV_SetMapMode, /* pSetMapMode */
64 NULL, /* pSetMapperFlags */
65 MFDRV_SetPixel, /* pSetPixel */
66 NULL, /* pSetPolyFillMode */
67 NULL, /* pSetROP2 */
68 NULL, /* pSetRelAbs */
69 NULL, /* pSetStretchBltMode */
70 NULL, /* pSetTextAlign */
71 NULL, /* pSetTextCharacterExtra */
72 NULL, /* pSetTextColor */
73 NULL, /* pSetTextJustification */
74 MFDRV_SetViewportExt, /* pSetViewportExt */
75 MFDRV_SetViewportOrg, /* pSetViewportOrg */
76 MFDRV_SetWindowExt, /* pSetWindowExt */
77 MFDRV_SetWindowOrg, /* pSetWindowOrg */
78 MFDRV_StretchBlt, /* pStretchBlt */
79 NULL /* pStretchDIBits */
84 /**********************************************************************
85 * MFDRV_AllocMetaFile
87 static DC *MFDRV_AllocMetaFile(void)
89 DC *dc;
90 METAFILEDRV_PDEVICE *physDev;
92 if (!(dc = DC_AllocDC( &MFDRV_Funcs ))) return NULL;
93 dc->header.wMagic = METAFILE_DC_MAGIC;
95 physDev = (METAFILEDRV_PDEVICE *)HeapAlloc(SystemHeap,0,sizeof(*physDev));
96 if (!physDev)
98 GDI_HEAP_FREE( dc->hSelf );
99 return NULL;
101 dc->physDev = physDev;
103 if (!(physDev->mh = HeapAlloc( SystemHeap, 0, sizeof(*physDev->mh) )))
105 HeapFree( SystemHeap, 0, physDev );
106 GDI_HEAP_FREE( dc->hSelf );
107 return NULL;
110 physDev->nextHandle = 0;
112 physDev->mh->mtHeaderSize = sizeof(METAHEADER) / sizeof(WORD);
113 physDev->mh->mtVersion = 0x0300;
114 physDev->mh->mtSize = physDev->mh->mtHeaderSize;
115 physDev->mh->mtNoObjects = 0;
116 physDev->mh->mtMaxRecord = 0;
117 physDev->mh->mtNoParameters = 0;
119 /* DC_InitDC( dc ); */
120 return dc;
124 /**********************************************************************
125 * MFDRV_DeleteDC
127 static BOOL32 MFDRV_DeleteDC( DC *dc )
129 METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
131 if (physDev->mh) HeapFree( SystemHeap, 0, physDev->mh );
132 HeapFree( SystemHeap, 0, physDev );
133 dc->physDev = NULL;
134 return TRUE;
138 /**********************************************************************
139 * CreateMetafile16 (GDI.125)
141 HDC16 CreateMetaFile16( LPCSTR filename )
143 DC *dc;
144 METAFILEDRV_PDEVICE *physDev;
145 HFILE32 hFile;
147 dprintf_metafile( stddeb, "CreateMetaFile16: '%s'\n", filename );
149 if (!(dc = MFDRV_AllocMetaFile())) return 0;
150 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
152 if (filename) /* disk based metafile */
154 physDev->mh->mtType = METAFILE_DISK;
155 if ((hFile = _lcreat32( filename, 0 )) == HFILE_ERROR32)
157 DeleteDC32( dc->hSelf );
158 return 0;
160 if (_lwrite32( hFile, (LPSTR)physDev->mh,
161 sizeof(*physDev->mh)) == HFILE_ERROR32)
163 DeleteDC32( dc->hSelf );
164 return 0;
166 physDev->mh->mtNoParameters = hFile; /* store file descriptor here */
167 /* windows probably uses this too*/
169 else /* memory based metafile */
170 physDev->mh->mtType = METAFILE_MEMORY;
172 dprintf_metafile( stddeb, "CreateMetaFile16: returning %04x\n", dc->hSelf);
173 return dc->hSelf;
177 /******************************************************************
178 * CloseMetafile16 (GDI.126)
180 HMETAFILE16 CloseMetaFile16( HDC16 hdc )
182 DC *dc;
183 HMETAFILE16 hmf;
184 HFILE32 hFile;
185 METAFILEDRV_PDEVICE *physDev;
187 dprintf_metafile( stddeb, "CloseMetaFile(%04x)\n", hdc );
189 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
190 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
192 /* Construct the end of metafile record - this is documented
193 * in SDK Knowledgebase Q99334.
196 if (!MF_MetaParam0(dc, META_EOF))
198 DeleteDC32( hdc );
199 return 0;
202 if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */
204 hFile = physDev->mh->mtNoParameters;
205 physDev->mh->mtNoParameters = 0;
206 if (_llseek32(hFile, 0L, 0) == HFILE_ERROR32)
208 DeleteDC32( hdc );
209 return 0;
211 if (_lwrite32( hFile, (LPSTR)physDev->mh,
212 sizeof(*physDev->mh)) == HFILE_ERROR32)
214 DeleteDC32( hdc );
215 return 0;
217 _lclose32(hFile);
220 /* Now allocate a global handle for the metafile */
222 hmf = GLOBAL_CreateBlock( GMEM_MOVEABLE, physDev->mh,
223 physDev->mh->mtSize * sizeof(WORD),
224 GetCurrentPDB(), FALSE, FALSE, FALSE, NULL );
225 physDev->mh = NULL; /* So it won't be deleted */
226 DeleteDC32( hdc );
227 return hmf;
231 /******************************************************************
232 * DeleteMetafile16 (GDI.127)
234 BOOL16 DeleteMetaFile16( HMETAFILE16 hmf )
236 return !GlobalFree16( hmf );