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/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(browseui
);
45 struct ACLMultiSublist
{
51 typedef struct tagACLMulti
{
52 const IEnumStringVtbl
*vtbl
;
53 const IACListVtbl
*aclVtbl
;
54 const IObjMgrVtbl
*objmgrVtbl
;
58 struct ACLMultiSublist
*objs
;
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
);
79 IEnumString_Release(obj
->pEnum
);
81 IACList_Release(obj
->pACL
);
84 HRESULT WINAPI
ACLMulti_Constructor(IUnknown
*pUnkOuter
, IUnknown
**ppOut
)
88 return CLASS_E_NOAGGREGATION
;
90 This
= CoTaskMemAlloc(sizeof(ACLMulti
));
93 ZeroMemory(This
, sizeof(*This
));
94 This
->vtbl
= &ACLMultiVtbl
;
95 This
->aclVtbl
= &ACLMulti_ACListVtbl
;
96 This
->objmgrVtbl
= &ACLMulti_ObjMgrVtbl
;
99 TRACE("returning %p\n", This
);
100 *ppOut
= (IUnknown
*)This
;
105 static void WINAPI
ACLMulti_Destructor(ACLMulti
*This
)
108 TRACE("destroying %p\n", This
);
109 for (i
= 0; i
< This
->nObjs
; i
++)
110 release_obj(&This
->objs
[i
]);
111 CoTaskMemFree(This
->objs
);
116 static HRESULT WINAPI
ACLMulti_QueryInterface(IEnumString
*iface
, REFIID iid
, LPVOID
*ppvOut
)
118 ACLMulti
*This
= (ACLMulti
*)iface
;
121 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_IEnumString
))
125 else if (IsEqualIID(iid
, &IID_IACList
))
127 *ppvOut
= &This
->aclVtbl
;
129 else if (IsEqualIID(iid
, &IID_IObjMgr
))
131 *ppvOut
= &This
->objmgrVtbl
;
136 IUnknown_AddRef(iface
);
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
;
155 ret
= InterlockedDecrement(&This
->refCount
);
157 ACLMulti_Destructor(This
);
161 static HRESULT WINAPI
ACLMulti_Append(IObjMgr
*iface
, IUnknown
*obj
)
163 ACLMulti
*This
= impl_from_IObjMgr(iface
);
165 TRACE("(%p, %p)\n", This
, obj
);
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
;
180 static HRESULT WINAPI
ACLMulti_Remove(IObjMgr
*iface
, IUnknown
*obj
)
182 ACLMulti
*This
= impl_from_IObjMgr(iface
);
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
));
192 This
->objs
= CoTaskMemRealloc(This
->objs
, sizeof(This
->objs
[0]) * This
->nObjs
);
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
);
222 static HRESULT WINAPI
ACLMulti_Reset(IEnumString
*iface
)
224 ACLMulti
*This
= (ACLMulti
*)iface
;
228 for (i
= 0; i
< This
->nObjs
; i
++)
230 if (This
->objs
[i
].pEnum
)
231 IEnumString_Reset(This
->objs
[i
].pEnum
);
236 static HRESULT WINAPI
ACLMulti_Skip(IEnumString
*iface
, ULONG celt
)
238 /* native browseui 6.0 returns this: */
242 static HRESULT WINAPI
ACLMulti_Clone(IEnumString
*iface
, IEnumString
**ppOut
)
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
);
255 for (i
= 0; i
< This
->nObjs
; i
++)
257 if (!This
->objs
[i
].pACL
)
259 res
= IACList_Expand(This
->objs
[i
].pACL
, wstr
);
266 static const IEnumStringVtbl ACLMultiVtbl
=
268 ACLMulti_QueryInterface
,
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
,
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
,