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
24 #include <libxml/parser.h>
25 #include <libxml/xmlerror.h>
33 #include "msxml2did.h"
35 #include "msxml_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
44 IXMLDOMNamedNodeMap IXMLDOMNamedNodeMap_iface
;
45 ISupportErrorInfo ISupportErrorInfo_iface
;
50 IEnumVARIANT
*enumvariant
;
52 const struct nodemap_funcs
*funcs
;
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
= {
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
) )
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
;
109 TRACE("interface %s not implemented\n", debugstr_guid(riid
));
111 return E_NOINTERFACE
;
114 IXMLDOMNamedNodeMap_AddRef( iface
);
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
);
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
);
137 xmlnode_release( This
->node
);
138 xmldoc_release( This
->node
->doc
);
139 if (This
->enumvariant
) IEnumVARIANT_Release(This
->enumvariant
);
146 static HRESULT WINAPI
xmlnodemap_GetTypeInfoCount(
147 IXMLDOMNamedNodeMap
*iface
,
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
,
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
,
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
,
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
,
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
,
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
,
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
);
293 static HRESULT WINAPI
xmlnodemap__newEnum(
294 IXMLDOMNamedNodeMap
*iface
,
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
,
307 xmlnodemap_GetTypeInfoCount
,
308 xmlnodemap_GetTypeInfo
,
309 xmlnodemap_GetIDsOfNames
,
311 xmlnodemap_getNamedItem
,
312 xmlnodemap_setNamedItem
,
313 xmlnodemap_removeNamedItem
,
315 xmlnodemap_get_length
,
316 xmlnodemap_getQualifiedItem
,
317 xmlnodemap_removeQualifiedItem
,
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
,
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
)
368 for(ptr
= name
; *ptr
>= '0' && *ptr
<= '9'; ptr
++)
369 idx
= idx
*10 + (*ptr
-'0');
371 return DISP_E_UNKNOWNNAME
;
373 *dispid
= DISPID_DOM_COLLECTION_BASE
+ idx
;
374 TRACE("ret %x\n", *dispid
);
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
;
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
;
403 FIXME("unimplemented flags %x\n", flags
);
408 TRACE("ret %p\n", V_DISPATCH(res
));
413 static const dispex_static_data_vtbl_t xmlnodemap_dispex_vtbl
= {
414 xmlnodemap_get_dispid
,
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
,
427 xmlnodemap_iface_tids
430 IXMLDOMNamedNodeMap
*create_nodemap(xmlNodePtr node
, const struct nodemap_funcs
*funcs
)
434 This
= heap_alloc( sizeof *This
);
438 This
->IXMLDOMNamedNodeMap_iface
.lpVtbl
= &XMLDOMNamedNodeMapVtbl
;
439 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
443 This
->enumvariant
= NULL
;
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
;