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) DEFINE_THIS(EnumFORMATETC, EnumFORMATETC, iface)
40 static HRESULT WINAPI EnumFORMATETC_QueryInterface(IEnumFORMATETC *iface, REFIID riid, void **ppv)
42 EnumFORMATETC *This = ENUMF_THIS(iface);
44 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
48 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IEnumFORMATETC, riid)) {
49 IEnumFORMATETC_AddRef(iface);
54 WARN("not supported interface %s\n", debugstr_guid(riid));
58 static ULONG WINAPI EnumFORMATETC_AddRef(IEnumFORMATETC *iface)
60 EnumFORMATETC *This = ENUMF_THIS(iface);
61 LONG ref = InterlockedIncrement(&This->ref);
62 TRACE("(%p) ref=%d\n", This, ref);
66 static ULONG WINAPI EnumFORMATETC_Release(IEnumFORMATETC *iface)
68 EnumFORMATETC *This = ENUMF_THIS(iface);
69 LONG ref = InterlockedDecrement(&This->ref);
71 TRACE("(%p) ref=%d\n", This, ref);
74 heap_free(This->fetc);
77 URLMON_UnlockModule();
83 static HRESULT WINAPI EnumFORMATETC_Next(IEnumFORMATETC *iface, ULONG celt,
84 FORMATETC *rgelt, ULONG *pceltFetched)
86 EnumFORMATETC *This = ENUMF_THIS(iface);
89 TRACE("(%p)->(%d %p %p)\n", This, celt, rgelt, pceltFetched);
94 if(This->it >= This->fetc_cnt || !celt) {
97 return celt ? S_FALSE : S_OK;
100 cnt = This->fetc_cnt-This->it > celt ? celt : This->fetc_cnt-This->it;
102 memcpy(rgelt, This->fetc+This->it, cnt*sizeof(FORMATETC));
108 return cnt == celt ? S_OK : S_FALSE;
111 static HRESULT WINAPI EnumFORMATETC_Skip(IEnumFORMATETC *iface, ULONG celt)
113 EnumFORMATETC *This = ENUMF_THIS(iface);
115 TRACE("(%p)->(%d)\n", This, celt);
118 return This->it > This->fetc_cnt ? S_FALSE : S_OK;
121 static HRESULT WINAPI EnumFORMATETC_Reset(IEnumFORMATETC *iface)
123 EnumFORMATETC *This = ENUMF_THIS(iface);
125 TRACE("(%p)\n", This);
131 static HRESULT WINAPI EnumFORMATETC_Clone(IEnumFORMATETC *iface, IEnumFORMATETC **ppenum)
133 EnumFORMATETC *This = ENUMF_THIS(iface);
135 TRACE("(%p)->(%p)\n", This, ppenum);
140 *ppenum = EnumFORMATETC_Create(This->fetc_cnt, This->fetc, This->it);
144 static const IEnumFORMATETCVtbl EnumFORMATETCVtbl = {
145 EnumFORMATETC_QueryInterface,
146 EnumFORMATETC_AddRef,
147 EnumFORMATETC_Release,
154 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it)
156 EnumFORMATETC *ret = heap_alloc(sizeof(EnumFORMATETC));
160 ret->lpEnumFORMATETCVtbl = &EnumFORMATETCVtbl;
163 ret->fetc_cnt = cfmtetc;
165 ret->fetc = heap_alloc(cfmtetc*sizeof(FORMATETC));
166 memcpy(ret->fetc, rgfmtetc, cfmtetc*sizeof(FORMATETC));
168 return (IEnumFORMATETC*)ret;
171 /**********************************************************
172 * CreateFormatEnumerator (urlmon.@)
174 HRESULT WINAPI CreateFormatEnumerator(UINT cfmtetc, FORMATETC *rgfmtetc,
175 IEnumFORMATETC** ppenumfmtetc)
177 TRACE("(%d %p %p)\n", cfmtetc, rgfmtetc, ppenumfmtetc);
184 *ppenumfmtetc = EnumFORMATETC_Create(cfmtetc, rgfmtetc, 0);
188 /**********************************************************
189 * RegisterFormatEnumerator (urlmon.@)
191 HRESULT WINAPI RegisterFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc, DWORD reserved)
193 TRACE("(%p %p %d)\n", pBC, pEFetc, reserved);
196 WARN("reserved != 0\n");
201 return IBindCtx_RegisterObjectParam(pBC, wszEnumFORMATETC, (IUnknown*)pEFetc);
204 /**********************************************************
205 * RevokeFormatEnumerator (urlmon.@)
207 HRESULT WINAPI RevokeFormatEnumerator(LPBC pbc, IEnumFORMATETC *pEFetc)
209 TRACE("(%p %p)\n", pbc, pEFetc);
214 return IBindCtx_RevokeObjectParam(pbc, wszEnumFORMATETC);