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
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
37 #include "msxml2did.h"
39 #include "msxml_private.h"
41 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
50 IXMLDOMNamedNodeMap IXMLDOMNamedNodeMap_iface
;
51 ISupportErrorInfo ISupportErrorInfo_iface
;
56 IEnumVARIANT
*enumvariant
;
58 const struct nodemap_funcs
*funcs
;
61 static HRESULT
nodemap_get_item(IUnknown
*iface
, LONG index
, VARIANT
*item
)
63 V_VT(item
) = VT_DISPATCH
;
64 return IXMLDOMNamedNodeMap_get_item((IXMLDOMNamedNodeMap
*)iface
, index
, (IXMLDOMNode
**)&V_DISPATCH(item
));
67 static const struct enumvariant_funcs nodemap_enumvariant
= {
72 static inline xmlnodemap
*impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap
*iface
)
74 return CONTAINING_RECORD(iface
, xmlnodemap
, IXMLDOMNamedNodeMap_iface
);
77 static inline xmlnodemap
*impl_from_ISupportErrorInfo( ISupportErrorInfo
*iface
)
79 return CONTAINING_RECORD(iface
, xmlnodemap
, ISupportErrorInfo_iface
);
82 static HRESULT WINAPI
xmlnodemap_QueryInterface(
83 IXMLDOMNamedNodeMap
*iface
,
84 REFIID riid
, void** ppvObject
)
86 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
87 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppvObject
);
89 if( IsEqualGUID( riid
, &IID_IUnknown
) ||
90 IsEqualGUID( riid
, &IID_IDispatch
) ||
91 IsEqualGUID( riid
, &IID_IXMLDOMNamedNodeMap
) )
95 else if (IsEqualGUID( riid
, &IID_IEnumVARIANT
))
97 if (!This
->enumvariant
)
99 HRESULT hr
= create_enumvariant((IUnknown
*)iface
, FALSE
, &nodemap_enumvariant
, &This
->enumvariant
);
100 if (FAILED(hr
)) return hr
;
103 return IEnumVARIANT_QueryInterface(This
->enumvariant
, &IID_IEnumVARIANT
, ppvObject
);
105 else if (dispex_query_interface(&This
->dispex
, riid
, ppvObject
))
107 return *ppvObject
? S_OK
: E_NOINTERFACE
;
109 else if( IsEqualGUID( riid
, &IID_ISupportErrorInfo
))
111 *ppvObject
= &This
->ISupportErrorInfo_iface
;
115 TRACE("interface %s not implemented\n", debugstr_guid(riid
));
117 return E_NOINTERFACE
;
120 IXMLDOMNamedNodeMap_AddRef( iface
);
125 static ULONG WINAPI
xmlnodemap_AddRef(
126 IXMLDOMNamedNodeMap
*iface
)
128 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
129 ULONG ref
= InterlockedIncrement( &This
->ref
);
130 TRACE("(%p)->(%d)\n", This
, ref
);
134 static ULONG WINAPI
xmlnodemap_Release(
135 IXMLDOMNamedNodeMap
*iface
)
137 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
138 ULONG ref
= InterlockedDecrement( &This
->ref
);
140 TRACE("(%p)->(%d)\n", This
, ref
);
143 xmlnode_release( This
->node
);
144 xmldoc_release( This
->node
->doc
);
145 if (This
->enumvariant
) IEnumVARIANT_Release(This
->enumvariant
);
152 static HRESULT WINAPI
xmlnodemap_GetTypeInfoCount(
153 IXMLDOMNamedNodeMap
*iface
,
156 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
157 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
160 static HRESULT WINAPI
xmlnodemap_GetTypeInfo(
161 IXMLDOMNamedNodeMap
*iface
,
162 UINT iTInfo
, LCID lcid
,
163 ITypeInfo
** ppTInfo
)
165 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
166 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
167 iTInfo
, lcid
, ppTInfo
);
170 static HRESULT WINAPI
xmlnodemap_GetIDsOfNames(
171 IXMLDOMNamedNodeMap
*iface
,
172 REFIID riid
, LPOLESTR
* rgszNames
,
173 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
175 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
176 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
177 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
180 static HRESULT WINAPI
xmlnodemap_Invoke(
181 IXMLDOMNamedNodeMap
*iface
,
182 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
183 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
184 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
186 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
187 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
188 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
191 static HRESULT WINAPI
xmlnodemap_getNamedItem(
192 IXMLDOMNamedNodeMap
*iface
,
196 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
198 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(name
), item
);
200 return This
->funcs
->get_named_item(This
->node
, name
, item
);
203 static HRESULT WINAPI
xmlnodemap_setNamedItem(
204 IXMLDOMNamedNodeMap
*iface
,
205 IXMLDOMNode
* newItem
,
206 IXMLDOMNode
** namedItem
)
208 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
210 TRACE("(%p)->(%p %p)\n", This
, newItem
, namedItem
);
212 return This
->funcs
->set_named_item(This
->node
, newItem
, namedItem
);
215 static HRESULT WINAPI
xmlnodemap_removeNamedItem(
216 IXMLDOMNamedNodeMap
*iface
,
218 IXMLDOMNode
** namedItem
)
220 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
222 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(name
), namedItem
);
224 return This
->funcs
->remove_named_item(This
->node
, name
, namedItem
);
227 static HRESULT WINAPI
xmlnodemap_get_item(
228 IXMLDOMNamedNodeMap
*iface
,
232 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
234 TRACE("(%p)->(%d %p)\n", This
, index
, item
);
236 return This
->funcs
->get_item(This
->node
, index
, item
);
239 static HRESULT WINAPI
xmlnodemap_get_length(
240 IXMLDOMNamedNodeMap
*iface
,
243 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
245 TRACE("(%p)->(%p)\n", This
, length
);
247 return This
->funcs
->get_length(This
->node
, length
);
250 static HRESULT WINAPI
xmlnodemap_getQualifiedItem(
251 IXMLDOMNamedNodeMap
*iface
,
256 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
258 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_w(baseName
), debugstr_w(namespaceURI
), item
);
260 return This
->funcs
->get_qualified_item(This
->node
, baseName
, namespaceURI
, item
);
263 static HRESULT WINAPI
xmlnodemap_removeQualifiedItem(
264 IXMLDOMNamedNodeMap
*iface
,
269 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
271 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_w(baseName
), debugstr_w(namespaceURI
), item
);
273 return This
->funcs
->remove_qualified_item(This
->node
, baseName
, namespaceURI
, item
);
276 static HRESULT WINAPI
xmlnodemap_nextNode(
277 IXMLDOMNamedNodeMap
*iface
,
278 IXMLDOMNode
** nextItem
)
280 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
282 TRACE("(%p)->(%p: %d)\n", This
, nextItem
, This
->iterator
);
284 return This
->funcs
->next_node(This
->node
, &This
->iterator
, nextItem
);
287 static HRESULT WINAPI
xmlnodemap_reset(
288 IXMLDOMNamedNodeMap
*iface
)
290 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
292 TRACE("(%p)->(%d)\n", This
, This
->iterator
);
299 static HRESULT WINAPI
xmlnodemap__newEnum(
300 IXMLDOMNamedNodeMap
*iface
,
303 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
304 TRACE("(%p)->(%p)\n", This
, enumv
);
305 return create_enumvariant((IUnknown
*)iface
, TRUE
, &nodemap_enumvariant
, (IEnumVARIANT
**)enumv
);
308 static const struct IXMLDOMNamedNodeMapVtbl XMLDOMNamedNodeMapVtbl
=
310 xmlnodemap_QueryInterface
,
313 xmlnodemap_GetTypeInfoCount
,
314 xmlnodemap_GetTypeInfo
,
315 xmlnodemap_GetIDsOfNames
,
317 xmlnodemap_getNamedItem
,
318 xmlnodemap_setNamedItem
,
319 xmlnodemap_removeNamedItem
,
321 xmlnodemap_get_length
,
322 xmlnodemap_getQualifiedItem
,
323 xmlnodemap_removeQualifiedItem
,
329 static HRESULT WINAPI
support_error_QueryInterface(
330 ISupportErrorInfo
*iface
,
331 REFIID riid
, void** ppvObject
)
333 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
334 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
335 return IXMLDOMNamedNodeMap_QueryInterface(&This
->IXMLDOMNamedNodeMap_iface
, riid
, ppvObject
);
338 static ULONG WINAPI
support_error_AddRef(
339 ISupportErrorInfo
*iface
)
341 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
342 return IXMLDOMNamedNodeMap_AddRef(&This
->IXMLDOMNamedNodeMap_iface
);
345 static ULONG WINAPI
support_error_Release(
346 ISupportErrorInfo
*iface
)
348 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
349 return IXMLDOMNamedNodeMap_Release(&This
->IXMLDOMNamedNodeMap_iface
);
352 static HRESULT WINAPI
support_error_InterfaceSupportsErrorInfo(
353 ISupportErrorInfo
*iface
,
356 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
357 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
358 return IsEqualGUID(riid
, &IID_IXMLDOMNamedNodeMap
) ? S_OK
: S_FALSE
;
361 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
=
363 support_error_QueryInterface
,
364 support_error_AddRef
,
365 support_error_Release
,
366 support_error_InterfaceSupportsErrorInfo
369 static HRESULT
xmlnodemap_get_dispid(IUnknown
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
374 for(ptr
= name
; *ptr
>= '0' && *ptr
<= '9'; ptr
++)
375 idx
= idx
*10 + (*ptr
-'0');
377 return DISP_E_UNKNOWNNAME
;
379 *dispid
= DISPID_DOM_COLLECTION_BASE
+ idx
;
380 TRACE("ret %x\n", *dispid
);
384 static HRESULT
xmlnodemap_invoke(IUnknown
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
385 VARIANT
*res
, EXCEPINFO
*ei
)
387 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( (IXMLDOMNamedNodeMap
*)iface
);
389 TRACE("(%p)->(%x %x %x %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
);
391 V_VT(res
) = VT_DISPATCH
;
392 V_DISPATCH(res
) = NULL
;
394 if (id
< DISPID_DOM_COLLECTION_BASE
|| id
> DISPID_DOM_COLLECTION_MAX
)
395 return DISP_E_UNKNOWNNAME
;
399 case INVOKE_PROPERTYGET
:
401 IXMLDOMNode
*disp
= NULL
;
403 IXMLDOMNamedNodeMap_get_item(&This
->IXMLDOMNamedNodeMap_iface
, id
- DISPID_DOM_COLLECTION_BASE
, &disp
);
404 V_DISPATCH(res
) = (IDispatch
*)disp
;
409 FIXME("unimplemented flags %x\n", flags
);
414 TRACE("ret %p\n", V_DISPATCH(res
));
419 static const dispex_static_data_vtbl_t xmlnodemap_dispex_vtbl
= {
420 xmlnodemap_get_dispid
,
424 static const tid_t xmlnodemap_iface_tids
[] = {
425 IXMLDOMNamedNodeMap_tid
,
429 static dispex_static_data_t xmlnodemap_dispex
= {
430 &xmlnodemap_dispex_vtbl
,
431 IXMLDOMNamedNodeMap_tid
,
433 xmlnodemap_iface_tids
436 IXMLDOMNamedNodeMap
*create_nodemap(xmlNodePtr node
, const struct nodemap_funcs
*funcs
)
440 This
= heap_alloc( sizeof *This
);
444 This
->IXMLDOMNamedNodeMap_iface
.lpVtbl
= &XMLDOMNamedNodeMapVtbl
;
445 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
449 This
->enumvariant
= NULL
;
452 init_dispex(&This
->dispex
, (IUnknown
*)&This
->IXMLDOMNamedNodeMap_iface
, &xmlnodemap_dispex
);
454 xmlnode_add_ref(node
);
455 xmldoc_add_ref(node
->doc
);
457 return &This
->IXMLDOMNamedNodeMap_iface
;