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, refcount %lu.\n", iface
, 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, refcount %lu.\n", iface
, ref
);
138 xmlnode_release( This
->node
);
139 xmldoc_release( This
->node
->doc
);
140 if (This
->enumvariant
) IEnumVARIANT_Release(This
->enumvariant
);
147 static HRESULT WINAPI
xmlnodemap_GetTypeInfoCount(
148 IXMLDOMNamedNodeMap
*iface
,
151 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
152 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
155 static HRESULT WINAPI
xmlnodemap_GetTypeInfo(
156 IXMLDOMNamedNodeMap
*iface
,
157 UINT iTInfo
, LCID lcid
,
158 ITypeInfo
** ppTInfo
)
160 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
161 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
162 iTInfo
, lcid
, ppTInfo
);
165 static HRESULT WINAPI
xmlnodemap_GetIDsOfNames(
166 IXMLDOMNamedNodeMap
*iface
,
167 REFIID riid
, LPOLESTR
* rgszNames
,
168 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
170 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
171 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
172 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
175 static HRESULT WINAPI
xmlnodemap_Invoke(
176 IXMLDOMNamedNodeMap
*iface
,
177 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
178 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
179 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
181 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
182 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
183 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
186 static HRESULT WINAPI
xmlnodemap_getNamedItem(
187 IXMLDOMNamedNodeMap
*iface
,
191 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
193 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(name
), item
);
195 return This
->funcs
->get_named_item(This
->node
, name
, item
);
198 static HRESULT WINAPI
xmlnodemap_setNamedItem(
199 IXMLDOMNamedNodeMap
*iface
,
200 IXMLDOMNode
* newItem
,
201 IXMLDOMNode
** namedItem
)
203 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
205 TRACE("(%p)->(%p %p)\n", This
, newItem
, namedItem
);
207 return This
->funcs
->set_named_item(This
->node
, newItem
, namedItem
);
210 static HRESULT WINAPI
xmlnodemap_removeNamedItem(
211 IXMLDOMNamedNodeMap
*iface
,
213 IXMLDOMNode
** namedItem
)
215 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
217 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(name
), namedItem
);
219 return This
->funcs
->remove_named_item(This
->node
, name
, namedItem
);
222 static HRESULT WINAPI
xmlnodemap_get_item(
223 IXMLDOMNamedNodeMap
*iface
,
227 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
229 TRACE("%p, %ld, %p.\n", iface
, index
, item
);
231 return This
->funcs
->get_item(This
->node
, index
, item
);
234 static HRESULT WINAPI
xmlnodemap_get_length(
235 IXMLDOMNamedNodeMap
*iface
,
238 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
240 TRACE("(%p)->(%p)\n", This
, length
);
242 return This
->funcs
->get_length(This
->node
, length
);
245 static HRESULT WINAPI
xmlnodemap_getQualifiedItem(
246 IXMLDOMNamedNodeMap
*iface
,
251 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
253 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_w(baseName
), debugstr_w(namespaceURI
), item
);
255 return This
->funcs
->get_qualified_item(This
->node
, baseName
, namespaceURI
, item
);
258 static HRESULT WINAPI
xmlnodemap_removeQualifiedItem(
259 IXMLDOMNamedNodeMap
*iface
,
264 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
266 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_w(baseName
), debugstr_w(namespaceURI
), item
);
268 return This
->funcs
->remove_qualified_item(This
->node
, baseName
, namespaceURI
, item
);
271 static HRESULT WINAPI
xmlnodemap_nextNode(
272 IXMLDOMNamedNodeMap
*iface
,
273 IXMLDOMNode
** nextItem
)
275 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
277 TRACE("%p, %p, %ld.\n", iface
, nextItem
, This
->iterator
);
279 return This
->funcs
->next_node(This
->node
, &This
->iterator
, nextItem
);
282 static HRESULT WINAPI
xmlnodemap_reset(
283 IXMLDOMNamedNodeMap
*iface
)
285 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
287 TRACE("%p, %ld.\n", iface
, This
->iterator
);
294 static HRESULT WINAPI
xmlnodemap__newEnum(
295 IXMLDOMNamedNodeMap
*iface
,
298 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
299 TRACE("(%p)->(%p)\n", This
, enumv
);
300 return create_enumvariant((IUnknown
*)iface
, TRUE
, &nodemap_enumvariant
, (IEnumVARIANT
**)enumv
);
303 static const struct IXMLDOMNamedNodeMapVtbl XMLDOMNamedNodeMapVtbl
=
305 xmlnodemap_QueryInterface
,
308 xmlnodemap_GetTypeInfoCount
,
309 xmlnodemap_GetTypeInfo
,
310 xmlnodemap_GetIDsOfNames
,
312 xmlnodemap_getNamedItem
,
313 xmlnodemap_setNamedItem
,
314 xmlnodemap_removeNamedItem
,
316 xmlnodemap_get_length
,
317 xmlnodemap_getQualifiedItem
,
318 xmlnodemap_removeQualifiedItem
,
324 static HRESULT WINAPI
support_error_QueryInterface(
325 ISupportErrorInfo
*iface
,
326 REFIID riid
, void** ppvObject
)
328 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
329 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
330 return IXMLDOMNamedNodeMap_QueryInterface(&This
->IXMLDOMNamedNodeMap_iface
, riid
, ppvObject
);
333 static ULONG WINAPI
support_error_AddRef(
334 ISupportErrorInfo
*iface
)
336 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
337 return IXMLDOMNamedNodeMap_AddRef(&This
->IXMLDOMNamedNodeMap_iface
);
340 static ULONG WINAPI
support_error_Release(
341 ISupportErrorInfo
*iface
)
343 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
344 return IXMLDOMNamedNodeMap_Release(&This
->IXMLDOMNamedNodeMap_iface
);
347 static HRESULT WINAPI
support_error_InterfaceSupportsErrorInfo(
348 ISupportErrorInfo
*iface
,
351 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
352 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
353 return IsEqualGUID(riid
, &IID_IXMLDOMNamedNodeMap
) ? S_OK
: S_FALSE
;
356 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
=
358 support_error_QueryInterface
,
359 support_error_AddRef
,
360 support_error_Release
,
361 support_error_InterfaceSupportsErrorInfo
364 static HRESULT
xmlnodemap_get_dispid(IUnknown
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
369 for(ptr
= name
; *ptr
>= '0' && *ptr
<= '9'; ptr
++)
370 idx
= idx
*10 + (*ptr
-'0');
372 return DISP_E_UNKNOWNNAME
;
374 *dispid
= DISPID_DOM_COLLECTION_BASE
+ idx
;
375 TRACE("ret %lx\n", *dispid
);
379 static HRESULT
xmlnodemap_invoke(IUnknown
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
380 VARIANT
*res
, EXCEPINFO
*ei
)
382 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( (IXMLDOMNamedNodeMap
*)iface
);
384 TRACE("%p, %ld, %lx, %x, %p, %p, %p.\n", iface
, id
, lcid
, flags
, params
, res
, ei
);
386 V_VT(res
) = VT_DISPATCH
;
387 V_DISPATCH(res
) = NULL
;
389 if (id
< DISPID_DOM_COLLECTION_BASE
|| id
> DISPID_DOM_COLLECTION_MAX
)
390 return DISP_E_UNKNOWNNAME
;
394 case INVOKE_PROPERTYGET
:
396 IXMLDOMNode
*disp
= NULL
;
398 IXMLDOMNamedNodeMap_get_item(&This
->IXMLDOMNamedNodeMap_iface
, id
- DISPID_DOM_COLLECTION_BASE
, &disp
);
399 V_DISPATCH(res
) = (IDispatch
*)disp
;
404 FIXME("unimplemented flags %x\n", flags
);
409 TRACE("ret %p\n", V_DISPATCH(res
));
414 static const dispex_static_data_vtbl_t xmlnodemap_dispex_vtbl
= {
415 xmlnodemap_get_dispid
,
419 static const tid_t xmlnodemap_iface_tids
[] = {
420 IXMLDOMNamedNodeMap_tid
,
424 static dispex_static_data_t xmlnodemap_dispex
= {
425 &xmlnodemap_dispex_vtbl
,
426 IXMLDOMNamedNodeMap_tid
,
428 xmlnodemap_iface_tids
431 IXMLDOMNamedNodeMap
*create_nodemap(xmlNodePtr node
, const struct nodemap_funcs
*funcs
)
435 This
= heap_alloc( sizeof *This
);
439 This
->IXMLDOMNamedNodeMap_iface
.lpVtbl
= &XMLDOMNamedNodeMapVtbl
;
440 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
444 This
->enumvariant
= NULL
;
447 init_dispex(&This
->dispex
, (IUnknown
*)&This
->IXMLDOMNamedNodeMap_iface
, &xmlnodemap_dispex
);
449 xmlnode_add_ref(node
);
450 xmldoc_add_ref(node
->doc
);
452 return &This
->IXMLDOMNamedNodeMap_iface
;