wined3d: Use wined3d_bit_scan() in context_preload_textures().
[wine.git] / dlls / msxml3 / nodemap.c
blobafe7065dfd983342361782e7f7039a62bae1f80d
1 /*
2 * Node map implementation
4 * Copyright 2005 Mike McCormack
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 #define COBJMACROS
23 #include <stdarg.h>
24 #include <libxml/parser.h>
25 #include <libxml/xmlerror.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "ole2.h"
32 #include "msxml6.h"
33 #include "msxml2did.h"
35 #include "msxml_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
41 typedef struct
43 DispatchEx dispex;
44 IXMLDOMNamedNodeMap IXMLDOMNamedNodeMap_iface;
45 ISupportErrorInfo ISupportErrorInfo_iface;
46 LONG ref;
48 xmlNodePtr node;
49 LONG iterator;
50 IEnumVARIANT *enumvariant;
52 const struct nodemap_funcs *funcs;
53 } xmlnodemap;
55 static HRESULT nodemap_get_item(IUnknown *iface, LONG index, VARIANT *item)
57 V_VT(item) = VT_DISPATCH;
58 return IXMLDOMNamedNodeMap_get_item((IXMLDOMNamedNodeMap*)iface, index, (IXMLDOMNode**)&V_DISPATCH(item));
61 static const struct enumvariant_funcs nodemap_enumvariant = {
62 nodemap_get_item,
63 NULL
66 static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface )
68 return CONTAINING_RECORD(iface, xmlnodemap, IXMLDOMNamedNodeMap_iface);
71 static inline xmlnodemap *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface )
73 return CONTAINING_RECORD(iface, xmlnodemap, ISupportErrorInfo_iface);
76 static HRESULT WINAPI xmlnodemap_QueryInterface(
77 IXMLDOMNamedNodeMap *iface,
78 REFIID riid, void** ppvObject )
80 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
81 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
83 if( IsEqualGUID( riid, &IID_IUnknown ) ||
84 IsEqualGUID( riid, &IID_IDispatch ) ||
85 IsEqualGUID( riid, &IID_IXMLDOMNamedNodeMap ) )
87 *ppvObject = iface;
89 else if (IsEqualGUID( riid, &IID_IEnumVARIANT ))
91 if (!This->enumvariant)
93 HRESULT hr = create_enumvariant((IUnknown*)iface, FALSE, &nodemap_enumvariant, &This->enumvariant);
94 if (FAILED(hr)) return hr;
97 return IEnumVARIANT_QueryInterface(This->enumvariant, &IID_IEnumVARIANT, ppvObject);
99 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
101 return *ppvObject ? S_OK : E_NOINTERFACE;
103 else if( IsEqualGUID( riid, &IID_ISupportErrorInfo ))
105 *ppvObject = &This->ISupportErrorInfo_iface;
107 else
109 TRACE("interface %s not implemented\n", debugstr_guid(riid));
110 *ppvObject = NULL;
111 return E_NOINTERFACE;
114 IXMLDOMNamedNodeMap_AddRef( iface );
116 return S_OK;
119 static ULONG WINAPI xmlnodemap_AddRef(
120 IXMLDOMNamedNodeMap *iface )
122 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
123 ULONG ref = InterlockedIncrement( &This->ref );
124 TRACE("(%p)->(%d)\n", This, ref);
125 return ref;
128 static ULONG WINAPI xmlnodemap_Release(
129 IXMLDOMNamedNodeMap *iface )
131 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
132 ULONG ref = InterlockedDecrement( &This->ref );
134 TRACE("(%p)->(%d)\n", This, ref);
135 if ( ref == 0 )
137 xmlnode_release( This->node );
138 xmldoc_release( This->node->doc );
139 if (This->enumvariant) IEnumVARIANT_Release(This->enumvariant);
140 heap_free( This );
143 return ref;
146 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount(
147 IXMLDOMNamedNodeMap *iface,
148 UINT* pctinfo )
150 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
151 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
154 static HRESULT WINAPI xmlnodemap_GetTypeInfo(
155 IXMLDOMNamedNodeMap *iface,
156 UINT iTInfo, LCID lcid,
157 ITypeInfo** ppTInfo )
159 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
160 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
161 iTInfo, lcid, ppTInfo);
164 static HRESULT WINAPI xmlnodemap_GetIDsOfNames(
165 IXMLDOMNamedNodeMap *iface,
166 REFIID riid, LPOLESTR* rgszNames,
167 UINT cNames, LCID lcid, DISPID* rgDispId )
169 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
170 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
171 riid, rgszNames, cNames, lcid, rgDispId);
174 static HRESULT WINAPI xmlnodemap_Invoke(
175 IXMLDOMNamedNodeMap *iface,
176 DISPID dispIdMember, REFIID riid, LCID lcid,
177 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
178 EXCEPINFO* pExcepInfo, UINT* puArgErr )
180 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
181 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
182 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
185 static HRESULT WINAPI xmlnodemap_getNamedItem(
186 IXMLDOMNamedNodeMap *iface,
187 BSTR name,
188 IXMLDOMNode** item)
190 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
192 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), item );
194 return This->funcs->get_named_item(This->node, name, item);
197 static HRESULT WINAPI xmlnodemap_setNamedItem(
198 IXMLDOMNamedNodeMap *iface,
199 IXMLDOMNode* newItem,
200 IXMLDOMNode** namedItem)
202 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
204 TRACE("(%p)->(%p %p)\n", This, newItem, namedItem );
206 return This->funcs->set_named_item(This->node, newItem, namedItem);
209 static HRESULT WINAPI xmlnodemap_removeNamedItem(
210 IXMLDOMNamedNodeMap *iface,
211 BSTR name,
212 IXMLDOMNode** namedItem)
214 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
216 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), namedItem );
218 return This->funcs->remove_named_item(This->node, name, namedItem);
221 static HRESULT WINAPI xmlnodemap_get_item(
222 IXMLDOMNamedNodeMap *iface,
223 LONG index,
224 IXMLDOMNode** item)
226 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
228 TRACE("(%p)->(%d %p)\n", This, index, item);
230 return This->funcs->get_item(This->node, index, item);
233 static HRESULT WINAPI xmlnodemap_get_length(
234 IXMLDOMNamedNodeMap *iface,
235 LONG *length)
237 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
239 TRACE("(%p)->(%p)\n", This, length);
241 return This->funcs->get_length(This->node, length);
244 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
245 IXMLDOMNamedNodeMap *iface,
246 BSTR baseName,
247 BSTR namespaceURI,
248 IXMLDOMNode** item)
250 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
252 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), item);
254 return This->funcs->get_qualified_item(This->node, baseName, namespaceURI, item);
257 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
258 IXMLDOMNamedNodeMap *iface,
259 BSTR baseName,
260 BSTR namespaceURI,
261 IXMLDOMNode** item)
263 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
265 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), item);
267 return This->funcs->remove_qualified_item(This->node, baseName, namespaceURI, item);
270 static HRESULT WINAPI xmlnodemap_nextNode(
271 IXMLDOMNamedNodeMap *iface,
272 IXMLDOMNode** nextItem)
274 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
276 TRACE("(%p)->(%p: %d)\n", This, nextItem, This->iterator);
278 return This->funcs->next_node(This->node, &This->iterator, nextItem);
281 static HRESULT WINAPI xmlnodemap_reset(
282 IXMLDOMNamedNodeMap *iface )
284 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
286 TRACE("(%p)->(%d)\n", This, This->iterator);
288 This->iterator = 0;
290 return S_OK;
293 static HRESULT WINAPI xmlnodemap__newEnum(
294 IXMLDOMNamedNodeMap *iface,
295 IUnknown** enumv)
297 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
298 TRACE("(%p)->(%p)\n", This, enumv);
299 return create_enumvariant((IUnknown*)iface, TRUE, &nodemap_enumvariant, (IEnumVARIANT**)enumv);
302 static const struct IXMLDOMNamedNodeMapVtbl XMLDOMNamedNodeMapVtbl =
304 xmlnodemap_QueryInterface,
305 xmlnodemap_AddRef,
306 xmlnodemap_Release,
307 xmlnodemap_GetTypeInfoCount,
308 xmlnodemap_GetTypeInfo,
309 xmlnodemap_GetIDsOfNames,
310 xmlnodemap_Invoke,
311 xmlnodemap_getNamedItem,
312 xmlnodemap_setNamedItem,
313 xmlnodemap_removeNamedItem,
314 xmlnodemap_get_item,
315 xmlnodemap_get_length,
316 xmlnodemap_getQualifiedItem,
317 xmlnodemap_removeQualifiedItem,
318 xmlnodemap_nextNode,
319 xmlnodemap_reset,
320 xmlnodemap__newEnum,
323 static HRESULT WINAPI support_error_QueryInterface(
324 ISupportErrorInfo *iface,
325 REFIID riid, void** ppvObject )
327 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
328 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
329 return IXMLDOMNamedNodeMap_QueryInterface(&This->IXMLDOMNamedNodeMap_iface, riid, ppvObject);
332 static ULONG WINAPI support_error_AddRef(
333 ISupportErrorInfo *iface )
335 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
336 return IXMLDOMNamedNodeMap_AddRef(&This->IXMLDOMNamedNodeMap_iface);
339 static ULONG WINAPI support_error_Release(
340 ISupportErrorInfo *iface )
342 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
343 return IXMLDOMNamedNodeMap_Release(&This->IXMLDOMNamedNodeMap_iface);
346 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo(
347 ISupportErrorInfo *iface,
348 REFIID riid )
350 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
351 TRACE("(%p)->(%s)\n", This, debugstr_guid(riid));
352 return IsEqualGUID(riid, &IID_IXMLDOMNamedNodeMap) ? S_OK : S_FALSE;
355 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl =
357 support_error_QueryInterface,
358 support_error_AddRef,
359 support_error_Release,
360 support_error_InterfaceSupportsErrorInfo
363 static HRESULT xmlnodemap_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
365 WCHAR *ptr;
366 int idx = 0;
368 for(ptr = name; *ptr >= '0' && *ptr <= '9'; ptr++)
369 idx = idx*10 + (*ptr-'0');
370 if(*ptr)
371 return DISP_E_UNKNOWNNAME;
373 *dispid = DISPID_DOM_COLLECTION_BASE + idx;
374 TRACE("ret %x\n", *dispid);
375 return S_OK;
378 static HRESULT xmlnodemap_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
379 VARIANT *res, EXCEPINFO *ei)
381 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( (IXMLDOMNamedNodeMap*)iface );
383 TRACE("(%p)->(%x %x %x %p %p %p)\n", This, id, lcid, flags, params, res, ei);
385 V_VT(res) = VT_DISPATCH;
386 V_DISPATCH(res) = NULL;
388 if (id < DISPID_DOM_COLLECTION_BASE || id > DISPID_DOM_COLLECTION_MAX)
389 return DISP_E_UNKNOWNNAME;
391 switch(flags)
393 case INVOKE_PROPERTYGET:
395 IXMLDOMNode *disp = NULL;
397 IXMLDOMNamedNodeMap_get_item(&This->IXMLDOMNamedNodeMap_iface, id - DISPID_DOM_COLLECTION_BASE, &disp);
398 V_DISPATCH(res) = (IDispatch*)disp;
399 break;
401 default:
403 FIXME("unimplemented flags %x\n", flags);
404 break;
408 TRACE("ret %p\n", V_DISPATCH(res));
410 return S_OK;
413 static const dispex_static_data_vtbl_t xmlnodemap_dispex_vtbl = {
414 xmlnodemap_get_dispid,
415 xmlnodemap_invoke
418 static const tid_t xmlnodemap_iface_tids[] = {
419 IXMLDOMNamedNodeMap_tid,
423 static dispex_static_data_t xmlnodemap_dispex = {
424 &xmlnodemap_dispex_vtbl,
425 IXMLDOMNamedNodeMap_tid,
426 NULL,
427 xmlnodemap_iface_tids
430 IXMLDOMNamedNodeMap *create_nodemap(xmlNodePtr node, const struct nodemap_funcs *funcs)
432 xmlnodemap *This;
434 This = heap_alloc( sizeof *This );
435 if ( !This )
436 return NULL;
438 This->IXMLDOMNamedNodeMap_iface.lpVtbl = &XMLDOMNamedNodeMapVtbl;
439 This->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
440 This->node = node;
441 This->ref = 1;
442 This->iterator = 0;
443 This->enumvariant = NULL;
444 This->funcs = funcs;
446 init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMNamedNodeMap_iface, &xmlnodemap_dispex);
448 xmlnode_add_ref(node);
449 xmldoc_add_ref(node->doc);
451 return &This->IXMLDOMNamedNodeMap_iface;