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
28 #include "shell32_main.h"
29 #include "wine/debug.h"
30 #include "undocshell.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(shell);
34 /***********************************************************************
35 * IEnumFORMATETC implementation
41 ICOM_VFIELD(IEnumFORMATETC);
43 /* IEnumFORMATETC fields */
49 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj);
50 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface);
51 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface);
52 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC* rgelt, ULONG* pceltFethed);
53 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt);
54 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface);
55 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum);
57 static struct ICOM_VTABLE(IEnumFORMATETC) efvt =
59 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
60 IEnumFORMATETC_fnQueryInterface,
61 IEnumFORMATETC_fnAddRef,
62 IEnumFORMATETC_fnRelease,
63 IEnumFORMATETC_fnNext,
64 IEnumFORMATETC_fnSkip,
65 IEnumFORMATETC_fnReset,
66 IEnumFORMATETC_fnClone
69 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
71 IEnumFORMATETCImpl* ef;
72 DWORD size=cfmt * sizeof(FORMATETC);
74 ef=(IEnumFORMATETCImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
82 ef->pFmt = SHAlloc (size);
86 memcpy(ef->pFmt, afmt, size);
90 TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
91 return (LPENUMFORMATETC)ef;
94 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
96 ICOM_THIS(IEnumFORMATETCImpl,iface);
97 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
101 if(IsEqualIID(riid, &IID_IUnknown))
105 else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
107 *ppvObj = (IEnumFORMATETC*)This;
112 IUnknown_AddRef((IUnknown*)(*ppvObj));
113 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
116 TRACE("-- Interface: E_NOINTERFACE\n");
117 return E_NOINTERFACE;
121 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
123 ICOM_THIS(IEnumFORMATETCImpl,iface);
124 TRACE("(%p)->(count=%lu)\n",This, This->ref);
125 return ++(This->ref);
128 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
130 ICOM_THIS(IEnumFORMATETCImpl,iface);
131 TRACE("(%p)->()\n",This);
135 TRACE(" destroying IEnumFORMATETC(%p)\n",This);
140 HeapFree(GetProcessHeap(),0,This);
146 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
148 ICOM_THIS(IEnumFORMATETCImpl,iface);
151 TRACE("(%p)->(%lu,%p)\n", This, celt, rgelt);
153 if(!This->pFmt)return S_FALSE;
154 if(!rgelt) return E_INVALIDARG;
155 if (pceltFethed) *pceltFethed = 0;
157 for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
159 *rgelt++ = This->pFmt[This->posFmt++];
162 if (pceltFethed) *pceltFethed = i;
164 return ((i == celt) ? S_OK : S_FALSE);
167 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
169 ICOM_THIS(IEnumFORMATETCImpl,iface);
170 TRACE("(%p)->(num=%lu)\n", This, celt);
172 if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
173 This->posFmt += celt;
177 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
179 ICOM_THIS(IEnumFORMATETCImpl,iface);
180 TRACE("(%p)->()\n", This);
186 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
188 ICOM_THIS(IEnumFORMATETCImpl,iface);
189 TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
191 if (!ppenum) return E_INVALIDARG;
192 *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
194 IEnumFORMATETC_fnSkip(*ppenum, This->posFmt);
199 /***********************************************************************
200 * IDataObject implementation
203 /* number of supported formats */
204 #define MAX_FORMATS 4
208 /* IUnknown fields */
209 ICOM_VFIELD(IDataObject);
212 /* IDataObject fields */
214 LPITEMIDLIST * apidl;
217 FORMATETC pFormatEtc[MAX_FORMATS];
224 static struct ICOM_VTABLE(IDataObject) dtovt;
226 /**************************************************************************
227 * IDataObject_Constructor
229 LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner, LPITEMIDLIST pMyPidl, LPITEMIDLIST * apidl, UINT cidl)
231 IDataObjectImpl* dto;
233 dto = (IDataObjectImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDataObjectImpl));
238 dto->lpVtbl = &dtovt;
239 dto->pidl = ILClone(pMyPidl);
240 dto->apidl = _ILCopyaPidl(apidl, cidl);
243 dto->cfShellIDList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
244 dto->cfFileNameA = RegisterClipboardFormatA(CFSTR_FILENAMEA);
245 dto->cfFileNameW = RegisterClipboardFormatA(CFSTR_FILENAMEW);
246 InitFormatEtc(dto->pFormatEtc[0], dto->cfShellIDList, TYMED_HGLOBAL);
247 InitFormatEtc(dto->pFormatEtc[1], CF_HDROP, TYMED_HGLOBAL);
248 InitFormatEtc(dto->pFormatEtc[2], dto->cfFileNameA, TYMED_HGLOBAL);
249 InitFormatEtc(dto->pFormatEtc[3], dto->cfFileNameW, TYMED_HGLOBAL);
252 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto, apidl, cidl);
253 return (LPDATAOBJECT)dto;
256 /***************************************************************************
257 * IDataObject_QueryInterface
259 static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID * ppvObj)
261 ICOM_THIS(IDataObjectImpl,iface);
262 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
266 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
270 else if(IsEqualIID(riid, &IID_IDataObject)) /*IDataObject*/
272 *ppvObj = (IDataObject*)This;
277 IUnknown_AddRef((IUnknown*)*ppvObj);
278 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
281 TRACE("-- Interface: E_NOINTERFACE\n");
282 return E_NOINTERFACE;
285 /**************************************************************************
288 static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface)
290 ICOM_THIS(IDataObjectImpl,iface);
291 TRACE("(%p)->(count=%lu)\n",This, This->ref);
292 return ++(This->ref);
295 /**************************************************************************
296 * IDataObject_Release
298 static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface)
300 ICOM_THIS(IDataObjectImpl,iface);
301 TRACE("(%p)->()\n",This);
305 TRACE(" destroying IDataObject(%p)\n",This);
306 _ILFreeaPidl(This->apidl, This->cidl);
308 HeapFree(GetProcessHeap(),0,This);
314 /**************************************************************************
315 * IDataObject_fnGetData
317 static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
319 ICOM_THIS(IDataObjectImpl,iface);
324 GetClipboardFormatNameA (pformatetcIn->cfFormat, szTemp, 256);
325 TRACE("(%p)->(%p %p format=%s)\n", This, pformatetcIn, pmedium, szTemp);
327 if (pformatetcIn->cfFormat == This->cfShellIDList)
329 if (This->cidl < 1) return(E_UNEXPECTED);
330 pmedium->u.hGlobal = RenderSHELLIDLIST(This->pidl, This->apidl, This->cidl);
332 else if (pformatetcIn->cfFormat == CF_HDROP)
334 if (This->cidl < 1) return(E_UNEXPECTED);
335 pmedium->u.hGlobal = RenderHDROP(This->pidl, This->apidl, This->cidl);
337 else if (pformatetcIn->cfFormat == This->cfFileNameA)
339 if (This->cidl < 1) return(E_UNEXPECTED);
340 pmedium->u.hGlobal = RenderFILENAMEA(This->pidl, This->apidl, This->cidl);
342 else if (pformatetcIn->cfFormat == This->cfFileNameW)
344 if (This->cidl < 1) return(E_UNEXPECTED);
345 pmedium->u.hGlobal = RenderFILENAMEW(This->pidl, This->apidl, This->cidl);
349 FIXME("-- expected clipformat not implemented\n");
350 return (E_INVALIDARG);
352 if (pmedium->u.hGlobal)
354 pmedium->tymed = TYMED_HGLOBAL;
355 pmedium->pUnkForRelease = NULL;
358 return E_OUTOFMEMORY;
361 static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
363 ICOM_THIS(IDataObjectImpl,iface);
364 FIXME("(%p)->()\n", This);
368 static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc)
370 ICOM_THIS(IDataObjectImpl,iface);
373 TRACE("(%p)->(fmt=0x%08x tym=0x%08lx)\n", This, pformatetc->cfFormat, pformatetc->tymed);
375 if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
376 return DV_E_DVASPECT;
378 /* check our formats table what we have */
379 for (i=0; i<MAX_FORMATS; i++)
381 if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
382 && (This->pFormatEtc[i].tymed == pformatetc->tymed))
391 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
393 ICOM_THIS(IDataObjectImpl,iface);
394 FIXME("(%p)->()\n", This);
398 static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
400 ICOM_THIS(IDataObjectImpl,iface);
401 FIXME("(%p)->()\n", This);
405 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
407 ICOM_THIS(IDataObjectImpl,iface);
409 TRACE("(%p)->()\n", This);
410 *ppenumFormatEtc=NULL;
413 if (DATADIR_GET == dwDirection)
415 *ppenumFormatEtc = IEnumFORMATETC_Constructor(MAX_FORMATS, This->pFormatEtc);
416 return (*ppenumFormatEtc) ? S_OK : E_FAIL;
422 static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
424 ICOM_THIS(IDataObjectImpl,iface);
425 FIXME("(%p)->()\n", This);
428 static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection)
430 ICOM_THIS(IDataObjectImpl,iface);
431 FIXME("(%p)->()\n", This);
434 static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise)
436 ICOM_THIS(IDataObjectImpl,iface);
437 FIXME("(%p)->()\n", This);
441 static struct ICOM_VTABLE(IDataObject) dtovt =
443 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
444 IDataObject_fnQueryInterface,
445 IDataObject_fnAddRef,
446 IDataObject_fnRelease,
447 IDataObject_fnGetData,
448 IDataObject_fnGetDataHere,
449 IDataObject_fnQueryGetData,
450 IDataObject_fnGetCanonicalFormatEtc,
451 IDataObject_fnSetData,
452 IDataObject_fnEnumFormatEtc,
453 IDataObject_fnDAdvise,
454 IDataObject_fnDUnadvise,
455 IDataObject_fnEnumDAdvise