2 * IEnumFORMATETC, IDataObject
4 * selecting and dropping 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 const IEnumFORMATETCVtbl *lpVtbl;
47 /* IEnumFORMATETC fields */
53 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(
54 LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
56 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
57 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
61 if(IsEqualIID(riid, &IID_IUnknown))
65 else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
72 IUnknown_AddRef((IUnknown*)(*ppvObj));
73 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
76 TRACE("-- Interface: E_NOINTERFACE\n");
80 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
82 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
83 ULONG refCount = InterlockedIncrement(&This->ref);
85 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
90 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
92 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
93 ULONG refCount = InterlockedDecrement(&This->ref);
95 TRACE("(%p)->(%u)\n", This, refCount + 1);
99 TRACE(" destroying IEnumFORMATETC(%p)\n",This);
101 HeapFree(GetProcessHeap(),0,This);
107 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
109 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
112 TRACE("(%p)->(%u,%p)\n", This, celt, rgelt);
114 if(!This->pFmt)return S_FALSE;
115 if(!rgelt) return E_INVALIDARG;
116 if (pceltFethed) *pceltFethed = 0;
118 for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
120 *rgelt++ = This->pFmt[This->posFmt++];
123 if (pceltFethed) *pceltFethed = i;
125 return ((i == celt) ? S_OK : S_FALSE);
128 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
130 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
131 TRACE("(%p)->(num=%u)\n", This, celt);
133 if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
134 This->posFmt += celt;
138 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
140 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
141 TRACE("(%p)->()\n", This);
147 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
149 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
150 TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
152 if (!ppenum) return E_INVALIDARG;
153 *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
155 IEnumFORMATETC_fnSkip(*ppenum, This->posFmt);
159 static const IEnumFORMATETCVtbl efvt =
161 IEnumFORMATETC_fnQueryInterface,
162 IEnumFORMATETC_fnAddRef,
163 IEnumFORMATETC_fnRelease,
164 IEnumFORMATETC_fnNext,
165 IEnumFORMATETC_fnSkip,
166 IEnumFORMATETC_fnReset,
167 IEnumFORMATETC_fnClone
170 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
172 IEnumFORMATETCImpl* ef;
173 DWORD size=cfmt * sizeof(FORMATETC);
175 ef = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
183 ef->pFmt = SHAlloc (size);
186 memcpy(ef->pFmt, afmt, size);
189 TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
190 return (LPENUMFORMATETC)ef;
194 /***********************************************************************
195 * IDataObject implementation
198 /* number of supported formats */
199 #define MAX_FORMATS 4
203 /* IUnknown fields */
204 const IDataObjectVtbl *lpVtbl;
207 /* IDataObject fields */
209 LPITEMIDLIST * apidl;
212 FORMATETC pFormatEtc[MAX_FORMATS];
219 /***************************************************************************
220 * IDataObject_QueryInterface
222 static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID * ppvObj)
224 IDataObjectImpl *This = (IDataObjectImpl *)iface;
225 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
229 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
233 else if(IsEqualIID(riid, &IID_IDataObject)) /*IDataObject*/
240 IUnknown_AddRef((IUnknown*)*ppvObj);
241 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
244 TRACE("-- Interface: E_NOINTERFACE\n");
245 return E_NOINTERFACE;
248 /**************************************************************************
251 static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface)
253 IDataObjectImpl *This = (IDataObjectImpl *)iface;
254 ULONG refCount = InterlockedIncrement(&This->ref);
256 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
261 /**************************************************************************
262 * IDataObject_Release
264 static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface)
266 IDataObjectImpl *This = (IDataObjectImpl *)iface;
267 ULONG refCount = InterlockedDecrement(&This->ref);
269 TRACE("(%p)->(%u)\n", This, refCount + 1);
273 TRACE(" destroying IDataObject(%p)\n",This);
274 _ILFreeaPidl(This->apidl, This->cidl);
276 HeapFree(GetProcessHeap(),0,This);
281 /**************************************************************************
282 * IDataObject_fnGetData
284 static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
286 IDataObjectImpl *This = (IDataObjectImpl *)iface;
291 GetClipboardFormatNameA (pformatetcIn->cfFormat, szTemp, 256);
292 TRACE("(%p)->(%p %p format=%s)\n", This, pformatetcIn, pmedium, szTemp);
294 if (pformatetcIn->cfFormat == This->cfShellIDList)
296 if (This->cidl < 1) return(E_UNEXPECTED);
297 pmedium->u.hGlobal = RenderSHELLIDLIST(This->pidl, This->apidl, This->cidl);
299 else if (pformatetcIn->cfFormat == CF_HDROP)
301 if (This->cidl < 1) return(E_UNEXPECTED);
302 pmedium->u.hGlobal = RenderHDROP(This->pidl, This->apidl, This->cidl);
304 else if (pformatetcIn->cfFormat == This->cfFileNameA)
306 if (This->cidl < 1) return(E_UNEXPECTED);
307 pmedium->u.hGlobal = RenderFILENAMEA(This->pidl, This->apidl, This->cidl);
309 else if (pformatetcIn->cfFormat == This->cfFileNameW)
311 if (This->cidl < 1) return(E_UNEXPECTED);
312 pmedium->u.hGlobal = RenderFILENAMEW(This->pidl, This->apidl, This->cidl);
316 FIXME("-- expected clipformat not implemented\n");
317 return (E_INVALIDARG);
319 if (pmedium->u.hGlobal)
321 pmedium->tymed = TYMED_HGLOBAL;
322 pmedium->pUnkForRelease = NULL;
325 return E_OUTOFMEMORY;
328 static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
330 IDataObjectImpl *This = (IDataObjectImpl *)iface;
331 FIXME("(%p)->()\n", This);
335 static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc)
337 IDataObjectImpl *This = (IDataObjectImpl *)iface;
340 TRACE("(%p)->(fmt=0x%08x tym=0x%08x)\n", This, pformatetc->cfFormat, pformatetc->tymed);
342 if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
343 return DV_E_DVASPECT;
345 /* check our formats table what we have */
346 for (i=0; i<MAX_FORMATS; i++)
348 if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
349 && (This->pFormatEtc[i].tymed == pformatetc->tymed))
358 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
360 IDataObjectImpl *This = (IDataObjectImpl *)iface;
361 FIXME("(%p)->()\n", This);
365 static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
367 IDataObjectImpl *This = (IDataObjectImpl *)iface;
368 FIXME("(%p)->()\n", This);
372 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
374 IDataObjectImpl *This = (IDataObjectImpl *)iface;
376 TRACE("(%p)->()\n", This);
377 *ppenumFormatEtc=NULL;
380 if (DATADIR_GET == dwDirection)
382 *ppenumFormatEtc = IEnumFORMATETC_Constructor(MAX_FORMATS, This->pFormatEtc);
383 return (*ppenumFormatEtc) ? S_OK : E_FAIL;
389 static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
391 IDataObjectImpl *This = (IDataObjectImpl *)iface;
392 FIXME("(%p)->()\n", This);
395 static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection)
397 IDataObjectImpl *This = (IDataObjectImpl *)iface;
398 FIXME("(%p)->()\n", This);
401 static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise)
403 IDataObjectImpl *This = (IDataObjectImpl *)iface;
404 FIXME("(%p)->()\n", This);
408 static const IDataObjectVtbl dtovt =
410 IDataObject_fnQueryInterface,
411 IDataObject_fnAddRef,
412 IDataObject_fnRelease,
413 IDataObject_fnGetData,
414 IDataObject_fnGetDataHere,
415 IDataObject_fnQueryGetData,
416 IDataObject_fnGetCanonicalFormatEtc,
417 IDataObject_fnSetData,
418 IDataObject_fnEnumFormatEtc,
419 IDataObject_fnDAdvise,
420 IDataObject_fnDUnadvise,
421 IDataObject_fnEnumDAdvise
424 /**************************************************************************
425 * IDataObject_Constructor
427 LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner,
428 LPCITEMIDLIST pMyPidl, LPCITEMIDLIST * apidl, UINT cidl)
430 IDataObjectImpl* dto;
432 dto = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDataObjectImpl));
437 dto->lpVtbl = &dtovt;
438 dto->pidl = ILClone(pMyPidl);
439 dto->apidl = _ILCopyaPidl(apidl, cidl);
442 dto->cfShellIDList = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
443 dto->cfFileNameA = RegisterClipboardFormatA(CFSTR_FILENAMEA);
444 dto->cfFileNameW = RegisterClipboardFormatW(CFSTR_FILENAMEW);
445 InitFormatEtc(dto->pFormatEtc[0], dto->cfShellIDList, TYMED_HGLOBAL);
446 InitFormatEtc(dto->pFormatEtc[1], CF_HDROP, TYMED_HGLOBAL);
447 InitFormatEtc(dto->pFormatEtc[2], dto->cfFileNameA, TYMED_HGLOBAL);
448 InitFormatEtc(dto->pFormatEtc[3], dto->cfFileNameW, TYMED_HGLOBAL);
451 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto, apidl, cidl);
452 return (LPDATAOBJECT)dto;