quartz: Add stubbed IAMDirectSound interface to DSoundRenderer.
[wine.git] / dlls / msxml3 / nodelist.c
blob011fff0bf61910bd9ede1eaf372afa94d7e09abb
1 /*
2 * Node list 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 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "msxml2.h"
32 #include "msxml_private.h"
34 #include "wine/debug.h"
36 /* This file implements the object returned by childNodes property. Note that this is
37 * not the IXMLDOMNodeList returned by XPath querites - it's implemented in queryresult.c.
38 * They are different because the list returned by childNodes:
39 * - is "live" - changes to the XML tree are automatically reflected in the list
40 * - doesn't supports IXMLDOMSelection
41 * - note that an attribute node have a text child in DOM but not in the XPath data model
42 * thus the child is inaccessible by an XPath query
45 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
47 #ifdef HAVE_LIBXML2
49 typedef struct _xmlnodelist
51 const struct IXMLDOMNodeListVtbl *lpVtbl;
52 LONG ref;
53 xmlNodePtr parent;
54 xmlNodePtr current;
55 } xmlnodelist;
57 static inline xmlnodelist *impl_from_IXMLDOMNodeList( IXMLDOMNodeList *iface )
59 return (xmlnodelist *)((char*)iface - FIELD_OFFSET(xmlnodelist, lpVtbl));
62 static HRESULT WINAPI xmlnodelist_QueryInterface(
63 IXMLDOMNodeList *iface,
64 REFIID riid,
65 void** ppvObject )
67 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
69 if(!ppvObject)
70 return E_INVALIDARG;
72 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
73 IsEqualGUID( riid, &IID_IDispatch ) ||
74 IsEqualGUID( riid, &IID_IXMLDOMNodeList ) )
76 *ppvObject = iface;
78 else
80 FIXME("interface %s not implemented\n", debugstr_guid(riid));
81 *ppvObject = NULL;
82 return E_NOINTERFACE;
85 IXMLDOMNodeList_AddRef( iface );
87 return S_OK;
90 static ULONG WINAPI xmlnodelist_AddRef(
91 IXMLDOMNodeList *iface )
93 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
94 return InterlockedIncrement( &This->ref );
97 static ULONG WINAPI xmlnodelist_Release(
98 IXMLDOMNodeList *iface )
100 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
101 ULONG ref;
103 ref = InterlockedDecrement( &This->ref );
104 if ( ref == 0 )
106 xmldoc_release( This->parent->doc );
107 heap_free( This );
110 return ref;
113 static HRESULT WINAPI xmlnodelist_GetTypeInfoCount(
114 IXMLDOMNodeList *iface,
115 UINT* pctinfo )
117 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
119 TRACE("(%p)->(%p)\n", This, pctinfo);
121 *pctinfo = 1;
123 return S_OK;
126 static HRESULT WINAPI xmlnodelist_GetTypeInfo(
127 IXMLDOMNodeList *iface,
128 UINT iTInfo,
129 LCID lcid,
130 ITypeInfo** ppTInfo )
132 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
133 HRESULT hr;
135 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
137 hr = get_typeinfo(IXMLDOMNodeList_tid, ppTInfo);
139 return hr;
142 static HRESULT WINAPI xmlnodelist_GetIDsOfNames(
143 IXMLDOMNodeList *iface,
144 REFIID riid,
145 LPOLESTR* rgszNames,
146 UINT cNames,
147 LCID lcid,
148 DISPID* rgDispId )
150 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
151 ITypeInfo *typeinfo;
152 HRESULT hr;
154 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
155 lcid, rgDispId);
157 if(!rgszNames || cNames == 0 || !rgDispId)
158 return E_INVALIDARG;
160 hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
161 if(SUCCEEDED(hr))
163 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
164 ITypeInfo_Release(typeinfo);
167 return hr;
170 static HRESULT WINAPI xmlnodelist_Invoke(
171 IXMLDOMNodeList *iface,
172 DISPID dispIdMember,
173 REFIID riid,
174 LCID lcid,
175 WORD wFlags,
176 DISPPARAMS* pDispParams,
177 VARIANT* pVarResult,
178 EXCEPINFO* pExcepInfo,
179 UINT* puArgErr )
181 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
182 ITypeInfo *typeinfo;
183 HRESULT hr;
185 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
186 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
188 hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
189 if(SUCCEEDED(hr))
191 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
192 pVarResult, pExcepInfo, puArgErr);
193 ITypeInfo_Release(typeinfo);
196 return hr;
199 static HRESULT WINAPI xmlnodelist_get_item(
200 IXMLDOMNodeList* iface,
201 LONG index,
202 IXMLDOMNode** listItem)
204 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
205 xmlNodePtr curr;
206 LONG nodeIndex = 0;
208 TRACE("%p %d\n", This, index);
210 if(!listItem)
211 return E_INVALIDARG;
213 *listItem = NULL;
215 if (index < 0)
216 return S_FALSE;
218 curr = This->parent->children;
219 while(curr)
221 if(nodeIndex++ == index) break;
222 curr = curr->next;
224 if(!curr) return S_FALSE;
226 *listItem = create_node( curr );
228 return S_OK;
231 static HRESULT WINAPI xmlnodelist_get_length(
232 IXMLDOMNodeList* iface,
233 LONG* listLength)
236 xmlNodePtr curr;
237 LONG nodeCount = 0;
239 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
241 TRACE("%p\n", This);
243 if(!listLength)
244 return E_INVALIDARG;
246 curr = This->parent->children;
247 while (curr)
249 nodeCount++;
250 curr = curr->next;
253 *listLength = nodeCount;
254 return S_OK;
257 static HRESULT WINAPI xmlnodelist_nextNode(
258 IXMLDOMNodeList* iface,
259 IXMLDOMNode** nextItem)
261 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
263 TRACE("%p %p\n", This, nextItem );
265 if(!nextItem)
266 return E_INVALIDARG;
268 *nextItem = NULL;
270 if (!This->current)
271 return S_FALSE;
273 *nextItem = create_node( This->current );
274 This->current = This->current->next;
275 return S_OK;
278 static HRESULT WINAPI xmlnodelist_reset(
279 IXMLDOMNodeList* iface)
281 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
283 TRACE("%p\n", This);
284 This->current = This->parent->children;
285 return S_OK;
288 static HRESULT WINAPI xmlnodelist__newEnum(
289 IXMLDOMNodeList* iface,
290 IUnknown** ppUnk)
292 FIXME("\n");
293 return E_NOTIMPL;
297 static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl =
299 xmlnodelist_QueryInterface,
300 xmlnodelist_AddRef,
301 xmlnodelist_Release,
302 xmlnodelist_GetTypeInfoCount,
303 xmlnodelist_GetTypeInfo,
304 xmlnodelist_GetIDsOfNames,
305 xmlnodelist_Invoke,
306 xmlnodelist_get_item,
307 xmlnodelist_get_length,
308 xmlnodelist_nextNode,
309 xmlnodelist_reset,
310 xmlnodelist__newEnum,
313 IXMLDOMNodeList* create_children_nodelist( xmlNodePtr node )
315 xmlnodelist *nodelist;
317 nodelist = heap_alloc( sizeof *nodelist );
318 if ( !nodelist )
319 return NULL;
321 nodelist->lpVtbl = &xmlnodelist_vtbl;
322 nodelist->ref = 1;
323 nodelist->parent = node;
324 nodelist->current = node->children;
326 xmldoc_add_ref( node->doc );
328 return (IXMLDOMNodeList*) &nodelist->lpVtbl;
331 #endif