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"
30 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
32 /***********************************************************************
33 * IEnumFORMATETC implementation
39 ICOM_VFIELD(IEnumFORMATETC
);
41 /* IEnumFORMATETC fields */
47 static HRESULT WINAPI
IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface
, REFIID riid
, LPVOID
* ppvObj
);
48 static ULONG WINAPI
IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface
);
49 static ULONG WINAPI
IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface
);
50 static HRESULT WINAPI
IEnumFORMATETC_fnNext(LPENUMFORMATETC iface
, ULONG celt
, FORMATETC
* rgelt
, ULONG
* pceltFethed
);
51 static HRESULT WINAPI
IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface
, ULONG celt
);
52 static HRESULT WINAPI
IEnumFORMATETC_fnReset(LPENUMFORMATETC iface
);
53 static HRESULT WINAPI
IEnumFORMATETC_fnClone(LPENUMFORMATETC iface
, LPENUMFORMATETC
* ppenum
);
55 static struct ICOM_VTABLE(IEnumFORMATETC
) efvt
=
57 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
58 IEnumFORMATETC_fnQueryInterface
,
59 IEnumFORMATETC_fnAddRef
,
60 IEnumFORMATETC_fnRelease
,
61 IEnumFORMATETC_fnNext
,
62 IEnumFORMATETC_fnSkip
,
63 IEnumFORMATETC_fnReset
,
64 IEnumFORMATETC_fnClone
67 LPENUMFORMATETC
IEnumFORMATETC_Constructor(UINT cfmt
, const FORMATETC afmt
[])
69 IEnumFORMATETCImpl
* ef
;
70 DWORD size
=cfmt
* sizeof(FORMATETC
);
72 ef
=(IEnumFORMATETCImpl
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumFORMATETCImpl
));
80 ef
->pFmt
= SHAlloc (size
);
84 memcpy(ef
->pFmt
, afmt
, size
);
88 TRACE("(%p)->(%u,%p)\n",ef
, cfmt
, afmt
);
89 return (LPENUMFORMATETC
)ef
;
92 static HRESULT WINAPI
IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface
, REFIID riid
, LPVOID
* ppvObj
)
94 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
95 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
99 if(IsEqualIID(riid
, &IID_IUnknown
))
103 else if(IsEqualIID(riid
, &IID_IEnumFORMATETC
))
105 *ppvObj
= (IEnumFORMATETC
*)This
;
110 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
111 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
114 TRACE("-- Interface: E_NOINTERFACE\n");
115 return E_NOINTERFACE
;
119 static ULONG WINAPI
IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface
)
121 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
122 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
123 return ++(This
->ref
);
126 static ULONG WINAPI
IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface
)
128 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
129 TRACE("(%p)->()\n",This
);
133 TRACE(" destroying IEnumFORMATETC(%p)\n",This
);
138 HeapFree(GetProcessHeap(),0,This
);
144 static HRESULT WINAPI
IEnumFORMATETC_fnNext(LPENUMFORMATETC iface
, ULONG celt
, FORMATETC
*rgelt
, ULONG
*pceltFethed
)
146 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
149 TRACE("(%p)->(%lu,%p)\n", This
, celt
, rgelt
);
151 if(!This
->pFmt
)return S_FALSE
;
152 if(!rgelt
) return E_INVALIDARG
;
153 if (pceltFethed
) *pceltFethed
= 0;
155 for(i
= 0; This
->posFmt
< This
->countFmt
&& celt
> i
; i
++)
157 *rgelt
++ = This
->pFmt
[This
->posFmt
++];
160 if (pceltFethed
) *pceltFethed
= i
;
162 return ((i
== celt
) ? S_OK
: S_FALSE
);
165 static HRESULT WINAPI
IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface
, ULONG celt
)
167 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
168 TRACE("(%p)->(num=%lu)\n", This
, celt
);
170 if((This
->posFmt
+ celt
) >= This
->countFmt
) return S_FALSE
;
171 This
->posFmt
+= celt
;
175 static HRESULT WINAPI
IEnumFORMATETC_fnReset(LPENUMFORMATETC iface
)
177 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
178 TRACE("(%p)->()\n", This
);
184 static HRESULT WINAPI
IEnumFORMATETC_fnClone(LPENUMFORMATETC iface
, LPENUMFORMATETC
* ppenum
)
186 ICOM_THIS(IEnumFORMATETCImpl
,iface
);
187 TRACE("(%p)->(ppenum=%p)\n", This
, ppenum
);
189 if (!ppenum
) return E_INVALIDARG
;
190 *ppenum
= IEnumFORMATETC_Constructor(This
->countFmt
, This
->pFmt
);
192 IEnumFORMATETC_fnSkip(*ppenum
, This
->posFmt
);
197 /***********************************************************************
198 * IDataObject implementation
201 /* number of supported formats */
202 #define MAX_FORMATS 3
206 /* IUnknown fields */
207 ICOM_VFIELD(IDataObject
);
210 /* IDataObject fields */
212 LPITEMIDLIST
* apidl
;
215 FORMATETC pFormatEtc
[MAX_FORMATS
];
221 static struct ICOM_VTABLE(IDataObject
) dtovt
;
223 /**************************************************************************
224 * IDataObject_Constructor
226 LPDATAOBJECT
IDataObject_Constructor(HWND hwndOwner
, LPITEMIDLIST pMyPidl
, LPITEMIDLIST
* apidl
, UINT cidl
)
228 IDataObjectImpl
* dto
;
230 dto
= (IDataObjectImpl
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDataObjectImpl
));
235 ICOM_VTBL(dto
) = &dtovt
;
236 dto
->pidl
= ILClone(pMyPidl
);
237 dto
->apidl
= _ILCopyaPidl(apidl
, cidl
);
240 dto
->cfShellIDList
= RegisterClipboardFormatA(CFSTR_SHELLIDLIST
);
241 dto
->cfFileName
= RegisterClipboardFormatA(CFSTR_FILENAMEA
);
242 InitFormatEtc(dto
->pFormatEtc
[0], dto
->cfShellIDList
, TYMED_HGLOBAL
);
243 InitFormatEtc(dto
->pFormatEtc
[1], CF_HDROP
, TYMED_HGLOBAL
);
244 InitFormatEtc(dto
->pFormatEtc
[2], dto
->cfFileName
, TYMED_HGLOBAL
);
247 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto
, apidl
, cidl
);
248 return (LPDATAOBJECT
)dto
;
251 /***************************************************************************
252 * IDataObject_QueryInterface
254 static HRESULT WINAPI
IDataObject_fnQueryInterface(LPDATAOBJECT iface
, REFIID riid
, LPVOID
* ppvObj
)
256 ICOM_THIS(IDataObjectImpl
,iface
);
257 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
261 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
265 else if(IsEqualIID(riid
, &IID_IDataObject
)) /*IDataObject*/
267 *ppvObj
= (IDataObject
*)This
;
272 IUnknown_AddRef((IUnknown
*)*ppvObj
);
273 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
276 TRACE("-- Interface: E_NOINTERFACE\n");
277 return E_NOINTERFACE
;
280 /**************************************************************************
283 static ULONG WINAPI
IDataObject_fnAddRef(LPDATAOBJECT iface
)
285 ICOM_THIS(IDataObjectImpl
,iface
);
286 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
287 return ++(This
->ref
);
290 /**************************************************************************
291 * IDataObject_Release
293 static ULONG WINAPI
IDataObject_fnRelease(LPDATAOBJECT iface
)
295 ICOM_THIS(IDataObjectImpl
,iface
);
296 TRACE("(%p)->()\n",This
);
300 TRACE(" destroying IDataObject(%p)\n",This
);
301 _ILFreeaPidl(This
->apidl
, This
->cidl
);
303 HeapFree(GetProcessHeap(),0,This
);
309 /**************************************************************************
310 * IDataObject_fnGetData
312 static HRESULT WINAPI
IDataObject_fnGetData(LPDATAOBJECT iface
, LPFORMATETC pformatetcIn
, STGMEDIUM
*pmedium
)
314 ICOM_THIS(IDataObjectImpl
,iface
);
319 GetClipboardFormatNameA (pformatetcIn
->cfFormat
, szTemp
, 256);
320 TRACE("(%p)->(%p %p format=%s)\n", This
, pformatetcIn
, pmedium
, szTemp
);
322 if (pformatetcIn
->cfFormat
== This
->cfShellIDList
)
324 if (This
->cidl
< 1) return(E_UNEXPECTED
);
325 pmedium
->u
.hGlobal
= RenderSHELLIDLIST(This
->pidl
, This
->apidl
, This
->cidl
);
327 else if (pformatetcIn
->cfFormat
== CF_HDROP
)
329 if (This
->cidl
< 1) return(E_UNEXPECTED
);
330 pmedium
->u
.hGlobal
= RenderHDROP(This
->pidl
, This
->apidl
, This
->cidl
);
332 else if (pformatetcIn
->cfFormat
== This
->cfFileName
)
334 if (This
->cidl
< 1) return(E_UNEXPECTED
);
335 pmedium
->u
.hGlobal
= RenderFILENAME(This
->pidl
, This
->apidl
, This
->cidl
);
339 FIXME("-- expected clipformat not implemented\n");
340 return (E_INVALIDARG
);
342 if (pmedium
->u
.hGlobal
)
344 pmedium
->tymed
= TYMED_HGLOBAL
;
345 pmedium
->pUnkForRelease
= NULL
;
348 return E_OUTOFMEMORY
;
351 static HRESULT WINAPI
IDataObject_fnGetDataHere(LPDATAOBJECT iface
, LPFORMATETC pformatetc
, STGMEDIUM
*pmedium
)
353 ICOM_THIS(IDataObjectImpl
,iface
);
354 FIXME("(%p)->()\n", This
);
358 static HRESULT WINAPI
IDataObject_fnQueryGetData(LPDATAOBJECT iface
, LPFORMATETC pformatetc
)
360 ICOM_THIS(IDataObjectImpl
,iface
);
363 TRACE("(%p)->(fmt=0x%08x tym=0x%08lx)\n", This
, pformatetc
->cfFormat
, pformatetc
->tymed
);
365 if(!(DVASPECT_CONTENT
& pformatetc
->dwAspect
))
366 return DV_E_DVASPECT
;
368 /* check our formats table what we have */
369 for (i
=0; i
<MAX_FORMATS
; i
++)
371 if ((This
->pFormatEtc
[i
].cfFormat
== pformatetc
->cfFormat
)
372 && (This
->pFormatEtc
[i
].tymed
== pformatetc
->tymed
))
381 static HRESULT WINAPI
IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface
, LPFORMATETC pformatectIn
, LPFORMATETC pformatetcOut
)
383 ICOM_THIS(IDataObjectImpl
,iface
);
384 FIXME("(%p)->()\n", This
);
388 static HRESULT WINAPI
IDataObject_fnSetData(LPDATAOBJECT iface
, LPFORMATETC pformatetc
, STGMEDIUM
*pmedium
, BOOL fRelease
)
390 ICOM_THIS(IDataObjectImpl
,iface
);
391 FIXME("(%p)->()\n", This
);
395 static HRESULT WINAPI
IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface
, DWORD dwDirection
, IEnumFORMATETC
**ppenumFormatEtc
)
397 ICOM_THIS(IDataObjectImpl
,iface
);
399 TRACE("(%p)->()\n", This
);
400 *ppenumFormatEtc
=NULL
;
403 if (DATADIR_GET
== dwDirection
)
405 *ppenumFormatEtc
= IEnumFORMATETC_Constructor(MAX_FORMATS
, This
->pFormatEtc
);
406 return (*ppenumFormatEtc
) ? S_OK
: E_FAIL
;
412 static HRESULT WINAPI
IDataObject_fnDAdvise(LPDATAOBJECT iface
, FORMATETC
*pformatetc
, DWORD advf
, IAdviseSink
*pAdvSink
, DWORD
*pdwConnection
)
414 ICOM_THIS(IDataObjectImpl
,iface
);
415 FIXME("(%p)->()\n", This
);
418 static HRESULT WINAPI
IDataObject_fnDUnadvise(LPDATAOBJECT iface
, DWORD dwConnection
)
420 ICOM_THIS(IDataObjectImpl
,iface
);
421 FIXME("(%p)->()\n", This
);
424 static HRESULT WINAPI
IDataObject_fnEnumDAdvise(LPDATAOBJECT iface
, IEnumSTATDATA
**ppenumAdvise
)
426 ICOM_THIS(IDataObjectImpl
,iface
);
427 FIXME("(%p)->()\n", This
);
431 static struct ICOM_VTABLE(IDataObject
) dtovt
=
433 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
434 IDataObject_fnQueryInterface
,
435 IDataObject_fnAddRef
,
436 IDataObject_fnRelease
,
437 IDataObject_fnGetData
,
438 IDataObject_fnGetDataHere
,
439 IDataObject_fnQueryGetData
,
440 IDataObject_fnGetCanonicalFormatEtc
,
441 IDataObject_fnSetData
,
442 IDataObject_fnEnumFormatEtc
,
443 IDataObject_fnDAdvise
,
444 IDataObject_fnDUnadvise
,
445 IDataObject_fnEnumDAdvise