ntdll: Make sure we don't try to attach the main exe a second time.
[wine/zf.git] / dlls / msxml3 / text.c
blobabd89dbd6ba8840a9b2e784b2b55f47dca9d1e27
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/parserInternals.h>
30 # include <libxml/xmlerror.h>
31 #endif
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winuser.h"
36 #include "ole2.h"
37 #include "msxml6.h"
39 #include "msxml_private.h"
41 #include "wine/debug.h"
43 #ifdef HAVE_LIBXML2
45 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
47 typedef struct _domtext
49 xmlnode node;
50 IXMLDOMText IXMLDOMText_iface;
51 LONG ref;
52 } domtext;
54 static inline domtext *impl_from_IXMLDOMText( IXMLDOMText *iface )
56 return CONTAINING_RECORD(iface, domtext, IXMLDOMText_iface);
59 static void domtext_reset_noenc(domtext *This)
61 This->node.node->name = NULL;
64 static HRESULT WINAPI domtext_QueryInterface(
65 IXMLDOMText *iface,
66 REFIID riid,
67 void** ppvObject )
69 domtext *This = impl_from_IXMLDOMText( iface );
70 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
72 if ( IsEqualGUID( riid, &IID_IXMLDOMText ) ||
73 IsEqualGUID( riid, &IID_IXMLDOMCharacterData) ||
74 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
75 IsEqualGUID( riid, &IID_IDispatch ) ||
76 IsEqualGUID( riid, &IID_IUnknown ) )
78 *ppvObject = iface;
80 else if(node_query_interface(&This->node, riid, ppvObject))
82 return *ppvObject ? S_OK : E_NOINTERFACE;
84 else
86 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
87 *ppvObject = NULL;
88 return E_NOINTERFACE;
91 IXMLDOMText_AddRef(iface);
92 return S_OK;
95 static ULONG WINAPI domtext_AddRef(
96 IXMLDOMText *iface )
98 domtext *This = impl_from_IXMLDOMText( iface );
99 ULONG ref = InterlockedIncrement( &This->ref );
100 TRACE("(%p)->(%d)\n", This, ref);
101 return ref;
104 static ULONG WINAPI domtext_Release(
105 IXMLDOMText *iface )
107 domtext *This = impl_from_IXMLDOMText( iface );
108 ULONG ref = InterlockedDecrement( &This->ref );
110 TRACE("(%p)->(%d)\n", This, ref);
111 if ( ref == 0 )
113 destroy_xmlnode(&This->node);
114 heap_free( This );
117 return ref;
120 static HRESULT WINAPI domtext_GetTypeInfoCount(
121 IXMLDOMText *iface,
122 UINT* pctinfo )
124 domtext *This = impl_from_IXMLDOMText( iface );
125 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
128 static HRESULT WINAPI domtext_GetTypeInfo(
129 IXMLDOMText *iface,
130 UINT iTInfo, LCID lcid,
131 ITypeInfo** ppTInfo )
133 domtext *This = impl_from_IXMLDOMText( iface );
134 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
135 iTInfo, lcid, ppTInfo);
138 static HRESULT WINAPI domtext_GetIDsOfNames(
139 IXMLDOMText *iface,
140 REFIID riid, LPOLESTR* rgszNames,
141 UINT cNames, LCID lcid, DISPID* rgDispId )
143 domtext *This = impl_from_IXMLDOMText( iface );
144 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
145 riid, rgszNames, cNames, lcid, rgDispId);
148 static HRESULT WINAPI domtext_Invoke(
149 IXMLDOMText *iface,
150 DISPID dispIdMember, REFIID riid, LCID lcid,
151 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
152 EXCEPINFO* pExcepInfo, UINT* puArgErr )
154 domtext *This = impl_from_IXMLDOMText( iface );
155 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
156 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
159 static HRESULT WINAPI domtext_get_nodeName(
160 IXMLDOMText *iface,
161 BSTR* p )
163 domtext *This = impl_from_IXMLDOMText( iface );
165 static const WCHAR textW[] = {'#','t','e','x','t',0};
167 TRACE("(%p)->(%p)\n", This, p);
169 return return_bstr(textW, p);
172 static HRESULT WINAPI domtext_get_nodeValue(
173 IXMLDOMText *iface,
174 VARIANT* value )
176 domtext *This = impl_from_IXMLDOMText( iface );
178 TRACE("(%p)->(%p)\n", This, value);
180 return node_get_content(&This->node, value);
183 static HRESULT WINAPI domtext_put_nodeValue(
184 IXMLDOMText *iface,
185 VARIANT value)
187 domtext *This = impl_from_IXMLDOMText( iface );
189 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
191 domtext_reset_noenc(This);
192 return node_put_value(&This->node, &value);
195 static HRESULT WINAPI domtext_get_nodeType(
196 IXMLDOMText *iface,
197 DOMNodeType* domNodeType )
199 domtext *This = impl_from_IXMLDOMText( iface );
201 TRACE("(%p)->(%p)\n", This, domNodeType);
203 *domNodeType = NODE_TEXT;
204 return S_OK;
207 static HRESULT WINAPI domtext_get_parentNode(
208 IXMLDOMText *iface,
209 IXMLDOMNode** parent )
211 domtext *This = impl_from_IXMLDOMText( iface );
213 TRACE("(%p)->(%p)\n", This, parent);
215 return node_get_parent(&This->node, parent);
218 static HRESULT WINAPI domtext_get_childNodes(
219 IXMLDOMText *iface,
220 IXMLDOMNodeList** outList)
222 domtext *This = impl_from_IXMLDOMText( iface );
224 TRACE("(%p)->(%p)\n", This, outList);
226 return node_get_child_nodes(&This->node, outList);
229 static HRESULT WINAPI domtext_get_firstChild(
230 IXMLDOMText *iface,
231 IXMLDOMNode** domNode)
233 domtext *This = impl_from_IXMLDOMText( iface );
235 TRACE("(%p)->(%p)\n", This, domNode);
237 return return_null_node(domNode);
240 static HRESULT WINAPI domtext_get_lastChild(
241 IXMLDOMText *iface,
242 IXMLDOMNode** domNode)
244 domtext *This = impl_from_IXMLDOMText( iface );
246 TRACE("(%p)->(%p)\n", This, domNode);
248 return return_null_node(domNode);
251 static HRESULT WINAPI domtext_get_previousSibling(
252 IXMLDOMText *iface,
253 IXMLDOMNode** domNode)
255 domtext *This = impl_from_IXMLDOMText( iface );
257 TRACE("(%p)->(%p)\n", This, domNode);
259 return node_get_previous_sibling(&This->node, domNode);
262 static HRESULT WINAPI domtext_get_nextSibling(
263 IXMLDOMText *iface,
264 IXMLDOMNode** domNode)
266 domtext *This = impl_from_IXMLDOMText( iface );
268 TRACE("(%p)->(%p)\n", This, domNode);
270 return node_get_next_sibling(&This->node, domNode);
273 static HRESULT WINAPI domtext_get_attributes(
274 IXMLDOMText *iface,
275 IXMLDOMNamedNodeMap** attributeMap)
277 domtext *This = impl_from_IXMLDOMText( iface );
279 TRACE("(%p)->(%p)\n", This, attributeMap);
281 return return_null_ptr((void**)attributeMap);
284 static HRESULT WINAPI domtext_insertBefore(
285 IXMLDOMText *iface,
286 IXMLDOMNode* newNode, VARIANT refChild,
287 IXMLDOMNode** outOldNode)
289 domtext *This = impl_from_IXMLDOMText( iface );
291 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
293 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
296 static HRESULT WINAPI domtext_replaceChild(
297 IXMLDOMText *iface,
298 IXMLDOMNode* newNode,
299 IXMLDOMNode* oldNode,
300 IXMLDOMNode** outOldNode)
302 domtext *This = impl_from_IXMLDOMText( iface );
304 FIXME("(%p)->(%p %p %p) needs test\n", This, newNode, oldNode, outOldNode);
306 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
309 static HRESULT WINAPI domtext_removeChild(
310 IXMLDOMText *iface,
311 IXMLDOMNode *child, IXMLDOMNode **oldChild)
313 domtext *This = impl_from_IXMLDOMText( iface );
314 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
315 return node_remove_child(&This->node, child, oldChild);
318 static HRESULT WINAPI domtext_appendChild(
319 IXMLDOMText *iface,
320 IXMLDOMNode *child, IXMLDOMNode **outChild)
322 domtext *This = impl_from_IXMLDOMText( iface );
323 TRACE("(%p)->(%p %p)\n", This, child, outChild);
324 return node_append_child(&This->node, child, outChild);
327 static HRESULT WINAPI domtext_hasChildNodes(
328 IXMLDOMText *iface,
329 VARIANT_BOOL *ret)
331 domtext *This = impl_from_IXMLDOMText( iface );
332 TRACE("(%p)->(%p)\n", This, ret);
333 return return_var_false(ret);
336 static HRESULT WINAPI domtext_get_ownerDocument(
337 IXMLDOMText *iface,
338 IXMLDOMDocument **doc)
340 domtext *This = impl_from_IXMLDOMText( iface );
341 TRACE("(%p)->(%p)\n", This, doc);
342 return node_get_owner_doc(&This->node, doc);
345 static HRESULT WINAPI domtext_cloneNode(
346 IXMLDOMText *iface,
347 VARIANT_BOOL deep, IXMLDOMNode** outNode)
349 domtext *This = impl_from_IXMLDOMText( iface );
350 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
351 return node_clone( &This->node, deep, outNode );
354 static HRESULT WINAPI domtext_get_nodeTypeString(
355 IXMLDOMText *iface,
356 BSTR* p)
358 domtext *This = impl_from_IXMLDOMText( iface );
359 static const WCHAR textW[] = {'t','e','x','t',0};
361 TRACE("(%p)->(%p)\n", This, p);
363 return return_bstr(textW, p);
366 static HRESULT WINAPI domtext_get_text(
367 IXMLDOMText *iface,
368 BSTR* p)
370 domtext *This = impl_from_IXMLDOMText( iface );
371 TRACE("(%p)->(%p)\n", This, p);
372 return node_get_text(&This->node, p);
375 static HRESULT WINAPI domtext_put_text(
376 IXMLDOMText *iface,
377 BSTR p)
379 domtext *This = impl_from_IXMLDOMText( iface );
380 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
381 domtext_reset_noenc(This);
382 return node_put_text( &This->node, p );
385 static HRESULT WINAPI domtext_get_specified(
386 IXMLDOMText *iface,
387 VARIANT_BOOL* isSpecified)
389 domtext *This = impl_from_IXMLDOMText( iface );
390 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
391 *isSpecified = VARIANT_TRUE;
392 return S_OK;
395 static HRESULT WINAPI domtext_get_definition(
396 IXMLDOMText *iface,
397 IXMLDOMNode** definitionNode)
399 domtext *This = impl_from_IXMLDOMText( iface );
400 FIXME("(%p)->(%p)\n", This, definitionNode);
401 return E_NOTIMPL;
404 static HRESULT WINAPI domtext_get_nodeTypedValue(
405 IXMLDOMText *iface,
406 VARIANT* var1)
408 domtext *This = impl_from_IXMLDOMText( iface );
409 IXMLDOMNode* parent = NULL;
410 HRESULT hr;
412 TRACE("(%p)->(%p)\n", This, var1);
414 if (!var1)
415 return E_INVALIDARG;
417 hr = IXMLDOMText_get_parentNode(iface, &parent);
419 if (hr == S_OK)
421 hr = IXMLDOMNode_get_nodeTypedValue(parent, var1);
422 IXMLDOMNode_Release(parent);
424 else
426 V_VT(var1) = VT_NULL;
427 V_BSTR(var1) = NULL;
428 hr = S_FALSE;
431 return hr;
434 static HRESULT WINAPI domtext_put_nodeTypedValue(
435 IXMLDOMText *iface,
436 VARIANT value)
438 domtext *This = impl_from_IXMLDOMText( iface );
439 IXMLDOMNode* parent = NULL;
440 HRESULT hr;
442 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
444 hr = IXMLDOMText_get_parentNode(iface, &parent);
446 if (hr == S_OK)
448 hr = IXMLDOMNode_put_nodeTypedValue(parent, value);
449 IXMLDOMNode_Release(parent);
451 else
453 hr = S_FALSE;
456 return hr;
459 static HRESULT WINAPI domtext_get_dataType(
460 IXMLDOMText *iface,
461 VARIANT* dtName)
463 domtext *This = impl_from_IXMLDOMText( iface );
464 IXMLDOMNode* parent = NULL;
465 HRESULT hr;
467 TRACE("(%p)->(%p)\n", This, dtName);
469 if (!dtName)
470 return E_INVALIDARG;
472 hr = IXMLDOMText_get_parentNode(iface, &parent);
474 if (hr == S_OK)
476 hr = IXMLDOMNode_get_dataType(parent, dtName);
477 IXMLDOMNode_Release(parent);
479 else
481 V_VT(dtName) = VT_NULL;
482 V_BSTR(dtName) = NULL;
483 hr = S_FALSE;
486 return hr;
489 static HRESULT WINAPI domtext_put_dataType(
490 IXMLDOMText *iface,
491 BSTR dtName)
493 domtext *This = impl_from_IXMLDOMText( iface );
494 IXMLDOMNode* parent = NULL;
495 HRESULT hr;
497 TRACE("(%p)->(%p)\n", This, dtName);
499 if (!dtName)
500 return E_INVALIDARG;
502 hr = IXMLDOMText_get_parentNode(iface, &parent);
504 if (hr == S_OK)
506 hr = IXMLDOMNode_put_dataType(parent, dtName);
507 IXMLDOMNode_Release(parent);
509 else
511 hr = S_FALSE;
514 return hr;
517 static HRESULT WINAPI domtext_get_xml(
518 IXMLDOMText *iface,
519 BSTR* p)
521 domtext *This = impl_from_IXMLDOMText( iface );
523 TRACE("(%p)->(%p)\n", This, p);
525 return node_get_xml(&This->node, TRUE, p);
528 static HRESULT WINAPI domtext_transformNode(
529 IXMLDOMText *iface,
530 IXMLDOMNode *node, BSTR *p)
532 domtext *This = impl_from_IXMLDOMText( iface );
533 TRACE("(%p)->(%p %p)\n", This, node, p);
534 return node_transform_node(&This->node, node, p);
537 static HRESULT WINAPI domtext_selectNodes(
538 IXMLDOMText *iface,
539 BSTR p, IXMLDOMNodeList** outList)
541 domtext *This = impl_from_IXMLDOMText( iface );
542 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
543 return node_select_nodes(&This->node, p, outList);
546 static HRESULT WINAPI domtext_selectSingleNode(
547 IXMLDOMText *iface,
548 BSTR p, IXMLDOMNode** outNode)
550 domtext *This = impl_from_IXMLDOMText( iface );
551 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
552 return node_select_singlenode(&This->node, p, outNode);
555 static HRESULT WINAPI domtext_get_parsed(
556 IXMLDOMText *iface,
557 VARIANT_BOOL* isParsed)
559 domtext *This = impl_from_IXMLDOMText( iface );
560 FIXME("(%p)->(%p) stub!\n", This, isParsed);
561 *isParsed = VARIANT_TRUE;
562 return S_OK;
565 static HRESULT WINAPI domtext_get_namespaceURI(
566 IXMLDOMText *iface,
567 BSTR* p)
569 domtext *This = impl_from_IXMLDOMText( iface );
570 TRACE("(%p)->(%p)\n", This, p);
571 return node_get_namespaceURI(&This->node, p);
574 static HRESULT WINAPI domtext_get_prefix(
575 IXMLDOMText *iface,
576 BSTR* prefix)
578 domtext *This = impl_from_IXMLDOMText( iface );
579 TRACE("(%p)->(%p)\n", This, prefix);
580 return return_null_bstr( prefix );
583 static HRESULT WINAPI domtext_get_baseName(
584 IXMLDOMText *iface,
585 BSTR* name)
587 domtext *This = impl_from_IXMLDOMText( iface );
588 TRACE("(%p)->(%p)\n", This, name);
589 return return_null_bstr( name );
592 static HRESULT WINAPI domtext_transformNodeToObject(
593 IXMLDOMText *iface,
594 IXMLDOMNode* domNode, VARIANT var1)
596 domtext *This = impl_from_IXMLDOMText( iface );
597 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
598 return E_NOTIMPL;
601 static HRESULT WINAPI domtext_get_data(
602 IXMLDOMText *iface,
603 BSTR *p)
605 domtext *This = impl_from_IXMLDOMText( iface );
607 if(!p)
608 return E_INVALIDARG;
610 *p = bstr_from_xmlChar(This->node.node->content);
611 return S_OK;
614 static HRESULT WINAPI domtext_put_data(
615 IXMLDOMText *iface,
616 BSTR data)
618 domtext *This = impl_from_IXMLDOMText( iface );
619 BSTR normalized_data = NULL;
620 HRESULT hr;
621 size_t i, j;
623 TRACE("(%p)->(%s)\n", This, debugstr_w(data));
625 if (data)
627 /* normalize line endings */
628 normalized_data = SysAllocStringLen(NULL, SysStringLen(data));
629 if (!normalized_data) return E_OUTOFMEMORY;
630 for (i = 0, j = 0; data[i]; i++)
632 if (data[i] == '\r')
634 if (data[i + 1] == '\n') i++; /* change \r\n to just \n */
635 normalized_data[j++] = '\n'; /* change \r by itself to \n */
637 else
638 normalized_data[j++] = data[i];
640 normalized_data[j] = 0;
643 domtext_reset_noenc(This);
644 hr = node_set_content(&This->node, normalized_data);
646 SysFreeString(normalized_data);
647 return hr;
650 static HRESULT WINAPI domtext_get_length(
651 IXMLDOMText *iface,
652 LONG *len)
654 domtext *This = impl_from_IXMLDOMText( iface );
655 HRESULT hr;
656 BSTR data;
658 TRACE("(%p)->(%p)\n", This, len);
660 if(!len)
661 return E_INVALIDARG;
663 hr = IXMLDOMText_get_data(iface, &data);
664 if(hr == S_OK)
666 *len = SysStringLen(data);
667 SysFreeString(data);
670 return hr;
673 static HRESULT WINAPI domtext_substringData(
674 IXMLDOMText *iface,
675 LONG offset, LONG count, BSTR *p)
677 domtext *This = impl_from_IXMLDOMText( iface );
678 HRESULT hr;
679 BSTR data;
681 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
683 if(!p)
684 return E_INVALIDARG;
686 *p = NULL;
687 if(offset < 0 || count < 0)
688 return E_INVALIDARG;
690 if(count == 0)
691 return S_FALSE;
693 hr = IXMLDOMText_get_data(iface, &data);
694 if(hr == S_OK)
696 LONG len = SysStringLen(data);
698 if(offset < len)
700 if(offset + count > len)
701 *p = SysAllocString(&data[offset]);
702 else
703 *p = SysAllocStringLen(&data[offset], count);
705 else
706 hr = S_FALSE;
708 SysFreeString(data);
711 return hr;
714 static HRESULT WINAPI domtext_appendData(
715 IXMLDOMText *iface,
716 BSTR p)
718 domtext *This = impl_from_IXMLDOMText( iface );
719 HRESULT hr;
720 BSTR data;
721 LONG p_len;
723 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
725 /* Nothing to do if NULL or an Empty string passed in. */
726 if((p_len = SysStringLen(p)) == 0) return S_OK;
728 hr = IXMLDOMText_get_data(iface, &data);
729 if(hr == S_OK)
731 LONG len = SysStringLen(data);
732 BSTR str = SysAllocStringLen(NULL, p_len + len);
734 memcpy(str, data, len*sizeof(WCHAR));
735 memcpy(&str[len], p, p_len*sizeof(WCHAR));
736 str[len+p_len] = 0;
738 hr = IXMLDOMText_put_data(iface, str);
740 SysFreeString(str);
741 SysFreeString(data);
744 return hr;
747 static HRESULT WINAPI domtext_insertData(
748 IXMLDOMText *iface,
749 LONG offset, BSTR p)
751 domtext *This = impl_from_IXMLDOMText( iface );
752 HRESULT hr;
753 BSTR data;
754 LONG p_len;
756 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
758 /* If have a NULL or empty string, don't do anything. */
759 if((p_len = SysStringLen(p)) == 0)
760 return S_OK;
762 if(offset < 0)
764 return E_INVALIDARG;
767 hr = IXMLDOMText_get_data(iface, &data);
768 if(hr == S_OK)
770 LONG len = SysStringLen(data);
771 BSTR str;
773 if(len < offset)
775 SysFreeString(data);
776 return E_INVALIDARG;
779 str = SysAllocStringLen(NULL, len + p_len);
780 /* start part, supplied string and end part */
781 memcpy(str, data, offset*sizeof(WCHAR));
782 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
783 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
784 str[len+p_len] = 0;
786 hr = IXMLDOMText_put_data(iface, str);
788 SysFreeString(str);
789 SysFreeString(data);
792 return hr;
795 static HRESULT WINAPI domtext_deleteData(
796 IXMLDOMText *iface,
797 LONG offset, LONG count)
799 HRESULT hr;
800 LONG len = -1;
801 BSTR str;
803 TRACE("(%p)->(%d %d)\n", iface, offset, count);
805 hr = IXMLDOMText_get_length(iface, &len);
806 if(hr != S_OK) return hr;
808 if((offset < 0) || (offset > len) || (count < 0))
809 return E_INVALIDARG;
811 if(len == 0) return S_OK;
813 /* cutting start or end */
814 if((offset == 0) || ((count + offset) >= len))
816 if(offset == 0)
817 IXMLDOMText_substringData(iface, count, len - count, &str);
818 else
819 IXMLDOMText_substringData(iface, 0, offset, &str);
820 hr = IXMLDOMText_put_data(iface, str);
822 else
823 /* cutting from the inside */
825 BSTR str_end;
827 IXMLDOMText_substringData(iface, 0, offset, &str);
828 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
830 hr = IXMLDOMText_put_data(iface, str);
831 if(hr == S_OK)
832 hr = IXMLDOMText_appendData(iface, str_end);
834 SysFreeString(str_end);
837 SysFreeString(str);
839 return hr;
842 static HRESULT WINAPI domtext_replaceData(
843 IXMLDOMText *iface,
844 LONG offset, LONG count, BSTR p)
846 domtext *This = impl_from_IXMLDOMText( iface );
847 HRESULT hr;
849 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
851 hr = IXMLDOMText_deleteData(iface, offset, count);
853 if (hr == S_OK)
854 hr = IXMLDOMText_insertData(iface, offset, p);
856 return hr;
859 static HRESULT WINAPI domtext_splitText(
860 IXMLDOMText *iface,
861 LONG offset, IXMLDOMText **txtNode)
863 domtext *This = impl_from_IXMLDOMText( iface );
864 LONG length = 0;
866 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
868 if (!txtNode || offset < 0) return E_INVALIDARG;
870 *txtNode = NULL;
872 IXMLDOMText_get_length(iface, &length);
874 if (offset > length) return E_INVALIDARG;
875 if (offset == length) return S_FALSE;
877 FIXME("adjacent text nodes are not supported\n");
879 return E_NOTIMPL;
882 static const struct IXMLDOMTextVtbl domtext_vtbl =
884 domtext_QueryInterface,
885 domtext_AddRef,
886 domtext_Release,
887 domtext_GetTypeInfoCount,
888 domtext_GetTypeInfo,
889 domtext_GetIDsOfNames,
890 domtext_Invoke,
891 domtext_get_nodeName,
892 domtext_get_nodeValue,
893 domtext_put_nodeValue,
894 domtext_get_nodeType,
895 domtext_get_parentNode,
896 domtext_get_childNodes,
897 domtext_get_firstChild,
898 domtext_get_lastChild,
899 domtext_get_previousSibling,
900 domtext_get_nextSibling,
901 domtext_get_attributes,
902 domtext_insertBefore,
903 domtext_replaceChild,
904 domtext_removeChild,
905 domtext_appendChild,
906 domtext_hasChildNodes,
907 domtext_get_ownerDocument,
908 domtext_cloneNode,
909 domtext_get_nodeTypeString,
910 domtext_get_text,
911 domtext_put_text,
912 domtext_get_specified,
913 domtext_get_definition,
914 domtext_get_nodeTypedValue,
915 domtext_put_nodeTypedValue,
916 domtext_get_dataType,
917 domtext_put_dataType,
918 domtext_get_xml,
919 domtext_transformNode,
920 domtext_selectNodes,
921 domtext_selectSingleNode,
922 domtext_get_parsed,
923 domtext_get_namespaceURI,
924 domtext_get_prefix,
925 domtext_get_baseName,
926 domtext_transformNodeToObject,
927 domtext_get_data,
928 domtext_put_data,
929 domtext_get_length,
930 domtext_substringData,
931 domtext_appendData,
932 domtext_insertData,
933 domtext_deleteData,
934 domtext_replaceData,
935 domtext_splitText
938 static const tid_t domtext_iface_tids[] = {
939 IXMLDOMText_tid,
943 static dispex_static_data_t domtext_dispex = {
944 NULL,
945 IXMLDOMText_tid,
946 NULL,
947 domtext_iface_tids
950 IUnknown* create_text( xmlNodePtr text )
952 domtext *This;
954 This = heap_alloc( sizeof *This );
955 if ( !This )
956 return NULL;
958 This->IXMLDOMText_iface.lpVtbl = &domtext_vtbl;
959 This->ref = 1;
961 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMText_iface, &domtext_dispex);
963 return (IUnknown*)&This->IXMLDOMText_iface;
966 #endif