1 /*
2 * Multisource AutoComplete list
3 *
4 * Copyright 2007 Mikolaj Zalewski
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #define COBJMACROS
26
27 #include "wine/debug.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winuser.h"
32 #include "shlwapi.h"
33 #include "winerror.h"
34 #include "objbase.h"
35
36 #include "shlguid.h"
37 #include "shlobj.h"
38
39 #include "wine/unicode.h"
40
41 #include "browseui.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
44
45 struct ACLMultiSublist {
46 IUnknown *punk;
47 IEnumString *pEnum;
48 IACList *pACL;
49 };
50
51 typedef struct tagACLMulti {
52 const IEnumStringVtbl *vtbl;
53 const IACListVtbl *aclVtbl;
54 const IObjMgrVtbl *objmgrVtbl;
55 LONG refCount;
56 INT nObjs;
57 INT currObj;
58 struct ACLMultiSublist *objs;
59 } ACLMulti;
60
61 static inline ACLMulti *impl_from_IACList(IACList *iface)
62 {
63 return (ACLMulti *)((char *)iface - FIELD_OFFSET(ACLMulti, aclVtbl));
64 }
65
66 static inline ACLMulti *impl_from_IObjMgr(IObjMgr *iface)
67 {
68 return (ACLMulti *)((char *)iface - FIELD_OFFSET(ACLMulti, objmgrVtbl));
69 }
70
71 static void release_obj(struct ACLMultiSublist *obj)
72 {
73 IUnknown_Release(obj->punk);
74 if (obj->pEnum)
75 IEnumString_Release(obj->pEnum);
76 if (obj->pACL)
77 IACList_Release(obj->pACL);
78 }
79
80 static void ACLMulti_Destructor(ACLMulti *This)
81 {
82 int i;
83 TRACE("destroying %p\n", This);
84 for (i = 0; i < This->nObjs; i++)
85 release_obj(&This->objs[i]);
86 heap_free(This->objs);
87 heap_free(This);
88 BROWSEUI_refCount--;
89 }
90
91 static HRESULT WINAPI ACLMulti_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
92 {
93 ACLMulti *This = (ACLMulti *)iface;
94 *ppvOut = NULL;
95
96 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumString))
97 {
98 *ppvOut = This;
99 }
100 else if (IsEqualIID(iid, &IID_IACList))
101 {
102 *ppvOut = &This->aclVtbl;
103 }
104 else if (IsEqualIID(iid, &IID_IObjMgr))
105 {
106 *ppvOut = &This->objmgrVtbl;
107 }
108
109 if (*ppvOut)
110 {
111 IUnknown_AddRef(iface);
112 return S_OK;
113 }
114
115 WARN("unsupported interface: %s\n", debugstr_guid(iid));
116 return E_NOINTERFACE;
117 }
118
119 static ULONG WINAPI ACLMulti_AddRef(IEnumString *iface)
120 {
121 ACLMulti *This = (ACLMulti *)iface;
122 return InterlockedIncrement(&This->refCount);
123 }
124
125 static ULONG WINAPI ACLMulti_Release(IEnumString *iface)
126 {
127 ACLMulti *This = (ACLMulti *)iface;
128 ULONG ret;
129
130 ret = InterlockedDecrement(&This->refCount);
131 if (ret == 0)
132 ACLMulti_Destructor(This);
133 return ret;
134 }
135
136 static HRESULT WINAPI ACLMulti_Append(IObjMgr *iface, IUnknown *obj)
137 {
138 ACLMulti *This = impl_from_IObjMgr(iface);
139
140 TRACE("(%p, %p)\n", This, obj);
141 if (obj == NULL)
142 return E_FAIL;
143
144 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * (This->nObjs+1));
145 This->objs[This->nObjs].punk = obj;
146 IUnknown_AddRef(obj);
147 if (FAILED(IUnknown_QueryInterface(obj, &IID_IEnumString, (LPVOID *)&This->objs[This->nObjs].pEnum)))
148 This->objs[This->nObjs].pEnum = NULL;
149 if (FAILED(IUnknown_QueryInterface(obj, &IID_IACList, (LPVOID *)&This->objs[This->nObjs].pACL)))
150 This->objs[This->nObjs].pACL = NULL;
151 This->nObjs++;
152 return S_OK;
153 }
154
155 static HRESULT WINAPI ACLMulti_Remove(IObjMgr *iface, IUnknown *obj)
156 {
157 ACLMulti *This = impl_from_IObjMgr(iface);
158 int i;
159
160 TRACE("(%p, %p)\n", This, obj);
161 for (i = 0; i < This->nObjs; i++)
162 if (This->objs[i].punk == obj)
163 {
164 release_obj(&This->objs[i]);
165 memmove(&This->objs[i], &This->objs[i+1], (This->nObjs-i-1)*sizeof(struct ACLMultiSublist));
166 This->nObjs--;
167 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * This->nObjs);
168 return S_OK;
169 }
170
171 return E_FAIL;
172 }
173
174 static HRESULT WINAPI ACLMulti_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
175 {
176 ACLMulti *This = (ACLMulti *)iface;
177
178 TRACE("(%p, %d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
179 while (This->currObj < This->nObjs)
180 {
181 if (This->objs[This->currObj].pEnum)
182 {
183 /* native browseui 6.0 also returns only one element */
184 HRESULT ret = IEnumString_Next(This->objs[This->currObj].pEnum, 1, rgelt, pceltFetched);
185 if (ret != S_FALSE)
186 return ret;
187 }
188 This->currObj++;
189 }
190
191 if (pceltFetched)
192 *pceltFetched = 0;
193 *rgelt = NULL;
194 return S_FALSE;
195 }
196
197 static HRESULT WINAPI ACLMulti_Reset(IEnumString *iface)
198 {
199 ACLMulti *This = (ACLMulti *)iface;
200 int i;
201
202 This->currObj = 0;
203 for (i = 0; i < This->nObjs; i++)
204 {
205 if (This->objs[i].pEnum)
206 IEnumString_Reset(This->objs[i].pEnum);
207 }
208 return S_OK;
209 }
210
211 static HRESULT WINAPI ACLMulti_Skip(IEnumString *iface, ULONG celt)
212 {
213 /* native browseui 6.0 returns this: */
214 return E_NOTIMPL;
215 }
216
217 static HRESULT WINAPI ACLMulti_Clone(IEnumString *iface, IEnumString **ppOut)
218 {
219 *ppOut = NULL;
220 /* native browseui 6.0 returns this: */
221 return E_OUTOFMEMORY;
222 }
223
224 static HRESULT WINAPI ACLMulti_Expand(IACList *iface, LPCWSTR wstr)
225 {
226 ACLMulti *This = impl_from_IACList(iface);
227 HRESULT res = S_OK;
228 int i;
229
230 for (i = 0; i < This->nObjs; i++)
231 {
232 if (!This->objs[i].pACL)
233 continue;
234 res = IACList_Expand(This->objs[i].pACL, wstr);
235 /* Vista behaviour - XP would break out of the loop if res == S_OK (usually calling Expand only once) */
236 }
237 return res;
238 }
239
240 static const IEnumStringVtbl ACLMultiVtbl =
241 {
242 ACLMulti_QueryInterface,
243 ACLMulti_AddRef,
244 ACLMulti_Release,
245
246 ACLMulti_Next,
247 ACLMulti_Skip,
248 ACLMulti_Reset,
249 ACLMulti_Clone
250 };
251
252 static HRESULT WINAPI ACLMulti_IObjMgr_QueryInterface(IObjMgr *iface, REFIID iid, LPVOID *ppvOut)
253 {
254 ACLMulti *This = impl_from_IObjMgr(iface);
255 return ACLMulti_QueryInterface((IEnumString *)This, iid, ppvOut);
256 }
257
258 static ULONG WINAPI ACLMulti_IObjMgr_AddRef(IObjMgr *iface)
259 {
260 ACLMulti *This = impl_from_IObjMgr(iface);
261 return ACLMulti_AddRef((IEnumString *)This);
262 }
263
264 static ULONG WINAPI ACLMulti_IObjMgr_Release(IObjMgr *iface)
265 {
266 ACLMulti *This = impl_from_IObjMgr(iface);
267 return ACLMulti_Release((IEnumString *)This);
268 }
269
270 static const IObjMgrVtbl ACLMulti_ObjMgrVtbl =
271 {
272 ACLMulti_IObjMgr_QueryInterface,
273 ACLMulti_IObjMgr_AddRef,
274 ACLMulti_IObjMgr_Release,
275
276 ACLMulti_Append,
277 ACLMulti_Remove
278 };
279
280 static HRESULT WINAPI ACLMulti_IACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvOut)
281 {
282 ACLMulti *This = impl_from_IACList(iface);
283 return ACLMulti_QueryInterface((IEnumString *)This, iid, ppvOut);
284 }
285
286 static ULONG WINAPI ACLMulti_IACList_AddRef(IACList *iface)
287 {
288 ACLMulti *This = impl_from_IACList(iface);
289 return ACLMulti_AddRef((IEnumString *)This);
290 }
291
292 static ULONG WINAPI ACLMulti_IACList_Release(IACList *iface)
293 {
294 ACLMulti *This = impl_from_IACList(iface);
295 return ACLMulti_Release((IEnumString *)This);
296 }
297
298 static const IACListVtbl ACLMulti_ACListVtbl =
299 {
300 ACLMulti_IACList_QueryInterface,
301 ACLMulti_IACList_AddRef,
302 ACLMulti_IACList_Release,
303
304 ACLMulti_Expand
305 };
306
307 HRESULT ACLMulti_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
308 {
309 ACLMulti *This;
310 if (pUnkOuter)
311 return CLASS_E_NOAGGREGATION;
312
313 This = heap_alloc_zero(sizeof(ACLMulti));
314 if (This == NULL)
315 return E_OUTOFMEMORY;
316
317 This->vtbl = &ACLMultiVtbl;
318 This->aclVtbl = &ACLMulti_ACListVtbl;
319 This->objmgrVtbl = &ACLMulti_ObjMgrVtbl;
320 This->refCount = 1;
321
322 TRACE("returning %p\n", This);
323 *ppOut = (IUnknown *)This;
324 BROWSEUI_refCount++;
325 return S_OK;
326 }
327
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.