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_IXMLDOMNode ) ||
64 IsEqualGUID( riid, &IID_IDispatch ) ||
65 IsEqualGUID( riid, &IID_IUnknown ) )
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");
82 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
86 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
90 static ULONG WINAPI domtext_AddRef(
93 domtext *This = impl_from_IXMLDOMText( iface );
94 return InterlockedIncrement( &This->ref );
97 static ULONG WINAPI domtext_Release(
100 domtext *This = impl_from_IXMLDOMText( iface );
103 ref = InterlockedDecrement( &This->ref );
106 destroy_xmlnode(&This->node);
113 static HRESULT WINAPI domtext_GetTypeInfoCount(
117 domtext *This = impl_from_IXMLDOMText( iface );
119 TRACE("(%p)->(%p)\n", This, pctinfo);
126 static HRESULT WINAPI domtext_GetTypeInfo(
128 UINT iTInfo, LCID lcid,
129 ITypeInfo** ppTInfo )
131 domtext *This = impl_from_IXMLDOMText( iface );
134 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
136 hr = get_typeinfo(IXMLDOMText_tid, ppTInfo);
141 static HRESULT WINAPI domtext_GetIDsOfNames(
143 REFIID riid, LPOLESTR* rgszNames,
144 UINT cNames, LCID lcid, DISPID* rgDispId )
146 domtext *This = impl_from_IXMLDOMText( iface );
150 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
153 if(!rgszNames || cNames == 0 || !rgDispId)
156 hr = get_typeinfo(IXMLDOMText_tid, &typeinfo);
159 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
160 ITypeInfo_Release(typeinfo);
166 static HRESULT WINAPI domtext_Invoke(
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 );
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);
182 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
183 pVarResult, pExcepInfo, puArgErr);
184 ITypeInfo_Release(typeinfo);
190 static HRESULT WINAPI domtext_get_nodeName(
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(
207 domtext *This = impl_from_IXMLDOMText( iface );
209 TRACE("(%p)->(%p)\n", This, value);
214 V_VT(value) = VT_BSTR;
215 V_BSTR(value) = bstr_from_xmlChar(This->node.node->content);
219 static HRESULT WINAPI domtext_put_nodeValue(
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(
232 DOMNodeType* domNodeType )
234 domtext *This = impl_from_IXMLDOMText( iface );
236 TRACE("(%p)->(%p)\n", This, domNodeType);
238 *domNodeType = NODE_TEXT;
242 static HRESULT WINAPI domtext_get_parentNode(
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(
255 IXMLDOMNodeList** outList)
257 domtext *This = impl_from_IXMLDOMText( iface );
258 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
261 static HRESULT WINAPI domtext_get_firstChild(
263 IXMLDOMNode** domNode)
265 domtext *This = impl_from_IXMLDOMText( iface );
266 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
269 static HRESULT WINAPI domtext_get_lastChild(
271 IXMLDOMNode** domNode)
273 domtext *This = impl_from_IXMLDOMText( iface );
274 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
277 static HRESULT WINAPI domtext_get_previousSibling(
279 IXMLDOMNode** domNode)
281 domtext *This = impl_from_IXMLDOMText( iface );
282 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
285 static HRESULT WINAPI domtext_get_nextSibling(
287 IXMLDOMNode** domNode)
289 domtext *This = impl_from_IXMLDOMText( iface );
290 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
293 static HRESULT WINAPI domtext_get_attributes(
295 IXMLDOMNamedNodeMap** attributeMap)
297 domtext *This = impl_from_IXMLDOMText( iface );
298 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
301 static HRESULT WINAPI domtext_insertBefore(
303 IXMLDOMNode* newNode, VARIANT var1,
304 IXMLDOMNode** outOldNode)
306 domtext *This = impl_from_IXMLDOMText( iface );
307 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
310 static HRESULT WINAPI domtext_replaceChild(
312 IXMLDOMNode* newNode,
313 IXMLDOMNode* oldNode,
314 IXMLDOMNode** outOldNode)
316 domtext *This = impl_from_IXMLDOMText( iface );
317 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
320 static HRESULT WINAPI domtext_removeChild(
322 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
324 domtext *This = impl_from_IXMLDOMText( iface );
325 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
328 static HRESULT WINAPI domtext_appendChild(
330 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
332 domtext *This = impl_from_IXMLDOMText( iface );
333 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
336 static HRESULT WINAPI domtext_hasChildNodes(
340 domtext *This = impl_from_IXMLDOMText( iface );
341 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
344 static HRESULT WINAPI domtext_get_ownerDocument(
346 IXMLDOMDocument** domDocument)
348 domtext *This = impl_from_IXMLDOMText( iface );
349 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
352 static HRESULT WINAPI domtext_cloneNode(
354 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
356 domtext *This = impl_from_IXMLDOMText( iface );
357 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
360 static HRESULT WINAPI domtext_get_nodeTypeString(
364 domtext *This = impl_from_IXMLDOMText( iface );
365 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
368 static HRESULT WINAPI domtext_get_text(
372 domtext *This = impl_from_IXMLDOMText( iface );
373 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
376 static HRESULT WINAPI domtext_put_text(
380 domtext *This = impl_from_IXMLDOMText( iface );
381 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
384 static HRESULT WINAPI domtext_get_specified(
388 domtext *This = impl_from_IXMLDOMText( iface );
389 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
392 static HRESULT WINAPI domtext_get_definition(
394 IXMLDOMNode** domNode)
396 domtext *This = impl_from_IXMLDOMText( iface );
397 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
400 static HRESULT WINAPI domtext_get_nodeTypedValue(
404 domtext *This = impl_from_IXMLDOMText( iface );
405 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
408 static HRESULT WINAPI domtext_put_nodeTypedValue(
412 domtext *This = impl_from_IXMLDOMText( iface );
413 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
416 static HRESULT WINAPI domtext_get_dataType(
420 domtext *This = impl_from_IXMLDOMText( iface );
421 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
424 static HRESULT WINAPI domtext_put_dataType(
428 domtext *This = impl_from_IXMLDOMText( iface );
429 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
432 static HRESULT WINAPI domtext_get_xml(
436 domtext *This = impl_from_IXMLDOMText( iface );
437 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
440 static HRESULT WINAPI domtext_transformNode(
442 IXMLDOMNode* domNode, BSTR* p)
444 domtext *This = impl_from_IXMLDOMText( iface );
445 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
448 static HRESULT WINAPI domtext_selectNodes(
450 BSTR p, IXMLDOMNodeList** outList)
452 domtext *This = impl_from_IXMLDOMText( iface );
453 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
456 static HRESULT WINAPI domtext_selectSingleNode(
458 BSTR p, IXMLDOMNode** outNode)
460 domtext *This = impl_from_IXMLDOMText( iface );
461 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
464 static HRESULT WINAPI domtext_get_parsed(
468 domtext *This = impl_from_IXMLDOMText( iface );
469 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
472 static HRESULT WINAPI domtext_get_namespaceURI(
476 domtext *This = impl_from_IXMLDOMText( iface );
477 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
480 static HRESULT WINAPI domtext_get_prefix(
484 domtext *This = impl_from_IXMLDOMText( iface );
485 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
488 static HRESULT WINAPI domtext_get_baseName(
492 domtext *This = impl_from_IXMLDOMText( iface );
493 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
496 static HRESULT WINAPI domtext_transformNodeToObject(
498 IXMLDOMNode* domNode, VARIANT var1)
500 domtext *This = impl_from_IXMLDOMText( iface );
501 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
504 static HRESULT WINAPI domtext_get_data(
508 domtext *This = impl_from_IXMLDOMText( iface );
513 *p = bstr_from_xmlChar(This->node.node->content);
517 static HRESULT WINAPI domtext_put_data(
521 domtext *This = impl_from_IXMLDOMText( iface );
524 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
526 V_VT(&val) = VT_BSTR;
528 return node_put_value(&This->node, &val);
531 static HRESULT WINAPI domtext_get_length(
535 domtext *This = impl_from_IXMLDOMText( iface );
539 TRACE("(%p)->(%p)\n", This, len);
544 hr = IXMLDOMText_get_data(iface, &data);
547 *len = SysStringLen(data);
554 static HRESULT WINAPI domtext_substringData(
556 LONG offset, LONG count, BSTR *p)
558 domtext *This = impl_from_IXMLDOMText( iface );
562 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
568 if(offset < 0 || count < 0)
574 hr = IXMLDOMText_get_data(iface, &data);
577 LONG len = SysStringLen(data);
581 if(offset + count > len)
582 *p = SysAllocString(&data[offset]);
584 *p = SysAllocStringLen(&data[offset], count);
595 static HRESULT WINAPI domtext_appendData(
599 domtext *This = impl_from_IXMLDOMText( iface );
604 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
606 /* Nothing to do if NULL or an Empty string passed in. */
607 if((p_len = SysStringLen(p)) == 0) return S_OK;
609 hr = IXMLDOMText_get_data(iface, &data);
612 LONG len = SysStringLen(data);
613 BSTR str = SysAllocStringLen(NULL, p_len + len);
615 memcpy(str, data, len*sizeof(WCHAR));
616 memcpy(&str[len], p, p_len*sizeof(WCHAR));
619 hr = IXMLDOMText_put_data(iface, str);
628 static HRESULT WINAPI domtext_insertData(
632 domtext *This = impl_from_IXMLDOMText( iface );
637 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
639 /* If have a NULL or empty string, don't do anything. */
640 if((p_len = SysStringLen(p)) == 0)
648 hr = IXMLDOMText_get_data(iface, &data);
651 LONG len = SysStringLen(data);
660 str = SysAllocStringLen(NULL, len + p_len);
661 /* start part, supplied string and end part */
662 memcpy(str, data, offset*sizeof(WCHAR));
663 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
664 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
667 hr = IXMLDOMText_put_data(iface, str);
676 static HRESULT WINAPI domtext_deleteData(
678 LONG offset, LONG count)
684 TRACE("(%p)->(%d %d)\n", iface, offset, count);
686 hr = IXMLDOMText_get_length(iface, &len);
687 if(hr != S_OK) return hr;
689 if((offset < 0) || (offset > len) || (count < 0))
692 if(len == 0) return S_OK;
694 /* cutting start or end */
695 if((offset == 0) || ((count + offset) >= len))
698 IXMLDOMText_substringData(iface, count, len - count, &str);
700 IXMLDOMText_substringData(iface, 0, offset, &str);
701 hr = IXMLDOMText_put_data(iface, str);
704 /* cutting from the inside */
708 IXMLDOMText_substringData(iface, 0, offset, &str);
709 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
711 hr = IXMLDOMText_put_data(iface, str);
713 hr = IXMLDOMText_appendData(iface, str_end);
715 SysFreeString(str_end);
723 static HRESULT WINAPI domtext_replaceData(
725 LONG offset, LONG count, BSTR p)
727 domtext *This = impl_from_IXMLDOMText( iface );
730 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
732 hr = IXMLDOMText_deleteData(iface, offset, count);
735 hr = IXMLDOMText_insertData(iface, offset, p);
740 static HRESULT WINAPI domtext_splitText(
742 LONG offset, IXMLDOMText **txtNode)
744 domtext *This = impl_from_IXMLDOMText( iface );
747 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
749 if (!txtNode || offset < 0) return E_INVALIDARG;
753 IXMLDOMText_get_length(iface, &length);
755 if (offset > length) return E_INVALIDARG;
756 if (offset == length) return S_FALSE;
758 FIXME("adjacent text nodes are not supported\n");
763 static const struct IXMLDOMTextVtbl domtext_vtbl =
765 domtext_QueryInterface,
768 domtext_GetTypeInfoCount,
770 domtext_GetIDsOfNames,
772 domtext_get_nodeName,
773 domtext_get_nodeValue,
774 domtext_put_nodeValue,
775 domtext_get_nodeType,
776 domtext_get_parentNode,
777 domtext_get_childNodes,
778 domtext_get_firstChild,
779 domtext_get_lastChild,
780 domtext_get_previousSibling,
781 domtext_get_nextSibling,
782 domtext_get_attributes,
783 domtext_insertBefore,
784 domtext_replaceChild,
787 domtext_hasChildNodes,
788 domtext_get_ownerDocument,
790 domtext_get_nodeTypeString,
793 domtext_get_specified,
794 domtext_get_definition,
795 domtext_get_nodeTypedValue,
796 domtext_put_nodeTypedValue,
797 domtext_get_dataType,
798 domtext_put_dataType,
800 domtext_transformNode,
802 domtext_selectSingleNode,
804 domtext_get_namespaceURI,
806 domtext_get_baseName,
807 domtext_transformNodeToObject,
811 domtext_substringData,
819 IUnknown* create_text( xmlNodePtr text )
823 This = heap_alloc( sizeof *This );
827 This->lpVtbl = &domtext_vtbl;
830 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->lpVtbl, NULL);
832 return (IUnknown*) &This->lpVtbl;