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
);
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
);
507 TRACE("(%p)->(%s)\n", This
, debugstr_w(data
) );
509 V_VT(&val
) = VT_BSTR
;
512 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This
->node
), val
);
515 static HRESULT WINAPI
domtext_get_length(
519 domtext
*This
= impl_from_IXMLDOMText( iface
);
523 TRACE("(%p)->(%p)\n", This
, len
);
528 hr
= IXMLDOMText_get_data(iface
, &data
);
531 *len
= SysStringLen(data
);
538 static HRESULT WINAPI
domtext_substringData(
540 LONG offset
, LONG count
, BSTR
*p
)
542 domtext
*This
= impl_from_IXMLDOMText( iface
);
546 TRACE("(%p)->(%d %d %p)\n", This
, offset
, count
, p
);
552 if(offset
< 0 || count
< 0)
558 hr
= IXMLDOMText_get_data(iface
, &data
);
561 LONG len
= SysStringLen(data
);
565 if(offset
+ count
> len
)
566 *p
= SysAllocString(&data
[offset
]);
568 *p
= SysAllocStringLen(&data
[offset
], count
);
579 static HRESULT WINAPI
domtext_appendData(
583 domtext
*This
= impl_from_IXMLDOMText( iface
);
588 TRACE("(%p)->(%s)\n", This
, debugstr_w(p
));
590 /* Nothing to do if NULL or an Empty string passed in. */
591 if((p_len
= SysStringLen(p
)) == 0) return S_OK
;
593 hr
= IXMLDOMText_get_data(iface
, &data
);
596 LONG len
= SysStringLen(data
);
597 BSTR str
= SysAllocStringLen(NULL
, p_len
+ len
);
599 memcpy(str
, data
, len
*sizeof(WCHAR
));
600 memcpy(&str
[len
], p
, p_len
*sizeof(WCHAR
));
603 hr
= IXMLDOMText_put_data(iface
, str
);
612 static HRESULT WINAPI
domtext_insertData(
616 domtext
*This
= impl_from_IXMLDOMText( iface
);
621 TRACE("(%p)->(%d %s)\n", This
, offset
, debugstr_w(p
));
623 /* If have a NULL or empty string, don't do anything. */
624 if((p_len
= SysStringLen(p
)) == 0)
632 hr
= IXMLDOMText_get_data(iface
, &data
);
635 LONG len
= SysStringLen(data
);
644 str
= SysAllocStringLen(NULL
, len
+ p_len
);
645 /* start part, supplied string and end part */
646 memcpy(str
, data
, offset
*sizeof(WCHAR
));
647 memcpy(&str
[offset
], p
, p_len
*sizeof(WCHAR
));
648 memcpy(&str
[offset
+p_len
], &data
[offset
], (len
-offset
)*sizeof(WCHAR
));
651 hr
= IXMLDOMText_put_data(iface
, str
);
660 static HRESULT WINAPI
domtext_deleteData(
662 LONG offset
, LONG count
)
668 TRACE("(%p)->(%d %d)\n", iface
, offset
, count
);
670 hr
= IXMLDOMText_get_length(iface
, &len
);
671 if(hr
!= S_OK
) return hr
;
673 if((offset
< 0) || (offset
> len
) || (count
< 0))
676 if(len
== 0) return S_OK
;
678 /* cutting start or end */
679 if((offset
== 0) || ((count
+ offset
) >= len
))
682 IXMLDOMText_substringData(iface
, count
, len
- count
, &str
);
684 IXMLDOMText_substringData(iface
, 0, offset
, &str
);
685 hr
= IXMLDOMText_put_data(iface
, str
);
688 /* cutting from the inside */
692 IXMLDOMText_substringData(iface
, 0, offset
, &str
);
693 IXMLDOMText_substringData(iface
, offset
+ count
, len
- count
, &str_end
);
695 hr
= IXMLDOMText_put_data(iface
, str
);
697 hr
= IXMLDOMText_appendData(iface
, str_end
);
699 SysFreeString(str_end
);
707 static HRESULT WINAPI
domtext_replaceData(
709 LONG offset
, LONG count
, BSTR p
)
711 domtext
*This
= impl_from_IXMLDOMText( iface
);
714 TRACE("(%p)->(%d %d %s)\n", This
, offset
, count
, debugstr_w(p
));
716 hr
= IXMLDOMText_deleteData(iface
, offset
, count
);
719 hr
= IXMLDOMText_insertData(iface
, offset
, p
);
724 static HRESULT WINAPI
domtext_splitText(
726 LONG offset
, IXMLDOMText
**txtNode
)
728 domtext
*This
= impl_from_IXMLDOMText( iface
);
729 FIXME("(%p)->(%d %p)\n", This
, offset
, txtNode
);
734 static const struct IXMLDOMTextVtbl domtext_vtbl
=
736 domtext_QueryInterface
,
739 domtext_GetTypeInfoCount
,
741 domtext_GetIDsOfNames
,
743 domtext_get_nodeName
,
744 domtext_get_nodeValue
,
745 domtext_put_nodeValue
,
746 domtext_get_nodeType
,
747 domtext_get_parentNode
,
748 domtext_get_childNodes
,
749 domtext_get_firstChild
,
750 domtext_get_lastChild
,
751 domtext_get_previousSibling
,
752 domtext_get_nextSibling
,
753 domtext_get_attributes
,
754 domtext_insertBefore
,
755 domtext_replaceChild
,
758 domtext_hasChildNodes
,
759 domtext_get_ownerDocument
,
761 domtext_get_nodeTypeString
,
764 domtext_get_specified
,
765 domtext_get_definition
,
766 domtext_get_nodeTypedValue
,
767 domtext_put_nodeTypedValue
,
768 domtext_get_dataType
,
769 domtext_put_dataType
,
771 domtext_transformNode
,
773 domtext_selectSingleNode
,
775 domtext_get_namespaceURI
,
777 domtext_get_baseName
,
778 domtext_transformNodeToObject
,
782 domtext_substringData
,
790 IUnknown
* create_text( xmlNodePtr text
)
794 This
= heap_alloc( sizeof *This
);
798 This
->lpVtbl
= &domtext_vtbl
;
801 init_xmlnode(&This
->node
, text
, (IUnknown
*)&This
->lpVtbl
, NULL
);
803 return (IUnknown
*) &This
->lpVtbl
;