2 * Implementation of IEnumUnknown (for internal use).
4 * Copyright (C) Hidenori TAKESHIMA <hidenori@a2.ctktv.ne.jp>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/obj_base.h"
27 #include "wine/obj_misc.h"
29 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
32 #include "quartz_private.h"
38 typedef struct IEnumUnknownImpl
40 ICOM_VFIELD(IEnumUnknown);
46 IEnumUnknownImpl enumunk;
47 struct QUARTZ_IFEntry IFEntries[1];
48 QUARTZ_CompList* pCompList;
49 QUARTZ_CompListItem* pItemCur;
52 #define CEnumUnknown_THIS(iface,member) CEnumUnknown* This = ((CEnumUnknown*)(((char*)iface)-offsetof(CEnumUnknown,member)))
58 IEnumUnknown_fnQueryInterface(IEnumUnknown* iface,REFIID riid,void** ppobj)
60 CEnumUnknown_THIS(iface,enumunk);
62 TRACE("(%p)->()\n",This);
64 return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
68 IEnumUnknown_fnAddRef(IEnumUnknown* iface)
70 CEnumUnknown_THIS(iface,enumunk);
72 TRACE("(%p)->()\n",This);
74 return IUnknown_AddRef(This->unk.punkControl);
78 IEnumUnknown_fnRelease(IEnumUnknown* iface)
80 CEnumUnknown_THIS(iface,enumunk);
82 TRACE("(%p)->()\n",This);
84 return IUnknown_Release(This->unk.punkControl);
88 IEnumUnknown_fnNext(IEnumUnknown* iface,ULONG cReq,IUnknown** ppunk,ULONG* pcFetched)
90 CEnumUnknown_THIS(iface,enumunk);
94 TRACE("(%p)->(%lu,%p,%p)\n",This,cReq,ppunk,pcFetched);
96 if ( pcFetched == NULL && cReq > 1 )
101 QUARTZ_CompList_Lock( This->pCompList );
107 if ( This->pItemCur == NULL )
112 ppunk[ cFetched ++ ] = QUARTZ_CompList_GetItemPtr( This->pItemCur );
113 IUnknown_AddRef( *ppunk );
116 QUARTZ_CompList_GetNext( This->pCompList, This->pItemCur );
120 QUARTZ_CompList_Unlock( This->pCompList );
122 if ( pcFetched != NULL )
123 *pcFetched = cFetched;
128 static HRESULT WINAPI
129 IEnumUnknown_fnSkip(IEnumUnknown* iface,ULONG cSkip)
131 CEnumUnknown_THIS(iface,enumunk);
134 TRACE("(%p)->()\n",This);
136 QUARTZ_CompList_Lock( This->pCompList );
141 if ( This->pItemCur == NULL )
147 QUARTZ_CompList_GetNext( This->pCompList, This->pItemCur );
151 QUARTZ_CompList_Unlock( This->pCompList );
156 static HRESULT WINAPI
157 IEnumUnknown_fnReset(IEnumUnknown* iface)
159 CEnumUnknown_THIS(iface,enumunk);
161 TRACE("(%p)->()\n",This);
163 QUARTZ_CompList_Lock( This->pCompList );
165 This->pItemCur = QUARTZ_CompList_GetFirst( This->pCompList );
167 QUARTZ_CompList_Unlock( This->pCompList );
172 static HRESULT WINAPI
173 IEnumUnknown_fnClone(IEnumUnknown* iface,IEnumUnknown** ppunk)
175 CEnumUnknown_THIS(iface,enumunk);
178 TRACE("(%p)->()\n",This);
183 QUARTZ_CompList_Lock( This->pCompList );
185 hr = QUARTZ_CreateEnumUnknown(
186 This->IFEntries[0].piid,
189 FIXME( "current pointer must be seeked correctly\n" );
191 QUARTZ_CompList_Unlock( This->pCompList );
197 static ICOM_VTABLE(IEnumUnknown) ienumunk =
199 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
200 /* IUnknown fields */
201 IEnumUnknown_fnQueryInterface,
202 IEnumUnknown_fnAddRef,
203 IEnumUnknown_fnRelease,
204 /* IEnumUnknown fields */
207 IEnumUnknown_fnReset,
208 IEnumUnknown_fnClone,
211 void QUARTZ_DestroyEnumUnknown(IUnknown* punk)
213 CEnumUnknown_THIS(punk,unk);
215 if ( This->pCompList != NULL )
216 QUARTZ_CompList_Free( This->pCompList );
219 HRESULT QUARTZ_CreateEnumUnknown(
220 REFIID riidEnum, void** ppobj, const QUARTZ_CompList* pCompList )
223 QUARTZ_CompList* pCompListDup;
225 TRACE("(%s,%p,%p)\n",debugstr_guid(riidEnum),ppobj,pCompList);
227 pCompListDup = QUARTZ_CompList_Dup( pCompList, FALSE );
228 if ( pCompListDup == NULL )
229 return E_OUTOFMEMORY;
231 penum = (CEnumUnknown*)QUARTZ_AllocObj( sizeof(CEnumUnknown) );
234 QUARTZ_CompList_Free( pCompListDup );
235 return E_OUTOFMEMORY;
238 QUARTZ_IUnkInit( &penum->unk, NULL );
239 ICOM_VTBL(&penum->enumunk) = &ienumunk;
241 penum->IFEntries[0].piid = riidEnum;
242 penum->IFEntries[0].ofsVTPtr =
243 offsetof(CEnumUnknown,enumunk)-offsetof(CEnumUnknown,unk);
244 penum->pCompList = pCompListDup;
245 penum->pItemCur = QUARTZ_CompList_GetFirst( pCompListDup );
247 penum->unk.pEntries = penum->IFEntries;
248 penum->unk.dwEntries = 1;
249 penum->unk.pOnFinalRelease = QUARTZ_DestroyEnumUnknown;
251 *ppobj = (void*)(&penum->enumunk);