ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

nodelist.c
Go to the documentation of this file.
00001 /*
00002  *    Node list implementation
00003  *
00004  * Copyright 2005 Mike McCormack
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #define COBJMACROS
00022 
00023 #include "config.h"
00024 
00025 #include <stdarg.h>
00026 #include "windef.h"
00027 #include "winbase.h"
00028 #include "winuser.h"
00029 #include "ole2.h"
00030 #include "msxml2.h"
00031 
00032 #include "msxml_private.h"
00033 
00034 #include "wine/debug.h"
00035 
00036 /* This file implements the object returned by childNodes property. Note that this is
00037  * not the IXMLDOMNodeList returned by XPath querites - it's implemented in queryresult.c.
00038  * They are different because the list returned by childNodes:
00039  *  - is "live" - changes to the XML tree are automatically reflected in the list
00040  *  - doesn't supports IXMLDOMSelection
00041  *  - note that an attribute node have a text child in DOM but not in the XPath data model
00042  *    thus the child is inaccessible by an XPath query
00043  */
00044 
00045 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
00046 
00047 #ifdef HAVE_LIBXML2
00048 
00049 typedef struct _xmlnodelist
00050 {
00051     const struct IXMLDOMNodeListVtbl *lpVtbl;
00052     LONG ref;
00053     xmlNodePtr parent;
00054     xmlNodePtr current;
00055 } xmlnodelist;
00056 
00057 static inline xmlnodelist *impl_from_IXMLDOMNodeList( IXMLDOMNodeList *iface )
00058 {
00059     return (xmlnodelist *)((char*)iface - FIELD_OFFSET(xmlnodelist, lpVtbl));
00060 }
00061 
00062 static HRESULT WINAPI xmlnodelist_QueryInterface(
00063     IXMLDOMNodeList *iface,
00064     REFIID riid,
00065     void** ppvObject )
00066 {
00067     TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
00068 
00069     if(!ppvObject)
00070         return E_INVALIDARG;
00071 
00072     if ( IsEqualGUID( riid, &IID_IUnknown ) ||
00073          IsEqualGUID( riid, &IID_IDispatch ) ||
00074          IsEqualGUID( riid, &IID_IXMLDOMNodeList ) )
00075     {
00076         *ppvObject = iface;
00077     }
00078     else
00079     {
00080         FIXME("interface %s not implemented\n", debugstr_guid(riid));
00081         *ppvObject = NULL;
00082         return E_NOINTERFACE;
00083     }
00084 
00085     IXMLDOMNodeList_AddRef( iface );
00086 
00087     return S_OK;
00088 }
00089 
00090 static ULONG WINAPI xmlnodelist_AddRef(
00091     IXMLDOMNodeList *iface )
00092 {
00093     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00094     return InterlockedIncrement( &This->ref );
00095 }
00096 
00097 static ULONG WINAPI xmlnodelist_Release(
00098     IXMLDOMNodeList *iface )
00099 {
00100     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00101     ULONG ref;
00102 
00103     ref = InterlockedDecrement( &This->ref );
00104     if ( ref == 0 )
00105     {
00106         xmldoc_release( This->parent->doc );
00107         heap_free( This );
00108     }
00109 
00110     return ref;
00111 }
00112 
00113 static HRESULT WINAPI xmlnodelist_GetTypeInfoCount(
00114     IXMLDOMNodeList *iface,
00115     UINT* pctinfo )
00116 {
00117     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00118 
00119     TRACE("(%p)->(%p)\n", This, pctinfo);
00120 
00121     *pctinfo = 1;
00122 
00123     return S_OK;
00124 }
00125 
00126 static HRESULT WINAPI xmlnodelist_GetTypeInfo(
00127     IXMLDOMNodeList *iface,
00128     UINT iTInfo,
00129     LCID lcid,
00130     ITypeInfo** ppTInfo )
00131 {
00132     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00133     HRESULT hr;
00134 
00135     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
00136 
00137     hr = get_typeinfo(IXMLDOMNodeList_tid, ppTInfo);
00138 
00139     return hr;
00140 }
00141 
00142 static HRESULT WINAPI xmlnodelist_GetIDsOfNames(
00143     IXMLDOMNodeList *iface,
00144     REFIID riid,
00145     LPOLESTR* rgszNames,
00146     UINT cNames,
00147     LCID lcid,
00148     DISPID* rgDispId )
00149 {
00150     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00151     ITypeInfo *typeinfo;
00152     HRESULT hr;
00153 
00154     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
00155           lcid, rgDispId);
00156 
00157     if(!rgszNames || cNames == 0 || !rgDispId)
00158         return E_INVALIDARG;
00159 
00160     hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
00161     if(SUCCEEDED(hr))
00162     {
00163         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
00164         ITypeInfo_Release(typeinfo);
00165     }
00166 
00167     return hr;
00168 }
00169 
00170 static HRESULT WINAPI xmlnodelist_Invoke(
00171     IXMLDOMNodeList *iface,
00172     DISPID dispIdMember,
00173     REFIID riid,
00174     LCID lcid,
00175     WORD wFlags,
00176     DISPPARAMS* pDispParams,
00177     VARIANT* pVarResult,
00178     EXCEPINFO* pExcepInfo,
00179     UINT* puArgErr )
00180 {
00181     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00182     ITypeInfo *typeinfo;
00183     HRESULT hr;
00184 
00185     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
00186           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
00187 
00188     hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
00189     if(SUCCEEDED(hr))
00190     {
00191         hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
00192                 pVarResult, pExcepInfo, puArgErr);
00193         ITypeInfo_Release(typeinfo);
00194     }
00195 
00196     return hr;
00197 }
00198 
00199 static HRESULT WINAPI xmlnodelist_get_item(
00200         IXMLDOMNodeList* iface,
00201         LONG index,
00202         IXMLDOMNode** listItem)
00203 {
00204     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00205     xmlNodePtr curr;
00206     LONG nodeIndex = 0;
00207 
00208     TRACE("(%p)->(%d %p)\n", This, index, listItem);
00209 
00210     if(!listItem)
00211         return E_INVALIDARG;
00212 
00213     *listItem = NULL;
00214 
00215     if (index < 0)
00216         return S_FALSE;
00217 
00218     curr = This->parent->children;
00219     while(curr)
00220     {
00221         if(nodeIndex++ == index) break;
00222         curr = curr->next;
00223     }
00224     if(!curr) return S_FALSE;
00225 
00226     *listItem = create_node( curr );
00227 
00228     return S_OK;
00229 }
00230 
00231 static HRESULT WINAPI xmlnodelist_get_length(
00232         IXMLDOMNodeList* iface,
00233         LONG* listLength)
00234 {
00235 
00236     xmlNodePtr curr;
00237     LONG nodeCount = 0;
00238 
00239     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00240 
00241     TRACE("(%p)->(%p)\n", This, listLength);
00242 
00243     if(!listLength)
00244         return E_INVALIDARG;
00245 
00246     curr = This->parent->children;
00247     while (curr)
00248     {
00249         nodeCount++;
00250         curr = curr->next;
00251     }
00252 
00253     *listLength = nodeCount;
00254     return S_OK;
00255 }
00256 
00257 static HRESULT WINAPI xmlnodelist_nextNode(
00258         IXMLDOMNodeList* iface,
00259         IXMLDOMNode** nextItem)
00260 {
00261     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00262 
00263     TRACE("(%p)->(%p)\n", This, nextItem );
00264 
00265     if(!nextItem)
00266         return E_INVALIDARG;
00267 
00268     *nextItem = NULL;
00269 
00270     if (!This->current)
00271         return S_FALSE;
00272 
00273     *nextItem = create_node( This->current );
00274     This->current = This->current->next;
00275     return S_OK;
00276 }
00277 
00278 static HRESULT WINAPI xmlnodelist_reset(
00279         IXMLDOMNodeList* iface)
00280 {
00281     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00282 
00283     TRACE("%p\n", This);
00284     This->current = This->parent->children;
00285     return S_OK;
00286 }
00287 
00288 static HRESULT WINAPI xmlnodelist__newEnum(
00289         IXMLDOMNodeList* iface,
00290         IUnknown** ppUnk)
00291 {
00292     xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
00293     FIXME("(%p)->(%p)\n", This, ppUnk);
00294     return E_NOTIMPL;
00295 }
00296 
00297 
00298 static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl =
00299 {
00300     xmlnodelist_QueryInterface,
00301     xmlnodelist_AddRef,
00302     xmlnodelist_Release,
00303     xmlnodelist_GetTypeInfoCount,
00304     xmlnodelist_GetTypeInfo,
00305     xmlnodelist_GetIDsOfNames,
00306     xmlnodelist_Invoke,
00307     xmlnodelist_get_item,
00308     xmlnodelist_get_length,
00309     xmlnodelist_nextNode,
00310     xmlnodelist_reset,
00311     xmlnodelist__newEnum,
00312 };
00313 
00314 IXMLDOMNodeList* create_children_nodelist( xmlNodePtr node )
00315 {
00316     xmlnodelist *nodelist;
00317 
00318     nodelist = heap_alloc( sizeof *nodelist );
00319     if ( !nodelist )
00320         return NULL;
00321 
00322     nodelist->lpVtbl = &xmlnodelist_vtbl;
00323     nodelist->ref = 1;
00324     nodelist->parent = node;
00325     nodelist->current = node->children;
00326 
00327     xmldoc_add_ref( node->doc );
00328 
00329     return (IXMLDOMNodeList*) &nodelist->lpVtbl;
00330 }
00331 
00332 #endif

Generated on Mon May 28 2012 04:24:58 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.