1 | /*
|
---|
2 | * Implementation of IEnumUnknown (for internal use).
|
---|
3 | *
|
---|
4 | * hidenori@a2.ctktv.ne.jp
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "config.h"
|
---|
8 |
|
---|
9 | #include "windef.h"
|
---|
10 | #include "winbase.h"
|
---|
11 | #include "wingdi.h"
|
---|
12 | #include "winuser.h"
|
---|
13 | #include "winerror.h"
|
---|
14 | #include "wine/obj_base.h"
|
---|
15 | #include "wine/obj_oleaut.h"
|
---|
16 | #include "strmif.h"
|
---|
17 | #include "control.h"
|
---|
18 | #include "uuids.h"
|
---|
19 |
|
---|
20 | #include "debugtools.h"
|
---|
21 | DEFAULT_DEBUG_CHANNEL(quartz);
|
---|
22 |
|
---|
23 | #include "quartz_private.h"
|
---|
24 | #include "enumunk.h"
|
---|
25 | #include "iunk.h"
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 | typedef struct IEnumUnknownImpl
|
---|
30 | {
|
---|
31 | ICOM_VFIELD(IEnumUnknown);
|
---|
32 | } IEnumUnknownImpl;
|
---|
33 |
|
---|
34 | typedef struct
|
---|
35 | {
|
---|
36 | QUARTZ_IUnkImpl unk;
|
---|
37 | IEnumUnknownImpl enumunk;
|
---|
38 | struct QUARTZ_IFEntry IFEntries[1];
|
---|
39 | QUARTZ_CompList* pCompList;
|
---|
40 | QUARTZ_CompListItem* pItemCur;
|
---|
41 | } CEnumUnknown;
|
---|
42 |
|
---|
43 | #define CEnumUnknown_THIS(iface,member) CEnumUnknown* This = ((CEnumUnknown*)(((char*)iface)-offsetof(CEnumUnknown,member)))
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | static HRESULT WINAPI
|
---|
49 | IEnumUnknown_fnQueryInterface(IEnumUnknown* iface,REFIID riid,void** ppobj)
|
---|
50 | {
|
---|
51 | CEnumUnknown_THIS(iface,enumunk);
|
---|
52 |
|
---|
53 | TRACE("(%p)->()\n",This);
|
---|
54 |
|
---|
55 | return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
|
---|
56 | }
|
---|
57 |
|
---|
58 | static ULONG WINAPI
|
---|
59 | IEnumUnknown_fnAddRef(IEnumUnknown* iface)
|
---|
60 | {
|
---|
61 | CEnumUnknown_THIS(iface,enumunk);
|
---|
62 |
|
---|
63 | TRACE("(%p)->()\n",This);
|
---|
64 |
|
---|
65 | return IUnknown_AddRef(This->unk.punkControl);
|
---|
66 | }
|
---|
67 |
|
---|
68 | static ULONG WINAPI
|
---|
69 | IEnumUnknown_fnRelease(IEnumUnknown* iface)
|
---|
70 | {
|
---|
71 | CEnumUnknown_THIS(iface,enumunk);
|
---|
72 |
|
---|
73 | TRACE("(%p)->()\n",This);
|
---|
74 |
|
---|
75 | return IUnknown_Release(This->unk.punkControl);
|
---|
76 | }
|
---|
77 |
|
---|
78 | static HRESULT WINAPI
|
---|
79 | IEnumUnknown_fnNext(IEnumUnknown* iface,ULONG cReq,IUnknown** ppunk,ULONG* pcFetched)
|
---|
80 | {
|
---|
81 | CEnumUnknown_THIS(iface,enumunk);
|
---|
82 | HRESULT hr;
|
---|
83 | ULONG cFetched;
|
---|
84 |
|
---|
85 | TRACE("(%p)->(%lu,%p,%p)\n",This,cReq,ppunk,pcFetched);
|
---|
86 |
|
---|
87 | if ( pcFetched == NULL && cReq > 1 )
|
---|
88 | return E_INVALIDARG;
|
---|
89 | if ( ppunk == NULL )
|
---|
90 | return E_POINTER;
|
---|
91 |
|
---|
92 | QUARTZ_CompList_Lock( This->pCompList );
|
---|
93 |
|
---|
94 | hr = NOERROR;
|
---|
95 | cFetched = 0;
|
---|
96 | while ( cReq > 0 )
|
---|
97 | {
|
---|
98 | if ( This->pItemCur == NULL )
|
---|
99 | {
|
---|
100 | hr = S_FALSE;
|
---|
101 | break;
|
---|
102 | }
|
---|
103 | ppunk[ cFetched ++ ] = QUARTZ_CompList_GetItemPtr( This->pItemCur );
|
---|
104 | IUnknown_AddRef( *ppunk );
|
---|
105 |
|
---|
106 | This->pItemCur =
|
---|
107 | QUARTZ_CompList_GetNext( This->pCompList, This->pItemCur );
|
---|
108 | cReq --;
|
---|
109 | }
|
---|
110 |
|
---|
111 | QUARTZ_CompList_Unlock( This->pCompList );
|
---|
112 |
|
---|
113 | if ( pcFetched != NULL )
|
---|
114 | *pcFetched = cFetched;
|
---|
115 |
|
---|
116 | return hr;
|
---|
117 | }
|
---|
118 |
|
---|
119 | static HRESULT WINAPI
|
---|
120 | IEnumUnknown_fnSkip(IEnumUnknown* iface,ULONG cSkip)
|
---|
121 | {
|
---|
122 | CEnumUnknown_THIS(iface,enumunk);
|
---|
123 | HRESULT hr;
|
---|
124 |
|
---|
125 | TRACE("(%p)->()\n",This);
|
---|
126 |
|
---|
127 | QUARTZ_CompList_Lock( This->pCompList );
|
---|
128 |
|
---|
129 | hr = NOERROR;
|
---|
130 | while ( cSkip > 0 )
|
---|
131 | {
|
---|
132 | if ( This->pItemCur == NULL )
|
---|
133 | {
|
---|
134 | hr = S_FALSE;
|
---|
135 | break;
|
---|
136 | }
|
---|
137 | This->pItemCur =
|
---|
138 | QUARTZ_CompList_GetNext( This->pCompList, This->pItemCur );
|
---|
139 | cSkip --;
|
---|
140 | }
|
---|
141 |
|
---|
142 | QUARTZ_CompList_Unlock( This->pCompList );
|
---|
143 |
|
---|
144 | return hr;
|
---|
145 | }
|
---|
146 |
|
---|
147 | static HRESULT WINAPI
|
---|
148 | IEnumUnknown_fnReset(IEnumUnknown* iface)
|
---|
149 | {
|
---|
150 | CEnumUnknown_THIS(iface,enumunk);
|
---|
151 |
|
---|
152 | TRACE("(%p)->()\n",This);
|
---|
153 |
|
---|
154 | QUARTZ_CompList_Lock( This->pCompList );
|
---|
155 |
|
---|
156 | This->pItemCur = QUARTZ_CompList_GetFirst( This->pCompList );
|
---|
157 |
|
---|
158 | QUARTZ_CompList_Unlock( This->pCompList );
|
---|
159 |
|
---|
160 | return NOERROR;
|
---|
161 | }
|
---|
162 |
|
---|
163 | static HRESULT WINAPI
|
---|
164 | IEnumUnknown_fnClone(IEnumUnknown* iface,IEnumUnknown** ppunk)
|
---|
165 | {
|
---|
166 | CEnumUnknown_THIS(iface,enumunk);
|
---|
167 | HRESULT hr;
|
---|
168 |
|
---|
169 | TRACE("(%p)->()\n",This);
|
---|
170 |
|
---|
171 | if ( ppunk == NULL )
|
---|
172 | return E_POINTER;
|
---|
173 |
|
---|
174 | QUARTZ_CompList_Lock( This->pCompList );
|
---|
175 |
|
---|
176 | hr = QUARTZ_CreateEnumUnknown(
|
---|
177 | This->IFEntries[0].piid,
|
---|
178 | (void**)ppunk,
|
---|
179 | This->pCompList );
|
---|
180 | FIXME( "current pointer must be seeked correctly\n" );
|
---|
181 |
|
---|
182 | QUARTZ_CompList_Unlock( This->pCompList );
|
---|
183 |
|
---|
184 | return hr;
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | static ICOM_VTABLE(IEnumUnknown) ienumunk =
|
---|
189 | {
|
---|
190 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
---|
191 | /* IUnknown fields */
|
---|
192 | IEnumUnknown_fnQueryInterface,
|
---|
193 | IEnumUnknown_fnAddRef,
|
---|
194 | IEnumUnknown_fnRelease,
|
---|
195 | /* IEnumUnknown fields */
|
---|
196 | IEnumUnknown_fnNext,
|
---|
197 | IEnumUnknown_fnSkip,
|
---|
198 | IEnumUnknown_fnReset,
|
---|
199 | IEnumUnknown_fnClone,
|
---|
200 | };
|
---|
201 |
|
---|
202 | void QUARTZ_DestroyEnumUnknown(IUnknown* punk)
|
---|
203 | {
|
---|
204 | CEnumUnknown_THIS(punk,unk);
|
---|
205 |
|
---|
206 | if ( This->pCompList != NULL )
|
---|
207 | QUARTZ_CompList_Free( This->pCompList );
|
---|
208 | }
|
---|
209 |
|
---|
210 | HRESULT QUARTZ_CreateEnumUnknown(
|
---|
211 | REFIID riidEnum, void** ppobj, const QUARTZ_CompList* pCompList )
|
---|
212 | {
|
---|
213 | CEnumUnknown* penum;
|
---|
214 | QUARTZ_CompList* pCompListDup;
|
---|
215 |
|
---|
216 | TRACE("(%s,%p,%p)\n",debugstr_guid(riidEnum),ppobj,pCompList);
|
---|
217 |
|
---|
218 | pCompListDup = QUARTZ_CompList_Dup( pCompList, FALSE );
|
---|
219 | if ( pCompListDup == NULL )
|
---|
220 | return E_OUTOFMEMORY;
|
---|
221 |
|
---|
222 | penum = (CEnumUnknown*)QUARTZ_AllocObj( sizeof(CEnumUnknown) );
|
---|
223 | if ( penum == NULL )
|
---|
224 | {
|
---|
225 | QUARTZ_CompList_Free( pCompListDup );
|
---|
226 | return E_OUTOFMEMORY;
|
---|
227 | }
|
---|
228 |
|
---|
229 | QUARTZ_IUnkInit( &penum->unk, NULL );
|
---|
230 | ICOM_VTBL(&penum->enumunk) = &ienumunk;
|
---|
231 |
|
---|
232 | penum->IFEntries[0].piid = riidEnum;
|
---|
233 | penum->IFEntries[0].ofsVTPtr =
|
---|
234 | offsetof(CEnumUnknown,enumunk)-offsetof(CEnumUnknown,unk);
|
---|
235 | penum->pCompList = pCompListDup;
|
---|
236 | penum->pItemCur = QUARTZ_CompList_GetFirst( pCompListDup );
|
---|
237 |
|
---|
238 | penum->unk.pEntries = penum->IFEntries;
|
---|
239 | penum->unk.dwEntries = 1;
|
---|
240 | penum->unk.pOnFinalRelease = QUARTZ_DestroyEnumUnknown;
|
---|
241 |
|
---|
242 | *ppobj = (void*)(&penum->enumunk);
|
---|
243 |
|
---|
244 | return S_OK;
|
---|
245 | }
|
---|
246 |
|
---|