msxml3: Stub domdoc_get_readyState().
[wine/multimedia.git] / dlls / shell32 / dataobject.c
blobf949fe022ae206f87092f41b93bbd295345ab4f2
1 /*
2 * IEnumFORMATETC, IDataObject
4 * selecting and dropping 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <string.h>
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "wingdi.h"
30 #include "pidl.h"
31 #include "winerror.h"
32 #include "shell32_main.h"
33 #include "wine/debug.h"
34 #include "undocshell.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shell);
38 /***********************************************************************
39 * IEnumFORMATETC implementation
42 typedef struct
44 /* IUnknown fields */
45 const IEnumFORMATETCVtbl *lpVtbl;
46 LONG ref;
47 /* IEnumFORMATETC fields */
48 UINT posFmt;
49 UINT countFmt;
50 LPFORMATETC pFmt;
51 } IEnumFORMATETCImpl;
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);
59 *ppvObj = NULL;
61 if(IsEqualIID(riid, &IID_IUnknown))
63 *ppvObj = This;
65 else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
67 *ppvObj = This;
70 if(*ppvObj)
72 IUnknown_AddRef((IUnknown*)(*ppvObj));
73 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
74 return S_OK;
76 TRACE("-- Interface: E_NOINTERFACE\n");
77 return E_NOINTERFACE;
80 static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
82 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
83 ULONG refCount = InterlockedIncrement(&This->ref);
85 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
87 return refCount;
90 static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
92 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
93 ULONG refCount = InterlockedDecrement(&This->ref);
95 TRACE("(%p)->(%u)\n", This, refCount + 1);
97 if (!refCount)
99 TRACE(" destroying IEnumFORMATETC(%p)\n",This);
100 SHFree (This->pFmt);
101 HeapFree(GetProcessHeap(),0,This);
102 return 0;
104 return refCount;
107 static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
109 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
110 UINT i;
112 TRACE("(%p)->(%u,%p)\n", This, celt, rgelt);
114 if(!This->pFmt)return S_FALSE;
115 if(!rgelt) return E_INVALIDARG;
116 if (pceltFethed) *pceltFethed = 0;
118 for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
120 *rgelt++ = This->pFmt[This->posFmt++];
123 if (pceltFethed) *pceltFethed = i;
125 return ((i == celt) ? S_OK : S_FALSE);
128 static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
130 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
131 TRACE("(%p)->(num=%u)\n", This, celt);
133 if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
134 This->posFmt += celt;
135 return S_OK;
138 static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
140 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
141 TRACE("(%p)->()\n", This);
143 This->posFmt = 0;
144 return S_OK;
147 static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
149 IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
150 TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
152 if (!ppenum) return E_INVALIDARG;
153 *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
154 if(*ppenum)
155 IEnumFORMATETC_fnSkip(*ppenum, This->posFmt);
156 return S_OK;
159 static const IEnumFORMATETCVtbl efvt =
161 IEnumFORMATETC_fnQueryInterface,
162 IEnumFORMATETC_fnAddRef,
163 IEnumFORMATETC_fnRelease,
164 IEnumFORMATETC_fnNext,
165 IEnumFORMATETC_fnSkip,
166 IEnumFORMATETC_fnReset,
167 IEnumFORMATETC_fnClone
170 LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
172 IEnumFORMATETCImpl* ef;
173 DWORD size=cfmt * sizeof(FORMATETC);
175 ef = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
177 if(ef)
179 ef->ref=1;
180 ef->lpVtbl=&efvt;
182 ef->countFmt = cfmt;
183 ef->pFmt = SHAlloc (size);
185 if (ef->pFmt)
186 memcpy(ef->pFmt, afmt, size);
189 TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
190 return (LPENUMFORMATETC)ef;
194 /***********************************************************************
195 * IDataObject implementation
198 /* number of supported formats */
199 #define MAX_FORMATS 4
201 typedef struct
203 /* IUnknown fields */
204 const IDataObjectVtbl *lpVtbl;
205 LONG ref;
207 /* IDataObject fields */
208 LPITEMIDLIST pidl;
209 LPITEMIDLIST * apidl;
210 UINT cidl;
212 FORMATETC pFormatEtc[MAX_FORMATS];
213 UINT cfShellIDList;
214 UINT cfFileNameA;
215 UINT cfFileNameW;
217 } IDataObjectImpl;
219 /***************************************************************************
220 * IDataObject_QueryInterface
222 static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID * ppvObj)
224 IDataObjectImpl *This = (IDataObjectImpl *)iface;
225 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
227 *ppvObj = NULL;
229 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
231 *ppvObj = This;
233 else if(IsEqualIID(riid, &IID_IDataObject)) /*IDataObject*/
235 *ppvObj = This;
238 if(*ppvObj)
240 IUnknown_AddRef((IUnknown*)*ppvObj);
241 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
242 return S_OK;
244 TRACE("-- Interface: E_NOINTERFACE\n");
245 return E_NOINTERFACE;
248 /**************************************************************************
249 * IDataObject_AddRef
251 static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface)
253 IDataObjectImpl *This = (IDataObjectImpl *)iface;
254 ULONG refCount = InterlockedIncrement(&This->ref);
256 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
258 return refCount;
261 /**************************************************************************
262 * IDataObject_Release
264 static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface)
266 IDataObjectImpl *This = (IDataObjectImpl *)iface;
267 ULONG refCount = InterlockedDecrement(&This->ref);
269 TRACE("(%p)->(%u)\n", This, refCount + 1);
271 if (!refCount)
273 TRACE(" destroying IDataObject(%p)\n",This);
274 _ILFreeaPidl(This->apidl, This->cidl);
275 ILFree(This->pidl),
276 HeapFree(GetProcessHeap(),0,This);
278 return refCount;
281 /**************************************************************************
282 * IDataObject_fnGetData
284 static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
286 IDataObjectImpl *This = (IDataObjectImpl *)iface;
288 char szTemp[256];
290 szTemp[0]=0;
291 GetClipboardFormatNameA (pformatetcIn->cfFormat, szTemp, 256);
292 TRACE("(%p)->(%p %p format=%s)\n", This, pformatetcIn, pmedium, szTemp);
294 if (pformatetcIn->cfFormat == This->cfShellIDList)
296 if (This->cidl < 1) return(E_UNEXPECTED);
297 pmedium->u.hGlobal = RenderSHELLIDLIST(This->pidl, This->apidl, This->cidl);
299 else if (pformatetcIn->cfFormat == CF_HDROP)
301 if (This->cidl < 1) return(E_UNEXPECTED);
302 pmedium->u.hGlobal = RenderHDROP(This->pidl, This->apidl, This->cidl);
304 else if (pformatetcIn->cfFormat == This->cfFileNameA)
306 if (This->cidl < 1) return(E_UNEXPECTED);
307 pmedium->u.hGlobal = RenderFILENAMEA(This->pidl, This->apidl, This->cidl);
309 else if (pformatetcIn->cfFormat == This->cfFileNameW)
311 if (This->cidl < 1) return(E_UNEXPECTED);
312 pmedium->u.hGlobal = RenderFILENAMEW(This->pidl, This->apidl, This->cidl);
314 else
316 FIXME("-- expected clipformat not implemented\n");
317 return (E_INVALIDARG);
319 if (pmedium->u.hGlobal)
321 pmedium->tymed = TYMED_HGLOBAL;
322 pmedium->pUnkForRelease = NULL;
323 return S_OK;
325 return E_OUTOFMEMORY;
328 static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
330 IDataObjectImpl *This = (IDataObjectImpl *)iface;
331 FIXME("(%p)->()\n", This);
332 return E_NOTIMPL;
335 static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc)
337 IDataObjectImpl *This = (IDataObjectImpl *)iface;
338 UINT i;
340 TRACE("(%p)->(fmt=0x%08x tym=0x%08x)\n", This, pformatetc->cfFormat, pformatetc->tymed);
342 if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
343 return DV_E_DVASPECT;
345 /* check our formats table what we have */
346 for (i=0; i<MAX_FORMATS; i++)
348 if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
349 && (This->pFormatEtc[i].tymed == pformatetc->tymed))
351 return S_OK;
355 return DV_E_TYMED;
358 static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
360 IDataObjectImpl *This = (IDataObjectImpl *)iface;
361 FIXME("(%p)->()\n", This);
362 return E_NOTIMPL;
365 static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
367 IDataObjectImpl *This = (IDataObjectImpl *)iface;
368 FIXME("(%p)->()\n", This);
369 return E_NOTIMPL;
372 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
374 IDataObjectImpl *This = (IDataObjectImpl *)iface;
376 TRACE("(%p)->()\n", This);
377 *ppenumFormatEtc=NULL;
379 /* only get data */
380 if (DATADIR_GET == dwDirection)
382 *ppenumFormatEtc = IEnumFORMATETC_Constructor(MAX_FORMATS, This->pFormatEtc);
383 return (*ppenumFormatEtc) ? S_OK : E_FAIL;
386 return E_NOTIMPL;
389 static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
391 IDataObjectImpl *This = (IDataObjectImpl *)iface;
392 FIXME("(%p)->()\n", This);
393 return E_NOTIMPL;
395 static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection)
397 IDataObjectImpl *This = (IDataObjectImpl *)iface;
398 FIXME("(%p)->()\n", This);
399 return E_NOTIMPL;
401 static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise)
403 IDataObjectImpl *This = (IDataObjectImpl *)iface;
404 FIXME("(%p)->()\n", This);
405 return E_NOTIMPL;
408 static const IDataObjectVtbl dtovt =
410 IDataObject_fnQueryInterface,
411 IDataObject_fnAddRef,
412 IDataObject_fnRelease,
413 IDataObject_fnGetData,
414 IDataObject_fnGetDataHere,
415 IDataObject_fnQueryGetData,
416 IDataObject_fnGetCanonicalFormatEtc,
417 IDataObject_fnSetData,
418 IDataObject_fnEnumFormatEtc,
419 IDataObject_fnDAdvise,
420 IDataObject_fnDUnadvise,
421 IDataObject_fnEnumDAdvise
424 /**************************************************************************
425 * IDataObject_Constructor
427 LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner,
428 LPCITEMIDLIST pMyPidl, LPCITEMIDLIST * apidl, UINT cidl)
430 IDataObjectImpl* dto;
432 dto = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDataObjectImpl));
434 if (dto)
436 dto->ref = 1;
437 dto->lpVtbl = &dtovt;
438 dto->pidl = ILClone(pMyPidl);
439 dto->apidl = _ILCopyaPidl(apidl, cidl);
440 dto->cidl = cidl;
442 dto->cfShellIDList = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
443 dto->cfFileNameA = RegisterClipboardFormatA(CFSTR_FILENAMEA);
444 dto->cfFileNameW = RegisterClipboardFormatW(CFSTR_FILENAMEW);
445 InitFormatEtc(dto->pFormatEtc[0], dto->cfShellIDList, TYMED_HGLOBAL);
446 InitFormatEtc(dto->pFormatEtc[1], CF_HDROP, TYMED_HGLOBAL);
447 InitFormatEtc(dto->pFormatEtc[2], dto->cfFileNameA, TYMED_HGLOBAL);
448 InitFormatEtc(dto->pFormatEtc[3], dto->cfFileNameW, TYMED_HGLOBAL);
451 TRACE("(%p)->(apidl=%p cidl=%u)\n",dto, apidl, cidl);
452 return (LPDATAOBJECT)dto;