2 * Multisource AutoComplete list
4 * Copyright 2007 Mikolaj Zalewski
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
27 #include "wine/debug.h"
39 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
45 struct ACLMultiSublist {
51 typedef struct tagACLMulti {
52 IEnumString IEnumString_iface;
53 IACList IACList_iface;
54 IObjMgr IObjMgr_iface;
58 struct ACLMultiSublist *objs;
61 static inline ACLMulti *impl_from_IEnumString(IEnumString *iface)
63 return CONTAINING_RECORD(iface, ACLMulti, IEnumString_iface);
66 static inline ACLMulti *impl_from_IACList(IACList *iface)
68 return CONTAINING_RECORD(iface, ACLMulti, IACList_iface);
71 static inline ACLMulti *impl_from_IObjMgr(IObjMgr *iface)
73 return CONTAINING_RECORD(iface, ACLMulti, IObjMgr_iface);
76 static void release_obj(struct ACLMultiSublist *obj)
78 IUnknown_Release(obj->punk);
80 IEnumString_Release(obj->pEnum);
82 IACList_Release(obj->pACL);
85 static void ACLMulti_Destructor(ACLMulti *This)
88 TRACE("destroying %p\n", This);
89 for (i = 0; i < This->nObjs; i++)
90 release_obj(&This->objs[i]);
91 heap_free(This->objs);
96 static HRESULT WINAPI ACLMulti_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
98 ACLMulti *This = impl_from_IEnumString(iface);
101 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumString))
105 else if (IsEqualIID(iid, &IID_IACList))
107 *ppvOut = &This->IACList_iface;
109 else if (IsEqualIID(iid, &IID_IObjMgr))
111 *ppvOut = &This->IObjMgr_iface;
116 IEnumString_AddRef(iface);
120 WARN("unsupported interface: %s\n", debugstr_guid(iid));
121 return E_NOINTERFACE;
124 static ULONG WINAPI ACLMulti_AddRef(IEnumString *iface)
126 ACLMulti *This = impl_from_IEnumString(iface);
127 return InterlockedIncrement(&This->refCount);
130 static ULONG WINAPI ACLMulti_Release(IEnumString *iface)
132 ACLMulti *This = impl_from_IEnumString(iface);
135 ret = InterlockedDecrement(&This->refCount);
137 ACLMulti_Destructor(This);
141 static HRESULT WINAPI ACLMulti_Append(IObjMgr *iface, IUnknown *obj)
143 ACLMulti *This = impl_from_IObjMgr(iface);
145 TRACE("(%p, %p)\n", This, obj);
149 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * (This->nObjs+1));
150 This->objs[This->nObjs].punk = obj;
151 IUnknown_AddRef(obj);
152 if (FAILED(IUnknown_QueryInterface(obj, &IID_IEnumString, (LPVOID *)&This->objs[This->nObjs].pEnum)))
153 This->objs[This->nObjs].pEnum = NULL;
154 if (FAILED(IUnknown_QueryInterface(obj, &IID_IACList, (LPVOID *)&This->objs[This->nObjs].pACL)))
155 This->objs[This->nObjs].pACL = NULL;
160 static HRESULT WINAPI ACLMulti_Remove(IObjMgr *iface, IUnknown *obj)
162 ACLMulti *This = impl_from_IObjMgr(iface);
165 TRACE("(%p, %p)\n", This, obj);
166 for (i = 0; i < This->nObjs; i++)
167 if (This->objs[i].punk == obj)
169 release_obj(&This->objs[i]);
170 memmove(&This->objs[i], &This->objs[i+1], (This->nObjs-i-1)*sizeof(struct ACLMultiSublist));
172 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * This->nObjs);
179 static HRESULT WINAPI ACLMulti_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
181 ACLMulti *This = impl_from_IEnumString(iface);
183 TRACE("(%p, %d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
184 while (This->currObj < This->nObjs)
186 if (This->objs[This->currObj].pEnum)
188 /* native browseui 6.0 also returns only one element */
189 HRESULT ret = IEnumString_Next(This->objs[This->currObj].pEnum, 1, rgelt, pceltFetched);
202 static HRESULT WINAPI ACLMulti_Reset(IEnumString *iface)
204 ACLMulti *This = impl_from_IEnumString(iface);
208 for (i = 0; i < This->nObjs; i++)
210 if (This->objs[i].pEnum)
211 IEnumString_Reset(This->objs[i].pEnum);
216 static HRESULT WINAPI ACLMulti_Skip(IEnumString *iface, ULONG celt)
218 /* native browseui 6.0 returns this: */
222 static HRESULT WINAPI ACLMulti_Clone(IEnumString *iface, IEnumString **ppOut)
225 /* native browseui 6.0 returns this: */
226 return E_OUTOFMEMORY;
229 static HRESULT WINAPI ACLMulti_Expand(IACList *iface, LPCWSTR wstr)
231 ACLMulti *This = impl_from_IACList(iface);
235 for (i = 0; i < This->nObjs; i++)
237 if (!This->objs[i].pACL)
239 res = IACList_Expand(This->objs[i].pACL, wstr);
240 /* Vista behaviour - XP would break out of the loop if res == S_OK (usually calling Expand only once) */
245 static const IEnumStringVtbl ACLMultiVtbl =
247 ACLMulti_QueryInterface,
257 static HRESULT WINAPI ACLMulti_IObjMgr_QueryInterface(IObjMgr *iface, REFIID iid, LPVOID *ppvOut)
259 ACLMulti *This = impl_from_IObjMgr(iface);
260 return ACLMulti_QueryInterface(&This->IEnumString_iface, iid, ppvOut);
263 static ULONG WINAPI ACLMulti_IObjMgr_AddRef(IObjMgr *iface)
265 ACLMulti *This = impl_from_IObjMgr(iface);
266 return ACLMulti_AddRef(&This->IEnumString_iface);
269 static ULONG WINAPI ACLMulti_IObjMgr_Release(IObjMgr *iface)
271 ACLMulti *This = impl_from_IObjMgr(iface);
272 return ACLMulti_Release(&This->IEnumString_iface);
275 static const IObjMgrVtbl ACLMulti_ObjMgrVtbl =
277 ACLMulti_IObjMgr_QueryInterface,
278 ACLMulti_IObjMgr_AddRef,
279 ACLMulti_IObjMgr_Release,
285 static HRESULT WINAPI ACLMulti_IACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvOut)
287 ACLMulti *This = impl_from_IACList(iface);
288 return ACLMulti_QueryInterface(&This->IEnumString_iface, iid, ppvOut);
291 static ULONG WINAPI ACLMulti_IACList_AddRef(IACList *iface)
293 ACLMulti *This = impl_from_IACList(iface);
294 return ACLMulti_AddRef(&This->IEnumString_iface);
297 static ULONG WINAPI ACLMulti_IACList_Release(IACList *iface)
299 ACLMulti *This = impl_from_IACList(iface);
300 return ACLMulti_Release(&This->IEnumString_iface);
303 static const IACListVtbl ACLMulti_ACListVtbl =
305 ACLMulti_IACList_QueryInterface,
306 ACLMulti_IACList_AddRef,
307 ACLMulti_IACList_Release,
312 HRESULT ACLMulti_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
316 return CLASS_E_NOAGGREGATION;
318 This = heap_alloc_zero(sizeof(ACLMulti));
320 return E_OUTOFMEMORY;
322 This->IEnumString_iface.lpVtbl = &ACLMultiVtbl;
323 This->IACList_iface.lpVtbl = &ACLMulti_ACListVtbl;
324 This->IObjMgr_iface.lpVtbl = &ACLMulti_ObjMgrVtbl;
327 TRACE("returning %p\n", This);
328 *ppOut = (IUnknown *)This;