mapi32: Remove DECLSPEC_HIDDEN usage.
[wine.git] / dlls / shell32 / dataobject.c
blobf7f7ee152c8eeecb2d1558684e5449ca281f7755
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"
34 WINE_DEFAULT_DEBUG_CHANNEL(shell);
36 /***********************************************************************
37 * IEnumFORMATETC implementation
40 typedef struct
42 /* IUnknown fields */
43 IEnumFORMATETC IEnumFORMATETC_iface;
44 LONG ref;
45 /* IEnumFORMATETC fields */
46 UINT posFmt;
47 UINT countFmt;
48 LPFORMATETC pFmt;
49 } IEnumFORMATETCImpl;
51 static inline IEnumFORMATETCImpl *impl_from_IEnumFORMATETC(IEnumFORMATETC *iface)
53 return CONTAINING_RECORD(iface, IEnumFORMATETCImpl, IEnumFORMATETC_iface);
56 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(
57 LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
59 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
60 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
62 *ppvObj = NULL;
64 if(IsEqualIID(riid, &IID_IUnknown) ||
65 IsEqualIID(riid, &IID_IEnumFORMATETC))
67 *ppvObj = &This->IEnumFORMATETC_iface;
70 if(*ppvObj)
72 IUnknown_AddRef((IUnknown*)(*ppvObj));
73 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
74 return S_OK;
76 TRACE("-- Interface: E_NOINTERFACE\n");
77 return E_NOINTERFACE;
80 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
82 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
83 ULONG refCount = InterlockedIncrement(&This->ref);
85 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
87 return refCount;
90 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
92 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
93 ULONG refCount = InterlockedDecrement(&This->ref);
95 TRACE("(%p)->(%lu)\n", This, refCount + 1);
97 if (!refCount)
99 TRACE(" destroying IEnumFORMATETC(%p)\n",This);
100 SHFree (This->pFmt);
101 heap_free(This);
103 return refCount;
106 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
108 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
109 UINT i;
111 TRACE("(%p)->(%lu,%p)\n", This, celt, rgelt);
113 if(!This->pFmt)return S_FALSE;
114 if(!rgelt) return E_INVALIDARG;
115 if (pceltFethed) *pceltFethed = 0;
117 for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
119 *rgelt++ = This->pFmt[This->posFmt++];
122 if (pceltFethed) *pceltFethed = i;
124 return ((i == celt) ? S_OK : S_FALSE);
127 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
129 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
130 TRACE("(%p)->(num=%lu)\n", This, celt);
132 if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
133 This->posFmt += celt;
134 return S_OK;
137 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
139 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
140 TRACE("(%p)->()\n", This);
142 This->posFmt = 0;
143 return S_OK;
146 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
148 IEnumFORMATETCImpl *This = impl_from_IEnumFORMATETC(iface);
149 TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
151 if (!ppenum) return E_INVALIDARG;
152 *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
153 if(*ppenum)
154 IEnumFORMATETC_fnSkip(*ppenum, This->posFmt);
155 return S_OK;
158 static const IEnumFORMATETCVtbl efvt =
160 IEnumFORMATETC_fnQueryInterface,
161 IEnumFORMATETC_fnAddRef,
162 IEnumFORMATETC_fnRelease,
163 IEnumFORMATETC_fnNext,
164 IEnumFORMATETC_fnSkip,
165 IEnumFORMATETC_fnReset,
166 IEnumFORMATETC_fnClone
169 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
171 IEnumFORMATETCImpl* ef;
172 DWORD size=cfmt * sizeof(FORMATETC);
174 ef = heap_alloc_zero(sizeof(*ef));
176 if(ef)
178 ef->ref=1;
179 ef->IEnumFORMATETC_iface.lpVtbl = &efvt;
181 ef->countFmt = cfmt;
182 ef->pFmt = SHAlloc (size);
184 if (ef->pFmt)
185 memcpy(ef->pFmt, afmt, size);
188 TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
189 return &ef->IEnumFORMATETC_iface;
193 /***********************************************************************
194 * IDataObject implementation
197 /* number of supported formats */
198 #define MAX_FORMATS 4
200 typedef struct
202 /* IUnknown fields */
203 IDataObject IDataObject_iface;
204 LONG ref;
206 /* IDataObject fields */
207 LPITEMIDLIST pidl;
208 LPITEMIDLIST * apidl;
209 UINT cidl;
211 FORMATETC pFormatEtc[MAX_FORMATS];
212 UINT cfShellIDList;
213 UINT cfFileNameA;
214 UINT cfFileNameW;
216 } IDataObjectImpl;
218 static inline IDataObjectImpl *impl_from_IDataObject(IDataObject *iface)
220 return CONTAINING_RECORD(iface, IDataObjectImpl, IDataObject_iface);
223 /***************************************************************************
224 * IDataObject_QueryInterface
226 static HRESULT WINAPI IDataObject_fnQueryInterface(IDataObject *iface, REFIID riid, LPVOID * ppvObj)
228 IDataObjectImpl *This = impl_from_IDataObject(iface);
229 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
231 *ppvObj = NULL;
233 if(IsEqualIID(riid, &IID_IUnknown) ||
234 IsEqualIID(riid, &IID_IDataObject))
236 *ppvObj = &This->IDataObject_iface;
239 if(*ppvObj)
241 IUnknown_AddRef((IUnknown*)*ppvObj);
242 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
243 return S_OK;
245 TRACE("-- Interface: E_NOINTERFACE\n");
246 return E_NOINTERFACE;
249 /**************************************************************************
250 * IDataObject_AddRef
252 static ULONG WINAPI IDataObject_fnAddRef(IDataObject *iface)
254 IDataObjectImpl *This = impl_from_IDataObject(iface);
255 ULONG refCount = InterlockedIncrement(&This->ref);
257 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
259 return refCount;
262 /**************************************************************************
263 * IDataObject_Release
265 static ULONG WINAPI IDataObject_fnRelease(IDataObject *iface)
267 IDataObjectImpl *This = impl_from_IDataObject(iface);
268 ULONG refCount = InterlockedDecrement(&This->ref);
270 TRACE("(%p)->(%lu)\n", This, refCount + 1);
272 if (!refCount)
274 TRACE(" destroying IDataObject(%p)\n",This);
275 _ILFreeaPidl(This->apidl, This->cidl);
276 ILFree(This->pidl);
277 heap_free(This);
279 return refCount;
282 /**************************************************************************
283 * IDataObject_fnGetData
285 static HRESULT WINAPI IDataObject_fnGetData(IDataObject *iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
287 IDataObjectImpl *This = impl_from_IDataObject(iface);
289 char szTemp[256];
291 szTemp[0]=0;
292 GetClipboardFormatNameA (pformatetcIn->cfFormat, szTemp, 256);
293 TRACE("(%p)->(%p %p format=%s)\n", This, pformatetcIn, pmedium, szTemp);
295 if (pformatetcIn->cfFormat == This->cfShellIDList)
297 if (This->cidl < 1) return(E_UNEXPECTED);
298 pmedium->u.hGlobal = RenderSHELLIDLIST(This->pidl, This->apidl, This->cidl);
300 else if (pformatetcIn->cfFormat == CF_HDROP)
302 if (This->cidl < 1) return(E_UNEXPECTED);
303 pmedium->u.hGlobal = RenderHDROP(This->pidl, This->apidl, This->cidl);
305 else if (pformatetcIn->cfFormat == This->cfFileNameA)
307 if (This->cidl < 1) return(E_UNEXPECTED);
308 pmedium->u.hGlobal = RenderFILENAMEA(This->pidl, This->apidl, This->cidl);
310 else if (pformatetcIn->cfFormat == This->cfFileNameW)
312 if (This->cidl < 1) return(E_UNEXPECTED);
313 pmedium->u.hGlobal = RenderFILENAMEW(This->pidl, This->apidl, This->cidl);
315 else
317 FIXME("-- expected clipformat not implemented\n");
318 return (E_INVALIDARG);
320 if (pmedium->u.hGlobal)
322 pmedium->tymed = TYMED_HGLOBAL;
323 pmedium->pUnkForRelease = NULL;
324 return S_OK;
326 return E_OUTOFMEMORY;
329 static HRESULT WINAPI IDataObject_fnGetDataHere(IDataObject *iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
331 IDataObjectImpl *This = impl_from_IDataObject(iface);
332 FIXME("(%p)->()\n", This);
333 return E_NOTIMPL;
336 static HRESULT WINAPI IDataObject_fnQueryGetData(IDataObject *iface, LPFORMATETC pformatetc)
338 IDataObjectImpl *This = impl_from_IDataObject(iface);
339 UINT i;
341 TRACE("(%p)->(fmt=0x%08x tym=0x%08lx)\n", This, pformatetc->cfFormat, pformatetc->tymed);
343 if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
344 return DV_E_DVASPECT;
346 /* check our formats table what we have */
347 for (i=0; i<MAX_FORMATS; i++)
349 if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
350 && (This->pFormatEtc[i].tymed & pformatetc->tymed))
352 return S_OK;
356 return DV_E_TYMED;
359 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(IDataObject *iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
361 IDataObjectImpl *This = impl_from_IDataObject(iface);
362 FIXME("(%p)->()\n", This);
363 return E_NOTIMPL;
366 static HRESULT WINAPI IDataObject_fnSetData(IDataObject *iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
368 IDataObjectImpl *This = impl_from_IDataObject(iface);
369 FIXME("(%p)->()\n", This);
370 return E_NOTIMPL;
373 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(IDataObject *iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
375 IDataObjectImpl *This = impl_from_IDataObject(iface);
377 TRACE("(%p)->()\n", This);
378 *ppenumFormatEtc=NULL;
380 /* only get data */
381 if (DATADIR_GET == dwDirection)
383 *ppenumFormatEtc = IEnumFORMATETC_Constructor(MAX_FORMATS, This->pFormatEtc);
384 return (*ppenumFormatEtc) ? S_OK : E_FAIL;
387 return E_NOTIMPL;
390 static HRESULT WINAPI IDataObject_fnDAdvise(IDataObject *iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
392 IDataObjectImpl *This = impl_from_IDataObject(iface);
393 FIXME("(%p)->()\n", This);
394 return E_NOTIMPL;
396 static HRESULT WINAPI IDataObject_fnDUnadvise(IDataObject *iface, DWORD dwConnection)
398 IDataObjectImpl *This = impl_from_IDataObject(iface);
399 FIXME("(%p)->()\n", This);
400 return E_NOTIMPL;
402 static HRESULT WINAPI IDataObject_fnEnumDAdvise(IDataObject *iface, IEnumSTATDATA **ppenumAdvise)
404 IDataObjectImpl *This = impl_from_IDataObject(iface);
405 FIXME("(%p)->()\n", This);
406 return E_NOTIMPL;
409 static const IDataObjectVtbl dtovt =
411 IDataObject_fnQueryInterface,
412 IDataObject_fnAddRef,
413 IDataObject_fnRelease,
414 IDataObject_fnGetData,
415 IDataObject_fnGetDataHere,
416 IDataObject_fnQueryGetData,
417 IDataObject_fnGetCanonicalFormatEtc,
418 IDataObject_fnSetData,
419 IDataObject_fnEnumFormatEtc,
420 IDataObject_fnDAdvise,
421 IDataObject_fnDUnadvise,
422 IDataObject_fnEnumDAdvise
425 /**************************************************************************
426 * IDataObject_Constructor
428 IDataObject* IDataObject_Constructor(HWND hwndOwner,
429 LPCITEMIDLIST pMyPidl, LPCITEMIDLIST * apidl, UINT cidl)
431 IDataObjectImpl* dto;
433 dto = heap_alloc_zero(sizeof(*dto));
435 if (dto)
437 dto->ref = 1;
438 dto->IDataObject_iface.lpVtbl = &dtovt;
439 dto->pidl = ILClone(pMyPidl);
440 dto->apidl = _ILCopyaPidl(apidl, cidl);
441 dto->cidl = cidl;
443 dto->cfShellIDList = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
444 dto->cfFileNameA = RegisterClipboardFormatA(CFSTR_FILENAMEA);
445 dto->cfFileNameW = RegisterClipboardFormatW(CFSTR_FILENAMEW);
446 InitFormatEtc(dto->pFormatEtc[0], dto->cfShellIDList, TYMED_HGLOBAL);
447 InitFormatEtc(dto->pFormatEtc[1], CF_HDROP, TYMED_HGLOBAL);
448 InitFormatEtc(dto->pFormatEtc[2], dto->cfFileNameA, TYMED_HGLOBAL);
449 InitFormatEtc(dto->pFormatEtc[3], dto->cfFileNameW, TYMED_HGLOBAL);
452 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto, apidl, cidl);
453 return &dto->IDataObject_iface;