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
27 #include "wine/debug.h"
39 #include "wine/heap.h"
40 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(browseui
);
46 struct ACLMultiSublist
{
52 typedef struct tagACLMulti
{
53 IEnumString IEnumString_iface
;
54 IACList IACList_iface
;
55 IObjMgr IObjMgr_iface
;
59 struct ACLMultiSublist
*objs
;
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
);
81 IEnumString_Release(obj
->pEnum
);
83 IACList_Release(obj
->pACL
);
86 static void ACLMulti_Destructor(ACLMulti
*This
)
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
);
97 static HRESULT WINAPI
ACLMulti_QueryInterface(IEnumString
*iface
, REFIID iid
, LPVOID
*ppvOut
)
99 ACLMulti
*This
= impl_from_IEnumString(iface
);
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
;
117 IEnumString_AddRef(iface
);
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
);
136 ret
= InterlockedDecrement(&This
->refCount
);
138 ACLMulti_Destructor(This
);
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
);
165 static HRESULT WINAPI
ACLMulti_Reset(IEnumString
*iface
)
167 ACLMulti
*This
= impl_from_IEnumString(iface
);
171 for (i
= 0; i
< This
->nObjs
; i
++)
173 if (This
->objs
[i
].pEnum
)
174 IEnumString_Reset(This
->objs
[i
].pEnum
);
179 static HRESULT WINAPI
ACLMulti_Skip(IEnumString
*iface
, ULONG celt
)
181 /* native browseui 6.0 returns this: */
185 static HRESULT WINAPI
ACLMulti_Clone(IEnumString
*iface
, IEnumString
**ppOut
)
188 /* native browseui 6.0 returns this: */
189 return E_OUTOFMEMORY
;
192 static const IEnumStringVtbl ACLMultiVtbl
=
194 ACLMulti_QueryInterface
,
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
);
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
;
241 static HRESULT WINAPI
ACLMulti_Remove(IObjMgr
*iface
, IUnknown
*obj
)
243 ACLMulti
*This
= impl_from_IObjMgr(iface
);
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
));
253 This
->objs
= heap_realloc(This
->objs
, sizeof(This
->objs
[0]) * This
->nObjs
);
260 static const IObjMgrVtbl ACLMulti_ObjMgrVtbl
=
262 ACLMulti_IObjMgr_QueryInterface
,
263 ACLMulti_IObjMgr_AddRef
,
264 ACLMulti_IObjMgr_Release
,
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
);
294 for (i
= 0; i
< This
->nObjs
; i
++)
296 if (!This
->objs
[i
].pACL
)
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) */
304 static const IACListVtbl ACLMulti_ACListVtbl
=
306 ACLMulti_IACList_QueryInterface
,
307 ACLMulti_IACList_AddRef
,
308 ACLMulti_IACList_Release
,
313 HRESULT
ACLMulti_Constructor(IUnknown
*pUnkOuter
, IUnknown
**ppOut
)
317 return CLASS_E_NOAGGREGATION
;
319 This
= heap_alloc_zero(sizeof(ACLMulti
));
321 return E_OUTOFMEMORY
;
323 This
->IEnumString_iface
.lpVtbl
= &ACLMultiVtbl
;
324 This
->IACList_iface
.lpVtbl
= &ACLMulti_ACListVtbl
;
325 This
->IObjMgr_iface
.lpVtbl
= &ACLMulti_ObjMgrVtbl
;
328 TRACE("returning %p\n", This
);
329 *ppOut
= (IUnknown
*)&This
->IEnumString_iface
;