~ [ 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 #include "compobj_private.h"
 36 
 37 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 38 
 39 #define MAX_CLIPFORMAT_NAME   80
 40 
 41 /******************************************************************************
 42  *              OleQueryCreateFromData [OLE32.@]
 43  *
 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(IDataObject *data)
 52 {
 53     IEnumFORMATETC *enum_fmt;
 54     FORMATETC fmt;
 55     BOOL found_static = FALSE;
 56     HRESULT hr;
 57 
 58     hr = IDataObject_EnumFormatEtc(data, DATADIR_GET, &enum_fmt);
 59 
 60     if(FAILED(hr)) return hr;
 61 
 62     do
 63     {
 64         hr = IEnumFORMATETC_Next(enum_fmt, 1, &fmt, NULL);
 65         if(hr == S_OK)
 66         {
 67             if(fmt.cfFormat == embedded_object_clipboard_format ||
 68                fmt.cfFormat == embed_source_clipboard_format ||
 69                fmt.cfFormat == filename_clipboard_format)
 70             {
 71                 IEnumFORMATETC_Release(enum_fmt);
 72                 return S_OK;
 73             }
 74 
 75             if(fmt.cfFormat == CF_METAFILEPICT ||
 76                fmt.cfFormat == CF_BITMAP ||
 77                fmt.cfFormat == CF_DIB)
 78                 found_static = TRUE;
 79         }
 80     } while (hr == S_OK);
 81 
 82     IEnumFORMATETC_Release(enum_fmt);
 83 
 84     return found_static ? OLE_S_STATIC : S_FALSE;
 85 }
 86 
 87 /******************************************************************************
 88  *              OleCreateFromDataEx        [OLE32.@]
 89  *
 90  * Creates an embedded object from data transfer object retrieved from
 91  * the clipboard or OLE drag and drop.
 92  */
 93 HRESULT WINAPI OleCreateFromDataEx(IDataObject *data, REFIID iid, DWORD flags,
 94                                    DWORD renderopt, ULONG num_fmts, DWORD *adv_flags, FORMATETC *fmts,
 95                                    IAdviseSink *sink, DWORD *conns,
 96                                    IOleClientSite *client_site, IStorage *stg, void **obj)
 97 {
 98     FIXME("(%p, %s, %08x, %08x, %d, %p, %p, %p, %p, %p, %p, %p): stub\n",
 99           data, debugstr_guid(iid), flags, renderopt, num_fmts, adv_flags, fmts,
100           sink, conns, client_site, stg, obj);
101 
102     return E_NOTIMPL;
103 }
104 
105 /******************************************************************************
106  *              OleCreateFromData        [OLE32.@]
107  *
108  * Author   : Abey George
109  * Creates an embedded object from data transfer object retrieved from
110  * the clipboard or OLE drag and drop.
111  * Returns  : S_OK - Embedded object was created successfully.
112  *            OLE_E_STATIC - OLE can create only a static object
113  *            DV_E_FORMATETC - No acceptable format is available (only error return code)
114  * TODO : CF_FILENAME, CF_EMBEDEDOBJECT formats. Parameter renderopt is currently ignored.
115  */
116 
117 HRESULT WINAPI OleCreateFromData(LPDATAOBJECT pSrcDataObject, REFIID riid,
118                 DWORD renderopt, LPFORMATETC pFormatEtc,
119                 LPOLECLIENTSITE pClientSite, LPSTORAGE pStg,
120                 LPVOID* ppvObj)
121 {
122   IEnumFORMATETC *pfmt;
123   FORMATETC fmt;
124   CHAR szFmtName[MAX_CLIPFORMAT_NAME];
125   STGMEDIUM std;
126   HRESULT hr;
127   HRESULT hr1;
128 
129   hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
130 
131   if (hr == S_OK)
132   {
133     memset(&std, 0, sizeof(STGMEDIUM));
134 
135     hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
136     while (hr == S_OK)
137     {
138       GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
139 
140       /* first, Check for Embedded Object, Embed Source or Filename */
141       /* TODO: Currently checks only for Embed Source. */
142 
143       if (!strcmp(szFmtName, CF_EMBEDSOURCE))
144       {
145         std.tymed = TYMED_HGLOBAL;
146 
147         if ((hr1 = IDataObject_GetData(pSrcDataObject, &fmt, &std)) == S_OK)
148         {
149           ILockBytes *ptrILockBytes = 0;
150           IStorage *pStorage = 0;
151           IOleObject *pOleObject = 0;
152           IPersistStorage *pPersistStorage = 0;
153           CLSID clsID;
154 
155           /* Create ILock bytes */
156 
157           hr1 = CreateILockBytesOnHGlobal(std.u.hGlobal, FALSE, &ptrILockBytes);
158 
159           /* Open storage on the ILock bytes */
160 
161           if (hr1 == S_OK)
162             hr1 = StgOpenStorageOnILockBytes(ptrILockBytes, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
163 
164           /* Get Class ID from the opened storage */
165 
166           if (hr1 == S_OK)
167             hr1 = ReadClassStg(pStorage, &clsID);
168 
169           /* Create default handler for Persist storage */
170 
171           if (hr1 == S_OK)
172             hr1 = OleCreateDefaultHandler(&clsID, NULL, &IID_IPersistStorage, (LPVOID*)&pPersistStorage);
173 
174           /* Load the storage to Persist storage */
175 
176           if (hr1 == S_OK)
177             hr1 = IPersistStorage_Load(pPersistStorage, pStorage);
178 
179           /* Query for IOleObject */
180 
181           if (hr1 == S_OK)
182             hr1 = IPersistStorage_QueryInterface(pPersistStorage, &IID_IOleObject, (LPVOID*)&pOleObject);
183 
184           /* Set client site with the IOleObject */
185 
186           if (hr1 == S_OK)
187             hr1 = IOleObject_SetClientSite(pOleObject, pClientSite);
188 
189           IPersistStorage_Release(pPersistStorage);
190           /* Query for the requested interface */
191 
192           if (hr1 == S_OK)
193             hr1 = IPersistStorage_QueryInterface(pPersistStorage, riid, ppvObj);
194 
195           IPersistStorage_Release(pPersistStorage);
196 
197           IStorage_Release(pStorage);
198 
199           if (hr1 == S_OK)
200             return S_OK;
201         }
202 
203         /* Return error */
204 
205         return DV_E_FORMATETC;
206       }
207 
208       hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
209     }
210   }
211 
212   return DV_E_FORMATETC;
213 }
214 
215 
216 /******************************************************************************
217  *              OleDuplicateData        [OLE32.@]
218  *
219  * Duplicates clipboard data.
220  *
221  * PARAMS
222  *  hSrc     [I] Handle of the source clipboard data.
223  *  cfFormat [I] The clipboard format of hSrc.
224  *  uiFlags  [I] Flags to pass to GlobalAlloc.
225  *
226  * RETURNS
227  *  Success: handle to the duplicated data.
228  *  Failure: NULL.
229  */
230 HANDLE WINAPI OleDuplicateData(HANDLE hSrc, CLIPFORMAT cfFormat,
231                                   UINT uiFlags)
232 {
233     HANDLE hDst = NULL;
234 
235     TRACE("(%p,%x,%x)\n", hSrc, cfFormat, uiFlags);
236 
237     if (!uiFlags) uiFlags = GMEM_MOVEABLE;
238 
239     switch (cfFormat)
240     {
241     case CF_ENHMETAFILE:
242         hDst = CopyEnhMetaFileW(hSrc, NULL);
243         break;
244     case CF_METAFILEPICT:
245         hDst = CopyMetaFileW(hSrc, NULL);
246         break;
247     case CF_PALETTE:
248         {
249             LOGPALETTE * logpalette;
250             UINT nEntries = GetPaletteEntries(hSrc, 0, 0, NULL);
251             if (!nEntries) return NULL;
252             logpalette = HeapAlloc(GetProcessHeap(), 0,
253                 FIELD_OFFSET(LOGPALETTE, palPalEntry[nEntries]));
254             if (!logpalette) return NULL;
255             if (!GetPaletteEntries(hSrc, 0, nEntries, logpalette->palPalEntry))
256             {
257                 HeapFree(GetProcessHeap(), 0, logpalette);
258                 return NULL;
259             }
260             logpalette->palVersion = 0x300;
261             logpalette->palNumEntries = (WORD)nEntries;
262 
263             hDst = CreatePalette(logpalette);
264 
265             HeapFree(GetProcessHeap(), 0, logpalette);
266             break;
267         }
268     case CF_BITMAP:
269         {
270             LONG size;
271             BITMAP bm;
272             if (!GetObjectW(hSrc, sizeof(bm), &bm))
273                 return NULL;
274             size = GetBitmapBits(hSrc, 0, NULL);
275             if (!size) return NULL;
276             bm.bmBits = HeapAlloc(GetProcessHeap(), 0, size);
277             if (!bm.bmBits) return NULL;
278             if (GetBitmapBits(hSrc, size, bm.bmBits))
279                 hDst = CreateBitmapIndirect(&bm);
280             HeapFree(GetProcessHeap(), 0, bm.bmBits);
281             break;
282         }
283     default:
284         {
285             SIZE_T size = GlobalSize(hSrc);
286             LPVOID pvSrc = NULL;
287             LPVOID pvDst = NULL;
288 
289             /* allocate space for object */
290             if (!size) return NULL;
291             hDst = GlobalAlloc(uiFlags, size);
292             if (!hDst) return NULL;
293 
294             /* lock pointers */
295             pvSrc = GlobalLock(hSrc);
296             if (!pvSrc)
297             {
298                 GlobalFree(hDst);
299                 return NULL;
300             }
301             pvDst = GlobalLock(hDst);
302             if (!pvDst)
303             {
304                 GlobalUnlock(hSrc);
305                 GlobalFree(hDst);
306                 return NULL;
307             }
308             /* copy data */
309             memcpy(pvDst, pvSrc, size);
310 
311             /* cleanup */
312             GlobalUnlock(hDst);
313             GlobalUnlock(hSrc);
314         }
315     }
316 
317     TRACE("returning %p\n", hDst);
318     return hDst;
319 }
320 

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