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 %p\n", This, debugstr_w(name), namedItem );
173 node = xmlNodePtr_from_domnode( This->node, 0 );
177 element_name = xmlChar_from_wchar( name );
178 attr = xmlHasNsProp( node, element_name, NULL );
179 HeapFree( GetProcessHeap(), 0, element_name );
187 *namedItem = create_node( (xmlNodePtr) attr );
192 static HRESULT WINAPI xmlnodemap_setNamedItem(
193 IXMLDOMNamedNodeMap *iface,
194 IXMLDOMNode* newItem,
195 IXMLDOMNode** namedItem)
201 static HRESULT WINAPI xmlnodemap_removeNamedItem(
202 IXMLDOMNamedNodeMap *iface,
204 IXMLDOMNode** namedItem)
210 static HRESULT WINAPI xmlnodemap_get_item(
211 IXMLDOMNamedNodeMap *iface,
213 IXMLDOMNode** listItem)
215 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
220 TRACE("%p %ld\n", This, index);
227 node = xmlNodePtr_from_domnode( This->node, 0 );
228 curr = node->properties;
230 for (attrIndex = 0; attrIndex < index; attrIndex++) {
231 if (curr->next == NULL)
237 *listItem = create_node( (xmlNodePtr) curr );
242 static HRESULT WINAPI xmlnodemap_get_length(
243 IXMLDOMNamedNodeMap *iface,
251 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
255 node = xmlNodePtr_from_domnode( This->node, 0 );
259 first = node->properties;
267 while (curr->next != NULL) {
271 *listLength = attrCount;
276 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
277 IXMLDOMNamedNodeMap *iface,
280 IXMLDOMNode** qualifiedItem)
286 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
287 IXMLDOMNamedNodeMap *iface,
290 IXMLDOMNode** qualifiedItem)
296 static HRESULT WINAPI xmlnodemap_nextNode(
297 IXMLDOMNamedNodeMap *iface,
298 IXMLDOMNode** nextItem)
304 static HRESULT WINAPI xmlnodemap_reset(
305 IXMLDOMNamedNodeMap *iface )
311 static HRESULT WINAPI xmlnodemap__newEnum(
312 IXMLDOMNamedNodeMap *iface,
319 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl =
321 xmlnodemap_QueryInterface,
324 xmlnodemap_GetTypeInfoCount,
325 xmlnodemap_GetTypeInfo,
326 xmlnodemap_GetIDsOfNames,
328 xmlnodemap_getNamedItem,
329 xmlnodemap_setNamedItem,
330 xmlnodemap_removeNamedItem,
332 xmlnodemap_get_length,
333 xmlnodemap_getQualifiedItem,
334 xmlnodemap_removeQualifiedItem,
340 static HRESULT WINAPI support_error_QueryInterface(
341 ISupportErrorInfo *iface,
342 REFIID riid, void** ppvObject )
344 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
345 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
347 return IXMLDOMNamedNodeMap_QueryInterface((IXMLDOMNamedNodeMap*)&This->lpVtbl, riid, ppvObject);
350 static ULONG WINAPI support_error_AddRef(
351 ISupportErrorInfo *iface )
353 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
354 return IXMLDOMNamedNodeMap_AddRef((IXMLDOMNamedNodeMap*)&This->lpVtbl);
357 static ULONG WINAPI support_error_Release(
358 ISupportErrorInfo *iface )
360 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
361 return IXMLDOMNamedNodeMap_Release((IXMLDOMNamedNodeMap*)&This->lpVtbl);
364 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo(
365 ISupportErrorInfo *iface,
368 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
372 static const struct ISupportErrorInfoVtbl support_error_vtbl =
374 support_error_QueryInterface,
375 support_error_AddRef,
376 support_error_Release,
377 support_error_InterfaceSupportsErrorInfo
380 IXMLDOMNamedNodeMap *create_nodemap( IXMLDOMNode *node )
384 nodemap = HeapAlloc( GetProcessHeap(), 0, sizeof *nodemap );
388 nodemap->lpVtbl = &xmlnodemap_vtbl;
389 nodemap->lpSEIVtbl = &support_error_vtbl;
390 nodemap->node = node;
393 IXMLDOMNode_AddRef( node );
394 /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */
396 return (IXMLDOMNamedNodeMap*) &nodemap->lpVtbl;