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
33 #include "msxml_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
41 typedef struct _xmlnodemap
43 const struct IXMLDOMNamedNodeMapVtbl
*lpVtbl
;
44 const struct ISupportErrorInfoVtbl
*lpSEIVtbl
;
50 static inline xmlnodemap
*impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap
*iface
)
52 return (xmlnodemap
*)((char*)iface
- FIELD_OFFSET(xmlnodemap
, lpVtbl
));
55 static inline xmlnodemap
*impl_from_ISupportErrorInfo( ISupportErrorInfo
*iface
)
57 return (xmlnodemap
*)((char*)iface
- FIELD_OFFSET(xmlnodemap
, lpSEIVtbl
));
60 static HRESULT WINAPI
xmlnodemap_QueryInterface(
61 IXMLDOMNamedNodeMap
*iface
,
62 REFIID riid
, void** ppvObject
)
64 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
65 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppvObject
);
67 if( IsEqualGUID( riid
, &IID_IUnknown
) ||
68 IsEqualGUID( riid
, &IID_IDispatch
) ||
69 IsEqualGUID( riid
, &IID_IXMLDOMNamedNodeMap
) )
73 else if( IsEqualGUID( riid
, &IID_ISupportErrorInfo
))
75 *ppvObject
= &This
->lpSEIVtbl
;
79 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
83 IXMLDOMElement_AddRef( iface
);
88 static ULONG WINAPI
xmlnodemap_AddRef(
89 IXMLDOMNamedNodeMap
*iface
)
91 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
92 return InterlockedIncrement( &This
->ref
);
95 static ULONG WINAPI
xmlnodemap_Release(
96 IXMLDOMNamedNodeMap
*iface
)
98 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
101 ref
= InterlockedDecrement( &This
->ref
);
104 IXMLDOMNode_Release( This
->node
);
111 static HRESULT WINAPI
xmlnodemap_GetTypeInfoCount(
112 IXMLDOMNamedNodeMap
*iface
,
115 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
117 TRACE("(%p)->(%p)\n", This
, pctinfo
);
124 static HRESULT WINAPI
xmlnodemap_GetTypeInfo(
125 IXMLDOMNamedNodeMap
*iface
,
126 UINT iTInfo
, LCID lcid
,
127 ITypeInfo
** ppTInfo
)
129 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
130 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
131 return get_typeinfo(IXMLDOMNamedNodeMap_tid
, ppTInfo
);
134 static HRESULT WINAPI
xmlnodemap_GetIDsOfNames(
135 IXMLDOMNamedNodeMap
*iface
,
136 REFIID riid
, LPOLESTR
* rgszNames
,
137 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
139 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
143 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
146 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
149 hr
= get_typeinfo(IXMLDOMNamedNodeMap_tid
, &typeinfo
);
152 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
153 ITypeInfo_Release(typeinfo
);
159 static HRESULT WINAPI
xmlnodemap_Invoke(
160 IXMLDOMNamedNodeMap
*iface
,
161 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
162 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
163 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
165 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
169 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
170 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
172 hr
= get_typeinfo(IXMLDOMNamedNodeMap_tid
, &typeinfo
);
175 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
176 pVarResult
, pExcepInfo
, puArgErr
);
177 ITypeInfo_Release(typeinfo
);
183 xmlChar
*xmlChar_from_wchar( LPCWSTR str
)
188 len
= WideCharToMultiByte( CP_UTF8
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
189 xmlstr
= heap_alloc( len
);
191 WideCharToMultiByte( CP_UTF8
, 0, str
, -1, (LPSTR
) xmlstr
, len
, NULL
, NULL
);
195 static HRESULT WINAPI
xmlnodemap_getNamedItem(
196 IXMLDOMNamedNodeMap
*iface
,
198 IXMLDOMNode
** namedItem
)
200 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
201 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(name
), namedItem
);
202 return IXMLDOMNamedNodeMap_getQualifiedItem(iface
, name
, NULL
, namedItem
);
205 static HRESULT WINAPI
xmlnodemap_setNamedItem(
206 IXMLDOMNamedNodeMap
*iface
,
207 IXMLDOMNode
* newItem
,
208 IXMLDOMNode
** namedItem
)
210 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
215 TRACE("(%p)->(%p %p)\n", This
, newItem
, namedItem
);
220 if(namedItem
) *namedItem
= NULL
;
222 node
= xmlNodePtr_from_domnode( This
->node
, 0 );
226 /* Must be an Attribute */
227 ThisNew
= get_node_obj( newItem
);
229 FIXME("ThisNew is not our node implementation\n");
233 if(ThisNew
->node
->type
!= XML_ATTRIBUTE_NODE
)
236 if(!ThisNew
->node
->parent
)
237 if(xmldoc_remove_orphan(ThisNew
->node
->doc
, ThisNew
->node
) != S_OK
)
238 WARN("%p is not an orphan of %p\n", ThisNew
->node
, ThisNew
->node
->doc
);
240 nodeNew
= xmlAddChild(node
, ThisNew
->node
);
243 *namedItem
= create_node( nodeNew
);
247 static HRESULT WINAPI
xmlnodemap_removeNamedItem(
248 IXMLDOMNamedNodeMap
*iface
,
250 IXMLDOMNode
** namedItem
)
252 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
253 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(name
), namedItem
);
254 return IXMLDOMNamedNodeMap_removeQualifiedItem(iface
, name
, NULL
, namedItem
);
257 static HRESULT WINAPI
xmlnodemap_get_item(
258 IXMLDOMNamedNodeMap
*iface
,
260 IXMLDOMNode
** listItem
)
262 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
267 TRACE("(%p)->(%d %p)\n", This
, index
, listItem
);
274 node
= xmlNodePtr_from_domnode( This
->node
, 0 );
275 curr
= node
->properties
;
277 for (attrIndex
= 0; attrIndex
< index
; attrIndex
++) {
278 if (curr
->next
== NULL
)
284 *listItem
= create_node( (xmlNodePtr
) curr
);
289 static HRESULT WINAPI
xmlnodemap_get_length(
290 IXMLDOMNamedNodeMap
*iface
,
298 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
300 TRACE("(%p)->(%p)\n", This
, listLength
);
305 node
= xmlNodePtr_from_domnode( This
->node
, 0 );
309 first
= node
->properties
;
321 *listLength
= attrCount
;
326 static HRESULT WINAPI
xmlnodemap_getQualifiedItem(
327 IXMLDOMNamedNodeMap
*iface
,
330 IXMLDOMNode
** qualifiedItem
)
332 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
338 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_w(baseName
), debugstr_w(namespaceURI
), qualifiedItem
);
340 if (!baseName
|| !qualifiedItem
) return E_INVALIDARG
;
342 node
= xmlNodePtr_from_domnode(This
->node
, XML_ELEMENT_NODE
);
346 if (namespaceURI
&& *namespaceURI
)
348 href
= xmlChar_from_wchar(namespaceURI
);
349 if (!href
) return E_OUTOFMEMORY
;
354 name
= xmlChar_from_wchar(baseName
);
358 return E_OUTOFMEMORY
;
361 attr
= xmlHasNsProp(node
, name
, href
);
368 *qualifiedItem
= NULL
;
372 *qualifiedItem
= create_node((xmlNodePtr
)attr
);
377 static HRESULT WINAPI
xmlnodemap_removeQualifiedItem(
378 IXMLDOMNamedNodeMap
*iface
,
381 IXMLDOMNode
** qualifiedItem
)
383 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
389 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_w(baseName
), debugstr_w(namespaceURI
), qualifiedItem
);
391 if (!baseName
) return E_INVALIDARG
;
393 node
= xmlNodePtr_from_domnode( This
->node
, XML_ELEMENT_NODE
);
397 if (namespaceURI
&& *namespaceURI
)
399 href
= xmlChar_from_wchar(namespaceURI
);
400 if (!href
) return E_OUTOFMEMORY
;
405 name
= xmlChar_from_wchar(baseName
);
409 return E_OUTOFMEMORY
;
412 attr
= xmlHasNsProp( node
, name
, href
);
419 if (qualifiedItem
) *qualifiedItem
= NULL
;
425 xmlUnlinkNode( (xmlNodePtr
) attr
);
426 xmldoc_add_orphan( attr
->doc
, (xmlNodePtr
) attr
);
427 *qualifiedItem
= create_node( (xmlNodePtr
) attr
);
431 if (xmlRemoveProp(attr
) == -1)
432 ERR("xmlRemoveProp failed\n");
438 static HRESULT WINAPI
xmlnodemap_nextNode(
439 IXMLDOMNamedNodeMap
*iface
,
440 IXMLDOMNode
** nextItem
)
442 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
447 TRACE("(%p)->(%p: %d)\n", This
, nextItem
, This
->iterator
);
451 node
= xmlNodePtr_from_domnode( This
->node
, 0 );
452 curr
= node
->properties
;
454 for (attrIndex
= 0; attrIndex
< This
->iterator
; attrIndex
++) {
455 if (curr
->next
== NULL
)
463 *nextItem
= create_node( (xmlNodePtr
) curr
);
468 static HRESULT WINAPI
xmlnodemap_reset(
469 IXMLDOMNamedNodeMap
*iface
)
471 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
473 TRACE("(%p: %d)\n", This
, This
->iterator
);
480 static HRESULT WINAPI
xmlnodemap__newEnum(
481 IXMLDOMNamedNodeMap
*iface
,
484 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
485 FIXME("(%p)->(%p)\n", This
, ppUnk
);
489 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl
=
491 xmlnodemap_QueryInterface
,
494 xmlnodemap_GetTypeInfoCount
,
495 xmlnodemap_GetTypeInfo
,
496 xmlnodemap_GetIDsOfNames
,
498 xmlnodemap_getNamedItem
,
499 xmlnodemap_setNamedItem
,
500 xmlnodemap_removeNamedItem
,
502 xmlnodemap_get_length
,
503 xmlnodemap_getQualifiedItem
,
504 xmlnodemap_removeQualifiedItem
,
510 static HRESULT WINAPI
support_error_QueryInterface(
511 ISupportErrorInfo
*iface
,
512 REFIID riid
, void** ppvObject
)
514 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
515 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
516 return IXMLDOMNamedNodeMap_QueryInterface((IXMLDOMNamedNodeMap
*)&This
->lpVtbl
, riid
, ppvObject
);
519 static ULONG WINAPI
support_error_AddRef(
520 ISupportErrorInfo
*iface
)
522 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
523 return IXMLDOMNamedNodeMap_AddRef((IXMLDOMNamedNodeMap
*)&This
->lpVtbl
);
526 static ULONG WINAPI
support_error_Release(
527 ISupportErrorInfo
*iface
)
529 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
530 return IXMLDOMNamedNodeMap_Release((IXMLDOMNamedNodeMap
*)&This
->lpVtbl
);
533 static HRESULT WINAPI
support_error_InterfaceSupportsErrorInfo(
534 ISupportErrorInfo
*iface
,
537 FIXME("(%p)->(%s)\n", iface
, debugstr_guid(riid
));
541 static const struct ISupportErrorInfoVtbl support_error_vtbl
=
543 support_error_QueryInterface
,
544 support_error_AddRef
,
545 support_error_Release
,
546 support_error_InterfaceSupportsErrorInfo
549 IXMLDOMNamedNodeMap
*create_nodemap( IXMLDOMNode
*node
)
553 nodemap
= heap_alloc( sizeof *nodemap
);
557 nodemap
->lpVtbl
= &xmlnodemap_vtbl
;
558 nodemap
->lpSEIVtbl
= &support_error_vtbl
;
559 nodemap
->node
= node
;
561 nodemap
->iterator
= 0;
563 IXMLDOMNode_AddRef( node
);
564 /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */
566 return (IXMLDOMNamedNodeMap
*) &nodemap
->lpVtbl
;