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
);
105 HeapFree( GetProcessHeap(), 0, This
);
111 static HRESULT WINAPI
xmlnodemap_GetTypeInfoCount(
112 IXMLDOMNamedNodeMap
*iface
,
119 static HRESULT WINAPI
xmlnodemap_GetTypeInfo(
120 IXMLDOMNamedNodeMap
*iface
,
121 UINT iTInfo
, LCID lcid
,
122 ITypeInfo
** ppTInfo
)
128 static HRESULT WINAPI
xmlnodemap_GetIDsOfNames(
129 IXMLDOMNamedNodeMap
*iface
,
130 REFIID riid
, LPOLESTR
* rgszNames
,
131 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
137 static HRESULT WINAPI
xmlnodemap_Invoke(
138 IXMLDOMNamedNodeMap
*iface
,
139 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
140 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
141 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
147 xmlChar
*xmlChar_from_wchar( LPWSTR str
)
152 len
= WideCharToMultiByte( CP_UTF8
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
153 xmlstr
= HeapAlloc( GetProcessHeap(), 0, len
);
155 WideCharToMultiByte( CP_UTF8
, 0, str
, -1, (LPSTR
) xmlstr
, len
, NULL
, NULL
);
159 static HRESULT WINAPI
xmlnodemap_getNamedItem(
160 IXMLDOMNamedNodeMap
*iface
,
162 IXMLDOMNode
** namedItem
)
164 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
165 xmlChar
*element_name
;
169 TRACE("%p %s %p\n", This
, debugstr_w(name
), namedItem
);
174 node
= xmlNodePtr_from_domnode( This
->node
, 0 );
178 element_name
= xmlChar_from_wchar( name
);
179 attr
= xmlHasNsProp( node
, element_name
, NULL
);
180 HeapFree( GetProcessHeap(), 0, element_name
);
188 *namedItem
= create_node( (xmlNodePtr
) attr
);
193 static HRESULT WINAPI
xmlnodemap_setNamedItem(
194 IXMLDOMNamedNodeMap
*iface
,
195 IXMLDOMNode
* newItem
,
196 IXMLDOMNode
** namedItem
)
198 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
199 xmlnode
*ThisNew
= NULL
;
201 IXMLDOMNode
*pAttr
= NULL
;
204 TRACE("%p %p %p\n", This
, newItem
, namedItem
);
209 if(namedItem
) *namedItem
= NULL
;
211 node
= xmlNodePtr_from_domnode( This
->node
, 0 );
215 /* Must be an Attribute */
216 IUnknown_QueryInterface(newItem
, &IID_IXMLDOMNode
, (LPVOID
*)&pAttr
);
219 ThisNew
= impl_from_IXMLDOMNode( pAttr
);
221 if(ThisNew
->node
->type
!= XML_ATTRIBUTE_NODE
)
223 IUnknown_Release(pAttr
);
227 nodeNew
= xmlAddChild(node
, ThisNew
->node
);
230 *namedItem
= create_node( nodeNew
);
232 IUnknown_Release(pAttr
);
240 static HRESULT WINAPI
xmlnodemap_removeNamedItem(
241 IXMLDOMNamedNodeMap
*iface
,
243 IXMLDOMNode
** namedItem
)
249 static HRESULT WINAPI
xmlnodemap_get_item(
250 IXMLDOMNamedNodeMap
*iface
,
252 IXMLDOMNode
** listItem
)
254 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
259 TRACE("%p %ld\n", This
, index
);
266 node
= xmlNodePtr_from_domnode( This
->node
, 0 );
267 curr
= node
->properties
;
269 for (attrIndex
= 0; attrIndex
< index
; attrIndex
++) {
270 if (curr
->next
== NULL
)
276 *listItem
= create_node( (xmlNodePtr
) curr
);
281 static HRESULT WINAPI
xmlnodemap_get_length(
282 IXMLDOMNamedNodeMap
*iface
,
290 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
294 node
= xmlNodePtr_from_domnode( This
->node
, 0 );
298 first
= node
->properties
;
306 while (curr
->next
!= NULL
) {
310 *listLength
= attrCount
;
315 static HRESULT WINAPI
xmlnodemap_getQualifiedItem(
316 IXMLDOMNamedNodeMap
*iface
,
319 IXMLDOMNode
** qualifiedItem
)
325 static HRESULT WINAPI
xmlnodemap_removeQualifiedItem(
326 IXMLDOMNamedNodeMap
*iface
,
329 IXMLDOMNode
** qualifiedItem
)
335 static HRESULT WINAPI
xmlnodemap_nextNode(
336 IXMLDOMNamedNodeMap
*iface
,
337 IXMLDOMNode
** nextItem
)
339 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
344 TRACE("%p %ld\n", This
, This
->iterator
);
348 node
= xmlNodePtr_from_domnode( This
->node
, 0 );
349 curr
= node
->properties
;
351 for (attrIndex
= 0; attrIndex
< This
->iterator
; attrIndex
++) {
352 if (curr
->next
== NULL
)
360 *nextItem
= create_node( (xmlNodePtr
) curr
);
365 static HRESULT WINAPI
xmlnodemap_reset(
366 IXMLDOMNamedNodeMap
*iface
)
368 xmlnodemap
*This
= impl_from_IXMLDOMNamedNodeMap( iface
);
370 TRACE("%p %ld\n", This
, This
->iterator
);
377 static HRESULT WINAPI
xmlnodemap__newEnum(
378 IXMLDOMNamedNodeMap
*iface
,
385 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl
=
387 xmlnodemap_QueryInterface
,
390 xmlnodemap_GetTypeInfoCount
,
391 xmlnodemap_GetTypeInfo
,
392 xmlnodemap_GetIDsOfNames
,
394 xmlnodemap_getNamedItem
,
395 xmlnodemap_setNamedItem
,
396 xmlnodemap_removeNamedItem
,
398 xmlnodemap_get_length
,
399 xmlnodemap_getQualifiedItem
,
400 xmlnodemap_removeQualifiedItem
,
406 static HRESULT WINAPI
support_error_QueryInterface(
407 ISupportErrorInfo
*iface
,
408 REFIID riid
, void** ppvObject
)
410 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
411 TRACE("%p %s %p\n", iface
, debugstr_guid(riid
), ppvObject
);
413 return IXMLDOMNamedNodeMap_QueryInterface((IXMLDOMNamedNodeMap
*)&This
->lpVtbl
, riid
, ppvObject
);
416 static ULONG WINAPI
support_error_AddRef(
417 ISupportErrorInfo
*iface
)
419 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
420 return IXMLDOMNamedNodeMap_AddRef((IXMLDOMNamedNodeMap
*)&This
->lpVtbl
);
423 static ULONG WINAPI
support_error_Release(
424 ISupportErrorInfo
*iface
)
426 xmlnodemap
*This
= impl_from_ISupportErrorInfo( iface
);
427 return IXMLDOMNamedNodeMap_Release((IXMLDOMNamedNodeMap
*)&This
->lpVtbl
);
430 static HRESULT WINAPI
support_error_InterfaceSupportsErrorInfo(
431 ISupportErrorInfo
*iface
,
434 FIXME("(%p)->(%s)\n", iface
, debugstr_guid(riid
));
438 static const struct ISupportErrorInfoVtbl support_error_vtbl
=
440 support_error_QueryInterface
,
441 support_error_AddRef
,
442 support_error_Release
,
443 support_error_InterfaceSupportsErrorInfo
446 IXMLDOMNamedNodeMap
*create_nodemap( IXMLDOMNode
*node
)
450 nodemap
= HeapAlloc( GetProcessHeap(), 0, sizeof *nodemap
);
454 nodemap
->lpVtbl
= &xmlnodemap_vtbl
;
455 nodemap
->lpSEIVtbl
= &support_error_vtbl
;
456 nodemap
->node
= node
;
458 nodemap
->iterator
= 0;
460 IXMLDOMNode_AddRef( node
);
461 /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */
463 return (IXMLDOMNamedNodeMap
*) &nodemap
->lpVtbl
;