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
;
45 IUnknown
*element_unk
;
46 IXMLDOMElement
*element
;
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
) ||
70 IsEqualGUID( riid
, &IID_IXMLDOMElement
) )
72 return IUnknown_QueryInterface(This
->element_unk
, riid
, ppvObject
);
76 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
80 IXMLDOMText_AddRef( iface
);
85 static ULONG WINAPI
domtext_AddRef(
88 domtext
*This
= impl_from_IXMLDOMText( iface
);
89 return InterlockedIncrement( &This
->ref
);
92 static ULONG WINAPI
domtext_Release(
95 domtext
*This
= impl_from_IXMLDOMText( iface
);
98 ref
= InterlockedDecrement( &This
->ref
);
101 IUnknown_Release( This
->element_unk
);
102 HeapFree( GetProcessHeap(), 0, This
);
108 static HRESULT WINAPI
domtext_GetTypeInfoCount(
112 domtext
*This
= impl_from_IXMLDOMText( iface
);
114 TRACE("(%p)->(%p)\n", This
, pctinfo
);
121 static HRESULT WINAPI
domtext_GetTypeInfo(
123 UINT iTInfo
, LCID lcid
,
124 ITypeInfo
** ppTInfo
)
126 domtext
*This
= impl_from_IXMLDOMText( iface
);
129 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
131 hr
= get_typeinfo(IXMLDOMText_tid
, ppTInfo
);
136 static HRESULT WINAPI
domtext_GetIDsOfNames(
138 REFIID riid
, LPOLESTR
* rgszNames
,
139 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
141 domtext
*This
= impl_from_IXMLDOMText( iface
);
145 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
148 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
151 hr
= get_typeinfo(IXMLDOMText_tid
, &typeinfo
);
154 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
155 ITypeInfo_Release(typeinfo
);
161 static HRESULT WINAPI
domtext_Invoke(
163 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
164 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
165 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
167 domtext
*This
= impl_from_IXMLDOMText( iface
);
171 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
172 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
174 hr
= get_typeinfo(IXMLDOMText_tid
, &typeinfo
);
177 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
178 pVarResult
, pExcepInfo
, puArgErr
);
179 ITypeInfo_Release(typeinfo
);
185 static HRESULT WINAPI
domtext_get_nodeName(
189 domtext
*This
= impl_from_IXMLDOMText( iface
);
190 return IXMLDOMNode_get_nodeName( This
->element
, p
);
193 static HRESULT WINAPI
domtext_get_nodeValue(
197 domtext
*This
= impl_from_IXMLDOMText( iface
);
198 return IXMLDOMNode_get_nodeValue( This
->element
, var1
);
201 static HRESULT WINAPI
domtext_put_nodeValue(
205 domtext
*This
= impl_from_IXMLDOMText( iface
);
206 return IXMLDOMNode_put_nodeValue( This
->element
, var1
);
209 static HRESULT WINAPI
domtext_get_nodeType(
211 DOMNodeType
* domNodeType
)
213 domtext
*This
= impl_from_IXMLDOMText( iface
);
214 return IXMLDOMNode_get_nodeType( This
->element
, domNodeType
);
217 static HRESULT WINAPI
domtext_get_parentNode(
219 IXMLDOMNode
** parent
)
221 domtext
*This
= impl_from_IXMLDOMText( iface
);
222 return IXMLDOMNode_get_parentNode( This
->element
, parent
);
225 static HRESULT WINAPI
domtext_get_childNodes(
227 IXMLDOMNodeList
** outList
)
229 domtext
*This
= impl_from_IXMLDOMText( iface
);
230 return IXMLDOMNode_get_childNodes( This
->element
, outList
);
233 static HRESULT WINAPI
domtext_get_firstChild(
235 IXMLDOMNode
** domNode
)
237 domtext
*This
= impl_from_IXMLDOMText( iface
);
238 return IXMLDOMNode_get_firstChild( This
->element
, domNode
);
241 static HRESULT WINAPI
domtext_get_lastChild(
243 IXMLDOMNode
** domNode
)
245 domtext
*This
= impl_from_IXMLDOMText( iface
);
246 return IXMLDOMNode_get_lastChild( This
->element
, domNode
);
249 static HRESULT WINAPI
domtext_get_previousSibling(
251 IXMLDOMNode
** domNode
)
253 domtext
*This
= impl_from_IXMLDOMText( iface
);
254 return IXMLDOMNode_get_previousSibling( This
->element
, domNode
);
257 static HRESULT WINAPI
domtext_get_nextSibling(
259 IXMLDOMNode
** domNode
)
261 domtext
*This
= impl_from_IXMLDOMText( iface
);
262 return IXMLDOMNode_get_nextSibling( This
->element
, domNode
);
265 static HRESULT WINAPI
domtext_get_attributes(
267 IXMLDOMNamedNodeMap
** attributeMap
)
269 domtext
*This
= impl_from_IXMLDOMText( iface
);
270 return IXMLDOMNode_get_attributes( This
->element
, attributeMap
);
273 static HRESULT WINAPI
domtext_insertBefore(
275 IXMLDOMNode
* newNode
, VARIANT var1
,
276 IXMLDOMNode
** outOldNode
)
278 domtext
*This
= impl_from_IXMLDOMText( iface
);
279 return IXMLDOMNode_insertBefore( This
->element
, newNode
, var1
, outOldNode
);
282 static HRESULT WINAPI
domtext_replaceChild(
284 IXMLDOMNode
* newNode
,
285 IXMLDOMNode
* oldNode
,
286 IXMLDOMNode
** outOldNode
)
288 domtext
*This
= impl_from_IXMLDOMText( iface
);
289 return IXMLDOMNode_replaceChild( This
->element
, newNode
, oldNode
, outOldNode
);
292 static HRESULT WINAPI
domtext_removeChild(
294 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
296 domtext
*This
= impl_from_IXMLDOMText( iface
);
297 return IXMLDOMNode_removeChild( This
->element
, domNode
, oldNode
);
300 static HRESULT WINAPI
domtext_appendChild(
302 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
304 domtext
*This
= impl_from_IXMLDOMText( iface
);
305 return IXMLDOMNode_appendChild( This
->element
, newNode
, outNewNode
);
308 static HRESULT WINAPI
domtext_hasChildNodes(
312 domtext
*This
= impl_from_IXMLDOMText( iface
);
313 return IXMLDOMNode_hasChildNodes( This
->element
, pbool
);
316 static HRESULT WINAPI
domtext_get_ownerDocument(
318 IXMLDOMDocument
** domDocument
)
320 domtext
*This
= impl_from_IXMLDOMText( iface
);
321 return IXMLDOMNode_get_ownerDocument( This
->element
, domDocument
);
324 static HRESULT WINAPI
domtext_cloneNode(
326 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
328 domtext
*This
= impl_from_IXMLDOMText( iface
);
329 return IXMLDOMNode_cloneNode( This
->element
, pbool
, outNode
);
332 static HRESULT WINAPI
domtext_get_nodeTypeString(
336 domtext
*This
= impl_from_IXMLDOMText( iface
);
337 return IXMLDOMNode_get_nodeTypeString( This
->element
, p
);
340 static HRESULT WINAPI
domtext_get_text(
344 domtext
*This
= impl_from_IXMLDOMText( iface
);
345 return IXMLDOMNode_get_text( This
->element
, p
);
348 static HRESULT WINAPI
domtext_put_text(
352 domtext
*This
= impl_from_IXMLDOMText( iface
);
353 return IXMLDOMNode_put_text( This
->element
, p
);
356 static HRESULT WINAPI
domtext_get_specified(
360 domtext
*This
= impl_from_IXMLDOMText( iface
);
361 return IXMLDOMNode_get_specified( This
->element
, pbool
);
364 static HRESULT WINAPI
domtext_get_definition(
366 IXMLDOMNode
** domNode
)
368 domtext
*This
= impl_from_IXMLDOMText( iface
);
369 return IXMLDOMNode_get_definition( This
->element
, domNode
);
372 static HRESULT WINAPI
domtext_get_nodeTypedValue(
376 domtext
*This
= impl_from_IXMLDOMText( iface
);
377 return IXMLDOMNode_get_nodeTypedValue( This
->element
, var1
);
380 static HRESULT WINAPI
domtext_put_nodeTypedValue(
384 domtext
*This
= impl_from_IXMLDOMText( iface
);
385 return IXMLDOMNode_put_nodeTypedValue( This
->element
, var1
);
388 static HRESULT WINAPI
domtext_get_dataType(
392 domtext
*This
= impl_from_IXMLDOMText( iface
);
393 return IXMLDOMNode_get_dataType( This
->element
, var1
);
396 static HRESULT WINAPI
domtext_put_dataType(
400 domtext
*This
= impl_from_IXMLDOMText( iface
);
401 return IXMLDOMNode_put_dataType( This
->element
, p
);
404 static HRESULT WINAPI
domtext_get_xml(
408 domtext
*This
= impl_from_IXMLDOMText( iface
);
409 return IXMLDOMNode_get_xml( This
->element
, p
);
412 static HRESULT WINAPI
domtext_transformNode(
414 IXMLDOMNode
* domNode
, BSTR
* p
)
416 domtext
*This
= impl_from_IXMLDOMText( iface
);
417 return IXMLDOMNode_transformNode( This
->element
, domNode
, p
);
420 static HRESULT WINAPI
domtext_selectNodes(
422 BSTR p
, IXMLDOMNodeList
** outList
)
424 domtext
*This
= impl_from_IXMLDOMText( iface
);
425 return IXMLDOMNode_selectNodes( This
->element
, p
, outList
);
428 static HRESULT WINAPI
domtext_selectSingleNode(
430 BSTR p
, IXMLDOMNode
** outNode
)
432 domtext
*This
= impl_from_IXMLDOMText( iface
);
433 return IXMLDOMNode_selectSingleNode( This
->element
, p
, outNode
);
436 static HRESULT WINAPI
domtext_get_parsed(
440 domtext
*This
= impl_from_IXMLDOMText( iface
);
441 return IXMLDOMNode_get_parsed( This
->element
, pbool
);
444 static HRESULT WINAPI
domtext_get_namespaceURI(
448 domtext
*This
= impl_from_IXMLDOMText( iface
);
449 return IXMLDOMNode_get_namespaceURI( This
->element
, p
);
452 static HRESULT WINAPI
domtext_get_prefix(
456 domtext
*This
= impl_from_IXMLDOMText( iface
);
457 return IXMLDOMNode_get_prefix( This
->element
, p
);
460 static HRESULT WINAPI
domtext_get_baseName(
464 domtext
*This
= impl_from_IXMLDOMText( iface
);
465 return IXMLDOMNode_get_baseName( This
->element
, p
);
468 static HRESULT WINAPI
domtext_transformNodeToObject(
470 IXMLDOMNode
* domNode
, VARIANT var1
)
472 domtext
*This
= impl_from_IXMLDOMText( iface
);
473 return IXMLDOMNode_transformNodeToObject( This
->element
, domNode
, var1
);
476 static HRESULT WINAPI
domtext_get_data(
480 domtext
*This
= impl_from_IXMLDOMText( iface
);
487 hr
= IXMLDOMNode_get_nodeValue( This
->element
, &vRet
);
496 static HRESULT WINAPI
domtext_put_data(
500 domtext
*This
= impl_from_IXMLDOMText( iface
);
504 TRACE("%p %s\n", This
, debugstr_w(data
) );
506 V_VT(&val
) = VT_BSTR
;
509 hr
= IXMLDOMNode_put_nodeValue( This
->element
, val
);
514 static HRESULT WINAPI
domtext_get_length(
518 domtext
*This
= impl_from_IXMLDOMText( iface
);
519 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
523 TRACE("%p\n", iface
);
528 pContent
= xmlNodeGetContent(pDOMNode
->node
);
531 nLength
= xmlStrlen(pContent
);
540 static HRESULT WINAPI
domtext_substringData(
542 long offset
, long count
, BSTR
*p
)
544 domtext
*This
= impl_from_IXMLDOMText( iface
);
545 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
548 HRESULT hr
= S_FALSE
;
550 TRACE("%p\n", iface
);
556 if(offset
< 0 || count
< 0)
562 pContent
= xmlNodeGetContent(pDOMNode
->node
);
565 nLength
= xmlStrlen(pContent
);
567 if( offset
< nLength
)
569 BSTR sContent
= bstr_from_xmlChar(pContent
);
570 if(offset
+ count
> nLength
)
571 *p
= SysAllocString(&sContent
[offset
]);
573 *p
= SysAllocStringLen(&sContent
[offset
], count
);
575 SysFreeString(sContent
);
585 static HRESULT WINAPI
domtext_appendData(
589 domtext
*This
= impl_from_IXMLDOMText( iface
);
590 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
592 HRESULT hr
= S_FALSE
;
594 TRACE("%p\n", iface
);
596 /* Nothing to do if NULL or an Empty string passed in. */
597 if(p
== NULL
|| SysStringLen(p
) == 0)
600 pContent
= xmlChar_from_wchar( (WCHAR
*)p
);
603 if(xmlTextConcat(pDOMNode
->node
, pContent
, SysStringLen(p
) ) == 0)
614 static HRESULT WINAPI
domtext_insertData(
618 domtext
*This
= impl_from_IXMLDOMText( iface
);
619 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
620 xmlChar
*pXmlContent
;
622 HRESULT hr
= S_FALSE
;
623 long nLength
= 0, nLengthP
= 0;
628 /* If have a NULL or empty string, don't do anything. */
629 if(SysStringLen(p
) == 0)
637 pXmlContent
= xmlNodeGetContent(pDOMNode
->node
);
640 BSTR sContent
= bstr_from_xmlChar( pXmlContent
);
641 nLength
= SysStringLen(sContent
);
642 nLengthP
= SysStringLen(p
);
646 SysFreeString(sContent
);
647 xmlFree(pXmlContent
);
652 sNewString
= SysAllocStringLen(NULL
, nLength
+ nLengthP
+ 1);
656 memcpy(sNewString
, sContent
, offset
* sizeof(WCHAR
));
658 memcpy(&sNewString
[offset
], p
, nLengthP
* sizeof(WCHAR
));
660 if(offset
+nLengthP
< nLength
)
661 memcpy(&sNewString
[offset
+nLengthP
], &sContent
[offset
], (nLength
-offset
) * sizeof(WCHAR
));
663 sNewString
[nLengthP
+ nLength
] = 0;
665 str
= xmlChar_from_wchar((WCHAR
*)sNewString
);
668 xmlNodeSetContent(pDOMNode
->node
, str
);
672 SysFreeString(sNewString
);
675 SysFreeString(sContent
);
677 xmlFree(pXmlContent
);
683 static HRESULT WINAPI
domtext_deleteData(
685 long offset
, long count
)
691 static HRESULT WINAPI
domtext_replaceData(
693 long offset
, long count
, BSTR p
)
699 static HRESULT WINAPI
domtext_splitText(
701 long offset
, IXMLDOMText
**txtNode
)
708 static const struct IXMLDOMTextVtbl domtext_vtbl
=
710 domtext_QueryInterface
,
713 domtext_GetTypeInfoCount
,
715 domtext_GetIDsOfNames
,
717 domtext_get_nodeName
,
718 domtext_get_nodeValue
,
719 domtext_put_nodeValue
,
720 domtext_get_nodeType
,
721 domtext_get_parentNode
,
722 domtext_get_childNodes
,
723 domtext_get_firstChild
,
724 domtext_get_lastChild
,
725 domtext_get_previousSibling
,
726 domtext_get_nextSibling
,
727 domtext_get_attributes
,
728 domtext_insertBefore
,
729 domtext_replaceChild
,
732 domtext_hasChildNodes
,
733 domtext_get_ownerDocument
,
735 domtext_get_nodeTypeString
,
738 domtext_get_specified
,
739 domtext_get_definition
,
740 domtext_get_nodeTypedValue
,
741 domtext_put_nodeTypedValue
,
742 domtext_get_dataType
,
743 domtext_put_dataType
,
745 domtext_transformNode
,
747 domtext_selectSingleNode
,
749 domtext_get_namespaceURI
,
751 domtext_get_baseName
,
752 domtext_transformNodeToObject
,
756 domtext_substringData
,
764 IUnknown
* create_text( xmlNodePtr text
)
769 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
773 This
->lpVtbl
= &domtext_vtbl
;
776 This
->element_unk
= create_element( text
, (IUnknown
*)&This
->lpVtbl
);
777 if(!This
->element_unk
)
779 HeapFree(GetProcessHeap(), 0, This
);
783 hr
= IUnknown_QueryInterface(This
->element_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&This
->element
);
786 IUnknown_Release(This
->element_unk
);
787 HeapFree( GetProcessHeap(), 0, This
);
790 /* The ref on This->element is actually looped back into this object, so release it */
791 IXMLDOMNode_Release(This
->element
);
793 return (IUnknown
*) &This
->lpVtbl
;