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
);
193 IEnumFORMATETC_fnSkip(*ppenum
, This
->posFmt
);
198 /***********************************************************************
199 * IDataObject implementation
202 /* number of supported formats */
203 #define MAX_FORMATS 3
207 /* IUnknown fields */
208 ICOM_VFIELD(IDataObject
);
211 /* IDataObject fields */
213 LPITEMIDLIST
* apidl
;
216 FORMATETC pFormatEtc
[MAX_FORMATS
];
222 static struct ICOM_VTABLE(IDataObject
) dtovt
;
224 /**************************************************************************
225 * IDataObject_Constructor
227 LPDATAOBJECT
IDataObject_Constructor(HWND hwndOwner
, LPITEMIDLIST pMyPidl
, LPITEMIDLIST
* apidl
, UINT cidl
)
229 IDataObjectImpl
* dto
;
231 dto
= (IDataObjectImpl
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDataObjectImpl
));
236 ICOM_VTBL(dto
) = &dtovt
;
237 dto
->pidl
= ILClone(pMyPidl
);
238 dto
->apidl
= _ILCopyaPidl(apidl
, cidl
);
241 dto
->cfShellIDList
= RegisterClipboardFormatA(CFSTR_SHELLIDLIST
);
242 dto
->cfFileName
= RegisterClipboardFormatA(CFSTR_FILENAMEA
);
243 InitFormatEtc(dto
->pFormatEtc
[0], dto
->cfShellIDList
, TYMED_HGLOBAL
);
244 InitFormatEtc(dto
->pFormatEtc
[1], CF_HDROP
, TYMED_HGLOBAL
);
245 InitFormatEtc(dto
->pFormatEtc
[2], dto
->cfFileName
, TYMED_HGLOBAL
);
248 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto
, apidl
, cidl
);
249 return (LPDATAOBJECT
)dto
;
252 /***************************************************************************
253 * IDataObject_QueryInterface
255 static HRESULT WINAPI
IDataObject_fnQueryInterface(LPDATAOBJECT iface
, REFIID riid
, LPVOID
* ppvObj
)
257 ICOM_THIS(IDataObjectImpl
,iface
);
258 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
262 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
266 else if(IsEqualIID(riid
, &IID_IDataObject
)) /*IDataObject*/
268 *ppvObj
= (IDataObject
*)This
;
273 IUnknown_AddRef((IUnknown
*)*ppvObj
);
274 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
277 TRACE("-- Interface: E_NOINTERFACE\n");
278 return E_NOINTERFACE
;
281 /**************************************************************************
284 static ULONG WINAPI
IDataObject_fnAddRef(LPDATAOBJECT iface
)
286 ICOM_THIS(IDataObjectImpl
,iface
);
287 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
288 return ++(This
->ref
);
291 /**************************************************************************
292 * IDataObject_Release
294 static ULONG WINAPI
IDataObject_fnRelease(LPDATAOBJECT iface
)
296 ICOM_THIS(IDataObjectImpl
,iface
);
297 TRACE("(%p)->()\n",This
);
301 TRACE(" destroying IDataObject(%p)\n",This
);
302 _ILFreeaPidl(This
->apidl
, This
->cidl
);
304 HeapFree(GetProcessHeap(),0,This
);
310 /**************************************************************************
311 * IDataObject_fnGetData
313 static HRESULT WINAPI
IDataObject_fnGetData(LPDATAOBJECT iface
, LPFORMATETC pformatetcIn
, STGMEDIUM
*pmedium
)
315 ICOM_THIS(IDataObjectImpl
,iface
);
320 GetClipboardFormatNameA (pformatetcIn
->cfFormat
, szTemp
, 256);
321 TRACE("(%p)->(%p %p format=%s)\n", This
, pformatetcIn
, pmedium
, szTemp
);
323 if (pformatetcIn
->cfFormat
== This
->cfShellIDList
)
325 if (This
->cidl
< 1) return(E_UNEXPECTED
);
326 pmedium
->u
.hGlobal
= RenderSHELLIDLIST(This
->pidl
, This
->apidl
, This
->cidl
);
328 else if (pformatetcIn
->cfFormat
== CF_HDROP
)
330 if (This
->cidl
< 1) return(E_UNEXPECTED
);
331 pmedium
->u
.hGlobal
= RenderHDROP(This
->pidl
, This
->apidl
, This
->cidl
);
333 else if (pformatetcIn
->cfFormat
== This
->cfFileName
)
335 if (This
->cidl
< 1) return(E_UNEXPECTED
);
336 pmedium
->u
.hGlobal
= RenderFILENAME(This
->pidl
, This
->apidl
, This
->cidl
);
340 FIXME("-- expected clipformat not implemented\n");
341 return (E_INVALIDARG
);
343 if (pmedium
->u
.hGlobal
)
345 pmedium
->tymed
= TYMED_HGLOBAL
;
346 pmedium
->pUnkForRelease
= NULL
;
349 return E_OUTOFMEMORY
;
352 static HRESULT WINAPI
IDataObject_fnGetDataHere(LPDATAOBJECT iface
, LPFORMATETC pformatetc
, STGMEDIUM
*pmedium
)
354 ICOM_THIS(IDataObjectImpl
,iface
);
355 FIXME("(%p)->()\n", This
);
359 static HRESULT WINAPI
IDataObject_fnQueryGetData(LPDATAOBJECT iface
, LPFORMATETC pformatetc
)
361 ICOM_THIS(IDataObjectImpl
,iface
);
364 TRACE("(%p)->(fmt=0x%08x tym=0x%08lx)\n", This
, pformatetc
->cfFormat
, pformatetc
->tymed
);
366 if(!(DVASPECT_CONTENT
& pformatetc
->dwAspect
))
367 return DV_E_DVASPECT
;
369 /* check our formats table what we have */
370 for (i
=0; i
<MAX_FORMATS
; i
++)
372 if ((This
->pFormatEtc
[i
].cfFormat
== pformatetc
->cfFormat
)
373 && (This
->pFormatEtc
[i
].tymed
== pformatetc
->tymed
))
382 static HRESULT WINAPI
IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface
, LPFORMATETC pformatectIn
, LPFORMATETC pformatetcOut
)
384 ICOM_THIS(IDataObjectImpl
,iface
);
385 FIXME("(%p)->()\n", This
);
389 static HRESULT WINAPI
IDataObject_fnSetData(LPDATAOBJECT iface
, LPFORMATETC pformatetc
, STGMEDIUM
*pmedium
, BOOL fRelease
)
391 ICOM_THIS(IDataObjectImpl
,iface
);
392 FIXME("(%p)->()\n", This
);
396 static HRESULT WINAPI
IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface
, DWORD dwDirection
, IEnumFORMATETC
**ppenumFormatEtc
)
398 ICOM_THIS(IDataObjectImpl
,iface
);
400 TRACE("(%p)->()\n", This
);
401 *ppenumFormatEtc
=NULL
;
404 if (DATADIR_GET
== dwDirection
)
406 *ppenumFormatEtc
= IEnumFORMATETC_Constructor(MAX_FORMATS
, This
->pFormatEtc
);
407 return (*ppenumFormatEtc
) ? S_OK
: E_FAIL
;
413 static HRESULT WINAPI
IDataObject_fnDAdvise(LPDATAOBJECT iface
, FORMATETC
*pformatetc
, DWORD advf
, IAdviseSink
*pAdvSink
, DWORD
*pdwConnection
)
415 ICOM_THIS(IDataObjectImpl
,iface
);
416 FIXME("(%p)->()\n", This
);
419 static HRESULT WINAPI
IDataObject_fnDUnadvise(LPDATAOBJECT iface
, DWORD dwConnection
)
421 ICOM_THIS(IDataObjectImpl
,iface
);
422 FIXME("(%p)->()\n", This
);
425 static HRESULT WINAPI
IDataObject_fnEnumDAdvise(LPDATAOBJECT iface
, IEnumSTATDATA
**ppenumAdvise
)
427 ICOM_THIS(IDataObjectImpl
,iface
);
428 FIXME("(%p)->()\n", This
);
432 static struct ICOM_VTABLE(IDataObject
) dtovt
=
434 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
435 IDataObject_fnQueryInterface
,
436 IDataObject_fnAddRef
,
437 IDataObject_fnRelease
,
438 IDataObject_fnGetData
,
439 IDataObject_fnGetDataHere
,
440 IDataObject_fnQueryGetData
,
441 IDataObject_fnGetCanonicalFormatEtc
,
442 IDataObject_fnSetData
,
443 IDataObject_fnEnumFormatEtc
,
444 IDataObject_fnDAdvise
,
445 IDataObject_fnDUnadvise
,
446 IDataObject_fnEnumDAdvise