wordpad: Remove untranslated resources from the Turkish translation.
[wine/testsucceed.git] / dlls / browseui / aclmulti.c
blobc7daba065ae986c1448308d1ba9a44ef721d23e2
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 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);
74 if (obj->pEnum)
75 IEnumString_Release(obj->pEnum);
76 if (obj->pACL)
77 IACList_Release(obj->pACL);
80 static void ACLMulti_Destructor(ACLMulti *This)
82 int i;
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);
87 heap_free(This);
88 BROWSEUI_refCount--;
91 static HRESULT WINAPI ACLMulti_QueryInterface(IEnumString *iface, REFIID iid, LPVOID *ppvOut)
93 ACLMulti *This = (ACLMulti *)iface;
94 *ppvOut = NULL;
96 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumString))
98 *ppvOut = This;
100 else if (IsEqualIID(iid, &IID_IACList))
102 *ppvOut = &This->aclVtbl;
104 else if (IsEqualIID(iid, &IID_IObjMgr))
106 *ppvOut = &This->objmgrVtbl;
109 if (*ppvOut)
111 IUnknown_AddRef(iface);
112 return S_OK;
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;
128 ULONG ret;
130 ret = InterlockedDecrement(&This->refCount);
131 if (ret == 0)
132 ACLMulti_Destructor(This);
133 return ret;
136 static HRESULT WINAPI ACLMulti_Append(IObjMgr *iface, IUnknown *obj)
138 ACLMulti *This = impl_from_IObjMgr(iface);
140 TRACE("(%p, %p)\n", This, obj);
141 if (obj == NULL)
142 return E_FAIL;
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;
151 This->nObjs++;
152 return S_OK;
155 static HRESULT WINAPI ACLMulti_Remove(IObjMgr *iface, IUnknown *obj)
157 ACLMulti *This = impl_from_IObjMgr(iface);
158 int i;
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));
166 This->nObjs--;
167 This->objs = heap_realloc(This->objs, sizeof(This->objs[0]) * This->nObjs);
168 return S_OK;
171 return E_FAIL;
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);
185 if (ret != S_FALSE)
186 return ret;
188 This->currObj++;
191 if (pceltFetched)
192 *pceltFetched = 0;
193 *rgelt = NULL;
194 return S_FALSE;
197 static HRESULT WINAPI ACLMulti_Reset(IEnumString *iface)
199 ACLMulti *This = (ACLMulti *)iface;
200 int i;
202 This->currObj = 0;
203 for (i = 0; i < This->nObjs; i++)
205 if (This->objs[i].pEnum)
206 IEnumString_Reset(This->objs[i].pEnum);
208 return S_OK;
211 static HRESULT WINAPI ACLMulti_Skip(IEnumString *iface, ULONG celt)
213 /* native browseui 6.0 returns this: */
214 return E_NOTIMPL;
217 static HRESULT WINAPI ACLMulti_Clone(IEnumString *iface, IEnumString **ppOut)
219 *ppOut = NULL;
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);
227 HRESULT res = S_OK;
228 int i;
230 for (i = 0; i < This->nObjs; i++)
232 if (!This->objs[i].pACL)
233 continue;
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) */
237 return res;
240 static const IEnumStringVtbl ACLMultiVtbl =
242 ACLMulti_QueryInterface,
243 ACLMulti_AddRef,
244 ACLMulti_Release,
246 ACLMulti_Next,
247 ACLMulti_Skip,
248 ACLMulti_Reset,
249 ACLMulti_Clone
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,
276 ACLMulti_Append,
277 ACLMulti_Remove
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,
304 ACLMulti_Expand
307 HRESULT ACLMulti_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
309 ACLMulti *This;
310 if (pUnkOuter)
311 return CLASS_E_NOAGGREGATION;
313 This = heap_alloc_zero(sizeof(ACLMulti));
314 if (This == NULL)
315 return E_OUTOFMEMORY;
317 This->vtbl = &ACLMultiVtbl;
318 This->aclVtbl = &ACLMulti_ACListVtbl;
319 This->objmgrVtbl = &ACLMulti_ObjMgrVtbl;
320 This->refCount = 1;
322 TRACE("returning %p\n", This);
323 *ppOut = (IUnknown *)This;
324 BROWSEUI_refCount++;
325 return S_OK;