~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/gdi32/metafile16.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Metafile functions
  3  *
  4  * Copyright  David W. Metcalfe, 1994
  5  * Copyright  Niels de Carpentier, 1996
  6  * Copyright  Albrecht Kleine, 1996
  7  * Copyright  Huw Davies, 1996
  8  *
  9  * This library is free software; you can redistribute it and/or
 10  * modify it under the terms of the GNU Lesser General Public
 11  * License as published by the Free Software Foundation; either
 12  * version 2.1 of the License, or (at your option) any later version.
 13  *
 14  * This library is distributed in the hope that it will be useful,
 15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17  * Lesser General Public License for more details.
 18  *
 19  * You should have received a copy of the GNU Lesser General Public
 20  * License along with this library; if not, write to the Free Software
 21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 22  */
 23 
 24 #include "config.h"
 25 
 26 #include <string.h>
 27 #include <fcntl.h>
 28 
 29 #include "wine/winbase16.h"
 30 #include "wine/wingdi16.h"
 31 #include "wownt32.h"
 32 #include "winreg.h"
 33 #include "winternl.h"
 34 #include "gdi_private.h"
 35 #include "wine/debug.h"
 36 
 37 WINE_DEFAULT_DEBUG_CHANNEL(metafile);
 38 
 39 /******************************************************************
 40  *         MF_GetMetaHeader16
 41  *
 42  * Returns ptr to METAHEADER associated with HMETAFILE16
 43  * Should be followed by call to MF_ReleaseMetaHeader16
 44  */
 45 static METAHEADER *MF_GetMetaHeader16( HMETAFILE16 hmf )
 46 {
 47     return GlobalLock16(hmf);
 48 }
 49 
 50 /******************************************************************
 51  *         MF_ReleaseMetaHeader16
 52  *
 53  * Releases METAHEADER associated with HMETAFILE16
 54  */
 55 static BOOL16 MF_ReleaseMetaHeader16( HMETAFILE16 hmf )
 56 {
 57     return GlobalUnlock16( hmf );
 58 }
 59 
 60 /******************************************************************
 61  *         MF_Create_HMETATFILE16
 62  *
 63  * Creates a HMETAFILE16 object from a METAHEADER
 64  *
 65  * HMETAFILE16s are Global memory handles.
 66  */
 67 static HMETAFILE16 MF_Create_HMETAFILE16(METAHEADER *mh)
 68 {
 69     HMETAFILE16 hmf;
 70     DWORD size = mh->mtSize * sizeof(WORD);
 71 
 72     hmf = GlobalAlloc16(GMEM_MOVEABLE, size);
 73     if(hmf)
 74     {
 75         METAHEADER *mh_dest = GlobalLock16(hmf);
 76         memcpy(mh_dest, mh, size);
 77         GlobalUnlock16(hmf);
 78     }
 79     HeapFree(GetProcessHeap(), 0, mh);
 80     return hmf;
 81 }
 82 
 83 /**********************************************************************
 84  *           CreateMetaFile     (GDI.125)
 85  */
 86 HDC16 WINAPI CreateMetaFile16( LPCSTR filename )
 87 {
 88     return HDC_16( CreateMetaFileA( filename ) );
 89 }
 90 
 91 /******************************************************************
 92  *           CloseMetaFile     (GDI.126)
 93  */
 94 HMETAFILE16 WINAPI CloseMetaFile16(HDC16 hdc)
 95 {
 96     HMETAFILE16 hmf16 = 0;
 97     HMETAFILE hmf = CloseMetaFile( HDC_32(hdc) );
 98 
 99     if (hmf)
100     {
101         UINT size = GetMetaFileBitsEx( hmf, 0, NULL );
102 
103         hmf16 = GlobalAlloc16( GMEM_MOVEABLE, size );
104         if (hmf16)
105         {
106             void *buffer = GlobalLock16( hmf16 );
107             GetMetaFileBitsEx( hmf, size, buffer );
108             GlobalUnlock16( hmf16 );
109         }
110         DeleteMetaFile( hmf );
111     }
112     return hmf16;
113 }
114 
115 /******************************************************************
116  *           DeleteMetaFile   (GDI.127)
117  */
118 BOOL16 WINAPI DeleteMetaFile16(  HMETAFILE16 hmf )
119 {
120     return !GlobalFree16( hmf );
121 }
122 
123 /******************************************************************
124  *         GetMetaFile   (GDI.124)
125  */
126 HMETAFILE16 WINAPI GetMetaFile16( LPCSTR lpFilename )
127 {
128     METAHEADER *mh;
129     HANDLE hFile;
130 
131     TRACE("%s\n", lpFilename);
132 
133     if(!lpFilename)
134         return 0;
135 
136     if((hFile = CreateFileA(lpFilename, GENERIC_READ, FILE_SHARE_READ, NULL,
137                             OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
138         return 0;
139 
140     mh = MF_ReadMetaFile(hFile);
141     CloseHandle(hFile);
142     if(!mh) return 0;
143     return MF_Create_HMETAFILE16( mh );
144 }
145 
146 /******************************************************************
147  *         CopyMetaFile   (GDI.151)
148  */
149 HMETAFILE16 WINAPI CopyMetaFile16( HMETAFILE16 hSrcMetaFile, LPCSTR lpFilename)
150 {
151     METAHEADER *mh = MF_GetMetaHeader16( hSrcMetaFile );
152     METAHEADER *mh2 = NULL;
153     HANDLE hFile;
154 
155     TRACE("(%08x,%s)\n", hSrcMetaFile, lpFilename);
156 
157     if(!mh) return 0;
158 
159     if(mh->mtType == METAFILE_DISK)
160         mh2 = MF_LoadDiskBasedMetaFile(mh);
161     else {
162         mh2 = HeapAlloc( GetProcessHeap(), 0, mh->mtSize * 2 );
163         memcpy( mh2, mh, mh->mtSize * 2 );
164     }
165     MF_ReleaseMetaHeader16( hSrcMetaFile );
166 
167     if(lpFilename) {         /* disk based metafile */
168         DWORD w;
169         if((hFile = CreateFileA(lpFilename, GENERIC_WRITE, 0, NULL,
170                                 CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) {
171             HeapFree( GetProcessHeap(), 0, mh2 );
172             return 0;
173         }
174         WriteFile(hFile, mh2, mh2->mtSize * 2, &w, NULL);
175         CloseHandle(hFile);
176         mh2 = MF_CreateMetaHeaderDisk(mh2, lpFilename, FALSE);
177     }
178 
179     return MF_Create_HMETAFILE16( mh2 );
180 }
181 
182 /******************************************************************
183  *         IsValidMetaFile   (GDI.410)
184  *
185  *  Attempts to check if a given metafile is correctly formatted.
186  *  Currently, the only things verified are several properties of the
187  *  header.
188  *
189  * RETURNS
190  *  TRUE if hmf passes some tests for being a valid metafile, FALSE otherwise.
191  *
192  * BUGS
193  *  This is not exactly what windows does, see _Undocumented_Windows_
194  *  for details.
195  */
196 BOOL16 WINAPI IsValidMetaFile16(HMETAFILE16 hmf)
197 {
198     BOOL16 res=FALSE;
199     METAHEADER *mh = MF_GetMetaHeader16(hmf);
200     if (mh) {
201         if (mh->mtType == METAFILE_MEMORY || mh->mtType == METAFILE_DISK)
202             if (mh->mtHeaderSize == MFHEADERSIZE/sizeof(INT16))
203                 if (mh->mtVersion == MFVERSION)
204                     res=TRUE;
205         MF_ReleaseMetaHeader16(hmf);
206     }
207     TRACE("IsValidMetaFile %x => %d\n",hmf,res);
208     return res;
209 }
210 
211 /******************************************************************
212  *         PlayMetaFile   (GDI.123)
213  *
214  */
215 BOOL16 WINAPI PlayMetaFile16( HDC16 hdc, HMETAFILE16 hmf )
216 {
217     BOOL16 ret;
218     METAHEADER *mh = MF_GetMetaHeader16( hmf );
219     ret = MF_PlayMetaFile( HDC_32(hdc), mh );
220     MF_ReleaseMetaHeader16( hmf );
221     return ret;
222 }
223 
224 
225 /******************************************************************
226  *            EnumMetaFile   (GDI.175)
227  *
228  */
229 BOOL16 WINAPI EnumMetaFile16( HDC16 hdc16, HMETAFILE16 hmf,
230                               MFENUMPROC16 lpEnumFunc, LPARAM lpData )
231 {
232     METAHEADER *mh = MF_GetMetaHeader16(hmf);
233     METARECORD *mr;
234     HANDLETABLE16 *ht;
235     HDC hdc = HDC_32(hdc16);
236     HGLOBAL16 hHT;
237     SEGPTR spht;
238     unsigned int offset = 0;
239     WORD i, seg;
240     HPEN hPen;
241     HBRUSH hBrush;
242     HFONT hFont;
243     WORD args[8];
244     BOOL16 result = TRUE, loaded = FALSE;
245 
246     TRACE("(%p, %04x, %p, %08lx)\n", hdc, hmf, lpEnumFunc, lpData);
247 
248     if(!mh) return FALSE;
249     if(mh->mtType == METAFILE_DISK) { /* Create a memory-based copy */
250         mh = MF_LoadDiskBasedMetaFile(mh);
251         if(!mh) return FALSE;
252         loaded = TRUE;
253     }
254 
255     /* save the current pen, brush and font */
256     hPen = GetCurrentObject(hdc, OBJ_PEN);
257     hBrush = GetCurrentObject(hdc, OBJ_BRUSH);
258     hFont = GetCurrentObject(hdc, OBJ_FONT);
259 
260     /* create the handle table */
261 
262     hHT = GlobalAlloc16(GMEM_MOVEABLE | GMEM_ZEROINIT,
263                      sizeof(HANDLETABLE16) * mh->mtNoObjects);
264     spht = WOWGlobalLock16(hHT);
265 
266     seg = hmf | 7;
267     offset = mh->mtHeaderSize * 2;
268 
269     /* loop through metafile records */
270 
271     args[7] = hdc16;
272     args[6] = SELECTOROF(spht);
273     args[5] = OFFSETOF(spht);
274     args[4] = seg + (HIWORD(offset) << __AHSHIFT);
275     args[3] = LOWORD(offset);
276     args[2] = mh->mtNoObjects;
277     args[1] = HIWORD(lpData);
278     args[0] = LOWORD(lpData);
279 
280     while (offset < (mh->mtSize * 2))
281     {
282         DWORD ret;
283 
284         mr = (METARECORD *)((char *)mh + offset);
285 
286         WOWCallback16Ex( (DWORD)lpEnumFunc, WCB16_PASCAL, sizeof(args), args, &ret );
287         if (!LOWORD(ret))
288         {
289             result = FALSE;
290             break;
291         }
292 
293         offset += (mr->rdSize * 2);
294         args[4] = seg + (HIWORD(offset) << __AHSHIFT);
295         args[3] = LOWORD(offset);
296     }
297 
298     SelectObject(hdc, hBrush);
299     SelectObject(hdc, hPen);
300     SelectObject(hdc, hFont);
301 
302     ht = GlobalLock16(hHT);
303 
304     /* free objects in handle table */
305     for(i = 0; i < mh->mtNoObjects; i++)
306       if(*(ht->objectHandle + i) != 0)
307         DeleteObject( (HGDIOBJ)(ULONG_PTR)(*(ht->objectHandle + i) ));
308 
309     /* free handle table */
310     GlobalFree16(hHT);
311     if(loaded)
312         HeapFree( GetProcessHeap(), 0, mh );
313     MF_ReleaseMetaHeader16(hmf);
314     return result;
315 }
316 
317 /******************************************************************
318  *         GetMetaFileBits   (GDI.159)
319  *
320  * Trade in a metafile object handle for a handle to the metafile memory.
321  *
322  * PARAMS
323  *  hmf [I] metafile handle
324  */
325 
326 HGLOBAL16 WINAPI GetMetaFileBits16( HMETAFILE16 hmf )
327 {
328     TRACE("hMem out: %04x\n", hmf);
329     return hmf;
330 }
331 
332 /******************************************************************
333  *         SetMetaFileBits   (GDI.160)
334  *
335  * Trade in a metafile memory handle for a handle to a metafile object.
336  * The memory region should hold a proper metafile, otherwise
337  * problems will occur when it is used. Validity of the memory is not
338  * checked. The function is essentially just the identity function.
339  *
340  * PARAMS
341  *  hMem [I] handle to a memory region holding a metafile
342  *
343  * RETURNS
344  *  Handle to a metafile on success, NULL on failure..
345  */
346 HMETAFILE16 WINAPI SetMetaFileBits16( HGLOBAL16 hMem )
347 {
348     TRACE("hmf out: %04x\n", hMem);
349 
350     return hMem;
351 }
352 
353 /******************************************************************
354  *         SetMetaFileBitsBetter   (GDI.196)
355  *
356  * Trade in a metafile memory handle for a handle to a metafile object,
357  * making a cursory check (using IsValidMetaFile()) that the memory
358  * handle points to a valid metafile.
359  *
360  * RETURNS
361  *  Handle to a metafile on success, NULL on failure..
362  */
363 HMETAFILE16 WINAPI SetMetaFileBitsBetter16( HMETAFILE16 hMeta )
364 {
365     if( IsValidMetaFile16( hMeta ) )
366         return GlobalReAlloc16( hMeta, 0, GMEM_SHARE | GMEM_NODISCARD | GMEM_MODIFY);
367     return 0;
368 }
369 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.