wined3d: Store sub-resource map counts in the sub-resource structure.
[wine.git] / dlls / quartz / enummoniker.c
blobc0071a3360b06f3a088a5e3131f167e1f9cc782f
1 /*
2 * IEnumMoniker implementation
4 * Copyright 2003 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include "quartz_private.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
29 typedef struct EnumMonikerImpl
31 IEnumMoniker IEnumMoniker_iface;
32 LONG ref;
33 IMoniker ** ppMoniker;
34 ULONG nMonikerCount;
35 ULONG index;
36 } EnumMonikerImpl;
38 static const IEnumMonikerVtbl EnumMonikerImpl_Vtbl;
40 static inline EnumMonikerImpl *impl_from_IEnumMoniker(IEnumMoniker *iface)
42 return CONTAINING_RECORD(iface, EnumMonikerImpl, IEnumMoniker_iface);
45 static ULONG WINAPI EnumMonikerImpl_AddRef(LPENUMMONIKER iface);
47 HRESULT EnumMonikerImpl_Create(IMoniker ** ppMoniker, ULONG nMonikerCount, IEnumMoniker ** ppEnum)
49 /* NOTE: assumes that array of IMonikers has already been AddRef'd
50 * I.e. this function does not AddRef the array of incoming
51 * IMonikers */
52 EnumMonikerImpl * pemi = CoTaskMemAlloc(sizeof(EnumMonikerImpl));
54 TRACE("(%p, %d, %p)\n", ppMoniker, nMonikerCount, ppEnum);
56 *ppEnum = NULL;
58 if (!pemi)
59 return E_OUTOFMEMORY;
61 pemi->IEnumMoniker_iface.lpVtbl = &EnumMonikerImpl_Vtbl;
62 pemi->ref = 1;
63 pemi->ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker*));
64 memcpy(pemi->ppMoniker, ppMoniker, nMonikerCount*sizeof(IMoniker*));
65 pemi->nMonikerCount = nMonikerCount;
66 pemi->index = 0;
68 *ppEnum = &pemi->IEnumMoniker_iface;
70 return S_OK;
73 /**********************************************************************
74 * IEnumMoniker_QueryInterface (also IUnknown)
76 static HRESULT WINAPI EnumMonikerImpl_QueryInterface(
77 LPENUMMONIKER iface,
78 REFIID riid,
79 LPVOID *ppvObj)
81 EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
82 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
84 if (This == NULL || ppvObj == NULL) return E_POINTER;
86 if (IsEqualGUID(riid, &IID_IUnknown) ||
87 IsEqualGUID(riid, &IID_IEnumMoniker))
89 *ppvObj = iface;
90 EnumMonikerImpl_AddRef(iface);
91 return S_OK;
94 *ppvObj = NULL;
95 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
96 return E_NOINTERFACE;
99 /**********************************************************************
100 * IEnumMoniker_AddRef (also IUnknown)
102 static ULONG WINAPI EnumMonikerImpl_AddRef(LPENUMMONIKER iface)
104 EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
105 ULONG ref;
107 if (This == NULL) return E_POINTER;
109 ref = InterlockedIncrement(&This->ref);
111 TRACE("(%p)->() AddRef from %d\n", iface, ref - 1);
113 return ref;
116 /**********************************************************************
117 * IEnumMoniker_Release (also IUnknown)
119 static ULONG WINAPI EnumMonikerImpl_Release(LPENUMMONIKER iface)
121 EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
122 ULONG ref = InterlockedDecrement(&This->ref);
124 TRACE("(%p)->() Release from %d\n", iface, ref + 1);
126 if (!ref)
128 ULONG i;
130 for (i = 0; i < This->nMonikerCount; i++)
131 IMoniker_Release(This->ppMoniker[i]);
133 CoTaskMemFree(This->ppMoniker);
134 This->ppMoniker = NULL;
135 CoTaskMemFree(This);
136 return 0;
138 return ref;
141 static HRESULT WINAPI EnumMonikerImpl_Next(LPENUMMONIKER iface, ULONG celt, IMoniker ** rgelt, ULONG * pceltFetched)
143 ULONG fetched;
144 EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
146 TRACE("(%p)->(%d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
148 for (fetched = 0; (This->index + fetched < This->nMonikerCount) && (fetched < celt); fetched++)
150 rgelt[fetched] = This->ppMoniker[This->index + fetched];
151 IMoniker_AddRef(rgelt[fetched]);
154 This->index += fetched;
156 TRACE("-- fetched %d\n", fetched);
158 if (pceltFetched)
159 *pceltFetched = fetched;
161 if (fetched != celt)
162 return S_FALSE;
163 else
164 return S_OK;
167 static HRESULT WINAPI EnumMonikerImpl_Skip(LPENUMMONIKER iface, ULONG celt)
169 EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
171 TRACE("(%p)->(%d)\n", iface, celt);
173 This->index += celt;
175 return S_OK;
178 static HRESULT WINAPI EnumMonikerImpl_Reset(LPENUMMONIKER iface)
180 EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
182 TRACE("(%p)->()\n", iface);
184 This->index = 0;
186 return S_OK;
189 static HRESULT WINAPI EnumMonikerImpl_Clone(LPENUMMONIKER iface, IEnumMoniker ** ppenum)
191 FIXME("(%p)->(%p): stub\n", iface, ppenum);
193 return E_NOTIMPL;
196 /**********************************************************************
197 * IEnumMoniker_Vtbl
199 static const IEnumMonikerVtbl EnumMonikerImpl_Vtbl =
201 EnumMonikerImpl_QueryInterface,
202 EnumMonikerImpl_AddRef,
203 EnumMonikerImpl_Release,
204 EnumMonikerImpl_Next,
205 EnumMonikerImpl_Skip,
206 EnumMonikerImpl_Reset,
207 EnumMonikerImpl_Clone