2 * IEnumFORMATETC, IDataObject
4 * selecting and droping objects within the shell and/or common dialogs
6 * Copyright 1998, 1999 <juergen.schmied@metronet.de>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
30 #include "shell32_main.h"
31 #include "wine/debug.h"
32 #include "undocshell.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(shell);
36 /***********************************************************************
37 * IEnumFORMATETC implementation
43 ICOM_VFIELD(IEnumFORMATETC);
45 /* IEnumFORMATETC fields */
51 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj);
52 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface);
53 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface);
54 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC* rgelt, ULONG* pceltFethed);
55 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt);
56 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface);
57 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum);
59 static struct ICOM_VTABLE(IEnumFORMATETC) efvt =
61 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
62 IEnumFORMATETC_fnQueryInterface,
63 IEnumFORMATETC_fnAddRef,
64 IEnumFORMATETC_fnRelease,
65 IEnumFORMATETC_fnNext,
66 IEnumFORMATETC_fnSkip,
67 IEnumFORMATETC_fnReset,
68 IEnumFORMATETC_fnClone
71 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
73 IEnumFORMATETCImpl* ef;
74 DWORD size=cfmt * sizeof(FORMATETC);
76 ef=(IEnumFORMATETCImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
84 ef->pFmt = SHAlloc (size);
88 memcpy(ef->pFmt, afmt, size);
92 TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
93 return (LPENUMFORMATETC)ef;
96 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
98 ICOM_THIS(IEnumFORMATETCImpl,iface);
99 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
103 if(IsEqualIID(riid, &IID_IUnknown))
107 else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
109 *ppvObj = (IEnumFORMATETC*)This;
114 IUnknown_AddRef((IUnknown*)(*ppvObj));
115 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
118 TRACE("-- Interface: E_NOINTERFACE\n");
119 return E_NOINTERFACE;
123 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
125 ICOM_THIS(IEnumFORMATETCImpl,iface);
126 TRACE("(%p)->(count=%lu)\n",This, This->ref);
127 return ++(This->ref);
130 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
132 ICOM_THIS(IEnumFORMATETCImpl,iface);
133 TRACE("(%p)->()\n",This);
137 TRACE(" destroying IEnumFORMATETC(%p)\n",This);
142 HeapFree(GetProcessHeap(),0,This);
148 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
150 ICOM_THIS(IEnumFORMATETCImpl,iface);
153 TRACE("(%p)->(%lu,%p)\n", This, celt, rgelt);
155 if(!This->pFmt)return S_FALSE;
156 if(!rgelt) return E_INVALIDARG;
157 if (pceltFethed) *pceltFethed = 0;
159 for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
161 *rgelt++ = This->pFmt[This->posFmt++];
164 if (pceltFethed) *pceltFethed = i;
166 return ((i == celt) ? S_OK : S_FALSE);
169 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
171 ICOM_THIS(IEnumFORMATETCImpl,iface);
172 TRACE("(%p)->(num=%lu)\n", This, celt);
174 if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
175 This->posFmt += celt;
179 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
181 ICOM_THIS(IEnumFORMATETCImpl,iface);
182 TRACE("(%p)->()\n", This);
188 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
190 ICOM_THIS(IEnumFORMATETCImpl,iface);
191 TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
193 if (!ppenum) return E_INVALIDARG;
194 *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
196 IEnumFORMATETC_fnSkip(*ppenum, This->posFmt);
201 /***********************************************************************
202 * IDataObject implementation
205 /* number of supported formats */
206 #define MAX_FORMATS 4
210 /* IUnknown fields */
211 ICOM_VFIELD(IDataObject);
214 /* IDataObject fields */
216 LPITEMIDLIST * apidl;
219 FORMATETC pFormatEtc[MAX_FORMATS];
226 static struct ICOM_VTABLE(IDataObject) dtovt;
228 /**************************************************************************
229 * IDataObject_Constructor
231 LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner, LPCITEMIDLIST pMyPidl, LPCITEMIDLIST * apidl, UINT cidl)
233 IDataObjectImpl* dto;
235 dto = (IDataObjectImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDataObjectImpl));
240 dto->lpVtbl = &dtovt;
241 dto->pidl = ILClone(pMyPidl);
242 dto->apidl = _ILCopyaPidl(apidl, cidl);
245 dto->cfShellIDList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
246 dto->cfFileNameA = RegisterClipboardFormatA(CFSTR_FILENAMEA);
247 dto->cfFileNameW = RegisterClipboardFormatA(CFSTR_FILENAMEW);
248 InitFormatEtc(dto->pFormatEtc[0], dto->cfShellIDList, TYMED_HGLOBAL);
249 InitFormatEtc(dto->pFormatEtc[1], CF_HDROP, TYMED_HGLOBAL);
250 InitFormatEtc(dto->pFormatEtc[2], dto->cfFileNameA, TYMED_HGLOBAL);
251 InitFormatEtc(dto->pFormatEtc[3], dto->cfFileNameW, TYMED_HGLOBAL);
254 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto, apidl, cidl);
255 return (LPDATAOBJECT)dto;
258 /***************************************************************************
259 * IDataObject_QueryInterface
261 static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID * ppvObj)
263 ICOM_THIS(IDataObjectImpl,iface);
264 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
268 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
272 else if(IsEqualIID(riid, &IID_IDataObject)) /*IDataObject*/
274 *ppvObj = (IDataObject*)This;
279 IUnknown_AddRef((IUnknown*)*ppvObj);
280 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
283 TRACE("-- Interface: E_NOINTERFACE\n");
284 return E_NOINTERFACE;
287 /**************************************************************************
290 static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface)
292 ICOM_THIS(IDataObjectImpl,iface);
293 TRACE("(%p)->(count=%lu)\n",This, This->ref);
294 return ++(This->ref);
297 /**************************************************************************
298 * IDataObject_Release
300 static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface)
302 ICOM_THIS(IDataObjectImpl,iface);
303 TRACE("(%p)->()\n",This);
307 TRACE(" destroying IDataObject(%p)\n",This);
308 _ILFreeaPidl(This->apidl, This->cidl);
310 HeapFree(GetProcessHeap(),0,This);
316 /**************************************************************************
317 * IDataObject_fnGetData
319 static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
321 ICOM_THIS(IDataObjectImpl,iface);
326 GetClipboardFormatNameA (pformatetcIn->cfFormat, szTemp, 256);
327 TRACE("(%p)->(%p %p format=%s)\n", This, pformatetcIn, pmedium, szTemp);
329 if (pformatetcIn->cfFormat == This->cfShellIDList)
331 if (This->cidl < 1) return(E_UNEXPECTED);
332 pmedium->u.hGlobal = RenderSHELLIDLIST(This->pidl, This->apidl, This->cidl);
334 else if (pformatetcIn->cfFormat == CF_HDROP)
336 if (This->cidl < 1) return(E_UNEXPECTED);
337 pmedium->u.hGlobal = RenderHDROP(This->pidl, This->apidl, This->cidl);
339 else if (pformatetcIn->cfFormat == This->cfFileNameA)
341 if (This->cidl < 1) return(E_UNEXPECTED);
342 pmedium->u.hGlobal = RenderFILENAMEA(This->pidl, This->apidl, This->cidl);
344 else if (pformatetcIn->cfFormat == This->cfFileNameW)
346 if (This->cidl < 1) return(E_UNEXPECTED);
347 pmedium->u.hGlobal = RenderFILENAMEW(This->pidl, This->apidl, This->cidl);
351 FIXME("-- expected clipformat not implemented\n");
352 return (E_INVALIDARG);
354 if (pmedium->u.hGlobal)
356 pmedium->tymed = TYMED_HGLOBAL;
357 pmedium->pUnkForRelease = NULL;
360 return E_OUTOFMEMORY;
363 static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
365 ICOM_THIS(IDataObjectImpl,iface);
366 FIXME("(%p)->()\n", This);
370 static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc)
372 ICOM_THIS(IDataObjectImpl,iface);
375 TRACE("(%p)->(fmt=0x%08x tym=0x%08lx)\n", This, pformatetc->cfFormat, pformatetc->tymed);
377 if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
378 return DV_E_DVASPECT;
380 /* check our formats table what we have */
381 for (i=0; i<MAX_FORMATS; i++)
383 if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
384 && (This->pFormatEtc[i].tymed == pformatetc->tymed))
393 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
395 ICOM_THIS(IDataObjectImpl,iface);
396 FIXME("(%p)->()\n", This);
400 static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
402 ICOM_THIS(IDataObjectImpl,iface);
403 FIXME("(%p)->()\n", This);
407 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
409 ICOM_THIS(IDataObjectImpl,iface);
411 TRACE("(%p)->()\n", This);
412 *ppenumFormatEtc=NULL;
415 if (DATADIR_GET == dwDirection)
417 *ppenumFormatEtc = IEnumFORMATETC_Constructor(MAX_FORMATS, This->pFormatEtc);
418 return (*ppenumFormatEtc) ? S_OK : E_FAIL;
424 static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
426 ICOM_THIS(IDataObjectImpl,iface);
427 FIXME("(%p)->()\n", This);
430 static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection)
432 ICOM_THIS(IDataObjectImpl,iface);
433 FIXME("(%p)->()\n", This);
436 static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise)
438 ICOM_THIS(IDataObjectImpl,iface);
439 FIXME("(%p)->()\n", This);
443 static struct ICOM_VTABLE(IDataObject) dtovt =
445 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
446 IDataObject_fnQueryInterface,
447 IDataObject_fnAddRef,
448 IDataObject_fnRelease,
449 IDataObject_fnGetData,
450 IDataObject_fnGetDataHere,
451 IDataObject_fnQueryGetData,
452 IDataObject_fnGetCanonicalFormatEtc,
453 IDataObject_fnSetData,
454 IDataObject_fnEnumFormatEtc,
455 IDataObject_fnDAdvise,
456 IDataObject_fnDUnadvise,
457 IDataObject_fnEnumDAdvise