2 * IEnumFORMATETC, IDataObject
4 * selecting and droping objects within the shell and/or common dialogs
6 * Copyright 1998 <juergen.schmied@metronet.de>
10 #include "wine/obj_dataobject.h"
13 #include "shell32_main.h"
17 UINT cfFileGroupDesc=0;
18 UINT cfFileContents=0;
20 /***********************************************************************
21 * IEnumFORMATETC implementation
26 ICOM_VTABLE(IEnumFORMATETC)* lpvtbl;
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 IEnumFORMATETC_fnQueryInterface,
45 IEnumFORMATETC_fnAddRef,
46 IEnumFORMATETC_fnRelease,
47 IEnumFORMATETC_fnNext,
48 IEnumFORMATETC_fnSkip,
49 IEnumFORMATETC_fnReset,
50 IEnumFORMATETC_fnClone
53 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
55 IEnumFORMATETCImpl* ef;
56 DWORD size=cfmt * sizeof(FORMATETC);
58 ef=(IEnumFORMATETCImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IEnumFORMATETCImpl));
64 ef->pFmt = SHAlloc (size);
67 { memcpy(ef->pFmt, afmt, size);
70 TRACE(shell,"(%p)->()\n",ef);
72 return (LPENUMFORMATETC)ef;
74 static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
76 ICOM_THIS(IEnumFORMATETCImpl,iface);
78 WINE_StringFromCLSID((LPCLSID)riid,xriid);
79 TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
83 if(IsEqualIID(riid, &IID_IUnknown))
86 else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
87 { *ppvObj = (IDataObject*)This;
91 { IEnumFORMATETC_AddRef((IEnumFORMATETC*)*ppvObj);
92 TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
95 TRACE(shell,"-- Interface: E_NOINTERFACE\n");
99 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
101 ICOM_THIS(IEnumFORMATETCImpl,iface);
102 TRACE(shell,"(%p)->(count=%lu)\n",This,(This->ref)+1);
104 return ++(This->ref);
106 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
108 ICOM_THIS(IEnumFORMATETCImpl,iface);
109 TRACE(shell,"(%p)->()\n",This);
114 { TRACE(shell," destroying IEnumFORMATETC(%p)\n",This);
116 { SHFree (This->pFmt);
118 HeapFree(GetProcessHeap(),0,This);
123 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
125 ICOM_THIS(IEnumFORMATETCImpl,iface);
127 HRESULT hres = S_FALSE;
129 TRACE (shell, "(%p)->()\n", This);
131 if (This->posFmt < This->countFmt)
132 { cfetch = This->countFmt - This->posFmt;
137 memcpy(rgelt, &This->pFmt[This->posFmt], cfetch * sizeof(FORMATETC));
138 This->posFmt += cfetch;
145 { *pceltFethed = cfetch;
150 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
152 ICOM_THIS(IEnumFORMATETCImpl,iface);
153 FIXME (shell, "(%p)->(num=%lu)\n", This, celt);
155 This->posFmt += celt;
156 if (This->posFmt > This->countFmt)
157 { This->posFmt = This->countFmt;
162 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
164 ICOM_THIS(IEnumFORMATETCImpl,iface);
165 FIXME (shell, "(%p)->()\n", This);
170 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
172 ICOM_THIS(IEnumFORMATETCImpl,iface);
173 FIXME (shell, "(%p)->(ppenum=%p)\n", This, ppenum);
177 /***********************************************************************
178 * IDataObject implementation
182 /* IUnknown fields */
183 ICOM_VTABLE(IDataObject)* lpvtbl;
185 /* IDataObject fields */
187 LPIDLLIST lpill; /* the data of the dataobject */
191 static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID* ppvObj);
192 static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface);
193 static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface);
194 static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM* pmedium);
195 static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM* pmedium);
196 static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc);
197 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut);
198 static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM* pmedium, BOOL fRelease);
199 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc);
200 static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, LPFORMATETC* pformatetc, DWORD advf, IAdviseSink* pAdvSink, DWORD* pdwConnection);
201 static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection);
202 static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise);
204 static struct ICOM_VTABLE(IDataObject) dtovt =
206 IDataObject_fnQueryInterface,
207 IDataObject_fnAddRef,
208 IDataObject_fnRelease,
209 IDataObject_fnGetData,
210 IDataObject_fnGetDataHere,
211 IDataObject_fnQueryGetData,
212 IDataObject_fnGetCanonicalFormatEtc,
213 IDataObject_fnSetData,
214 IDataObject_fnEnumFormatEtc,
215 IDataObject_fnDAdvise,
216 IDataObject_fnDUnadvise,
217 IDataObject_fnEnumDAdvise
220 /**************************************************************************
221 * IDataObject_Constructor
223 LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner, LPSHELLFOLDER psf, LPITEMIDLIST * apidl, UINT cidl)
225 IDataObjectImpl* dto;
226 if (!(dto = (IDataObjectImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDataObjectImpl))))
232 dto->pidl=ILClone(psf->mpidl); /* FIXME:add a reference and don't copy*/
234 /* fill the ItemID List List */
235 dto->lpill = IDLList_Constructor (8);
239 dto->lpill->lpvtbl->fnAddItems(dto->lpill, apidl, cidl);
241 TRACE(shell,"(%p)->(sf=%p apidl=%p cidl=%u)\n",dto, psf, apidl, cidl);
243 return (LPDATAOBJECT)dto;
245 /***************************************************************************
246 * IDataObject_QueryInterface
248 static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID * ppvObj)
250 ICOM_THIS(IDataObjectImpl,iface);
252 WINE_StringFromCLSID((LPCLSID)riid,xriid);
253 TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
257 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
260 else if(IsEqualIID(riid, &IID_IDataObject)) /*IDataObject*/
261 { *ppvObj = (IDataObject*)This;
265 { IDataObject_AddRef((IDataObject*)*ppvObj);
266 TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
269 TRACE(shell,"-- Interface: E_NOINTERFACE\n");
270 return E_NOINTERFACE;
272 /**************************************************************************
275 static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface)
277 ICOM_THIS(IDataObjectImpl,iface);
279 TRACE(shell,"(%p)->(count=%lu)\n",This,(This->ref)+1);
282 return ++(This->ref);
284 /**************************************************************************
285 * IDataObject_Release
287 static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface)
289 ICOM_THIS(IDataObjectImpl,iface);
290 TRACE(shell,"(%p)->()\n",This);
295 { TRACE(shell," destroying IDataObject(%p)\n",This);
296 IDLList_Destructor(This->lpill);
297 HeapFree(GetProcessHeap(),0,This);
302 /**************************************************************************
303 * DATAOBJECT_InitShellIDList (internal)
306 * get or register the "Shell IDList Array" clipformat
308 static BOOL DATAOBJECT_InitShellIDList(void)
313 cfShellIDList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
314 return(cfShellIDList != 0);
317 /**************************************************************************
318 * DATAOBJECT_InitFileGroupDesc (internal)
321 * get or register the "FileGroupDescriptor" clipformat
323 /* FIXME: DATAOBJECT_InitFileGroupDesc is not used (19981226)
324 static BOOL32 DATAOBJECT_InitFileGroupDesc(void)
325 { if (cfFileGroupDesc)
329 cfFileGroupDesc = RegisterClipboardFormat32A(CFSTR_FILEDESCRIPTORA);
330 return(cfFileGroupDesc != 0);
333 /**************************************************************************
334 * DATAOBJECT_InitFileContents (internal)
337 * get or register the "FileContents" clipformat
339 /* FIXME: DATAOBJECT_InitFileContents is not used (19981226)
340 static BOOL32 DATAOBJECT_InitFileContents(void)
341 { if (cfFileContents)
345 cfFileContents = RegisterClipboardFormat32A(CFSTR_FILECONTENTS);
346 return(cfFileContents != 0);
350 /**************************************************************************
351 * interface implementation
353 static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
355 ICOM_THIS(IDataObjectImpl,iface);
358 DWORD size, size1, size2;
363 GetClipboardFormatNameA (pformatetcIn->cfFormat, temp, 256);
364 WARN (shell, "(%p)->(%p %p format=%s)semi-stub\n", This, pformatetcIn, pmedium, temp);
366 if (!DATAOBJECT_InitShellIDList()) /* is the clipformat registred? */
367 { return(E_UNEXPECTED);
370 if (pformatetcIn->cfFormat == cfShellIDList)
371 { if (pformatetcIn->ptd==NULL
372 && (pformatetcIn->dwAspect & DVASPECT_CONTENT)
373 && pformatetcIn->lindex==-1
374 && (pformatetcIn->tymed&TYMED_HGLOBAL))
375 { cItems = This->lpill->lpvtbl->fnGetCount(This->lpill);
377 { return(E_UNEXPECTED);
379 pidl = This->lpill->lpvtbl->fnGetElement(This->lpill, 0);
384 /*hack consider only the first item*/
386 size = sizeof(CIDA) + sizeof (UINT)*(cItems-1);
387 size1 = ILGetSize (This->pidl);
388 size2 = ILGetSize (pidl);
389 hmem = GlobalAlloc(GMEM_FIXED, size+size1+size2);
390 pcida = GlobalLock (hmem);
392 { return(E_OUTOFMEMORY);
396 pcida->aoffset[0] = size;
397 pcida->aoffset[1] = size+size1;
399 TRACE(shell,"-- %lu %lu %lu\n",size, size1, size2 );
400 TRACE(shell,"-- %p %p\n",This->pidl, pidl);
401 TRACE(shell,"-- %p %p %p\n",pcida, (LPBYTE)pcida+size,(LPBYTE)pcida+size+size1);
403 memcpy ((LPBYTE)pcida+size, This->pidl, size1);
404 memcpy ((LPBYTE)pcida+size+size1, pidl, size2);
405 TRACE(shell,"-- after copy\n");
409 pmedium->tymed = TYMED_HGLOBAL;
410 pmedium->u.hGlobal = (HGLOBAL)pcida;
411 pmedium->pUnkForRelease = NULL;
412 TRACE(shell,"-- ready\n");
416 FIXME (shell, "-- clipformat not implemented\n");
417 return (E_INVALIDARG);
419 static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
421 ICOM_THIS(IDataObjectImpl,iface);
422 FIXME (shell, "(%p)->()\n", This);
425 static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc)
427 ICOM_THIS(IDataObjectImpl,iface);
428 FIXME (shell, "(%p)->()\n", This);
431 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
433 ICOM_THIS(IDataObjectImpl,iface);
434 FIXME (shell, "(%p)->()\n", This);
437 static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
439 ICOM_THIS(IDataObjectImpl,iface);
440 FIXME (shell, "(%p)->()\n", This);
443 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
445 ICOM_THIS(IDataObjectImpl,iface);
446 FIXME (shell, "(%p)->()\n", This);
449 static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, LPFORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
451 ICOM_THIS(IDataObjectImpl,iface);
452 FIXME (shell, "(%p)->()\n", This);
455 static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection)
457 ICOM_THIS(IDataObjectImpl,iface);
458 FIXME (shell, "(%p)->()\n", This);
461 static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise)
463 ICOM_THIS(IDataObjectImpl,iface);
464 FIXME (shell, "(%p)->()\n", This);