msxml: Add ISupportErrorInfo for named node maps.
[wine/wine-kai.git] / dlls / msxml3 / nodemap.c
blob4edb950bd46ae92238320df5745b2cd6284b397c
1 /*
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
21 #include "config.h"
23 #define COBJMACROS
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
31 #include "msxml2.h"
33 #include "msxml_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
39 #ifdef HAVE_LIBXML2
41 typedef struct _xmlnodemap
43 const struct IXMLDOMNamedNodeMapVtbl *lpVtbl;
44 const struct ISupportErrorInfoVtbl *lpSEIVtbl;
45 LONG ref;
46 IXMLDOMNode *node;
47 } xmlnodemap;
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 ) )
70 *ppvObject = iface;
72 else if( IsEqualGUID( riid, &IID_ISupportErrorInfo ))
74 *ppvObject = &This->lpSEIVtbl;
76 else
78 FIXME("interface %s not implemented\n", debugstr_guid(riid));
79 return E_NOINTERFACE;
82 IXMLDOMElement_AddRef( iface );
84 return S_OK;
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 );
98 ULONG ref;
100 ref = InterlockedDecrement( &This->ref );
101 if ( ref == 0 )
103 IXMLDOMNode_Release( This->node );
104 HeapFree( GetProcessHeap(), 0, This );
107 return ref;
110 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount(
111 IXMLDOMNamedNodeMap *iface,
112 UINT* pctinfo )
114 FIXME("\n");
115 return E_NOTIMPL;
118 static HRESULT WINAPI xmlnodemap_GetTypeInfo(
119 IXMLDOMNamedNodeMap *iface,
120 UINT iTInfo, LCID lcid,
121 ITypeInfo** ppTInfo )
123 FIXME("\n");
124 return E_NOTIMPL;
127 static HRESULT WINAPI xmlnodemap_GetIDsOfNames(
128 IXMLDOMNamedNodeMap *iface,
129 REFIID riid, LPOLESTR* rgszNames,
130 UINT cNames, LCID lcid, DISPID* rgDispId )
132 FIXME("\n");
133 return E_NOTIMPL;
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 )
142 FIXME("\n");
143 return E_NOTIMPL;
146 xmlChar *xmlChar_from_wchar( LPWSTR str )
148 DWORD len;
149 xmlChar *xmlstr;
151 len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
152 xmlstr = (xmlChar*) HeapAlloc( GetProcessHeap(), 0, len );
153 if ( xmlstr )
154 WideCharToMultiByte( CP_UTF8, 0, str, -1, (LPSTR) xmlstr, len, NULL, NULL );
155 return xmlstr;
158 static HRESULT WINAPI xmlnodemap_getNamedItem(
159 IXMLDOMNamedNodeMap *iface,
160 BSTR name,
161 IXMLDOMNode** namedItem)
163 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
164 xmlChar *element_name;
165 xmlAttrPtr attr;
166 xmlNodePtr node;
168 TRACE("%p %s\n", This, debugstr_w(name) );
170 node = xmlNodePtr_from_domnode( This->node, 0 );
171 if ( !node )
172 return E_FAIL;
174 element_name = xmlChar_from_wchar( name );
175 attr = xmlHasNsProp( node, element_name, NULL );
176 HeapFree( GetProcessHeap(), 0, element_name );
178 if ( !attr )
179 return E_FAIL;
181 *namedItem = create_node( (xmlNodePtr) attr );
183 return S_OK;
186 static HRESULT WINAPI xmlnodemap_setNamedItem(
187 IXMLDOMNamedNodeMap *iface,
188 IXMLDOMNode* newItem,
189 IXMLDOMNode** namedItem)
191 FIXME("\n");
192 return E_NOTIMPL;
195 static HRESULT WINAPI xmlnodemap_removeNamedItem(
196 IXMLDOMNamedNodeMap *iface,
197 BSTR name,
198 IXMLDOMNode** namedItem)
200 FIXME("\n");
201 return E_NOTIMPL;
204 static HRESULT WINAPI xmlnodemap_get_item(
205 IXMLDOMNamedNodeMap *iface,
206 long index,
207 IXMLDOMNode** listItem)
209 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
210 xmlNodePtr node;
211 xmlAttrPtr curr;
212 long attrIndex;
214 TRACE("%p %ld\n", This, index);
216 *listItem = NULL;
218 if (index < 0)
219 return S_FALSE;
221 node = xmlNodePtr_from_domnode( This->node, 0 );
222 curr = node->properties;
224 for (attrIndex = 0; attrIndex < index; attrIndex++) {
225 if (curr->next == NULL)
226 return S_FALSE;
227 else
228 curr = curr->next;
231 *listItem = create_node( (xmlNodePtr) curr );
233 return S_OK;
236 static HRESULT WINAPI xmlnodemap_get_length(
237 IXMLDOMNamedNodeMap *iface,
238 long* listLength)
240 xmlNodePtr node;
241 xmlAttrPtr first;
242 xmlAttrPtr curr;
243 long attrCount;
245 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
247 TRACE("%p\n", This);
249 node = xmlNodePtr_from_domnode( This->node, 0 );
250 if ( !node )
251 return E_FAIL;
253 first = node->properties;
254 if (first == NULL) {
255 *listLength = 0;
256 return S_OK;
259 curr = first;
260 attrCount = 1;
261 while (curr->next != NULL) {
262 attrCount++;
263 curr = curr->next;
265 *listLength = attrCount;
267 return S_OK;
270 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
271 IXMLDOMNamedNodeMap *iface,
272 BSTR baseName,
273 BSTR namespaceURI,
274 IXMLDOMNode** qualifiedItem)
276 FIXME("\n");
277 return E_NOTIMPL;
280 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
281 IXMLDOMNamedNodeMap *iface,
282 BSTR baseName,
283 BSTR namespaceURI,
284 IXMLDOMNode** qualifiedItem)
286 FIXME("\n");
287 return E_NOTIMPL;
290 static HRESULT WINAPI xmlnodemap_nextNode(
291 IXMLDOMNamedNodeMap *iface,
292 IXMLDOMNode** nextItem)
294 FIXME("\n");
295 return E_NOTIMPL;
298 static HRESULT WINAPI xmlnodemap_reset(
299 IXMLDOMNamedNodeMap *iface )
301 FIXME("\n");
302 return E_NOTIMPL;
305 static HRESULT WINAPI xmlnodemap__newEnum(
306 IXMLDOMNamedNodeMap *iface,
307 IUnknown** ppUnk)
309 FIXME("\n");
310 return E_NOTIMPL;
313 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl =
315 xmlnodemap_QueryInterface,
316 xmlnodemap_AddRef,
317 xmlnodemap_Release,
318 xmlnodemap_GetTypeInfoCount,
319 xmlnodemap_GetTypeInfo,
320 xmlnodemap_GetIDsOfNames,
321 xmlnodemap_Invoke,
322 xmlnodemap_getNamedItem,
323 xmlnodemap_setNamedItem,
324 xmlnodemap_removeNamedItem,
325 xmlnodemap_get_item,
326 xmlnodemap_get_length,
327 xmlnodemap_getQualifiedItem,
328 xmlnodemap_removeQualifiedItem,
329 xmlnodemap_nextNode,
330 xmlnodemap_reset,
331 xmlnodemap__newEnum,
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,
360 REFIID riid )
362 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
363 return S_FALSE;
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 )
376 xmlnodemap *nodemap;
378 nodemap = HeapAlloc( GetProcessHeap(), 0, sizeof *nodemap );
379 if ( !nodemap )
380 return NULL;
382 nodemap->lpVtbl = &xmlnodemap_vtbl;
383 nodemap->lpSEIVtbl = &support_error_vtbl;
384 nodemap->node = node;
385 nodemap->ref = 1;
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;
393 #endif