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 IXMLDOMText IXMLDOMText_iface;
48 static inline domtext *impl_from_IXMLDOMText( IXMLDOMText *iface )
50 return CONTAINING_RECORD(iface, domtext, IXMLDOMText_iface);
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_IXMLDOMNode ) ||
64 IsEqualGUID( riid, &IID_IDispatch ) ||
65 IsEqualGUID( riid, &IID_IUnknown ) )
69 else if(node_query_interface(&This->node, riid, ppvObject))
71 return *ppvObject ? S_OK : E_NOINTERFACE;
73 else if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
74 IsEqualGUID( riid, &IID_IXMLDOMCDATASection ) )
76 /* IXMLDOMText is known to be correct in not implementing these */
77 TRACE("Unsupported interface\n");
82 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
86 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
90 static ULONG WINAPI domtext_AddRef(
93 domtext *This = impl_from_IXMLDOMText( iface );
94 return InterlockedIncrement( &This->ref );
97 static ULONG WINAPI domtext_Release(
100 domtext *This = impl_from_IXMLDOMText( iface );
103 ref = InterlockedDecrement( &This->ref );
106 destroy_xmlnode(&This->node);
113 static HRESULT WINAPI domtext_GetTypeInfoCount(
117 domtext *This = impl_from_IXMLDOMText( iface );
119 TRACE("(%p)->(%p)\n", This, pctinfo);
126 static HRESULT WINAPI domtext_GetTypeInfo(
128 UINT iTInfo, LCID lcid,
129 ITypeInfo** ppTInfo )
131 domtext *This = impl_from_IXMLDOMText( iface );
134 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
136 hr = get_typeinfo(IXMLDOMText_tid, ppTInfo);
141 static HRESULT WINAPI domtext_GetIDsOfNames(
143 REFIID riid, LPOLESTR* rgszNames,
144 UINT cNames, LCID lcid, DISPID* rgDispId )
146 domtext *This = impl_from_IXMLDOMText( iface );
150 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
153 if(!rgszNames || cNames == 0 || !rgDispId)
156 hr = get_typeinfo(IXMLDOMText_tid, &typeinfo);
159 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
160 ITypeInfo_Release(typeinfo);
166 static HRESULT WINAPI domtext_Invoke(
168 DISPID dispIdMember, REFIID riid, LCID lcid,
169 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
170 EXCEPINFO* pExcepInfo, UINT* puArgErr )
172 domtext *This = impl_from_IXMLDOMText( iface );
176 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
177 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
179 hr = get_typeinfo(IXMLDOMText_tid, &typeinfo);
182 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMText_iface, dispIdMember, wFlags, pDispParams,
183 pVarResult, pExcepInfo, puArgErr);
184 ITypeInfo_Release(typeinfo);
190 static HRESULT WINAPI domtext_get_nodeName(
194 domtext *This = impl_from_IXMLDOMText( iface );
196 static const WCHAR textW[] = {'#','t','e','x','t',0};
198 TRACE("(%p)->(%p)\n", This, p);
200 return return_bstr(textW, p);
203 static HRESULT WINAPI domtext_get_nodeValue(
207 domtext *This = impl_from_IXMLDOMText( iface );
209 TRACE("(%p)->(%p)\n", This, value);
214 V_VT(value) = VT_BSTR;
215 V_BSTR(value) = bstr_from_xmlChar(This->node.node->content);
219 static HRESULT WINAPI domtext_put_nodeValue(
223 domtext *This = impl_from_IXMLDOMText( iface );
225 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
227 return node_put_value(&This->node, &value);
230 static HRESULT WINAPI domtext_get_nodeType(
232 DOMNodeType* domNodeType )
234 domtext *This = impl_from_IXMLDOMText( iface );
236 TRACE("(%p)->(%p)\n", This, domNodeType);
238 *domNodeType = NODE_TEXT;
242 static HRESULT WINAPI domtext_get_parentNode(
244 IXMLDOMNode** parent )
246 domtext *This = impl_from_IXMLDOMText( iface );
248 TRACE("(%p)->(%p)\n", This, parent);
250 return node_get_parent(&This->node, parent);
253 static HRESULT WINAPI domtext_get_childNodes(
255 IXMLDOMNodeList** outList)
257 domtext *This = impl_from_IXMLDOMText( iface );
259 TRACE("(%p)->(%p)\n", This, outList);
261 return node_get_child_nodes(&This->node, outList);
264 static HRESULT WINAPI domtext_get_firstChild(
266 IXMLDOMNode** domNode)
268 domtext *This = impl_from_IXMLDOMText( iface );
270 TRACE("(%p)->(%p)\n", This, domNode);
272 return return_null_node(domNode);
275 static HRESULT WINAPI domtext_get_lastChild(
277 IXMLDOMNode** domNode)
279 domtext *This = impl_from_IXMLDOMText( iface );
281 TRACE("(%p)->(%p)\n", This, domNode);
283 return return_null_node(domNode);
286 static HRESULT WINAPI domtext_get_previousSibling(
288 IXMLDOMNode** domNode)
290 domtext *This = impl_from_IXMLDOMText( iface );
292 TRACE("(%p)->(%p)\n", This, domNode);
294 return node_get_previous_sibling(&This->node, domNode);
297 static HRESULT WINAPI domtext_get_nextSibling(
299 IXMLDOMNode** domNode)
301 domtext *This = impl_from_IXMLDOMText( iface );
303 TRACE("(%p)->(%p)\n", This, domNode);
305 return node_get_next_sibling(&This->node, domNode);
308 static HRESULT WINAPI domtext_get_attributes(
310 IXMLDOMNamedNodeMap** attributeMap)
312 domtext *This = impl_from_IXMLDOMText( iface );
314 TRACE("(%p)->(%p)\n", This, attributeMap);
316 return return_null_ptr((void**)attributeMap);
319 static HRESULT WINAPI domtext_insertBefore(
321 IXMLDOMNode* newNode, VARIANT refChild,
322 IXMLDOMNode** outOldNode)
324 domtext *This = impl_from_IXMLDOMText( iface );
326 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
328 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
331 static HRESULT WINAPI domtext_replaceChild(
333 IXMLDOMNode* newNode,
334 IXMLDOMNode* oldNode,
335 IXMLDOMNode** outOldNode)
337 domtext *This = impl_from_IXMLDOMText( iface );
339 FIXME("(%p)->(%p %p %p) needs test\n", This, newNode, oldNode, outOldNode);
341 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
344 static HRESULT WINAPI domtext_removeChild(
346 IXMLDOMNode *child, IXMLDOMNode **oldChild)
348 domtext *This = impl_from_IXMLDOMText( iface );
349 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
350 return node_remove_child(&This->node, child, oldChild);
353 static HRESULT WINAPI domtext_appendChild(
355 IXMLDOMNode *child, IXMLDOMNode **outChild)
357 domtext *This = impl_from_IXMLDOMText( iface );
358 TRACE("(%p)->(%p %p)\n", This, child, outChild);
359 return node_append_child(&This->node, child, outChild);
362 static HRESULT WINAPI domtext_hasChildNodes(
366 domtext *This = impl_from_IXMLDOMText( iface );
367 return IXMLDOMNode_hasChildNodes( &This->node.IXMLDOMNode_iface, pbool );
370 static HRESULT WINAPI domtext_get_ownerDocument(
372 IXMLDOMDocument** domDocument)
374 domtext *This = impl_from_IXMLDOMText( iface );
375 return IXMLDOMNode_get_ownerDocument( &This->node.IXMLDOMNode_iface, domDocument );
378 static HRESULT WINAPI domtext_cloneNode(
380 VARIANT_BOOL deep, IXMLDOMNode** outNode)
382 domtext *This = impl_from_IXMLDOMText( iface );
383 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
384 return node_clone( &This->node, deep, outNode );
387 static HRESULT WINAPI domtext_get_nodeTypeString(
391 domtext *This = impl_from_IXMLDOMText( iface );
392 static const WCHAR textW[] = {'t','e','x','t',0};
394 TRACE("(%p)->(%p)\n", This, p);
396 return return_bstr(textW, p);
399 static HRESULT WINAPI domtext_get_text(
403 domtext *This = impl_from_IXMLDOMText( iface );
404 return IXMLDOMNode_get_text( &This->node.IXMLDOMNode_iface, p );
407 static HRESULT WINAPI domtext_put_text(
411 domtext *This = impl_from_IXMLDOMText( iface );
412 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
413 return node_put_text( &This->node, p );
416 static HRESULT WINAPI domtext_get_specified(
418 VARIANT_BOOL* isSpecified)
420 domtext *This = impl_from_IXMLDOMText( iface );
421 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
422 *isSpecified = VARIANT_TRUE;
426 static HRESULT WINAPI domtext_get_definition(
428 IXMLDOMNode** definitionNode)
430 domtext *This = impl_from_IXMLDOMText( iface );
431 FIXME("(%p)->(%p)\n", This, definitionNode);
435 static HRESULT WINAPI domtext_get_nodeTypedValue(
439 domtext *This = impl_from_IXMLDOMText( iface );
440 IXMLDOMNode* parent = NULL;
443 TRACE("(%p)->(%p)\n", This, var1);
448 hr = domtext_get_parentNode(iface, &parent);
452 hr = IXMLDOMNode_get_nodeTypedValue(parent, var1);
453 IXMLDOMNode_Release(parent);
457 V_VT(var1) = VT_NULL;
465 static HRESULT WINAPI domtext_put_nodeTypedValue(
469 domtext *This = impl_from_IXMLDOMText( iface );
470 IXMLDOMNode* parent = NULL;
473 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
475 hr = domtext_get_parentNode(iface, &parent);
479 hr = IXMLDOMNode_put_nodeTypedValue(parent, value);
480 IXMLDOMNode_Release(parent);
490 static HRESULT WINAPI domtext_get_dataType(
494 domtext *This = impl_from_IXMLDOMText( iface );
495 IXMLDOMNode* parent = NULL;
498 TRACE("(%p)->(%p)\n", This, dtName);
503 hr = domtext_get_parentNode(iface, &parent);
507 hr = IXMLDOMNode_get_dataType(parent, dtName);
508 IXMLDOMNode_Release(parent);
512 V_VT(dtName) = VT_NULL;
513 V_BSTR(dtName) = NULL;
520 static HRESULT WINAPI domtext_put_dataType(
524 domtext *This = impl_from_IXMLDOMText( iface );
525 IXMLDOMNode* parent = NULL;
528 TRACE("(%p)->(%p)\n", This, dtName);
533 hr = domtext_get_parentNode(iface, &parent);
537 hr = IXMLDOMNode_put_dataType(parent, dtName);
538 IXMLDOMNode_Release(parent);
548 static HRESULT WINAPI domtext_get_xml(
552 domtext *This = impl_from_IXMLDOMText( iface );
554 TRACE("(%p)->(%p)\n", This, p);
556 return node_get_xml(&This->node, FALSE, FALSE, p);
559 static HRESULT WINAPI domtext_transformNode(
561 IXMLDOMNode* domNode, BSTR* p)
563 domtext *This = impl_from_IXMLDOMText( iface );
564 return IXMLDOMNode_transformNode( &This->node.IXMLDOMNode_iface, domNode, p );
567 static HRESULT WINAPI domtext_selectNodes(
569 BSTR p, IXMLDOMNodeList** outList)
571 domtext *This = impl_from_IXMLDOMText( iface );
572 return IXMLDOMNode_selectNodes( &This->node.IXMLDOMNode_iface, p, outList );
575 static HRESULT WINAPI domtext_selectSingleNode(
577 BSTR p, IXMLDOMNode** outNode)
579 domtext *This = impl_from_IXMLDOMText( iface );
580 return IXMLDOMNode_selectSingleNode( &This->node.IXMLDOMNode_iface, p, outNode );
583 static HRESULT WINAPI domtext_get_parsed(
585 VARIANT_BOOL* isParsed)
587 domtext *This = impl_from_IXMLDOMText( iface );
588 FIXME("(%p)->(%p) stub!\n", This, isParsed);
589 *isParsed = VARIANT_TRUE;
593 static HRESULT WINAPI domtext_get_namespaceURI(
597 domtext *This = impl_from_IXMLDOMText( iface );
598 TRACE("(%p)->(%p)\n", This, p);
599 return node_get_namespaceURI(&This->node, p);
602 static HRESULT WINAPI domtext_get_prefix(
606 domtext *This = impl_from_IXMLDOMText( iface );
607 TRACE("(%p)->(%p)\n", This, prefix);
608 return return_null_bstr( prefix );
611 static HRESULT WINAPI domtext_get_baseName(
615 domtext *This = impl_from_IXMLDOMText( iface );
616 TRACE("(%p)->(%p)\n", This, name);
617 return return_null_bstr( name );
620 static HRESULT WINAPI domtext_transformNodeToObject(
622 IXMLDOMNode* domNode, VARIANT var1)
624 domtext *This = impl_from_IXMLDOMText( iface );
625 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
629 static HRESULT WINAPI domtext_get_data(
633 domtext *This = impl_from_IXMLDOMText( iface );
638 *p = bstr_from_xmlChar(This->node.node->content);
642 static HRESULT WINAPI domtext_put_data(
646 domtext *This = impl_from_IXMLDOMText( iface );
649 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
651 V_VT(&val) = VT_BSTR;
653 return node_put_value(&This->node, &val);
656 static HRESULT WINAPI domtext_get_length(
660 domtext *This = impl_from_IXMLDOMText( iface );
664 TRACE("(%p)->(%p)\n", This, len);
669 hr = IXMLDOMText_get_data(iface, &data);
672 *len = SysStringLen(data);
679 static HRESULT WINAPI domtext_substringData(
681 LONG offset, LONG count, BSTR *p)
683 domtext *This = impl_from_IXMLDOMText( iface );
687 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
693 if(offset < 0 || count < 0)
699 hr = IXMLDOMText_get_data(iface, &data);
702 LONG len = SysStringLen(data);
706 if(offset + count > len)
707 *p = SysAllocString(&data[offset]);
709 *p = SysAllocStringLen(&data[offset], count);
720 static HRESULT WINAPI domtext_appendData(
724 domtext *This = impl_from_IXMLDOMText( iface );
729 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
731 /* Nothing to do if NULL or an Empty string passed in. */
732 if((p_len = SysStringLen(p)) == 0) return S_OK;
734 hr = IXMLDOMText_get_data(iface, &data);
737 LONG len = SysStringLen(data);
738 BSTR str = SysAllocStringLen(NULL, p_len + len);
740 memcpy(str, data, len*sizeof(WCHAR));
741 memcpy(&str[len], p, p_len*sizeof(WCHAR));
744 hr = IXMLDOMText_put_data(iface, str);
753 static HRESULT WINAPI domtext_insertData(
757 domtext *This = impl_from_IXMLDOMText( iface );
762 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
764 /* If have a NULL or empty string, don't do anything. */
765 if((p_len = SysStringLen(p)) == 0)
773 hr = IXMLDOMText_get_data(iface, &data);
776 LONG len = SysStringLen(data);
785 str = SysAllocStringLen(NULL, len + p_len);
786 /* start part, supplied string and end part */
787 memcpy(str, data, offset*sizeof(WCHAR));
788 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
789 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
792 hr = IXMLDOMText_put_data(iface, str);
801 static HRESULT WINAPI domtext_deleteData(
803 LONG offset, LONG count)
809 TRACE("(%p)->(%d %d)\n", iface, offset, count);
811 hr = IXMLDOMText_get_length(iface, &len);
812 if(hr != S_OK) return hr;
814 if((offset < 0) || (offset > len) || (count < 0))
817 if(len == 0) return S_OK;
819 /* cutting start or end */
820 if((offset == 0) || ((count + offset) >= len))
823 IXMLDOMText_substringData(iface, count, len - count, &str);
825 IXMLDOMText_substringData(iface, 0, offset, &str);
826 hr = IXMLDOMText_put_data(iface, str);
829 /* cutting from the inside */
833 IXMLDOMText_substringData(iface, 0, offset, &str);
834 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
836 hr = IXMLDOMText_put_data(iface, str);
838 hr = IXMLDOMText_appendData(iface, str_end);
840 SysFreeString(str_end);
848 static HRESULT WINAPI domtext_replaceData(
850 LONG offset, LONG count, BSTR p)
852 domtext *This = impl_from_IXMLDOMText( iface );
855 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
857 hr = IXMLDOMText_deleteData(iface, offset, count);
860 hr = IXMLDOMText_insertData(iface, offset, p);
865 static HRESULT WINAPI domtext_splitText(
867 LONG offset, IXMLDOMText **txtNode)
869 domtext *This = impl_from_IXMLDOMText( iface );
872 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
874 if (!txtNode || offset < 0) return E_INVALIDARG;
878 IXMLDOMText_get_length(iface, &length);
880 if (offset > length) return E_INVALIDARG;
881 if (offset == length) return S_FALSE;
883 FIXME("adjacent text nodes are not supported\n");
888 static const struct IXMLDOMTextVtbl domtext_vtbl =
890 domtext_QueryInterface,
893 domtext_GetTypeInfoCount,
895 domtext_GetIDsOfNames,
897 domtext_get_nodeName,
898 domtext_get_nodeValue,
899 domtext_put_nodeValue,
900 domtext_get_nodeType,
901 domtext_get_parentNode,
902 domtext_get_childNodes,
903 domtext_get_firstChild,
904 domtext_get_lastChild,
905 domtext_get_previousSibling,
906 domtext_get_nextSibling,
907 domtext_get_attributes,
908 domtext_insertBefore,
909 domtext_replaceChild,
912 domtext_hasChildNodes,
913 domtext_get_ownerDocument,
915 domtext_get_nodeTypeString,
918 domtext_get_specified,
919 domtext_get_definition,
920 domtext_get_nodeTypedValue,
921 domtext_put_nodeTypedValue,
922 domtext_get_dataType,
923 domtext_put_dataType,
925 domtext_transformNode,
927 domtext_selectSingleNode,
929 domtext_get_namespaceURI,
931 domtext_get_baseName,
932 domtext_transformNodeToObject,
936 domtext_substringData,
944 IUnknown* create_text( xmlNodePtr text )
948 This = heap_alloc( sizeof *This );
952 This->IXMLDOMText_iface.lpVtbl = &domtext_vtbl;
955 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMText_iface, NULL);
957 return (IUnknown*)&This->IXMLDOMText_iface;