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

Wine Cross Reference
wine/dlls/ole32/ole2impl.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  * Ole 2 Create functions implementation
  3  *
  4  * Copyright (C) 1999-2000 Abey George
  5  *
  6  * This library is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU Lesser General Public
  8  * License as published by the Free Software Foundation; either
  9  * version 2.1 of the License, or (at your option) any later version.
 10  *
 11  * This library is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  * Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public
 17  * License along with this library; if not, write to the Free Software
 18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include <stdarg.h>
 22 #include <string.h>
 23 
 24 #define COBJMACROS
 25 #define NONAMELESSUNION
 26 #define NONAMELESSSTRUCT
 27 
 28 #include "windef.h"
 29 #include "winbase.h"
 30 #include "wingdi.h"
 31 #include "winuser.h"
 32 #include "wine/debug.h"
 33 #include "ole2.h"
 34 #include "olestd.h"
 35 
 36 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 37 
 38 #define MAX_CLIPFORMAT_NAME   80
 39 
 40 /******************************************************************************
 41  *              OleQueryCreateFromData [OLE32.@]
 42  *
 43  * Author   : Abey George
 44  * Checks whether an object can become an embedded object.
 45  * the clipboard or OLE drag and drop.
 46  * Returns  : S_OK - Format that supports Embedded object creation are present.
 47  *            OLE_E_STATIC - Format that supports static object creation are present.
 48  *            S_FALSE - No acceptable format is available.
 49  */
 50 
 51 HRESULT WINAPI OleQueryCreateFromData(LPDATAOBJECT pSrcDataObject)
 52 {
 53   IEnumFORMATETC *pfmt;
 54   FORMATETC fmt;
 55   CHAR szFmtName[MAX_CLIPFORMAT_NAME];
 56   BOOL bFoundStatic = FALSE;
 57 
 58   HRESULT hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
 59 
 60   if (hr == S_OK)
 61     hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
 62 
 63   while (hr == S_OK)
 64   {
 65     GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
 66 
 67     /* first, Check for Embedded Object, Embed Source or Filename */
 68 
 69     if (!strcmp(szFmtName, CF_EMBEDDEDOBJECT) || !strcmp(szFmtName, CF_EMBEDSOURCE) || !strcmp(szFmtName, CF_FILENAME))
 70       return S_OK;
 71 
 72     /* Check for Metafile, Bitmap or DIB */
 73 
 74     if (fmt.cfFormat == CF_METAFILEPICT || fmt.cfFormat == CF_BITMAP || fmt.cfFormat == CF_DIB)
 75       bFoundStatic = TRUE;
 76 
 77     hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
 78   }
 79 
 80   /* Found a static format, but no embed format */
 81 
 82   if (bFoundStatic)
 83     return OLE_S_STATIC;
 84 
 85   return S_FALSE;
 86 }
 87 
 88 /******************************************************************************
 89  *              OleCreateFromData        [OLE32.@]
 90  *
 91  * Author   : Abey George
 92  * Creates an embedded object from data transfer object retrieved from
 93  * the clipboard or OLE drag and drop.
 94  * Returns  : S_OK - Embedded object was created successfully.
 95  *            OLE_E_STATIC - OLE can create only a static object
 96  *            DV_E_FORMATETC - No acceptable format is available (only error return code)
 97  * TODO : CF_FILENAME, CF_EMBEDEDOBJECT formats. Parameter renderopt is currently ignored.
 98  */
 99 
