2 * Ole 2 Create functions implementation
4 * Copyright (C) 1999-2000 Abey George
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.
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.
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
25 #define NONAMELESSUNION
31 #include "wine/debug.h"
34 #include "compobj_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
38 /******************************************************************************
39 * OleQueryCreateFromData [OLE32.@]
41 * Checks whether an object can become an embedded object.
42 * the clipboard or OLE drag and drop.
43 * Returns : S_OK - Format that supports Embedded object creation are present.
44 * OLE_E_STATIC - Format that supports static object creation are present.
45 * S_FALSE - No acceptable format is available.
48 HRESULT WINAPI
OleQueryCreateFromData(IDataObject
*data
)
50 IEnumFORMATETC
*enum_fmt
;
52 BOOL found_static
= FALSE
;
55 hr
= IDataObject_EnumFormatEtc(data
, DATADIR_GET
, &enum_fmt
);
57 if(FAILED(hr
)) return hr
;
61 hr
= IEnumFORMATETC_Next(enum_fmt
, 1, &fmt
, NULL
);
64 if(fmt
.cfFormat
== embedded_object_clipboard_format
||
65 fmt
.cfFormat
== embed_source_clipboard_format
||
66 fmt
.cfFormat
== filename_clipboard_format
)
68 IEnumFORMATETC_Release(enum_fmt
);
72 if(fmt
.cfFormat
== CF_METAFILEPICT
||
73 fmt
.cfFormat
== CF_BITMAP
||
74 fmt
.cfFormat
== CF_DIB
)
79 IEnumFORMATETC_Release(enum_fmt
);
81 return found_static
? OLE_S_STATIC
: S_FALSE
;
84 static inline void init_fmtetc(FORMATETC
*fmt
, CLIPFORMAT cf
, TYMED tymed
)
88 fmt
->dwAspect
= DVASPECT_CONTENT
;
93 /***************************************************************************
96 * Retrieve an object's storage from a variety of sources.
100 static HRESULT
get_storage(IDataObject
*data
, IStorage
*stg
, UINT
*src_cf
)
102 static const UINT fmt_id
[] = { CF_METAFILEPICT
, CF_BITMAP
, CF_DIB
};
107 IPersistStorage
*persist
;
112 /* CF_EMBEDEDOBJECT */
113 init_fmtetc(&fmt
, embedded_object_clipboard_format
, TYMED_ISTORAGE
);
114 med
.tymed
= TYMED_ISTORAGE
;
116 hr
= IDataObject_GetDataHere(data
, &fmt
, &med
);
119 *src_cf
= embedded_object_clipboard_format
;
124 init_fmtetc(&fmt
, embed_source_clipboard_format
, TYMED_ISTORAGE
);
125 med
.tymed
= TYMED_ISTORAGE
;
127 hr
= IDataObject_GetDataHere(data
, &fmt
, &med
);
130 *src_cf
= embed_source_clipboard_format
;
134 for (i
= 0; i
< sizeof(fmt_id
)/sizeof(fmt_id
[0]); i
++)
136 init_fmtetc(&fmt
, fmt_id
[i
], TYMED_ISTORAGE
);
137 hr
= IDataObject_QueryGetData(data
, &fmt
);
145 /* IPersistStorage */
146 hr
= IDataObject_QueryInterface(data
, &IID_IPersistStorage
, (void**)&persist
);
147 if(FAILED(hr
)) return hr
;
149 hr
= IPersistStorage_GetClassID(persist
, &clsid
);
150 if(FAILED(hr
)) goto end
;
152 hr
= IStorage_SetClass(stg
, &clsid
);
153 if(FAILED(hr
)) goto end
;
155 hr
= IPersistStorage_Save(persist
, stg
, FALSE
);
156 if(FAILED(hr
)) goto end
;
158 hr
= IPersistStorage_SaveCompleted(persist
, NULL
);
161 IPersistStorage_Release(persist
);
166 /******************************************************************************
167 * OleCreateFromDataEx [OLE32.@]
169 * Creates an embedded object from data transfer object retrieved from
170 * the clipboard or OLE drag and drop.
172 HRESULT WINAPI
OleCreateFromDataEx(IDataObject
*data
, REFIID iid
, DWORD flags
,
173 DWORD renderopt
, ULONG num_cache_fmts
, DWORD
*adv_flags
, FORMATETC
*cache_fmts
,
174 IAdviseSink
*sink
, DWORD
*conns
,
175 IOleClientSite
*client_site
, IStorage
*stg
, void **obj
)
180 FIXME("(%p, %s, %08x, %08x, %d, %p, %p, %p, %p, %p, %p, %p): stub\n",
181 data
, debugstr_guid(iid
), flags
, renderopt
, num_cache_fmts
, adv_flags
, cache_fmts
,
182 sink
, conns
, client_site
, stg
, obj
);
184 hr
= get_storage(data
, stg
, &src_cf
);
185 if(FAILED(hr
)) return hr
;
187 hr
= OleLoad(stg
, iid
, client_site
, obj
);
188 if(FAILED(hr
)) return hr
;
190 /* FIXME: Init cache */
195 /******************************************************************************
196 * OleCreateFromData [OLE32.@]
198 HRESULT WINAPI
OleCreateFromData(LPDATAOBJECT data
, REFIID iid
,
199 DWORD renderopt
, LPFORMATETC fmt
,
200 LPOLECLIENTSITE client_site
, LPSTORAGE stg
,
203 DWORD advf
= ADVF_PRIMEFIRST
;
205 return OleCreateFromDataEx(data
, iid
, 0, renderopt
, fmt
? 1 : 0, fmt
? &advf
: NULL
,
206 fmt
, NULL
, NULL
, client_site
, stg
, obj
);
209 /******************************************************************************
210 * OleCreateLinkFromData [OLE32.@]
212 HRESULT WINAPI
OleCreateLinkFromData(IDataObject
*data
, REFIID iid
,
213 DWORD renderopt
, FORMATETC
*fmt
,
214 IOleClientSite
*client_site
, IStorage
*stg
,
217 FIXME("%p,%s,%08x,%p,%p,%p,%p: semi-stub\n",
218 data
, debugstr_guid(iid
), renderopt
, fmt
, client_site
, stg
, obj
);
219 return OleCreateFromData(data
, iid
, renderopt
, fmt
, client_site
, stg
, obj
);
222 /******************************************************************************
223 * OleCreateStaticFromData [OLE32.@]
225 HRESULT WINAPI
OleCreateStaticFromData(IDataObject
*data
, REFIID iid
,
226 DWORD renderopt
, FORMATETC
*fmt
,
227 IOleClientSite
*client_site
, IStorage
*stg
,
230 FIXME("%p,%s,%08x,%p,%p,%p,%p: semi-stub\n",
231 data
, debugstr_guid(iid
), renderopt
, fmt
, client_site
, stg
, obj
);
232 return OleCreateFromData(data
, iid
, renderopt
, fmt
, client_site
, stg
, obj
);
235 /******************************************************************************
236 * OleDuplicateData [OLE32.@]
238 * Duplicates clipboard data.
241 * hSrc [I] Handle of the source clipboard data.
242 * cfFormat [I] The clipboard format of hSrc.
243 * uiFlags [I] Flags to pass to GlobalAlloc.
246 * Success: handle to the duplicated data.
249 HANDLE WINAPI
OleDuplicateData(HANDLE hSrc
, CLIPFORMAT cfFormat
,
254 TRACE("(%p,%x,%x)\n", hSrc
, cfFormat
, uiFlags
);
256 if (!uiFlags
) uiFlags
= GMEM_MOVEABLE
;
261 hDst
= CopyEnhMetaFileW(hSrc
, NULL
);
263 case CF_METAFILEPICT
:
264 hDst
= CopyMetaFileW(hSrc
, NULL
);
268 LOGPALETTE
* logpalette
;
269 UINT nEntries
= GetPaletteEntries(hSrc
, 0, 0, NULL
);
270 if (!nEntries
) return NULL
;
271 logpalette
= HeapAlloc(GetProcessHeap(), 0,
272 FIELD_OFFSET(LOGPALETTE
, palPalEntry
[nEntries
]));
273 if (!logpalette
) return NULL
;
274 if (!GetPaletteEntries(hSrc
, 0, nEntries
, logpalette
->palPalEntry
))
276 HeapFree(GetProcessHeap(), 0, logpalette
);
279 logpalette
->palVersion
= 0x300;
280 logpalette
->palNumEntries
= (WORD
)nEntries
;
282 hDst
= CreatePalette(logpalette
);
284 HeapFree(GetProcessHeap(), 0, logpalette
);
291 if (!GetObjectW(hSrc
, sizeof(bm
), &bm
))
293 size
= GetBitmapBits(hSrc
, 0, NULL
);
294 if (!size
) return NULL
;
295 bm
.bmBits
= HeapAlloc(GetProcessHeap(), 0, size
);
296 if (!bm
.bmBits
) return NULL
;
297 if (GetBitmapBits(hSrc
, size
, bm
.bmBits
))
298 hDst
= CreateBitmapIndirect(&bm
);
299 HeapFree(GetProcessHeap(), 0, bm
.bmBits
);
304 SIZE_T size
= GlobalSize(hSrc
);
308 /* allocate space for object */
309 if (!size
) return NULL
;
310 hDst
= GlobalAlloc(uiFlags
, size
);
311 if (!hDst
) return NULL
;
314 pvSrc
= GlobalLock(hSrc
);
320 pvDst
= GlobalLock(hDst
);
328 memcpy(pvDst
, pvSrc
, size
);
336 TRACE("returning %p\n", hDst
);