2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "urlmon_main.h"
20 #include "wine/debug.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
24 static WCHAR wszEnumFORMATETC[] = {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
27 const IEnumFORMATETCVtbl *lpEnumFORMATETCVtbl;
36 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it);
38 #define ENUMF_THIS(iface) ICOM_THIS_MULTI(EnumFORMATETC, lpEnumFORMATETCVtbl, iface)
40 static HRESULT WINAPI EnumFORMATETC_QueryInterface(IEnumFORMATETC *iface, REFIID riid, void **ppv)
42 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
46 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IEnumFORMATETC, riid)) {
47 IEnumFORMATETC_AddRef(iface);
52 WARN("not supported interface %s\n", debugstr_guid(riid));
56 static ULONG WINAPI EnumFORMATETC_AddRef(IEnumFORMATETC *iface)
59 LONG ref = InterlockedIncrement(&This->ref);
60 TRACE("(%p) ref=%d\n", This, ref);
64 static ULONG WINAPI EnumFORMATETC_Release(IEnumFORMATETC *iface)
67 LONG ref = InterlockedDecrement(&This->ref);
69 TRACE("(%p) ref=%d\n", This, ref);
72 heap_free(This->fetc);
75 URLMON_UnlockModule();
81 static HRESULT WINAPI EnumFORMATETC_Next(IEnumFORMATETC *iface, ULONG celt,
82 FORMATETC *rgelt, ULONG *pceltFetched)
87 TRACE("(%p)->(%d %p %p)\n", This, celt, rgelt, pceltFetched);
92 if(This->it >= This->fetc_cnt || !celt) {
95 return celt ? S_FALSE : S_OK;
98 cnt = This->fetc_cnt-This->it > celt ? celt : This->fetc_cnt-This->it;
100 memcpy(rgelt, This->fetc+This->it, cnt*sizeof(FORMATETC));
106 return cnt == celt ? S_OK : S_FALSE;
109 static HRESULT WINAPI EnumFORMATETC_Skip(IEnumFORMATETC *iface, ULONG celt)
113 TRACE("(%p)->(%d)\n", This, celt);
116 return This->it > This->fetc_cnt ? S_FALSE : S_OK;
119 static HRESULT WINAPI EnumFORMATETC_Reset(IEnumFORMATETC *iface)
123 TRACE("(%p)\n", This);
129 static HRESULT WINAPI EnumFORMATETC_Clone(IEnumFORMATETC *iface, IEnumFORMATETC **ppenum)
133 TRACE("(%p)->(%p)\n", This, ppenum);
138 *ppenum = EnumFORMATETC_Create(This->fetc_cnt, This->fetc, This->it);
142 static const IEnumFORMATETCVtbl EnumFORMATETCVtbl = {
143 EnumFORMATETC_QueryInterface,
144 EnumFORMATETC_AddRef,
145 EnumFORMATETC_Release,
152 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it)
154 EnumFORMATETC *ret = heap_alloc(sizeof(EnumFORMATETC));
158 ret->lpEnumFORMATETCVtbl = &EnumFORMATETCVtbl;
161 ret->fetc_cnt = cfmtetc;
163 ret->fetc = heap_alloc(cfmtetc*sizeof(FORMATETC));
164 memcpy(ret->fetc, rgfmtetc, cfmtetc*sizeof(FORMATETC));
166 return (IEnumFORMATETC*)ret;
169 /**********************************************************
170 * CreateFormatEnumerator (urlmon.@)
172 HRESULT WINAPI CreateFormatEnumerator(UINT cfmtetc, FORMATETC *rgfmtetc,
173 IEnumFORMATETC** ppenumfmtetc)
175 TRACE("(%d %p %p)\n", cfmtetc, rgfmtetc, ppenumfmtetc);
182 *ppenumfmtetc = EnumFORMATETC_Create(cfmtetc, rgfmtetc, 0);
186 /**********************************************************
187 * RegisterFormatEnumerator (urlmon.@)
189 HRESULT WINAPI RegisterFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc, DWORD reserved)
191 TRACE("(%p %p %d)\n", pBC, pEFetc, reserved);
194 WARN("reserved != 0\n");
199 return IBindCtx_RegisterObjectParam(pBC, wszEnumFORMATETC, (IUnknown*)pEFetc);
202 /**********************************************************
203 * RevokeFormatEnumerator (urlmon.@)
205 HRESULT WINAPI RevokeFormatEnumerator(LPBC pbc, IEnumFORMATETC *pEFetc)
207 TRACE("(%p %p)\n", pbc, pEFetc);
212 return IBindCtx_RevokeObjectParam(pbc, wszEnumFORMATETC);