msxml3: Init IDispatchEx data for all node types.
[wine/multimedia.git] / dlls / msxml3 / cdata.c
blob348abb860426f1ca5dc104ee50cbd53caa2430a2
1 /*
2 * DOM CDATA node implementation
4 * Copyright 2007 Alistair Leslie-Hughes
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 _domcdata
47 xmlnode node;
48 IXMLDOMCDATASection IXMLDOMCDATASection_iface;
49 LONG ref;
50 } domcdata;
52 static inline domcdata *impl_from_IXMLDOMCDATASection( IXMLDOMCDATASection *iface )
54 return CONTAINING_RECORD(iface, domcdata, IXMLDOMCDATASection_iface);
57 static HRESULT WINAPI domcdata_QueryInterface(
58 IXMLDOMCDATASection *iface,
59 REFIID riid,
60 void** ppvObject )
62 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
63 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
65 if ( IsEqualGUID( riid, &IID_IXMLDOMCDATASection ) ||
66 IsEqualGUID( riid, &IID_IXMLDOMCharacterData) ||
67 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
68 IsEqualGUID( riid, &IID_IDispatch ) ||
69 IsEqualGUID( riid, &IID_IUnknown ) )
71 *ppvObject = iface;
73 else if(node_query_interface(&This->node, riid, ppvObject))
75 return *ppvObject ? S_OK : E_NOINTERFACE;
77 else
79 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
80 *ppvObject = NULL;
81 return E_NOINTERFACE;
84 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
85 return S_OK;
88 static ULONG WINAPI domcdata_AddRef(
89 IXMLDOMCDATASection *iface )
91 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
92 ULONG ref = InterlockedIncrement( &This->ref );
93 TRACE("(%p)->(%d)\n", This, ref);
94 return ref;
97 static ULONG WINAPI domcdata_Release(
98 IXMLDOMCDATASection *iface )
100 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
101 ULONG ref = InterlockedDecrement( &This->ref );
103 TRACE("(%p)->(%d)\n", This, ref);
104 if ( ref == 0 )
106 destroy_xmlnode(&This->node);
107 heap_free( This );
110 return ref;
113 static HRESULT WINAPI domcdata_GetTypeInfoCount(
114 IXMLDOMCDATASection *iface,
115 UINT* pctinfo )
117 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
119 TRACE("(%p)->(%p)\n", This, pctinfo);
121 *pctinfo = 1;
123 return S_OK;
126 static HRESULT WINAPI domcdata_GetTypeInfo(
127 IXMLDOMCDATASection *iface,
128 UINT iTInfo, LCID lcid,
129 ITypeInfo** ppTInfo )
131 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
132 HRESULT hr;
134 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
136 hr = get_typeinfo(IXMLDOMCDATASection_tid, ppTInfo);
138 return hr;
141 static HRESULT WINAPI domcdata_GetIDsOfNames(
142 IXMLDOMCDATASection *iface,
143 REFIID riid, LPOLESTR* rgszNames,
144 UINT cNames, LCID lcid, DISPID* rgDispId )
146 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
147 ITypeInfo *typeinfo;
148 HRESULT hr;
150 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
151 lcid, rgDispId);
153 if(!rgszNames || cNames == 0 || !rgDispId)
154 return E_INVALIDARG;
156 hr = get_typeinfo(IXMLDOMCDATASection_tid, &typeinfo);
157 if(SUCCEEDED(hr))
159 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
160 ITypeInfo_Release(typeinfo);
163 return hr;
166 static HRESULT WINAPI domcdata_Invoke(
167 IXMLDOMCDATASection *iface,
168 DISPID dispIdMember, REFIID riid, LCID lcid,
169 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
170 EXCEPINFO* pExcepInfo, UINT* puArgErr )
172 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
173 ITypeInfo *typeinfo;
174 HRESULT hr;
176 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
177 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
179 hr = get_typeinfo(IXMLDOMCDATASection_tid, &typeinfo);
180 if(SUCCEEDED(hr))
182 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMCDATASection_iface, dispIdMember, wFlags,
183 pDispParams, pVarResult, pExcepInfo, puArgErr);
184 ITypeInfo_Release(typeinfo);
187 return hr;
190 static HRESULT WINAPI domcdata_get_nodeName(
191 IXMLDOMCDATASection *iface,
192 BSTR* p )
194 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
196 static const WCHAR cdata_sectionW[] =
197 {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0};
199 TRACE("(%p)->(%p)\n", This, p);
201 return return_bstr(cdata_sectionW, p);
204 static HRESULT WINAPI domcdata_get_nodeValue(
205 IXMLDOMCDATASection *iface,
206 VARIANT* value)
208 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
210 TRACE("(%p)->(%p)\n", This, value);
212 return node_get_content(&This->node, value);
215 static HRESULT WINAPI domcdata_put_nodeValue(
216 IXMLDOMCDATASection *iface,
217 VARIANT value)
219 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
221 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
223 return node_put_value(&This->node, &value);
226 static HRESULT WINAPI domcdata_get_nodeType(
227 IXMLDOMCDATASection *iface,
228 DOMNodeType* domNodeType )
230 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
232 TRACE("(%p)->(%p)\n", This, domNodeType);
234 *domNodeType = NODE_CDATA_SECTION;
235 return S_OK;
238 static HRESULT WINAPI domcdata_get_parentNode(
239 IXMLDOMCDATASection *iface,
240 IXMLDOMNode** parent )
242 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
244 TRACE("(%p)->(%p)\n", This, parent);
246 return node_get_parent(&This->node, parent);
249 static HRESULT WINAPI domcdata_get_childNodes(
250 IXMLDOMCDATASection *iface,
251 IXMLDOMNodeList** outList)
253 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
255 TRACE("(%p)->(%p)\n", This, outList);
257 return node_get_child_nodes(&This->node, outList);
260 static HRESULT WINAPI domcdata_get_firstChild(
261 IXMLDOMCDATASection *iface,
262 IXMLDOMNode** domNode)
264 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
266 TRACE("(%p)->(%p)\n", This, domNode);
268 return return_null_node(domNode);
271 static HRESULT WINAPI domcdata_get_lastChild(
272 IXMLDOMCDATASection *iface,
273 IXMLDOMNode** domNode)
275 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
277 TRACE("(%p)->(%p)\n", This, domNode);
279 return return_null_node(domNode);
282 static HRESULT WINAPI domcdata_get_previousSibling(
283 IXMLDOMCDATASection *iface,
284 IXMLDOMNode** domNode)
286 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
288 TRACE("(%p)->(%p)\n", This, domNode);
290 return node_get_previous_sibling(&This->node, domNode);
293 static HRESULT WINAPI domcdata_get_nextSibling(
294 IXMLDOMCDATASection *iface,
295 IXMLDOMNode** domNode)
297 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
299 TRACE("(%p)->(%p)\n", This, domNode);
301 return node_get_next_sibling(&This->node, domNode);
304 static HRESULT WINAPI domcdata_get_attributes(
305 IXMLDOMCDATASection *iface,
306 IXMLDOMNamedNodeMap** attributeMap)
308 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
310 TRACE("(%p)->(%p)\n", This, attributeMap);
312 return return_null_ptr((void**)attributeMap);
315 static HRESULT WINAPI domcdata_insertBefore(
316 IXMLDOMCDATASection *iface,
317 IXMLDOMNode* newNode, VARIANT refChild,
318 IXMLDOMNode** outOldNode)
320 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
322 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
324 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
327 static HRESULT WINAPI domcdata_replaceChild(
328 IXMLDOMCDATASection *iface,
329 IXMLDOMNode* newNode,
330 IXMLDOMNode* oldNode,
331 IXMLDOMNode** outOldNode)
333 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
335 FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
337 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
340 static HRESULT WINAPI domcdata_removeChild(
341 IXMLDOMCDATASection *iface,
342 IXMLDOMNode *child, IXMLDOMNode **oldChild)
344 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
345 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
346 return node_remove_child(&This->node, child, oldChild);
349 static HRESULT WINAPI domcdata_appendChild(
350 IXMLDOMCDATASection *iface,
351 IXMLDOMNode *child, IXMLDOMNode **outChild)
353 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
354 TRACE("(%p)->(%p %p)\n", This, child, outChild);
355 return node_append_child(&This->node, child, outChild);
358 static HRESULT WINAPI domcdata_hasChildNodes(
359 IXMLDOMCDATASection *iface,
360 VARIANT_BOOL *ret)
362 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
363 TRACE("(%p)->(%p)\n", This, ret);
364 return node_has_childnodes(&This->node, ret);
367 static HRESULT WINAPI domcdata_get_ownerDocument(
368 IXMLDOMCDATASection *iface,
369 IXMLDOMDocument **doc)
371 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
372 TRACE("(%p)->(%p)\n", This, doc);
373 return node_get_owner_doc(&This->node, doc);
376 static HRESULT WINAPI domcdata_cloneNode(
377 IXMLDOMCDATASection *iface,
378 VARIANT_BOOL deep, IXMLDOMNode** outNode)
380 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
381 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
382 return node_clone( &This->node, deep, outNode );
385 static HRESULT WINAPI domcdata_get_nodeTypeString(
386 IXMLDOMCDATASection *iface,
387 BSTR* p)
389 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
390 static const WCHAR cdatasectionW[] = {'c','d','a','t','a','s','e','c','t','i','o','n',0};
392 TRACE("(%p)->(%p)\n", This, p);
394 return return_bstr(cdatasectionW, p);
397 static HRESULT WINAPI domcdata_get_text(
398 IXMLDOMCDATASection *iface,
399 BSTR* p)
401 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
402 TRACE("(%p)->(%p)\n", This, p);
403 return node_get_text(&This->node, p);
406 static HRESULT WINAPI domcdata_put_text(
407 IXMLDOMCDATASection *iface,
408 BSTR p)
410 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
411 TRACE("(%p)->(%p)\n", This, debugstr_w(p));
412 return node_put_text( &This->node, p );
415 static HRESULT WINAPI domcdata_get_specified(
416 IXMLDOMCDATASection *iface,
417 VARIANT_BOOL* isSpecified)
419 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
420 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
421 *isSpecified = VARIANT_TRUE;
422 return S_OK;
425 static HRESULT WINAPI domcdata_get_definition(
426 IXMLDOMCDATASection *iface,
427 IXMLDOMNode** definitionNode)
429 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
430 FIXME("(%p)->(%p)\n", This, definitionNode);
431 return E_NOTIMPL;
434 static HRESULT WINAPI domcdata_get_nodeTypedValue(
435 IXMLDOMCDATASection *iface,
436 VARIANT* v)
438 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
439 TRACE("(%p)->(%p)\n", This, v);
440 return node_get_content(&This->node, v);
443 static HRESULT WINAPI domcdata_put_nodeTypedValue(
444 IXMLDOMCDATASection *iface,
445 VARIANT typedValue)
447 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
448 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
449 return E_NOTIMPL;
452 static HRESULT WINAPI domcdata_get_dataType(
453 IXMLDOMCDATASection *iface,
454 VARIANT* typename)
456 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
457 TRACE("(%p)->(%p)\n", This, typename);
458 return return_null_var( typename );
461 static HRESULT WINAPI domcdata_put_dataType(
462 IXMLDOMCDATASection *iface,
463 BSTR p)
465 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
467 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
469 if(!p)
470 return E_INVALIDARG;
472 return E_FAIL;
475 static HRESULT WINAPI domcdata_get_xml(
476 IXMLDOMCDATASection *iface,
477 BSTR* p)
479 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
481 TRACE("(%p)->(%p)\n", This, p);
483 return node_get_xml(&This->node, FALSE, FALSE, p);
486 static HRESULT WINAPI domcdata_transformNode(
487 IXMLDOMCDATASection *iface,
488 IXMLDOMNode *node, BSTR *p)
490 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
491 TRACE("(%p)->(%p %p)\n", This, node, p);
492 return node_transform_node(&This->node, node, p);
495 static HRESULT WINAPI domcdata_selectNodes(
496 IXMLDOMCDATASection *iface,
497 BSTR p, IXMLDOMNodeList** outList)
499 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
500 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
501 return node_select_nodes(&This->node, p, outList);
504 static HRESULT WINAPI domcdata_selectSingleNode(
505 IXMLDOMCDATASection *iface,
506 BSTR p, IXMLDOMNode** outNode)
508 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
509 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
510 return node_select_singlenode(&This->node, p, outNode);
513 static HRESULT WINAPI domcdata_get_parsed(
514 IXMLDOMCDATASection *iface,
515 VARIANT_BOOL* isParsed)
517 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
518 FIXME("(%p)->(%p) stub!\n", This, isParsed);
519 *isParsed = VARIANT_TRUE;
520 return S_OK;
523 static HRESULT WINAPI domcdata_get_namespaceURI(
524 IXMLDOMCDATASection *iface,
525 BSTR* p)
527 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
528 TRACE("(%p)->(%p)\n", This, p);
529 return node_get_namespaceURI(&This->node, p);
532 static HRESULT WINAPI domcdata_get_prefix(
533 IXMLDOMCDATASection *iface,
534 BSTR* prefix)
536 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
537 TRACE("(%p)->(%p)\n", This, prefix);
538 return return_null_bstr( prefix );
541 static HRESULT WINAPI domcdata_get_baseName(
542 IXMLDOMCDATASection *iface,
543 BSTR* name)
545 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
546 FIXME("(%p)->(%p): needs test\n", This, name);
547 return return_null_bstr( name );
550 static HRESULT WINAPI domcdata_transformNodeToObject(
551 IXMLDOMCDATASection *iface,
552 IXMLDOMNode* domNode, VARIANT var1)
554 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
555 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
556 return E_NOTIMPL;
559 static HRESULT WINAPI domcdata_get_data(
560 IXMLDOMCDATASection *iface,
561 BSTR *p)
563 HRESULT hr;
564 VARIANT vRet;
566 if(!p)
567 return E_INVALIDARG;
569 hr = IXMLDOMCDATASection_get_nodeValue( iface, &vRet );
570 if(hr == S_OK)
572 *p = V_BSTR(&vRet);
575 return hr;
578 static HRESULT WINAPI domcdata_put_data(
579 IXMLDOMCDATASection *iface,
580 BSTR data)
582 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
583 VARIANT val;
585 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
587 V_VT(&val) = VT_BSTR;
588 V_BSTR(&val) = data;
590 return IXMLDOMCDATASection_put_nodeValue( iface, val );
593 static HRESULT WINAPI domcdata_get_length(
594 IXMLDOMCDATASection *iface,
595 LONG *len)
597 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
598 HRESULT hr;
599 BSTR data;
601 TRACE("(%p)->(%p)\n", This, len);
603 if(!len)
604 return E_INVALIDARG;
606 hr = IXMLDOMCDATASection_get_data(iface, &data);
607 if(hr == S_OK)
609 *len = SysStringLen(data);
610 SysFreeString(data);
613 return S_OK;
616 static HRESULT WINAPI domcdata_substringData(
617 IXMLDOMCDATASection *iface,
618 LONG offset, LONG count, BSTR *p)
620 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
621 HRESULT hr;
622 BSTR data;
624 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
626 if(!p)
627 return E_INVALIDARG;
629 *p = NULL;
630 if(offset < 0 || count < 0)
631 return E_INVALIDARG;
633 if(count == 0)
634 return S_FALSE;
636 hr = IXMLDOMCDATASection_get_data(iface, &data);
637 if(hr == S_OK)
639 LONG len = SysStringLen(data);
641 if(offset < len)
643 if(offset + count > len)
644 *p = SysAllocString(&data[offset]);
645 else
646 *p = SysAllocStringLen(&data[offset], count);
648 else
649 hr = S_FALSE;
651 SysFreeString(data);
654 return hr;
657 static HRESULT WINAPI domcdata_appendData(
658 IXMLDOMCDATASection *iface,
659 BSTR p)
661 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
662 HRESULT hr;
663 BSTR data;
664 LONG p_len;
666 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
668 /* Nothing to do if NULL or an Empty string passed in. */
669 if((p_len = SysStringLen(p)) == 0) return S_OK;
671 hr = IXMLDOMCDATASection_get_data(iface, &data);
672 if(hr == S_OK)
674 LONG len = SysStringLen(data);
675 BSTR str = SysAllocStringLen(NULL, p_len + len);
677 memcpy(str, data, len*sizeof(WCHAR));
678 memcpy(&str[len], p, p_len*sizeof(WCHAR));
679 str[len+p_len] = 0;
681 hr = IXMLDOMCDATASection_put_data(iface, str);
683 SysFreeString(str);
684 SysFreeString(data);
687 return hr;
690 static HRESULT WINAPI domcdata_insertData(
691 IXMLDOMCDATASection *iface,
692 LONG offset, BSTR p)
694 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
695 HRESULT hr;
696 BSTR data;
697 LONG p_len;
699 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
701 /* If have a NULL or empty string, don't do anything. */
702 if((p_len = SysStringLen(p)) == 0)
703 return S_OK;
705 if(offset < 0)
707 return E_INVALIDARG;
710 hr = IXMLDOMCDATASection_get_data(iface, &data);
711 if(hr == S_OK)
713 LONG len = SysStringLen(data);
714 BSTR str;
716 if(len < offset)
718 SysFreeString(data);
719 return E_INVALIDARG;
722 str = SysAllocStringLen(NULL, len + p_len);
723 /* start part, supplied string and end part */
724 memcpy(str, data, offset*sizeof(WCHAR));
725 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
726 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
727 str[len+p_len] = 0;
729 hr = IXMLDOMCDATASection_put_data(iface, str);
731 SysFreeString(str);
732 SysFreeString(data);
735 return hr;
738 static HRESULT WINAPI domcdata_deleteData(
739 IXMLDOMCDATASection *iface,
740 LONG offset, LONG count)
742 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
743 HRESULT hr;
744 LONG len = -1;
745 BSTR str;
747 TRACE("(%p)->(%d %d)\n", This, offset, count);
749 hr = IXMLDOMCDATASection_get_length(iface, &len);
750 if(hr != S_OK) return hr;
752 if((offset < 0) || (offset > len) || (count < 0))
753 return E_INVALIDARG;
755 if(len == 0) return S_OK;
757 /* cutting start or end */
758 if((offset == 0) || ((count + offset) >= len))
760 if(offset == 0)
761 IXMLDOMCDATASection_substringData(iface, count, len - count, &str);
762 else
763 IXMLDOMCDATASection_substringData(iface, 0, offset, &str);
764 hr = IXMLDOMCDATASection_put_data(iface, str);
766 else
767 /* cutting from the inside */
769 BSTR str_end;
771 IXMLDOMCDATASection_substringData(iface, 0, offset, &str);
772 IXMLDOMCDATASection_substringData(iface, offset + count, len - count, &str_end);
774 hr = IXMLDOMCDATASection_put_data(iface, str);
775 if(hr == S_OK)
776 hr = IXMLDOMCDATASection_appendData(iface, str_end);
778 SysFreeString(str_end);
781 SysFreeString(str);
783 return hr;
786 static HRESULT WINAPI domcdata_replaceData(
787 IXMLDOMCDATASection *iface,
788 LONG offset, LONG count, BSTR p)
790 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
791 HRESULT hr;
793 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
795 hr = IXMLDOMCDATASection_deleteData(iface, offset, count);
797 if (hr == S_OK)
798 hr = IXMLDOMCDATASection_insertData(iface, offset, p);
800 return hr;
803 static HRESULT WINAPI domcdata_splitText(
804 IXMLDOMCDATASection *iface,
805 LONG offset, IXMLDOMText **txtNode)
807 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
808 IXMLDOMDocument *doc;
809 LONG length = 0;
810 HRESULT hr;
812 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
814 if (!txtNode || offset < 0) return E_INVALIDARG;
816 *txtNode = NULL;
818 IXMLDOMCDATASection_get_length(iface, &length);
820 if (offset > length) return E_INVALIDARG;
821 if (offset == length) return S_FALSE;
823 hr = IXMLDOMCDATASection_get_ownerDocument(iface, &doc);
824 if (hr == S_OK)
826 BSTR data;
828 hr = IXMLDOMCDATASection_substringData(iface, offset, length - offset, &data);
829 if (hr == S_OK)
831 hr = IXMLDOMDocument_createTextNode(doc, data, txtNode);
832 if (hr == S_OK)
834 IXMLDOMNode *parent;
836 hr = IXMLDOMCDATASection_get_parentNode(iface, &parent);
837 if (hr == S_OK)
839 IXMLDOMCDATASection_deleteData(iface, 0, offset);
840 hr = IXMLDOMNode_appendChild(parent, (IXMLDOMNode*)*txtNode, NULL);
841 IXMLDOMNode_Release(parent);
844 SysFreeString(data);
846 IXMLDOMDocument_Release(doc);
849 return hr;
852 static const struct IXMLDOMCDATASectionVtbl domcdata_vtbl =
854 domcdata_QueryInterface,
855 domcdata_AddRef,
856 domcdata_Release,
857 domcdata_GetTypeInfoCount,
858 domcdata_GetTypeInfo,
859 domcdata_GetIDsOfNames,
860 domcdata_Invoke,
861 domcdata_get_nodeName,
862 domcdata_get_nodeValue,
863 domcdata_put_nodeValue,
864 domcdata_get_nodeType,
865 domcdata_get_parentNode,
866 domcdata_get_childNodes,
867 domcdata_get_firstChild,
868 domcdata_get_lastChild,
869 domcdata_get_previousSibling,
870 domcdata_get_nextSibling,
871 domcdata_get_attributes,
872 domcdata_insertBefore,
873 domcdata_replaceChild,
874 domcdata_removeChild,
875 domcdata_appendChild,
876 domcdata_hasChildNodes,
877 domcdata_get_ownerDocument,
878 domcdata_cloneNode,
879 domcdata_get_nodeTypeString,
880 domcdata_get_text,
881 domcdata_put_text,
882 domcdata_get_specified,
883 domcdata_get_definition,
884 domcdata_get_nodeTypedValue,
885 domcdata_put_nodeTypedValue,
886 domcdata_get_dataType,
887 domcdata_put_dataType,
888 domcdata_get_xml,
889 domcdata_transformNode,
890 domcdata_selectNodes,
891 domcdata_selectSingleNode,
892 domcdata_get_parsed,
893 domcdata_get_namespaceURI,
894 domcdata_get_prefix,
895 domcdata_get_baseName,
896 domcdata_transformNodeToObject,
897 domcdata_get_data,
898 domcdata_put_data,
899 domcdata_get_length,
900 domcdata_substringData,
901 domcdata_appendData,
902 domcdata_insertData,
903 domcdata_deleteData,
904 domcdata_replaceData,
905 domcdata_splitText
908 static const tid_t domcdata_iface_tids[] = {
909 IXMLDOMCDATASection_tid,
913 static dispex_static_data_t domcdata_dispex = {
914 NULL,
915 IXMLDOMCDATASection_tid,
916 NULL,
917 domcdata_iface_tids
920 IUnknown* create_cdata( xmlNodePtr text )
922 domcdata *This;
924 This = heap_alloc( sizeof *This );
925 if ( !This )
926 return NULL;
928 This->IXMLDOMCDATASection_iface.lpVtbl = &domcdata_vtbl;
929 This->ref = 1;
931 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMCDATASection_iface, &domcdata_dispex);
933 return (IUnknown*)&This->IXMLDOMCDATASection_iface;
936 #endif