wined3d: Get rid of the WINED3DSHADER_PARAM_SRCMOD_TYPE typedef.
[wine/multimedia.git] / dlls / msxml3 / text.c
blob9bda6531b8c6eed5a1520cc09baf558c706d60ad
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 #ifdef HAVE_LIBXML2
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
30 #endif
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winuser.h"
35 #include "ole2.h"
36 #include "msxml6.h"
38 #include "msxml_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
44 #ifdef HAVE_LIBXML2
46 typedef struct _domtext
48 xmlnode node;
49 IXMLDOMText IXMLDOMText_iface;
50 LONG ref;
51 } domtext;
53 static inline domtext *impl_from_IXMLDOMText( IXMLDOMText *iface )
55 return CONTAINING_RECORD(iface, domtext, IXMLDOMText_iface);
58 static HRESULT WINAPI domtext_QueryInterface(
59 IXMLDOMText *iface,
60 REFIID riid,
61 void** ppvObject )
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 ) )
72 *ppvObject = iface;
74 else if(node_query_interface(&This->node, riid, ppvObject))
76 return *ppvObject ? S_OK : E_NOINTERFACE;
78 else
80 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
81 *ppvObject = NULL;
82 return E_NOINTERFACE;
85 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
86 return S_OK;
89 static ULONG WINAPI domtext_AddRef(
90 IXMLDOMText *iface )
92 domtext *This = impl_from_IXMLDOMText( iface );
93 ULONG ref = InterlockedIncrement( &This->ref );
94 TRACE("(%p)->(%d)\n", This, ref);
95 return ref;
98 static ULONG WINAPI domtext_Release(
99 IXMLDOMText *iface )
101 domtext *This = impl_from_IXMLDOMText( iface );
102 ULONG ref = InterlockedDecrement( &This->ref );
104 TRACE("(%p)->(%d)\n", This, ref);
105 if ( ref == 0 )
107 destroy_xmlnode(&This->node);
108 heap_free( This );
111 return ref;
114 static HRESULT WINAPI domtext_GetTypeInfoCount(
115 IXMLDOMText *iface,
116 UINT* pctinfo )
118 domtext *This = impl_from_IXMLDOMText( iface );
120 TRACE("(%p)->(%p)\n", This, pctinfo);
122 *pctinfo = 1;
124 return S_OK;
127 static HRESULT WINAPI domtext_GetTypeInfo(
128 IXMLDOMText *iface,
129 UINT iTInfo, LCID lcid,
130 ITypeInfo** ppTInfo )
132 domtext *This = impl_from_IXMLDOMText( iface );
133 HRESULT hr;
135 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
137 hr = get_typeinfo(IXMLDOMText_tid, ppTInfo);
139 return hr;
142 static HRESULT WINAPI domtext_GetIDsOfNames(
143 IXMLDOMText *iface,
144 REFIID riid, LPOLESTR* rgszNames,
145 UINT cNames, LCID lcid, DISPID* rgDispId )
147 domtext *This = impl_from_IXMLDOMText( iface );
148 ITypeInfo *typeinfo;
149 HRESULT hr;
151 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
152 lcid, rgDispId);
154 if(!rgszNames || cNames == 0 || !rgDispId)
155 return E_INVALIDARG;
157 hr = get_typeinfo(IXMLDOMText_tid, &typeinfo);
158 if(SUCCEEDED(hr))
160 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
161 ITypeInfo_Release(typeinfo);
164 return hr;
167 static HRESULT WINAPI domtext_Invoke(
168 IXMLDOMText *iface,
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 );
174 ITypeInfo *typeinfo;
175 HRESULT hr;
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);
181 if(SUCCEEDED(hr))
183 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMText_iface, dispIdMember, wFlags, pDispParams,
184 pVarResult, pExcepInfo, puArgErr);
185 ITypeInfo_Release(typeinfo);
188 return hr;
191 static HRESULT WINAPI domtext_get_nodeName(
192 IXMLDOMText *iface,
193 BSTR* p )
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(
205 IXMLDOMText *iface,
206 VARIANT* value )
208 domtext *This = impl_from_IXMLDOMText( iface );
210 TRACE("(%p)->(%p)\n", This, value);
212 if(!value)
213 return E_INVALIDARG;
215 V_VT(value) = VT_BSTR;
216 V_BSTR(value) = bstr_from_xmlChar(This->node.node->content);
217 return S_OK;
220 static HRESULT WINAPI domtext_put_nodeValue(
221 IXMLDOMText *iface,
222 VARIANT value)
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(
232 IXMLDOMText *iface,
233 DOMNodeType* domNodeType )
235 domtext *This = impl_from_IXMLDOMText( iface );
237 TRACE("(%p)->(%p)\n", This, domNodeType);
239 *domNodeType = NODE_TEXT;
240 return S_OK;
243 static HRESULT WINAPI domtext_get_parentNode(
244 IXMLDOMText *iface,
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(
255 IXMLDOMText *iface,
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(
266 IXMLDOMText *iface,
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(
277 IXMLDOMText *iface,
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(
288 IXMLDOMText *iface,
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(
299 IXMLDOMText *iface,
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(
310 IXMLDOMText *iface,
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(
321 IXMLDOMText *iface,
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(
333 IXMLDOMText *iface,
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(
346 IXMLDOMText *iface,
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(
355 IXMLDOMText *iface,
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(
364 IXMLDOMText *iface,
365 VARIANT_BOOL *ret)
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(
373 IXMLDOMText *iface,
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(
382 IXMLDOMText *iface,
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(
391 IXMLDOMText *iface,
392 BSTR* p)
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(
403 IXMLDOMText *iface,
404 BSTR* p)
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(
412 IXMLDOMText *iface,
413 BSTR p)
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(
421 IXMLDOMText *iface,
422 VARIANT_BOOL* isSpecified)
424 domtext *This = impl_from_IXMLDOMText( iface );
425 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
426 *isSpecified = VARIANT_TRUE;
427 return S_OK;
430 static HRESULT WINAPI domtext_get_definition(
431 IXMLDOMText *iface,
432 IXMLDOMNode** definitionNode)
434 domtext *This = impl_from_IXMLDOMText( iface );
435 FIXME("(%p)->(%p)\n", This, definitionNode);
436 return E_NOTIMPL;
439 static HRESULT WINAPI domtext_get_nodeTypedValue(
440 IXMLDOMText *iface,
441 VARIANT* var1)
443 domtext *This = impl_from_IXMLDOMText( iface );
444 IXMLDOMNode* parent = NULL;
445 HRESULT hr;
447 TRACE("(%p)->(%p)\n", This, var1);
449 if (!var1)
450 return E_INVALIDARG;
452 hr = domtext_get_parentNode(iface, &parent);
454 if (hr == S_OK)
456 hr = IXMLDOMNode_get_nodeTypedValue(parent, var1);
457 IXMLDOMNode_Release(parent);
459 else
461 V_VT(var1) = VT_NULL;
462 V_BSTR(var1) = NULL;
463 hr = S_FALSE;
466 return hr;
469 static HRESULT WINAPI domtext_put_nodeTypedValue(
470 IXMLDOMText *iface,
471 VARIANT value)
473 domtext *This = impl_from_IXMLDOMText( iface );
474 IXMLDOMNode* parent = NULL;
475 HRESULT hr;
477 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
479 hr = domtext_get_parentNode(iface, &parent);
481 if (hr == S_OK)
483 hr = IXMLDOMNode_put_nodeTypedValue(parent, value);
484 IXMLDOMNode_Release(parent);
486 else
488 hr = S_FALSE;
491 return hr;
494 static HRESULT WINAPI domtext_get_dataType(
495 IXMLDOMText *iface,
496 VARIANT* dtName)
498 domtext *This = impl_from_IXMLDOMText( iface );
499 IXMLDOMNode* parent = NULL;
500 HRESULT hr;
502 TRACE("(%p)->(%p)\n", This, dtName);
504 if (!dtName)
505 return E_INVALIDARG;
507 hr = domtext_get_parentNode(iface, &parent);
509 if (hr == S_OK)
511 hr = IXMLDOMNode_get_dataType(parent, dtName);
512 IXMLDOMNode_Release(parent);
514 else
516 V_VT(dtName) = VT_NULL;
517 V_BSTR(dtName) = NULL;
518 hr = S_FALSE;
521 return hr;
524 static HRESULT WINAPI domtext_put_dataType(
525 IXMLDOMText *iface,
526 BSTR dtName)
528 domtext *This = impl_from_IXMLDOMText( iface );
529 IXMLDOMNode* parent = NULL;
530 HRESULT hr;
532 TRACE("(%p)->(%p)\n", This, dtName);
534 if (!dtName)
535 return E_INVALIDARG;
537 hr = domtext_get_parentNode(iface, &parent);
539 if (hr == S_OK)
541 hr = IXMLDOMNode_put_dataType(parent, dtName);
542 IXMLDOMNode_Release(parent);
544 else
546 hr = S_FALSE;
549 return hr;
552 static HRESULT WINAPI domtext_get_xml(
553 IXMLDOMText *iface,
554 BSTR* p)
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(
564 IXMLDOMText *iface,
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(
573 IXMLDOMText *iface,
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(
582 IXMLDOMText *iface,
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(
591 IXMLDOMText *iface,
592 VARIANT_BOOL* isParsed)
594 domtext *This = impl_from_IXMLDOMText( iface );
595 FIXME("(%p)->(%p) stub!\n", This, isParsed);
596 *isParsed = VARIANT_TRUE;
597 return S_OK;
600 static HRESULT WINAPI domtext_get_namespaceURI(
601 IXMLDOMText *iface,
602 BSTR* p)
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(
610 IXMLDOMText *iface,
611 BSTR* 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(
619 IXMLDOMText *iface,
620 BSTR* name)
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(
628 IXMLDOMText *iface,
629 IXMLDOMNode* domNode, VARIANT var1)
631 domtext *This = impl_from_IXMLDOMText( iface );
632 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
633 return E_NOTIMPL;
636 static HRESULT WINAPI domtext_get_data(
637 IXMLDOMText *iface,
638 BSTR *p)
640 domtext *This = impl_from_IXMLDOMText( iface );
642 if(!p)
643 return E_INVALIDARG;
645 *p = bstr_from_xmlChar(This->node.node->content);
646 return S_OK;
649 static HRESULT WINAPI domtext_put_data(
650 IXMLDOMText *iface,
651 BSTR data)
653 domtext *This = impl_from_IXMLDOMText( iface );
654 VARIANT val;
656 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
658 V_VT(&val) = VT_BSTR;
659 V_BSTR(&val) = data;
660 return node_put_value(&This->node, &val);
663 static HRESULT WINAPI domtext_get_length(
664 IXMLDOMText *iface,
665 LONG *len)
667 domtext *This = impl_from_IXMLDOMText( iface );
668 HRESULT hr;
669 BSTR data;
671 TRACE("(%p)->(%p)\n", This, len);
673 if(!len)
674 return E_INVALIDARG;
676 hr = IXMLDOMText_get_data(iface, &data);
677 if(hr == S_OK)
679 *len = SysStringLen(data);
680 SysFreeString(data);
683 return hr;
686 static HRESULT WINAPI domtext_substringData(
687 IXMLDOMText *iface,
688 LONG offset, LONG count, BSTR *p)
690 domtext *This = impl_from_IXMLDOMText( iface );
691 HRESULT hr;
692 BSTR data;
694 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
696 if(!p)
697 return E_INVALIDARG;
699 *p = NULL;
700 if(offset < 0 || count < 0)
701 return E_INVALIDARG;
703 if(count == 0)
704 return S_FALSE;
706 hr = IXMLDOMText_get_data(iface, &data);
707 if(hr == S_OK)
709 LONG len = SysStringLen(data);
711 if(offset < len)
713 if(offset + count > len)
714 *p = SysAllocString(&data[offset]);
715 else
716 *p = SysAllocStringLen(&data[offset], count);
718 else
719 hr = S_FALSE;
721 SysFreeString(data);
724 return hr;
727 static HRESULT WINAPI domtext_appendData(
728 IXMLDOMText *iface,
729 BSTR p)
731 domtext *This = impl_from_IXMLDOMText( iface );
732 HRESULT hr;
733 BSTR data;
734 LONG p_len;
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);
742 if(hr == S_OK)
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));
749 str[len+p_len] = 0;
751 hr = IXMLDOMText_put_data(iface, str);
753 SysFreeString(str);
754 SysFreeString(data);
757 return hr;
760 static HRESULT WINAPI domtext_insertData(
761 IXMLDOMText *iface,
762 LONG offset, BSTR p)
764 domtext *This = impl_from_IXMLDOMText( iface );
765 HRESULT hr;
766 BSTR data;
767 LONG p_len;
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)
773 return S_OK;
775 if(offset < 0)
777 return E_INVALIDARG;
780 hr = IXMLDOMText_get_data(iface, &data);
781 if(hr == S_OK)
783 LONG len = SysStringLen(data);
784 BSTR str;
786 if(len < offset)
788 SysFreeString(data);
789 return E_INVALIDARG;
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));
797 str[len+p_len] = 0;
799 hr = IXMLDOMText_put_data(iface, str);
801 SysFreeString(str);
802 SysFreeString(data);
805 return hr;
808 static HRESULT WINAPI domtext_deleteData(
809 IXMLDOMText *iface,
810 LONG offset, LONG count)
812 HRESULT hr;
813 LONG len = -1;
814 BSTR str;
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))
822 return E_INVALIDARG;
824 if(len == 0) return S_OK;
826 /* cutting start or end */
827 if((offset == 0) || ((count + offset) >= len))
829 if(offset == 0)
830 IXMLDOMText_substringData(iface, count, len - count, &str);
831 else
832 IXMLDOMText_substringData(iface, 0, offset, &str);
833 hr = IXMLDOMText_put_data(iface, str);
835 else
836 /* cutting from the inside */
838 BSTR str_end;
840 IXMLDOMText_substringData(iface, 0, offset, &str);
841 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
843 hr = IXMLDOMText_put_data(iface, str);
844 if(hr == S_OK)
845 hr = IXMLDOMText_appendData(iface, str_end);
847 SysFreeString(str_end);
850 SysFreeString(str);
852 return hr;
855 static HRESULT WINAPI domtext_replaceData(
856 IXMLDOMText *iface,
857 LONG offset, LONG count, BSTR p)
859 domtext *This = impl_from_IXMLDOMText( iface );
860 HRESULT hr;
862 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
864 hr = IXMLDOMText_deleteData(iface, offset, count);
866 if (hr == S_OK)
867 hr = IXMLDOMText_insertData(iface, offset, p);
869 return hr;
872 static HRESULT WINAPI domtext_splitText(
873 IXMLDOMText *iface,
874 LONG offset, IXMLDOMText **txtNode)
876 domtext *This = impl_from_IXMLDOMText( iface );
877 LONG length = 0;
879 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
881 if (!txtNode || offset < 0) return E_INVALIDARG;
883 *txtNode = NULL;
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");
892 return E_NOTIMPL;
895 static const struct IXMLDOMTextVtbl domtext_vtbl =
897 domtext_QueryInterface,
898 domtext_AddRef,
899 domtext_Release,
900 domtext_GetTypeInfoCount,
901 domtext_GetTypeInfo,
902 domtext_GetIDsOfNames,
903 domtext_Invoke,
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,
917 domtext_removeChild,
918 domtext_appendChild,
919 domtext_hasChildNodes,
920 domtext_get_ownerDocument,
921 domtext_cloneNode,
922 domtext_get_nodeTypeString,
923 domtext_get_text,
924 domtext_put_text,
925 domtext_get_specified,
926 domtext_get_definition,
927 domtext_get_nodeTypedValue,
928 domtext_put_nodeTypedValue,
929 domtext_get_dataType,
930 domtext_put_dataType,
931 domtext_get_xml,
932 domtext_transformNode,
933 domtext_selectNodes,
934 domtext_selectSingleNode,
935 domtext_get_parsed,
936 domtext_get_namespaceURI,
937 domtext_get_prefix,
938 domtext_get_baseName,
939 domtext_transformNodeToObject,
940 domtext_get_data,
941 domtext_put_data,
942 domtext_get_length,
943 domtext_substringData,
944 domtext_appendData,
945 domtext_insertData,
946 domtext_deleteData,
947 domtext_replaceData,
948 domtext_splitText
951 static const tid_t domtext_iface_tids[] = {
952 IXMLDOMText_tid,
956 static dispex_static_data_t domtext_dispex = {
957 NULL,
958 IXMLDOMText_tid,
959 NULL,
960 domtext_iface_tids
963 IUnknown* create_text( xmlNodePtr text )
965 domtext *This;
967 This = heap_alloc( sizeof *This );
968 if ( !This )
969 return NULL;
971 This->IXMLDOMText_iface.lpVtbl = &domtext_vtbl;
972 This->ref = 1;
974 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMText_iface, &domtext_dispex);
976 return (IUnknown*)&This->IXMLDOMText_iface;
979 #endif