shell32: Added missing arguments to trace messages.
[wine.git] / dlls / shell32 / dataobject.c
blobcc7b63e5d0589a5a5b4639184316d98fd87e533e
1 /*
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
22 #include <string.h>
24 #define COBJMACROS
25 #define NONAMELESSUNION
27 #include "windef.h"
28 #include "wingdi.h"
29 #include "pidl.h"
30 #include "winerror.h"
31 #include "shell32_main.h"
32 #include "wine/debug.h"
33 #include "undocshell.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(shell);
37 /***********************************************************************
38 * IEnumFORMATETC implementation
41 typedef struct
43 /* IUnknown fields */
44 IEnumFORMATETC IEnumFORMATETC_iface;
45 LONG ref;
46 /* IEnumFORMATETC fields */
47 UINT posFmt;
48 UINT countFmt;
49 LPFORMATETC pFmt;
50 } IEnumFORMATETCImpl;
52 static inline IEnumFORMATETCImpl *impl_from_IEnumFORMATETC(IEnumFORMATETC *iface)
54 return CONTAINING_RECORD(iface, IEnumFORMATETCImpl, IEnumFORMATETC_iface);
57 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(
58 LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
60 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
61 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
63 *ppvObj = NULL;
65 if(IsEqualIID(riid, &IID_IUnknown) ||
66 IsEqualIID(riid, &IID_IEnumFORMATETC))
68 *ppvObj = &This->IEnumFORMATETC_iface;
71 if(*ppvObj)
73 IUnknown_AddRef((IUnknown*)(*ppvObj));
74 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
75 return S_OK;
77 TRACE("-- Interface: E_NOINTERFACE\n");
78 return E_NOINTERFACE;
81 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
83 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
84 ULONG refCount = InterlockedIncrement(&This->ref);
86 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
88 return refCount;
91 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
93 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
94 ULONG refCount = InterlockedDecrement(&This->ref);
96 TRACE("(%p)->(%u)\n", This, refCount + 1);
98 if (!refCount)
100 TRACE(" destroying IEnumFORMATETC(%p)\n",This);
101 SHFree (This->pFmt);
102 HeapFree(GetProcessHeap(),0,This);
103 return 0;
105 return refCount;
108 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
110 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
111 UINT i;
113 TRACE("(%p)->(%u,%p)\n", This, celt, rgelt);
115 if(!This->pFmt)return S_FALSE;
116 if(!rgelt) return E_INVALIDARG;
117 if (pceltFethed) *pceltFethed = 0;
119 for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
121 *rgelt++ = This->pFmt[This->posFmt++];
124 if (pceltFethed) *pceltFethed = i;
126 return ((i == celt) ? S_OK : S_FALSE);
129 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
131 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
132 TRACE("(%p)->(num=%u)\n", This, celt);
134 if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
135 This->posFmt += celt;
136 return S_OK;
139 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
141 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
142 TRACE("(%p)->()\n", This);
144 This->posFmt = 0;
145 return S_OK;
148 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
150 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
151 TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
153 if (!ppenum) return E_INVALIDARG;
154 *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
155 if(*ppenum)
156 IEnumFORMATETC_fnSkip(*ppenum, This->posFmt);
157 return S_OK;
160 static const IEnumFORMATETCVtbl efvt =
162 IEnumFORMATETC_fnQueryInterface,
163 IEnumFORMATETC_fnAddRef,
164 IEnumFORMATETC_fnRelease,
165 IEnumFORMATETC_fnNext,
166 IEnumFORMATETC_fnSkip,
167 IEnumFORMATETC_fnReset,
168 IEnumFORMATETC_fnClone
171 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
173 IEnumFORMATETCImpl* ef;
174 DWORD size=cfmt * sizeof(FORMATETC);
176 ef = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
178 if(ef)
180 ef->ref=1;
181 ef->IEnumFORMATETC_iface.lpVtbl = &efvt;
183 ef->countFmt = cfmt;
184 ef->pFmt = SHAlloc (size);
186 if (ef->pFmt)
187 memcpy(ef->pFmt, afmt, size);
190 TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
191 return (LPENUMFORMATETC)ef;
195 /***********************************************************************
196 * IDataObject implementation
199 /* number of supported formats */
200 #define MAX_FORMATS 4
202 typedef struct
204 /* IUnknown fields */
205 IDataObject IDataObject_iface;
206 LONG ref;
208 /* IDataObject fields */
209 LPITEMIDLIST pidl;
210 LPITEMIDLIST * apidl;
211 UINT cidl;
213 FORMATETC pFormatEtc[MAX_FORMATS];
214 UINT cfShellIDList;
215 UINT cfFileNameA;
216 UINT cfFileNameW;
218 } IDataObjectImpl;
220 static inline IDataObjectImpl *impl_from_IDataObject(IDataObject *iface)
222 return CONTAINING_RECORD(iface, IDataObjectImpl, IDataObject_iface);
225 /***************************************************************************
226 * IDataObject_QueryInterface
228 static HRESULT WINAPI IDataObject_fnQueryInterface(IDataObject *iface, REFIID riid, LPVOID * ppvObj)
230 IDataObjectImpl *This = impl_from_IDataObject(iface);
231 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
233 *ppvObj = NULL;
235 if(IsEqualIID(riid, &IID_IUnknown) ||
236 IsEqualIID(riid, &IID_IDataObject))
238 *ppvObj = &This->IDataObject_iface;
241 if(*ppvObj)
243 IUnknown_AddRef((IUnknown*)*ppvObj);
244 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
245 return S_OK;
247 TRACE("-- Interface: E_NOINTERFACE\n");
248 return E_NOINTERFACE;
251 /**************************************************************************
252 * IDataObject_AddRef
254 static ULONG WINAPI IDataObject_fnAddRef(IDataObject *iface)
256 IDataObjectImpl *This = impl_from_IDataObject(iface);
257 ULONG refCount = InterlockedIncrement(&This->ref);
259 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
261 return refCount;
264 /**************************************************************************
265 * IDataObject_Release
267 static ULONG WINAPI IDataObject_fnRelease(IDataObject *iface)
269 IDataObjectImpl *This = impl_from_IDataObject(iface);
270 ULONG refCount = InterlockedDecrement(&This->ref);
272 TRACE("(%p)->(%u)\n", This, refCount + 1);
274 if (!refCount)
276 TRACE(" destroying IDataObject(%p)\n",This);
277 _ILFreeaPidl(This->apidl, This->cidl);
278 ILFree(This->pidl),
279 HeapFree(GetProcessHeap(),0,This);
281 return refCount;
284 /**************************************************************************
285 * IDataObject_fnGetData
287 static HRESULT WINAPI IDataObject_fnGetData(IDataObject *iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
289 IDataObjectImpl *This = impl_from_IDataObject(iface);
291 char szTemp[256];
293 szTemp[0]=0;
294 GetClipboardFormatNameA (pformatetcIn->cfFormat, szTemp, 256);
295 TRACE("(%p)->(%p %p format=%s)\n", This, pformatetcIn, pmedium, szTemp);
297 if (pformatetcIn->cfFormat == This->cfShellIDList)
299 if (This->cidl < 1) return(E_UNEXPECTED);
300 pmedium->u.hGlobal = RenderSHELLIDLIST(This->pidl, This->apidl, This->cidl);
302 else if (pformatetcIn->cfFormat == CF_HDROP)
304 if (This->cidl < 1) return(E_UNEXPECTED);
305 pmedium->u.hGlobal = RenderHDROP(This->pidl, This->apidl, This->cidl);
307 else if (pformatetcIn->cfFormat == This->cfFileNameA)
309 if (This->cidl < 1) return(E_UNEXPECTED);
310 pmedium->u.hGlobal = RenderFILENAMEA(This->pidl, This->apidl, This->cidl);
312 else if (pformatetcIn->cfFormat == This->cfFileNameW)
314 if (This->cidl < 1) return(E_UNEXPECTED);
315 pmedium->u.hGlobal = RenderFILENAMEW(This->pidl, This->apidl, This->cidl);
317 else
319 FIXME("-- expected clipformat not implemented\n");
320 return (E_INVALIDARG);
322 if (pmedium->u.hGlobal)
324 pmedium->tymed = TYMED_HGLOBAL;
325 pmedium->pUnkForRelease = NULL;
326 return S_OK;
328 return E_OUTOFMEMORY;
331 static HRESULT WINAPI IDataObject_fnGetDataHere(IDataObject *iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
333 IDataObjectImpl *This = impl_from_IDataObject(iface);
334 FIXME("(%p)->()\n", This);
335 return E_NOTIMPL;
338 static HRESULT WINAPI IDataObject_fnQueryGetData(IDataObject *iface, LPFORMATETC pformatetc)
340 IDataObjectImpl *This = impl_from_IDataObject(iface);
341 UINT i;
343 TRACE("(%p)->(fmt=0x%08x tym=0x%08x)\n", This, pformatetc->cfFormat, pformatetc->tymed);
345 if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
346 return DV_E_DVASPECT;
348 /* check our formats table what we have */
349 for (i=0; i<MAX_FORMATS; i++)
351 if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
352 && (This->pFormatEtc[i].tymed & pformatetc->tymed))
354 return S_OK;
358 return DV_E_TYMED;
361 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(IDataObject *iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
363 IDataObjectImpl *This = impl_from_IDataObject(iface);
364 FIXME("(%p)->()\n", This);
365 return E_NOTIMPL;
368 static HRESULT WINAPI IDataObject_fnSetData(IDataObject *iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
370 IDataObjectImpl *This = impl_from_IDataObject(iface);
371 FIXME("(%p)->()\n", This);
372 return E_NOTIMPL;
375 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(IDataObject *iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
377 IDataObjectImpl *This = impl_from_IDataObject(iface);
379 TRACE("(%p)->()\n", This);
380 *ppenumFormatEtc=NULL;
382 /* only get data */
383 if (DATADIR_GET == dwDirection)
385 *ppenumFormatEtc = IEnumFORMATETC_Constructor(MAX_FORMATS, This->pFormatEtc);
386 return (*ppenumFormatEtc) ? S_OK : E_FAIL;
389 return E_NOTIMPL;
392 static HRESULT WINAPI IDataObject_fnDAdvise(IDataObject *iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
394 IDataObjectImpl *This = impl_from_IDataObject(iface);
395 FIXME("(%p)->()\n", This);
396 return E_NOTIMPL;
398 static HRESULT WINAPI IDataObject_fnDUnadvise(IDataObject *iface, DWORD dwConnection)
400 IDataObjectImpl *This = impl_from_IDataObject(iface);
401 FIXME("(%p)->()\n", This);
402 return E_NOTIMPL;
404 static HRESULT WINAPI IDataObject_fnEnumDAdvise(IDataObject *iface, IEnumSTATDATA **ppenumAdvise)
406 IDataObjectImpl *This = impl_from_IDataObject(iface);
407 FIXME("(%p)->()\n", This);
408 return E_NOTIMPL;
411 static const IDataObjectVtbl dtovt =
413 IDataObject_fnQueryInterface,
414 IDataObject_fnAddRef,
415 IDataObject_fnRelease,
416 IDataObject_fnGetData,
417 IDataObject_fnGetDataHere,
418 IDataObject_fnQueryGetData,
419 IDataObject_fnGetCanonicalFormatEtc,
420 IDataObject_fnSetData,
421 IDataObject_fnEnumFormatEtc,
422 IDataObject_fnDAdvise,
423 IDataObject_fnDUnadvise,
424 IDataObject_fnEnumDAdvise
427 /**************************************************************************
428 * IDataObject_Constructor
430 IDataObject* IDataObject_Constructor(HWND hwndOwner,
431 LPCITEMIDLIST pMyPidl, LPCITEMIDLIST * apidl, UINT cidl)
433 IDataObjectImpl* dto;
435 dto = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDataObjectImpl));
437 if (dto)
439 dto->ref = 1;
440 dto->IDataObject_iface.lpVtbl = &dtovt;
441 dto->pidl = ILClone(pMyPidl);
442 dto->apidl = _ILCopyaPidl(apidl, cidl);
443 dto->cidl = cidl;
445 dto->cfShellIDList = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
446 dto->cfFileNameA = RegisterClipboardFormatA(CFSTR_FILENAMEA);
447 dto->cfFileNameW = RegisterClipboardFormatW(CFSTR_FILENAMEW);
448 InitFormatEtc(dto->pFormatEtc[0], dto->cfShellIDList, TYMED_HGLOBAL);
449 InitFormatEtc(dto->pFormatEtc[1], CF_HDROP, TYMED_HGLOBAL);
450 InitFormatEtc(dto->pFormatEtc[2], dto->cfFileNameA, TYMED_HGLOBAL);
451 InitFormatEtc(dto->pFormatEtc[3], dto->cfFileNameW, TYMED_HGLOBAL);
454 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto, apidl, cidl);
455 return &dto->IDataObject_iface;