ntdll: Translate signal to trap when trap code is 0 on ARM.
[wine.git] / dlls / browseui / aclmulti.c
blob412a18d3ab8204f904654d19ce23c58a96b45d51
1 /*
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
21 #include "config.h"
23 #include <stdarg.h>
25 #define COBJMACROS
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"
36 #include "shlguid.h"
37 #include "shlobj.h"
39 #include "wine/heap.h"
40 #include "wine/unicode.h"
42 #include "browseui.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
46 struct ACLMultiSublist {
47 IUnknown *punk;
48 IEnumString *pEnum;
49 IACList *pACL;
52 typedef struct tagACLMulti {
53 IEnumString IEnumString_iface;
54 IACList IACList_iface;
55 IObjMgr IObjMgr_iface;
56 LONG refCount;
57 INT nObjs;
58 INT currObj;
59 struct ACLMultiSublist *objs;
60 } ACLMulti;
62 static inline ACLMulti *impl_from_IEnumString(IEnumString *iface)
64 return CONTAINING_RECORD(iface, ACLMulti, IEnumString_iface);
67 static inline ACLMulti *impl_from_IACList(IACList *iface)
69 return CONTAINING_RECORD(iface, ACLMulti, IACList_iface);
72 static inline ACLMulti *impl_from_IObjMgr(IObjMgr *iface)
74 return CONTAINING_RECORD(iface, ACLMulti, IObjMgr_iface);
77 static void release_obj(struct ACLMultiSublist *obj)
79 IUnknown_Release(obj->punk);
80 if (obj->pEnum)
81 IEnumString_Release(obj->pEnum);
82 if (obj->pACL)
83 IACList_Release(obj->pACL);
86 static void ACLMulti_Destructor(ACLMulti *This)
88 int i;
89 TRACE("destroying %p\n", This);
90 for (i = 0; i < This->nObjs; i++)
91 release_obj(&This->objs[i]);
92 heap_free(This->objs);
93 heap_free(This);
94 BROWSEUI_refCount--;
97 static HRESULT WINAPI ACLMulti_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
99 ACLMulti *This = impl_from_IEnumString(iface);
100 *ppvOut = NULL;
102 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumString))
104 *ppvOut = &This->IEnumString_iface;
106 else if (IsEqualIID(iid, &IID_IACList))
108 *ppvOut = &This->IACList_iface;
110 else if (IsEqualIID(iid, &IID_IObjMgr))
112 *ppvOut = &This->IObjMgr_iface;
115 if (*ppvOut)
117 IEnumString_AddRef(iface);
118 return S_OK;
121 WARN("unsupported interface: %s\n", debugstr_guid(iid));
122 return E_NOINTERFACE;
125 static ULONG WINAPI ACLMulti_AddRef(IEnumString *iface)
127 ACLMulti *This = impl_from_IEnumString(iface);
128 return InterlockedIncrement(&This->refCount);
131 static ULONG WINAPI ACLMulti_Release(IEnumString *iface)
133 ACLMulti *This = impl_from_IEnumString(iface);
134 ULONG ret;
136 ret = InterlockedDecrement(&This->refCount);
137 if (ret == 0)
138 ACLMulti_Destructor(This);
139 return ret;
142 static HRESULT WINAPI ACLMulti_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
144 ACLMulti *This = impl_from_IEnumString(iface);
146 TRACE("(%p, %d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
147 while (This->currObj < This->nObjs)
149 if (This->objs[This->currObj].pEnum)
151 /* native browseui 6.0 also returns only one element */
152 HRESULT ret = IEnumString_Next(This->objs[This->currObj].pEnum, 1, rgelt, pceltFetched);
153 if (ret != S_FALSE)
154 return ret;
156 This->currObj++;
159 if (pceltFetched)
160 *pceltFetched = 0;
161 *rgelt = NULL;
162 return S_FALSE;
165 static HRESULT WINAPI ACLMulti_Reset(IEnumString *iface)
167 ACLMulti *This = impl_from_IEnumString(iface);
168 int i;
170 This->currObj = 0;
171 for (i = 0; i < This->nObjs; i++)
173 if (This->objs[i].pEnum)
174 IEnumString_Reset(This->objs[i].pEnum);
176 return S_OK;
179 static HRESULT WINAPI ACLMulti_Skip(IEnumString *iface, ULONG celt)
181 /* native browseui 6.0 returns this: */
182 return E_NOTIMPL;
185 static HRESULT WINAPI ACLMulti_Clone(IEnumString *iface, IEnumString **ppOut)
187 *ppOut = NULL;
188 /* native browseui 6.0 returns this: */
189 return E_OUTOFMEMORY;
192 static const IEnumStringVtbl ACLMultiVtbl =
194 ACLMulti_QueryInterface,
195 ACLMulti_AddRef,
196 ACLMulti_Release,
198 ACLMulti_Next,
199 ACLMulti_Skip,
200 ACLMulti_Reset,
201 ACLMulti_Clone
204 static HRESULT WINAPI ACLMulti_IObjMgr_QueryInterface(IObjMgr *iface, REFIID iid, LPVOID *ppvOut)
206 ACLMulti *This = impl_from_IObjMgr(iface);
207 return IEnumString_QueryInterface(&This->IEnumString_iface, iid, ppvOut);
210 static ULONG WINAPI ACLMulti_IObjMgr_AddRef(IObjMgr *iface)
212 ACLMulti *This = impl_from_IObjMgr(iface);
213 return IEnumString_AddRef(&This->IEnumString_iface);
216 static ULONG WINAPI ACLMulti_IObjMgr_Release(IObjMgr *iface)
218 ACLMulti *This = impl_from_IObjMgr(iface);
219 return IEnumString_Release(&This->IEnumString_iface);
222 static HRESULT WINAPI ACLMulti_Append(IObjMgr *iface, IUnknown *obj)
224 ACLMulti *This = impl_from_IObjMgr(iface);
226 TRACE("(%p, %p)\n", This, obj);
227 if (obj == NULL)
228 return E_FAIL;
230 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * (This->nObjs+1));
231 This->objs[This->nObjs].punk = obj;
232 IUnknown_AddRef(obj);
233 if (FAILED(IUnknown_QueryInterface(obj, &IID_IEnumString, (LPVOID *)&This->objs[This->nObjs].pEnum)))
234 This->objs[This->nObjs].pEnum = NULL;
235 if (FAILED(IUnknown_QueryInterface(obj, &IID_IACList, (LPVOID *)&This->objs[This->nObjs].pACL)))
236 This->objs[This->nObjs].pACL = NULL;
237 This->nObjs++;
238 return S_OK;
241 static HRESULT WINAPI ACLMulti_Remove(IObjMgr *iface, IUnknown *obj)
243 ACLMulti *This = impl_from_IObjMgr(iface);
244 int i;
246 TRACE("(%p, %p)\n", This, obj);
247 for (i = 0; i < This->nObjs; i++)
248 if (This->objs[i].punk == obj)
250 release_obj(&This->objs[i]);
251 memmove(&This->objs[i], &This->objs[i+1], (This->nObjs-i-1)*sizeof(struct ACLMultiSublist));
252 This->nObjs--;
253 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * This->nObjs);
254 return S_OK;
257 return E_FAIL;
260 static const IObjMgrVtbl ACLMulti_ObjMgrVtbl =
262 ACLMulti_IObjMgr_QueryInterface,
263 ACLMulti_IObjMgr_AddRef,
264 ACLMulti_IObjMgr_Release,
266 ACLMulti_Append,
267 ACLMulti_Remove
270 static HRESULT WINAPI ACLMulti_IACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvOut)
272 ACLMulti *This = impl_from_IACList(iface);
273 return IEnumString_QueryInterface(&This->IEnumString_iface, iid, ppvOut);
276 static ULONG WINAPI ACLMulti_IACList_AddRef(IACList *iface)
278 ACLMulti *This = impl_from_IACList(iface);
279 return IEnumString_AddRef(&This->IEnumString_iface);
282 static ULONG WINAPI ACLMulti_IACList_Release(IACList *iface)
284 ACLMulti *This = impl_from_IACList(iface);
285 return IEnumString_Release(&This->IEnumString_iface);
288 static HRESULT WINAPI ACLMulti_Expand(IACList *iface, LPCWSTR wstr)
290 ACLMulti *This = impl_from_IACList(iface);
291 HRESULT res = S_OK;
292 int i;
294 for (i = 0; i < This->nObjs; i++)
296 if (!This->objs[i].pACL)
297 continue;
298 res = IACList_Expand(This->objs[i].pACL, wstr);
299 /* Vista behaviour - XP would break out of the loop if res == S_OK (usually calling Expand only once) */
301 return res;
304 static const IACListVtbl ACLMulti_ACListVtbl =
306 ACLMulti_IACList_QueryInterface,
307 ACLMulti_IACList_AddRef,
308 ACLMulti_IACList_Release,
310 ACLMulti_Expand
313 HRESULT ACLMulti_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
315 ACLMulti *This;
316 if (pUnkOuter)
317 return CLASS_E_NOAGGREGATION;
319 This = heap_alloc_zero(sizeof(ACLMulti));
320 if (This == NULL)
321 return E_OUTOFMEMORY;
323 This->IEnumString_iface.lpVtbl = &ACLMultiVtbl;
324 This->IACList_iface.lpVtbl = &ACLMulti_ACListVtbl;
325 This->IObjMgr_iface.lpVtbl = &ACLMulti_ObjMgrVtbl;
326 This->refCount = 1;
328 TRACE("returning %p\n", This);
329 *ppOut = (IUnknown *)&This->IEnumString_iface;
330 BROWSEUI_refCount++;
331 return S_OK;