100 HRESULT WINAPI OleCreateFromData(LPDATAOBJECT pSrcDataObject, REFIID riid,
101                 DWORD renderopt, LPFORMATETC pFormatEtc,
102                 LPOLECLIENTSITE pClientSite, LPSTORAGE pStg,
103                 LPVOID* ppvObj)
104 {
105   IEnumFORMATETC *pfmt;
106   FORMATETC fmt;
107   CHAR szFmtName[MAX_CLIPFORMAT_NAME];
108   STGMEDIUM std;
109   HRESULT hr;
110   HRESULT hr1;
111 
112   hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
113 
114   if (hr == S_OK)
115   {
116     memset(&std, 0, sizeof(STGMEDIUM));
117 
118     hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
119     while (hr == S_OK)
120     {
121       GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
122 
123       /* first, Check for Embedded Object, Embed Source or Filename */
124       /* TODO: Currently checks only for Embed Source. */
125 
126       if (!strcmp(szFmtName, CF_EMBEDSOURCE))
127       {
128         std.tymed = TYMED_HGLOBAL;
129 
130         if ((hr1 = IDataObject_GetData(pSrcDataObject, &fmt, &std)) == S_OK)
131         {
132           ILockBytes *ptrILockBytes = 0;
133           IStorage *pStorage = 0;
134           IOleObject *pOleObject = 0;
135           IPersistStorage *pPersistStorage = 0;
136           CLSID clsID;
137 
138           /* Create ILock bytes */
139 
140           hr1 = CreateILockBytesOnHGlobal(std.u.hGlobal, FALSE, &ptrILockBytes);
141 
142           /* Open storage on the ILock bytes */
143 
144           if (hr1 == S_OK)
145             hr1 = StgOpenStorageOnILockBytes(ptrILockBytes, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
146 
147           /* Get Class ID from the opened storage */
148 
149           if (hr1 == S_OK)
150             hr1 = ReadClassStg(pStorage, &clsID);
151 
152           /* Create default handler for Persist storage */
153 
154           if (hr1 == S_OK)
155             hr1 = OleCreateDefaultHandler(&clsID, NULL, &IID_IPersistStorage, (LPVOID*)&pPersistStorage);
156 
157           /* Load the storage to Persist storage */
158 
159           if (hr1 == S_OK)
160             hr1 = IPersistStorage_Load(pPersistStorage, pStorage);
161 
162           /* Query for IOleObject */
163 
164           if (hr1 == S_OK)
165             hr1 = IPersistStorage_QueryInterface(pPersistStorage, &IID_IOleObject, (LPVOID*)&pOleObject);
166 
167           /* Set client site with the IOleObject */
168 
169           if (hr1 == S_OK)
170             hr1 = IOleObject_SetClientSite(pOleObject, pClientSite);
171 
172           IPersistStorage_Release(pPersistStorage);
173           /* Query for the requested interface */
174 
175           if (hr1 == S_OK)
176             hr1 = IPersistStorage_QueryInterface(pPersistStorage, riid, ppvObj);
177 
178           IPersistStorage_Release(pPersistStorage);
179 
180           IStorage_Release(pStorage);
181 
182           if (hr1 == S_OK)
183             return S_OK;
184         }
185 
186         /* Return error */
187 
188         return DV_E_FORMATETC;
189       }
190 
191       hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
192     }
193   }
194 
195   return DV_E_FORMATETC;
196 }
197 
198 
199 /******************************************************************************
200  *              OleDuplicateData        [OLE32.@]
201  *
202  * Duplicates clipboard data.
203  *
204  * PARAMS
205  *  hSrc     [I] Handle of the source clipboard data.
206  *  cfFormat [I] The clipboard format of hSrc.
207  *  uiFlags  [I] Flags to pass to GlobalAlloc.
208  *
209  * RETURNS
210  *  Success: handle to the duplicated data.
211  *  Failure: NULL.
212  */
213 HANDLE WINAPI OleDuplicateData(HANDLE hSrc, CLIPFORMAT cfFormat,
214                                   UINT uiFlags)
215 {
216     HANDLE hDst = NULL;
217 
218     TRACE("(%p,%x,%x)\n", hSrc, cfFormat, uiFlags);
219 
220     if (!uiFlags) uiFlags = GMEM_MOVEABLE;
221 
222     switch (cfFormat)
223     {
224     case CF_ENHMETAFILE:
225         hDst = CopyEnhMetaFileW(hSrc, NULL);
226         break;
227     case CF_METAFILEPICT:
228         hDst = CopyMetaFileW(hSrc, NULL);
229         break;
230     case CF_PALETTE:
231         {
232             LOGPALETTE * logpalette;
233             UINT nEntries = GetPaletteEntries(hSrc, 0, 0, NULL);
234             if (!nEntries) return NULL;
235             logpalette = HeapAlloc(GetProcessHeap(), 0,
236                 FIELD_OFFSET(LOGPALETTE, palPalEntry[nEntries]));
237             if (!logpalette) return NULL;
238             if (!GetPaletteEntries(hSrc, 0, nEntries, logpalette->palPalEntry))
239             {
240                 HeapFree(GetProcessHeap(), 0, logpalette);
241                 return NULL;
242             }
243             logpalette->palVersion = 0x300;
244             logpalette->palNumEntries = (WORD)nEntries;
245 
246             hDst = CreatePalette(logpalette);
247 
248             HeapFree(GetProcessHeap(), 0, logpalette);
249             break;
250         }
251     case CF_BITMAP:
252         {
253             LONG size;
254             BITMAP bm;
255             if (!GetObjectW(hSrc, sizeof(bm), &bm))
256                 return NULL;
257             size = GetBitmapBits(hSrc, 0, NULL);
258             if (!size) return NULL;
259             bm.bmBits = HeapAlloc(GetProcessHeap(), 0, size);
260             if (!bm.bmBits) return NULL;
261             if (GetBitmapBits(hSrc, size, bm.bmBits))
262                 hDst = CreateBitmapIndirect(&bm);
263             HeapFree(GetProcessHeap(), 0, bm.bmBits);
264             break;
265         }
266     default:
267         {
268             SIZE_T size = GlobalSize(hSrc);
269             LPVOID pvSrc = NULL;
270             LPVOID pvDst = NULL;
271 
272             /* allocate space for object */
273             if (!size) return NULL;
274             hDst = GlobalAlloc(uiFlags, size);
275             if (!hDst) return NULL;
276 
277             /* lock pointers */
278             pvSrc = GlobalLock(hSrc);
279             if (!pvSrc)
280             {
281                 GlobalFree(hDst);
282                 return NULL;
283             }
284             pvDst = GlobalLock(hDst);
285             if (!pvDst)
286             {
287                 GlobalUnlock(hSrc);
288                 GlobalFree(hDst);
289                 return NULL;
290             }
291             /* copy data */
292             memcpy(pvDst, pvSrc, size);
293 
294             /* cleanup */
295             GlobalUnlock(hDst);
296             GlobalUnlock(hSrc);
297         }
298     }
299 
300     TRACE("returning %p\n", hDst);
301     return hDst;
302 }
303 

~ [ 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.