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
28 #include "urlmon_main.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
34 static WCHAR wszEnumFORMATETC[] = {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
37 const IEnumFORMATETCVtbl *lpEnumFORMATETCVtbl;
46 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it);
48 #define ENUMF_THIS(iface) ICOM_THIS_MULTI(EnumFORMATETC, lpEnumFORMATETCVtbl, iface)
50 static HRESULT WINAPI EnumFORMATETC_QueryInterface(IEnumFORMATETC *iface, REFIID riid, void **ppv)
52 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
56 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IEnumFORMATETC, riid)) {
61 WARN("not supported interface %s\n", debugstr_guid(riid));
65 static ULONG WINAPI EnumFORMATETC_AddRef(IEnumFORMATETC *iface)
68 LONG ref = InterlockedIncrement(&This->ref);
69 TRACE("(%p) ref=%d\n", This, ref);
73 static ULONG WINAPI EnumFORMATETC_Release(IEnumFORMATETC *iface)
76 LONG ref = InterlockedDecrement(&This->ref);
78 TRACE("(%p) ref=%d\n", This, ref);
81 HeapFree(GetProcessHeap(), 0, This->fetc);
82 HeapFree(GetProcessHeap(), 0, This);
84 URLMON_UnlockModule();
90 static HRESULT WINAPI EnumFORMATETC_Next(IEnumFORMATETC *iface, ULONG celt,
91 FORMATETC *rgelt, ULONG *pceltFetched)
96 TRACE("(%p)->(%d %p %p)\n", This, celt, rgelt, pceltFetched);
101 if(This->it >= This->fetc_cnt || !celt) {
104 return celt ? S_FALSE : S_OK;
107 cnt = This->fetc_cnt-This->it > celt ? celt : This->fetc_cnt-This->it;
109 memcpy(rgelt, This->fetc+This->it, cnt*sizeof(FORMATETC));
115 return cnt == celt ? S_OK : S_FALSE;
118 static HRESULT WINAPI EnumFORMATETC_Skip(IEnumFORMATETC *iface, ULONG celt)
122 TRACE("(%p)->(%d)\n", This, celt);
125 return This->it > This->fetc_cnt ? S_FALSE : S_OK;
128 static HRESULT WINAPI EnumFORMATETC_Reset(IEnumFORMATETC *iface)
132 TRACE("(%p)\n", This);
138 static HRESULT WINAPI EnumFORMATETC_Clone(IEnumFORMATETC *iface, IEnumFORMATETC **ppenum)
142 TRACE("(%p)->(%p)\n", This, ppenum);
147 *ppenum = EnumFORMATETC_Create(This->fetc_cnt, This->fetc, This->it);
151 static const IEnumFORMATETCVtbl EnumFORMATETCVtbl = {
152 EnumFORMATETC_QueryInterface,
153 EnumFORMATETC_AddRef,
154 EnumFORMATETC_Release,
161 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it)
163 EnumFORMATETC *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(EnumFORMATETC));
167 ret->lpEnumFORMATETCVtbl = &EnumFORMATETCVtbl;
170 ret->fetc_cnt = cfmtetc;
172 ret->fetc = HeapAlloc(GetProcessHeap(), 0, cfmtetc*sizeof(FORMATETC));
173 memcpy(ret->fetc, rgfmtetc, cfmtetc*sizeof(FORMATETC));
175 return (IEnumFORMATETC*)ret;
178 /**********************************************************
179 * CreateFormatEnumerator (urlmon.@)
181 HRESULT WINAPI CreateFormatEnumerator(UINT cfmtetc, FORMATETC *rgfmtetc,
182 IEnumFORMATETC** ppenumfmtetc)
184 TRACE("(%d %p %p)\n", cfmtetc, rgfmtetc, ppenumfmtetc);
191 *ppenumfmtetc = EnumFORMATETC_Create(cfmtetc, rgfmtetc, 0);
195 /**********************************************************
196 * RegisterFormatEnumerator (urlmon.@)
198 HRESULT WINAPI RegisterFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc, DWORD reserved)
200 TRACE("(%p %p %d)\n", pBC, pEFetc, reserved);
203 WARN("reserved != 0\n");
208 return IBindCtx_RegisterObjectParam(pBC, wszEnumFORMATETC, (IUnknown*)pEFetc);
211 /**********************************************************
212 * RevokeFormatEnumerator (urlmon.@)
214 HRESULT WINAPI RevokeFormatEnumerator(LPBC pbc, IEnumFORMATETC *pEFetc)
216 TRACE("(%p %p)\n", pbc, pEFetc);
221 return IBindCtx_RevokeObjectParam(pbc, wszEnumFORMATETC);