2 * DOM text node implementation
4 * Copyright 2006 Huw Davies
5 * Copyright 2007-2008 Alistair Leslie-Hughes
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "msxml_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
41 typedef struct _domtext
44 const struct IXMLDOMTextVtbl *lpVtbl;
48 static inline domtext *impl_from_IXMLDOMText( IXMLDOMText *iface )
50 return (domtext *)((char*)iface - FIELD_OFFSET(domtext, lpVtbl));
53 static HRESULT WINAPI domtext_QueryInterface(
58 domtext *This = impl_from_IXMLDOMText( iface );
59 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
61 if ( IsEqualGUID( riid, &IID_IXMLDOMText ) ||
62 IsEqualGUID( riid, &IID_IXMLDOMCharacterData) ||
63 IsEqualGUID( riid, &IID_IDispatch ) ||
64 IsEqualGUID( riid, &IID_IUnknown ) )
68 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
70 *ppvObject = IXMLDOMNode_from_impl(&This->node);
72 else if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
73 IsEqualGUID( riid, &IID_IXMLDOMCDATASection ) )
75 /* IXMLDOMText is known to be correct in not implementing these */
76 TRACE("Unsupported interface\n");
81 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
85 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
89 static ULONG WINAPI domtext_AddRef(
92 domtext *This = impl_from_IXMLDOMText( iface );
93 return InterlockedIncrement( &This->ref );
96 static ULONG WINAPI domtext_Release(
99 domtext *This = impl_from_IXMLDOMText( iface );
102 ref = InterlockedDecrement( &This->ref );
105 destroy_xmlnode(&This->node);
106 HeapFree( GetProcessHeap(), 0, This );
112 static HRESULT WINAPI domtext_GetTypeInfoCount(
116 domtext *This = impl_from_IXMLDOMText( iface );
118 TRACE("(%p)->(%p)\n", This, pctinfo);
125 static HRESULT WINAPI domtext_GetTypeInfo(
127 UINT iTInfo, LCID lcid,
128 ITypeInfo** ppTInfo )
130 domtext *This = impl_from_IXMLDOMText( iface );
133 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
135 hr = get_typeinfo(IXMLDOMText_tid, ppTInfo);
140 static HRESULT WINAPI domtext_GetIDsOfNames(
142 REFIID riid, LPOLESTR* rgszNames,
143 UINT cNames, LCID lcid, DISPID* rgDispId )
145 domtext *This = impl_from_IXMLDOMText( iface );
149 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
152 if(!rgszNames || cNames == 0 || !rgDispId)
155 hr = get_typeinfo(IXMLDOMText_tid, &typeinfo);
158 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
159 ITypeInfo_Release(typeinfo);
165 static HRESULT WINAPI domtext_Invoke(
167 DISPID dispIdMember, REFIID riid, LCID lcid,
168 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
169 EXCEPINFO* pExcepInfo, UINT* puArgErr )
171 domtext *This = impl_from_IXMLDOMText( iface );
175 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
176 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
178 hr = get_typeinfo(IXMLDOMText_tid, &typeinfo);
181 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
182 pVarResult, pExcepInfo, puArgErr);
183 ITypeInfo_Release(typeinfo);
189 static HRESULT WINAPI domtext_get_nodeName(
193 domtext *This = impl_from_IXMLDOMText( iface );
194 return IXMLDOMNode_get_nodeName( IXMLDOMNode_from_impl(&This->node), p );
197 static HRESULT WINAPI domtext_get_nodeValue(
201 domtext *This = impl_from_IXMLDOMText( iface );
202 return IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
205 static HRESULT WINAPI domtext_put_nodeValue(
209 domtext *This = impl_from_IXMLDOMText( iface );
210 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
213 static HRESULT WINAPI domtext_get_nodeType(
215 DOMNodeType* domNodeType )
217 domtext *This = impl_from_IXMLDOMText( iface );
218 return IXMLDOMNode_get_nodeType( IXMLDOMNode_from_impl(&This->node), domNodeType );
221 static HRESULT WINAPI domtext_get_parentNode(
223 IXMLDOMNode** parent )
225 domtext *This = impl_from_IXMLDOMText( iface );
226 return IXMLDOMNode_get_parentNode( IXMLDOMNode_from_impl(&This->node), parent );
229 static HRESULT WINAPI domtext_get_childNodes(
231 IXMLDOMNodeList** outList)
233 domtext *This = impl_from_IXMLDOMText( iface );
234 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
237 static HRESULT WINAPI domtext_get_firstChild(
239 IXMLDOMNode** domNode)
241 domtext *This = impl_from_IXMLDOMText( iface );
242 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
245 static HRESULT WINAPI domtext_get_lastChild(
247 IXMLDOMNode** domNode)
249 domtext *This = impl_from_IXMLDOMText( iface );
250 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
253 static HRESULT WINAPI domtext_get_previousSibling(
255 IXMLDOMNode** domNode)
257 domtext *This = impl_from_IXMLDOMText( iface );
258 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
261 static HRESULT WINAPI domtext_get_nextSibling(
263 IXMLDOMNode** domNode)
265 domtext *This = impl_from_IXMLDOMText( iface );
266 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
269 static HRESULT WINAPI domtext_get_attributes(
271 IXMLDOMNamedNodeMap** attributeMap)
273 domtext *This = impl_from_IXMLDOMText( iface );
274 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
277 static HRESULT WINAPI domtext_insertBefore(
279 IXMLDOMNode* newNode, VARIANT var1,
280 IXMLDOMNode** outOldNode)
282 domtext *This = impl_from_IXMLDOMText( iface );
283 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
286 static HRESULT WINAPI domtext_replaceChild(
288 IXMLDOMNode* newNode,
289 IXMLDOMNode* oldNode,
290 IXMLDOMNode** outOldNode)
292 domtext *This = impl_from_IXMLDOMText( iface );
293 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
296 static HRESULT WINAPI domtext_removeChild(
298 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
300 domtext *This = impl_from_IXMLDOMText( iface );
301 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
304 static HRESULT WINAPI domtext_appendChild(
306 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
308 domtext *This = impl_from_IXMLDOMText( iface );
309 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
312 static HRESULT WINAPI domtext_hasChildNodes(
316 domtext *This = impl_from_IXMLDOMText( iface );
317 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
320 static HRESULT WINAPI domtext_get_ownerDocument(
322 IXMLDOMDocument** domDocument)
324 domtext *This = impl_from_IXMLDOMText( iface );
325 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
328 static HRESULT WINAPI domtext_cloneNode(
330 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
332 domtext *This = impl_from_IXMLDOMText( iface );
333 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
336 static HRESULT WINAPI domtext_get_nodeTypeString(
340 domtext *This = impl_from_IXMLDOMText( iface );
341 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
344 static HRESULT WINAPI domtext_get_text(
348 domtext *This = impl_from_IXMLDOMText( iface );
349 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
352 static HRESULT WINAPI domtext_put_text(
356 domtext *This = impl_from_IXMLDOMText( iface );
357 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
360 static HRESULT WINAPI domtext_get_specified(
364 domtext *This = impl_from_IXMLDOMText( iface );
365 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
368 static HRESULT WINAPI domtext_get_definition(
370 IXMLDOMNode** domNode)
372 domtext *This = impl_from_IXMLDOMText( iface );
373 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
376 static HRESULT WINAPI domtext_get_nodeTypedValue(
380 domtext *This = impl_from_IXMLDOMText( iface );
381 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
384 static HRESULT WINAPI domtext_put_nodeTypedValue(
388 domtext *This = impl_from_IXMLDOMText( iface );
389 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
392 static HRESULT WINAPI domtext_get_dataType(
396 domtext *This = impl_from_IXMLDOMText( iface );
397 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
400 static HRESULT WINAPI domtext_put_dataType(
404 domtext *This = impl_from_IXMLDOMText( iface );
405 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
408 static HRESULT WINAPI domtext_get_xml(
412 domtext *This = impl_from_IXMLDOMText( iface );
413 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
416 static HRESULT WINAPI domtext_transformNode(
418 IXMLDOMNode* domNode, BSTR* p)
420 domtext *This = impl_from_IXMLDOMText( iface );
421 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
424 static HRESULT WINAPI domtext_selectNodes(
426 BSTR p, IXMLDOMNodeList** outList)
428 domtext *This = impl_from_IXMLDOMText( iface );
429 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
432 static HRESULT WINAPI domtext_selectSingleNode(
434 BSTR p, IXMLDOMNode** outNode)
436 domtext *This = impl_from_IXMLDOMText( iface );
437 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
440 static HRESULT WINAPI domtext_get_parsed(
444 domtext *This = impl_from_IXMLDOMText( iface );
445 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
448 static HRESULT WINAPI domtext_get_namespaceURI(
452 domtext *This = impl_from_IXMLDOMText( iface );
453 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
456 static HRESULT WINAPI domtext_get_prefix(
460 domtext *This = impl_from_IXMLDOMText( iface );
461 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
464 static HRESULT WINAPI domtext_get_baseName(
468 domtext *This = impl_from_IXMLDOMText( iface );
469 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
472 static HRESULT WINAPI domtext_transformNodeToObject(
474 IXMLDOMNode* domNode, VARIANT var1)
476 domtext *This = impl_from_IXMLDOMText( iface );
477 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
480 static HRESULT WINAPI domtext_get_data(
484 domtext *This = impl_from_IXMLDOMText( iface );
491 hr = IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), &vRet );
500 static HRESULT WINAPI domtext_put_data(
504 domtext *This = impl_from_IXMLDOMText( iface );
508 TRACE("%p %s\n", This, debugstr_w(data) );
510 V_VT(&val) = VT_BSTR;
513 hr = IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), val );
518 static HRESULT WINAPI domtext_get_length(
522 domtext *This = impl_from_IXMLDOMText( iface );
526 TRACE("%p\n", iface);
531 pContent = xmlNodeGetContent(This->node.node);
534 nLength = xmlStrlen(pContent);
543 static HRESULT WINAPI domtext_substringData(
545 LONG offset, LONG count, BSTR *p)
547 domtext *This = impl_from_IXMLDOMText( iface );
550 HRESULT hr = S_FALSE;
552 TRACE("%p\n", iface);
558 if(offset < 0 || count < 0)
564 pContent = xmlNodeGetContent(This->node.node);
567 nLength = xmlStrlen(pContent);
569 if( offset < nLength)
571 BSTR sContent = bstr_from_xmlChar(pContent);
572 if(offset + count > nLength)
573 *p = SysAllocString(&sContent[offset]);
575 *p = SysAllocStringLen(&sContent[offset], count);
577 SysFreeString(sContent);
587 static HRESULT WINAPI domtext_appendData(
591 domtext *This = impl_from_IXMLDOMText( iface );
593 HRESULT hr = S_FALSE;
595 TRACE("%p\n", iface);
597 /* Nothing to do if NULL or an Empty string passed in. */
598 if(p == NULL || SysStringLen(p) == 0)
601 pContent = xmlChar_from_wchar( p );
604 if(xmlTextConcat(This->node.node, pContent, SysStringLen(p)) == 0)
608 HeapFree( GetProcessHeap(), 0, pContent );
616 static HRESULT WINAPI domtext_insertData(
620 domtext *This = impl_from_IXMLDOMText( iface );
621 xmlChar *pXmlContent;
623 HRESULT hr = S_FALSE;
624 LONG nLength = 0, nLengthP = 0;
629 /* If have a NULL or empty string, don't do anything. */
630 if(SysStringLen(p) == 0)
638 pXmlContent = xmlNodeGetContent(This->node.node);
641 BSTR sContent = bstr_from_xmlChar( pXmlContent );
642 nLength = SysStringLen(sContent);
643 nLengthP = SysStringLen(p);
647 SysFreeString(sContent);
648 xmlFree(pXmlContent);
653 sNewString = SysAllocStringLen(NULL, nLength + nLengthP + 1);
657 memcpy(sNewString, sContent, offset * sizeof(WCHAR));
659 memcpy(&sNewString[offset], p, nLengthP * sizeof(WCHAR));
661 if(offset+nLengthP < nLength)
662 memcpy(&sNewString[offset+nLengthP], &sContent[offset], (nLength-offset) * sizeof(WCHAR));
664 sNewString[nLengthP + nLength] = 0;
666 str = xmlChar_from_wchar(sNewString);
669 xmlNodeSetContent(This->node.node, str);
672 HeapFree(GetProcessHeap(), 0, str);
674 SysFreeString(sNewString);
677 SysFreeString(sContent);
679 xmlFree(pXmlContent);
685 static HRESULT WINAPI domtext_deleteData(
687 LONG offset, LONG count)
693 static HRESULT WINAPI domtext_replaceData(
695 LONG offset, LONG count, BSTR p)
701 static HRESULT WINAPI domtext_splitText(
703 LONG offset, IXMLDOMText **txtNode)
710 static const struct IXMLDOMTextVtbl domtext_vtbl =
712 domtext_QueryInterface,
715 domtext_GetTypeInfoCount,
717 domtext_GetIDsOfNames,
719 domtext_get_nodeName,
720 domtext_get_nodeValue,
721 domtext_put_nodeValue,
722 domtext_get_nodeType,
723 domtext_get_parentNode,
724 domtext_get_childNodes,
725 domtext_get_firstChild,
726 domtext_get_lastChild,
727 domtext_get_previousSibling,
728 domtext_get_nextSibling,
729 domtext_get_attributes,
730 domtext_insertBefore,
731 domtext_replaceChild,
734 domtext_hasChildNodes,
735 domtext_get_ownerDocument,
737 domtext_get_nodeTypeString,
740 domtext_get_specified,
741 domtext_get_definition,
742 domtext_get_nodeTypedValue,
743 domtext_put_nodeTypedValue,
744 domtext_get_dataType,
745 domtext_put_dataType,
747 domtext_transformNode,
749 domtext_selectSingleNode,
751 domtext_get_namespaceURI,
753 domtext_get_baseName,
754 domtext_transformNodeToObject,
758 domtext_substringData,
766 IUnknown* create_text( xmlNodePtr text )
770 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
774 This->lpVtbl = &domtext_vtbl;
777 init_xmlnode(&This->node, text, (IUnknown*)&This->lpVtbl, NULL);
779 return (IUnknown*) &This->lpVtbl;