wined3d: Simplify the fragment pipeline selection.
[wine/gsoc_dplay.git] / dlls / urlmon / format.c
blob0c87ca5478913f81ac22de1ed75c08a98c50721b
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 const IEnumFORMATETCVtbl *lpEnumFORMATETCVtbl;
29 FORMATETC *fetc;
30 UINT fetc_cnt;
31 UINT it;
33 LONG ref;
34 } EnumFORMATETC;
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);
44 *ppv = NULL;
46 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IEnumFORMATETC, riid)) {
47 IEnumFORMATETC_AddRef(iface);
48 *ppv = iface;
49 return S_OK;
52 WARN("not supported interface %s\n", debugstr_guid(riid));
53 return E_NOINTERFACE;
56 static ULONG WINAPI EnumFORMATETC_AddRef(IEnumFORMATETC *iface)
58 ENUMF_THIS(iface);
59 LONG ref = InterlockedIncrement(&This->ref);
60 TRACE("(%p) ref=%d\n", This, ref);
61 return ref;
64 static ULONG WINAPI EnumFORMATETC_Release(IEnumFORMATETC *iface)
66 ENUMF_THIS(iface);
67 LONG ref = InterlockedDecrement(&This->ref);
69 TRACE("(%p) ref=%d\n", This, ref);
71 if(!ref) {
72 heap_free(This->fetc);
73 heap_free(This);
75 URLMON_UnlockModule();
78 return ref;
81 static HRESULT WINAPI EnumFORMATETC_Next(IEnumFORMATETC *iface, ULONG celt,
82 FORMATETC *rgelt, ULONG *pceltFetched)
84 ENUMF_THIS(iface);
85 ULONG cnt;
87 TRACE("(%p)->(%d %p %p)\n", This, celt, rgelt, pceltFetched);
89 if(!rgelt)
90 return E_INVALIDARG;
92 if(This->it >= This->fetc_cnt || !celt) {
93 if(pceltFetched)
94 *pceltFetched = 0;
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));
101 This->it += cnt;
103 if(pceltFetched)
104 *pceltFetched = cnt;
106 return cnt == celt ? S_OK : S_FALSE;
109 static HRESULT WINAPI EnumFORMATETC_Skip(IEnumFORMATETC *iface, ULONG celt)
111 ENUMF_THIS(iface);
113 TRACE("(%p)->(%d)\n", This, celt);
115 This->it += celt;
116 return This->it > This->fetc_cnt ? S_FALSE : S_OK;
119 static HRESULT WINAPI EnumFORMATETC_Reset(IEnumFORMATETC *iface)
121 ENUMF_THIS(iface);
123 TRACE("(%p)\n", This);
125 This->it = 0;
126 return S_OK;
129 static HRESULT WINAPI EnumFORMATETC_Clone(IEnumFORMATETC *iface, IEnumFORMATETC **ppenum)
131 ENUMF_THIS(iface);
133 TRACE("(%p)->(%p)\n", This, ppenum);
135 if(!ppenum)
136 return E_INVALIDARG;
138 *ppenum = EnumFORMATETC_Create(This->fetc_cnt, This->fetc, This->it);
139 return S_OK;
142 static const IEnumFORMATETCVtbl EnumFORMATETCVtbl = {
143 EnumFORMATETC_QueryInterface,
144 EnumFORMATETC_AddRef,
145 EnumFORMATETC_Release,
146 EnumFORMATETC_Next,
147 EnumFORMATETC_Skip,
148 EnumFORMATETC_Reset,
149 EnumFORMATETC_Clone
152 static IEnumFORMATETC *EnumFORMATETC_Create(UINT cfmtetc, const FORMATETC *rgfmtetc, UINT it)
154 EnumFORMATETC *ret = heap_alloc(sizeof(EnumFORMATETC));
156 URLMON_LockModule();
158 ret->lpEnumFORMATETCVtbl = &EnumFORMATETCVtbl;
159 ret->ref = 1;
160 ret->it = it;
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);
177 if(!ppenumfmtetc)
178 return E_INVALIDARG;
179 if(!cfmtetc)
180 return E_FAIL;
182 *ppenumfmtetc = EnumFORMATETC_Create(cfmtetc, rgfmtetc, 0);
183 return S_OK;
186 /**********************************************************
187 * RegisterFormatEnumerator (urlmon.@)
189 HRESULT WINAPI RegisterFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc, DWORD reserved)
191 TRACE("(%p %p %d)\n", pBC, pEFetc, reserved);
193 if(reserved)
194 WARN("reserved != 0\n");
196 if(!pBC || !pEFetc)
197 return E_INVALIDARG;
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);
209 if(!pbc)
210 return E_INVALIDARG;
212 return IBindCtx_RevokeObjectParam(pbc, wszEnumFORMATETC);