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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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;
48 static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface )
50 return (xmlnodemap *)((char*)iface - FIELD_OFFSET(xmlnodemap, lpVtbl));
53 static HRESULT WINAPI xmlnodemap_QueryInterface(
54 IXMLDOMNamedNodeMap *iface,
55 REFIID riid, void** ppvObject )
57 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
59 if( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
60 IsEqualGUID( riid, &IID_IUnknown ) ||
61 IsEqualGUID( riid, &IID_IDispatch ) ||
62 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
68 FIXME("interface %s not implemented\n", debugstr_guid(riid));
72 IXMLDOMElement_AddRef( iface );
77 static ULONG WINAPI xmlnodemap_AddRef(
78 IXMLDOMNamedNodeMap *iface )
80 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
81 return InterlockedIncrement( &This->ref );
84 static ULONG WINAPI xmlnodemap_Release(
85 IXMLDOMNamedNodeMap *iface )
87 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
90 ref = InterlockedDecrement( &This->ref );
93 IXMLDOMNode_Release( This->node );
94 HeapFree( GetProcessHeap(), 0, This );
100 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount(
101 IXMLDOMNamedNodeMap *iface,
108 static HRESULT WINAPI xmlnodemap_GetTypeInfo(
109 IXMLDOMNamedNodeMap *iface,
110 UINT iTInfo, LCID lcid,
111 ITypeInfo** ppTInfo )
117 static HRESULT WINAPI xmlnodemap_GetIDsOfNames(
118 IXMLDOMNamedNodeMap *iface,
119 REFIID riid, LPOLESTR* rgszNames,
120 UINT cNames, LCID lcid, DISPID* rgDispId )
126 static HRESULT WINAPI xmlnodemap_Invoke(
127 IXMLDOMNamedNodeMap *iface,
128 DISPID dispIdMember, REFIID riid, LCID lcid,
129 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
130 EXCEPINFO* pExcepInfo, UINT* puArgErr )
136 xmlChar *xmlChar_from_wchar( LPWSTR str )
141 len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
142 xmlstr = (xmlChar*) HeapAlloc( GetProcessHeap(), 0, len );
144 WideCharToMultiByte( CP_UTF8, 0, str, -1, (LPSTR) xmlstr, len, NULL, NULL );
148 static HRESULT WINAPI xmlnodemap_getNamedItem(
149 IXMLDOMNamedNodeMap *iface,
151 IXMLDOMNode** namedItem)
153 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
154 xmlChar *element_name;
158 TRACE("%p %s\n", This, debugstr_w(name) );
160 node = xmlNodePtr_from_domnode( This->node, 0 );
164 element_name = xmlChar_from_wchar( name );
165 attr = xmlHasNsProp( node, element_name, NULL );
166 HeapFree( GetProcessHeap(), 0, element_name );
171 *namedItem = create_node( (xmlNodePtr) attr );
176 static HRESULT WINAPI xmlnodemap_setNamedItem(
177 IXMLDOMNamedNodeMap *iface,
178 IXMLDOMNode* newItem,
179 IXMLDOMNode** namedItem)
185 static HRESULT WINAPI xmlnodemap_removeNamedItem(
186 IXMLDOMNamedNodeMap *iface,
188 IXMLDOMNode** namedItem)
194 static HRESULT WINAPI xmlnodemap_get_item(
195 IXMLDOMNamedNodeMap *iface,
197 IXMLDOMNode** listItem)
199 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
204 TRACE("%p %ld\n", This, index);
211 node = xmlNodePtr_from_domnode( This->node, 0 );
212 curr = node->properties;
214 for (attrIndex = 0; attrIndex < index; attrIndex++) {
215 if (curr->next == NULL)
221 *listItem = create_node( (xmlNodePtr) curr );
226 static HRESULT WINAPI xmlnodemap_get_length(
227 IXMLDOMNamedNodeMap *iface,
235 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
239 node = xmlNodePtr_from_domnode( This->node, 0 );
243 first = node->properties;
251 while (curr->next != NULL) {
255 *listLength = attrCount;
260 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
261 IXMLDOMNamedNodeMap *iface,
264 IXMLDOMNode** qualifiedItem)
270 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
271 IXMLDOMNamedNodeMap *iface,
274 IXMLDOMNode** qualifiedItem)
280 static HRESULT WINAPI xmlnodemap_nextNode(
281 IXMLDOMNamedNodeMap *iface,
282 IXMLDOMNode** nextItem)
288 static HRESULT WINAPI xmlnodemap_reset(
289 IXMLDOMNamedNodeMap *iface )
295 static HRESULT WINAPI xmlnodemap__newEnum(
296 IXMLDOMNamedNodeMap *iface,
303 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl =
305 xmlnodemap_QueryInterface,
308 xmlnodemap_GetTypeInfoCount,
309 xmlnodemap_GetTypeInfo,
310 xmlnodemap_GetIDsOfNames,
312 xmlnodemap_getNamedItem,
313 xmlnodemap_setNamedItem,
314 xmlnodemap_removeNamedItem,
316 xmlnodemap_get_length,
317 xmlnodemap_getQualifiedItem,
318 xmlnodemap_removeQualifiedItem,
324 IXMLDOMNamedNodeMap *create_nodemap( IXMLDOMNode *node )
328 nodemap = HeapAlloc( GetProcessHeap(), 0, sizeof *nodemap );
332 nodemap->lpVtbl = &xmlnodemap_vtbl;
333 nodemap->node = node;
336 IXMLDOMNode_AddRef( node );
337 /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */
339 return (IXMLDOMNamedNodeMap*) &nodemap->lpVtbl;