ntdll: move relocations from mapping into loader
[wine/kumbayo.git] / dlls / msxml3 / nodelist.c
blob9b1aa90483374a879d50cbe46beeda657380e044
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 ( IsEqualGUID( riid, &IID_IUnknown ) ||
70 IsEqualGUID( riid, &IID_IDispatch ) ||
71 IsEqualGUID( riid, &IID_IXMLDOMNodeList ) )
73 *ppvObject = iface;
75 else
77 FIXME("interface %s not implemented\n", debugstr_guid(riid));
78 *ppvObject = NULL;
79 return E_NOINTERFACE;
82 IXMLDOMNodeList_AddRef( iface );
84 return S_OK;
87 static ULONG WINAPI xmlnodelist_AddRef(
88 IXMLDOMNodeList *iface )
90 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
91 return InterlockedIncrement( &This->ref );
94 static ULONG WINAPI xmlnodelist_Release(
95 IXMLDOMNodeList *iface )
97 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
98 ULONG ref;
100 ref = InterlockedDecrement( &This->ref );
101 if ( ref == 0 )
103 xmldoc_release( This->parent->doc );
104 HeapFree( GetProcessHeap(), 0, This );
107 return ref;
110 static HRESULT WINAPI xmlnodelist_GetTypeInfoCount(
111 IXMLDOMNodeList *iface,
112 UINT* pctinfo )
114 FIXME("\n");
115 return E_NOTIMPL;
118 static HRESULT WINAPI xmlnodelist_GetTypeInfo(
119 IXMLDOMNodeList *iface,
120 UINT iTInfo,
121 LCID lcid,
122 ITypeInfo** ppTInfo )
124 FIXME("\n");
125 return E_NOTIMPL;
128 static HRESULT WINAPI xmlnodelist_GetIDsOfNames(
129 IXMLDOMNodeList *iface,
130 REFIID riid,
131 LPOLESTR* rgszNames,
132 UINT cNames,
133 LCID lcid,
134 DISPID* rgDispId )
136 FIXME("\n");
137 return E_NOTIMPL;
140 static HRESULT WINAPI xmlnodelist_Invoke(
141 IXMLDOMNodeList *iface,
142 DISPID dispIdMember,
143 REFIID riid,
144 LCID lcid,
145 WORD wFlags,
146 DISPPARAMS* pDispParams,
147 VARIANT* pVarResult,
148 EXCEPINFO* pExcepInfo,
149 UINT* puArgErr )
151 FIXME("\n");
152 return E_NOTIMPL;
155 static HRESULT WINAPI xmlnodelist_get_item(
156 IXMLDOMNodeList* iface,
157 long index,
158 IXMLDOMNode** listItem)
160 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
161 xmlNodePtr curr;
162 long nodeIndex = 0;
164 TRACE("%p %ld\n", This, index);
166 *listItem = NULL;
168 if (index < 0)
169 return S_FALSE;
171 curr = This->parent->children;
172 while(curr)
174 if(nodeIndex++ == index) break;
175 curr = curr->next;
177 if(!curr) return S_FALSE;
179 *listItem = create_node( curr );
181 return S_OK;
184 static HRESULT WINAPI xmlnodelist_get_length(
185 IXMLDOMNodeList* iface,
186 long* listLength)
189 xmlNodePtr curr;
190 long nodeCount = 0;
192 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
194 TRACE("%p\n", This);
196 curr = This->parent->children;
197 while (curr)
199 nodeCount++;
200 curr = curr->next;
203 *listLength = nodeCount;
204 return S_OK;
207 static HRESULT WINAPI xmlnodelist_nextNode(
208 IXMLDOMNodeList* iface,
209 IXMLDOMNode** nextItem)
211 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
213 TRACE("%p %p\n", This, nextItem );
215 *nextItem = NULL;
217 if (!This->current)
218 return S_FALSE;
220 *nextItem = create_node( This->current );
221 This->current = This->current->next;
222 return S_OK;
225 static HRESULT WINAPI xmlnodelist_reset(
226 IXMLDOMNodeList* iface)
228 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
230 TRACE("%p\n", This);
231 This->current = This->parent->children;
232 return S_OK;
235 static HRESULT WINAPI xmlnodelist__newEnum(
236 IXMLDOMNodeList* iface,
237 IUnknown** ppUnk)
239 FIXME("\n");
240 return E_NOTIMPL;
244 static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl =
246 xmlnodelist_QueryInterface,
247 xmlnodelist_AddRef,
248 xmlnodelist_Release,
249 xmlnodelist_GetTypeInfoCount,
250 xmlnodelist_GetTypeInfo,
251 xmlnodelist_GetIDsOfNames,
252 xmlnodelist_Invoke,
253 xmlnodelist_get_item,
254 xmlnodelist_get_length,
255 xmlnodelist_nextNode,
256 xmlnodelist_reset,
257 xmlnodelist__newEnum,
260 IXMLDOMNodeList* create_children_nodelist( xmlNodePtr node )
262 xmlnodelist *nodelist;
264 nodelist = HeapAlloc( GetProcessHeap(), 0, sizeof *nodelist );
265 if ( !nodelist )
266 return NULL;
268 nodelist->lpVtbl = &xmlnodelist_vtbl;
269 nodelist->ref = 1;
270 nodelist->parent = node;
271 nodelist->current = node->children;
273 xmldoc_add_ref( node->doc );
275 return (IXMLDOMNodeList*) &nodelist->lpVtbl;
278 #endif