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
32 #include "msxml_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
40 typedef struct _domcdata
43 const struct IXMLDOMCDATASectionVtbl *lpVtbl;
47 static inline domcdata *impl_from_IXMLDOMCDATASection( IXMLDOMCDATASection *iface )
49 return (domcdata *)((char*)iface - FIELD_OFFSET(domcdata, lpVtbl));
52 static HRESULT WINAPI domcdata_QueryInterface(
53 IXMLDOMCDATASection *iface,
57 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
58 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
60 if ( IsEqualGUID( riid, &IID_IXMLDOMCDATASection ) ||
61 IsEqualGUID( riid, &IID_IXMLDOMCharacterData) ||
62 IsEqualGUID( riid, &IID_IDispatch ) ||
63 IsEqualGUID( riid, &IID_IUnknown ) )
67 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
69 *ppvObject = IXMLDOMNode_from_impl(&This->node);
71 else if ( IsEqualGUID( riid, &IID_IXMLDOMText ) ||
72 IsEqualGUID( riid, &IID_IXMLDOMElement ) )
74 TRACE("Unsupported interface\n");
79 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
83 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
87 static ULONG WINAPI domcdata_AddRef(
88 IXMLDOMCDATASection *iface )
90 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
91 return InterlockedIncrement( &This->ref );
94 static ULONG WINAPI domcdata_Release(
95 IXMLDOMCDATASection *iface )
97 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
100 ref = InterlockedDecrement( &This->ref );
103 destroy_xmlnode(&This->node);
110 static HRESULT WINAPI domcdata_GetTypeInfoCount(
111 IXMLDOMCDATASection *iface,
114 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
116 TRACE("(%p)->(%p)\n", This, pctinfo);
123 static HRESULT WINAPI domcdata_GetTypeInfo(
124 IXMLDOMCDATASection *iface,
125 UINT iTInfo, LCID lcid,
126 ITypeInfo** ppTInfo )
128 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
131 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
133 hr = get_typeinfo(IXMLDOMCDATASection_tid, ppTInfo);
138 static HRESULT WINAPI domcdata_GetIDsOfNames(
139 IXMLDOMCDATASection *iface,
140 REFIID riid, LPOLESTR* rgszNames,
141 UINT cNames, LCID lcid, DISPID* rgDispId )
143 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
147 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
150 if(!rgszNames || cNames == 0 || !rgDispId)
153 hr = get_typeinfo(IXMLDOMCDATASection_tid, &typeinfo);
156 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
157 ITypeInfo_Release(typeinfo);
163 static HRESULT WINAPI domcdata_Invoke(
164 IXMLDOMCDATASection *iface,
165 DISPID dispIdMember, REFIID riid, LCID lcid,
166 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
167 EXCEPINFO* pExcepInfo, UINT* puArgErr )
169 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
173 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
174 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
176 hr = get_typeinfo(IXMLDOMCDATASection_tid, &typeinfo);
179 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
180 pVarResult, pExcepInfo, puArgErr);
181 ITypeInfo_Release(typeinfo);
187 static HRESULT WINAPI domcdata_get_nodeName(
188 IXMLDOMCDATASection *iface,
191 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
192 return IXMLDOMNode_get_nodeName( IXMLDOMNode_from_impl(&This->node), p );
195 static HRESULT WINAPI domcdata_get_nodeValue(
196 IXMLDOMCDATASection *iface,
199 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
200 return IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
203 static HRESULT WINAPI domcdata_put_nodeValue(
204 IXMLDOMCDATASection *iface,
207 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
208 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
211 static HRESULT WINAPI domcdata_get_nodeType(
212 IXMLDOMCDATASection *iface,
213 DOMNodeType* domNodeType )
215 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
216 return IXMLDOMNode_get_nodeType( IXMLDOMNode_from_impl(&This->node), domNodeType );
219 static HRESULT WINAPI domcdata_get_parentNode(
220 IXMLDOMCDATASection *iface,
221 IXMLDOMNode** parent )
223 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
224 return IXMLDOMNode_get_parentNode( IXMLDOMNode_from_impl(&This->node), parent );
227 static HRESULT WINAPI domcdata_get_childNodes(
228 IXMLDOMCDATASection *iface,
229 IXMLDOMNodeList** outList)
231 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
232 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
235 static HRESULT WINAPI domcdata_get_firstChild(
236 IXMLDOMCDATASection *iface,
237 IXMLDOMNode** domNode)
239 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
240 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
243 static HRESULT WINAPI domcdata_get_lastChild(
244 IXMLDOMCDATASection *iface,
245 IXMLDOMNode** domNode)
247 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
248 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
251 static HRESULT WINAPI domcdata_get_previousSibling(
252 IXMLDOMCDATASection *iface,
253 IXMLDOMNode** domNode)
255 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
256 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
259 static HRESULT WINAPI domcdata_get_nextSibling(
260 IXMLDOMCDATASection *iface,
261 IXMLDOMNode** domNode)
263 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
264 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
267 static HRESULT WINAPI domcdata_get_attributes(
268 IXMLDOMCDATASection *iface,
269 IXMLDOMNamedNodeMap** attributeMap)
271 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
272 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
275 static HRESULT WINAPI domcdata_insertBefore(
276 IXMLDOMCDATASection *iface,
277 IXMLDOMNode* newNode, VARIANT var1,
278 IXMLDOMNode** outOldNode)
280 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
281 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
284 static HRESULT WINAPI domcdata_replaceChild(
285 IXMLDOMCDATASection *iface,
286 IXMLDOMNode* newNode,
287 IXMLDOMNode* oldNode,
288 IXMLDOMNode** outOldNode)
290 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
291 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
294 static HRESULT WINAPI domcdata_removeChild(
295 IXMLDOMCDATASection *iface,
296 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
298 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
299 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
302 static HRESULT WINAPI domcdata_appendChild(
303 IXMLDOMCDATASection *iface,
304 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
306 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
307 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
310 static HRESULT WINAPI domcdata_hasChildNodes(
311 IXMLDOMCDATASection *iface,
314 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
315 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
318 static HRESULT WINAPI domcdata_get_ownerDocument(
319 IXMLDOMCDATASection *iface,
320 IXMLDOMDocument** domDocument)
322 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
323 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
326 static HRESULT WINAPI domcdata_cloneNode(
327 IXMLDOMCDATASection *iface,
328 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
330 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
331 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
334 static HRESULT WINAPI domcdata_get_nodeTypeString(
335 IXMLDOMCDATASection *iface,
338 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
339 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
342 static HRESULT WINAPI domcdata_get_text(
343 IXMLDOMCDATASection *iface,
346 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
347 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
350 static HRESULT WINAPI domcdata_put_text(
351 IXMLDOMCDATASection *iface,
354 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
355 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
358 static HRESULT WINAPI domcdata_get_specified(
359 IXMLDOMCDATASection *iface,
362 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
363 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
366 static HRESULT WINAPI domcdata_get_definition(
367 IXMLDOMCDATASection *iface,
368 IXMLDOMNode** domNode)
370 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
371 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
374 static HRESULT WINAPI domcdata_get_nodeTypedValue(
375 IXMLDOMCDATASection *iface,
378 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
379 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
382 static HRESULT WINAPI domcdata_put_nodeTypedValue(
383 IXMLDOMCDATASection *iface,
386 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
387 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
390 static HRESULT WINAPI domcdata_get_dataType(
391 IXMLDOMCDATASection *iface,
394 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
395 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
398 static HRESULT WINAPI domcdata_put_dataType(
399 IXMLDOMCDATASection *iface,
402 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
403 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
406 static HRESULT WINAPI domcdata_get_xml(
407 IXMLDOMCDATASection *iface,
410 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
411 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
414 static HRESULT WINAPI domcdata_transformNode(
415 IXMLDOMCDATASection *iface,
416 IXMLDOMNode* domNode, BSTR* p)
418 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
419 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
422 static HRESULT WINAPI domcdata_selectNodes(
423 IXMLDOMCDATASection *iface,
424 BSTR p, IXMLDOMNodeList** outList)
426 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
427 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
430 static HRESULT WINAPI domcdata_selectSingleNode(
431 IXMLDOMCDATASection *iface,
432 BSTR p, IXMLDOMNode** outNode)
434 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
435 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
438 static HRESULT WINAPI domcdata_get_parsed(
439 IXMLDOMCDATASection *iface,
442 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
443 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
446 static HRESULT WINAPI domcdata_get_namespaceURI(
447 IXMLDOMCDATASection *iface,
450 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
451 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
454 static HRESULT WINAPI domcdata_get_prefix(
455 IXMLDOMCDATASection *iface,
458 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
459 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
462 static HRESULT WINAPI domcdata_get_baseName(
463 IXMLDOMCDATASection *iface,
466 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
467 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
470 static HRESULT WINAPI domcdata_transformNodeToObject(
471 IXMLDOMCDATASection *iface,
472 IXMLDOMNode* domNode, VARIANT var1)
474 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
475 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
478 static HRESULT WINAPI domcdata_get_data(
479 IXMLDOMCDATASection *iface,
482 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
489 hr = IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), &vRet );
498 static HRESULT WINAPI domcdata_put_data(
499 IXMLDOMCDATASection *iface,
502 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
505 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
507 V_VT(&val) = VT_BSTR;
510 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), val );
513 static HRESULT WINAPI domcdata_get_length(
514 IXMLDOMCDATASection *iface,
517 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
521 TRACE("(%p)->(%p)\n", This, len);
526 hr = IXMLDOMCDATASection_get_data(iface, &data);
529 *len = SysStringLen(data);
536 static HRESULT WINAPI domcdata_substringData(
537 IXMLDOMCDATASection *iface,
538 LONG offset, LONG count, BSTR *p)
540 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
544 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
550 if(offset < 0 || count < 0)
556 hr = IXMLDOMCDATASection_get_data(iface, &data);
559 LONG len = SysStringLen(data);
563 if(offset + count > len)
564 *p = SysAllocString(&data[offset]);
566 *p = SysAllocStringLen(&data[offset], count);
577 static HRESULT WINAPI domcdata_appendData(
578 IXMLDOMCDATASection *iface,
581 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
586 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
588 /* Nothing to do if NULL or an Empty string passed in. */
589 if((p_len = SysStringLen(p)) == 0) return S_OK;
591 hr = IXMLDOMCDATASection_get_data(iface, &data);
594 LONG len = SysStringLen(data);
595 BSTR str = SysAllocStringLen(NULL, p_len + len);
597 memcpy(str, data, len*sizeof(WCHAR));
598 memcpy(&str[len], p, p_len*sizeof(WCHAR));
601 hr = IXMLDOMCDATASection_put_data(iface, str);
610 static HRESULT WINAPI domcdata_insertData(
611 IXMLDOMCDATASection *iface,
614 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
619 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
621 /* If have a NULL or empty string, don't do anything. */
622 if((p_len = SysStringLen(p)) == 0)
630 hr = IXMLDOMCDATASection_get_data(iface, &data);
633 LONG len = SysStringLen(data);
642 str = SysAllocStringLen(NULL, len + p_len);
643 /* start part, supplied string and end part */
644 memcpy(str, data, offset*sizeof(WCHAR));
645 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
646 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
649 hr = IXMLDOMCDATASection_put_data(iface, str);
658 static HRESULT WINAPI domcdata_deleteData(
659 IXMLDOMCDATASection *iface,
660 LONG offset, LONG count)
662 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
667 TRACE("(%p)->(%d %d)\n", This, offset, count);
669 hr = IXMLDOMCDATASection_get_length(iface, &len);
670 if(hr != S_OK) return hr;
672 if((offset < 0) || (offset > len) || (count < 0))
675 if(len == 0) return S_OK;
677 /* cutting start or end */
678 if((offset == 0) || ((count + offset) >= len))
681 IXMLDOMCDATASection_substringData(iface, count, len - count, &str);
683 IXMLDOMCDATASection_substringData(iface, 0, offset, &str);
684 hr = IXMLDOMCDATASection_put_data(iface, str);
687 /* cutting from the inside */
691 IXMLDOMCDATASection_substringData(iface, 0, offset, &str);
692 IXMLDOMCDATASection_substringData(iface, offset + count, len - count, &str_end);
694 hr = IXMLDOMCDATASection_put_data(iface, str);
696 hr = IXMLDOMCDATASection_appendData(iface, str_end);
698 SysFreeString(str_end);
706 static HRESULT WINAPI domcdata_replaceData(
707 IXMLDOMCDATASection *iface,
708 LONG offset, LONG count, BSTR p)
710 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
713 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
715 hr = IXMLDOMCDATASection_deleteData(iface, offset, count);
718 hr = IXMLDOMCDATASection_insertData(iface, offset, p);
723 static HRESULT WINAPI domcdata_splitText(
724 IXMLDOMCDATASection *iface,
725 LONG offset, IXMLDOMText **txtNode)
727 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
728 FIXME("(%p)->(%d %p)\n", This, offset, txtNode);
733 static const struct IXMLDOMCDATASectionVtbl domcdata_vtbl =
735 domcdata_QueryInterface,
738 domcdata_GetTypeInfoCount,
739 domcdata_GetTypeInfo,
740 domcdata_GetIDsOfNames,
742 domcdata_get_nodeName,
743 domcdata_get_nodeValue,
744 domcdata_put_nodeValue,
745 domcdata_get_nodeType,
746 domcdata_get_parentNode,
747 domcdata_get_childNodes,
748 domcdata_get_firstChild,
749 domcdata_get_lastChild,
750 domcdata_get_previousSibling,
751 domcdata_get_nextSibling,
752 domcdata_get_attributes,
753 domcdata_insertBefore,
754 domcdata_replaceChild,
755 domcdata_removeChild,
756 domcdata_appendChild,
757 domcdata_hasChildNodes,
758 domcdata_get_ownerDocument,
760 domcdata_get_nodeTypeString,
763 domcdata_get_specified,
764 domcdata_get_definition,
765 domcdata_get_nodeTypedValue,
766 domcdata_put_nodeTypedValue,
767 domcdata_get_dataType,
768 domcdata_put_dataType,
770 domcdata_transformNode,
771 domcdata_selectNodes,
772 domcdata_selectSingleNode,
774 domcdata_get_namespaceURI,
776 domcdata_get_baseName,
777 domcdata_transformNodeToObject,
781 domcdata_substringData,
785 domcdata_replaceData,
789 IUnknown* create_cdata( xmlNodePtr text )
793 This = heap_alloc( sizeof *This );
797 This->lpVtbl = &domcdata_vtbl;
800 init_xmlnode(&This->node, text, (IUnknown*)&This->lpVtbl, NULL);
802 return (IUnknown*) &This->lpVtbl;