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;
49 static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface )
51 return (xmlnodemap *)((char*)iface - FIELD_OFFSET(xmlnodemap, lpVtbl));
54 static inline xmlnodemap *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface )
56 return (xmlnodemap *)((char*)iface - FIELD_OFFSET(xmlnodemap, lpSEIVtbl));
59 static HRESULT WINAPI xmlnodemap_QueryInterface(
60 IXMLDOMNamedNodeMap *iface,
61 REFIID riid, void** ppvObject )
63 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
64 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
66 if( IsEqualGUID( riid, &IID_IUnknown ) ||
67 IsEqualGUID( riid, &IID_IDispatch ) ||
68 IsEqualGUID( riid, &IID_IXMLDOMNamedNodeMap ) )
72 else if( IsEqualGUID( riid, &IID_ISupportErrorInfo ))
74 *ppvObject = &This->lpSEIVtbl;
78 FIXME("interface %s not implemented\n", debugstr_guid(riid));
82 IXMLDOMElement_AddRef( iface );
87 static ULONG WINAPI xmlnodemap_AddRef(
88 IXMLDOMNamedNodeMap *iface )
90 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
91 return InterlockedIncrement( &This->ref );
94 static ULONG WINAPI xmlnodemap_Release(
95 IXMLDOMNamedNodeMap *iface )
97 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
100 ref = InterlockedDecrement( &This->ref );
103 IXMLDOMNode_Release( This->node );
104 HeapFree( GetProcessHeap(), 0, This );
110 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount(
111 IXMLDOMNamedNodeMap *iface,
118 static HRESULT WINAPI xmlnodemap_GetTypeInfo(
119 IXMLDOMNamedNodeMap *iface,
120 UINT iTInfo, LCID lcid,
121 ITypeInfo** ppTInfo )
127 static HRESULT WINAPI xmlnodemap_GetIDsOfNames(
128 IXMLDOMNamedNodeMap *iface,
129 REFIID riid, LPOLESTR* rgszNames,
130 UINT cNames, LCID lcid, DISPID* rgDispId )
136 static HRESULT WINAPI xmlnodemap_Invoke(
137 IXMLDOMNamedNodeMap *iface,
138 DISPID dispIdMember, REFIID riid, LCID lcid,
139 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
140 EXCEPINFO* pExcepInfo, UINT* puArgErr )
146 xmlChar *xmlChar_from_wchar( LPWSTR str )
151 len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
152 xmlstr = (xmlChar*) HeapAlloc( GetProcessHeap(), 0, len );
154 WideCharToMultiByte( CP_UTF8, 0, str, -1, (LPSTR) xmlstr, len, NULL, NULL );
158 static HRESULT WINAPI xmlnodemap_getNamedItem(
159 IXMLDOMNamedNodeMap *iface,
161 IXMLDOMNode** namedItem)
163 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
164 xmlChar *element_name;
168 TRACE("%p %s\n", This, debugstr_w(name) );
170 node = xmlNodePtr_from_domnode( This->node, 0 );
174 element_name = xmlChar_from_wchar( name );
175 attr = xmlHasNsProp( node, element_name, NULL );
176 HeapFree( GetProcessHeap(), 0, element_name );
181 *namedItem = create_node( (xmlNodePtr) attr );
186 static HRESULT WINAPI xmlnodemap_setNamedItem(
187 IXMLDOMNamedNodeMap *iface,
188 IXMLDOMNode* newItem,
189 IXMLDOMNode** namedItem)
195 static HRESULT WINAPI xmlnodemap_removeNamedItem(
196 IXMLDOMNamedNodeMap *iface,
198 IXMLDOMNode** namedItem)
204 static HRESULT WINAPI xmlnodemap_get_item(
205 IXMLDOMNamedNodeMap *iface,
207 IXMLDOMNode** listItem)
209 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
214 TRACE("%p %ld\n", This, index);
221 node = xmlNodePtr_from_domnode( This->node, 0 );
222 curr = node->properties;
224 for (attrIndex = 0; attrIndex < index; attrIndex++) {
225 if (curr->next == NULL)
231 *listItem = create_node( (xmlNodePtr) curr );
236 static HRESULT WINAPI xmlnodemap_get_length(
237 IXMLDOMNamedNodeMap *iface,
245 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
249 node = xmlNodePtr_from_domnode( This->node, 0 );
253 first = node->properties;
261 while (curr->next != NULL) {
265 *listLength = attrCount;
270 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
271 IXMLDOMNamedNodeMap *iface,
274 IXMLDOMNode** qualifiedItem)
280 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
281 IXMLDOMNamedNodeMap *iface,
284 IXMLDOMNode** qualifiedItem)
290 static HRESULT WINAPI xmlnodemap_nextNode(
291 IXMLDOMNamedNodeMap *iface,
292 IXMLDOMNode** nextItem)
298 static HRESULT WINAPI xmlnodemap_reset(
299 IXMLDOMNamedNodeMap *iface )
305 static HRESULT WINAPI xmlnodemap__newEnum(
306 IXMLDOMNamedNodeMap *iface,
313 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl =
315 xmlnodemap_QueryInterface,
318 xmlnodemap_GetTypeInfoCount,
319 xmlnodemap_GetTypeInfo,
320 xmlnodemap_GetIDsOfNames,
322 xmlnodemap_getNamedItem,
323 xmlnodemap_setNamedItem,
324 xmlnodemap_removeNamedItem,
326 xmlnodemap_get_length,
327 xmlnodemap_getQualifiedItem,
328 xmlnodemap_removeQualifiedItem,
334 static HRESULT WINAPI support_error_QueryInterface(
335 ISupportErrorInfo *iface,
336 REFIID riid, void** ppvObject )
338 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
339 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
341 return IXMLDOMNamedNodeMap_QueryInterface((IXMLDOMNamedNodeMap*)&This->lpVtbl, riid, ppvObject);
344 static ULONG WINAPI support_error_AddRef(
345 ISupportErrorInfo *iface )
347 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
348 return IXMLDOMNamedNodeMap_AddRef((IXMLDOMNamedNodeMap*)&This->lpVtbl);
351 static ULONG WINAPI support_error_Release(
352 ISupportErrorInfo *iface )
354 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
355 return IXMLDOMNamedNodeMap_Release((IXMLDOMNamedNodeMap*)&This->lpVtbl);
358 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo(
359 ISupportErrorInfo *iface,
362 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
366 static const struct ISupportErrorInfoVtbl support_error_vtbl =
368 support_error_QueryInterface,
369 support_error_AddRef,
370 support_error_Release,
371 support_error_InterfaceSupportsErrorInfo
374 IXMLDOMNamedNodeMap *create_nodemap( IXMLDOMNode *node )
378 nodemap = HeapAlloc( GetProcessHeap(), 0, sizeof *nodemap );
382 nodemap->lpVtbl = &xmlnodemap_vtbl;
383 nodemap->lpSEIVtbl = &support_error_vtbl;
384 nodemap->node = node;
387 IXMLDOMNode_AddRef( node );
388 /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */
390 return (IXMLDOMNamedNodeMap*) &nodemap->lpVtbl;