2 * IEnumFORMATETC, IDataObject
4 * selecting and droping objects within the shell and/or common dialogs
6 * Copyright 1998, 1999 <juergen.schmied@metronet.de>
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
26 ICOM_VFIELD(IEnumFORMATETC
);
28 /* IEnumFORMATETC fields */
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
));
67 ef
->pFmt
= SHAlloc (size
);
71 memcpy(ef
->pFmt
, afmt
, size
);
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
);
88 if(IsEqualIID(riid
, &IID_IUnknown
))
92 else if(IsEqualIID(riid
, &IID_IEnumFORMATETC
))
94 *ppvObj
= (IEnumFORMATETC
*)This
;
99 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
100 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
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
);
113 return ++(This
->ref
);
116 static ULONG WINAPI
IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface
)
118 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
119 TRACE("(%p)->()\n",This
);
125 TRACE(" destroying IEnumFORMATETC(%p)\n",This
);
130 HeapFree(GetProcessHeap(),0,This
);
136 static HRESULT WINAPI
IEnumFORMATETC_fnNext(LPENUMFORMATETC iface
, ULONG celt
, FORMATETC
*rgelt
, ULONG
*pceltFethed
)
138 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
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
;
167 static HRESULT WINAPI
IEnumFORMATETC_fnReset(LPENUMFORMATETC iface
)
169 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
170 TRACE("(%p)->()\n", This
);
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
);
187 /***********************************************************************
188 * IDataObject implementation
191 /* number of supported formats */
192 #define MAX_FORMATS 3
196 /* IUnknown fields */
197 ICOM_VFIELD(IDataObject
);
200 /* IDataObject fields */
202 LPITEMIDLIST
* apidl
;
205 FORMATETC pFormatEtc
[MAX_FORMATS
];
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
));
225 ICOM_VTBL(dto
) = &dtovt
;
226 dto
->pidl
= ILClone(pMyPidl
);
227 dto
->apidl
= _ILCopyaPidl(apidl
, 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
);
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
);
253 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
257 else if(IsEqualIID(riid
, &IID_IDataObject
)) /*IDataObject*/
259 *ppvObj
= (IDataObject
*)This
;
264 IUnknown_AddRef((IUnknown
*)*ppvObj
);
265 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
268 TRACE("-- Interface: E_NOINTERFACE\n");
269 return E_NOINTERFACE
;
272 /**************************************************************************
275 static ULONG WINAPI
IDataObject_fnAddRef(LPDATAOBJECT iface
)
277 ICOM_THIS(IDataObjectImpl
,iface
);
279 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
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
);
297 TRACE(" destroying IDataObject(%p)\n",This
);
298 _ILFreeaPidl(This
->apidl
, This
->cidl
);
299 HeapFree(GetProcessHeap(),0,This
);
305 /**************************************************************************
306 * IDataObject_fnGetData
308 static HRESULT WINAPI
IDataObject_fnGetData(LPDATAOBJECT iface
, LPFORMATETC pformatetcIn
, STGMEDIUM
*pmedium
)
310 ICOM_THIS(IDataObjectImpl
,iface
);
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
);
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
;
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
);
354 static HRESULT WINAPI
IDataObject_fnQueryGetData(LPDATAOBJECT iface
, LPFORMATETC pformatetc
)
356 ICOM_THIS(IDataObjectImpl
,iface
);
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
))
377 static HRESULT WINAPI
IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface
, LPFORMATETC pformatectIn
, LPFORMATETC pformatetcOut
)
379 ICOM_THIS(IDataObjectImpl
,iface
);
380 FIXME("(%p)->()\n", This
);
384 static HRESULT WINAPI
IDataObject_fnSetData(LPDATAOBJECT iface
, LPFORMATETC pformatetc
, STGMEDIUM
*pmedium
, BOOL fRelease
)
386 ICOM_THIS(IDataObjectImpl
,iface
);
387 FIXME("(%p)->()\n", This
);
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
;
399 if (DATADIR_GET
== dwDirection
)
401 *ppenumFormatEtc
= IEnumFORMATETC_Constructor(MAX_FORMATS
, This
->pFormatEtc
);
402 return (*ppenumFormatEtc
) ? S_OK
: E_FAIL
;
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
);
414 static HRESULT WINAPI
IDataObject_fnDUnadvise(LPDATAOBJECT iface
, DWORD dwConnection
)
416 ICOM_THIS(IDataObjectImpl
,iface
);
417 FIXME("(%p)->()\n", This
);
420 static HRESULT WINAPI
IDataObject_fnEnumDAdvise(LPDATAOBJECT iface
, IEnumSTATDATA
**ppenumAdvise
)
422 ICOM_THIS(IDataObjectImpl
,iface
);
423 FIXME("(%p)->()\n", This
);
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