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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
32 #include "shell32_main.h"
33 #include "wine/debug.h"
34 #include "undocshell.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
38 /***********************************************************************
39 * IEnumFORMATETC implementation
45 const IEnumFORMATETCVtbl
*lpVtbl
;
47 /* IEnumFORMATETC fields */
53 static HRESULT WINAPI
IEnumFORMATETC_fnQueryInterface(
54 LPENUMFORMATETC iface
, REFIID riid
, LPVOID
* ppvObj
)
56 IEnumFORMATETCImpl
*This
= (IEnumFORMATETCImpl
*)iface
;
57 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
61 if(IsEqualIID(riid
, &IID_IUnknown
))
65 else if(IsEqualIID(riid
, &IID_IEnumFORMATETC
))
67 *ppvObj
= (IEnumFORMATETC
*)This
;
72 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
73 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
76 TRACE("-- Interface: E_NOINTERFACE\n");
80 static ULONG WINAPI
IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface
)
82 IEnumFORMATETCImpl
*This
= (IEnumFORMATETCImpl
*)iface
;
83 ULONG refCount
= InterlockedIncrement(&This
->ref
);
85 TRACE("(%p)->(count=%lu)\n", This
, refCount
- 1);
90 static ULONG WINAPI
IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface
)
92 IEnumFORMATETCImpl
*This
= (IEnumFORMATETCImpl
*)iface
;
93 ULONG refCount
= InterlockedDecrement(&This
->ref
);
95 TRACE("(%p)->(%lu)\n", This
, refCount
+ 1);
99 TRACE(" destroying IEnumFORMATETC(%p)\n",This
);
104 HeapFree(GetProcessHeap(),0,This
);
110 static HRESULT WINAPI
IEnumFORMATETC_fnNext(LPENUMFORMATETC iface
, ULONG celt
, FORMATETC
*rgelt
, ULONG
*pceltFethed
)
112 IEnumFORMATETCImpl
*This
= (IEnumFORMATETCImpl
*)iface
;
115 TRACE("(%p)->(%lu,%p)\n", This
, celt
, rgelt
);
117 if(!This
->pFmt
)return S_FALSE
;
118 if(!rgelt
) return E_INVALIDARG
;
119 if (pceltFethed
) *pceltFethed
= 0;
121 for(i
= 0; This
->posFmt
< This
->countFmt
&& celt
> i
; i
++)
123 *rgelt
++ = This
->pFmt
[This
->posFmt
++];
126 if (pceltFethed
) *pceltFethed
= i
;
128 return ((i
== celt
) ? S_OK
: S_FALSE
);
131 static HRESULT WINAPI
IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface
, ULONG celt
)
133 IEnumFORMATETCImpl
*This
= (IEnumFORMATETCImpl
*)iface
;
134 TRACE("(%p)->(num=%lu)\n", This
, celt
);
136 if((This
->posFmt
+ celt
) >= This
->countFmt
) return S_FALSE
;
137 This
->posFmt
+= celt
;
141 static HRESULT WINAPI
IEnumFORMATETC_fnReset(LPENUMFORMATETC iface
)
143 IEnumFORMATETCImpl
*This
= (IEnumFORMATETCImpl
*)iface
;
144 TRACE("(%p)->()\n", This
);
150 static HRESULT WINAPI
IEnumFORMATETC_fnClone(LPENUMFORMATETC iface
, LPENUMFORMATETC
* ppenum
)
152 IEnumFORMATETCImpl
*This
= (IEnumFORMATETCImpl
*)iface
;
153 TRACE("(%p)->(ppenum=%p)\n", This
, ppenum
);
155 if (!ppenum
) return E_INVALIDARG
;
156 *ppenum
= IEnumFORMATETC_Constructor(This
->countFmt
, This
->pFmt
);
158 IEnumFORMATETC_fnSkip(*ppenum
, This
->posFmt
);
162 static const IEnumFORMATETCVtbl efvt
=
164 IEnumFORMATETC_fnQueryInterface
,
165 IEnumFORMATETC_fnAddRef
,
166 IEnumFORMATETC_fnRelease
,
167 IEnumFORMATETC_fnNext
,
168 IEnumFORMATETC_fnSkip
,
169 IEnumFORMATETC_fnReset
,
170 IEnumFORMATETC_fnClone
173 LPENUMFORMATETC
IEnumFORMATETC_Constructor(UINT cfmt
, const FORMATETC afmt
[])
175 IEnumFORMATETCImpl
* ef
;
176 DWORD size
=cfmt
* sizeof(FORMATETC
);
178 ef
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumFORMATETCImpl
));
186 ef
->pFmt
= SHAlloc (size
);
189 memcpy(ef
->pFmt
, afmt
, size
);
192 TRACE("(%p)->(%u,%p)\n",ef
, cfmt
, afmt
);
193 return (LPENUMFORMATETC
)ef
;
197 /***********************************************************************
198 * IDataObject implementation
201 /* number of supported formats */
202 #define MAX_FORMATS 4
206 /* IUnknown fields */
207 const IDataObjectVtbl
*lpVtbl
;
210 /* IDataObject fields */
212 LPITEMIDLIST
* apidl
;
215 FORMATETC pFormatEtc
[MAX_FORMATS
];
222 /***************************************************************************
223 * IDataObject_QueryInterface
225 static HRESULT WINAPI
IDataObject_fnQueryInterface(LPDATAOBJECT iface
, REFIID riid
, LPVOID
* ppvObj
)
227 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
228 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
232 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
236 else if(IsEqualIID(riid
, &IID_IDataObject
)) /*IDataObject*/
238 *ppvObj
= (IDataObject
*)This
;
243 IUnknown_AddRef((IUnknown
*)*ppvObj
);
244 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
247 TRACE("-- Interface: E_NOINTERFACE\n");
248 return E_NOINTERFACE
;
251 /**************************************************************************
254 static ULONG WINAPI
IDataObject_fnAddRef(LPDATAOBJECT iface
)
256 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
257 ULONG refCount
= InterlockedIncrement(&This
->ref
);
259 TRACE("(%p)->(count=%lu)\n", This
, refCount
- 1);
264 /**************************************************************************
265 * IDataObject_Release
267 static ULONG WINAPI
IDataObject_fnRelease(LPDATAOBJECT iface
)
269 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
270 ULONG refCount
= InterlockedDecrement(&This
->ref
);
272 TRACE("(%p)->(%lu)\n", This
, refCount
+ 1);
276 TRACE(" destroying IDataObject(%p)\n",This
);
277 _ILFreeaPidl(This
->apidl
, This
->cidl
);
279 HeapFree(GetProcessHeap(),0,This
);
284 /**************************************************************************
285 * IDataObject_fnGetData
287 static HRESULT WINAPI
IDataObject_fnGetData(LPDATAOBJECT iface
, LPFORMATETC pformatetcIn
, STGMEDIUM
*pmedium
)
289 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
294 GetClipboardFormatNameA (pformatetcIn
->cfFormat
, szTemp
, 256);
295 TRACE("(%p)->(%p %p format=%s)\n", This
, pformatetcIn
, pmedium
, szTemp
);
297 if (pformatetcIn
->cfFormat
== This
->cfShellIDList
)
299 if (This
->cidl
< 1) return(E_UNEXPECTED
);
300 pmedium
->u
.hGlobal
= RenderSHELLIDLIST(This
->pidl
, This
->apidl
, This
->cidl
);
302 else if (pformatetcIn
->cfFormat
== CF_HDROP
)
304 if (This
->cidl
< 1) return(E_UNEXPECTED
);
305 pmedium
->u
.hGlobal
= RenderHDROP(This
->pidl
, This
->apidl
, This
->cidl
);
307 else if (pformatetcIn
->cfFormat
== This
->cfFileNameA
)
309 if (This
->cidl
< 1) return(E_UNEXPECTED
);
310 pmedium
->u
.hGlobal
= RenderFILENAMEA(This
->pidl
, This
->apidl
, This
->cidl
);
312 else if (pformatetcIn
->cfFormat
== This
->cfFileNameW
)
314 if (This
->cidl
< 1) return(E_UNEXPECTED
);
315 pmedium
->u
.hGlobal
= RenderFILENAMEW(This
->pidl
, This
->apidl
, This
->cidl
);
319 FIXME("-- expected clipformat not implemented\n");
320 return (E_INVALIDARG
);
322 if (pmedium
->u
.hGlobal
)
324 pmedium
->tymed
= TYMED_HGLOBAL
;
325 pmedium
->pUnkForRelease
= NULL
;
328 return E_OUTOFMEMORY
;
331 static HRESULT WINAPI
IDataObject_fnGetDataHere(LPDATAOBJECT iface
, LPFORMATETC pformatetc
, STGMEDIUM
*pmedium
)
333 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
334 FIXME("(%p)->()\n", This
);
338 static HRESULT WINAPI
IDataObject_fnQueryGetData(LPDATAOBJECT iface
, LPFORMATETC pformatetc
)
340 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
343 TRACE("(%p)->(fmt=0x%08x tym=0x%08lx)\n", This
, pformatetc
->cfFormat
, pformatetc
->tymed
);
345 if(!(DVASPECT_CONTENT
& pformatetc
->dwAspect
))
346 return DV_E_DVASPECT
;
348 /* check our formats table what we have */
349 for (i
=0; i
<MAX_FORMATS
; i
++)
351 if ((This
->pFormatEtc
[i
].cfFormat
== pformatetc
->cfFormat
)
352 && (This
->pFormatEtc
[i
].tymed
== pformatetc
->tymed
))
361 static HRESULT WINAPI
IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface
, LPFORMATETC pformatectIn
, LPFORMATETC pformatetcOut
)
363 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
364 FIXME("(%p)->()\n", This
);
368 static HRESULT WINAPI
IDataObject_fnSetData(LPDATAOBJECT iface
, LPFORMATETC pformatetc
, STGMEDIUM
*pmedium
, BOOL fRelease
)
370 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
371 FIXME("(%p)->()\n", This
);
375 static HRESULT WINAPI
IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface
, DWORD dwDirection
, IEnumFORMATETC
**ppenumFormatEtc
)
377 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
379 TRACE("(%p)->()\n", This
);
380 *ppenumFormatEtc
=NULL
;
383 if (DATADIR_GET
== dwDirection
)
385 *ppenumFormatEtc
= IEnumFORMATETC_Constructor(MAX_FORMATS
, This
->pFormatEtc
);
386 return (*ppenumFormatEtc
) ? S_OK
: E_FAIL
;
392 static HRESULT WINAPI
IDataObject_fnDAdvise(LPDATAOBJECT iface
, FORMATETC
*pformatetc
, DWORD advf
, IAdviseSink
*pAdvSink
, DWORD
*pdwConnection
)
394 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
395 FIXME("(%p)->()\n", This
);
398 static HRESULT WINAPI
IDataObject_fnDUnadvise(LPDATAOBJECT iface
, DWORD dwConnection
)
400 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
401 FIXME("(%p)->()\n", This
);
404 static HRESULT WINAPI
IDataObject_fnEnumDAdvise(LPDATAOBJECT iface
, IEnumSTATDATA
**ppenumAdvise
)
406 IDataObjectImpl
*This
= (IDataObjectImpl
*)iface
;
407 FIXME("(%p)->()\n", This
);
411 static const IDataObjectVtbl dtovt
=
413 IDataObject_fnQueryInterface
,
414 IDataObject_fnAddRef
,
415 IDataObject_fnRelease
,
416 IDataObject_fnGetData
,
417 IDataObject_fnGetDataHere
,
418 IDataObject_fnQueryGetData
,
419 IDataObject_fnGetCanonicalFormatEtc
,
420 IDataObject_fnSetData
,
421 IDataObject_fnEnumFormatEtc
,
422 IDataObject_fnDAdvise
,
423 IDataObject_fnDUnadvise
,
424 IDataObject_fnEnumDAdvise
427 /**************************************************************************
428 * IDataObject_Constructor
430 LPDATAOBJECT
IDataObject_Constructor(HWND hwndOwner
,
431 LPCITEMIDLIST pMyPidl
, LPCITEMIDLIST
* apidl
, UINT cidl
)
433 IDataObjectImpl
* dto
;
435 dto
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDataObjectImpl
));
440 dto
->lpVtbl
= &dtovt
;
441 dto
->pidl
= ILClone(pMyPidl
);
442 dto
->apidl
= _ILCopyaPidl(apidl
, cidl
);
445 dto
->cfShellIDList
= RegisterClipboardFormatA(CFSTR_SHELLIDLIST
);
446 dto
->cfFileNameA
= RegisterClipboardFormatA(CFSTR_FILENAMEA
);
447 dto
->cfFileNameW
= RegisterClipboardFormatA(CFSTR_FILENAMEW
);
448 InitFormatEtc(dto
->pFormatEtc
[0], dto
->cfShellIDList
, TYMED_HGLOBAL
);
449 InitFormatEtc(dto
->pFormatEtc
[1], CF_HDROP
, TYMED_HGLOBAL
);
450 InitFormatEtc(dto
->pFormatEtc
[2], dto
->cfFileNameA
, TYMED_HGLOBAL
);
451 InitFormatEtc(dto
->pFormatEtc
[3], dto
->cfFileNameW
, TYMED_HGLOBAL
);
454 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto
, apidl
, cidl
);
455 return (LPDATAOBJECT
)dto
;