po: Remove English strings from the Esperanto translation.
[wine/multimedia.git] / dlls / urlmon / format.c
blob6967c3b4f39af94577d63e0633aec20af0ae80ae
1 /*
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};
26 typedef struct {
27 IEnumFORMATETC IEnumFORMATETC_iface;
29 FORMATETC *fetc;
30 UINT fetc_cnt;
31 UINT it;
33 LONG ref;
34 } EnumFORMATETC;
36 static inline EnumFORMATETC *impl_from_IEnumFORMATETC(IEnumFORMATETC *iface)
38 return CONTAINING_RECORD(iface, EnumFORMATETC, IEnumFORMATETC_iface);
41 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it);
43 static HRESULT WINAPI EnumFORMATETC_QueryInterface(IEnumFORMATETC *iface, REFIID riid, void **ppv)
45 EnumFORMATETC *This = impl_from_IEnumFORMATETC(iface);
47 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
49 *ppv = NULL;
51 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IEnumFORMATETC, riid)) {
52 IEnumFORMATETC_AddRef(iface);
53 *ppv = iface;
54 return S_OK;
57 WARN("not supported interface %s\n", debugstr_guid(riid));
58 return E_NOINTERFACE;
61 static ULONG WINAPI EnumFORMATETC_AddRef(IEnumFORMATETC *iface)
63 EnumFORMATETC *This = impl_from_IEnumFORMATETC(iface);
64 LONG ref = InterlockedIncrement(&This->ref);
65 TRACE("(%p) ref=%d\n", This, ref);
66 return ref;
69 static ULONG WINAPI EnumFORMATETC_Release(IEnumFORMATETC *iface)
71 EnumFORMATETC *This = impl_from_IEnumFORMATETC(iface);
72 LONG ref = InterlockedDecrement(&This->ref);
74 TRACE("(%p) ref=%d\n", This, ref);
76 if(!ref) {
77 heap_free(This->fetc);
78 heap_free(This);
80 URLMON_UnlockModule();
83 return ref;
86 static HRESULT WINAPI EnumFORMATETC_Next(IEnumFORMATETC *iface, ULONG celt,
87 FORMATETC *rgelt, ULONG *pceltFetched)
89 EnumFORMATETC *This = impl_from_IEnumFORMATETC(iface);
90 ULONG cnt;
92 TRACE("(%p)->(%d %p %p)\n", This, celt, rgelt, pceltFetched);
94 if(!rgelt)
95 return E_INVALIDARG;
97 if(This->it >= This->fetc_cnt || !celt) {
98 if(pceltFetched)
99 *pceltFetched = 0;
100 return celt ? S_FALSE : S_OK;
103 cnt = This->fetc_cnt-This->it > celt ? celt : This->fetc_cnt-This->it;
105 memcpy(rgelt, This->fetc+This->it, cnt*sizeof(FORMATETC));
106 This->it += cnt;
108 if(pceltFetched)
109 *pceltFetched = cnt;
111 return cnt == celt ? S_OK : S_FALSE;
114 static HRESULT WINAPI EnumFORMATETC_Skip(IEnumFORMATETC *iface, ULONG celt)
116 EnumFORMATETC *This = impl_from_IEnumFORMATETC(iface);
118 TRACE("(%p)->(%d)\n", This, celt);
120 This->it += celt;
121 return This->it > This->fetc_cnt ? S_FALSE : S_OK;
124 static HRESULT WINAPI EnumFORMATETC_Reset(IEnumFORMATETC *iface)
126 EnumFORMATETC *This = impl_from_IEnumFORMATETC(iface);
128 TRACE("(%p)\n", This);
130 This->it = 0;
131 return S_OK;
134 static HRESULT WINAPI EnumFORMATETC_Clone(IEnumFORMATETC *iface, IEnumFORMATETC **ppenum)
136 EnumFORMATETC *This = impl_from_IEnumFORMATETC(iface);
138 TRACE("(%p)->(%p)\n", This, ppenum);
140 if(!ppenum)
141 return E_INVALIDARG;
143 *ppenum = EnumFORMATETC_Create(This->fetc_cnt, This->fetc, This->it);
144 return S_OK;
147 static const IEnumFORMATETCVtbl EnumFORMATETCVtbl = {
148 EnumFORMATETC_QueryInterface,
149 EnumFORMATETC_AddRef,
150 EnumFORMATETC_Release,
151 EnumFORMATETC_Next,
152 EnumFORMATETC_Skip,
153 EnumFORMATETC_Reset,
154 EnumFORMATETC_Clone
157 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it)
159 EnumFORMATETC *ret = heap_alloc(sizeof(EnumFORMATETC));
161 URLMON_LockModule();
163 ret->IEnumFORMATETC_iface.lpVtbl = &EnumFORMATETCVtbl;
164 ret->ref = 1;
165 ret->it = it;
166 ret->fetc_cnt = cfmtetc;
168 ret->fetc = heap_alloc(cfmtetc*sizeof(FORMATETC));
169 memcpy(ret->fetc, rgfmtetc, cfmtetc*sizeof(FORMATETC));
171 return &ret->IEnumFORMATETC_iface;
174 /**********************************************************
175 * CreateFormatEnumerator (urlmon.@)
177 HRESULT WINAPI CreateFormatEnumerator(UINT cfmtetc, FORMATETC *rgfmtetc,
178 IEnumFORMATETC** ppenumfmtetc)
180 TRACE("(%d %p %p)\n", cfmtetc, rgfmtetc, ppenumfmtetc);
182 if(!ppenumfmtetc)
183 return E_INVALIDARG;
184 if(!cfmtetc)
185 return E_FAIL;
187 *ppenumfmtetc = EnumFORMATETC_Create(cfmtetc, rgfmtetc, 0);
188 return S_OK;
191 /**********************************************************
192 * RegisterFormatEnumerator (urlmon.@)
194 HRESULT WINAPI RegisterFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc, DWORD reserved)
196 TRACE("(%p %p %d)\n", pBC, pEFetc, reserved);
198 if(reserved)
199 WARN("reserved != 0\n");
201 if(!pBC || !pEFetc)
202 return E_INVALIDARG;
204 return IBindCtx_RegisterObjectParam(pBC, wszEnumFORMATETC, (IUnknown*)pEFetc);
207 /**********************************************************
208 * RevokeFormatEnumerator (urlmon.@)
210 HRESULT WINAPI RevokeFormatEnumerator(LPBC pbc, IEnumFORMATETC *pEFetc)
212 TRACE("(%p %p)\n", pbc, pEFetc);
214 if(!pbc)
215 return E_INVALIDARG;
217 return IBindCtx_RevokeObjectParam(pbc, wszEnumFORMATETC);