wineps: Fix a couple of typos in the path painting function.
[wine/testsucceed.git] / dlls / msxml3 / stylesheet.c
blob5a21d65a416de9fc9f75301bdbfec1e094d68dad
1 /*
2 * XSLTemplate/XSLProcessor support
4 * Copyright 2011 Nikolay Sivov for CodeWeavers
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 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 #endif
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "ole2.h"
35 #include "msxml6.h"
37 #include "msxml_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
43 #ifdef HAVE_LIBXML2
45 typedef struct _xsltemplate
47 IXSLTemplate IXSLTemplate_iface;
48 LONG ref;
50 IXMLDOMNode *node;
51 } xsltemplate;
53 typedef struct _xslprocessor
55 IXSLProcessor IXSLProcessor_iface;
56 LONG ref;
58 xsltemplate *stylesheet;
59 IXMLDOMNode *input;
61 IStream *output;
62 BSTR outstr;
63 } xslprocessor;
65 static HRESULT XSLProcessor_create(xsltemplate*, IXSLProcessor**);
67 static inline xsltemplate *impl_from_IXSLTemplate( IXSLTemplate *iface )
69 return CONTAINING_RECORD(iface, xsltemplate, IXSLTemplate_iface);
72 static inline xslprocessor *impl_from_IXSLProcessor( IXSLProcessor *iface )
74 return CONTAINING_RECORD(iface, xslprocessor, IXSLProcessor_iface);
77 static void xsltemplate_set_node( xsltemplate *This, IXMLDOMNode *node )
79 if (This->node) IXMLDOMNode_Release(This->node);
80 This->node = node;
81 if (node) IXMLDOMNode_AddRef(node);
84 static HRESULT WINAPI xsltemplate_QueryInterface(
85 IXSLTemplate *iface,
86 REFIID riid,
87 void** ppvObject )
89 xsltemplate *This = impl_from_IXSLTemplate( iface );
90 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
92 if ( IsEqualGUID( riid, &IID_IXSLTemplate ) ||
93 IsEqualGUID( riid, &IID_IDispatch ) ||
94 IsEqualGUID( riid, &IID_IUnknown ) )
96 *ppvObject = iface;
98 else
100 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
101 *ppvObject = NULL;
102 return E_NOINTERFACE;
105 IUnknown_AddRef((IUnknown*)*ppvObject);
106 return S_OK;
109 static ULONG WINAPI xsltemplate_AddRef( IXSLTemplate *iface )
111 xsltemplate *This = impl_from_IXSLTemplate( iface );
112 return InterlockedIncrement( &This->ref );
115 static ULONG WINAPI xsltemplate_Release( IXSLTemplate *iface )
117 xsltemplate *This = impl_from_IXSLTemplate( iface );
118 ULONG ref;
120 ref = InterlockedDecrement( &This->ref );
121 if ( ref == 0 )
123 if (This->node) IXMLDOMNode_Release( This->node );
124 heap_free( This );
127 return ref;
130 static HRESULT WINAPI xsltemplate_GetTypeInfoCount( IXSLTemplate *iface, UINT* pctinfo )
132 xsltemplate *This = impl_from_IXSLTemplate( iface );
134 TRACE("(%p)->(%p)\n", This, pctinfo);
136 *pctinfo = 1;
137 return S_OK;
140 static HRESULT WINAPI xsltemplate_GetTypeInfo(
141 IXSLTemplate *iface,
142 UINT iTInfo, LCID lcid,
143 ITypeInfo** ppTInfo )
145 xsltemplate *This = impl_from_IXSLTemplate( iface );
147 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
149 return get_typeinfo(IXSLTemplate_tid, ppTInfo);
152 static HRESULT WINAPI xsltemplate_GetIDsOfNames(
153 IXSLTemplate *iface,
154 REFIID riid, LPOLESTR* rgszNames,
155 UINT cNames, LCID lcid, DISPID* rgDispId )
157 xsltemplate *This = impl_from_IXSLTemplate( iface );
158 ITypeInfo *typeinfo;
159 HRESULT hr;
161 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
162 lcid, rgDispId);
164 if(!rgszNames || cNames == 0 || !rgDispId)
165 return E_INVALIDARG;
167 hr = get_typeinfo(IXSLTemplate_tid, &typeinfo);
168 if(SUCCEEDED(hr))
170 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
171 ITypeInfo_Release(typeinfo);
174 return hr;
177 static HRESULT WINAPI xsltemplate_Invoke(
178 IXSLTemplate *iface,
179 DISPID dispIdMember, REFIID riid, LCID lcid,
180 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
181 EXCEPINFO* pExcepInfo, UINT* puArgErr )
183 xsltemplate *This = impl_from_IXSLTemplate( iface );
184 ITypeInfo *typeinfo;
185 HRESULT hr;
187 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
188 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
190 hr = get_typeinfo(IXSLTemplate_tid, &typeinfo);
191 if(SUCCEEDED(hr))
193 hr = ITypeInfo_Invoke(typeinfo, &This->IXSLTemplate_iface, dispIdMember,
194 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
195 ITypeInfo_Release(typeinfo);
198 return hr;
201 static HRESULT WINAPI xsltemplate_putref_stylesheet( IXSLTemplate *iface,
202 IXMLDOMNode *node)
204 xsltemplate *This = impl_from_IXSLTemplate( iface );
206 TRACE("(%p)->(%p)\n", This, node);
208 if (!node)
210 xsltemplate_set_node(This, NULL);
211 return S_OK;
214 /* FIXME: test for document type */
215 xsltemplate_set_node(This, node);
217 return S_OK;
220 static HRESULT WINAPI xsltemplate_get_stylesheet( IXSLTemplate *iface,
221 IXMLDOMNode **node)
223 xsltemplate *This = impl_from_IXSLTemplate( iface );
225 FIXME("(%p)->(%p): stub\n", This, node);
226 return E_NOTIMPL;
229 static HRESULT WINAPI xsltemplate_createProcessor( IXSLTemplate *iface,
230 IXSLProcessor **processor)
232 xsltemplate *This = impl_from_IXSLTemplate( iface );
234 TRACE("(%p)->(%p)\n", This, processor);
236 if (!processor) return E_INVALIDARG;
238 return XSLProcessor_create(This, processor);
241 static const struct IXSLTemplateVtbl xsltemplate_vtbl =
243 xsltemplate_QueryInterface,
244 xsltemplate_AddRef,
245 xsltemplate_Release,
246 xsltemplate_GetTypeInfoCount,
247 xsltemplate_GetTypeInfo,
248 xsltemplate_GetIDsOfNames,
249 xsltemplate_Invoke,
251 xsltemplate_putref_stylesheet,
252 xsltemplate_get_stylesheet,
253 xsltemplate_createProcessor
256 HRESULT XSLTemplate_create(IUnknown *pUnkOuter, void **ppObj)
258 xsltemplate *This;
260 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
262 if(pUnkOuter) FIXME("support aggregation, outer\n");
264 This = heap_alloc( sizeof (*This) );
265 if(!This)
266 return E_OUTOFMEMORY;
268 This->IXSLTemplate_iface.lpVtbl = &xsltemplate_vtbl;
269 This->ref = 1;
270 This->node = NULL;
272 *ppObj = &This->IXSLTemplate_iface;
274 TRACE("returning iface %p\n", *ppObj);
276 return S_OK;
279 /*** IXSLProcessor ***/
280 static HRESULT WINAPI xslprocessor_QueryInterface(
281 IXSLProcessor *iface,
282 REFIID riid,
283 void** ppvObject )
285 xslprocessor *This = impl_from_IXSLProcessor( iface );
286 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
288 if ( IsEqualGUID( riid, &IID_IXSLProcessor ) ||
289 IsEqualGUID( riid, &IID_IDispatch ) ||
290 IsEqualGUID( riid, &IID_IUnknown ) )
292 *ppvObject = iface;
294 else
296 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
297 *ppvObject = NULL;
298 return E_NOINTERFACE;
301 IUnknown_AddRef((IUnknown*)*ppvObject);
302 return S_OK;
305 static ULONG WINAPI xslprocessor_AddRef( IXSLProcessor *iface )
307 xslprocessor *This = impl_from_IXSLProcessor( iface );
308 return InterlockedIncrement( &This->ref );
311 static ULONG WINAPI xslprocessor_Release( IXSLProcessor *iface )
313 xslprocessor *This = impl_from_IXSLProcessor( iface );
314 ULONG ref;
316 ref = InterlockedDecrement( &This->ref );
317 if ( ref == 0 )
319 if (This->input) IXMLDOMNode_Release(This->input);
320 if (This->output) IStream_Release(This->output);
321 SysFreeString(This->outstr);
322 IXSLTemplate_Release(&This->stylesheet->IXSLTemplate_iface);
323 heap_free( This );
326 return ref;
329 static HRESULT WINAPI xslprocessor_GetTypeInfoCount( IXSLProcessor *iface, UINT* pctinfo )
331 xslprocessor *This = impl_from_IXSLProcessor( iface );
333 TRACE("(%p)->(%p)\n", This, pctinfo);
335 *pctinfo = 1;
336 return S_OK;
339 static HRESULT WINAPI xslprocessor_GetTypeInfo(
340 IXSLProcessor *iface,
341 UINT iTInfo, LCID lcid,
342 ITypeInfo** ppTInfo )
344 xslprocessor *This = impl_from_IXSLProcessor( iface );
346 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
348 return get_typeinfo(IXSLProcessor_tid, ppTInfo);
351 static HRESULT WINAPI xslprocessor_GetIDsOfNames(
352 IXSLProcessor *iface,
353 REFIID riid, LPOLESTR* rgszNames,
354 UINT cNames, LCID lcid, DISPID* rgDispId )
356 xslprocessor *This = impl_from_IXSLProcessor( iface );
357 ITypeInfo *typeinfo;
358 HRESULT hr;
360 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
361 lcid, rgDispId);
363 if(!rgszNames || cNames == 0 || !rgDispId)
364 return E_INVALIDARG;
366 hr = get_typeinfo(IXSLProcessor_tid, &typeinfo);
367 if(SUCCEEDED(hr))
369 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
370 ITypeInfo_Release(typeinfo);
373 return hr;
376 static HRESULT WINAPI xslprocessor_Invoke(
377 IXSLProcessor *iface,
378 DISPID dispIdMember, REFIID riid, LCID lcid,
379 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
380 EXCEPINFO* pExcepInfo, UINT* puArgErr )
382 xslprocessor *This = impl_from_IXSLProcessor( iface );
383 ITypeInfo *typeinfo;
384 HRESULT hr;
386 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
387 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
389 hr = get_typeinfo(IXSLProcessor_tid, &typeinfo);
390 if(SUCCEEDED(hr))
392 hr = ITypeInfo_Invoke(typeinfo, &This->IXSLProcessor_iface, dispIdMember,
393 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
394 ITypeInfo_Release(typeinfo);
397 return hr;
400 static HRESULT WINAPI xslprocessor_put_input( IXSLProcessor *iface, VARIANT input )
402 xslprocessor *This = impl_from_IXSLProcessor( iface );
403 IXMLDOMNode *input_node;
404 HRESULT hr;
406 TRACE("(%p)->(%s)\n", This, debugstr_variant(&input));
408 /* try IXMLDOMNode directly first */
409 if (V_VT(&input) == VT_UNKNOWN)
410 hr = IUnknown_QueryInterface(V_UNKNOWN(&input), &IID_IXMLDOMNode, (void**)&input_node);
411 else if (V_VT(&input) == VT_DISPATCH)
412 hr = IDispatch_QueryInterface(V_DISPATCH(&input), &IID_IXMLDOMNode, (void**)&input_node);
413 else
415 IXMLDOMDocument *doc;
417 hr = DOMDocument_create(MSXML_DEFAULT, NULL, (void**)&doc);
418 if (hr == S_OK)
420 VARIANT_BOOL b;
422 hr = IXMLDOMDocument_load(doc, input, &b);
423 if (hr == S_OK)
424 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&input_node);
425 IXMLDOMDocument_Release(doc);
429 if (hr == S_OK)
431 if (This->input) IXMLDOMNode_Release(This->input);
432 This->input = input_node;
435 return hr;
438 static HRESULT WINAPI xslprocessor_get_input( IXSLProcessor *iface, VARIANT *input )
440 xslprocessor *This = impl_from_IXSLProcessor( iface );
442 FIXME("(%p)->(%p): stub\n", This, input);
443 return E_NOTIMPL;
446 static HRESULT WINAPI xslprocessor_get_ownerTemplate(
447 IXSLProcessor *iface,
448 IXSLTemplate **template)
450 xslprocessor *This = impl_from_IXSLProcessor( iface );
452 FIXME("(%p)->(%p): stub\n", This, template);
453 return E_NOTIMPL;
456 static HRESULT WINAPI xslprocessor_setStartMode(
457 IXSLProcessor *iface,
458 BSTR p,
459 BSTR uri)
461 xslprocessor *This = impl_from_IXSLProcessor( iface );
463 FIXME("(%p)->(%s %s): stub\n", This, wine_dbgstr_w(p), wine_dbgstr_w(uri));
464 return E_NOTIMPL;
467 static HRESULT WINAPI xslprocessor_get_startMode(
468 IXSLProcessor *iface,
469 BSTR *p)
471 xslprocessor *This = impl_from_IXSLProcessor( iface );
473 FIXME("(%p)->(%p): stub\n", This, p);
474 return E_NOTIMPL;
477 static HRESULT WINAPI xslprocessor_get_startModeURI(
478 IXSLProcessor *iface,
479 BSTR *uri)
481 xslprocessor *This = impl_from_IXSLProcessor( iface );
483 FIXME("(%p)->(%p): stub\n", This, uri);
484 return E_NOTIMPL;
487 static HRESULT WINAPI xslprocessor_put_output(
488 IXSLProcessor *iface,
489 VARIANT output)
491 xslprocessor *This = impl_from_IXSLProcessor( iface );
492 IStream *stream;
493 HRESULT hr;
495 FIXME("(%p)->(%s): semi-stub\n", This, debugstr_variant(&output));
497 switch (V_VT(&output))
499 case VT_EMPTY:
500 stream = NULL;
501 hr = S_OK;
502 break;
503 case VT_UNKNOWN:
504 hr = IUnknown_QueryInterface(V_UNKNOWN(&output), &IID_IStream, (void**)&stream);
505 break;
506 default:
507 hr = E_FAIL;
510 if (hr == S_OK)
512 if (This->output) IStream_Release(This->output);
513 This->output = stream;
516 return hr;
519 static HRESULT WINAPI xslprocessor_get_output(
520 IXSLProcessor *iface,
521 VARIANT *output)
523 xslprocessor *This = impl_from_IXSLProcessor( iface );
525 TRACE("(%p)->(%p)\n", This, output);
527 if (!output) return E_INVALIDARG;
529 if (This->output)
531 V_VT(output) = VT_UNKNOWN;
532 V_UNKNOWN(output) = (IUnknown*)This->output;
533 IStream_AddRef(This->output);
535 else if (This->outstr)
537 V_VT(output) = VT_BSTR;
538 V_BSTR(output) = SysAllocString(This->outstr);
540 else
541 V_VT(output) = VT_EMPTY;
543 return S_OK;
546 static HRESULT WINAPI xslprocessor_transform(
547 IXSLProcessor *iface,
548 VARIANT_BOOL *ret)
550 xslprocessor *This = impl_from_IXSLProcessor( iface );
551 HRESULT hr;
553 TRACE("(%p)->(%p)\n", This, ret);
555 if (!ret) return E_INVALIDARG;
557 SysFreeString(This->outstr);
558 hr = IXMLDOMNode_transformNode(This->input, This->stylesheet->node, &This->outstr);
559 if (hr == S_OK)
561 if (This->output)
563 ULONG len = 0;
565 /* output to stream */
566 hr = IStream_Write(This->output, This->outstr, SysStringByteLen(This->outstr), &len);
567 *ret = len == SysStringByteLen(This->outstr) ? VARIANT_TRUE : VARIANT_FALSE;
570 else
571 *ret = VARIANT_FALSE;
573 return hr;
576 static HRESULT WINAPI xslprocessor_reset( IXSLProcessor *iface )
578 xslprocessor *This = impl_from_IXSLProcessor( iface );
580 FIXME("(%p): stub\n", This);
581 return E_NOTIMPL;
584 static HRESULT WINAPI xslprocessor_get_readyState(
585 IXSLProcessor *iface,
586 LONG *state)
588 xslprocessor *This = impl_from_IXSLProcessor( iface );
590 FIXME("(%p)->(%p): stub\n", This, state);
591 return E_NOTIMPL;
594 static HRESULT WINAPI xslprocessor_addParameter(
595 IXSLProcessor *iface,
596 BSTR p,
597 VARIANT var,
598 BSTR uri)
600 xslprocessor *This = impl_from_IXSLProcessor( iface );
602 FIXME("(%p)->(%s %s %s): stub\n", This, wine_dbgstr_w(p), debugstr_variant(&var),
603 wine_dbgstr_w(uri));
604 return E_NOTIMPL;
607 static HRESULT WINAPI xslprocessor_addObject(
608 IXSLProcessor *iface,
609 IDispatch *obj,
610 BSTR uri)
612 xslprocessor *This = impl_from_IXSLProcessor( iface );
614 FIXME("(%p)->(%p %s): stub\n", This, obj, wine_dbgstr_w(uri));
615 return E_NOTIMPL;
618 static HRESULT WINAPI xslprocessor_get_stylesheet(
619 IXSLProcessor *iface,
620 IXMLDOMNode **node)
622 xslprocessor *This = impl_from_IXSLProcessor( iface );
624 FIXME("(%p)->(%p): stub\n", This, node);
625 return E_NOTIMPL;
628 static const struct IXSLProcessorVtbl xslprocessor_vtbl =
630 xslprocessor_QueryInterface,
631 xslprocessor_AddRef,
632 xslprocessor_Release,
633 xslprocessor_GetTypeInfoCount,
634 xslprocessor_GetTypeInfo,
635 xslprocessor_GetIDsOfNames,
636 xslprocessor_Invoke,
638 xslprocessor_put_input,
639 xslprocessor_get_input,
640 xslprocessor_get_ownerTemplate,
641 xslprocessor_setStartMode,
642 xslprocessor_get_startMode,
643 xslprocessor_get_startModeURI,
644 xslprocessor_put_output,
645 xslprocessor_get_output,
646 xslprocessor_transform,
647 xslprocessor_reset,
648 xslprocessor_get_readyState,
649 xslprocessor_addParameter,
650 xslprocessor_addObject,
651 xslprocessor_get_stylesheet
654 HRESULT XSLProcessor_create(xsltemplate *template, IXSLProcessor **ppObj)
656 xslprocessor *This;
658 TRACE("(%p)\n", ppObj);
660 This = heap_alloc( sizeof (*This) );
661 if(!This)
662 return E_OUTOFMEMORY;
664 This->IXSLProcessor_iface.lpVtbl = &xslprocessor_vtbl;
665 This->ref = 1;
666 This->input = NULL;
667 This->output = NULL;
668 This->outstr = NULL;
669 This->stylesheet = template;
670 IXSLTemplate_AddRef(&template->IXSLTemplate_iface);
672 *ppObj = &This->IXSLProcessor_iface;
674 TRACE("returning iface %p\n", *ppObj);
676 return S_OK;
679 #else
681 HRESULT XSLTemplate_create(IUnknown *pUnkOuter, void **ppObj)
683 MESSAGE("This program tried to use a XSLTemplate object, but\n"
684 "libxml2 support was not present at compile time.\n");
685 return E_NOTIMPL;
688 #endif