msxml3: Remove get_ownerDocument() forward.
[wine/multimedia.git] / dlls / msxml3 / text.c
blobc57428f5d222fb43e665eb6eb9ac836e9e382781
1 /*
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
22 #define COBJMACROS
24 #include "config.h"
26 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "msxml6.h"
33 #include "msxml_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
39 #ifdef HAVE_LIBXML2
41 typedef struct _domtext
43 xmlnode node;
44 IXMLDOMText IXMLDOMText_iface;
45 LONG ref;
46 } domtext;
48 static inline domtext *impl_from_IXMLDOMText( IXMLDOMText *iface )
50 return CONTAINING_RECORD(iface, domtext, IXMLDOMText_iface);
53 static HRESULT WINAPI domtext_QueryInterface(
54 IXMLDOMText *iface,
55 REFIID riid,
56 void** ppvObject )
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 ) )
67 *ppvObject = iface;
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");
78 return E_NOINTERFACE;
80 else
82 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
83 return E_NOINTERFACE;
86 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
87 return S_OK;
90 static ULONG WINAPI domtext_AddRef(
91 IXMLDOMText *iface )
93 domtext *This = impl_from_IXMLDOMText( iface );
94 return InterlockedIncrement( &This->ref );
97 static ULONG WINAPI domtext_Release(
98 IXMLDOMText *iface )
100 domtext *This = impl_from_IXMLDOMText( iface );
101 ULONG ref;
103 ref = InterlockedDecrement( &This->ref );
104 if ( ref == 0 )
106 destroy_xmlnode(&This->node);
107 heap_free( This );
110 return ref;
113 static HRESULT WINAPI domtext_GetTypeInfoCount(
114 IXMLDOMText *iface,
115 UINT* pctinfo )
117 domtext *This = impl_from_IXMLDOMText( iface );
119 TRACE("(%p)->(%p)\n", This, pctinfo);
121 *pctinfo = 1;
123 return S_OK;
126 static HRESULT WINAPI domtext_GetTypeInfo(
127 IXMLDOMText *iface,
128 UINT iTInfo, LCID lcid,
129 ITypeInfo** ppTInfo )
131 domtext *This = impl_from_IXMLDOMText( iface );
132 HRESULT hr;
134 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
136 hr = get_typeinfo(IXMLDOMText_tid, ppTInfo);
138 return hr;
141 static HRESULT WINAPI domtext_GetIDsOfNames(
142 IXMLDOMText *iface,
143 REFIID riid, LPOLESTR* rgszNames,
144 UINT cNames, LCID lcid, DISPID* rgDispId )
146 domtext *This = impl_from_IXMLDOMText( iface );
147 ITypeInfo *typeinfo;
148 HRESULT hr;
150 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
151 lcid, rgDispId);
153 if(!rgszNames || cNames == 0 || !rgDispId)
154 return E_INVALIDARG;
156 hr = get_typeinfo(IXMLDOMText_tid, &typeinfo);
157 if(SUCCEEDED(hr))
159 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
160 ITypeInfo_Release(typeinfo);
163 return hr;
166 static HRESULT WINAPI domtext_Invoke(
167 IXMLDOMText *iface,
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 );
173 ITypeInfo *typeinfo;
174 HRESULT hr;
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);
180 if(SUCCEEDED(hr))
182 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMText_iface, dispIdMember, wFlags, pDispParams,
183 pVarResult, pExcepInfo, puArgErr);
184 ITypeInfo_Release(typeinfo);
187 return hr;
190 static HRESULT WINAPI domtext_get_nodeName(
191 IXMLDOMText *iface,
192 BSTR* p )
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(
204 IXMLDOMText *iface,
205 VARIANT* value )
207 domtext *This = impl_from_IXMLDOMText( iface );
209 TRACE("(%p)->(%p)\n", This, value);
211 if(!value)
212 return E_INVALIDARG;
214 V_VT(value) = VT_BSTR;
215 V_BSTR(value) = bstr_from_xmlChar(This->node.node->content);
216 return S_OK;
219 static HRESULT WINAPI domtext_put_nodeValue(
220 IXMLDOMText *iface,
221 VARIANT value)
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(
231 IXMLDOMText *iface,
232 DOMNodeType* domNodeType )
234 domtext *This = impl_from_IXMLDOMText( iface );
236 TRACE("(%p)->(%p)\n", This, domNodeType);
238 *domNodeType = NODE_TEXT;
239 return S_OK;
242 static HRESULT WINAPI domtext_get_parentNode(
243 IXMLDOMText *iface,
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(
254 IXMLDOMText *iface,
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(
265 IXMLDOMText *iface,
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(
276 IXMLDOMText *iface,
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(
287 IXMLDOMText *iface,
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(
298 IXMLDOMText *iface,
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(
309 IXMLDOMText *iface,
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(
320 IXMLDOMText *iface,
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(
332 IXMLDOMText *iface,
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(
345 IXMLDOMText *iface,
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(
354 IXMLDOMText *iface,
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(
363 IXMLDOMText *iface,
364 VARIANT_BOOL *ret)
366 domtext *This = impl_from_IXMLDOMText( iface );
367 TRACE("(%p)->(%p)\n", This, ret);
368 return node_has_childnodes(&This->node, ret);
371 static HRESULT WINAPI domtext_get_ownerDocument(
372 IXMLDOMText *iface,
373 IXMLDOMDocument **doc)
375 domtext *This = impl_from_IXMLDOMText( iface );
376 TRACE("(%p)->(%p)\n", This, doc);
377 return node_get_owner_doc(&This->node, doc);
380 static HRESULT WINAPI domtext_cloneNode(
381 IXMLDOMText *iface,
382 VARIANT_BOOL deep, IXMLDOMNode** outNode)
384 domtext *This = impl_from_IXMLDOMText( iface );
385 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
386 return node_clone( &This->node, deep, outNode );
389 static HRESULT WINAPI domtext_get_nodeTypeString(
390 IXMLDOMText *iface,
391 BSTR* p)
393 domtext *This = impl_from_IXMLDOMText( iface );
394 static const WCHAR textW[] = {'t','e','x','t',0};
396 TRACE("(%p)->(%p)\n", This, p);
398 return return_bstr(textW, p);
401 static HRESULT WINAPI domtext_get_text(
402 IXMLDOMText *iface,
403 BSTR* p)
405 domtext *This = impl_from_IXMLDOMText( iface );
406 return IXMLDOMNode_get_text( &This->node.IXMLDOMNode_iface, p );
409 static HRESULT WINAPI domtext_put_text(
410 IXMLDOMText *iface,
411 BSTR p)
413 domtext *This = impl_from_IXMLDOMText( iface );
414 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
415 return node_put_text( &This->node, p );
418 static HRESULT WINAPI domtext_get_specified(
419 IXMLDOMText *iface,
420 VARIANT_BOOL* isSpecified)
422 domtext *This = impl_from_IXMLDOMText( iface );
423 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
424 *isSpecified = VARIANT_TRUE;
425 return S_OK;
428 static HRESULT WINAPI domtext_get_definition(
429 IXMLDOMText *iface,
430 IXMLDOMNode** definitionNode)
432 domtext *This = impl_from_IXMLDOMText( iface );
433 FIXME("(%p)->(%p)\n", This, definitionNode);
434 return E_NOTIMPL;
437 static HRESULT WINAPI domtext_get_nodeTypedValue(
438 IXMLDOMText *iface,
439 VARIANT* var1)
441 domtext *This = impl_from_IXMLDOMText( iface );
442 IXMLDOMNode* parent = NULL;
443 HRESULT hr;
445 TRACE("(%p)->(%p)\n", This, var1);
447 if (!var1)
448 return E_INVALIDARG;
450 hr = domtext_get_parentNode(iface, &parent);
452 if (hr == S_OK)
454 hr = IXMLDOMNode_get_nodeTypedValue(parent, var1);
455 IXMLDOMNode_Release(parent);
457 else
459 V_VT(var1) = VT_NULL;
460 V_BSTR(var1) = NULL;
461 hr = S_FALSE;
464 return hr;
467 static HRESULT WINAPI domtext_put_nodeTypedValue(
468 IXMLDOMText *iface,
469 VARIANT value)
471 domtext *This = impl_from_IXMLDOMText( iface );
472 IXMLDOMNode* parent = NULL;
473 HRESULT hr;
475 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
477 hr = domtext_get_parentNode(iface, &parent);
479 if (hr == S_OK)
481 hr = IXMLDOMNode_put_nodeTypedValue(parent, value);
482 IXMLDOMNode_Release(parent);
484 else
486 hr = S_FALSE;
489 return hr;
492 static HRESULT WINAPI domtext_get_dataType(
493 IXMLDOMText *iface,
494 VARIANT* dtName)
496 domtext *This = impl_from_IXMLDOMText( iface );
497 IXMLDOMNode* parent = NULL;
498 HRESULT hr;
500 TRACE("(%p)->(%p)\n", This, dtName);
502 if (!dtName)
503 return E_INVALIDARG;
505 hr = domtext_get_parentNode(iface, &parent);
507 if (hr == S_OK)
509 hr = IXMLDOMNode_get_dataType(parent, dtName);
510 IXMLDOMNode_Release(parent);
512 else
514 V_VT(dtName) = VT_NULL;
515 V_BSTR(dtName) = NULL;
516 hr = S_FALSE;
519 return hr;
522 static HRESULT WINAPI domtext_put_dataType(
523 IXMLDOMText *iface,
524 BSTR dtName)
526 domtext *This = impl_from_IXMLDOMText( iface );
527 IXMLDOMNode* parent = NULL;
528 HRESULT hr;
530 TRACE("(%p)->(%p)\n", This, dtName);
532 if (!dtName)
533 return E_INVALIDARG;
535 hr = domtext_get_parentNode(iface, &parent);
537 if (hr == S_OK)
539 hr = IXMLDOMNode_put_dataType(parent, dtName);
540 IXMLDOMNode_Release(parent);
542 else
544 hr = S_FALSE;
547 return hr;
550 static HRESULT WINAPI domtext_get_xml(
551 IXMLDOMText *iface,
552 BSTR* p)
554 domtext *This = impl_from_IXMLDOMText( iface );
556 TRACE("(%p)->(%p)\n", This, p);
558 return node_get_xml(&This->node, FALSE, FALSE, p);
561 static HRESULT WINAPI domtext_transformNode(
562 IXMLDOMText *iface,
563 IXMLDOMNode* domNode, BSTR* p)
565 domtext *This = impl_from_IXMLDOMText( iface );
566 return IXMLDOMNode_transformNode( &This->node.IXMLDOMNode_iface, domNode, p );
569 static HRESULT WINAPI domtext_selectNodes(
570 IXMLDOMText *iface,
571 BSTR p, IXMLDOMNodeList** outList)
573 domtext *This = impl_from_IXMLDOMText( iface );
574 return IXMLDOMNode_selectNodes( &This->node.IXMLDOMNode_iface, p, outList );
577 static HRESULT WINAPI domtext_selectSingleNode(
578 IXMLDOMText *iface,
579 BSTR p, IXMLDOMNode** outNode)
581 domtext *This = impl_from_IXMLDOMText( iface );
582 return IXMLDOMNode_selectSingleNode( &This->node.IXMLDOMNode_iface, p, outNode );
585 static HRESULT WINAPI domtext_get_parsed(
586 IXMLDOMText *iface,
587 VARIANT_BOOL* isParsed)
589 domtext *This = impl_from_IXMLDOMText( iface );
590 FIXME("(%p)->(%p) stub!\n", This, isParsed);
591 *isParsed = VARIANT_TRUE;
592 return S_OK;
595 static HRESULT WINAPI domtext_get_namespaceURI(
596 IXMLDOMText *iface,
597 BSTR* p)
599 domtext *This = impl_from_IXMLDOMText( iface );
600 TRACE("(%p)->(%p)\n", This, p);
601 return node_get_namespaceURI(&This->node, p);
604 static HRESULT WINAPI domtext_get_prefix(
605 IXMLDOMText *iface,
606 BSTR* prefix)
608 domtext *This = impl_from_IXMLDOMText( iface );
609 TRACE("(%p)->(%p)\n", This, prefix);
610 return return_null_bstr( prefix );
613 static HRESULT WINAPI domtext_get_baseName(
614 IXMLDOMText *iface,
615 BSTR* name)
617 domtext *This = impl_from_IXMLDOMText( iface );
618 TRACE("(%p)->(%p)\n", This, name);
619 return return_null_bstr( name );
622 static HRESULT WINAPI domtext_transformNodeToObject(
623 IXMLDOMText *iface,
624 IXMLDOMNode* domNode, VARIANT var1)
626 domtext *This = impl_from_IXMLDOMText( iface );
627 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
628 return E_NOTIMPL;
631 static HRESULT WINAPI domtext_get_data(
632 IXMLDOMText *iface,
633 BSTR *p)
635 domtext *This = impl_from_IXMLDOMText( iface );
637 if(!p)
638 return E_INVALIDARG;
640 *p = bstr_from_xmlChar(This->node.node->content);
641 return S_OK;
644 static HRESULT WINAPI domtext_put_data(
645 IXMLDOMText *iface,
646 BSTR data)
648 domtext *This = impl_from_IXMLDOMText( iface );
649 VARIANT val;
651 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
653 V_VT(&val) = VT_BSTR;
654 V_BSTR(&val) = data;
655 return node_put_value(&This->node, &val);
658 static HRESULT WINAPI domtext_get_length(
659 IXMLDOMText *iface,
660 LONG *len)
662 domtext *This = impl_from_IXMLDOMText( iface );
663 HRESULT hr;
664 BSTR data;
666 TRACE("(%p)->(%p)\n", This, len);
668 if(!len)
669 return E_INVALIDARG;
671 hr = IXMLDOMText_get_data(iface, &data);
672 if(hr == S_OK)
674 *len = SysStringLen(data);
675 SysFreeString(data);
678 return hr;
681 static HRESULT WINAPI domtext_substringData(
682 IXMLDOMText *iface,
683 LONG offset, LONG count, BSTR *p)
685 domtext *This = impl_from_IXMLDOMText( iface );
686 HRESULT hr;
687 BSTR data;
689 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
691 if(!p)
692 return E_INVALIDARG;
694 *p = NULL;
695 if(offset < 0 || count < 0)
696 return E_INVALIDARG;
698 if(count == 0)
699 return S_FALSE;
701 hr = IXMLDOMText_get_data(iface, &data);
702 if(hr == S_OK)
704 LONG len = SysStringLen(data);
706 if(offset < len)
708 if(offset + count > len)
709 *p = SysAllocString(&data[offset]);
710 else
711 *p = SysAllocStringLen(&data[offset], count);
713 else
714 hr = S_FALSE;
716 SysFreeString(data);
719 return hr;
722 static HRESULT WINAPI domtext_appendData(
723 IXMLDOMText *iface,
724 BSTR p)
726 domtext *This = impl_from_IXMLDOMText( iface );
727 HRESULT hr;
728 BSTR data;
729 LONG p_len;
731 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
733 /* Nothing to do if NULL or an Empty string passed in. */
734 if((p_len = SysStringLen(p)) == 0) return S_OK;
736 hr = IXMLDOMText_get_data(iface, &data);
737 if(hr == S_OK)
739 LONG len = SysStringLen(data);
740 BSTR str = SysAllocStringLen(NULL, p_len + len);
742 memcpy(str, data, len*sizeof(WCHAR));
743 memcpy(&str[len], p, p_len*sizeof(WCHAR));
744 str[len+p_len] = 0;
746 hr = IXMLDOMText_put_data(iface, str);
748 SysFreeString(str);
749 SysFreeString(data);
752 return hr;
755 static HRESULT WINAPI domtext_insertData(
756 IXMLDOMText *iface,
757 LONG offset, BSTR p)
759 domtext *This = impl_from_IXMLDOMText( iface );
760 HRESULT hr;
761 BSTR data;
762 LONG p_len;
764 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
766 /* If have a NULL or empty string, don't do anything. */
767 if((p_len = SysStringLen(p)) == 0)
768 return S_OK;
770 if(offset < 0)
772 return E_INVALIDARG;
775 hr = IXMLDOMText_get_data(iface, &data);
776 if(hr == S_OK)
778 LONG len = SysStringLen(data);
779 BSTR str;
781 if(len < offset)
783 SysFreeString(data);
784 return E_INVALIDARG;
787 str = SysAllocStringLen(NULL, len + p_len);
788 /* start part, supplied string and end part */
789 memcpy(str, data, offset*sizeof(WCHAR));
790 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
791 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
792 str[len+p_len] = 0;
794 hr = IXMLDOMText_put_data(iface, str);
796 SysFreeString(str);
797 SysFreeString(data);
800 return hr;
803 static HRESULT WINAPI domtext_deleteData(
804 IXMLDOMText *iface,
805 LONG offset, LONG count)
807 HRESULT hr;
808 LONG len = -1;
809 BSTR str;
811 TRACE("(%p)->(%d %d)\n", iface, offset, count);
813 hr = IXMLDOMText_get_length(iface, &len);
814 if(hr != S_OK) return hr;
816 if((offset < 0) || (offset > len) || (count < 0))
817 return E_INVALIDARG;
819 if(len == 0) return S_OK;
821 /* cutting start or end */
822 if((offset == 0) || ((count + offset) >= len))
824 if(offset == 0)
825 IXMLDOMText_substringData(iface, count, len - count, &str);
826 else
827 IXMLDOMText_substringData(iface, 0, offset, &str);
828 hr = IXMLDOMText_put_data(iface, str);
830 else
831 /* cutting from the inside */
833 BSTR str_end;
835 IXMLDOMText_substringData(iface, 0, offset, &str);
836 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
838 hr = IXMLDOMText_put_data(iface, str);
839 if(hr == S_OK)
840 hr = IXMLDOMText_appendData(iface, str_end);
842 SysFreeString(str_end);
845 SysFreeString(str);
847 return hr;
850 static HRESULT WINAPI domtext_replaceData(
851 IXMLDOMText *iface,
852 LONG offset, LONG count, BSTR p)
854 domtext *This = impl_from_IXMLDOMText( iface );
855 HRESULT hr;
857 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
859 hr = IXMLDOMText_deleteData(iface, offset, count);
861 if (hr == S_OK)
862 hr = IXMLDOMText_insertData(iface, offset, p);
864 return hr;
867 static HRESULT WINAPI domtext_splitText(
868 IXMLDOMText *iface,
869 LONG offset, IXMLDOMText **txtNode)
871 domtext *This = impl_from_IXMLDOMText( iface );
872 LONG length = 0;
874 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
876 if (!txtNode || offset < 0) return E_INVALIDARG;
878 *txtNode = NULL;
880 IXMLDOMText_get_length(iface, &length);
882 if (offset > length) return E_INVALIDARG;
883 if (offset == length) return S_FALSE;
885 FIXME("adjacent text nodes are not supported\n");
887 return E_NOTIMPL;
890 static const struct IXMLDOMTextVtbl domtext_vtbl =
892 domtext_QueryInterface,
893 domtext_AddRef,
894 domtext_Release,
895 domtext_GetTypeInfoCount,
896 domtext_GetTypeInfo,
897 domtext_GetIDsOfNames,
898 domtext_Invoke,
899 domtext_get_nodeName,
900 domtext_get_nodeValue,
901 domtext_put_nodeValue,
902 domtext_get_nodeType,
903 domtext_get_parentNode,
904 domtext_get_childNodes,
905 domtext_get_firstChild,
906 domtext_get_lastChild,
907 domtext_get_previousSibling,
908 domtext_get_nextSibling,
909 domtext_get_attributes,
910 domtext_insertBefore,
911 domtext_replaceChild,
912 domtext_removeChild,
913 domtext_appendChild,
914 domtext_hasChildNodes,
915 domtext_get_ownerDocument,
916 domtext_cloneNode,
917 domtext_get_nodeTypeString,
918 domtext_get_text,
919 domtext_put_text,
920 domtext_get_specified,
921 domtext_get_definition,
922 domtext_get_nodeTypedValue,
923 domtext_put_nodeTypedValue,
924 domtext_get_dataType,
925 domtext_put_dataType,
926 domtext_get_xml,
927 domtext_transformNode,
928 domtext_selectNodes,
929 domtext_selectSingleNode,
930 domtext_get_parsed,
931 domtext_get_namespaceURI,
932 domtext_get_prefix,
933 domtext_get_baseName,
934 domtext_transformNodeToObject,
935 domtext_get_data,
936 domtext_put_data,
937 domtext_get_length,
938 domtext_substringData,
939 domtext_appendData,
940 domtext_insertData,
941 domtext_deleteData,
942 domtext_replaceData,
943 domtext_splitText
946 IUnknown* create_text( xmlNodePtr text )
948 domtext *This;
950 This = heap_alloc( sizeof *This );
951 if ( !This )
952 return NULL;
954 This->IXMLDOMText_iface.lpVtbl = &domtext_vtbl;
955 This->ref = 1;
957 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMText_iface, NULL);
959 return (IUnknown*)&This->IXMLDOMText_iface;
962 #endif