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 );
259 TRACE("(%p)->(%p)\n", This, outList);
261 return node_get_child_nodes(&This->node, outList);
264 static HRESULT WINAPI domtext_get_firstChild(
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(
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(
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(
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(
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(
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(
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(
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(
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(
364 domtext *This = impl_from_IXMLDOMText( iface );
365 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
368 static HRESULT WINAPI domtext_get_ownerDocument(
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(
378 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
380 domtext *This = impl_from_IXMLDOMText( iface );
381 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
384 static HRESULT WINAPI domtext_get_nodeTypeString(
388 domtext *This = impl_from_IXMLDOMText( iface );
389 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
392 static HRESULT WINAPI domtext_get_text(
396 domtext *This = impl_from_IXMLDOMText( iface );
397 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
400 static HRESULT WINAPI domtext_put_text(
404 domtext *This = impl_from_IXMLDOMText( iface );
405 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
406 return node_put_text( &This->node, p );
409 static HRESULT WINAPI domtext_get_specified(
413 domtext *This = impl_from_IXMLDOMText( iface );
414 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
417 static HRESULT WINAPI domtext_get_definition(
419 IXMLDOMNode** domNode)
421 domtext *This = impl_from_IXMLDOMText( iface );
422 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
425 static HRESULT WINAPI domtext_get_nodeTypedValue(
429 domtext *This = impl_from_IXMLDOMText( iface );
430 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
433 static HRESULT WINAPI domtext_put_nodeTypedValue(
437 domtext *This = impl_from_IXMLDOMText( iface );
438 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
441 static HRESULT WINAPI domtext_get_dataType(
445 domtext *This = impl_from_IXMLDOMText( iface );
446 TRACE("(%p)->(%p)\n", This, typename);
447 return return_null_var( typename );
450 static HRESULT WINAPI domtext_put_dataType(
454 domtext *This = impl_from_IXMLDOMText( iface );
455 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
458 static HRESULT WINAPI domtext_get_xml(
462 domtext *This = impl_from_IXMLDOMText( iface );
463 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
466 static HRESULT WINAPI domtext_transformNode(
468 IXMLDOMNode* domNode, BSTR* p)
470 domtext *This = impl_from_IXMLDOMText( iface );
471 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
474 static HRESULT WINAPI domtext_selectNodes(
476 BSTR p, IXMLDOMNodeList** outList)
478 domtext *This = impl_from_IXMLDOMText( iface );
479 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
482 static HRESULT WINAPI domtext_selectSingleNode(
484 BSTR p, IXMLDOMNode** outNode)
486 domtext *This = impl_from_IXMLDOMText( iface );
487 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
490 static HRESULT WINAPI domtext_get_parsed(
494 domtext *This = impl_from_IXMLDOMText( iface );
495 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
498 static HRESULT WINAPI domtext_get_namespaceURI(
502 domtext *This = impl_from_IXMLDOMText( iface );
503 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
506 static HRESULT WINAPI domtext_get_prefix(
510 domtext *This = impl_from_IXMLDOMText( iface );
511 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
514 static HRESULT WINAPI domtext_get_baseName(
518 domtext *This = impl_from_IXMLDOMText( iface );
519 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
522 static HRESULT WINAPI domtext_transformNodeToObject(
524 IXMLDOMNode* domNode, VARIANT var1)
526 domtext *This = impl_from_IXMLDOMText( iface );
527 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
530 static HRESULT WINAPI domtext_get_data(
534 domtext *This = impl_from_IXMLDOMText( iface );
539 *p = bstr_from_xmlChar(This->node.node->content);
543 static HRESULT WINAPI domtext_put_data(
547 domtext *This = impl_from_IXMLDOMText( iface );
550 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
552 V_VT(&val) = VT_BSTR;
554 return node_put_value(&This->node, &val);
557 static HRESULT WINAPI domtext_get_length(
561 domtext *This = impl_from_IXMLDOMText( iface );
565 TRACE("(%p)->(%p)\n", This, len);
570 hr = IXMLDOMText_get_data(iface, &data);
573 *len = SysStringLen(data);
580 static HRESULT WINAPI domtext_substringData(
582 LONG offset, LONG count, BSTR *p)
584 domtext *This = impl_from_IXMLDOMText( iface );
588 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
594 if(offset < 0 || count < 0)
600 hr = IXMLDOMText_get_data(iface, &data);
603 LONG len = SysStringLen(data);
607 if(offset + count > len)
608 *p = SysAllocString(&data[offset]);
610 *p = SysAllocStringLen(&data[offset], count);
621 static HRESULT WINAPI domtext_appendData(
625 domtext *This = impl_from_IXMLDOMText( iface );
630 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
632 /* Nothing to do if NULL or an Empty string passed in. */
633 if((p_len = SysStringLen(p)) == 0) return S_OK;
635 hr = IXMLDOMText_get_data(iface, &data);
638 LONG len = SysStringLen(data);
639 BSTR str = SysAllocStringLen(NULL, p_len + len);
641 memcpy(str, data, len*sizeof(WCHAR));
642 memcpy(&str[len], p, p_len*sizeof(WCHAR));
645 hr = IXMLDOMText_put_data(iface, str);
654 static HRESULT WINAPI domtext_insertData(
658 domtext *This = impl_from_IXMLDOMText( iface );
663 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
665 /* If have a NULL or empty string, don't do anything. */
666 if((p_len = SysStringLen(p)) == 0)
674 hr = IXMLDOMText_get_data(iface, &data);
677 LONG len = SysStringLen(data);
686 str = SysAllocStringLen(NULL, len + p_len);
687 /* start part, supplied string and end part */
688 memcpy(str, data, offset*sizeof(WCHAR));
689 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
690 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
693 hr = IXMLDOMText_put_data(iface, str);
702 static HRESULT WINAPI domtext_deleteData(
704 LONG offset, LONG count)
710 TRACE("(%p)->(%d %d)\n", iface, offset, count);
712 hr = IXMLDOMText_get_length(iface, &len);
713 if(hr != S_OK) return hr;
715 if((offset < 0) || (offset > len) || (count < 0))
718 if(len == 0) return S_OK;
720 /* cutting start or end */
721 if((offset == 0) || ((count + offset) >= len))
724 IXMLDOMText_substringData(iface, count, len - count, &str);
726 IXMLDOMText_substringData(iface, 0, offset, &str);
727 hr = IXMLDOMText_put_data(iface, str);
730 /* cutting from the inside */
734 IXMLDOMText_substringData(iface, 0, offset, &str);
735 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
737 hr = IXMLDOMText_put_data(iface, str);
739 hr = IXMLDOMText_appendData(iface, str_end);
741 SysFreeString(str_end);
749 static HRESULT WINAPI domtext_replaceData(
751 LONG offset, LONG count, BSTR p)
753 domtext *This = impl_from_IXMLDOMText( iface );
756 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
758 hr = IXMLDOMText_deleteData(iface, offset, count);
761 hr = IXMLDOMText_insertData(iface, offset, p);
766 static HRESULT WINAPI domtext_splitText(
768 LONG offset, IXMLDOMText **txtNode)
770 domtext *This = impl_from_IXMLDOMText( iface );
773 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
775 if (!txtNode || offset < 0) return E_INVALIDARG;
779 IXMLDOMText_get_length(iface, &length);
781 if (offset > length) return E_INVALIDARG;
782 if (offset == length) return S_FALSE;
784 FIXME("adjacent text nodes are not supported\n");
789 static const struct IXMLDOMTextVtbl domtext_vtbl =
791 domtext_QueryInterface,
794 domtext_GetTypeInfoCount,
796 domtext_GetIDsOfNames,
798 domtext_get_nodeName,
799 domtext_get_nodeValue,
800 domtext_put_nodeValue,
801 domtext_get_nodeType,
802 domtext_get_parentNode,
803 domtext_get_childNodes,
804 domtext_get_firstChild,
805 domtext_get_lastChild,
806 domtext_get_previousSibling,
807 domtext_get_nextSibling,
808 domtext_get_attributes,
809 domtext_insertBefore,
810 domtext_replaceChild,
813 domtext_hasChildNodes,
814 domtext_get_ownerDocument,
816 domtext_get_nodeTypeString,
819 domtext_get_specified,
820 domtext_get_definition,
821 domtext_get_nodeTypedValue,
822 domtext_put_nodeTypedValue,
823 domtext_get_dataType,
824 domtext_put_dataType,
826 domtext_transformNode,
828 domtext_selectSingleNode,
830 domtext_get_namespaceURI,
832 domtext_get_baseName,
833 domtext_transformNodeToObject,
837 domtext_substringData,
845 IUnknown* create_text( xmlNodePtr text )
849 This = heap_alloc( sizeof *This );
853 This->lpVtbl = &domtext_vtbl;
856 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->lpVtbl, NULL);
858 return (IUnknown*) &This->lpVtbl;