2005-08-19 17:18:05 +02:00
|
|
|
/*
|
|
|
|
* Node list implementation
|
|
|
|
*
|
|
|
|
* Copyright 2005 Mike McCormack
|
|
|
|
*
|
2005-11-08 13:46:43 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
2005-08-19 17:18:05 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2005-11-08 13:46:43 +01:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2005-08-19 17:18:05 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-08-19 17:18:05 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2011-02-24 13:11:53 +01:00
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
# include <libxml/parser.h>
|
|
|
|
# include <libxml/xmlerror.h>
|
|
|
|
#endif
|
|
|
|
|
2005-08-19 17:18:05 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2010-08-29 23:31:49 +02:00
|
|
|
#include "msxml6.h"
|
2005-08-19 17:18:05 +02:00
|
|
|
|
|
|
|
#include "msxml_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2007-05-11 17:03:13 +02:00
|
|
|
/* This file implements the object returned by childNodes property. Note that this is
|
|
|
|
* not the IXMLDOMNodeList returned by XPath querites - it's implemented in queryresult.c.
|
|
|
|
* They are different because the list returned by childNodes:
|
|
|
|
* - is "live" - changes to the XML tree are automatically reflected in the list
|
|
|
|
* - doesn't supports IXMLDOMSelection
|
|
|
|
* - note that an attribute node have a text child in DOM but not in the XPath data model
|
|
|
|
* thus the child is inaccessible by an XPath query
|
|
|
|
*/
|
|
|
|
|
2005-09-03 11:39:38 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
|
|
|
|
|
2005-08-19 17:18:05 +02:00
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
|
|
|
|
typedef struct _xmlnodelist
|
|
|
|
{
|
2010-12-16 01:04:15 +01:00
|
|
|
IXMLDOMNodeList IXMLDOMNodeList_iface;
|
2005-08-19 17:18:05 +02:00
|
|
|
LONG ref;
|
2007-05-11 17:03:13 +02:00
|
|
|
xmlNodePtr parent;
|
2005-08-19 17:18:05 +02:00
|
|
|
xmlNodePtr current;
|
|
|
|
} xmlnodelist;
|
|
|
|
|
|
|
|
static inline xmlnodelist *impl_from_IXMLDOMNodeList( IXMLDOMNodeList *iface )
|
|
|
|
{
|
2010-12-16 01:04:15 +01:00
|
|
|
return CONTAINING_RECORD(iface, xmlnodelist, IXMLDOMNodeList_iface);
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist_QueryInterface(
|
|
|
|
IXMLDOMNodeList *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject )
|
|
|
|
{
|
2010-02-17 07:40:40 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
|
2005-08-19 17:18:05 +02:00
|
|
|
|
|
|
|
if ( IsEqualGUID( riid, &IID_IUnknown ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IDispatch ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IXMLDOMNodeList ) )
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else
|
2006-01-27 19:22:56 +01:00
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
2006-06-12 02:34:17 +02:00
|
|
|
*ppvObject = NULL;
|
2005-08-19 17:18:05 +02:00
|
|
|
return E_NOINTERFACE;
|
2006-01-27 19:22:56 +01:00
|
|
|
}
|
2005-08-19 17:18:05 +02:00
|
|
|
|
|
|
|
IXMLDOMNodeList_AddRef( iface );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlnodelist_AddRef(
|
|
|
|
IXMLDOMNodeList *iface )
|
|
|
|
{
|
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
return InterlockedIncrement( &This->ref );
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlnodelist_Release(
|
|
|
|
IXMLDOMNodeList *iface )
|
|
|
|
{
|
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
ULONG ref;
|
|
|
|
|
|
|
|
ref = InterlockedDecrement( &This->ref );
|
|
|
|
if ( ref == 0 )
|
|
|
|
{
|
2007-05-11 17:03:13 +02:00
|
|
|
xmldoc_release( This->parent->doc );
|
2010-02-03 20:47:53 +01:00
|
|
|
heap_free( This );
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist_GetTypeInfoCount(
|
|
|
|
IXMLDOMNodeList *iface,
|
|
|
|
UINT* pctinfo )
|
|
|
|
{
|
2008-02-21 10:24:32 +01:00
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pctinfo);
|
|
|
|
|
|
|
|
*pctinfo = 1;
|
|
|
|
|
|
|
|
return S_OK;
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist_GetTypeInfo(
|
|
|
|
IXMLDOMNodeList *iface,
|
|
|
|
UINT iTInfo,
|
|
|
|
LCID lcid,
|
|
|
|
ITypeInfo** ppTInfo )
|
|
|
|
{
|
2008-02-21 10:24:32 +01:00
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
|
|
|
|
|
|
|
|
hr = get_typeinfo(IXMLDOMNodeList_tid, ppTInfo);
|
|
|
|
|
|
|
|
return hr;
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist_GetIDsOfNames(
|
|
|
|
IXMLDOMNodeList *iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPOLESTR* rgszNames,
|
|
|
|
UINT cNames,
|
|
|
|
LCID lcid,
|
|
|
|
DISPID* rgDispId )
|
|
|
|
{
|
2008-02-21 10:24:32 +01:00
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
ITypeInfo *typeinfo;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
|
|
|
|
lcid, rgDispId);
|
|
|
|
|
|
|
|
if(!rgszNames || cNames == 0 || !rgDispId)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
|
|
|
|
ITypeInfo_Release(typeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist_Invoke(
|
|
|
|
IXMLDOMNodeList *iface,
|
|
|
|
DISPID dispIdMember,
|
|
|
|
REFIID riid,
|
|
|
|
LCID lcid,
|
|
|
|
WORD wFlags,
|
|
|
|
DISPPARAMS* pDispParams,
|
|
|
|
VARIANT* pVarResult,
|
|
|
|
EXCEPINFO* pExcepInfo,
|
|
|
|
UINT* puArgErr )
|
|
|
|
{
|
2008-02-21 10:24:32 +01:00
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
ITypeInfo *typeinfo;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
|
|
|
|
lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
|
|
|
|
hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
2010-12-16 01:04:15 +01:00
|
|
|
hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMNodeList_iface, dispIdMember, wFlags,
|
|
|
|
pDispParams, pVarResult, pExcepInfo, puArgErr);
|
2008-02-21 10:24:32 +01:00
|
|
|
ITypeInfo_Release(typeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist_get_item(
|
|
|
|
IXMLDOMNodeList* iface,
|
2009-03-09 23:28:16 +01:00
|
|
|
LONG index,
|
2005-08-19 17:18:05 +02:00
|
|
|
IXMLDOMNode** listItem)
|
|
|
|
{
|
2005-11-03 13:04:52 +01:00
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
2007-05-11 17:03:13 +02:00
|
|
|
xmlNodePtr curr;
|
2009-03-09 23:28:53 +01:00
|
|
|
LONG nodeIndex = 0;
|
2005-11-03 13:04:52 +01:00
|
|
|
|
2010-02-17 07:40:40 +01:00
|
|
|
TRACE("(%p)->(%d %p)\n", This, index, listItem);
|
2008-07-02 08:16:05 +02:00
|
|
|
|
|
|
|
if(!listItem)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2005-11-03 13:04:52 +01:00
|
|
|
*listItem = NULL;
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2007-05-11 17:03:13 +02:00
|
|
|
curr = This->parent->children;
|
2005-11-05 11:42:45 +01:00
|
|
|
while(curr)
|
|
|
|
{
|
|
|
|
if(nodeIndex++ == index) break;
|
2007-05-11 17:03:13 +02:00
|
|
|
curr = curr->next;
|
2005-11-03 13:04:52 +01:00
|
|
|
}
|
2005-11-05 11:42:45 +01:00
|
|
|
if(!curr) return S_FALSE;
|
|
|
|
|
2005-11-03 13:04:52 +01:00
|
|
|
*listItem = create_node( curr );
|
|
|
|
|
|
|
|
return S_OK;
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist_get_length(
|
|
|
|
IXMLDOMNodeList* iface,
|
2009-03-09 23:28:16 +01:00
|
|
|
LONG* listLength)
|
2005-08-19 17:18:05 +02:00
|
|
|
{
|
2005-11-03 13:04:52 +01:00
|
|
|
|
2007-05-11 17:03:13 +02:00
|
|
|
xmlNodePtr curr;
|
2009-03-09 23:28:53 +01:00
|
|
|
LONG nodeCount = 0;
|
2005-11-03 13:04:52 +01:00
|
|
|
|
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
|
2010-02-17 07:40:40 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, listLength);
|
2005-11-03 13:04:52 +01:00
|
|
|
|
2008-07-02 08:16:05 +02:00
|
|
|
if(!listLength)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-05-11 17:03:13 +02:00
|
|
|
curr = This->parent->children;
|
2006-10-22 21:48:42 +02:00
|
|
|
while (curr)
|
2005-11-05 11:42:45 +01:00
|
|
|
{
|
2005-11-03 13:04:52 +01:00
|
|
|
nodeCount++;
|
2007-05-11 17:03:13 +02:00
|
|
|
curr = curr->next;
|
2005-11-03 13:04:52 +01:00
|
|
|
}
|
2005-11-05 11:42:45 +01:00
|
|
|
|
|
|
|
*listLength = nodeCount;
|
2005-11-03 13:04:52 +01:00
|
|
|
return S_OK;
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist_nextNode(
|
|
|
|
IXMLDOMNodeList* iface,
|
|
|
|
IXMLDOMNode** nextItem)
|
|
|
|
{
|
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
|
2010-02-17 07:40:40 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, nextItem );
|
2005-08-19 17:18:05 +02:00
|
|
|
|
2008-07-02 08:16:05 +02:00
|
|
|
if(!nextItem)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2006-06-12 02:34:17 +02:00
|
|
|
*nextItem = NULL;
|
|
|
|
|
2005-08-19 17:18:05 +02:00
|
|
|
if (!This->current)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
*nextItem = create_node( This->current );
|
2007-05-11 17:03:13 +02:00
|
|
|
This->current = This->current->next;
|
2005-08-19 17:18:05 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist_reset(
|
|
|
|
IXMLDOMNodeList* iface)
|
|
|
|
{
|
2005-09-03 11:39:38 +02:00
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
|
|
|
|
TRACE("%p\n", This);
|
2007-05-11 17:03:13 +02:00
|
|
|
This->current = This->parent->children;
|
2005-09-03 11:39:38 +02:00
|
|
|
return S_OK;
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlnodelist__newEnum(
|
|
|
|
IXMLDOMNodeList* iface,
|
|
|
|
IUnknown** ppUnk)
|
|
|
|
{
|
2010-02-17 07:40:40 +01:00
|
|
|
xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
|
|
|
|
FIXME("(%p)->(%p)\n", This, ppUnk);
|
2005-08-19 17:18:05 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl =
|
|
|
|
{
|
|
|
|
xmlnodelist_QueryInterface,
|
|
|
|
xmlnodelist_AddRef,
|
|
|
|
xmlnodelist_Release,
|
|
|
|
xmlnodelist_GetTypeInfoCount,
|
|
|
|
xmlnodelist_GetTypeInfo,
|
|
|
|
xmlnodelist_GetIDsOfNames,
|
|
|
|
xmlnodelist_Invoke,
|
|
|
|
xmlnodelist_get_item,
|
|
|
|
xmlnodelist_get_length,
|
|
|
|
xmlnodelist_nextNode,
|
|
|
|
xmlnodelist_reset,
|
|
|
|
xmlnodelist__newEnum,
|
|
|
|
};
|
|
|
|
|
2007-05-11 17:03:13 +02:00
|
|
|
IXMLDOMNodeList* create_children_nodelist( xmlNodePtr node )
|
2005-08-19 17:18:05 +02:00
|
|
|
{
|
|
|
|
xmlnodelist *nodelist;
|
|
|
|
|
2010-02-03 20:47:53 +01:00
|
|
|
nodelist = heap_alloc( sizeof *nodelist );
|
2005-08-19 17:18:05 +02:00
|
|
|
if ( !nodelist )
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-16 01:04:15 +01:00
|
|
|
nodelist->IXMLDOMNodeList_iface.lpVtbl = &xmlnodelist_vtbl;
|
2005-08-19 17:18:05 +02:00
|
|
|
nodelist->ref = 1;
|
2007-05-11 17:03:13 +02:00
|
|
|
nodelist->parent = node;
|
|
|
|
nodelist->current = node->children;
|
2005-08-19 17:18:05 +02:00
|
|
|
|
2007-05-11 17:03:13 +02:00
|
|
|
xmldoc_add_ref( node->doc );
|
2005-11-18 16:05:26 +01:00
|
|
|
|
2010-12-16 01:04:15 +01:00
|
|
|
return &nodelist->IXMLDOMNodeList_iface;
|
2005-08-19 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|