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
26 #include "shell32_main.h"
27 #include "wine/debug.h"
28 #include "undocshell.h"
29 #include "wine/obj_dataobject.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(shell);
33 /***********************************************************************
34 * IEnumFORMATETC implementation
40 ICOM_VFIELD(IEnumFORMATETC);
42 /* IEnumFORMATETC fields */
48 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj);
49 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface);
50 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface);
51 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC* rgelt, ULONG* pceltFethed);
52 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt);
53 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface);
54 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum);
56 static struct ICOM_VTABLE(IEnumFORMATETC) efvt =
58 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
59 IEnumFORMATETC_fnQueryInterface,
60 IEnumFORMATETC_fnAddRef,
61 IEnumFORMATETC_fnRelease,
62 IEnumFORMATETC_fnNext,
63 IEnumFORMATETC_fnSkip,
64 IEnumFORMATETC_fnReset,
65 IEnumFORMATETC_fnClone
68 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
70 IEnumFORMATETCImpl* ef;
71 DWORD size=cfmt * sizeof(FORMATETC);
73 ef=(IEnumFORMATETCImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
81 ef->pFmt = SHAlloc (size);
85 memcpy(ef->pFmt, afmt, size);
89 TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
90 return (LPENUMFORMATETC)ef;
93 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
95 ICOM_THIS(IEnumFORMATETCImpl,iface);
96 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
100 if(IsEqualIID(riid, &IID_IUnknown))
104 else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
106 *ppvObj = (IEnumFORMATETC*)This;
111 IUnknown_AddRef((IUnknown*)(*ppvObj));
112 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
115 TRACE("-- Interface: E_NOINTERFACE\n");
116 return E_NOINTERFACE;
120 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
122 ICOM_THIS(IEnumFORMATETCImpl,iface);
123 TRACE("(%p)->(count=%lu)\n",This, This->ref);
124 return ++(This->ref);
127 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
129 ICOM_THIS(IEnumFORMATETCImpl,iface);
130 TRACE("(%p)->()\n",This);
134 TRACE(" destroying IEnumFORMATETC(%p)\n",This);
139 HeapFree(GetProcessHeap(),0,This);
145 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
147 ICOM_THIS(IEnumFORMATETCImpl,iface);
150 TRACE("(%p)->(%lu,%p)\n", This, celt, rgelt);
152 if(!This->pFmt)return S_FALSE;
153 if(!rgelt) return E_INVALIDARG;
154 if (pceltFethed) *pceltFethed = 0;
156 for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
158 *rgelt++ = This->pFmt[This->posFmt++];
161 if (pceltFethed) *pceltFethed = i;
163 return ((i == celt) ? S_OK : S_FALSE);
166 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
168 ICOM_THIS(IEnumFORMATETCImpl,iface);
169 TRACE("(%p)->(num=%lu)\n", This, celt);
171 if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
172 This->posFmt += celt;
176 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
178 ICOM_THIS(IEnumFORMATETCImpl,iface);
179 TRACE("(%p)->()\n", This);
185 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
187 ICOM_THIS(IEnumFORMATETCImpl,iface);
188 TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
190 if (!ppenum) return E_INVALIDARG;
191 *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
196 /***********************************************************************
197 * IDataObject implementation
200 /* number of supported formats */
201 #define MAX_FORMATS 3
205 /* IUnknown fields */
206 ICOM_VFIELD(IDataObject);
209 /* IDataObject fields */
211 LPITEMIDLIST * apidl;
214 FORMATETC pFormatEtc[MAX_FORMATS];
220 static struct ICOM_VTABLE(IDataObject) dtovt;
222 /**************************************************************************
223 * IDataObject_Constructor
225 LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner, LPITEMIDLIST pMyPidl, LPITEMIDLIST * apidl, UINT cidl)
227 IDataObjectImpl* dto;
229 dto = (IDataObjectImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDataObjectImpl));
234 ICOM_VTBL(dto) = &dtovt;
235 dto->pidl = ILClone(pMyPidl);
236 dto->apidl = _ILCopyaPidl(apidl, cidl);
239 dto->cfShellIDList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
240 dto->cfFileName = RegisterClipboardFormatA(CFSTR_FILENAMEA);
241 InitFormatEtc(dto->pFormatEtc[0], dto->cfShellIDList, TYMED_HGLOBAL);
242 InitFormatEtc(dto->pFormatEtc[1], CF_HDROP, TYMED_HGLOBAL);
243 InitFormatEtc(dto->pFormatEtc[2], dto->cfFileName, TYMED_HGLOBAL);
246 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto, apidl, cidl);
247 return (LPDATAOBJECT)dto;
250 /***************************************************************************
251 * IDataObject_QueryInterface
253 static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID * ppvObj)
255 ICOM_THIS(IDataObjectImpl,iface);
256 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
260 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
264 else if(IsEqualIID(riid, &IID_IDataObject)) /*IDataObject*/
266 *ppvObj = (IDataObject*)This;
271 IUnknown_AddRef((IUnknown*)*ppvObj);
272 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
275 TRACE("-- Interface: E_NOINTERFACE\n");
276 return E_NOINTERFACE;
279 /**************************************************************************
282 static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface)
284 ICOM_THIS(IDataObjectImpl,iface);
285 TRACE("(%p)->(count=%lu)\n",This, This->ref);
286 return ++(This->ref);
289 /**************************************************************************
290 * IDataObject_Release
292 static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface)
294 ICOM_THIS(IDataObjectImpl,iface);
295 TRACE("(%p)->()\n",This);
299 TRACE(" destroying IDataObject(%p)\n",This);
300 _ILFreeaPidl(This->apidl, This->cidl);
302 HeapFree(GetProcessHeap(),0,This);
308 /**************************************************************************
309 * IDataObject_fnGetData
311 static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
313 ICOM_THIS(IDataObjectImpl,iface);
318 GetClipboardFormatNameA (pformatetcIn->cfFormat, szTemp, 256);
319 TRACE("(%p)->(%p %p format=%s)\n", This, pformatetcIn, pmedium, szTemp);
321 if (pformatetcIn->cfFormat == This->cfShellIDList)
323 if (This->cidl < 1) return(E_UNEXPECTED);
324 pmedium->u.hGlobal = RenderSHELLIDLIST(This->pidl, This->apidl, This->cidl);
326 else if (pformatetcIn->cfFormat == CF_HDROP)
328 if (This->cidl < 1) return(E_UNEXPECTED);
329 pmedium->u.hGlobal = RenderHDROP(This->pidl, This->apidl, This->cidl);
331 else if (pformatetcIn->cfFormat == This->cfFileName)
333 if (This->cidl < 1) return(E_UNEXPECTED);
334 pmedium->u.hGlobal = RenderFILENAME(This->pidl, This->apidl, This->cidl);
338 FIXME("-- expected clipformat not implemented\n");
339 return (E_INVALIDARG);
341 if (pmedium->u.hGlobal)
343 pmedium->tymed = TYMED_HGLOBAL;
344 pmedium->pUnkForRelease = NULL;
347 return E_OUTOFMEMORY;
350 static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
352 ICOM_THIS(IDataObjectImpl,iface);
353 FIXME("(%p)->()\n", This);
357 static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc)
359 ICOM_THIS(IDataObjectImpl,iface);
362 TRACE("(%p)->(fmt=0x%08x tym=0x%08lx)\n", This, pformatetc->cfFormat, pformatetc->tymed);
364 if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
365 return DV_E_DVASPECT;
367 /* check our formats table what we have */
368 for (i=0; i<MAX_FORMATS; i++)
370 if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
371 && (This->pFormatEtc[i].tymed == pformatetc->tymed))
380 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
382 ICOM_THIS(IDataObjectImpl,iface);
383 FIXME("(%p)->()\n", This);
387 static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
389 ICOM_THIS(IDataObjectImpl,iface);
390 FIXME("(%p)->()\n", This);
394 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
396 ICOM_THIS(IDataObjectImpl,iface);
398 TRACE("(%p)->()\n", This);
399 *ppenumFormatEtc=NULL;
402 if (DATADIR_GET == dwDirection)
404 *ppenumFormatEtc = IEnumFORMATETC_Constructor(MAX_FORMATS, This->pFormatEtc);
405 return (*ppenumFormatEtc) ? S_OK : E_FAIL;
411 static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
413 ICOM_THIS(IDataObjectImpl,iface);
414 FIXME("(%p)->()\n", This);
417 static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection)
419 ICOM_THIS(IDataObjectImpl,iface);
420 FIXME("(%p)->()\n", This);
423 static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise)
425 ICOM_THIS(IDataObjectImpl,iface);
426 FIXME("(%p)->()\n", This);
430 static struct ICOM_VTABLE(IDataObject) dtovt =
432 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
433 IDataObject_fnQueryInterface,
434 IDataObject_fnAddRef,
435 IDataObject_fnRelease,
436 IDataObject_fnGetData,
437 IDataObject_fnGetDataHere,
438 IDataObject_fnQueryGetData,
439 IDataObject_fnGetCanonicalFormatEtc,
440 IDataObject_fnSetData,
441 IDataObject_fnEnumFormatEtc,
442 IDataObject_fnDAdvise,
443 IDataObject_fnDUnadvise,
444 IDataObject_fnEnumDAdvise