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 const IEnumStringVtbl *vtbl;
53 const IACListVtbl *aclVtbl;
54 const IObjMgrVtbl *objmgrVtbl;
58 struct ACLMultiSublist *objs;
61 static inline ACLMulti *impl_from_IACList(IACList *iface)
63 return (ACLMulti *)((char *)iface - FIELD_OFFSET(ACLMulti, aclVtbl));
66 static inline ACLMulti *impl_from_IObjMgr(IObjMgr *iface)
68 return (ACLMulti *)((char *)iface - FIELD_OFFSET(ACLMulti, objmgrVtbl));
71 static void release_obj(struct ACLMultiSublist *obj)
73 IUnknown_Release(obj->punk);
75 IEnumString_Release(obj->pEnum);
77 IACList_Release(obj->pACL);
80 static void ACLMulti_Destructor(ACLMulti *This)
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);
91 static HRESULT WINAPI ACLMulti_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
93 ACLMulti *This = (ACLMulti *)iface;
96 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumString))
100 else if (IsEqualIID(iid, &IID_IACList))
102 *ppvOut = &This->aclVtbl;
104 else if (IsEqualIID(iid, &IID_IObjMgr))
106 *ppvOut = &This->objmgrVtbl;
111 IUnknown_AddRef(iface);
115 WARN("unsupported interface: %s\n", debugstr_guid(iid));
116 return E_NOINTERFACE;
119 static ULONG WINAPI ACLMulti_AddRef(IEnumString *iface)
121 ACLMulti *This = (ACLMulti *)iface;
122 return InterlockedIncrement(&This->refCount);
125 static ULONG WINAPI ACLMulti_Release(IEnumString *iface)
127 ACLMulti *This = (ACLMulti *)iface;
130 ret = InterlockedDecrement(&This->refCount);
132 ACLMulti_Destructor(This);
136 static HRESULT WINAPI ACLMulti_Append(IObjMgr *iface, IUnknown *obj)
138 ACLMulti *This = impl_from_IObjMgr(iface);
140 TRACE("(%p, %p)\n", This, obj);
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;
155 static HRESULT WINAPI ACLMulti_Remove(IObjMgr *iface, IUnknown *obj)
157 ACLMulti *This = impl_from_IObjMgr(iface);
160 TRACE("(%p, %p)\n", This, obj);
161 for (i = 0; i < This->nObjs; i++)
162 if (This->objs[i].punk == obj)
164 release_obj(&This->objs[i]);
165 memmove(&This->objs[i], &This->objs[i+1], (This->nObjs-i-1)*sizeof(struct ACLMultiSublist));
167 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * This->nObjs);
174 static HRESULT WINAPI ACLMulti_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
176 ACLMulti *This = (ACLMulti *)iface;
178 TRACE("(%p, %d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
179 while (This->currObj < This->nObjs)
181 if (This->objs[This->currObj].pEnum)
183 /* native browseui 6.0 also returns only one element */
184 HRESULT ret = IEnumString_Next(This->objs[This->currObj].pEnum, 1, rgelt, pceltFetched);
197 static HRESULT WINAPI ACLMulti_Reset(IEnumString *iface)
199 ACLMulti *This = (ACLMulti *)iface;
203 for (i = 0; i < This->nObjs; i++)
205 if (This->objs[i].pEnum)
206 IEnumString_Reset(This->objs[i].pEnum);
211 static HRESULT WINAPI ACLMulti_Skip(IEnumString *iface, ULONG celt)
213 /* native browseui 6.0 returns this: */
217 static HRESULT WINAPI ACLMulti_Clone(IEnumString *iface, IEnumString **ppOut)
220 /* native browseui 6.0 returns this: */
221 return E_OUTOFMEMORY;
224 static HRESULT WINAPI ACLMulti_Expand(IACList *iface, LPCWSTR wstr)
226 ACLMulti *This = impl_from_IACList(iface);
230 for (i = 0; i < This->nObjs; i++)
232 if (!This->objs[i].pACL)
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) */
240 static const IEnumStringVtbl ACLMultiVtbl =
242 ACLMulti_QueryInterface,
252 static HRESULT WINAPI ACLMulti_IObjMgr_QueryInterface(IObjMgr *iface, REFIID iid, LPVOID *ppvOut)
254 ACLMulti *This = impl_from_IObjMgr(iface);
255 return ACLMulti_QueryInterface((IEnumString *)This, iid, ppvOut);
258 static ULONG WINAPI ACLMulti_IObjMgr_AddRef(IObjMgr *iface)
260 ACLMulti *This = impl_from_IObjMgr(iface);
261 return ACLMulti_AddRef((IEnumString *)This);
264 static ULONG WINAPI ACLMulti_IObjMgr_Release(IObjMgr *iface)
266 ACLMulti *This = impl_from_IObjMgr(iface);
267 return ACLMulti_Release((IEnumString *)This);
270 static const IObjMgrVtbl ACLMulti_ObjMgrVtbl =
272 ACLMulti_IObjMgr_QueryInterface,
273 ACLMulti_IObjMgr_AddRef,
274 ACLMulti_IObjMgr_Release,
280 static HRESULT WINAPI ACLMulti_IACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvOut)
282 ACLMulti *This = impl_from_IACList(iface);
283 return ACLMulti_QueryInterface((IEnumString *)This, iid, ppvOut);
286 static ULONG WINAPI ACLMulti_IACList_AddRef(IACList *iface)
288 ACLMulti *This = impl_from_IACList(iface);
289 return ACLMulti_AddRef((IEnumString *)This);
292 static ULONG WINAPI ACLMulti_IACList_Release(IACList *iface)
294 ACLMulti *This = impl_from_IACList(iface);
295 return ACLMulti_Release((IEnumString *)This);
298 static const IACListVtbl ACLMulti_ACListVtbl =
300 ACLMulti_IACList_QueryInterface,
301 ACLMulti_IACList_AddRef,
302 ACLMulti_IACList_Release,
307 HRESULT ACLMulti_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
311 return CLASS_E_NOAGGREGATION;
313 This = heap_alloc_zero(sizeof(ACLMulti));
315 return E_OUTOFMEMORY;
317 This->vtbl = &ACLMultiVtbl;
318 This->aclVtbl = &ACLMulti_ACListVtbl;
319 This->objmgrVtbl = &ACLMulti_ObjMgrVtbl;
322 TRACE("returning %p\n", This);
323 *ppOut = (IUnknown *)This;