windowscodecs: Add stub for DllCanUnloadNow.
[wine.git] / dlls / browseui / aclmulti.c
blob0ca6758ab6a6050e7c0a33c72ea7198469e6d2c4
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;
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 IUnknown_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_Append(IObjMgr *iface, IUnknown *obj)
143 ACLMulti *This = impl_from_IObjMgr(iface);
145 TRACE("(%p, %p)\n", This, obj);
146 if (obj == NULL)
147 return E_FAIL;
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;
156 This->nObjs++;
157 return S_OK;
160 static HRESULT WINAPI ACLMulti_Remove(IObjMgr *iface, IUnknown *obj)
162 ACLMulti *This = impl_from_IObjMgr(iface);
163 int i;
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));
171 This->nObjs--;
172 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * This->nObjs);
173 return S_OK;
176 return E_FAIL;
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);
190 if (ret != S_FALSE)
191 return ret;
193 This->currObj++;
196 if (pceltFetched)
197 *pceltFetched = 0;
198 *rgelt = NULL;
199 return S_FALSE;
202 static HRESULT WINAPI ACLMulti_Reset(IEnumString *iface)
204 ACLMulti *This = impl_from_IEnumString(iface);
205 int i;
207 This->currObj = 0;
208 for (i = 0; i < This->nObjs; i++)
210 if (This->objs[i].pEnum)
211 IEnumString_Reset(This->objs[i].pEnum);
213 return S_OK;
216 static HRESULT WINAPI ACLMulti_Skip(IEnumString *iface, ULONG celt)
218 /* native browseui 6.0 returns this: */
219 return E_NOTIMPL;
222 static HRESULT WINAPI ACLMulti_Clone(IEnumString *iface, IEnumString **ppOut)
224 *ppOut = NULL;
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);
232 HRESULT res = S_OK;
233 int i;
235 for (i = 0; i < This->nObjs; i++)
237 if (!This->objs[i].pACL)
238 continue;
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) */
242 return res;
245 static const IEnumStringVtbl ACLMultiVtbl =
247 ACLMulti_QueryInterface,
248 ACLMulti_AddRef,
249 ACLMulti_Release,
251 ACLMulti_Next,
252 ACLMulti_Skip,
253 ACLMulti_Reset,
254 ACLMulti_Clone
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,
281 ACLMulti_Append,
282 ACLMulti_Remove
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,
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;
329 BROWSEUI_refCount++;
330 return S_OK;