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 const struct IXMLDOMTextVtbl *lpVtbl;
48 static inline domtext *impl_from_IXMLDOMText( IXMLDOMText *iface )
50 return (domtext *)((char*)iface - FIELD_OFFSET(domtext, lpVtbl));
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_IDispatch ) ||
64 IsEqualGUID( riid, &IID_IUnknown ) )
68 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
70 *ppvObject = IXMLDOMNode_from_impl(&This->node);
72 else if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
73 IsEqualGUID( riid, &IID_IXMLDOMCDATASection ) )
75 /* IXMLDOMText is known to be correct in not implementing these */
76 TRACE("Unsupported interface\n");
81 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
85 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
89 static ULONG WINAPI domtext_AddRef(
92 domtext *This = impl_from_IXMLDOMText( iface );
93 return InterlockedIncrement( &This->ref );
96 static ULONG WINAPI domtext_Release(
99 domtext *This = impl_from_IXMLDOMText( iface );
102 ref = InterlockedDecrement( &This->ref );
105 destroy_xmlnode(&This->node);
112 static HRESULT WINAPI domtext_GetTypeInfoCount(
116 domtext *This = impl_from_IXMLDOMText( iface );
118 TRACE("(%p)->(%p)\n", This, pctinfo);
125 static HRESULT WINAPI domtext_GetTypeInfo(
127 UINT iTInfo, LCID lcid,
128 ITypeInfo** ppTInfo )
130 domtext *This = impl_from_IXMLDOMText( iface );
133 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
135 hr = get_typeinfo(IXMLDOMText_tid, ppTInfo);
140 static HRESULT WINAPI domtext_GetIDsOfNames(
142 REFIID riid, LPOLESTR* rgszNames,
143 UINT cNames, LCID lcid, DISPID* rgDispId )
145 domtext *This = impl_from_IXMLDOMText( iface );
149 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
152 if(!rgszNames || cNames == 0 || !rgDispId)
155 hr = get_typeinfo(IXMLDOMText_tid, &typeinfo);
158 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
159 ITypeInfo_Release(typeinfo);
165 static HRESULT WINAPI domtext_Invoke(
167 DISPID dispIdMember, REFIID riid, LCID lcid,
168 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
169 EXCEPINFO* pExcepInfo, UINT* puArgErr )
171 domtext *This = impl_from_IXMLDOMText( iface );
175 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
176 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
178 hr = get_typeinfo(IXMLDOMText_tid, &typeinfo);
181 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
182 pVarResult, pExcepInfo, puArgErr);
183 ITypeInfo_Release(typeinfo);
189 static HRESULT WINAPI domtext_get_nodeName(
193 domtext *This = impl_from_IXMLDOMText( iface );
194 return IXMLDOMNode_get_nodeName( IXMLDOMNode_from_impl(&This->node), p );
197 static HRESULT WINAPI domtext_get_nodeValue(
201 domtext *This = impl_from_IXMLDOMText( iface );
202 return IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
205 static HRESULT WINAPI domtext_put_nodeValue(
209 domtext *This = impl_from_IXMLDOMText( iface );
210 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
213 static HRESULT WINAPI domtext_get_nodeType(
215 DOMNodeType* domNodeType )
217 domtext *This = impl_from_IXMLDOMText( iface );
218 return IXMLDOMNode_get_nodeType( IXMLDOMNode_from_impl(&This->node), domNodeType );
221 static HRESULT WINAPI domtext_get_parentNode(
223 IXMLDOMNode** parent )
225 domtext *This = impl_from_IXMLDOMText( iface );
226 return IXMLDOMNode_get_parentNode( IXMLDOMNode_from_impl(&This->node), parent );
229 static HRESULT WINAPI domtext_get_childNodes(
231 IXMLDOMNodeList** outList)
233 domtext *This = impl_from_IXMLDOMText( iface );
234 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
237 static HRESULT WINAPI domtext_get_firstChild(
239 IXMLDOMNode** domNode)
241 domtext *This = impl_from_IXMLDOMText( iface );
242 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
245 static HRESULT WINAPI domtext_get_lastChild(
247 IXMLDOMNode** domNode)
249 domtext *This = impl_from_IXMLDOMText( iface );
250 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
253 static HRESULT WINAPI domtext_get_previousSibling(
255 IXMLDOMNode** domNode)
257 domtext *This = impl_from_IXMLDOMText( iface );
258 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
261 static HRESULT WINAPI domtext_get_nextSibling(
263 IXMLDOMNode** domNode)
265 domtext *This = impl_from_IXMLDOMText( iface );
266 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
269 static HRESULT WINAPI domtext_get_attributes(
271 IXMLDOMNamedNodeMap** attributeMap)
273 domtext *This = impl_from_IXMLDOMText( iface );
274 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
277 static HRESULT WINAPI domtext_insertBefore(
279 IXMLDOMNode* newNode, VARIANT var1,
280 IXMLDOMNode** outOldNode)
282 domtext *This = impl_from_IXMLDOMText( iface );
283 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
286 static HRESULT WINAPI domtext_replaceChild(
288 IXMLDOMNode* newNode,
289 IXMLDOMNode* oldNode,
290 IXMLDOMNode** outOldNode)
292 domtext *This = impl_from_IXMLDOMText( iface );
293 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
296 static HRESULT WINAPI domtext_removeChild(
298 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
300 domtext *This = impl_from_IXMLDOMText( iface );
301 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
304 static HRESULT WINAPI domtext_appendChild(
306 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
308 domtext *This = impl_from_IXMLDOMText( iface );
309 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
312 static HRESULT WINAPI domtext_hasChildNodes(
316 domtext *This = impl_from_IXMLDOMText( iface );
317 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
320 static HRESULT WINAPI domtext_get_ownerDocument(
322 IXMLDOMDocument** domDocument)
324 domtext *This = impl_from_IXMLDOMText( iface );
325 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
328 static HRESULT WINAPI domtext_cloneNode(
330 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
332 domtext *This = impl_from_IXMLDOMText( iface );
333 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
336 static HRESULT WINAPI domtext_get_nodeTypeString(
340 domtext *This = impl_from_IXMLDOMText( iface );
341 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
344 static HRESULT WINAPI domtext_get_text(
348 domtext *This = impl_from_IXMLDOMText( iface );
349 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
352 static HRESULT WINAPI domtext_put_text(
356 domtext *This = impl_from_IXMLDOMText( iface );
357 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
360 static HRESULT WINAPI domtext_get_specified(
364 domtext *This = impl_from_IXMLDOMText( iface );
365 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
368 static HRESULT WINAPI domtext_get_definition(
370 IXMLDOMNode** domNode)
372 domtext *This = impl_from_IXMLDOMText( iface );
373 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
376 static HRESULT WINAPI domtext_get_nodeTypedValue(
380 domtext *This = impl_from_IXMLDOMText( iface );
381 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
384 static HRESULT WINAPI domtext_put_nodeTypedValue(
388 domtext *This = impl_from_IXMLDOMText( iface );
389 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
392 static HRESULT WINAPI domtext_get_dataType(
396 domtext *This = impl_from_IXMLDOMText( iface );
397 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
400 static HRESULT WINAPI domtext_put_dataType(
404 domtext *This = impl_from_IXMLDOMText( iface );
405 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
408 static HRESULT WINAPI domtext_get_xml(
412 domtext *This = impl_from_IXMLDOMText( iface );
413 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
416 static HRESULT WINAPI domtext_transformNode(
418 IXMLDOMNode* domNode, BSTR* p)
420 domtext *This = impl_from_IXMLDOMText( iface );
421 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
424 static HRESULT WINAPI domtext_selectNodes(
426 BSTR p, IXMLDOMNodeList** outList)
428 domtext *This = impl_from_IXMLDOMText( iface );
429 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
432 static HRESULT WINAPI domtext_selectSingleNode(
434 BSTR p, IXMLDOMNode** outNode)
436 domtext *This = impl_from_IXMLDOMText( iface );
437 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
440 static HRESULT WINAPI domtext_get_parsed(
444 domtext *This = impl_from_IXMLDOMText( iface );
445 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
448 static HRESULT WINAPI domtext_get_namespaceURI(
452 domtext *This = impl_from_IXMLDOMText( iface );
453 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
456 static HRESULT WINAPI domtext_get_prefix(
460 domtext *This = impl_from_IXMLDOMText( iface );
461 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
464 static HRESULT WINAPI domtext_get_baseName(
468 domtext *This = impl_from_IXMLDOMText( iface );
469 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
472 static HRESULT WINAPI domtext_transformNodeToObject(
474 IXMLDOMNode* domNode, VARIANT var1)
476 domtext *This = impl_from_IXMLDOMText( iface );
477 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
480 static HRESULT WINAPI domtext_get_data(
484 domtext *This = impl_from_IXMLDOMText( iface );
491 hr = IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), &vRet );
500 static HRESULT WINAPI domtext_put_data(
504 domtext *This = impl_from_IXMLDOMText( iface );
507 TRACE("%p %s\n", This, debugstr_w(data) );
509 V_VT(&val) = VT_BSTR;
512 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), val );
515 static HRESULT WINAPI domtext_get_length(
519 domtext *This = impl_from_IXMLDOMText( iface );
523 TRACE("%p %p\n", This, len);
528 hr = IXMLDOMText_get_data(iface, &data);
531 *len = SysStringLen(data);
538 static HRESULT WINAPI domtext_substringData(
540 LONG offset, LONG count, BSTR *p)
542 domtext *This = impl_from_IXMLDOMText( iface );
545 HRESULT hr = S_FALSE;
547 TRACE("%p\n", iface);
553 if(offset < 0 || count < 0)
559 pContent = xmlNodeGetContent(This->node.node);
562 nLength = xmlStrlen(pContent);
564 if( offset < nLength)
566 BSTR sContent = bstr_from_xmlChar(pContent);
567 if(offset + count > nLength)
568 *p = SysAllocString(&sContent[offset]);
570 *p = SysAllocStringLen(&sContent[offset], count);
572 SysFreeString(sContent);
582 static HRESULT WINAPI domtext_appendData(
586 domtext *This = impl_from_IXMLDOMText( iface );
591 TRACE("%p %s\n", This, debugstr_w(p));
593 /* Nothing to do if NULL or an Empty string passed in. */
594 if((p_len = SysStringLen(p)) == 0) return S_OK;
596 hr = IXMLDOMText_get_data(iface, &data);
599 LONG len = SysStringLen(data);
600 BSTR str = SysAllocStringLen(NULL, p_len + len);
602 memcpy(str, data, len*sizeof(WCHAR));
603 memcpy(&str[len], p, p_len*sizeof(WCHAR));
606 hr = IXMLDOMText_put_data(iface, str);
615 static HRESULT WINAPI domtext_insertData(
619 domtext *This = impl_from_IXMLDOMText( iface );
624 TRACE("%p %d %s\n", This, offset, debugstr_w(p));
626 /* If have a NULL or empty string, don't do anything. */
627 if((p_len = SysStringLen(p)) == 0)
635 hr = IXMLDOMText_get_data(iface, &data);
638 LONG len = SysStringLen(data);
647 str = SysAllocStringLen(NULL, len + p_len);
648 /* start part, supplied string and end part */
649 memcpy(str, data, offset*sizeof(WCHAR));
650 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
651 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
654 hr = IXMLDOMText_put_data(iface, str);
663 static HRESULT WINAPI domtext_deleteData(
665 LONG offset, LONG count)
671 TRACE("%p %d %d\n", iface, offset, count);
673 hr = IXMLDOMText_get_length(iface, &len);
674 if(hr != S_OK) return hr;
676 if((offset < 0) || (offset > len) || (count < 0))
679 if(len == 0) return S_OK;
681 /* cutting start or end */
682 if((offset == 0) || ((count + offset) >= len))
685 IXMLDOMText_substringData(iface, count, len - count, &str);
687 IXMLDOMText_substringData(iface, 0, offset, &str);
688 hr = IXMLDOMText_put_data(iface, str);
691 /* cutting from the inside */
695 IXMLDOMText_substringData(iface, 0, offset, &str);
696 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
698 hr = IXMLDOMText_put_data(iface, str);
700 hr = IXMLDOMText_appendData(iface, str_end);
702 SysFreeString(str_end);
710 static HRESULT WINAPI domtext_replaceData(
712 LONG offset, LONG count, BSTR p)
714 domtext *This = impl_from_IXMLDOMText( iface );
717 TRACE("%p %d %d %s\n", This, offset, count, debugstr_w(p));
719 hr = IXMLDOMText_deleteData(iface, offset, count);
722 hr = IXMLDOMText_insertData(iface, offset, p);
727 static HRESULT WINAPI domtext_splitText(
729 LONG offset, IXMLDOMText **txtNode)
736 static const struct IXMLDOMTextVtbl domtext_vtbl =
738 domtext_QueryInterface,
741 domtext_GetTypeInfoCount,
743 domtext_GetIDsOfNames,
745 domtext_get_nodeName,
746 domtext_get_nodeValue,
747 domtext_put_nodeValue,
748 domtext_get_nodeType,
749 domtext_get_parentNode,
750 domtext_get_childNodes,
751 domtext_get_firstChild,
752 domtext_get_lastChild,
753 domtext_get_previousSibling,
754 domtext_get_nextSibling,
755 domtext_get_attributes,
756 domtext_insertBefore,
757 domtext_replaceChild,
760 domtext_hasChildNodes,
761 domtext_get_ownerDocument,
763 domtext_get_nodeTypeString,
766 domtext_get_specified,
767 domtext_get_definition,
768 domtext_get_nodeTypedValue,
769 domtext_put_nodeTypedValue,
770 domtext_get_dataType,
771 domtext_put_dataType,
773 domtext_transformNode,
775 domtext_selectSingleNode,
777 domtext_get_namespaceURI,
779 domtext_get_baseName,
780 domtext_transformNodeToObject,
784 domtext_substringData,
792 IUnknown* create_text( xmlNodePtr text )
796 This = heap_alloc( sizeof *This );
800 This->lpVtbl = &domtext_vtbl;
803 init_xmlnode(&This->node, text, (IUnknown*)&This->lpVtbl, NULL);
805 return (IUnknown*) &This->lpVtbl;