include: Use the hard-float calling convention for Windows APIs on ARM
[wine.git] / dlls / browseui / aclmulti.c
blob3a6525fc7a9dbf8b55cef9d0c1a088b8745dac97
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/unicode.h"
41 #include "browseui.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
45 struct ACLMultiSublist {
46 IUnknown *punk;
47 IEnumString *pEnum;
48 IACList *pACL;
51 typedef struct tagACLMulti {
52 IEnumString IEnumString_iface;
53 IACList IACList_iface;
54 IObjMgr IObjMgr_iface;
55 LONG refCount;
56 INT nObjs;
57 INT currObj;
58 struct ACLMultiSublist *objs;
59 } ACLMulti;
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);
79 if (obj->pEnum)
80 IEnumString_Release(obj->pEnum);
81 if (obj->pACL)
82 IACList_Release(obj->pACL);
85 static void ACLMulti_Destructor(ACLMulti *This)
87 int i;
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);
92 heap_free(This);
93 BROWSEUI_refCount--;
96 static HRESULT WINAPI ACLMulti_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
98 ACLMulti *This = impl_from_IEnumString(iface);
99 *ppvOut = NULL;
101 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumString))
103 *ppvOut = &This->IEnumString_iface;
105 else if (IsEqualIID(iid, &IID_IACList))
107 *ppvOut = &This->IACList_iface;
109 else if (IsEqualIID(iid, &IID_IObjMgr))
111 *ppvOut = &This->IObjMgr_iface;
114 if (*ppvOut)
116 IEnumString_AddRef(iface);
117 return S_OK;
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);
133 ULONG ret;
135 ret = InterlockedDecrement(&This->refCount);
136 if (ret == 0)
137 ACLMulti_Destructor(This);
138 return ret;
141 static HRESULT WINAPI ACLMulti_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
143 ACLMulti *This = impl_from_IEnumString(iface);
145 TRACE("(%p, %d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
146 while (This->currObj < This->nObjs)
148 if (This->objs[This->currObj].pEnum)
150 /* native browseui 6.0 also returns only one element */
151 HRESULT ret = IEnumString_Next(This->objs[This->currObj].pEnum, 1, rgelt, pceltFetched);
152 if (ret != S_FALSE)
153 return ret;
155 This->currObj++;
158 if (pceltFetched)
159 *pceltFetched = 0;
160 *rgelt = NULL;
161 return S_FALSE;
164 static HRESULT WINAPI ACLMulti_Reset(IEnumString *iface)
166 ACLMulti *This = impl_from_IEnumString(iface);
167 int i;
169 This->currObj = 0;
170 for (i = 0; i < This->nObjs; i++)
172 if (This->objs[i].pEnum)
173 IEnumString_Reset(This->objs[i].pEnum);
175 return S_OK;
178 static HRESULT WINAPI ACLMulti_Skip(IEnumString *iface, ULONG celt)
180 /* native browseui 6.0 returns this: */
181 return E_NOTIMPL;
184 static HRESULT WINAPI ACLMulti_Clone(IEnumString *iface, IEnumString **ppOut)
186 *ppOut = NULL;
187 /* native browseui 6.0 returns this: */
188 return E_OUTOFMEMORY;
191 static const IEnumStringVtbl ACLMultiVtbl =
193 ACLMulti_QueryInterface,
194 ACLMulti_AddRef,
195 ACLMulti_Release,
197 ACLMulti_Next,
198 ACLMulti_Skip,
199 ACLMulti_Reset,
200 ACLMulti_Clone
203 static HRESULT WINAPI ACLMulti_IObjMgr_QueryInterface(IObjMgr *iface, REFIID iid, LPVOID *ppvOut)
205 ACLMulti *This = impl_from_IObjMgr(iface);
206 return IEnumString_QueryInterface(&This->IEnumString_iface, iid, ppvOut);
209 static ULONG WINAPI ACLMulti_IObjMgr_AddRef(IObjMgr *iface)
211 ACLMulti *This = impl_from_IObjMgr(iface);
212 return IEnumString_AddRef(&This->IEnumString_iface);
215 static ULONG WINAPI ACLMulti_IObjMgr_Release(IObjMgr *iface)
217 ACLMulti *This = impl_from_IObjMgr(iface);
218 return IEnumString_Release(&This->IEnumString_iface);
221 static HRESULT WINAPI ACLMulti_Append(IObjMgr *iface, IUnknown *obj)
223 ACLMulti *This = impl_from_IObjMgr(iface);
225 TRACE("(%p, %p)\n", This, obj);
226 if (obj == NULL)
227 return E_FAIL;
229 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * (This->nObjs+1));
230 This->objs[This->nObjs].punk = obj;
231 IUnknown_AddRef(obj);
232 if (FAILED(IUnknown_QueryInterface(obj, &IID_IEnumString, (LPVOID *)&This->objs[This->nObjs].pEnum)))
233 This->objs[This->nObjs].pEnum = NULL;
234 if (FAILED(IUnknown_QueryInterface(obj, &IID_IACList, (LPVOID *)&This->objs[This->nObjs].pACL)))
235 This->objs[This->nObjs].pACL = NULL;
236 This->nObjs++;
237 return S_OK;
240 static HRESULT WINAPI ACLMulti_Remove(IObjMgr *iface, IUnknown *obj)
242 ACLMulti *This = impl_from_IObjMgr(iface);
243 int i;
245 TRACE("(%p, %p)\n", This, obj);
246 for (i = 0; i < This->nObjs; i++)
247 if (This->objs[i].punk == obj)
249 release_obj(&This->objs[i]);
250 memmove(&This->objs[i], &This->objs[i+1], (This->nObjs-i-1)*sizeof(struct ACLMultiSublist));
251 This->nObjs--;
252 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * This->nObjs);
253 return S_OK;
256 return E_FAIL;
259 static const IObjMgrVtbl ACLMulti_ObjMgrVtbl =
261 ACLMulti_IObjMgr_QueryInterface,
262 ACLMulti_IObjMgr_AddRef,
263 ACLMulti_IObjMgr_Release,
265 ACLMulti_Append,
266 ACLMulti_Remove
269 static HRESULT WINAPI ACLMulti_IACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvOut)
271 ACLMulti *This = impl_from_IACList(iface);
272 return IEnumString_QueryInterface(&This->IEnumString_iface, iid, ppvOut);
275 static ULONG WINAPI ACLMulti_IACList_AddRef(IACList *iface)
277 ACLMulti *This = impl_from_IACList(iface);
278 return IEnumString_AddRef(&This->IEnumString_iface);
281 static ULONG WINAPI ACLMulti_IACList_Release(IACList *iface)
283 ACLMulti *This = impl_from_IACList(iface);
284 return IEnumString_Release(&This->IEnumString_iface);
287 static HRESULT WINAPI ACLMulti_Expand(IACList *iface, LPCWSTR wstr)
289 ACLMulti *This = impl_from_IACList(iface);
290 HRESULT res = S_OK;
291 int i;
293 for (i = 0; i < This->nObjs; i++)
295 if (!This->objs[i].pACL)
296 continue;
297 res = IACList_Expand(This->objs[i].pACL, wstr);
298 /* Vista behaviour - XP would break out of the loop if res == S_OK (usually calling Expand only once) */
300 return res;
303 static const IACListVtbl ACLMulti_ACListVtbl =
305 ACLMulti_IACList_QueryInterface,
306 ACLMulti_IACList_AddRef,
307 ACLMulti_IACList_Release,
309 ACLMulti_Expand
312 HRESULT ACLMulti_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
314 ACLMulti *This;
315 if (pUnkOuter)
316 return CLASS_E_NOAGGREGATION;
318 This = heap_alloc_zero(sizeof(ACLMulti));
319 if (This == NULL)
320 return E_OUTOFMEMORY;
322 This->IEnumString_iface.lpVtbl = &ACLMultiVtbl;
323 This->IACList_iface.lpVtbl = &ACLMulti_ACListVtbl;
324 This->IObjMgr_iface.lpVtbl = &ACLMulti_ObjMgrVtbl;
325 This->refCount = 1;
327 TRACE("returning %p\n", This);
328 *ppOut = (IUnknown *)&This->IEnumString_iface;
329 BROWSEUI_refCount++;
330 return S_OK;