Release 20050930.
[wine/gsoc-2012-control.git] / dlls / msxml3 / nodelist.c
blobc64eddb3d62eb9df1f49551f67265b5aa88aebc4
1 /*
2 * Node list implementation
4 * Copyright 2005 Mike McCormack
6 * iface 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 * iface 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "winnls.h"
30 #include "ole2.h"
31 #include "ocidl.h"
32 #include "msxml.h"
33 #include "xmldom.h"
34 #include "msxml.h"
36 #include "msxml_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
42 #ifdef HAVE_LIBXML2
44 #ifdef HAVE_LIBXSLT
46 #ifdef HAVE_LIBXSLT_PATTERN_H
47 #include <libxslt/pattern.h>
48 #endif
49 #ifdef HAVE_LIBXSLT_TRANSFORM_H
50 #include <libxslt/transform.h>
51 #endif
53 struct xslt_info {
54 xsltTransformContextPtr ctxt;
55 xsltCompMatchPtr pattern;
56 xsltStylesheetPtr sheet;
59 static void xlst_info_init( struct xslt_info *info )
61 info->ctxt = NULL;
62 info->pattern = NULL;
63 info->sheet = NULL;
66 static int create_xslt_parser( struct xslt_info *info, xmlNodePtr node, const xmlChar *str )
68 info->sheet = xsltNewStylesheet();
69 if (!info->sheet)
70 return 0;
72 info->ctxt = xsltNewTransformContext( info->sheet, node->doc );
73 if (!info->ctxt)
74 return 0;
76 info->pattern = xsltCompilePattern( str, node->doc,
77 node, info->sheet, info->ctxt );
78 if (!info->pattern)
79 return 0;
80 return 1;
83 void free_xslt_info( struct xslt_info *info )
85 if (info->pattern)
86 xsltFreeCompMatchList( info->pattern );
87 if (info->sheet)
88 xsltFreeStylesheet( info->sheet );
89 if (info->ctxt)
90 xsltFreeTransformContext( info->ctxt );
93 static HRESULT xslt_next_match( struct xslt_info *info, xmlNodePtr *node )
95 if (!info->ctxt)
96 return S_FALSE;
98 /* make sure that the current element matches the pattern */
99 while ( *node )
101 int r;
103 r = xsltTestCompMatchList( info->ctxt, *node, info->pattern );
104 if ( 1 == r )
106 TRACE("Matched %p (%s)\n", *node, (*node)->name );
107 return S_OK;
109 if (r != 0)
111 ERR("Pattern match failed\n");
112 return E_FAIL;
114 *node = (*node)->next;
116 return S_OK;
119 #else
121 struct xslt_info {
122 /* empty */
125 static void xlst_info_init( struct xslt_info *info )
129 void free_xslt_info( struct xslt_info *info )
133 static int create_xslt_parser( struct xslt_info *info, xmlNodePtr node, const xmlChar *str )
135 MESSAGE("libxslt was missing at compile time\n");
136 return 0;
139 static HRESULT xslt_next_match( struct xslt_info *info, xmlNodePtr *node )
141 return S_FALSE;
144 #endif
146 typedef struct _xmlnodelist
148 const struct IXMLDOMNodeListVtbl *lpVtbl;
149 LONG ref;
150 xmlNodePtr node;
151 xmlNodePtr current;
152 struct xslt_info xinfo;
153 } xmlnodelist;
155 static inline xmlnodelist *impl_from_IXMLDOMNodeList( IXMLDOMNodeList *iface )
157 return (xmlnodelist *)((char*)iface - FIELD_OFFSET(xmlnodelist, lpVtbl));
160 static HRESULT WINAPI xmlnodelist_QueryInterface(
161 IXMLDOMNodeList *iface,
162 REFIID riid,
163 void** ppvObject )
165 TRACE("%p %p %p\n", iface, debugstr_guid(riid), ppvObject);
167 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
168 IsEqualGUID( riid, &IID_IDispatch ) ||
169 IsEqualGUID( riid, &IID_IXMLDOMNodeList ) )
171 *ppvObject = iface;
173 else
174 return E_NOINTERFACE;
176 IXMLDOMNodeList_AddRef( iface );
178 return S_OK;
181 static ULONG WINAPI xmlnodelist_AddRef(
182 IXMLDOMNodeList *iface )
184 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
185 return InterlockedIncrement( &This->ref );
188 static ULONG WINAPI xmlnodelist_Release(
189 IXMLDOMNodeList *iface )
191 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
192 ULONG ref;
194 ref = InterlockedDecrement( &This->ref );
195 if ( ref == 0 )
197 free_xslt_info( &This->xinfo );
198 HeapFree( GetProcessHeap(), 0, This );
201 return ref;
204 static HRESULT WINAPI xmlnodelist_GetTypeInfoCount(
205 IXMLDOMNodeList *iface,
206 UINT* pctinfo )
208 FIXME("\n");
209 return E_NOTIMPL;
212 static HRESULT WINAPI xmlnodelist_GetTypeInfo(
213 IXMLDOMNodeList *iface,
214 UINT iTInfo,
215 LCID lcid,
216 ITypeInfo** ppTInfo )
218 FIXME("\n");
219 return E_NOTIMPL;
222 static HRESULT WINAPI xmlnodelist_GetIDsOfNames(
223 IXMLDOMNodeList *iface,
224 REFIID riid,
225 LPOLESTR* rgszNames,
226 UINT cNames,
227 LCID lcid,
228 DISPID* rgDispId )
230 FIXME("\n");
231 return E_NOTIMPL;
234 static HRESULT WINAPI xmlnodelist_Invoke(
235 IXMLDOMNodeList *iface,
236 DISPID dispIdMember,
237 REFIID riid,
238 LCID lcid,
239 WORD wFlags,
240 DISPPARAMS* pDispParams,
241 VARIANT* pVarResult,
242 EXCEPINFO* pExcepInfo,
243 UINT* puArgErr )
245 FIXME("\n");
246 return E_NOTIMPL;
249 static HRESULT WINAPI xmlnodelist_get_item(
250 IXMLDOMNodeList* iface,
251 long index,
252 IXMLDOMNode** listItem)
254 FIXME("\n");
255 return E_NOTIMPL;
258 static HRESULT WINAPI xmlnodelist_get_length(
259 IXMLDOMNodeList* iface,
260 long* listLength)
262 FIXME("\n");
263 return E_NOTIMPL;
266 static HRESULT WINAPI xmlnodelist_nextNode(
267 IXMLDOMNodeList* iface,
268 IXMLDOMNode** nextItem)
270 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
271 HRESULT r;
273 TRACE("%p %p\n", This, nextItem );
275 r = xslt_next_match( &This->xinfo, &This->current );
276 if (FAILED(r) )
277 return r;
279 if (!This->current)
280 return S_FALSE;
282 *nextItem = create_node( This->current );
283 This->current = This->current->next;
284 return S_OK;
287 static HRESULT WINAPI xmlnodelist_reset(
288 IXMLDOMNodeList* iface)
290 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
292 TRACE("%p\n", This);
293 This->current = This->node;
294 return S_OK;
297 static HRESULT WINAPI xmlnodelist__newEnum(
298 IXMLDOMNodeList* iface,
299 IUnknown** ppUnk)
301 FIXME("\n");
302 return E_NOTIMPL;
306 static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl =
308 xmlnodelist_QueryInterface,
309 xmlnodelist_AddRef,
310 xmlnodelist_Release,
311 xmlnodelist_GetTypeInfoCount,
312 xmlnodelist_GetTypeInfo,
313 xmlnodelist_GetIDsOfNames,
314 xmlnodelist_Invoke,
315 xmlnodelist_get_item,
316 xmlnodelist_get_length,
317 xmlnodelist_nextNode,
318 xmlnodelist_reset,
319 xmlnodelist__newEnum,
322 static xmlnodelist *new_nodelist( xmlNodePtr node )
324 xmlnodelist *nodelist;
326 nodelist = HeapAlloc( GetProcessHeap(), 0, sizeof *nodelist );
327 if ( !nodelist )
328 return NULL;
330 nodelist->lpVtbl = &xmlnodelist_vtbl;
331 nodelist->ref = 1;
332 nodelist->node = node;
333 nodelist->current = node;
334 xlst_info_init( &nodelist->xinfo );
336 return nodelist;
339 IXMLDOMNodeList* create_nodelist( xmlNodePtr node )
341 xmlnodelist *nodelist = new_nodelist( node );
342 if (!node)
343 return NULL;
344 return (IXMLDOMNodeList*) &nodelist->lpVtbl;
347 IXMLDOMNodeList* create_filtered_nodelist( xmlNodePtr node, const xmlChar *str )
349 xmlnodelist *This = new_nodelist( node );
351 if (create_xslt_parser( &This->xinfo, node, str ))
352 return (IXMLDOMNodeList*) &This->lpVtbl;
354 IXMLDOMNodeList_Release( (IXMLDOMNodeList*) &This->lpVtbl );
355 return NULL;
358 #endif