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 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 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 );
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->IXMLDOMText_iface, 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 );
197 static const WCHAR textW[] = {'#','t','e','x','t',0};
199 TRACE("(%p)->(%p)\n", This, p);
201 return return_bstr(textW, p);
204 static HRESULT WINAPI domtext_get_nodeValue(
208 domtext *This = impl_from_IXMLDOMText( iface );
210 TRACE("(%p)->(%p)\n", This, value);
215 V_VT(value) = VT_BSTR;
216 V_BSTR(value) = bstr_from_xmlChar(This->node.node->content);
220 static HRESULT WINAPI domtext_put_nodeValue(
224 domtext *This = impl_from_IXMLDOMText( iface );
226 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
228 return node_put_value(&This->node, &value);
231 static HRESULT WINAPI domtext_get_nodeType(
233 DOMNodeType* domNodeType )
235 domtext *This = impl_from_IXMLDOMText( iface );
237 TRACE("(%p)->(%p)\n", This, domNodeType);
239 *domNodeType = NODE_TEXT;
243 static HRESULT WINAPI domtext_get_parentNode(
245 IXMLDOMNode** parent )
247 domtext *This = impl_from_IXMLDOMText( iface );
249 TRACE("(%p)->(%p)\n", This, parent);
251 return node_get_parent(&This->node, parent);
254 static HRESULT WINAPI domtext_get_childNodes(
256 IXMLDOMNodeList** outList)
258 domtext *This = impl_from_IXMLDOMText( iface );
260 TRACE("(%p)->(%p)\n", This, outList);
262 return node_get_child_nodes(&This->node, outList);
265 static HRESULT WINAPI domtext_get_firstChild(
267 IXMLDOMNode** domNode)
269 domtext *This = impl_from_IXMLDOMText( iface );
271 TRACE("(%p)->(%p)\n", This, domNode);
273 return return_null_node(domNode);
276 static HRESULT WINAPI domtext_get_lastChild(
278 IXMLDOMNode** domNode)
280 domtext *This = impl_from_IXMLDOMText( iface );
282 TRACE("(%p)->(%p)\n", This, domNode);
284 return return_null_node(domNode);
287 static HRESULT WINAPI domtext_get_previousSibling(
289 IXMLDOMNode** domNode)
291 domtext *This = impl_from_IXMLDOMText( iface );
293 TRACE("(%p)->(%p)\n", This, domNode);
295 return node_get_previous_sibling(&This->node, domNode);
298 static HRESULT WINAPI domtext_get_nextSibling(
300 IXMLDOMNode** domNode)
302 domtext *This = impl_from_IXMLDOMText( iface );
304 TRACE("(%p)->(%p)\n", This, domNode);
306 return node_get_next_sibling(&This->node, domNode);
309 static HRESULT WINAPI domtext_get_attributes(
311 IXMLDOMNamedNodeMap** attributeMap)
313 domtext *This = impl_from_IXMLDOMText( iface );
315 TRACE("(%p)->(%p)\n", This, attributeMap);
317 return return_null_ptr((void**)attributeMap);
320 static HRESULT WINAPI domtext_insertBefore(
322 IXMLDOMNode* newNode, VARIANT refChild,
323 IXMLDOMNode** outOldNode)
325 domtext *This = impl_from_IXMLDOMText( iface );
327 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
329 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
332 static HRESULT WINAPI domtext_replaceChild(
334 IXMLDOMNode* newNode,
335 IXMLDOMNode* oldNode,
336 IXMLDOMNode** outOldNode)
338 domtext *This = impl_from_IXMLDOMText( iface );
340 FIXME("(%p)->(%p %p %p) needs test\n", This, newNode, oldNode, outOldNode);
342 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
345 static HRESULT WINAPI domtext_removeChild(
347 IXMLDOMNode *child, IXMLDOMNode **oldChild)
349 domtext *This = impl_from_IXMLDOMText( iface );
350 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
351 return node_remove_child(&This->node, child, oldChild);
354 static HRESULT WINAPI domtext_appendChild(
356 IXMLDOMNode *child, IXMLDOMNode **outChild)
358 domtext *This = impl_from_IXMLDOMText( iface );
359 TRACE("(%p)->(%p %p)\n", This, child, outChild);
360 return node_append_child(&This->node, child, outChild);
363 static HRESULT WINAPI domtext_hasChildNodes(
367 domtext *This = impl_from_IXMLDOMText( iface );
368 TRACE("(%p)->(%p)\n", This, ret);
369 return node_has_childnodes(&This->node, ret);
372 static HRESULT WINAPI domtext_get_ownerDocument(
374 IXMLDOMDocument **doc)
376 domtext *This = impl_from_IXMLDOMText( iface );
377 TRACE("(%p)->(%p)\n", This, doc);
378 return node_get_owner_doc(&This->node, doc);
381 static HRESULT WINAPI domtext_cloneNode(
383 VARIANT_BOOL deep, IXMLDOMNode** outNode)
385 domtext *This = impl_from_IXMLDOMText( iface );
386 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
387 return node_clone( &This->node, deep, outNode );
390 static HRESULT WINAPI domtext_get_nodeTypeString(
394 domtext *This = impl_from_IXMLDOMText( iface );
395 static const WCHAR textW[] = {'t','e','x','t',0};
397 TRACE("(%p)->(%p)\n", This, p);
399 return return_bstr(textW, p);
402 static HRESULT WINAPI domtext_get_text(
406 domtext *This = impl_from_IXMLDOMText( iface );
407 TRACE("(%p)->(%p)\n", This, p);
408 return node_get_text(&This->node, p);
411 static HRESULT WINAPI domtext_put_text(
415 domtext *This = impl_from_IXMLDOMText( iface );
416 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
417 return node_put_text( &This->node, p );
420 static HRESULT WINAPI domtext_get_specified(
422 VARIANT_BOOL* isSpecified)
424 domtext *This = impl_from_IXMLDOMText( iface );
425 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
426 *isSpecified = VARIANT_TRUE;
430 static HRESULT WINAPI domtext_get_definition(
432 IXMLDOMNode** definitionNode)
434 domtext *This = impl_from_IXMLDOMText( iface );
435 FIXME("(%p)->(%p)\n", This, definitionNode);
439 static HRESULT WINAPI domtext_get_nodeTypedValue(
443 domtext *This = impl_from_IXMLDOMText( iface );
444 IXMLDOMNode* parent = NULL;
447 TRACE("(%p)->(%p)\n", This, var1);
452 hr = domtext_get_parentNode(iface, &parent);
456 hr = IXMLDOMNode_get_nodeTypedValue(parent, var1);
457 IXMLDOMNode_Release(parent);
461 V_VT(var1) = VT_NULL;
469 static HRESULT WINAPI domtext_put_nodeTypedValue(
473 domtext *This = impl_from_IXMLDOMText( iface );
474 IXMLDOMNode* parent = NULL;
477 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
479 hr = domtext_get_parentNode(iface, &parent);
483 hr = IXMLDOMNode_put_nodeTypedValue(parent, value);
484 IXMLDOMNode_Release(parent);
494 static HRESULT WINAPI domtext_get_dataType(
498 domtext *This = impl_from_IXMLDOMText( iface );
499 IXMLDOMNode* parent = NULL;
502 TRACE("(%p)->(%p)\n", This, dtName);
507 hr = domtext_get_parentNode(iface, &parent);
511 hr = IXMLDOMNode_get_dataType(parent, dtName);
512 IXMLDOMNode_Release(parent);
516 V_VT(dtName) = VT_NULL;
517 V_BSTR(dtName) = NULL;
524 static HRESULT WINAPI domtext_put_dataType(
528 domtext *This = impl_from_IXMLDOMText( iface );
529 IXMLDOMNode* parent = NULL;
532 TRACE("(%p)->(%p)\n", This, dtName);
537 hr = domtext_get_parentNode(iface, &parent);
541 hr = IXMLDOMNode_put_dataType(parent, dtName);
542 IXMLDOMNode_Release(parent);
552 static HRESULT WINAPI domtext_get_xml(
556 domtext *This = impl_from_IXMLDOMText( iface );
558 TRACE("(%p)->(%p)\n", This, p);
560 return node_get_xml(&This->node, FALSE, FALSE, p);
563 static HRESULT WINAPI domtext_transformNode(
565 IXMLDOMNode *node, BSTR *p)
567 domtext *This = impl_from_IXMLDOMText( iface );
568 TRACE("(%p)->(%p %p)\n", This, node, p);
569 return node_transform_node(&This->node, node, p);
572 static HRESULT WINAPI domtext_selectNodes(
574 BSTR p, IXMLDOMNodeList** outList)
576 domtext *This = impl_from_IXMLDOMText( iface );
577 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
578 return node_select_nodes(&This->node, p, outList);
581 static HRESULT WINAPI domtext_selectSingleNode(
583 BSTR p, IXMLDOMNode** outNode)
585 domtext *This = impl_from_IXMLDOMText( iface );
586 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
587 return node_select_singlenode(&This->node, p, outNode);
590 static HRESULT WINAPI domtext_get_parsed(
592 VARIANT_BOOL* isParsed)
594 domtext *This = impl_from_IXMLDOMText( iface );
595 FIXME("(%p)->(%p) stub!\n", This, isParsed);
596 *isParsed = VARIANT_TRUE;
600 static HRESULT WINAPI domtext_get_namespaceURI(
604 domtext *This = impl_from_IXMLDOMText( iface );
605 TRACE("(%p)->(%p)\n", This, p);
606 return node_get_namespaceURI(&This->node, p);
609 static HRESULT WINAPI domtext_get_prefix(
613 domtext *This = impl_from_IXMLDOMText( iface );
614 TRACE("(%p)->(%p)\n", This, prefix);
615 return return_null_bstr( prefix );
618 static HRESULT WINAPI domtext_get_baseName(
622 domtext *This = impl_from_IXMLDOMText( iface );
623 TRACE("(%p)->(%p)\n", This, name);
624 return return_null_bstr( name );
627 static HRESULT WINAPI domtext_transformNodeToObject(
629 IXMLDOMNode* domNode, VARIANT var1)
631 domtext *This = impl_from_IXMLDOMText( iface );
632 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
636 static HRESULT WINAPI domtext_get_data(
640 domtext *This = impl_from_IXMLDOMText( iface );
645 *p = bstr_from_xmlChar(This->node.node->content);
649 static HRESULT WINAPI domtext_put_data(
653 domtext *This = impl_from_IXMLDOMText( iface );
656 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
658 V_VT(&val) = VT_BSTR;
660 return node_put_value(&This->node, &val);
663 static HRESULT WINAPI domtext_get_length(
667 domtext *This = impl_from_IXMLDOMText( iface );
671 TRACE("(%p)->(%p)\n", This, len);
676 hr = IXMLDOMText_get_data(iface, &data);
679 *len = SysStringLen(data);
686 static HRESULT WINAPI domtext_substringData(
688 LONG offset, LONG count, BSTR *p)
690 domtext *This = impl_from_IXMLDOMText( iface );
694 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
700 if(offset < 0 || count < 0)
706 hr = IXMLDOMText_get_data(iface, &data);
709 LONG len = SysStringLen(data);
713 if(offset + count > len)
714 *p = SysAllocString(&data[offset]);
716 *p = SysAllocStringLen(&data[offset], count);
727 static HRESULT WINAPI domtext_appendData(
731 domtext *This = impl_from_IXMLDOMText( iface );
736 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
738 /* Nothing to do if NULL or an Empty string passed in. */
739 if((p_len = SysStringLen(p)) == 0) return S_OK;
741 hr = IXMLDOMText_get_data(iface, &data);
744 LONG len = SysStringLen(data);
745 BSTR str = SysAllocStringLen(NULL, p_len + len);
747 memcpy(str, data, len*sizeof(WCHAR));
748 memcpy(&str[len], p, p_len*sizeof(WCHAR));
751 hr = IXMLDOMText_put_data(iface, str);
760 static HRESULT WINAPI domtext_insertData(
764 domtext *This = impl_from_IXMLDOMText( iface );
769 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
771 /* If have a NULL or empty string, don't do anything. */
772 if((p_len = SysStringLen(p)) == 0)
780 hr = IXMLDOMText_get_data(iface, &data);
783 LONG len = SysStringLen(data);
792 str = SysAllocStringLen(NULL, len + p_len);
793 /* start part, supplied string and end part */
794 memcpy(str, data, offset*sizeof(WCHAR));
795 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
796 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
799 hr = IXMLDOMText_put_data(iface, str);
808 static HRESULT WINAPI domtext_deleteData(
810 LONG offset, LONG count)
816 TRACE("(%p)->(%d %d)\n", iface, offset, count);
818 hr = IXMLDOMText_get_length(iface, &len);
819 if(hr != S_OK) return hr;
821 if((offset < 0) || (offset > len) || (count < 0))
824 if(len == 0) return S_OK;
826 /* cutting start or end */
827 if((offset == 0) || ((count + offset) >= len))
830 IXMLDOMText_substringData(iface, count, len - count, &str);
832 IXMLDOMText_substringData(iface, 0, offset, &str);
833 hr = IXMLDOMText_put_data(iface, str);
836 /* cutting from the inside */
840 IXMLDOMText_substringData(iface, 0, offset, &str);
841 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
843 hr = IXMLDOMText_put_data(iface, str);
845 hr = IXMLDOMText_appendData(iface, str_end);
847 SysFreeString(str_end);
855 static HRESULT WINAPI domtext_replaceData(
857 LONG offset, LONG count, BSTR p)
859 domtext *This = impl_from_IXMLDOMText( iface );
862 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
864 hr = IXMLDOMText_deleteData(iface, offset, count);
867 hr = IXMLDOMText_insertData(iface, offset, p);
872 static HRESULT WINAPI domtext_splitText(
874 LONG offset, IXMLDOMText **txtNode)
876 domtext *This = impl_from_IXMLDOMText( iface );
879 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
881 if (!txtNode || offset < 0) return E_INVALIDARG;
885 IXMLDOMText_get_length(iface, &length);
887 if (offset > length) return E_INVALIDARG;
888 if (offset == length) return S_FALSE;
890 FIXME("adjacent text nodes are not supported\n");
895 static const struct IXMLDOMTextVtbl domtext_vtbl =
897 domtext_QueryInterface,
900 domtext_GetTypeInfoCount,
902 domtext_GetIDsOfNames,
904 domtext_get_nodeName,
905 domtext_get_nodeValue,
906 domtext_put_nodeValue,
907 domtext_get_nodeType,
908 domtext_get_parentNode,
909 domtext_get_childNodes,
910 domtext_get_firstChild,
911 domtext_get_lastChild,
912 domtext_get_previousSibling,
913 domtext_get_nextSibling,
914 domtext_get_attributes,
915 domtext_insertBefore,
916 domtext_replaceChild,
919 domtext_hasChildNodes,
920 domtext_get_ownerDocument,
922 domtext_get_nodeTypeString,
925 domtext_get_specified,
926 domtext_get_definition,
927 domtext_get_nodeTypedValue,
928 domtext_put_nodeTypedValue,
929 domtext_get_dataType,
930 domtext_put_dataType,
932 domtext_transformNode,
934 domtext_selectSingleNode,
936 domtext_get_namespaceURI,
938 domtext_get_baseName,
939 domtext_transformNodeToObject,
943 domtext_substringData,
951 IUnknown* create_text( xmlNodePtr text )
955 This = heap_alloc( sizeof *This );
959 This->IXMLDOMText_iface.lpVtbl = &domtext_vtbl;
962 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMText_iface, NULL);
964 return (IUnknown*)&This->IXMLDOMText_iface;