clock: Update Korean resource.
[wine/multimedia.git] / dlls / msxml3 / text.c
blob4a2bd2191055e006ce65f8462d001b8dd830ef6a
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)->(v%d)\n", This, V_VT(&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 x%d %p) needs test\n", This, newNode, V_VT(&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* domNode, IXMLDOMNode** oldNode)
348 domtext *This = impl_from_IXMLDOMText( iface );
349 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
352 static HRESULT WINAPI domtext_appendChild(
353 IXMLDOMText *iface,
354 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
356 domtext *This = impl_from_IXMLDOMText( iface );
357 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
360 static HRESULT WINAPI domtext_hasChildNodes(
361 IXMLDOMText *iface,
362 VARIANT_BOOL* pbool)
364 domtext *This = impl_from_IXMLDOMText( iface );
365 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
368 static HRESULT WINAPI domtext_get_ownerDocument(
369 IXMLDOMText *iface,
370 IXMLDOMDocument** domDocument)
372 domtext *This = impl_from_IXMLDOMText( iface );
373 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
376 static HRESULT WINAPI domtext_cloneNode(
377 IXMLDOMText *iface,
378 VARIANT_BOOL deep, IXMLDOMNode** outNode)
380 domtext *This = impl_from_IXMLDOMText( iface );
381 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
382 return node_clone( &This->node, deep, outNode );
385 static HRESULT WINAPI domtext_get_nodeTypeString(
386 IXMLDOMText *iface,
387 BSTR* p)
389 domtext *This = impl_from_IXMLDOMText( iface );
390 static const WCHAR textW[] = {'t','e','x','t',0};
392 TRACE("(%p)->(%p)\n", This, p);
394 return return_bstr(textW, p);
397 static HRESULT WINAPI domtext_get_text(
398 IXMLDOMText *iface,
399 BSTR* p)
401 domtext *This = impl_from_IXMLDOMText( iface );
402 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
405 static HRESULT WINAPI domtext_put_text(
406 IXMLDOMText *iface,
407 BSTR p)
409 domtext *This = impl_from_IXMLDOMText( iface );
410 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
411 return node_put_text( &This->node, p );
414 static HRESULT WINAPI domtext_get_specified(
415 IXMLDOMText *iface,
416 VARIANT_BOOL* isSpecified)
418 domtext *This = impl_from_IXMLDOMText( iface );
419 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
420 *isSpecified = VARIANT_TRUE;
421 return S_OK;
424 static HRESULT WINAPI domtext_get_definition(
425 IXMLDOMText *iface,
426 IXMLDOMNode** definitionNode)
428 domtext *This = impl_from_IXMLDOMText( iface );
429 FIXME("(%p)->(%p)\n", This, definitionNode);
430 return E_NOTIMPL;
433 static HRESULT WINAPI domtext_get_nodeTypedValue(
434 IXMLDOMText *iface,
435 VARIANT* var1)
437 domtext *This = impl_from_IXMLDOMText( iface );
438 IXMLDOMNode* parent = NULL;
439 HRESULT hr;
441 TRACE("(%p)->(%p)\n", This, var1);
443 if (!var1)
444 return E_INVALIDARG;
446 hr = domtext_get_parentNode(iface, &parent);
448 if (hr == S_OK)
450 hr = IXMLDOMNode_get_nodeTypedValue(parent, var1);
451 IXMLDOMNode_Release(parent);
453 else
455 V_VT(var1) = VT_NULL;
456 V_BSTR(var1) = NULL;
457 hr = S_FALSE;
460 return hr;
463 static HRESULT WINAPI domtext_put_nodeTypedValue(
464 IXMLDOMText *iface,
465 VARIANT var1)
467 domtext *This = impl_from_IXMLDOMText( iface );
468 IXMLDOMNode* parent = NULL;
469 HRESULT hr;
471 TRACE("(%p)->(VARIANT)\n", This);
473 hr = domtext_get_parentNode(iface, &parent);
475 if (hr == S_OK)
477 hr = IXMLDOMNode_put_nodeTypedValue(parent, var1);
478 IXMLDOMNode_Release(parent);
480 else
482 hr = S_FALSE;
485 return hr;
488 static HRESULT WINAPI domtext_get_dataType(
489 IXMLDOMText *iface,
490 VARIANT* dtName)
492 domtext *This = impl_from_IXMLDOMText( iface );
493 IXMLDOMNode* parent = NULL;
494 HRESULT hr;
496 TRACE("(%p)->(%p)\n", This, dtName);
498 if (!dtName)
499 return E_INVALIDARG;
501 hr = domtext_get_parentNode(iface, &parent);
503 if (hr == S_OK)
505 hr = IXMLDOMNode_get_dataType(parent, dtName);
506 IXMLDOMNode_Release(parent);
508 else
510 V_VT(dtName) = VT_NULL;
511 V_BSTR(dtName) = NULL;
512 hr = S_FALSE;
515 return hr;
518 static HRESULT WINAPI domtext_put_dataType(
519 IXMLDOMText *iface,
520 BSTR dtName)
522 domtext *This = impl_from_IXMLDOMText( iface );
523 IXMLDOMNode* parent = NULL;
524 HRESULT hr;
526 TRACE("(%p)->(%p)\n", This, dtName);
528 if (!dtName)
529 return E_INVALIDARG;
531 hr = domtext_get_parentNode(iface, &parent);
533 if (hr == S_OK)
535 hr = IXMLDOMNode_put_dataType(parent, dtName);
536 IXMLDOMNode_Release(parent);
538 else
540 hr = S_FALSE;
543 return hr;
546 static HRESULT WINAPI domtext_get_xml(
547 IXMLDOMText *iface,
548 BSTR* p)
550 domtext *This = impl_from_IXMLDOMText( iface );
552 TRACE("(%p)->(%p)\n", This, p);
554 return node_get_xml(&This->node, FALSE, FALSE, p);
557 static HRESULT WINAPI domtext_transformNode(
558 IXMLDOMText *iface,
559 IXMLDOMNode* domNode, BSTR* p)
561 domtext *This = impl_from_IXMLDOMText( iface );
562 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
565 static HRESULT WINAPI domtext_selectNodes(
566 IXMLDOMText *iface,
567 BSTR p, IXMLDOMNodeList** outList)
569 domtext *This = impl_from_IXMLDOMText( iface );
570 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
573 static HRESULT WINAPI domtext_selectSingleNode(
574 IXMLDOMText *iface,
575 BSTR p, IXMLDOMNode** outNode)
577 domtext *This = impl_from_IXMLDOMText( iface );
578 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
581 static HRESULT WINAPI domtext_get_parsed(
582 IXMLDOMText *iface,
583 VARIANT_BOOL* isParsed)
585 domtext *This = impl_from_IXMLDOMText( iface );
586 FIXME("(%p)->(%p) stub!\n", This, isParsed);
587 *isParsed = VARIANT_TRUE;
588 return S_OK;
591 static HRESULT WINAPI domtext_get_namespaceURI(
592 IXMLDOMText *iface,
593 BSTR* p)
595 domtext *This = impl_from_IXMLDOMText( iface );
596 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
599 static HRESULT WINAPI domtext_get_prefix(
600 IXMLDOMText *iface,
601 BSTR* prefix)
603 domtext *This = impl_from_IXMLDOMText( iface );
604 TRACE("(%p)->(%p)\n", This, prefix);
605 return return_null_bstr( prefix );
608 static HRESULT WINAPI domtext_get_baseName(
609 IXMLDOMText *iface,
610 BSTR* name)
612 domtext *This = impl_from_IXMLDOMText( iface );
613 TRACE("(%p)->(%p)\n", This, name);
614 return return_null_bstr( name );
617 static HRESULT WINAPI domtext_transformNodeToObject(
618 IXMLDOMText *iface,
619 IXMLDOMNode* domNode, VARIANT var1)
621 domtext *This = impl_from_IXMLDOMText( iface );
622 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
625 static HRESULT WINAPI domtext_get_data(
626 IXMLDOMText *iface,
627 BSTR *p)
629 domtext *This = impl_from_IXMLDOMText( iface );
631 if(!p)
632 return E_INVALIDARG;
634 *p = bstr_from_xmlChar(This->node.node->content);
635 return S_OK;
638 static HRESULT WINAPI domtext_put_data(
639 IXMLDOMText *iface,
640 BSTR data)
642 domtext *This = impl_from_IXMLDOMText( iface );
643 VARIANT val;
645 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
647 V_VT(&val) = VT_BSTR;
648 V_BSTR(&val) = data;
649 return node_put_value(&This->node, &val);
652 static HRESULT WINAPI domtext_get_length(
653 IXMLDOMText *iface,
654 LONG *len)
656 domtext *This = impl_from_IXMLDOMText( iface );
657 HRESULT hr;
658 BSTR data;
660 TRACE("(%p)->(%p)\n", This, len);
662 if(!len)
663 return E_INVALIDARG;
665 hr = IXMLDOMText_get_data(iface, &data);
666 if(hr == S_OK)
668 *len = SysStringLen(data);
669 SysFreeString(data);
672 return hr;
675 static HRESULT WINAPI domtext_substringData(
676 IXMLDOMText *iface,
677 LONG offset, LONG count, BSTR *p)
679 domtext *This = impl_from_IXMLDOMText( iface );
680 HRESULT hr;
681 BSTR data;
683 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
685 if(!p)
686 return E_INVALIDARG;
688 *p = NULL;
689 if(offset < 0 || count < 0)
690 return E_INVALIDARG;
692 if(count == 0)
693 return S_FALSE;
695 hr = IXMLDOMText_get_data(iface, &data);
696 if(hr == S_OK)
698 LONG len = SysStringLen(data);
700 if(offset < len)
702 if(offset + count > len)
703 *p = SysAllocString(&data[offset]);
704 else
705 *p = SysAllocStringLen(&data[offset], count);
707 else
708 hr = S_FALSE;
710 SysFreeString(data);
713 return hr;
716 static HRESULT WINAPI domtext_appendData(
717 IXMLDOMText *iface,
718 BSTR p)
720 domtext *This = impl_from_IXMLDOMText( iface );
721 HRESULT hr;
722 BSTR data;
723 LONG p_len;
725 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
727 /* Nothing to do if NULL or an Empty string passed in. */
728 if((p_len = SysStringLen(p)) == 0) return S_OK;
730 hr = IXMLDOMText_get_data(iface, &data);
731 if(hr == S_OK)
733 LONG len = SysStringLen(data);
734 BSTR str = SysAllocStringLen(NULL, p_len + len);
736 memcpy(str, data, len*sizeof(WCHAR));
737 memcpy(&str[len], p, p_len*sizeof(WCHAR));
738 str[len+p_len] = 0;
740 hr = IXMLDOMText_put_data(iface, str);
742 SysFreeString(str);
743 SysFreeString(data);
746 return hr;
749 static HRESULT WINAPI domtext_insertData(
750 IXMLDOMText *iface,
751 LONG offset, BSTR p)
753 domtext *This = impl_from_IXMLDOMText( iface );
754 HRESULT hr;
755 BSTR data;
756 LONG p_len;
758 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
760 /* If have a NULL or empty string, don't do anything. */
761 if((p_len = SysStringLen(p)) == 0)
762 return S_OK;
764 if(offset < 0)
766 return E_INVALIDARG;
769 hr = IXMLDOMText_get_data(iface, &data);
770 if(hr == S_OK)
772 LONG len = SysStringLen(data);
773 BSTR str;
775 if(len < offset)
777 SysFreeString(data);
778 return E_INVALIDARG;
781 str = SysAllocStringLen(NULL, len + p_len);
782 /* start part, supplied string and end part */
783 memcpy(str, data, offset*sizeof(WCHAR));
784 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
785 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
786 str[len+p_len] = 0;
788 hr = IXMLDOMText_put_data(iface, str);
790 SysFreeString(str);
791 SysFreeString(data);
794 return hr;
797 static HRESULT WINAPI domtext_deleteData(
798 IXMLDOMText *iface,
799 LONG offset, LONG count)
801 HRESULT hr;
802 LONG len = -1;
803 BSTR str;
805 TRACE("(%p)->(%d %d)\n", iface, offset, count);
807 hr = IXMLDOMText_get_length(iface, &len);
808 if(hr != S_OK) return hr;
810 if((offset < 0) || (offset > len) || (count < 0))
811 return E_INVALIDARG;
813 if(len == 0) return S_OK;
815 /* cutting start or end */
816 if((offset == 0) || ((count + offset) >= len))
818 if(offset == 0)
819 IXMLDOMText_substringData(iface, count, len - count, &str);
820 else
821 IXMLDOMText_substringData(iface, 0, offset, &str);
822 hr = IXMLDOMText_put_data(iface, str);
824 else
825 /* cutting from the inside */
827 BSTR str_end;
829 IXMLDOMText_substringData(iface, 0, offset, &str);
830 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
832 hr = IXMLDOMText_put_data(iface, str);
833 if(hr == S_OK)
834 hr = IXMLDOMText_appendData(iface, str_end);
836 SysFreeString(str_end);
839 SysFreeString(str);
841 return hr;
844 static HRESULT WINAPI domtext_replaceData(
845 IXMLDOMText *iface,
846 LONG offset, LONG count, BSTR p)
848 domtext *This = impl_from_IXMLDOMText( iface );
849 HRESULT hr;
851 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
853 hr = IXMLDOMText_deleteData(iface, offset, count);
855 if (hr == S_OK)
856 hr = IXMLDOMText_insertData(iface, offset, p);
858 return hr;
861 static HRESULT WINAPI domtext_splitText(
862 IXMLDOMText *iface,
863 LONG offset, IXMLDOMText **txtNode)
865 domtext *This = impl_from_IXMLDOMText( iface );
866 LONG length = 0;
868 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
870 if (!txtNode || offset < 0) return E_INVALIDARG;
872 *txtNode = NULL;
874 IXMLDOMText_get_length(iface, &length);
876 if (offset > length) return E_INVALIDARG;
877 if (offset == length) return S_FALSE;
879 FIXME("adjacent text nodes are not supported\n");
881 return E_NOTIMPL;
884 static const struct IXMLDOMTextVtbl domtext_vtbl =
886 domtext_QueryInterface,
887 domtext_AddRef,
888 domtext_Release,
889 domtext_GetTypeInfoCount,
890 domtext_GetTypeInfo,
891 domtext_GetIDsOfNames,
892 domtext_Invoke,
893 domtext_get_nodeName,
894 domtext_get_nodeValue,
895 domtext_put_nodeValue,
896 domtext_get_nodeType,
897 domtext_get_parentNode,
898 domtext_get_childNodes,
899 domtext_get_firstChild,
900 domtext_get_lastChild,
901 domtext_get_previousSibling,
902 domtext_get_nextSibling,
903 domtext_get_attributes,
904 domtext_insertBefore,
905 domtext_replaceChild,
906 domtext_removeChild,
907 domtext_appendChild,
908 domtext_hasChildNodes,
909 domtext_get_ownerDocument,
910 domtext_cloneNode,
911 domtext_get_nodeTypeString,
912 domtext_get_text,
913 domtext_put_text,
914 domtext_get_specified,
915 domtext_get_definition,
916 domtext_get_nodeTypedValue,
917 domtext_put_nodeTypedValue,
918 domtext_get_dataType,
919 domtext_put_dataType,
920 domtext_get_xml,
921 domtext_transformNode,
922 domtext_selectNodes,
923 domtext_selectSingleNode,
924 domtext_get_parsed,
925 domtext_get_namespaceURI,
926 domtext_get_prefix,
927 domtext_get_baseName,
928 domtext_transformNodeToObject,
929 domtext_get_data,
930 domtext_put_data,
931 domtext_get_length,
932 domtext_substringData,
933 domtext_appendData,
934 domtext_insertData,
935 domtext_deleteData,
936 domtext_replaceData,
937 domtext_splitText
940 IUnknown* create_text( xmlNodePtr text )
942 domtext *This;
944 This = heap_alloc( sizeof *This );
945 if ( !This )
946 return NULL;
948 This->IXMLDOMText_iface.lpVtbl = &domtext_vtbl;
949 This->ref = 1;
951 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMText_iface, NULL);
953 return (IUnknown*)&This->IXMLDOMText_iface;
956 #endif