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
43 const struct IXMLDOMTextVtbl
*lpVtbl
;
49 static inline domtext
*impl_from_IXMLDOMText( IXMLDOMText
*iface
)
51 return (domtext
*)((char*)iface
- FIELD_OFFSET(domtext
, lpVtbl
));
54 static HRESULT WINAPI
domtext_QueryInterface(
59 domtext
*This
= impl_from_IXMLDOMText( iface
);
60 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
62 if ( IsEqualGUID( riid
, &IID_IXMLDOMText
) ||
63 IsEqualGUID( riid
, &IID_IXMLDOMCharacterData
) ||
64 IsEqualGUID( riid
, &IID_IDispatch
) ||
65 IsEqualGUID( riid
, &IID_IUnknown
) )
69 else if ( IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
71 return IUnknown_QueryInterface(This
->node_unk
, riid
, ppvObject
);
73 else if ( IsEqualGUID( riid
, &IID_IXMLDOMElement
) ||
74 IsEqualGUID( riid
, &IID_IXMLDOMCDATASection
) )
76 /* IXMLDOMText is known to be correct in not implementing these */
77 TRACE("Unsupported interface\n");
82 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
86 IXMLDOMText_AddRef( iface
);
91 static ULONG WINAPI
domtext_AddRef(
94 domtext
*This
= impl_from_IXMLDOMText( iface
);
95 return InterlockedIncrement( &This
->ref
);
98 static ULONG WINAPI
domtext_Release(
101 domtext
*This
= impl_from_IXMLDOMText( iface
);
104 ref
= InterlockedDecrement( &This
->ref
);
107 IUnknown_Release( This
->node_unk
);
108 HeapFree( GetProcessHeap(), 0, This
);
114 static HRESULT WINAPI
domtext_GetTypeInfoCount(
118 domtext
*This
= impl_from_IXMLDOMText( iface
);
120 TRACE("(%p)->(%p)\n", This
, pctinfo
);
127 static HRESULT WINAPI
domtext_GetTypeInfo(
129 UINT iTInfo
, LCID lcid
,
130 ITypeInfo
** ppTInfo
)
132 domtext
*This
= impl_from_IXMLDOMText( iface
);
135 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
137 hr
= get_typeinfo(IXMLDOMText_tid
, ppTInfo
);
142 static HRESULT WINAPI
domtext_GetIDsOfNames(
144 REFIID riid
, LPOLESTR
* rgszNames
,
145 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
147 domtext
*This
= impl_from_IXMLDOMText( iface
);
151 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
154 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
157 hr
= get_typeinfo(IXMLDOMText_tid
, &typeinfo
);
160 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
161 ITypeInfo_Release(typeinfo
);
167 static HRESULT WINAPI
domtext_Invoke(
169 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
170 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
171 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
173 domtext
*This
= impl_from_IXMLDOMText( iface
);
177 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
178 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
180 hr
= get_typeinfo(IXMLDOMText_tid
, &typeinfo
);
183 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
184 pVarResult
, pExcepInfo
, puArgErr
);
185 ITypeInfo_Release(typeinfo
);
191 static HRESULT WINAPI
domtext_get_nodeName(
195 domtext
*This
= impl_from_IXMLDOMText( iface
);
196 return IXMLDOMNode_get_nodeName( This
->node
, p
);
199 static HRESULT WINAPI
domtext_get_nodeValue(
203 domtext
*This
= impl_from_IXMLDOMText( iface
);
204 return IXMLDOMNode_get_nodeValue( This
->node
, var1
);
207 static HRESULT WINAPI
domtext_put_nodeValue(
211 domtext
*This
= impl_from_IXMLDOMText( iface
);
212 return IXMLDOMNode_put_nodeValue( This
->node
, var1
);
215 static HRESULT WINAPI
domtext_get_nodeType(
217 DOMNodeType
* domNodeType
)
219 domtext
*This
= impl_from_IXMLDOMText( iface
);
220 return IXMLDOMNode_get_nodeType( This
->node
, domNodeType
);
223 static HRESULT WINAPI
domtext_get_parentNode(
225 IXMLDOMNode
** parent
)
227 domtext
*This
= impl_from_IXMLDOMText( iface
);
228 return IXMLDOMNode_get_parentNode( This
->node
, parent
);
231 static HRESULT WINAPI
domtext_get_childNodes(
233 IXMLDOMNodeList
** outList
)
235 domtext
*This
= impl_from_IXMLDOMText( iface
);
236 return IXMLDOMNode_get_childNodes( This
->node
, outList
);
239 static HRESULT WINAPI
domtext_get_firstChild(
241 IXMLDOMNode
** domNode
)
243 domtext
*This
= impl_from_IXMLDOMText( iface
);
244 return IXMLDOMNode_get_firstChild( This
->node
, domNode
);
247 static HRESULT WINAPI
domtext_get_lastChild(
249 IXMLDOMNode
** domNode
)
251 domtext
*This
= impl_from_IXMLDOMText( iface
);
252 return IXMLDOMNode_get_lastChild( This
->node
, domNode
);
255 static HRESULT WINAPI
domtext_get_previousSibling(
257 IXMLDOMNode
** domNode
)
259 domtext
*This
= impl_from_IXMLDOMText( iface
);
260 return IXMLDOMNode_get_previousSibling( This
->node
, domNode
);
263 static HRESULT WINAPI
domtext_get_nextSibling(
265 IXMLDOMNode
** domNode
)
267 domtext
*This
= impl_from_IXMLDOMText( iface
);
268 return IXMLDOMNode_get_nextSibling( This
->node
, domNode
);
271 static HRESULT WINAPI
domtext_get_attributes(
273 IXMLDOMNamedNodeMap
** attributeMap
)
275 domtext
*This
= impl_from_IXMLDOMText( iface
);
276 return IXMLDOMNode_get_attributes( This
->node
, attributeMap
);
279 static HRESULT WINAPI
domtext_insertBefore(
281 IXMLDOMNode
* newNode
, VARIANT var1
,
282 IXMLDOMNode
** outOldNode
)
284 domtext
*This
= impl_from_IXMLDOMText( iface
);
285 return IXMLDOMNode_insertBefore( This
->node
, newNode
, var1
, outOldNode
);
288 static HRESULT WINAPI
domtext_replaceChild(
290 IXMLDOMNode
* newNode
,
291 IXMLDOMNode
* oldNode
,
292 IXMLDOMNode
** outOldNode
)
294 domtext
*This
= impl_from_IXMLDOMText( iface
);
295 return IXMLDOMNode_replaceChild( This
->node
, newNode
, oldNode
, outOldNode
);
298 static HRESULT WINAPI
domtext_removeChild(
300 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
302 domtext
*This
= impl_from_IXMLDOMText( iface
);
303 return IXMLDOMNode_removeChild( This
->node
, domNode
, oldNode
);
306 static HRESULT WINAPI
domtext_appendChild(
308 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
310 domtext
*This
= impl_from_IXMLDOMText( iface
);
311 return IXMLDOMNode_appendChild( This
->node
, newNode
, outNewNode
);
314 static HRESULT WINAPI
domtext_hasChildNodes(
318 domtext
*This
= impl_from_IXMLDOMText( iface
);
319 return IXMLDOMNode_hasChildNodes( This
->node
, pbool
);
322 static HRESULT WINAPI
domtext_get_ownerDocument(
324 IXMLDOMDocument
** domDocument
)
326 domtext
*This
= impl_from_IXMLDOMText( iface
);
327 return IXMLDOMNode_get_ownerDocument( This
->node
, domDocument
);
330 static HRESULT WINAPI
domtext_cloneNode(
332 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
334 domtext
*This
= impl_from_IXMLDOMText( iface
);
335 return IXMLDOMNode_cloneNode( This
->node
, pbool
, outNode
);
338 static HRESULT WINAPI
domtext_get_nodeTypeString(
342 domtext
*This
= impl_from_IXMLDOMText( iface
);
343 return IXMLDOMNode_get_nodeTypeString( This
->node
, p
);
346 static HRESULT WINAPI
domtext_get_text(
350 domtext
*This
= impl_from_IXMLDOMText( iface
);
351 return IXMLDOMNode_get_text( This
->node
, p
);
354 static HRESULT WINAPI
domtext_put_text(
358 domtext
*This
= impl_from_IXMLDOMText( iface
);
359 return IXMLDOMNode_put_text( This
->node
, p
);
362 static HRESULT WINAPI
domtext_get_specified(
366 domtext
*This
= impl_from_IXMLDOMText( iface
);
367 return IXMLDOMNode_get_specified( This
->node
, pbool
);
370 static HRESULT WINAPI
domtext_get_definition(
372 IXMLDOMNode
** domNode
)
374 domtext
*This
= impl_from_IXMLDOMText( iface
);
375 return IXMLDOMNode_get_definition( This
->node
, domNode
);
378 static HRESULT WINAPI
domtext_get_nodeTypedValue(
382 domtext
*This
= impl_from_IXMLDOMText( iface
);
383 return IXMLDOMNode_get_nodeTypedValue( This
->node
, var1
);
386 static HRESULT WINAPI
domtext_put_nodeTypedValue(
390 domtext
*This
= impl_from_IXMLDOMText( iface
);
391 return IXMLDOMNode_put_nodeTypedValue( This
->node
, var1
);
394 static HRESULT WINAPI
domtext_get_dataType(
398 domtext
*This
= impl_from_IXMLDOMText( iface
);
399 return IXMLDOMNode_get_dataType( This
->node
, var1
);
402 static HRESULT WINAPI
domtext_put_dataType(
406 domtext
*This
= impl_from_IXMLDOMText( iface
);
407 return IXMLDOMNode_put_dataType( This
->node
, p
);
410 static HRESULT WINAPI
domtext_get_xml(
414 domtext
*This
= impl_from_IXMLDOMText( iface
);
415 return IXMLDOMNode_get_xml( This
->node
, p
);
418 static HRESULT WINAPI
domtext_transformNode(
420 IXMLDOMNode
* domNode
, BSTR
* p
)
422 domtext
*This
= impl_from_IXMLDOMText( iface
);
423 return IXMLDOMNode_transformNode( This
->node
, domNode
, p
);
426 static HRESULT WINAPI
domtext_selectNodes(
428 BSTR p
, IXMLDOMNodeList
** outList
)
430 domtext
*This
= impl_from_IXMLDOMText( iface
);
431 return IXMLDOMNode_selectNodes( This
->node
, p
, outList
);
434 static HRESULT WINAPI
domtext_selectSingleNode(
436 BSTR p
, IXMLDOMNode
** outNode
)
438 domtext
*This
= impl_from_IXMLDOMText( iface
);
439 return IXMLDOMNode_selectSingleNode( This
->node
, p
, outNode
);
442 static HRESULT WINAPI
domtext_get_parsed(
446 domtext
*This
= impl_from_IXMLDOMText( iface
);
447 return IXMLDOMNode_get_parsed( This
->node
, pbool
);
450 static HRESULT WINAPI
domtext_get_namespaceURI(
454 domtext
*This
= impl_from_IXMLDOMText( iface
);
455 return IXMLDOMNode_get_namespaceURI( This
->node
, p
);
458 static HRESULT WINAPI
domtext_get_prefix(
462 domtext
*This
= impl_from_IXMLDOMText( iface
);
463 return IXMLDOMNode_get_prefix( This
->node
, p
);
466 static HRESULT WINAPI
domtext_get_baseName(
470 domtext
*This
= impl_from_IXMLDOMText( iface
);
471 return IXMLDOMNode_get_baseName( This
->node
, p
);
474 static HRESULT WINAPI
domtext_transformNodeToObject(
476 IXMLDOMNode
* domNode
, VARIANT var1
)
478 domtext
*This
= impl_from_IXMLDOMText( iface
);
479 return IXMLDOMNode_transformNodeToObject( This
->node
, domNode
, var1
);
482 static HRESULT WINAPI
domtext_get_data(
486 domtext
*This
= impl_from_IXMLDOMText( iface
);
493 hr
= IXMLDOMNode_get_nodeValue( This
->node
, &vRet
);
502 static HRESULT WINAPI
domtext_put_data(
506 domtext
*This
= impl_from_IXMLDOMText( iface
);
510 TRACE("%p %s\n", This
, debugstr_w(data
) );
512 V_VT(&val
) = VT_BSTR
;
515 hr
= IXMLDOMNode_put_nodeValue( This
->node
, val
);
520 static HRESULT WINAPI
domtext_get_length(
524 domtext
*This
= impl_from_IXMLDOMText( iface
);
525 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( This
->node
);
529 TRACE("%p\n", iface
);
534 pContent
= xmlNodeGetContent(pDOMNode
->node
);
537 nLength
= xmlStrlen(pContent
);
546 static HRESULT WINAPI
domtext_substringData(
548 long offset
, long count
, BSTR
*p
)
550 domtext
*This
= impl_from_IXMLDOMText( iface
);
551 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( This
->node
);
554 HRESULT hr
= S_FALSE
;
556 TRACE("%p\n", iface
);
562 if(offset
< 0 || count
< 0)
568 pContent
= xmlNodeGetContent(pDOMNode
->node
);
571 nLength
= xmlStrlen(pContent
);
573 if( offset
< nLength
)
575 BSTR sContent
= bstr_from_xmlChar(pContent
);
576 if(offset
+ count
> nLength
)
577 *p
= SysAllocString(&sContent
[offset
]);
579 *p
= SysAllocStringLen(&sContent
[offset
], count
);
581 SysFreeString(sContent
);
591 static HRESULT WINAPI
domtext_appendData(
595 domtext
*This
= impl_from_IXMLDOMText( iface
);
596 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( This
->node
);
598 HRESULT hr
= S_FALSE
;
600 TRACE("%p\n", iface
);
602 /* Nothing to do if NULL or an Empty string passed in. */
603 if(p
== NULL
|| SysStringLen(p
) == 0)
606 pContent
= xmlChar_from_wchar( p
);
609 if(xmlTextConcat(pDOMNode
->node
, pContent
, SysStringLen(p
) ) == 0)
613 HeapFree( GetProcessHeap(), 0, pContent
);
621 static HRESULT WINAPI
domtext_insertData(
625 domtext
*This
= impl_from_IXMLDOMText( iface
);
626 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( This
->node
);
627 xmlChar
*pXmlContent
;
629 HRESULT hr
= S_FALSE
;
630 long nLength
= 0, nLengthP
= 0;
635 /* If have a NULL or empty string, don't do anything. */
636 if(SysStringLen(p
) == 0)
644 pXmlContent
= xmlNodeGetContent(pDOMNode
->node
);
647 BSTR sContent
= bstr_from_xmlChar( pXmlContent
);
648 nLength
= SysStringLen(sContent
);
649 nLengthP
= SysStringLen(p
);
653 SysFreeString(sContent
);
654 xmlFree(pXmlContent
);
659 sNewString
= SysAllocStringLen(NULL
, nLength
+ nLengthP
+ 1);
663 memcpy(sNewString
, sContent
, offset
* sizeof(WCHAR
));
665 memcpy(&sNewString
[offset
], p
, nLengthP
* sizeof(WCHAR
));
667 if(offset
+nLengthP
< nLength
)
668 memcpy(&sNewString
[offset
+nLengthP
], &sContent
[offset
], (nLength
-offset
) * sizeof(WCHAR
));
670 sNewString
[nLengthP
+ nLength
] = 0;
672 str
= xmlChar_from_wchar(sNewString
);
675 xmlNodeSetContent(pDOMNode
->node
, str
);
678 HeapFree(GetProcessHeap(), 0, str
);
680 SysFreeString(sNewString
);
683 SysFreeString(sContent
);
685 xmlFree(pXmlContent
);
691 static HRESULT WINAPI
domtext_deleteData(
693 long offset
, long count
)
699 static HRESULT WINAPI
domtext_replaceData(
701 long offset
, long count
, BSTR p
)
707 static HRESULT WINAPI
domtext_splitText(
709 long offset
, IXMLDOMText
**txtNode
)
716 static const struct IXMLDOMTextVtbl domtext_vtbl
=
718 domtext_QueryInterface
,
721 domtext_GetTypeInfoCount
,
723 domtext_GetIDsOfNames
,
725 domtext_get_nodeName
,
726 domtext_get_nodeValue
,
727 domtext_put_nodeValue
,
728 domtext_get_nodeType
,
729 domtext_get_parentNode
,
730 domtext_get_childNodes
,
731 domtext_get_firstChild
,
732 domtext_get_lastChild
,
733 domtext_get_previousSibling
,
734 domtext_get_nextSibling
,
735 domtext_get_attributes
,
736 domtext_insertBefore
,
737 domtext_replaceChild
,
740 domtext_hasChildNodes
,
741 domtext_get_ownerDocument
,
743 domtext_get_nodeTypeString
,
746 domtext_get_specified
,
747 domtext_get_definition
,
748 domtext_get_nodeTypedValue
,
749 domtext_put_nodeTypedValue
,
750 domtext_get_dataType
,
751 domtext_put_dataType
,
753 domtext_transformNode
,
755 domtext_selectSingleNode
,
757 domtext_get_namespaceURI
,
759 domtext_get_baseName
,
760 domtext_transformNodeToObject
,
764 domtext_substringData
,
772 IUnknown
* create_text( xmlNodePtr text
)
777 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
781 This
->lpVtbl
= &domtext_vtbl
;
784 This
->node_unk
= create_basic_node( text
, (IUnknown
*)&This
->lpVtbl
);
787 HeapFree(GetProcessHeap(), 0, This
);
791 hr
= IUnknown_QueryInterface(This
->node_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&This
->node
);
794 IUnknown_Release(This
->node_unk
);
795 HeapFree( GetProcessHeap(), 0, This
);
798 /* The ref on This->node is actually looped back into this object, so release it */
799 IXMLDOMNode_Release(This
->node
);
801 return (IUnknown
*) &This
->lpVtbl
;