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
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
);
49 typedef struct _xmlnodelist
51 const struct IXMLDOMNodeListVtbl
*lpVtbl
;
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
,
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
) )
77 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
82 IXMLDOMNodeList_AddRef( iface
);
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
);
100 ref
= InterlockedDecrement( &This
->ref
);
103 xmldoc_release( This
->parent
->doc
);
104 HeapFree( GetProcessHeap(), 0, This
);
110 static HRESULT WINAPI
xmlnodelist_GetTypeInfoCount(
111 IXMLDOMNodeList
*iface
,
118 static HRESULT WINAPI
xmlnodelist_GetTypeInfo(
119 IXMLDOMNodeList
*iface
,
122 ITypeInfo
** ppTInfo
)
128 static HRESULT WINAPI
xmlnodelist_GetIDsOfNames(
129 IXMLDOMNodeList
*iface
,
140 static HRESULT WINAPI
xmlnodelist_Invoke(
141 IXMLDOMNodeList
*iface
,
146 DISPPARAMS
* pDispParams
,
148 EXCEPINFO
* pExcepInfo
,
155 static HRESULT WINAPI
xmlnodelist_get_item(
156 IXMLDOMNodeList
* iface
,
158 IXMLDOMNode
** listItem
)
160 xmlnodelist
*This
= impl_from_IXMLDOMNodeList( iface
);
164 TRACE("%p %ld\n", This
, index
);
171 curr
= This
->parent
->children
;
174 if(nodeIndex
++ == index
) break;
177 if(!curr
) return S_FALSE
;
179 *listItem
= create_node( curr
);
184 static HRESULT WINAPI
xmlnodelist_get_length(
185 IXMLDOMNodeList
* iface
,
192 xmlnodelist
*This
= impl_from_IXMLDOMNodeList( iface
);
196 curr
= This
->parent
->children
;
203 *listLength
= nodeCount
;
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
);
220 *nextItem
= create_node( This
->current
);
221 This
->current
= This
->current
->next
;
225 static HRESULT WINAPI
xmlnodelist_reset(
226 IXMLDOMNodeList
* iface
)
228 xmlnodelist
*This
= impl_from_IXMLDOMNodeList( iface
);
231 This
->current
= This
->parent
->children
;
235 static HRESULT WINAPI
xmlnodelist__newEnum(
236 IXMLDOMNodeList
* iface
,
244 static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl
=
246 xmlnodelist_QueryInterface
,
249 xmlnodelist_GetTypeInfoCount
,
250 xmlnodelist_GetTypeInfo
,
251 xmlnodelist_GetIDsOfNames
,
253 xmlnodelist_get_item
,
254 xmlnodelist_get_length
,
255 xmlnodelist_nextNode
,
257 xmlnodelist__newEnum
,
260 IXMLDOMNodeList
* create_children_nodelist( xmlNodePtr node
)
262 xmlnodelist
*nodelist
;
264 nodelist
= HeapAlloc( GetProcessHeap(), 0, sizeof *nodelist
);
268 nodelist
->lpVtbl
= &xmlnodelist_vtbl
;
270 nodelist
->parent
= node
;
271 nodelist
->current
= node
->children
;
273 xmldoc_add_ref( node
->doc
);
275 return (IXMLDOMNodeList
*) &nodelist
->lpVtbl
;