Removed winmm from import list.
[wine/multimedia.git] / dlls / shell32 / dataobject.c
blob8c90b010ab3405e30fe221f80a50d5a709effd6e
1 /*
2 * IEnumFORMATETC, IDataObject
4 * selecting and droping objects within the shell and/or common dialogs
6 * Copyright 1998, 1999 <juergen.schmied@metronet.de>
7 */
8 #include <string.h>
10 #include "pidl.h"
11 #include "winerror.h"
12 #include "shell32_main.h"
13 #include "debugtools.h"
14 #include "wine/undocshell.h"
15 #include "wine/obj_dataobject.h"
17 DEFAULT_DEBUG_CHANNEL(shell)
19 /***********************************************************************
20 * IEnumFORMATETC implementation
23 typedef struct
25 /* IUnknown fields */
26 ICOM_VFIELD(IEnumFORMATETC);
27 DWORD ref;
28 /* IEnumFORMATETC fields */
29 UINT posFmt;
30 UINT countFmt;
31 LPFORMATETC pFmt;
32 } IEnumFORMATETCImpl;
34 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj);
35 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface);
36 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface);
37 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC* rgelt, ULONG* pceltFethed);
38 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt);
39 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface);
40 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum);
42 static struct ICOM_VTABLE(IEnumFORMATETC) efvt =
44 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
45 IEnumFORMATETC_fnQueryInterface,
46 IEnumFORMATETC_fnAddRef,
47 IEnumFORMATETC_fnRelease,
48 IEnumFORMATETC_fnNext,
49 IEnumFORMATETC_fnSkip,
50 IEnumFORMATETC_fnReset,
51 IEnumFORMATETC_fnClone
54 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
56 IEnumFORMATETCImpl* ef;
57 DWORD size=cfmt * sizeof(FORMATETC);
59 ef=(IEnumFORMATETCImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
61 if(ef)
63 ef->ref=1;
64 ICOM_VTBL(ef)=&efvt;
66 ef->countFmt = cfmt;
67 ef->pFmt = SHAlloc (size);
69 if (ef->pFmt)
71 memcpy(ef->pFmt, afmt, size);
74 shell32_ObjCount++;
77 TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
78 return (LPENUMFORMATETC)ef;
81 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
83 ICOM_THIS(IEnumFORMATETCImpl,iface);
84 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
86 *ppvObj = NULL;
88 if(IsEqualIID(riid, &IID_IUnknown))
90 *ppvObj = This;
92 else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
94 *ppvObj = (IEnumFORMATETC*)This;
97 if(*ppvObj)
99 IUnknown_AddRef((IUnknown*)(*ppvObj));
100 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
101 return S_OK;
103 TRACE("-- Interface: E_NOINTERFACE\n");
104 return E_NOINTERFACE;
108 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
110 ICOM_THIS(IEnumFORMATETCImpl,iface);
111 TRACE("(%p)->(count=%lu)\n",This, This->ref);
112 shell32_ObjCount++;
113 return ++(This->ref);
116 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
118 ICOM_THIS(IEnumFORMATETCImpl,iface);
119 TRACE("(%p)->()\n",This);
121 shell32_ObjCount--;
123 if (!--(This->ref))
125 TRACE(" destroying IEnumFORMATETC(%p)\n",This);
126 if (This->pFmt)
128 SHFree (This->pFmt);
130 HeapFree(GetProcessHeap(),0,This);
131 return 0;
133 return This->ref;
136 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
138 ICOM_THIS(IEnumFORMATETCImpl,iface);
139 int i;
141 TRACE("(%p)->(%lu,%p)\n", This, celt, rgelt);
143 if(!This->pFmt)return S_FALSE;
144 if(!rgelt) return E_INVALIDARG;
145 if (pceltFethed) *pceltFethed = 0;
147 for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
149 *rgelt++ = This->pFmt[This->posFmt++];
152 if (pceltFethed) *pceltFethed = i;
154 return ((i == celt) ? S_OK : S_FALSE);
157 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
159 ICOM_THIS(IEnumFORMATETCImpl,iface);
160 TRACE("(%p)->(num=%lu)\n", This, celt);
162 if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
163 This->posFmt += celt;
164 return S_OK;
167 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
169 ICOM_THIS(IEnumFORMATETCImpl,iface);
170 TRACE("(%p)->()\n", This);
172 This->posFmt = 0;
173 return S_OK;
176 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
178 ICOM_THIS(IEnumFORMATETCImpl,iface);
179 TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
181 if (!ppenum) return E_INVALIDARG;
182 *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
183 return S_OK;
187 /***********************************************************************
188 * IDataObject implementation
191 /* number of supported formats */
192 #define MAX_FORMATS 3
194 typedef struct
196 /* IUnknown fields */
197 ICOM_VFIELD(IDataObject);
198 DWORD ref;
200 /* IDataObject fields */
201 LPITEMIDLIST pidl;
202 LPITEMIDLIST * apidl;
203 UINT cidl;
205 FORMATETC pFormatEtc[MAX_FORMATS];
206 UINT cfShellIDList;
207 UINT cfFileName;
209 } IDataObjectImpl;
211 static struct ICOM_VTABLE(IDataObject) dtovt;
213 /**************************************************************************
214 * IDataObject_Constructor
216 LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner, LPITEMIDLIST pMyPidl, LPITEMIDLIST * apidl, UINT cidl)
218 IDataObjectImpl* dto;
220 dto = (IDataObjectImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDataObjectImpl));
222 if (dto)
224 dto->ref = 1;
225 ICOM_VTBL(dto) = &dtovt;
226 dto->pidl = ILClone(pMyPidl);
227 dto->apidl = _ILCopyaPidl(apidl, cidl);
228 dto->cidl = cidl;
230 dto->cfShellIDList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
231 dto->cfFileName = RegisterClipboardFormatA(CFSTR_FILENAMEA);
232 InitFormatEtc(dto->pFormatEtc[0], dto->cfShellIDList, TYMED_HGLOBAL);
233 InitFormatEtc(dto->pFormatEtc[1], CF_HDROP, TYMED_HGLOBAL);
234 InitFormatEtc(dto->pFormatEtc[2], dto->cfFileName, TYMED_HGLOBAL);
236 shell32_ObjCount++;
239 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto, apidl, cidl);
240 return (LPDATAOBJECT)dto;
243 /***************************************************************************
244 * IDataObject_QueryInterface
246 static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID * ppvObj)
248 ICOM_THIS(IDataObjectImpl,iface);
249 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
251 *ppvObj = NULL;
253 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
255 *ppvObj = This;
257 else if(IsEqualIID(riid, &IID_IDataObject)) /*IDataObject*/
259 *ppvObj = (IDataObject*)This;
262 if(*ppvObj)
264 IUnknown_AddRef((IUnknown*)*ppvObj);
265 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
266 return S_OK;
268 TRACE("-- Interface: E_NOINTERFACE\n");
269 return E_NOINTERFACE;
272 /**************************************************************************
273 * IDataObject_AddRef
275 static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface)
277 ICOM_THIS(IDataObjectImpl,iface);
279 TRACE("(%p)->(count=%lu)\n",This, This->ref);
281 shell32_ObjCount++;
282 return ++(This->ref);
285 /**************************************************************************
286 * IDataObject_Release
288 static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface)
290 ICOM_THIS(IDataObjectImpl,iface);
291 TRACE("(%p)->()\n",This);
293 shell32_ObjCount--;
295 if (!--(This->ref))
297 TRACE(" destroying IDataObject(%p)\n",This);
298 _ILFreeaPidl(This->apidl, This->cidl);
299 HeapFree(GetProcessHeap(),0,This);
300 return 0;
302 return This->ref;
305 /**************************************************************************
306 * IDataObject_fnGetData
308 static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
310 ICOM_THIS(IDataObjectImpl,iface);
312 char szTemp[256];
314 szTemp[0]=0;
315 GetClipboardFormatNameA (pformatetcIn->cfFormat, szTemp, 256);
316 TRACE("(%p)->(%p %p format=%s)\n", This, pformatetcIn, pmedium, szTemp);
318 if (pformatetcIn->cfFormat == This->cfShellIDList)
320 if (This->cidl < 1) return(E_UNEXPECTED);
321 pmedium->u.hGlobal = RenderSHELLIDLIST(This->pidl, This->apidl, This->cidl);
323 else if (pformatetcIn->cfFormat == CF_HDROP)
325 if (This->cidl < 1) return(E_UNEXPECTED);
326 pmedium->u.hGlobal = RenderHDROP(This->pidl, This->apidl, This->cidl);
328 else if (pformatetcIn->cfFormat == This->cfFileName)
330 if (This->cidl < 1) return(E_UNEXPECTED);
331 pmedium->u.hGlobal = RenderFILENAME(This->pidl, This->apidl, This->cidl);
333 else
335 FIXME("-- expected clipformat not implemented\n");
336 return (E_INVALIDARG);
338 if (pmedium->u.hGlobal)
340 pmedium->tymed = TYMED_HGLOBAL;
341 pmedium->pUnkForRelease = NULL;
342 return S_OK;
344 return E_OUTOFMEMORY;
347 static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
349 ICOM_THIS(IDataObjectImpl,iface);
350 FIXME("(%p)->()\n", This);
351 return E_NOTIMPL;
354 static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc)
356 ICOM_THIS(IDataObjectImpl,iface);
357 UINT i;
359 TRACE("(%p)->(fmt=0x%08x tym=0x%08lx)\n", This, pformatetc->cfFormat, pformatetc->tymed);
361 if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
362 return DV_E_DVASPECT;
364 /* check our formats table what we have */
365 for (i=0; i<MAX_FORMATS; i++)
367 if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
368 && (This->pFormatEtc[i].tymed == pformatetc->tymed))
370 return S_OK;
374 return DV_E_TYMED;
377 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
379 ICOM_THIS(IDataObjectImpl,iface);
380 FIXME("(%p)->()\n", This);
381 return E_NOTIMPL;
384 static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
386 ICOM_THIS(IDataObjectImpl,iface);
387 FIXME("(%p)->()\n", This);
388 return E_NOTIMPL;
391 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
393 ICOM_THIS(IDataObjectImpl,iface);
395 TRACE("(%p)->()\n", This);
396 *ppenumFormatEtc=NULL;
398 /* only get data */
399 if (DATADIR_GET == dwDirection)
401 *ppenumFormatEtc = IEnumFORMATETC_Constructor(MAX_FORMATS, This->pFormatEtc);
402 return (*ppenumFormatEtc) ? S_OK : E_FAIL;
405 return E_NOTIMPL;
408 static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
410 ICOM_THIS(IDataObjectImpl,iface);
411 FIXME("(%p)->()\n", This);
412 return E_NOTIMPL;
414 static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection)
416 ICOM_THIS(IDataObjectImpl,iface);
417 FIXME("(%p)->()\n", This);
418 return E_NOTIMPL;
420 static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise)
422 ICOM_THIS(IDataObjectImpl,iface);
423 FIXME("(%p)->()\n", This);
424 return E_NOTIMPL;
427 static struct ICOM_VTABLE(IDataObject) dtovt =
429 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
430 IDataObject_fnQueryInterface,
431 IDataObject_fnAddRef,
432 IDataObject_fnRelease,
433 IDataObject_fnGetData,
434 IDataObject_fnGetDataHere,
435 IDataObject_fnQueryGetData,
436 IDataObject_fnGetCanonicalFormatEtc,
437 IDataObject_fnSetData,
438 IDataObject_fnEnumFormatEtc,
439 IDataObject_fnDAdvise,
440 IDataObject_fnDUnadvise,
441 IDataObject_fnEnumDAdvise