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
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
38 #include "msxml_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
46 typedef struct _domtext
49 IXMLDOMText IXMLDOMText_iface;
53 static inline domtext *impl_from_IXMLDOMText( IXMLDOMText *iface )
55 return CONTAINING_RECORD(iface, domtext, IXMLDOMText_iface);
58 static HRESULT WINAPI domtext_QueryInterface(
63 domtext *This = impl_from_IXMLDOMText( iface );
64 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
66 if ( IsEqualGUID( riid, &IID_IXMLDOMText ) ||
67 IsEqualGUID( riid, &IID_IXMLDOMCharacterData) ||
68 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
69 IsEqualGUID( riid, &IID_IDispatch ) ||
70 IsEqualGUID( riid, &IID_IUnknown ) )
74 else if(node_query_interface(&This->node, riid, ppvObject))
76 return *ppvObject ? S_OK : E_NOINTERFACE;
80 TRACE("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 ULONG ref = InterlockedIncrement( &This->ref );
94 TRACE("(%p)->(%d)\n", This, ref);
98 static ULONG WINAPI domtext_Release(
101 domtext *This = impl_from_IXMLDOMText( iface );
102 ULONG ref = InterlockedDecrement( &This->ref );
104 TRACE("(%p)->(%d)\n", This, ref);
107 destroy_xmlnode(&This->node);
114 static HRESULT WINAPI domtext_GetTypeInfoCount(
118 domtext *This = impl_from_IXMLDOMText( iface );
119 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
122 static HRESULT WINAPI domtext_GetTypeInfo(
124 UINT iTInfo, LCID lcid,
125 ITypeInfo** ppTInfo )
127 domtext *This = impl_from_IXMLDOMText( iface );
128 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
129 iTInfo, lcid, ppTInfo);
132 static HRESULT WINAPI domtext_GetIDsOfNames(
134 REFIID riid, LPOLESTR* rgszNames,
135 UINT cNames, LCID lcid, DISPID* rgDispId )
137 domtext *This = impl_from_IXMLDOMText( iface );
138 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
139 riid, rgszNames, cNames, lcid, rgDispId);
142 static HRESULT WINAPI domtext_Invoke(
144 DISPID dispIdMember, REFIID riid, LCID lcid,
145 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
146 EXCEPINFO* pExcepInfo, UINT* puArgErr )
148 domtext *This = impl_from_IXMLDOMText( iface );
149 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
150 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
153 static HRESULT WINAPI domtext_get_nodeName(
157 domtext *This = impl_from_IXMLDOMText( iface );
159 static const WCHAR textW[] = {'#','t','e','x','t',0};
161 TRACE("(%p)->(%p)\n", This, p);
163 return return_bstr(textW, p);
166 static HRESULT WINAPI domtext_get_nodeValue(
170 domtext *This = impl_from_IXMLDOMText( iface );
172 TRACE("(%p)->(%p)\n", This, value);
174 return node_get_content(&This->node, value);
177 static HRESULT WINAPI domtext_put_nodeValue(
181 domtext *This = impl_from_IXMLDOMText( iface );
183 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
185 return node_put_value(&This->node, &value);
188 static HRESULT WINAPI domtext_get_nodeType(
190 DOMNodeType* domNodeType )
192 domtext *This = impl_from_IXMLDOMText( iface );
194 TRACE("(%p)->(%p)\n", This, domNodeType);
196 *domNodeType = NODE_TEXT;
200 static HRESULT WINAPI domtext_get_parentNode(
202 IXMLDOMNode** parent )
204 domtext *This = impl_from_IXMLDOMText( iface );
206 TRACE("(%p)->(%p)\n", This, parent);
208 return node_get_parent(&This->node, parent);
211 static HRESULT WINAPI domtext_get_childNodes(
213 IXMLDOMNodeList** outList)
215 domtext *This = impl_from_IXMLDOMText( iface );
217 TRACE("(%p)->(%p)\n", This, outList);
219 return node_get_child_nodes(&This->node, outList);
222 static HRESULT WINAPI domtext_get_firstChild(
224 IXMLDOMNode** domNode)
226 domtext *This = impl_from_IXMLDOMText( iface );
228 TRACE("(%p)->(%p)\n", This, domNode);
230 return return_null_node(domNode);
233 static HRESULT WINAPI domtext_get_lastChild(
235 IXMLDOMNode** domNode)
237 domtext *This = impl_from_IXMLDOMText( iface );
239 TRACE("(%p)->(%p)\n", This, domNode);
241 return return_null_node(domNode);
244 static HRESULT WINAPI domtext_get_previousSibling(
246 IXMLDOMNode** domNode)
248 domtext *This = impl_from_IXMLDOMText( iface );
250 TRACE("(%p)->(%p)\n", This, domNode);
252 return node_get_previous_sibling(&This->node, domNode);
255 static HRESULT WINAPI domtext_get_nextSibling(
257 IXMLDOMNode** domNode)
259 domtext *This = impl_from_IXMLDOMText( iface );
261 TRACE("(%p)->(%p)\n", This, domNode);
263 return node_get_next_sibling(&This->node, domNode);
266 static HRESULT WINAPI domtext_get_attributes(
268 IXMLDOMNamedNodeMap** attributeMap)
270 domtext *This = impl_from_IXMLDOMText( iface );
272 TRACE("(%p)->(%p)\n", This, attributeMap);
274 return return_null_ptr((void**)attributeMap);
277 static HRESULT WINAPI domtext_insertBefore(
279 IXMLDOMNode* newNode, VARIANT refChild,
280 IXMLDOMNode** outOldNode)
282 domtext *This = impl_from_IXMLDOMText( iface );
284 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
286 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
289 static HRESULT WINAPI domtext_replaceChild(
291 IXMLDOMNode* newNode,
292 IXMLDOMNode* oldNode,
293 IXMLDOMNode** outOldNode)
295 domtext *This = impl_from_IXMLDOMText( iface );
297 FIXME("(%p)->(%p %p %p) needs test\n", This, newNode, oldNode, outOldNode);
299 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
302 static HRESULT WINAPI domtext_removeChild(
304 IXMLDOMNode *child, IXMLDOMNode **oldChild)
306 domtext *This = impl_from_IXMLDOMText( iface );
307 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
308 return node_remove_child(&This->node, child, oldChild);
311 static HRESULT WINAPI domtext_appendChild(
313 IXMLDOMNode *child, IXMLDOMNode **outChild)
315 domtext *This = impl_from_IXMLDOMText( iface );
316 TRACE("(%p)->(%p %p)\n", This, child, outChild);
317 return node_append_child(&This->node, child, outChild);
320 static HRESULT WINAPI domtext_hasChildNodes(
324 domtext *This = impl_from_IXMLDOMText( iface );
325 TRACE("(%p)->(%p)\n", This, ret);
326 return node_has_childnodes(&This->node, ret);
329 static HRESULT WINAPI domtext_get_ownerDocument(
331 IXMLDOMDocument **doc)
333 domtext *This = impl_from_IXMLDOMText( iface );
334 TRACE("(%p)->(%p)\n", This, doc);
335 return node_get_owner_doc(&This->node, doc);
338 static HRESULT WINAPI domtext_cloneNode(
340 VARIANT_BOOL deep, IXMLDOMNode** outNode)
342 domtext *This = impl_from_IXMLDOMText( iface );
343 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
344 return node_clone( &This->node, deep, outNode );
347 static HRESULT WINAPI domtext_get_nodeTypeString(
351 domtext *This = impl_from_IXMLDOMText( iface );
352 static const WCHAR textW[] = {'t','e','x','t',0};
354 TRACE("(%p)->(%p)\n", This, p);
356 return return_bstr(textW, p);
359 static HRESULT WINAPI domtext_get_text(
363 domtext *This = impl_from_IXMLDOMText( iface );
364 TRACE("(%p)->(%p)\n", This, p);
365 return node_get_text(&This->node, p);
368 static HRESULT WINAPI domtext_put_text(
372 domtext *This = impl_from_IXMLDOMText( iface );
373 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
374 return node_put_text( &This->node, p );
377 static HRESULT WINAPI domtext_get_specified(
379 VARIANT_BOOL* isSpecified)
381 domtext *This = impl_from_IXMLDOMText( iface );
382 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
383 *isSpecified = VARIANT_TRUE;
387 static HRESULT WINAPI domtext_get_definition(
389 IXMLDOMNode** definitionNode)
391 domtext *This = impl_from_IXMLDOMText( iface );
392 FIXME("(%p)->(%p)\n", This, definitionNode);
396 static HRESULT WINAPI domtext_get_nodeTypedValue(
400 domtext *This = impl_from_IXMLDOMText( iface );
401 IXMLDOMNode* parent = NULL;
404 TRACE("(%p)->(%p)\n", This, var1);
409 hr = IXMLDOMText_get_parentNode(iface, &parent);
413 hr = IXMLDOMNode_get_nodeTypedValue(parent, var1);
414 IXMLDOMNode_Release(parent);
418 V_VT(var1) = VT_NULL;
426 static HRESULT WINAPI domtext_put_nodeTypedValue(
430 domtext *This = impl_from_IXMLDOMText( iface );
431 IXMLDOMNode* parent = NULL;
434 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
436 hr = IXMLDOMText_get_parentNode(iface, &parent);
440 hr = IXMLDOMNode_put_nodeTypedValue(parent, value);
441 IXMLDOMNode_Release(parent);
451 static HRESULT WINAPI domtext_get_dataType(
455 domtext *This = impl_from_IXMLDOMText( iface );
456 IXMLDOMNode* parent = NULL;
459 TRACE("(%p)->(%p)\n", This, dtName);
464 hr = IXMLDOMText_get_parentNode(iface, &parent);
468 hr = IXMLDOMNode_get_dataType(parent, dtName);
469 IXMLDOMNode_Release(parent);
473 V_VT(dtName) = VT_NULL;
474 V_BSTR(dtName) = NULL;
481 static HRESULT WINAPI domtext_put_dataType(
485 domtext *This = impl_from_IXMLDOMText( iface );
486 IXMLDOMNode* parent = NULL;
489 TRACE("(%p)->(%p)\n", This, dtName);
494 hr = IXMLDOMText_get_parentNode(iface, &parent);
498 hr = IXMLDOMNode_put_dataType(parent, dtName);
499 IXMLDOMNode_Release(parent);
509 static HRESULT WINAPI domtext_get_xml(
513 domtext *This = impl_from_IXMLDOMText( iface );
515 TRACE("(%p)->(%p)\n", This, p);
517 return node_get_xml(&This->node, FALSE, p);
520 static HRESULT WINAPI domtext_transformNode(
522 IXMLDOMNode *node, BSTR *p)
524 domtext *This = impl_from_IXMLDOMText( iface );
525 TRACE("(%p)->(%p %p)\n", This, node, p);
526 return node_transform_node(&This->node, node, p);
529 static HRESULT WINAPI domtext_selectNodes(
531 BSTR p, IXMLDOMNodeList** outList)
533 domtext *This = impl_from_IXMLDOMText( iface );
534 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
535 return node_select_nodes(&This->node, p, outList);
538 static HRESULT WINAPI domtext_selectSingleNode(
540 BSTR p, IXMLDOMNode** outNode)
542 domtext *This = impl_from_IXMLDOMText( iface );
543 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
544 return node_select_singlenode(&This->node, p, outNode);
547 static HRESULT WINAPI domtext_get_parsed(
549 VARIANT_BOOL* isParsed)
551 domtext *This = impl_from_IXMLDOMText( iface );
552 FIXME("(%p)->(%p) stub!\n", This, isParsed);
553 *isParsed = VARIANT_TRUE;
557 static HRESULT WINAPI domtext_get_namespaceURI(
561 domtext *This = impl_from_IXMLDOMText( iface );
562 TRACE("(%p)->(%p)\n", This, p);
563 return node_get_namespaceURI(&This->node, p);
566 static HRESULT WINAPI domtext_get_prefix(
570 domtext *This = impl_from_IXMLDOMText( iface );
571 TRACE("(%p)->(%p)\n", This, prefix);
572 return return_null_bstr( prefix );
575 static HRESULT WINAPI domtext_get_baseName(
579 domtext *This = impl_from_IXMLDOMText( iface );
580 TRACE("(%p)->(%p)\n", This, name);
581 return return_null_bstr( name );
584 static HRESULT WINAPI domtext_transformNodeToObject(
586 IXMLDOMNode* domNode, VARIANT var1)
588 domtext *This = impl_from_IXMLDOMText( iface );
589 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
593 static HRESULT WINAPI domtext_get_data(
597 domtext *This = impl_from_IXMLDOMText( iface );
602 *p = bstr_from_xmlChar(This->node.node->content);
606 static HRESULT WINAPI domtext_put_data(
610 domtext *This = impl_from_IXMLDOMText( iface );
611 TRACE("(%p)->(%s)\n", This, debugstr_w(data));
612 return node_set_content(&This->node, data);
615 static HRESULT WINAPI domtext_get_length(
619 domtext *This = impl_from_IXMLDOMText( iface );
623 TRACE("(%p)->(%p)\n", This, len);
628 hr = IXMLDOMText_get_data(iface, &data);
631 *len = SysStringLen(data);
638 static HRESULT WINAPI domtext_substringData(
640 LONG offset, LONG count, BSTR *p)
642 domtext *This = impl_from_IXMLDOMText( iface );
646 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
652 if(offset < 0 || count < 0)
658 hr = IXMLDOMText_get_data(iface, &data);
661 LONG len = SysStringLen(data);
665 if(offset + count > len)
666 *p = SysAllocString(&data[offset]);
668 *p = SysAllocStringLen(&data[offset], count);
679 static HRESULT WINAPI domtext_appendData(
683 domtext *This = impl_from_IXMLDOMText( iface );
688 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
690 /* Nothing to do if NULL or an Empty string passed in. */
691 if((p_len = SysStringLen(p)) == 0) return S_OK;
693 hr = IXMLDOMText_get_data(iface, &data);
696 LONG len = SysStringLen(data);
697 BSTR str = SysAllocStringLen(NULL, p_len + len);
699 memcpy(str, data, len*sizeof(WCHAR));
700 memcpy(&str[len], p, p_len*sizeof(WCHAR));
703 hr = IXMLDOMText_put_data(iface, str);
712 static HRESULT WINAPI domtext_insertData(
716 domtext *This = impl_from_IXMLDOMText( iface );
721 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
723 /* If have a NULL or empty string, don't do anything. */
724 if((p_len = SysStringLen(p)) == 0)
732 hr = IXMLDOMText_get_data(iface, &data);
735 LONG len = SysStringLen(data);
744 str = SysAllocStringLen(NULL, len + p_len);
745 /* start part, supplied string and end part */
746 memcpy(str, data, offset*sizeof(WCHAR));
747 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
748 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
751 hr = IXMLDOMText_put_data(iface, str);
760 static HRESULT WINAPI domtext_deleteData(
762 LONG offset, LONG count)
768 TRACE("(%p)->(%d %d)\n", iface, offset, count);
770 hr = IXMLDOMText_get_length(iface, &len);
771 if(hr != S_OK) return hr;
773 if((offset < 0) || (offset > len) || (count < 0))
776 if(len == 0) return S_OK;
778 /* cutting start or end */
779 if((offset == 0) || ((count + offset) >= len))
782 IXMLDOMText_substringData(iface, count, len - count, &str);
784 IXMLDOMText_substringData(iface, 0, offset, &str);
785 hr = IXMLDOMText_put_data(iface, str);
788 /* cutting from the inside */
792 IXMLDOMText_substringData(iface, 0, offset, &str);
793 IXMLDOMText_substringData(iface, offset + count, len - count, &str_end);
795 hr = IXMLDOMText_put_data(iface, str);
797 hr = IXMLDOMText_appendData(iface, str_end);
799 SysFreeString(str_end);
807 static HRESULT WINAPI domtext_replaceData(
809 LONG offset, LONG count, BSTR p)
811 domtext *This = impl_from_IXMLDOMText( iface );
814 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
816 hr = IXMLDOMText_deleteData(iface, offset, count);
819 hr = IXMLDOMText_insertData(iface, offset, p);
824 static HRESULT WINAPI domtext_splitText(
826 LONG offset, IXMLDOMText **txtNode)
828 domtext *This = impl_from_IXMLDOMText( iface );
831 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
833 if (!txtNode || offset < 0) return E_INVALIDARG;
837 IXMLDOMText_get_length(iface, &length);
839 if (offset > length) return E_INVALIDARG;
840 if (offset == length) return S_FALSE;
842 FIXME("adjacent text nodes are not supported\n");
847 static const struct IXMLDOMTextVtbl domtext_vtbl =
849 domtext_QueryInterface,
852 domtext_GetTypeInfoCount,
854 domtext_GetIDsOfNames,
856 domtext_get_nodeName,
857 domtext_get_nodeValue,
858 domtext_put_nodeValue,
859 domtext_get_nodeType,
860 domtext_get_parentNode,
861 domtext_get_childNodes,
862 domtext_get_firstChild,
863 domtext_get_lastChild,
864 domtext_get_previousSibling,
865 domtext_get_nextSibling,
866 domtext_get_attributes,
867 domtext_insertBefore,
868 domtext_replaceChild,
871 domtext_hasChildNodes,
872 domtext_get_ownerDocument,
874 domtext_get_nodeTypeString,
877 domtext_get_specified,
878 domtext_get_definition,
879 domtext_get_nodeTypedValue,
880 domtext_put_nodeTypedValue,
881 domtext_get_dataType,
882 domtext_put_dataType,
884 domtext_transformNode,
886 domtext_selectSingleNode,
888 domtext_get_namespaceURI,
890 domtext_get_baseName,
891 domtext_transformNodeToObject,
895 domtext_substringData,
903 static const tid_t domtext_iface_tids[] = {
908 static dispex_static_data_t domtext_dispex = {
915 IUnknown* create_text( xmlNodePtr text )
919 This = heap_alloc( sizeof *This );
923 This->IXMLDOMText_iface.lpVtbl = &domtext_vtbl;
926 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMText_iface, &domtext_dispex);
928 return (IUnknown*)&This->IXMLDOMText_iface;