wined3d: Add a test for fixed function bump mapping.
[wine/multimedia.git] / dlls / msxml3 / nodemap.c
blob1a7d4dcec93e23a7f8bbef7569866cc3f3a2ab76
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 long iterator;
48 } xmlnodemap;
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 ) )
71 *ppvObject = iface;
73 else if( IsEqualGUID( riid, &IID_ISupportErrorInfo ))
75 *ppvObject = &This->lpSEIVtbl;
77 else
79 FIXME("interface %s not implemented\n", debugstr_guid(riid));
80 return E_NOINTERFACE;
83 IXMLDOMElement_AddRef( iface );
85 return S_OK;
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 );
99 ULONG ref;
101 ref = InterlockedDecrement( &This->ref );
102 if ( ref == 0 )
104 IXMLDOMNode_Release( This->node );
105 HeapFree( GetProcessHeap(), 0, This );
108 return ref;
111 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount(
112 IXMLDOMNamedNodeMap *iface,
113 UINT* pctinfo )
115 FIXME("\n");
116 return E_NOTIMPL;
119 static HRESULT WINAPI xmlnodemap_GetTypeInfo(
120 IXMLDOMNamedNodeMap *iface,
121 UINT iTInfo, LCID lcid,
122 ITypeInfo** ppTInfo )
124 FIXME("\n");
125 return E_NOTIMPL;
128 static HRESULT WINAPI xmlnodemap_GetIDsOfNames(
129 IXMLDOMNamedNodeMap *iface,
130 REFIID riid, LPOLESTR* rgszNames,
131 UINT cNames, LCID lcid, DISPID* rgDispId )
133 FIXME("\n");
134 return E_NOTIMPL;
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 )
143 FIXME("\n");
144 return E_NOTIMPL;
147 xmlChar *xmlChar_from_wchar( LPWSTR str )
149 DWORD len;
150 xmlChar *xmlstr;
152 len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
153 xmlstr = HeapAlloc( GetProcessHeap(), 0, len );
154 if ( xmlstr )
155 WideCharToMultiByte( CP_UTF8, 0, str, -1, (LPSTR) xmlstr, len, NULL, NULL );
156 return xmlstr;
159 static HRESULT WINAPI xmlnodemap_getNamedItem(
160 IXMLDOMNamedNodeMap *iface,
161 BSTR name,
162 IXMLDOMNode** namedItem)
164 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
165 xmlChar *element_name;
166 xmlAttrPtr attr;
167 xmlNodePtr node;
169 TRACE("%p %s %p\n", This, debugstr_w(name), namedItem );
171 if ( !namedItem )
172 return E_INVALIDARG;
174 node = xmlNodePtr_from_domnode( This->node, 0 );
175 if ( !node )
176 return E_FAIL;
178 element_name = xmlChar_from_wchar( name );
179 attr = xmlHasNsProp( node, element_name, NULL );
180 HeapFree( GetProcessHeap(), 0, element_name );
182 if ( !attr )
184 *namedItem = NULL;
185 return S_FALSE;
188 *namedItem = create_node( (xmlNodePtr) attr );
190 return S_OK;
193 static HRESULT WINAPI xmlnodemap_setNamedItem(
194 IXMLDOMNamedNodeMap *iface,
195 IXMLDOMNode* newItem,
196 IXMLDOMNode** namedItem)
198 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
199 xmlnode *ThisNew = NULL;
200 xmlNodePtr nodeNew;
201 IXMLDOMNode *pAttr = NULL;
202 xmlNodePtr node;
204 TRACE("%p %p %p\n", This, newItem, namedItem );
206 if(!newItem)
207 return E_INVALIDARG;
209 if(namedItem) *namedItem = NULL;
211 node = xmlNodePtr_from_domnode( This->node, 0 );
212 if ( !node )
213 return E_FAIL;
215 /* Must be an Attribute */
216 IUnknown_QueryInterface(newItem, &IID_IXMLDOMNode, (LPVOID*)&pAttr);
217 if(pAttr)
219 ThisNew = impl_from_IXMLDOMNode( pAttr );
221 if(ThisNew->node->type != XML_ATTRIBUTE_NODE)
223 IUnknown_Release(pAttr);
224 return E_FAIL;
227 nodeNew = xmlAddChild(node, ThisNew->node);
229 if(namedItem)
230 *namedItem = create_node( nodeNew );
232 IUnknown_Release(pAttr);
234 return S_OK;
237 return E_INVALIDARG;
240 static HRESULT WINAPI xmlnodemap_removeNamedItem(
241 IXMLDOMNamedNodeMap *iface,
242 BSTR name,
243 IXMLDOMNode** namedItem)
245 FIXME("\n");
246 return E_NOTIMPL;
249 static HRESULT WINAPI xmlnodemap_get_item(
250 IXMLDOMNamedNodeMap *iface,
251 long index,
252 IXMLDOMNode** listItem)
254 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
255 xmlNodePtr node;
256 xmlAttrPtr curr;
257 long attrIndex;
259 TRACE("%p %ld\n", This, index);
261 *listItem = NULL;
263 if (index < 0)
264 return S_FALSE;
266 node = xmlNodePtr_from_domnode( This->node, 0 );
267 curr = node->properties;
269 for (attrIndex = 0; attrIndex < index; attrIndex++) {
270 if (curr->next == NULL)
271 return S_FALSE;
272 else
273 curr = curr->next;
276 *listItem = create_node( (xmlNodePtr) curr );
278 return S_OK;
281 static HRESULT WINAPI xmlnodemap_get_length(
282 IXMLDOMNamedNodeMap *iface,
283 long* listLength)
285 xmlNodePtr node;
286 xmlAttrPtr first;
287 xmlAttrPtr curr;
288 long attrCount;
290 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
292 TRACE("%p\n", This);
294 node = xmlNodePtr_from_domnode( This->node, 0 );
295 if ( !node )
296 return E_FAIL;
298 first = node->properties;
299 if (first == NULL) {
300 *listLength = 0;
301 return S_OK;
304 curr = first;
305 attrCount = 1;
306 while (curr->next != NULL) {
307 attrCount++;
308 curr = curr->next;
310 *listLength = attrCount;
312 return S_OK;
315 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
316 IXMLDOMNamedNodeMap *iface,
317 BSTR baseName,
318 BSTR namespaceURI,
319 IXMLDOMNode** qualifiedItem)
321 FIXME("\n");
322 return E_NOTIMPL;
325 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
326 IXMLDOMNamedNodeMap *iface,
327 BSTR baseName,
328 BSTR namespaceURI,
329 IXMLDOMNode** qualifiedItem)
331 FIXME("\n");
332 return E_NOTIMPL;
335 static HRESULT WINAPI xmlnodemap_nextNode(
336 IXMLDOMNamedNodeMap *iface,
337 IXMLDOMNode** nextItem)
339 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
340 xmlNodePtr node;
341 xmlAttrPtr curr;
342 long attrIndex;
344 TRACE("%p %ld\n", This, This->iterator);
346 *nextItem = NULL;
348 node = xmlNodePtr_from_domnode( This->node, 0 );
349 curr = node->properties;
351 for (attrIndex = 0; attrIndex < This->iterator; attrIndex++) {
352 if (curr->next == NULL)
353 return S_FALSE;
354 else
355 curr = curr->next;
358 This->iterator++;
360 *nextItem = create_node( (xmlNodePtr) curr );
362 return S_OK;
365 static HRESULT WINAPI xmlnodemap_reset(
366 IXMLDOMNamedNodeMap *iface )
368 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
370 TRACE("%p %ld\n", This, This->iterator);
372 This->iterator = 0;
374 return S_OK;
377 static HRESULT WINAPI xmlnodemap__newEnum(
378 IXMLDOMNamedNodeMap *iface,
379 IUnknown** ppUnk)
381 FIXME("\n");
382 return E_NOTIMPL;
385 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl =
387 xmlnodemap_QueryInterface,
388 xmlnodemap_AddRef,
389 xmlnodemap_Release,
390 xmlnodemap_GetTypeInfoCount,
391 xmlnodemap_GetTypeInfo,
392 xmlnodemap_GetIDsOfNames,
393 xmlnodemap_Invoke,
394 xmlnodemap_getNamedItem,
395 xmlnodemap_setNamedItem,
396 xmlnodemap_removeNamedItem,
397 xmlnodemap_get_item,
398 xmlnodemap_get_length,
399 xmlnodemap_getQualifiedItem,
400 xmlnodemap_removeQualifiedItem,
401 xmlnodemap_nextNode,
402 xmlnodemap_reset,
403 xmlnodemap__newEnum,
406 static HRESULT WINAPI support_error_QueryInterface(
407 ISupportErrorInfo *iface,
408 REFIID riid, void** ppvObject )
410 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
411 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
413 return IXMLDOMNamedNodeMap_QueryInterface((IXMLDOMNamedNodeMap*)&This->lpVtbl, riid, ppvObject);
416 static ULONG WINAPI support_error_AddRef(
417 ISupportErrorInfo *iface )
419 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
420 return IXMLDOMNamedNodeMap_AddRef((IXMLDOMNamedNodeMap*)&This->lpVtbl);
423 static ULONG WINAPI support_error_Release(
424 ISupportErrorInfo *iface )
426 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
427 return IXMLDOMNamedNodeMap_Release((IXMLDOMNamedNodeMap*)&This->lpVtbl);
430 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo(
431 ISupportErrorInfo *iface,
432 REFIID riid )
434 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
435 return S_FALSE;
438 static const struct ISupportErrorInfoVtbl support_error_vtbl =
440 support_error_QueryInterface,
441 support_error_AddRef,
442 support_error_Release,
443 support_error_InterfaceSupportsErrorInfo
446 IXMLDOMNamedNodeMap *create_nodemap( IXMLDOMNode *node )
448 xmlnodemap *nodemap;
450 nodemap = HeapAlloc( GetProcessHeap(), 0, sizeof *nodemap );
451 if ( !nodemap )
452 return NULL;
454 nodemap->lpVtbl = &xmlnodemap_vtbl;
455 nodemap->lpSEIVtbl = &support_error_vtbl;
456 nodemap->node = node;
457 nodemap->ref = 1;
458 nodemap->iterator = 0;
460 IXMLDOMNode_AddRef( node );
461 /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */
463 return (IXMLDOMNamedNodeMap*) &nodemap->lpVtbl;
466 #endif