Release 961222
[wine/gsoc-2012-control.git] / graphics / metafiledrv / init.c
blobf1d34546f84e6927cf9d785d87bf0e4cd432681b
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 NULL, /* pArc */
20 MFDRV_BitBlt, /* pBitBlt */
21 NULL, /* pChord */
22 NULL, /* pCreateDC */
23 MFDRV_DeleteDC, /* pDeleteDC */
24 NULL, /* pDeleteObject */
25 NULL, /* pEllipse */
26 NULL, /* pEscape */
27 NULL, /* pExcludeClipRect */
28 NULL, /* pExcludeVisRect */
29 NULL, /* pExtFloodFill */
30 NULL, /* pExtTextOut */
31 NULL, /* pFillRgn */
32 NULL, /* pFloodFill */
33 NULL, /* pFrameRgn */
34 NULL, /* pGetTextExtentPoint */
35 NULL, /* pGetTextMetrics */
36 NULL, /* pIntersectClipRect */
37 NULL, /* pIntersectVisRect */
38 NULL, /* pInvertRgn */
39 NULL, /* pLineTo */
40 NULL, /* pMoveToEx */
41 NULL, /* pOffsetClipRgn */
42 MFDRV_OffsetViewportOrg, /* pOffsetViewportOrg */
43 MFDRV_OffsetWindowOrg, /* pOffsetWindowOrg */
44 NULL, /* pPaintRgn */
45 MFDRV_PatBlt, /* pPatBlt */
46 NULL, /* pPie */
47 NULL, /* pPolyPolygon */
48 NULL, /* pPolygon */
49 NULL, /* pPolyline */
50 NULL, /* pRealizePalette */
51 NULL, /* pRectangle */
52 NULL, /* pRestoreDC */
53 NULL, /* pRoundRect */
54 NULL, /* pSaveDC */
55 MFDRV_ScaleViewportExt, /* pScaleViewportExt */
56 MFDRV_ScaleWindowExt, /* pScaleWindowExt */
57 NULL, /* pSelectClipRgn */
58 NULL, /* pSelectObject */
59 NULL, /* pSelectPalette */
60 NULL, /* pSetBkColor */
61 NULL, /* pSetBkMode */
62 NULL, /* pSetDeviceClipping */
63 NULL, /* pSetDIBitsToDevice */
64 MFDRV_SetMapMode, /* pSetMapMode */
65 NULL, /* pSetMapperFlags */
66 NULL, /* pSetPixel */
67 NULL, /* pSetPolyFillMode */
68 NULL, /* pSetROP2 */
69 NULL, /* pSetRelAbs */
70 NULL, /* pSetStretchBltMode */
71 NULL, /* pSetTextAlign */
72 NULL, /* pSetTextCharacterExtra */
73 NULL, /* pSetTextColor */
74 NULL, /* pSetTextJustification */
75 MFDRV_SetViewportExt, /* pSetViewportExt */
76 MFDRV_SetViewportOrg, /* pSetViewportOrg */
77 MFDRV_SetWindowExt, /* pSetWindowExt */
78 MFDRV_SetWindowOrg, /* pSetWindowOrg */
79 MFDRV_StretchBlt, /* pStretchBlt */
80 NULL, /* pStretchDIBits */
81 NULL /* pTextOut */
86 /**********************************************************************
87 * MFDRV_AllocMetaFile
89 static DC *MFDRV_AllocMetaFile(void)
91 DC *dc;
92 METAFILEDRV_PDEVICE *physDev;
94 if (!(dc = DC_AllocDC( &MFDRV_Funcs ))) return NULL;
95 dc->header.wMagic = METAFILE_DC_MAGIC;
97 physDev = (METAFILEDRV_PDEVICE *)HeapAlloc(SystemHeap,0,sizeof(*physDev));
98 if (!physDev)
100 GDI_HEAP_FREE( dc->hSelf );
101 return NULL;
103 dc->physDev = physDev;
105 if (!(physDev->mh = HeapAlloc( SystemHeap, 0, sizeof(*physDev->mh) )))
107 HeapFree( SystemHeap, 0, physDev );
108 GDI_HEAP_FREE( dc->hSelf );
109 return NULL;
112 physDev->nextHandle = 0;
114 physDev->mh->mtHeaderSize = sizeof(METAHEADER) / sizeof(WORD);
115 physDev->mh->mtVersion = 0x0300;
116 physDev->mh->mtSize = physDev->mh->mtHeaderSize;
117 physDev->mh->mtNoObjects = 0;
118 physDev->mh->mtMaxRecord = 0;
119 physDev->mh->mtNoParameters = 0;
121 /* DC_InitDC( dc ); */
122 return dc;
126 /**********************************************************************
127 * MFDRV_DeleteDC
129 static BOOL32 MFDRV_DeleteDC( DC *dc )
131 METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
133 if (physDev->mh) HeapFree( SystemHeap, 0, physDev->mh );
134 HeapFree( SystemHeap, 0, physDev );
135 dc->physDev = NULL;
136 return TRUE;
140 /**********************************************************************
141 * CreateMetafile16 (GDI.125)
143 HDC16 CreateMetaFile16( LPCSTR filename )
145 DC *dc;
146 METAFILEDRV_PDEVICE *physDev;
147 HFILE hFile;
149 dprintf_metafile( stddeb, "CreateMetaFile16: '%s'\n", filename );
151 if (!(dc = MFDRV_AllocMetaFile())) return 0;
152 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
154 if (filename) /* disk based metafile */
156 physDev->mh->mtType = METAFILE_DISK;
157 if ((hFile = _lcreat( filename, 0 )) == HFILE_ERROR)
159 DeleteDC32( dc->hSelf );
160 return 0;
162 if (_lwrite32( hFile, (LPSTR)physDev->mh,
163 sizeof(*physDev->mh)) == HFILE_ERROR)
165 DeleteDC32( dc->hSelf );
166 return 0;
168 physDev->mh->mtNoParameters = hFile; /* store file descriptor here */
169 /* windows probably uses this too*/
171 else /* memory based metafile */
172 physDev->mh->mtType = METAFILE_MEMORY;
174 dprintf_metafile( stddeb, "CreateMetaFile16: returning %04x\n", dc->hSelf);
175 return dc->hSelf;
179 /******************************************************************
180 * CloseMetafile16 (GDI.126)
182 HMETAFILE16 CloseMetaFile16( HDC16 hdc )
184 DC *dc;
185 HMETAFILE16 hmf;
186 HFILE hFile;
187 METAFILEDRV_PDEVICE *physDev;
189 dprintf_metafile( stddeb, "CloseMetaFile(%04x)\n", hdc );
191 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
192 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
194 /* Construct the end of metafile record - this is documented
195 * in SDK Knowledgebase Q99334.
198 if (!MF_MetaParam0(dc, META_EOF))
200 DeleteDC32( hdc );
201 return 0;
204 if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */
206 hFile = physDev->mh->mtNoParameters;
207 physDev->mh->mtNoParameters = 0;
208 if (_llseek(hFile, 0L, 0) == HFILE_ERROR)
210 DeleteDC32( hdc );
211 return 0;
213 if (_lwrite32( hFile, (LPSTR)physDev->mh,
214 sizeof(*physDev->mh)) == HFILE_ERROR)
216 DeleteDC32( hdc );
217 return 0;
219 _lclose(hFile);
222 /* Now allocate a global handle for the metafile */
224 hmf = GLOBAL_CreateBlock( GMEM_MOVEABLE, physDev->mh,
225 physDev->mh->mtSize * sizeof(WORD),
226 GetCurrentPDB(), FALSE, FALSE, FALSE, NULL );
227 physDev->mh = NULL; /* So it won't be deleted */
228 DeleteDC32( hdc );
229 return hmf;
233 /******************************************************************
234 * DeleteMetafile16 (GDI.127)
236 BOOL16 DeleteMetaFile16( HMETAFILE16 hmf )
238 return !GlobalFree16( hmf );