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 = (xmlChar*) 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)
202 static HRESULT WINAPI xmlnodemap_removeNamedItem(
203 IXMLDOMNamedNodeMap *iface,
205 IXMLDOMNode** namedItem)
211 static HRESULT WINAPI xmlnodemap_get_item(
212 IXMLDOMNamedNodeMap *iface,
214 IXMLDOMNode** listItem)
216 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
221 TRACE("%p %ld\n", This, index);
228 node = xmlNodePtr_from_domnode( This->node, 0 );
229 curr = node->properties;
231 for (attrIndex = 0; attrIndex < index; attrIndex++) {
232 if (curr->next == NULL)
238 *listItem = create_node( (xmlNodePtr) curr );
243 static HRESULT WINAPI xmlnodemap_get_length(
244 IXMLDOMNamedNodeMap *iface,
252 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
256 node = xmlNodePtr_from_domnode( This->node, 0 );
260 first = node->properties;
268 while (curr->next != NULL) {
272 *listLength = attrCount;
277 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
278 IXMLDOMNamedNodeMap *iface,
281 IXMLDOMNode** qualifiedItem)
287 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
288 IXMLDOMNamedNodeMap *iface,
291 IXMLDOMNode** qualifiedItem)
297 static HRESULT WINAPI xmlnodemap_nextNode(
298 IXMLDOMNamedNodeMap *iface,
299 IXMLDOMNode** nextItem)
301 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
306 TRACE("%p %ld\n", This, This->iterator);
310 node = xmlNodePtr_from_domnode( This->node, 0 );
311 curr = node->properties;
313 for (attrIndex = 0; attrIndex < This->iterator; attrIndex++) {
314 if (curr->next == NULL)
322 *nextItem = create_node( (xmlNodePtr) curr );
327 static HRESULT WINAPI xmlnodemap_reset(
328 IXMLDOMNamedNodeMap *iface )
330 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
332 TRACE("%p %ld\n", This, This->iterator);
339 static HRESULT WINAPI xmlnodemap__newEnum(
340 IXMLDOMNamedNodeMap *iface,
347 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl =
349 xmlnodemap_QueryInterface,
352 xmlnodemap_GetTypeInfoCount,
353 xmlnodemap_GetTypeInfo,
354 xmlnodemap_GetIDsOfNames,
356 xmlnodemap_getNamedItem,
357 xmlnodemap_setNamedItem,
358 xmlnodemap_removeNamedItem,
360 xmlnodemap_get_length,
361 xmlnodemap_getQualifiedItem,
362 xmlnodemap_removeQualifiedItem,
368 static HRESULT WINAPI support_error_QueryInterface(
369 ISupportErrorInfo *iface,
370 REFIID riid, void** ppvObject )
372 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
373 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
375 return IXMLDOMNamedNodeMap_QueryInterface((IXMLDOMNamedNodeMap*)&This->lpVtbl, riid, ppvObject);
378 static ULONG WINAPI support_error_AddRef(
379 ISupportErrorInfo *iface )
381 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
382 return IXMLDOMNamedNodeMap_AddRef((IXMLDOMNamedNodeMap*)&This->lpVtbl);
385 static ULONG WINAPI support_error_Release(
386 ISupportErrorInfo *iface )
388 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
389 return IXMLDOMNamedNodeMap_Release((IXMLDOMNamedNodeMap*)&This->lpVtbl);
392 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo(
393 ISupportErrorInfo *iface,
396 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
400 static const struct ISupportErrorInfoVtbl support_error_vtbl =
402 support_error_QueryInterface,
403 support_error_AddRef,
404 support_error_Release,
405 support_error_InterfaceSupportsErrorInfo
408 IXMLDOMNamedNodeMap *create_nodemap( IXMLDOMNode *node )
412 nodemap = HeapAlloc( GetProcessHeap(), 0, sizeof *nodemap );
416 nodemap->lpVtbl = &xmlnodemap_vtbl;
417 nodemap->lpSEIVtbl = &support_error_vtbl;
418 nodemap->node = node;
420 nodemap->iterator = 0;
422 IXMLDOMNode_AddRef( node );
423 /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */
425 return (IXMLDOMNamedNodeMap*) &nodemap->lpVtbl;