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"
43 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
47 typedef struct _xmlnodemap
50 IXMLDOMNamedNodeMap IXMLDOMNamedNodeMap_iface
;
51 ISupportErrorInfo ISupportErrorInfo_iface
;
57 const struct nodemap_funcs
*funcs
;
60 static inline xmlnodemap
*impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap
*iface
)
62 return CONTAINING_RECORD(iface
, xmlnodemap
, IXMLDOMNamedNodeMap_iface
);
65 static inline xmlnodemap
*impl_from_ISupportErrorInfo( ISupportErrorInfo
*iface
)
67 return CONTAINING_RECORD(iface
, xmlnodemap
, ISupportErrorInfo_iface
);
70 static HRESULT WINAPI
xmlnodemap_QueryInterface(
71 IXMLDOMNamedNodeMap
*iface
,
72 REFIID riid
, void** ppvObject
)
74 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
75 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppvObject
);
77 if( IsEqualGUID( riid
, &IID_IUnknown
) ||
78 IsEqualGUID( riid
, &IID_IDispatch
) ||
79 IsEqualGUID( riid
, &IID_IXMLDOMNamedNodeMap
) )
83 else if (dispex_query_interface(&This
->dispex
, riid
, ppvObject
))
85 return *ppvObject
? S_OK
: E_NOINTERFACE
;
87 else if( IsEqualGUID( riid
, &IID_ISupportErrorInfo
))
89 *ppvObject
= &This
->ISupportErrorInfo_iface
;
93 TRACE("interface %s not implemented\n", debugstr_guid(riid
));
98 IXMLDOMElement_AddRef( iface
);
103 static ULONG WINAPI
xmlnodemap_AddRef(
104 IXMLDOMNamedNodeMap
*iface
)
106 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
107 ULONG ref
= InterlockedIncrement( &This
->ref
);
108 TRACE("(%p)->(%d)\n", This
, ref
);
112 static ULONG WINAPI
xmlnodemap_Release(
113 IXMLDOMNamedNodeMap
*iface
)
115 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
116 ULONG ref
= InterlockedDecrement( &This
->ref
);
118 TRACE("(%p)->(%d)\n", This
, ref
);
121 xmldoc_release( This
->node
->doc
);
122 release_dispex(&This
->dispex
);
129 static HRESULT WINAPI
xmlnodemap_GetTypeInfoCount(
130 IXMLDOMNamedNodeMap
*iface
,
133 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
134 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
137 static HRESULT WINAPI
xmlnodemap_GetTypeInfo(
138 IXMLDOMNamedNodeMap
*iface
,
139 UINT iTInfo
, LCID lcid
,
140 ITypeInfo
** ppTInfo
)
142 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
143 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
144 iTInfo
, lcid
, ppTInfo
);
147 static HRESULT WINAPI
xmlnodemap_GetIDsOfNames(
148 IXMLDOMNamedNodeMap
*iface
,
149 REFIID riid
, LPOLESTR
* rgszNames
,
150 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
152 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
153 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
154 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
157 static HRESULT WINAPI
xmlnodemap_Invoke(
158 IXMLDOMNamedNodeMap
*iface
,
159 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
160 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
161 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
163 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
164 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
165 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
168 static HRESULT WINAPI
xmlnodemap_getNamedItem(
169 IXMLDOMNamedNodeMap
*iface
,
173 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
175 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(name
), item
);
177 return This
->funcs
->get_named_item(This
->node
, name
, item
);
180 static HRESULT WINAPI
xmlnodemap_setNamedItem(
181 IXMLDOMNamedNodeMap
*iface
,
182 IXMLDOMNode
* newItem
,
183 IXMLDOMNode
** namedItem
)
185 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
187 TRACE("(%p)->(%p %p)\n", This
, newItem
, namedItem
);
189 return This
->funcs
->set_named_item(This
->node
, newItem
, namedItem
);
192 static HRESULT WINAPI
xmlnodemap_removeNamedItem(
193 IXMLDOMNamedNodeMap
*iface
,
195 IXMLDOMNode
** namedItem
)
197 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
199 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(name
), namedItem
);
201 return This
->funcs
->remove_named_item(This
->node
, name
, namedItem
);
204 static HRESULT WINAPI
xmlnodemap_get_item(
205 IXMLDOMNamedNodeMap
*iface
,
209 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
211 TRACE("(%p)->(%d %p)\n", This
, index
, item
);
213 return This
->funcs
->get_item(This
->node
, index
, item
);
216 static HRESULT WINAPI
xmlnodemap_get_length(
217 IXMLDOMNamedNodeMap
*iface
,
220 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
222 TRACE("(%p)->(%p)\n", This
, length
);
224 return This
->funcs
->get_length(This
->node
, length
);
227 static HRESULT WINAPI
xmlnodemap_getQualifiedItem(
228 IXMLDOMNamedNodeMap
*iface
,
233 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
235 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_w(baseName
), debugstr_w(namespaceURI
), item
);
237 return This
->funcs
->get_qualified_item(This
->node
, baseName
, namespaceURI
, item
);
240 static HRESULT WINAPI
xmlnodemap_removeQualifiedItem(
241 IXMLDOMNamedNodeMap
*iface
,
246 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
248 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_w(baseName
), debugstr_w(namespaceURI
), item
);
250 return This
->funcs
->remove_qualified_item(This
->node
, baseName
, namespaceURI
, item
);
253 static HRESULT WINAPI
xmlnodemap_nextNode(
254 IXMLDOMNamedNodeMap
*iface
,
255 IXMLDOMNode
** nextItem
)
257 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
259 TRACE("(%p)->(%p: %d)\n", This
, nextItem
, This
->iterator
);
261 return This
->funcs
->next_node(This
->node
, &This
->iterator
, nextItem
);
264 static HRESULT WINAPI
xmlnodemap_reset(
265 IXMLDOMNamedNodeMap
*iface
)
267 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
269 TRACE("(%p)->(%d)\n", This
, This
->iterator
);
276 static HRESULT WINAPI
xmlnodemap__newEnum(
277 IXMLDOMNamedNodeMap
*iface
,
280 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
281 FIXME("(%p)->(%p)\n", This
, ppUnk
);
285 static const struct IXMLDOMNamedNodeMapVtbl XMLDOMNamedNodeMapVtbl
=
287 xmlnodemap_QueryInterface
,
290 xmlnodemap_GetTypeInfoCount
,
291 xmlnodemap_GetTypeInfo
,
292 xmlnodemap_GetIDsOfNames
,
294 xmlnodemap_getNamedItem
,
295 xmlnodemap_setNamedItem
,
296 xmlnodemap_removeNamedItem
,
298 xmlnodemap_get_length
,
299 xmlnodemap_getQualifiedItem
,
300 xmlnodemap_removeQualifiedItem
,
306 static HRESULT WINAPI
support_error_QueryInterface(
307 ISupportErrorInfo
*iface
,
308 REFIID riid
, void** ppvObject
)
310 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
311 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
312 return IXMLDOMNamedNodeMap_QueryInterface(&This
->IXMLDOMNamedNodeMap_iface
, riid
, ppvObject
);
315 static ULONG WINAPI
support_error_AddRef(
316 ISupportErrorInfo
*iface
)
318 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
319 return IXMLDOMNamedNodeMap_AddRef(&This
->IXMLDOMNamedNodeMap_iface
);
322 static ULONG WINAPI
support_error_Release(
323 ISupportErrorInfo
*iface
)
325 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
326 return IXMLDOMNamedNodeMap_Release(&This
->IXMLDOMNamedNodeMap_iface
);
329 static HRESULT WINAPI
support_error_InterfaceSupportsErrorInfo(
330 ISupportErrorInfo
*iface
,
333 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
334 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
335 return IsEqualGUID(riid
, &IID_IXMLDOMNamedNodeMap
) ? S_OK
: S_FALSE
;
338 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
=
340 support_error_QueryInterface
,
341 support_error_AddRef
,
342 support_error_Release
,
343 support_error_InterfaceSupportsErrorInfo
346 static HRESULT
xmlnodemap_get_dispid(IUnknown
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
351 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
352 idx
= idx
*10 + (*ptr
-'0');
354 return DISP_E_UNKNOWNNAME
;
356 *dispid
= DISPID_DOM_COLLECTION_BASE
+ idx
;
357 TRACE("ret %x\n", *dispid
);
361 static HRESULT
xmlnodemap_invoke(IUnknown
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
362 VARIANT
*res
, EXCEPINFO
*ei
)
364 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( (IXMLDOMNamedNodeMap
*)iface
);
366 TRACE("(%p)->(%x %x %x %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
);
368 V_VT(res
) = VT_DISPATCH
;
369 V_DISPATCH(res
) = NULL
;
371 if (id
< DISPID_DOM_COLLECTION_BASE
|| id
> DISPID_DOM_COLLECTION_MAX
)
372 return DISP_E_UNKNOWNNAME
;
376 case INVOKE_PROPERTYGET
:
378 IXMLDOMNode
*disp
= NULL
;
380 IXMLDOMNamedNodeMap_get_item(&This
->IXMLDOMNamedNodeMap_iface
, id
- DISPID_DOM_COLLECTION_BASE
, &disp
);
381 V_DISPATCH(res
) = (IDispatch
*)disp
;
386 FIXME("unimplemented flags %x\n", flags
);
391 TRACE("ret %p\n", V_DISPATCH(res
));
396 static const dispex_static_data_vtbl_t xmlnodemap_dispex_vtbl
= {
397 xmlnodemap_get_dispid
,
401 static const tid_t xmlnodemap_iface_tids
[] = {
402 IXMLDOMNamedNodeMap_tid
,
406 static dispex_static_data_t xmlnodemap_dispex
= {
407 &xmlnodemap_dispex_vtbl
,
408 IXMLDOMNamedNodeMap_tid
,
410 xmlnodemap_iface_tids
413 IXMLDOMNamedNodeMap
*create_nodemap(xmlNodePtr node
, const struct nodemap_funcs
*funcs
)
417 This
= heap_alloc( sizeof *This
);
421 This
->IXMLDOMNamedNodeMap_iface
.lpVtbl
= &XMLDOMNamedNodeMapVtbl
;
422 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
428 init_dispex(&This
->dispex
, (IUnknown
*)&This
->IXMLDOMNamedNodeMap_iface
, &xmlnodemap_dispex
);
430 xmldoc_add_ref(node
->doc
);
432 return &This
->IXMLDOMNamedNodeMap_iface
;