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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
32 #include "shell32_main.h"
33 #include "wine/debug.h"
34 #include "undocshell.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shell);
38 /***********************************************************************
39 * IEnumFORMATETC implementation
45 IEnumFORMATETCVtbl *lpVtbl;
47 /* IEnumFORMATETC fields */
53 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj);
54 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface);
55 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface);
56 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC* rgelt, ULONG* pceltFethed);
57 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt);
58 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface);
59 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum);
61 static struct IEnumFORMATETCVtbl efvt =
63 IEnumFORMATETC_fnQueryInterface,
64 IEnumFORMATETC_fnAddRef,
65 IEnumFORMATETC_fnRelease,
66 IEnumFORMATETC_fnNext,
67 IEnumFORMATETC_fnSkip,
68 IEnumFORMATETC_fnReset,
69 IEnumFORMATETC_fnClone
72 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
74 IEnumFORMATETCImpl* ef;
75 DWORD size=cfmt * sizeof(FORMATETC);
77 ef=(IEnumFORMATETCImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
85 ef->pFmt = SHAlloc (size);
89 memcpy(ef->pFmt, afmt, size);
93 TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
94 return (LPENUMFORMATETC)ef;
97 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
99 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
100 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
104 if(IsEqualIID(riid, &IID_IUnknown))
108 else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
110 *ppvObj = (IEnumFORMATETC*)This;
115 IUnknown_AddRef((IUnknown*)(*ppvObj));
116 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
119 TRACE("-- Interface: E_NOINTERFACE\n");
120 return E_NOINTERFACE;
124 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
126 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
127 TRACE("(%p)->(count=%lu)\n",This, This->ref);
128 return ++(This->ref);
131 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
133 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
134 TRACE("(%p)->()\n",This);
138 TRACE(" destroying IEnumFORMATETC(%p)\n",This);
143 HeapFree(GetProcessHeap(),0,This);
149 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
151 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
154 TRACE("(%p)->(%lu,%p)\n", This, celt, rgelt);
156 if(!This->pFmt)return S_FALSE;
157 if(!rgelt) return E_INVALIDARG;
158 if (pceltFethed) *pceltFethed = 0;
160 for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
162 *rgelt++ = This->pFmt[This->posFmt++];
165 if (pceltFethed) *pceltFethed = i;
167 return ((i == celt) ? S_OK : S_FALSE);
170 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
172 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
173 TRACE("(%p)->(num=%lu)\n", This, celt);
175 if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
176 This->posFmt += celt;
180 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
182 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
183 TRACE("(%p)->()\n", This);
189 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
191 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
192 TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
194 if (!ppenum) return E_INVALIDARG;
195 *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
197 IEnumFORMATETC_fnSkip(*ppenum, This->posFmt);
202 /***********************************************************************
203 * IDataObject implementation
206 /* number of supported formats */
207 #define MAX_FORMATS 4
211 /* IUnknown fields */
212 IDataObjectVtbl *lpVtbl;
215 /* IDataObject fields */
217 LPITEMIDLIST * apidl;
220 FORMATETC pFormatEtc[MAX_FORMATS];
227 static struct IDataObjectVtbl dtovt;
229 /**************************************************************************
230 * IDataObject_Constructor
232 LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner, LPCITEMIDLIST pMyPidl, LPCITEMIDLIST * apidl, UINT cidl)
234 IDataObjectImpl* dto;
236 dto = (IDataObjectImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDataObjectImpl));
241 dto->lpVtbl = &dtovt;
242 dto->pidl = ILClone(pMyPidl);
243 dto->apidl = _ILCopyaPidl(apidl, cidl);
246 dto->cfShellIDList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
247 dto->cfFileNameA = RegisterClipboardFormatA(CFSTR_FILENAMEA);
248 dto->cfFileNameW = RegisterClipboardFormatA(CFSTR_FILENAMEW);
249 InitFormatEtc(dto->pFormatEtc[0], dto->cfShellIDList, TYMED_HGLOBAL);
250 InitFormatEtc(dto->pFormatEtc[1], CF_HDROP, TYMED_HGLOBAL);
251 InitFormatEtc(dto->pFormatEtc[2], dto->cfFileNameA, TYMED_HGLOBAL);
252 InitFormatEtc(dto->pFormatEtc[3], dto->cfFileNameW, TYMED_HGLOBAL);
255 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto, apidl, cidl);
256 return (LPDATAOBJECT)dto;
259 /***************************************************************************
260 * IDataObject_QueryInterface
262 static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID * ppvObj)
264 IDataObjectImpl *This = (IDataObjectImpl *)iface;
265 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
269 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
273 else if(IsEqualIID(riid, &IID_IDataObject)) /*IDataObject*/
275 *ppvObj = (IDataObject*)This;
280 IUnknown_AddRef((IUnknown*)*ppvObj);
281 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
284 TRACE("-- Interface: E_NOINTERFACE\n");
285 return E_NOINTERFACE;
288 /**************************************************************************
291 static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface)
293 IDataObjectImpl *This = (IDataObjectImpl *)iface;
294 TRACE("(%p)->(count=%lu)\n",This, This->ref);
295 return ++(This->ref);
298 /**************************************************************************
299 * IDataObject_Release
301 static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface)
303 IDataObjectImpl *This = (IDataObjectImpl *)iface;
304 TRACE("(%p)->()\n",This);
308 TRACE(" destroying IDataObject(%p)\n",This);
309 _ILFreeaPidl(This->apidl, This->cidl);
311 HeapFree(GetProcessHeap(),0,This);
317 /**************************************************************************
318 * IDataObject_fnGetData
320 static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
322 IDataObjectImpl *This = (IDataObjectImpl *)iface;
327 GetClipboardFormatNameA (pformatetcIn->cfFormat, szTemp, 256);
328 TRACE("(%p)->(%p %p format=%s)\n", This, pformatetcIn, pmedium, szTemp);
330 if (pformatetcIn->cfFormat == This->cfShellIDList)
332 if (This->cidl < 1) return(E_UNEXPECTED);
333 pmedium->u.hGlobal = RenderSHELLIDLIST(This->pidl, This->apidl, This->cidl);
335 else if (pformatetcIn->cfFormat == CF_HDROP)
337 if (This->cidl < 1) return(E_UNEXPECTED);
338 pmedium->u.hGlobal = RenderHDROP(This->pidl, This->apidl, This->cidl);
340 else if (pformatetcIn->cfFormat == This->cfFileNameA)
342 if (This->cidl < 1) return(E_UNEXPECTED);
343 pmedium->u.hGlobal = RenderFILENAMEA(This->pidl, This->apidl, This->cidl);
345 else if (pformatetcIn->cfFormat == This->cfFileNameW)
347 if (This->cidl < 1) return(E_UNEXPECTED);
348 pmedium->u.hGlobal = RenderFILENAMEW(This->pidl, This->apidl, This->cidl);
352 FIXME("-- expected clipformat not implemented\n");
353 return (E_INVALIDARG);
355 if (pmedium->u.hGlobal)
357 pmedium->tymed = TYMED_HGLOBAL;
358 pmedium->pUnkForRelease = NULL;
361 return E_OUTOFMEMORY;
364 static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
366 IDataObjectImpl *This = (IDataObjectImpl *)iface;
367 FIXME("(%p)->()\n", This);
371 static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc)
373 IDataObjectImpl *This = (IDataObjectImpl *)iface;
376 TRACE("(%p)->(fmt=0x%08x tym=0x%08lx)\n", This, pformatetc->cfFormat, pformatetc->tymed);
378 if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
379 return DV_E_DVASPECT;
381 /* check our formats table what we have */
382 for (i=0; i<MAX_FORMATS; i++)
384 if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
385 && (This->pFormatEtc[i].tymed == pformatetc->tymed))
394 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
396 IDataObjectImpl *This = (IDataObjectImpl *)iface;
397 FIXME("(%p)->()\n", This);
401 static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
403 IDataObjectImpl *This = (IDataObjectImpl *)iface;
404 FIXME("(%p)->()\n", This);
408 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
410 IDataObjectImpl *This = (IDataObjectImpl *)iface;
412 TRACE("(%p)->()\n", This);
413 *ppenumFormatEtc=NULL;
416 if (DATADIR_GET == dwDirection)
418 *ppenumFormatEtc = IEnumFORMATETC_Constructor(MAX_FORMATS, This->pFormatEtc);
419 return (*ppenumFormatEtc) ? S_OK : E_FAIL;
425 static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
427 IDataObjectImpl *This = (IDataObjectImpl *)iface;
428 FIXME("(%p)->()\n", This);
431 static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection)
433 IDataObjectImpl *This = (IDataObjectImpl *)iface;
434 FIXME("(%p)->()\n", This);
437 static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise)
439 IDataObjectImpl *This = (IDataObjectImpl *)iface;
440 FIXME("(%p)->()\n", This);
444 static struct IDataObjectVtbl dtovt =
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