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
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
38 #include "msxml_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
46 typedef struct _domtext
49 IXMLDOMText IXMLDOMText_iface
;
53 static inline domtext
*impl_from_IXMLDOMText( IXMLDOMText
*iface
)
55 return CONTAINING_RECORD(iface
, domtext
, IXMLDOMText_iface
);
58 static HRESULT WINAPI
domtext_QueryInterface(
63 domtext
*This
= impl_from_IXMLDOMText( iface
);
64 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
66 if ( IsEqualGUID( riid
, &IID_IXMLDOMText
) ||
67 IsEqualGUID( riid
, &IID_IXMLDOMCharacterData
) ||
68 IsEqualGUID( riid
, &IID_IXMLDOMNode
) ||
69 IsEqualGUID( riid
, &IID_IDispatch
) ||
70 IsEqualGUID( riid
, &IID_IUnknown
) )
74 else if(node_query_interface(&This
->node
, riid
, ppvObject
))
76 return *ppvObject
? S_OK
: E_NOINTERFACE
;
80 TRACE("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 ULONG ref
= InterlockedIncrement( &This
->ref
);
94 TRACE("(%p)->(%d)\n", This
, ref
);
98 static ULONG WINAPI
domtext_Release(
101 domtext
*This
= impl_from_IXMLDOMText( iface
);
102 ULONG ref
= InterlockedDecrement( &This
->ref
);
104 TRACE("(%p)->(%d)\n", This
, ref
);
107 destroy_xmlnode(&This
->node
);
114 static HRESULT WINAPI
domtext_GetTypeInfoCount(
118 domtext
*This
= impl_from_IXMLDOMText( iface
);
119 return IDispatchEx_GetTypeInfoCount(&This
->node
.dispex
.IDispatchEx_iface
, pctinfo
);
122 static HRESULT WINAPI
domtext_GetTypeInfo(
124 UINT iTInfo
, LCID lcid
,
125 ITypeInfo
** ppTInfo
)
127 domtext
*This
= impl_from_IXMLDOMText( iface
);
128 return IDispatchEx_GetTypeInfo(&This
->node
.dispex
.IDispatchEx_iface
,
129 iTInfo
, lcid
, ppTInfo
);
132 static HRESULT WINAPI
domtext_GetIDsOfNames(
134 REFIID riid
, LPOLESTR
* rgszNames
,
135 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
137 domtext
*This
= impl_from_IXMLDOMText( iface
);
138 return IDispatchEx_GetIDsOfNames(&This
->node
.dispex
.IDispatchEx_iface
,
139 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
142 static HRESULT WINAPI
domtext_Invoke(
144 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
145 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
146 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
148 domtext
*This
= impl_from_IXMLDOMText( iface
);
149 return IDispatchEx_Invoke(&This
->node
.dispex
.IDispatchEx_iface
,
150 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
153 static HRESULT WINAPI
domtext_get_nodeName(
157 domtext
*This
= impl_from_IXMLDOMText( iface
);
159 static const WCHAR textW
[] = {'#','t','e','x','t',0};
161 TRACE("(%p)->(%p)\n", This
, p
);
163 return return_bstr(textW
, p
);
166 static HRESULT WINAPI
domtext_get_nodeValue(
170 domtext
*This
= impl_from_IXMLDOMText( iface
);
172 TRACE("(%p)->(%p)\n", This
, value
);
174 return node_get_content(&This
->node
, value
);
177 static HRESULT WINAPI
domtext_put_nodeValue(
181 domtext
*This
= impl_from_IXMLDOMText( iface
);
183 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&value
));
185 return node_put_value(&This
->node
, &value
);
188 static HRESULT WINAPI
domtext_get_nodeType(
190 DOMNodeType
* domNodeType
)
192 domtext
*This
= impl_from_IXMLDOMText( iface
);
194 TRACE("(%p)->(%p)\n", This
, domNodeType
);
196 *domNodeType
= NODE_TEXT
;
200 static HRESULT WINAPI
domtext_get_parentNode(
202 IXMLDOMNode
** parent
)
204 domtext
*This
= impl_from_IXMLDOMText( iface
);
206 TRACE("(%p)->(%p)\n", This
, parent
);
208 return node_get_parent(&This
->node
, parent
);
211 static HRESULT WINAPI
domtext_get_childNodes(
213 IXMLDOMNodeList
** outList
)
215 domtext
*This
= impl_from_IXMLDOMText( iface
);
217 TRACE("(%p)->(%p)\n", This
, outList
);
219 return node_get_child_nodes(&This
->node
, outList
);
222 static HRESULT WINAPI
domtext_get_firstChild(
224 IXMLDOMNode
** domNode
)
226 domtext
*This
= impl_from_IXMLDOMText( iface
);
228 TRACE("(%p)->(%p)\n", This
, domNode
);
230 return return_null_node(domNode
);
233 static HRESULT WINAPI
domtext_get_lastChild(
235 IXMLDOMNode
** domNode
)
237 domtext
*This
= impl_from_IXMLDOMText( iface
);
239 TRACE("(%p)->(%p)\n", This
, domNode
);
241 return return_null_node(domNode
);
244 static HRESULT WINAPI
domtext_get_previousSibling(
246 IXMLDOMNode
** domNode
)
248 domtext
*This
= impl_from_IXMLDOMText( iface
);
250 TRACE("(%p)->(%p)\n", This
, domNode
);
252 return node_get_previous_sibling(&This
->node
, domNode
);
255 static HRESULT WINAPI
domtext_get_nextSibling(
257 IXMLDOMNode
** domNode
)
259 domtext
*This
= impl_from_IXMLDOMText( iface
);
261 TRACE("(%p)->(%p)\n", This
, domNode
);
263 return node_get_next_sibling(&This
->node
, domNode
);
266 static HRESULT WINAPI
domtext_get_attributes(
268 IXMLDOMNamedNodeMap
** attributeMap
)
270 domtext
*This
= impl_from_IXMLDOMText( iface
);
272 TRACE("(%p)->(%p)\n", This
, attributeMap
);
274 return return_null_ptr((void**)attributeMap
);
277 static HRESULT WINAPI
domtext_insertBefore(
279 IXMLDOMNode
* newNode
, VARIANT refChild
,
280 IXMLDOMNode
** outOldNode
)
282 domtext
*This
= impl_from_IXMLDOMText( iface
);
284 FIXME("(%p)->(%p %s %p) needs test\n", This
, newNode
, debugstr_variant(&refChild
), outOldNode
);
286 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
289 static HRESULT WINAPI
domtext_replaceChild(
291 IXMLDOMNode
* newNode
,
292 IXMLDOMNode
* oldNode
,
293 IXMLDOMNode
** outOldNode
)
295 domtext
*This
= impl_from_IXMLDOMText( iface
);
297 FIXME("(%p)->(%p %p %p) needs test\n", This
, newNode
, oldNode
, outOldNode
);
299 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
302 static HRESULT WINAPI
domtext_removeChild(
304 IXMLDOMNode
*child
, IXMLDOMNode
**oldChild
)
306 domtext
*This
= impl_from_IXMLDOMText( iface
);
307 TRACE("(%p)->(%p %p)\n", This
, child
, oldChild
);
308 return node_remove_child(&This
->node
, child
, oldChild
);
311 static HRESULT WINAPI
domtext_appendChild(
313 IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
315 domtext
*This
= impl_from_IXMLDOMText( iface
);
316 TRACE("(%p)->(%p %p)\n", This
, child
, outChild
);
317 return node_append_child(&This
->node
, child
, outChild
);
320 static HRESULT WINAPI
domtext_hasChildNodes(
324 domtext
*This
= impl_from_IXMLDOMText( iface
);
325 TRACE("(%p)->(%p)\n", This
, ret
);
326 return node_has_childnodes(&This
->node
, ret
);
329 static HRESULT WINAPI
domtext_get_ownerDocument(
331 IXMLDOMDocument
**doc
)
333 domtext
*This
= impl_from_IXMLDOMText( iface
);
334 TRACE("(%p)->(%p)\n", This
, doc
);
335 return node_get_owner_doc(&This
->node
, doc
);
338 static HRESULT WINAPI
domtext_cloneNode(
340 VARIANT_BOOL deep
, IXMLDOMNode
** outNode
)
342 domtext
*This
= impl_from_IXMLDOMText( iface
);
343 TRACE("(%p)->(%d %p)\n", This
, deep
, outNode
);
344 return node_clone( &This
->node
, deep
, outNode
);
347 static HRESULT WINAPI
domtext_get_nodeTypeString(
351 domtext
*This
= impl_from_IXMLDOMText( iface
);
352 static const WCHAR textW
[] = {'t','e','x','t',0};
354 TRACE("(%p)->(%p)\n", This
, p
);
356 return return_bstr(textW
, p
);
359 static HRESULT WINAPI
domtext_get_text(
363 domtext
*This
= impl_from_IXMLDOMText( iface
);
364 TRACE("(%p)->(%p)\n", This
, p
);
365 return node_get_text(&This
->node
, p
);
368 static HRESULT WINAPI
domtext_put_text(
372 domtext
*This
= impl_from_IXMLDOMText( iface
);
373 TRACE("(%p)->(%s)\n", This
, debugstr_w(p
));
374 return node_put_text( &This
->node
, p
);
377 static HRESULT WINAPI
domtext_get_specified(
379 VARIANT_BOOL
* isSpecified
)
381 domtext
*This
= impl_from_IXMLDOMText( iface
);
382 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
383 *isSpecified
= VARIANT_TRUE
;
387 static HRESULT WINAPI
domtext_get_definition(
389 IXMLDOMNode
** definitionNode
)
391 domtext
*This
= impl_from_IXMLDOMText( iface
);
392 FIXME("(%p)->(%p)\n", This
, definitionNode
);
396 static HRESULT WINAPI
domtext_get_nodeTypedValue(
400 domtext
*This
= impl_from_IXMLDOMText( iface
);
401 IXMLDOMNode
* parent
= NULL
;
404 TRACE("(%p)->(%p)\n", This
, var1
);
409 hr
= IXMLDOMText_get_parentNode(iface
, &parent
);
413 hr
= IXMLDOMNode_get_nodeTypedValue(parent
, var1
);
414 IXMLDOMNode_Release(parent
);
418 V_VT(var1
) = VT_NULL
;
426 static HRESULT WINAPI
domtext_put_nodeTypedValue(
430 domtext
*This
= impl_from_IXMLDOMText( iface
);
431 IXMLDOMNode
* parent
= NULL
;
434 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&value
));
436 hr
= IXMLDOMText_get_parentNode(iface
, &parent
);
440 hr
= IXMLDOMNode_put_nodeTypedValue(parent
, value
);
441 IXMLDOMNode_Release(parent
);
451 static HRESULT WINAPI
domtext_get_dataType(
455 domtext
*This
= impl_from_IXMLDOMText( iface
);
456 IXMLDOMNode
* parent
= NULL
;
459 TRACE("(%p)->(%p)\n", This
, dtName
);
464 hr
= IXMLDOMText_get_parentNode(iface
, &parent
);
468 hr
= IXMLDOMNode_get_dataType(parent
, dtName
);
469 IXMLDOMNode_Release(parent
);
473 V_VT(dtName
) = VT_NULL
;
474 V_BSTR(dtName
) = NULL
;
481 static HRESULT WINAPI
domtext_put_dataType(
485 domtext
*This
= impl_from_IXMLDOMText( iface
);
486 IXMLDOMNode
* parent
= NULL
;
489 TRACE("(%p)->(%p)\n", This
, dtName
);
494 hr
= IXMLDOMText_get_parentNode(iface
, &parent
);
498 hr
= IXMLDOMNode_put_dataType(parent
, dtName
);
499 IXMLDOMNode_Release(parent
);
509 static HRESULT WINAPI
domtext_get_xml(
513 domtext
*This
= impl_from_IXMLDOMText( iface
);
515 TRACE("(%p)->(%p)\n", This
, p
);
517 return node_get_xml(&This
->node
, FALSE
, FALSE
, p
);
520 static HRESULT WINAPI
domtext_transformNode(
522 IXMLDOMNode
*node
, BSTR
*p
)
524 domtext
*This
= impl_from_IXMLDOMText( iface
);
525 TRACE("(%p)->(%p %p)\n", This
, node
, p
);
526 return node_transform_node(&This
->node
, node
, p
);
529 static HRESULT WINAPI
domtext_selectNodes(
531 BSTR p
, IXMLDOMNodeList
** outList
)
533 domtext
*This
= impl_from_IXMLDOMText( iface
);
534 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(p
), outList
);
535 return node_select_nodes(&This
->node
, p
, outList
);
538 static HRESULT WINAPI
domtext_selectSingleNode(
540 BSTR p
, IXMLDOMNode
** outNode
)
542 domtext
*This
= impl_from_IXMLDOMText( iface
);
543 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(p
), outNode
);
544 return node_select_singlenode(&This
->node
, p
, outNode
);
547 static HRESULT WINAPI
domtext_get_parsed(
549 VARIANT_BOOL
* isParsed
)
551 domtext
*This
= impl_from_IXMLDOMText( iface
);
552 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
553 *isParsed
= VARIANT_TRUE
;
557 static HRESULT WINAPI
domtext_get_namespaceURI(
561 domtext
*This
= impl_from_IXMLDOMText( iface
);
562 TRACE("(%p)->(%p)\n", This
, p
);
563 return node_get_namespaceURI(&This
->node
, p
);
566 static HRESULT WINAPI
domtext_get_prefix(
570 domtext
*This
= impl_from_IXMLDOMText( iface
);
571 TRACE("(%p)->(%p)\n", This
, prefix
);
572 return return_null_bstr( prefix
);
575 static HRESULT WINAPI
domtext_get_baseName(
579 domtext
*This
= impl_from_IXMLDOMText( iface
);
580 TRACE("(%p)->(%p)\n", This
, name
);
581 return return_null_bstr( name
);
584 static HRESULT WINAPI
domtext_transformNodeToObject(
586 IXMLDOMNode
* domNode
, VARIANT var1
)
588 domtext
*This
= impl_from_IXMLDOMText( iface
);
589 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
593 static HRESULT WINAPI
domtext_get_data(
597 domtext
*This
= impl_from_IXMLDOMText( iface
);
602 *p
= bstr_from_xmlChar(This
->node
.node
->content
);
606 static HRESULT WINAPI
domtext_put_data(
610 domtext
*This
= impl_from_IXMLDOMText( iface
);
613 TRACE("(%p)->(%s)\n", This
, debugstr_w(data
) );
615 V_VT(&val
) = VT_BSTR
;
617 return node_put_value(&This
->node
, &val
);
620 static HRESULT WINAPI
domtext_get_length(
624 domtext
*This
= impl_from_IXMLDOMText( iface
);
628 TRACE("(%p)->(%p)\n", This
, len
);
633 hr
= IXMLDOMText_get_data(iface
, &data
);
636 *len
= SysStringLen(data
);
643 static HRESULT WINAPI
domtext_substringData(
645 LONG offset
, LONG count
, BSTR
*p
)
647 domtext
*This
= impl_from_IXMLDOMText( iface
);
651 TRACE("(%p)->(%d %d %p)\n", This
, offset
, count
, p
);
657 if(offset
< 0 || count
< 0)
663 hr
= IXMLDOMText_get_data(iface
, &data
);
666 LONG len
= SysStringLen(data
);
670 if(offset
+ count
> len
)
671 *p
= SysAllocString(&data
[offset
]);
673 *p
= SysAllocStringLen(&data
[offset
], count
);
684 static HRESULT WINAPI
domtext_appendData(
688 domtext
*This
= impl_from_IXMLDOMText( iface
);
693 TRACE("(%p)->(%s)\n", This
, debugstr_w(p
));
695 /* Nothing to do if NULL or an Empty string passed in. */
696 if((p_len
= SysStringLen(p
)) == 0) return S_OK
;
698 hr
= IXMLDOMText_get_data(iface
, &data
);
701 LONG len
= SysStringLen(data
);
702 BSTR str
= SysAllocStringLen(NULL
, p_len
+ len
);
704 memcpy(str
, data
, len
*sizeof(WCHAR
));
705 memcpy(&str
[len
], p
, p_len
*sizeof(WCHAR
));
708 hr
= IXMLDOMText_put_data(iface
, str
);
717 static HRESULT WINAPI
domtext_insertData(
721 domtext
*This
= impl_from_IXMLDOMText( iface
);
726 TRACE("(%p)->(%d %s)\n", This
, offset
, debugstr_w(p
));
728 /* If have a NULL or empty string, don't do anything. */
729 if((p_len
= SysStringLen(p
)) == 0)
737 hr
= IXMLDOMText_get_data(iface
, &data
);
740 LONG len
= SysStringLen(data
);
749 str
= SysAllocStringLen(NULL
, len
+ p_len
);
750 /* start part, supplied string and end part */
751 memcpy(str
, data
, offset
*sizeof(WCHAR
));
752 memcpy(&str
[offset
], p
, p_len
*sizeof(WCHAR
));
753 memcpy(&str
[offset
+p_len
], &data
[offset
], (len
-offset
)*sizeof(WCHAR
));
756 hr
= IXMLDOMText_put_data(iface
, str
);
765 static HRESULT WINAPI
domtext_deleteData(
767 LONG offset
, LONG count
)
773 TRACE("(%p)->(%d %d)\n", iface
, offset
, count
);
775 hr
= IXMLDOMText_get_length(iface
, &len
);
776 if(hr
!= S_OK
) return hr
;
778 if((offset
< 0) || (offset
> len
) || (count
< 0))
781 if(len
== 0) return S_OK
;
783 /* cutting start or end */
784 if((offset
== 0) || ((count
+ offset
) >= len
))
787 IXMLDOMText_substringData(iface
, count
, len
- count
, &str
);
789 IXMLDOMText_substringData(iface
, 0, offset
, &str
);
790 hr
= IXMLDOMText_put_data(iface
, str
);
793 /* cutting from the inside */
797 IXMLDOMText_substringData(iface
, 0, offset
, &str
);
798 IXMLDOMText_substringData(iface
, offset
+ count
, len
- count
, &str_end
);
800 hr
= IXMLDOMText_put_data(iface
, str
);
802 hr
= IXMLDOMText_appendData(iface
, str_end
);
804 SysFreeString(str_end
);
812 static HRESULT WINAPI
domtext_replaceData(
814 LONG offset
, LONG count
, BSTR p
)
816 domtext
*This
= impl_from_IXMLDOMText( iface
);
819 TRACE("(%p)->(%d %d %s)\n", This
, offset
, count
, debugstr_w(p
));
821 hr
= IXMLDOMText_deleteData(iface
, offset
, count
);
824 hr
= IXMLDOMText_insertData(iface
, offset
, p
);
829 static HRESULT WINAPI
domtext_splitText(
831 LONG offset
, IXMLDOMText
**txtNode
)
833 domtext
*This
= impl_from_IXMLDOMText( iface
);
836 TRACE("(%p)->(%d %p)\n", This
, offset
, txtNode
);
838 if (!txtNode
|| offset
< 0) return E_INVALIDARG
;
842 IXMLDOMText_get_length(iface
, &length
);
844 if (offset
> length
) return E_INVALIDARG
;
845 if (offset
== length
) return S_FALSE
;
847 FIXME("adjacent text nodes are not supported\n");
852 static const struct IXMLDOMTextVtbl domtext_vtbl
=
854 domtext_QueryInterface
,
857 domtext_GetTypeInfoCount
,
859 domtext_GetIDsOfNames
,
861 domtext_get_nodeName
,
862 domtext_get_nodeValue
,
863 domtext_put_nodeValue
,
864 domtext_get_nodeType
,
865 domtext_get_parentNode
,
866 domtext_get_childNodes
,
867 domtext_get_firstChild
,
868 domtext_get_lastChild
,
869 domtext_get_previousSibling
,
870 domtext_get_nextSibling
,
871 domtext_get_attributes
,
872 domtext_insertBefore
,
873 domtext_replaceChild
,
876 domtext_hasChildNodes
,
877 domtext_get_ownerDocument
,
879 domtext_get_nodeTypeString
,
882 domtext_get_specified
,
883 domtext_get_definition
,
884 domtext_get_nodeTypedValue
,
885 domtext_put_nodeTypedValue
,
886 domtext_get_dataType
,
887 domtext_put_dataType
,
889 domtext_transformNode
,
891 domtext_selectSingleNode
,
893 domtext_get_namespaceURI
,
895 domtext_get_baseName
,
896 domtext_transformNodeToObject
,
900 domtext_substringData
,
908 static const tid_t domtext_iface_tids
[] = {
913 static dispex_static_data_t domtext_dispex
= {
920 IUnknown
* create_text( xmlNodePtr text
)
924 This
= heap_alloc( sizeof *This
);
928 This
->IXMLDOMText_iface
.lpVtbl
= &domtext_vtbl
;
931 init_xmlnode(&This
->node
, text
, (IXMLDOMNode
*)&This
->IXMLDOMText_iface
, &domtext_dispex
);
933 return (IUnknown
*)&This
->IXMLDOMText_iface
;