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);
177 V_VT(value) = VT_BSTR;
178 V_BSTR(value) = bstr_from_xmlChar(This->node.node->content);
182 static HRESULT WINAPI domtext_put_nodeValue(
186 domtext *This = impl_from_IXMLDOMText( iface );
188 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
190 return node_put_value(&This->node, &value);
193 static HRESULT WINAPI domtext_get_nodeType(
195 DOMNodeType* domNodeType )
197 domtext *This = impl_from_IXMLDOMText( iface );
199 TRACE("(%p)->(%p)\n", This, domNodeType);
201 *domNodeType = NODE_TEXT;
205 static HRESULT WINAPI domtext_get_parentNode(
207 IXMLDOMNode** parent )
209 domtext *This = impl_from_IXMLDOMText( iface );
211 TRACE("(%p)->(%p)\n", This, parent);
213 return node_get_parent(&This->node, parent);
216 static HRESULT WINAPI domtext_get_childNodes(
218 IXMLDOMNodeList** outList)
220 domtext *This = impl_from_IXMLDOMText( iface );
222 TRACE("(%p)->(%p)\n", This, outList);
224 return node_get_child_nodes(&This->node, outList);
227 static HRESULT WINAPI domtext_get_firstChild(
229 IXMLDOMNode** domNode)
231 domtext *This = impl_from_IXMLDOMText( iface );
233 TRACE("(%p)->(%p)\n", This, domNode);
235 return return_null_node(domNode);
238 static HRESULT WINAPI domtext_get_lastChild(
240 IXMLDOMNode** domNode)
242 domtext *This = impl_from_IXMLDOMText( iface );
244 TRACE("(%p)->(%p)\n", This, domNode);
246 return return_null_node(domNode);
249 static HRESULT WINAPI domtext_get_previousSibling(
251 IXMLDOMNode** domNode)
253 domtext *This = impl_from_IXMLDOMText( iface );
255 TRACE("(%p)->(%p)\n", This, domNode);
257 return node_get_previous_sibling(&This->node, domNode);
260 static HRESULT WINAPI domtext_get_nextSibling(
262 IXMLDOMNode** domNode)
264 domtext *This = impl_from_IXMLDOMText( iface );
266 TRACE("(%p)->(%p)\n", This, domNode);
268 return node_get_next_sibling(&This->node, domNode);
271 static HRESULT WINAPI domtext_get_attributes(
273 IXMLDOMNamedNodeMap** attributeMap)
275 domtext *This = impl_from_IXMLDOMText( iface );
277 TRACE("(%p)->(%p)\n", This, attributeMap);
279 return return_null_ptr((void**)attributeMap);
282 static HRESULT WINAPI domtext_insertBefore(
284 IXMLDOMNode* newNode, VARIANT refChild,
285 IXMLDOMNode** outOldNode)
287 domtext *This = impl_from_IXMLDOMText( iface );
289 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
291 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
294 static HRESULT WINAPI domtext_replaceChild(
296 IXMLDOMNode* newNode,
297 IXMLDOMNode* oldNode,
298 IXMLDOMNode** outOldNode)
300 domtext *This = impl_from_IXMLDOMText( iface );
302 FIXME("(%p)->(%p %p %p) needs test\n", This, newNode, oldNode, outOldNode);
304 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
307 static HRESULT WINAPI domtext_removeChild(
309 IXMLDOMNode *child, IXMLDOMNode **oldChild)
311 domtext *This = impl_from_IXMLDOMText( iface );
312 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
313 return node_remove_child(&This->node, child, oldChild);
316 static HRESULT WINAPI domtext_appendChild(
318 IXMLDOMNode *child, IXMLDOMNode **outChild)
320 domtext *This = impl_from_IXMLDOMText( iface );
321 TRACE("(%p)->(%p %p)\n", This, child, outChild);
322 return node_append_child(&This->node, child, outChild);
325 static HRESULT WINAPI domtext_hasChildNodes(
329 domtext *This = impl_from_IXMLDOMText( iface );
330 TRACE("(%p)->(%p)\n", This, ret);
331 return node_has_childnodes(&This->node, ret);
334 static HRESULT WINAPI domtext_get_ownerDocument(
336 IXMLDOMDocument **doc)
338 domtext *This = impl_from_IXMLDOMText( iface );
339 TRACE("(%p)->(%p)\n", This, doc);
340 return node_get_owner_doc(&This->node, doc);
343 static HRESULT WINAPI domtext_cloneNode(
345 VARIANT_BOOL deep, IXMLDOMNode** outNode)
347 domtext *This = impl_from_IXMLDOMText( iface );
348 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
349 return node_clone( &This->node, deep, outNode );
352 static HRESULT WINAPI domtext_get_nodeTypeString(
356 domtext *This = impl_from_IXMLDOMText( iface );
357 static const WCHAR textW[] = {'t','e','x','t',0};
359 TRACE("(%p)->(%p)\n", This, p);
361 return return_bstr(textW, p);
364 static HRESULT WINAPI domtext_get_text(
368 domtext *This = impl_from_IXMLDOMText( iface );
369 TRACE("(%p)->(%p)\n", This, p);
370 return node_get_text(&This->node, p);
373 static HRESULT WINAPI domtext_put_text(
377 domtext *This = impl_from_IXMLDOMText( iface );
378 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
379 return node_put_text( &This->node, p );
382 static HRESULT WINAPI domtext_get_specified(
384 VARIANT_BOOL* isSpecified)
386 domtext *This = impl_from_IXMLDOMText( iface );
387 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
388 *isSpecified = VARIANT_TRUE;
392 static HRESULT WINAPI domtext_get_definition(
394 IXMLDOMNode** definitionNode)
396 domtext *This = impl_from_IXMLDOMText( iface );
397 FIXME("(%p)->(%p)\n", This, definitionNode);
401 static HRESULT WINAPI domtext_get_nodeTypedValue(
405 domtext *This = impl_from_IXMLDOMText( iface );
406 IXMLDOMNode* parent = NULL;
409 TRACE("(%p)->(%p)\n", This, var1);
414 hr = domtext_get_parentNode(iface, &parent);
418 hr = IXMLDOMNode_get_nodeTypedValue(parent, var1);
419 IXMLDOMNode_Release(parent);
423 V_VT(var1) = VT_NULL;
431 static HRESULT WINAPI domtext_put_nodeTypedValue(
435 domtext *This = impl_from_IXMLDOMText( iface );
436 IXMLDOMNode* parent = NULL;
439 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
441 hr = domtext_get_parentNode(iface, &parent);
445 hr = IXMLDOMNode_put_nodeTypedValue(parent, value);
446 IXMLDOMNode_Release(parent);
456 static HRESULT WINAPI domtext_get_dataType(
460 domtext *This = impl_from_IXMLDOMText( iface );
461 IXMLDOMNode* parent = NULL;
464 TRACE("(%p)->(%p)\n", This, dtName);
469 hr = domtext_get_parentNode(iface, &parent);
473 hr = IXMLDOMNode_get_dataType(parent, dtName);
474 IXMLDOMNode_Release(parent);
478 V_VT(dtName) = VT_NULL;
479 V_BSTR(dtName) = NULL;
486 static HRESULT WINAPI domtext_put_dataType(
490 domtext *This = impl_from_IXMLDOMText( iface );
491 IXMLDOMNode* parent = NULL;
494 TRACE("(%p)->(%p)\n", This, dtName);
499 hr = domtext_get_parentNode(iface, &parent);
503 hr = IXMLDOMNode_put_dataType(parent, dtName);
504 IXMLDOMNode_Release(parent);
514 static HRESULT WINAPI domtext_get_xml(
518 domtext *This = impl_from_IXMLDOMText( iface );
520 TRACE("(%p)->(%p)\n", This, p);
522 return node_get_xml(&This->node, FALSE, FALSE, p);
525 static HRESULT WINAPI domtext_transformNode(
527 IXMLDOMNode *node, BSTR *p)
529 domtext *This = impl_from_IXMLDOMText( iface );
530 TRACE("(%p)->(%p %p)\n", This, node, p);
531 return node_transform_node(&This->node, node, p);
534 static HRESULT WINAPI domtext_selectNodes(
536 BSTR p, IXMLDOMNodeList** outList)
538 domtext *This = impl_from_IXMLDOMText( iface );
539 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
540 return node_select_nodes(&This->node, p, outList);
543 static HRESULT WINAPI domtext_selectSingleNode(
545 BSTR p, IXMLDOMNode** outNode)
547 domtext *This = impl_from_IXMLDOMText( iface );
548 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
549 return node_select_singlenode(&This->node, p, outNode);
552 static HRESULT WINAPI domtext_get_parsed(
554 VARIANT_BOOL* isParsed)
556 domtext *This = impl_from_IXMLDOMText( iface );
557 FIXME("(%p)->(%p) stub!\n", This, isParsed);
558 *isParsed = VARIANT_TRUE;
562 static HRESULT WINAPI domtext_get_namespaceURI(
566 domtext *This = impl_from_IXMLDOMText( iface );
567 TRACE("(%p)->(%p)\n", This, p);
568 return node_get_namespaceURI(&This->node, p);
571 static HRESULT WINAPI domtext_get_prefix(
575 domtext *This = impl_from_IXMLDOMText( iface );
576 TRACE("(%p)->(%p)\n", This, prefix);
577 return return_null_bstr( prefix );
580 static HRESULT WINAPI domtext_get_baseName(
584 domtext *This = impl_from_IXMLDOMText( iface );
585 TRACE("(%p)->(%p)\n", This, name);
586 return return_null_bstr( name );
589 static HRESULT WINAPI domtext_transformNodeToObject(
591 IXMLDOMNode* domNode, VARIANT var1)
593 domtext *This = impl_from_IXMLDOMText( iface );
594 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
598 static HRESULT WINAPI domtext_get_data(
602 domtext *This = impl_from_IXMLDOMText( iface );
607 *p = bstr_from_xmlChar(This->node.node->content);
611 static HRESULT WINAPI domtext_put_data(
615 domtext *This = impl_from_IXMLDOMText( iface );
618 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
620 V_VT(&val) = VT_BSTR;
622 return node_put_value(&This->node, &val);
625 static HRESULT WINAPI domtext_get_length(
629 domtext *This = impl_from_IXMLDOMText( iface );
633 TRACE("(%p)->(%p)\n", This, len);
638 hr = IXMLDOMText_get_data(iface, &data);
641 *len = SysStringLen(data);
648 static HRESULT WINAPI domtext_substringData(
650 LONG offset, LONG count, BSTR *p)
652 domtext *This = impl_from_IXMLDOMText( iface );
656 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
662 if(offset < 0 || count < 0)
668 hr = IXMLDOMText_get_data(iface, &data);
671 LONG len = SysStringLen(data);
675 if(offset + count > len)
676 *p = SysAllocString(&data[offset]);
678 *p = SysAllocStringLen(&data[offset], count);
689 static HRESULT WINAPI domtext_appendData(
693 domtext *This = impl_from_IXMLDOMText( iface );
698 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
700 /* Nothing to do if NULL or an Empty string passed in. */
701 if((p_len = SysStringLen(p)) == 0) return S_OK;
703 hr = IXMLDOMText_get_data(iface, &data);
706 LONG len = SysStringLen(data);
707 BSTR str = SysAllocStringLen(NULL, p_len + len);
709 memcpy(str, data, len*sizeof(WCHAR));
710 memcpy(&str[len], p, p_len*sizeof(WCHAR));
713 hr = IXMLDOMText_put_data(iface, str);
722 static HRESULT WINAPI domtext_insertData(
726 domtext *This = impl_from_IXMLDOMText( iface );
731 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
733 /* If have a NULL or empty string, don't do anything. */
734 if((p_len = SysStringLen(p)) == 0)
742 hr = IXMLDOMText_get_data(iface, &data);
745 LONG len = SysStringLen(data);
754 str = SysAllocStringLen(NULL, len + p_len);
755 /* start part, supplied string and end part */
756 memcpy(str, data, offset*sizeof(WCHAR));
757 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
758 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
761 hr = IXMLDOMText_put_data(iface, str);
770 static HRESULT WINAPI domtext_deleteData(
772 LONG offset, LONG count)
778 TRACE("(%p)->(%d %d)\n", iface, offset, count);
780 hr = IXMLDOMText_get_length(iface, &len);
781 if(hr != S_OK) return hr;
783 if((offset < 0) || (offset > len) || (count < 0))
786 if(len == 0) return S_OK;
788 /* cutting start or end */
789 if((offset == 0) || ((count + offset) >= len))
792 IXMLDOMText_substringData(iface, count, len - count, &str);
794 IXMLDOMText_substringData(iface, 0, offset, &str);
795 hr = IXMLDOMText_put_data(iface, str);
798 /* cutting from the inside */
802 IXMLDOMText_substringData(iface, 0, offset, &str);
803 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
805 hr = IXMLDOMText_put_data(iface, str);
807 hr = IXMLDOMText_appendData(iface, str_end);
809 SysFreeString(str_end);
817 static HRESULT WINAPI domtext_replaceData(
819 LONG offset, LONG count, BSTR p)
821 domtext *This = impl_from_IXMLDOMText( iface );
824 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
826 hr = IXMLDOMText_deleteData(iface, offset, count);
829 hr = IXMLDOMText_insertData(iface, offset, p);
834 static HRESULT WINAPI domtext_splitText(
836 LONG offset, IXMLDOMText **txtNode)
838 domtext *This = impl_from_IXMLDOMText( iface );
841 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
843 if (!txtNode || offset < 0) return E_INVALIDARG;
847 IXMLDOMText_get_length(iface, &length);
849 if (offset > length) return E_INVALIDARG;
850 if (offset == length) return S_FALSE;
852 FIXME("adjacent text nodes are not supported\n");
857 static const struct IXMLDOMTextVtbl domtext_vtbl =
859 domtext_QueryInterface,
862 domtext_GetTypeInfoCount,
864 domtext_GetIDsOfNames,
866 domtext_get_nodeName,
867 domtext_get_nodeValue,
868 domtext_put_nodeValue,
869 domtext_get_nodeType,
870 domtext_get_parentNode,
871 domtext_get_childNodes,
872 domtext_get_firstChild,
873 domtext_get_lastChild,
874 domtext_get_previousSibling,
875 domtext_get_nextSibling,
876 domtext_get_attributes,
877 domtext_insertBefore,
878 domtext_replaceChild,
881 domtext_hasChildNodes,
882 domtext_get_ownerDocument,
884 domtext_get_nodeTypeString,
887 domtext_get_specified,
888 domtext_get_definition,
889 domtext_get_nodeTypedValue,
890 domtext_put_nodeTypedValue,
891 domtext_get_dataType,
892 domtext_put_dataType,
894 domtext_transformNode,
896 domtext_selectSingleNode,
898 domtext_get_namespaceURI,
900 domtext_get_baseName,
901 domtext_transformNodeToObject,
905 domtext_substringData,
913 static const tid_t domtext_iface_tids[] = {
918 static dispex_static_data_t domtext_dispex = {
925 IUnknown* create_text( xmlNodePtr text )
929 This = heap_alloc( sizeof *This );
933 This->IXMLDOMText_iface.lpVtbl = &domtext_vtbl;
936 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMText_iface, &domtext_dispex);
938 return (IUnknown*)&This->IXMLDOMText_iface;