ddraw: Some drivers return a refresh rate of 0.
[wine/winequartzdrv.git] / dlls / browseui / aclmulti.c
blob3fb49b83ffb184296609437f478c437463bd6335
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 const IEnumStringVtbl *vtbl;
53 const IACListVtbl *aclVtbl;
54 const IObjMgrVtbl *objmgrVtbl;
55 LONG refCount;
56 INT nObjs;
57 INT currObj;
58 struct ACLMultiSublist *objs;
59 } ACLMulti;
61 static const IEnumStringVtbl ACLMultiVtbl;
62 static const IACListVtbl ACLMulti_ACListVtbl;
63 static const IObjMgrVtbl ACLMulti_ObjMgrVtbl;
65 static inline ACLMulti *impl_from_IACList(IACList *iface)
67 return (ACLMulti *)((char *)iface - FIELD_OFFSET(ACLMulti, aclVtbl));
70 static inline ACLMulti *impl_from_IObjMgr(IObjMgr *iface)
72 return (ACLMulti *)((char *)iface - FIELD_OFFSET(ACLMulti, objmgrVtbl));
75 static void release_obj(struct ACLMultiSublist *obj)
77 IUnknown_Release(obj->punk);
78 if (obj->pEnum)
79 IEnumString_Release(obj->pEnum);
80 if (obj->pACL)
81 IACList_Release(obj->pACL);
84 HRESULT WINAPI ACLMulti_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
86 ACLMulti *This;
87 if (pUnkOuter)
88 return CLASS_E_NOAGGREGATION;
90 This = CoTaskMemAlloc(sizeof(ACLMulti));
91 if (This == NULL)
92 return E_OUTOFMEMORY;
93 ZeroMemory(This, sizeof(*This));
94 This->vtbl = &ACLMultiVtbl;
95 This->aclVtbl = &ACLMulti_ACListVtbl;
96 This->objmgrVtbl = &ACLMulti_ObjMgrVtbl;
97 This->refCount = 1;
99 TRACE("returning %p\n", This);
100 *ppOut = (IUnknown *)This;
101 BROWSEUI_refCount++;
102 return S_OK;
105 static void WINAPI ACLMulti_Destructor(ACLMulti *This)
107 int i;
108 TRACE("destroying %p\n", This);
109 for (i = 0; i < This->nObjs; i++)
110 release_obj(&This->objs[i]);
111 CoTaskMemFree(This->objs);
112 CoTaskMemFree(This);
113 BROWSEUI_refCount--;
116 static HRESULT WINAPI ACLMulti_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
118 ACLMulti *This = (ACLMulti *)iface;
119 *ppvOut = NULL;
121 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumString))
123 *ppvOut = This;
125 else if (IsEqualIID(iid, &IID_IACList))
127 *ppvOut = &This->aclVtbl;
129 else if (IsEqualIID(iid, &IID_IObjMgr))
131 *ppvOut = &This->objmgrVtbl;
134 if (*ppvOut)
136 IUnknown_AddRef(iface);
137 return S_OK;
140 WARN("unsupported interface: %s\n", debugstr_guid(iid));
141 return E_NOINTERFACE;
144 static ULONG WINAPI ACLMulti_AddRef(IEnumString *iface)
146 ACLMulti *This = (ACLMulti *)iface;
147 return InterlockedIncrement(&This->refCount);
150 static ULONG WINAPI ACLMulti_Release(IEnumString *iface)
152 ACLMulti *This = (ACLMulti *)iface;
153 ULONG ret;
155 ret = InterlockedDecrement(&This->refCount);
156 if (ret == 0)
157 ACLMulti_Destructor(This);
158 return ret;
161 static HRESULT WINAPI ACLMulti_Append(IObjMgr *iface, IUnknown *obj)
163 ACLMulti *This = impl_from_IObjMgr(iface);
165 TRACE("(%p, %p)\n", This, obj);
166 if (obj == NULL)
167 return E_FAIL;
169 This->objs = CoTaskMemRealloc(This->objs, sizeof(This->objs[0]) * (This->nObjs+1));
170 This->objs[This->nObjs].punk = obj;
171 IUnknown_AddRef(obj);
172 if (FAILED(IUnknown_QueryInterface(obj, &IID_IEnumString, (LPVOID *)&This->objs[This->nObjs].pEnum)))
173 This->objs[This->nObjs].pEnum = NULL;
174 if (FAILED(IUnknown_QueryInterface(obj, &IID_IACList, (LPVOID *)&This->objs[This->nObjs].pACL)))
175 This->objs[This->nObjs].pACL = NULL;
176 This->nObjs++;
177 return S_OK;
180 static HRESULT WINAPI ACLMulti_Remove(IObjMgr *iface, IUnknown *obj)
182 ACLMulti *This = impl_from_IObjMgr(iface);
183 int i;
185 TRACE("(%p, %p)\n", This, obj);
186 for (i = 0; i < This->nObjs; i++)
187 if (This->objs[i].punk == obj)
189 release_obj(&This->objs[i]);
190 memmove(&This->objs[i], &This->objs[i+1], (This->nObjs-i-1)*sizeof(struct ACLMultiSublist));
191 This->nObjs--;
192 This->objs = CoTaskMemRealloc(This->objs, sizeof(This->objs[0]) * This->nObjs);
193 return S_OK;
196 return E_FAIL;
199 static HRESULT WINAPI ACLMulti_Next(IEnumString *iface, ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched)
201 ACLMulti *This = (ACLMulti *)iface;
203 TRACE("(%p, %d, %p, %p)\n", iface, celt, rgelt, pceltFetched);
204 while (This->currObj < This->nObjs)
206 if (This->objs[This->currObj].pEnum)
208 /* native browseui 6.0 also returns only one element */
209 HRESULT ret = IEnumString_Next(This->objs[This->currObj].pEnum, 1, rgelt, pceltFetched);
210 if (ret != S_FALSE)
211 return ret;
213 This->currObj++;
216 if (pceltFetched)
217 *pceltFetched = 0;
218 *rgelt = NULL;
219 return S_FALSE;
222 static HRESULT WINAPI ACLMulti_Reset(IEnumString *iface)
224 ACLMulti *This = (ACLMulti *)iface;
225 int i;
227 This->currObj = 0;
228 for (i = 0; i < This->nObjs; i++)
230 if (This->objs[i].pEnum)
231 IEnumString_Reset(This->objs[i].pEnum);
233 return S_OK;
236 static HRESULT WINAPI ACLMulti_Skip(IEnumString *iface, ULONG celt)
238 /* native browseui 6.0 returns this: */
239 return E_NOTIMPL;
242 static HRESULT WINAPI ACLMulti_Clone(IEnumString *iface, IEnumString **ppOut)
244 *ppOut = NULL;
245 /* native browseui 6.0 returns this: */
246 return E_OUTOFMEMORY;
249 static HRESULT WINAPI ACLMulti_Expand(IACList *iface, LPCWSTR wstr)
251 ACLMulti *This = impl_from_IACList(iface);
252 HRESULT res = S_OK;
253 int i;
255 for (i = 0; i < This->nObjs; i++)
257 if (!This->objs[i].pACL)
258 continue;
259 res = IACList_Expand(This->objs[i].pACL, wstr);
260 if (res == S_OK)
261 break;
263 return res;
266 static const IEnumStringVtbl ACLMultiVtbl =
268 ACLMulti_QueryInterface,
269 ACLMulti_AddRef,
270 ACLMulti_Release,
272 ACLMulti_Next,
273 ACLMulti_Skip,
274 ACLMulti_Reset,
275 ACLMulti_Clone
278 static HRESULT WINAPI ACLMulti_IObjMgr_QueryInterface(IObjMgr *iface, REFIID iid, LPVOID *ppvOut)
280 ACLMulti *This = impl_from_IObjMgr(iface);
281 return ACLMulti_QueryInterface((IEnumString *)This, iid, ppvOut);
284 static ULONG WINAPI ACLMulti_IObjMgr_AddRef(IObjMgr *iface)
286 ACLMulti *This = impl_from_IObjMgr(iface);
287 return ACLMulti_AddRef((IEnumString *)This);
290 static ULONG WINAPI ACLMulti_IObjMgr_Release(IObjMgr *iface)
292 ACLMulti *This = impl_from_IObjMgr(iface);
293 return ACLMulti_Release((IEnumString *)This);
296 static const IObjMgrVtbl ACLMulti_ObjMgrVtbl =
298 ACLMulti_IObjMgr_QueryInterface,
299 ACLMulti_IObjMgr_AddRef,
300 ACLMulti_IObjMgr_Release,
302 ACLMulti_Append,
303 ACLMulti_Remove
306 static HRESULT WINAPI ACLMulti_IACList_QueryInterface(IACList *iface, REFIID iid, LPVOID *ppvOut)
308 ACLMulti *This = impl_from_IACList(iface);
309 return ACLMulti_QueryInterface((IEnumString *)This, iid, ppvOut);
312 static ULONG WINAPI ACLMulti_IACList_AddRef(IACList *iface)
314 ACLMulti *This = impl_from_IACList(iface);
315 return ACLMulti_AddRef((IEnumString *)This);
318 static ULONG WINAPI ACLMulti_IACList_Release(IACList *iface)
320 ACLMulti *This = impl_from_IACList(iface);
321 return ACLMulti_Release((IEnumString *)This);
324 static const IACListVtbl ACLMulti_ACListVtbl =
326 ACLMulti_IACList_QueryInterface,
327 ACLMulti_IACList_AddRef,
328 ACLMulti_IACList_Release,
330 ACLMulti_Expand