2 * DOM comment node implementation
4 * Copyright 2006 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
37 #include "msxml_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
45 typedef struct _domcomment
48 IXMLDOMComment IXMLDOMComment_iface;
52 static inline domcomment *impl_from_IXMLDOMComment( IXMLDOMComment *iface )
54 return CONTAINING_RECORD(iface, domcomment, IXMLDOMComment_iface);
57 static HRESULT WINAPI domcomment_QueryInterface(
58 IXMLDOMComment *iface,
62 domcomment *This = impl_from_IXMLDOMComment( iface );
63 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
65 if ( IsEqualGUID( riid, &IID_IXMLDOMComment ) ||
66 IsEqualGUID( riid, &IID_IXMLDOMCharacterData) ||
67 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
68 IsEqualGUID( riid, &IID_IDispatch ) ||
69 IsEqualGUID( riid, &IID_IUnknown ) )
73 else if(node_query_interface(&This->node, riid, ppvObject))
75 return *ppvObject ? S_OK : E_NOINTERFACE;
79 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
84 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
88 static ULONG WINAPI domcomment_AddRef(
89 IXMLDOMComment *iface )
91 domcomment *This = impl_from_IXMLDOMComment( iface );
92 ULONG ref = InterlockedIncrement( &This->ref );
93 TRACE("(%p)->(%d)\n", This, ref);
97 static ULONG WINAPI domcomment_Release(
98 IXMLDOMComment *iface )
100 domcomment *This = impl_from_IXMLDOMComment( iface );
101 ULONG ref = InterlockedDecrement( &This->ref );
103 TRACE("(%p)->(%d)\n", This, ref);
106 destroy_xmlnode(&This->node);
113 static HRESULT WINAPI domcomment_GetTypeInfoCount(
114 IXMLDOMComment *iface,
117 domcomment *This = impl_from_IXMLDOMComment( iface );
119 TRACE("(%p)->(%p)\n", This, pctinfo);
126 static HRESULT WINAPI domcomment_GetTypeInfo(
127 IXMLDOMComment *iface,
128 UINT iTInfo, LCID lcid,
129 ITypeInfo** ppTInfo )
131 domcomment *This = impl_from_IXMLDOMComment( iface );
134 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
136 hr = get_typeinfo(IXMLDOMComment_tid, ppTInfo);
141 static HRESULT WINAPI domcomment_GetIDsOfNames(
142 IXMLDOMComment *iface,
143 REFIID riid, LPOLESTR* rgszNames,
144 UINT cNames, LCID lcid, DISPID* rgDispId )
146 domcomment *This = impl_from_IXMLDOMComment( 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(IXMLDOMComment_tid, &typeinfo);
159 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
160 ITypeInfo_Release(typeinfo);
166 static HRESULT WINAPI domcomment_Invoke(
167 IXMLDOMComment *iface,
168 DISPID dispIdMember, REFIID riid, LCID lcid,
169 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
170 EXCEPINFO* pExcepInfo, UINT* puArgErr )
172 domcomment *This = impl_from_IXMLDOMComment( 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(IXMLDOMComment_tid, &typeinfo);
182 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMComment_iface, dispIdMember, wFlags,
183 pDispParams, pVarResult, pExcepInfo, puArgErr);
184 ITypeInfo_Release(typeinfo);
190 static HRESULT WINAPI domcomment_get_nodeName(
191 IXMLDOMComment *iface,
194 domcomment *This = impl_from_IXMLDOMComment( iface );
196 static const WCHAR commentW[] = {'#','c','o','m','m','e','n','t',0};
198 TRACE("(%p)->(%p)\n", This, p);
200 return return_bstr(commentW, p);
203 static HRESULT WINAPI domcomment_get_nodeValue(
204 IXMLDOMComment *iface,
207 domcomment *This = impl_from_IXMLDOMComment( iface );
209 TRACE("(%p)->(%p)\n", This, value);
211 return node_get_content(&This->node, value);
214 static HRESULT WINAPI domcomment_put_nodeValue(
215 IXMLDOMComment *iface,
218 domcomment *This = impl_from_IXMLDOMComment( iface );
220 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
222 return node_put_value(&This->node, &value);
225 static HRESULT WINAPI domcomment_get_nodeType(
226 IXMLDOMComment *iface,
227 DOMNodeType* domNodeType )
229 domcomment *This = impl_from_IXMLDOMComment( iface );
231 TRACE("(%p)->(%p)\n", This, domNodeType);
233 *domNodeType = NODE_COMMENT;
237 static HRESULT WINAPI domcomment_get_parentNode(
238 IXMLDOMComment *iface,
239 IXMLDOMNode** parent )
241 domcomment *This = impl_from_IXMLDOMComment( iface );
243 TRACE("(%p)->(%p)\n", This, parent);
245 return node_get_parent(&This->node, parent);
248 static HRESULT WINAPI domcomment_get_childNodes(
249 IXMLDOMComment *iface,
250 IXMLDOMNodeList** outList)
252 domcomment *This = impl_from_IXMLDOMComment( iface );
254 TRACE("(%p)->(%p)\n", This, outList);
256 return node_get_child_nodes(&This->node, outList);
259 static HRESULT WINAPI domcomment_get_firstChild(
260 IXMLDOMComment *iface,
261 IXMLDOMNode** domNode)
263 domcomment *This = impl_from_IXMLDOMComment( iface );
265 TRACE("(%p)->(%p)\n", This, domNode);
267 return return_null_node(domNode);
270 static HRESULT WINAPI domcomment_get_lastChild(
271 IXMLDOMComment *iface,
272 IXMLDOMNode** domNode)
274 domcomment *This = impl_from_IXMLDOMComment( iface );
276 TRACE("(%p)->(%p)\n", This, domNode);
278 return return_null_node(domNode);
281 static HRESULT WINAPI domcomment_get_previousSibling(
282 IXMLDOMComment *iface,
283 IXMLDOMNode** domNode)
285 domcomment *This = impl_from_IXMLDOMComment( iface );
287 TRACE("(%p)->(%p)\n", This, domNode);
289 return node_get_previous_sibling(&This->node, domNode);
292 static HRESULT WINAPI domcomment_get_nextSibling(
293 IXMLDOMComment *iface,
294 IXMLDOMNode** domNode)
296 domcomment *This = impl_from_IXMLDOMComment( iface );
298 TRACE("(%p)->(%p)\n", This, domNode);
300 return node_get_next_sibling(&This->node, domNode);
303 static HRESULT WINAPI domcomment_get_attributes(
304 IXMLDOMComment *iface,
305 IXMLDOMNamedNodeMap** attributeMap)
307 domcomment *This = impl_from_IXMLDOMComment( iface );
309 TRACE("(%p)->(%p)\n", This, attributeMap);
311 return return_null_ptr((void**)attributeMap);
314 static HRESULT WINAPI domcomment_insertBefore(
315 IXMLDOMComment *iface,
316 IXMLDOMNode* newNode, VARIANT refChild,
317 IXMLDOMNode** outOldNode)
319 domcomment *This = impl_from_IXMLDOMComment( iface );
321 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
323 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
326 static HRESULT WINAPI domcomment_replaceChild(
327 IXMLDOMComment *iface,
328 IXMLDOMNode* newNode,
329 IXMLDOMNode* oldNode,
330 IXMLDOMNode** outOldNode)
332 domcomment *This = impl_from_IXMLDOMComment( iface );
334 FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
336 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
339 static HRESULT WINAPI domcomment_removeChild(
340 IXMLDOMComment *iface,
341 IXMLDOMNode *child, IXMLDOMNode **oldChild)
343 domcomment *This = impl_from_IXMLDOMComment( iface );
344 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
345 return node_remove_child(&This->node, child, oldChild);
348 static HRESULT WINAPI domcomment_appendChild(
349 IXMLDOMComment *iface,
350 IXMLDOMNode *child, IXMLDOMNode **outChild)
352 domcomment *This = impl_from_IXMLDOMComment( iface );
353 TRACE("(%p)->(%p %p)\n", This, child, outChild);
354 return node_append_child(&This->node, child, outChild);
357 static HRESULT WINAPI domcomment_hasChildNodes(
358 IXMLDOMComment *iface,
361 domcomment *This = impl_from_IXMLDOMComment( iface );
362 TRACE("(%p)->(%p)\n", This, ret);
363 return node_has_childnodes(&This->node, ret);
366 static HRESULT WINAPI domcomment_get_ownerDocument(
367 IXMLDOMComment *iface,
368 IXMLDOMDocument **doc)
370 domcomment *This = impl_from_IXMLDOMComment( iface );
371 TRACE("(%p)->(%p)\n", This, doc);
372 return node_get_owner_doc(&This->node, doc);
375 static HRESULT WINAPI domcomment_cloneNode(
376 IXMLDOMComment *iface,
377 VARIANT_BOOL deep, IXMLDOMNode** outNode)
379 domcomment *This = impl_from_IXMLDOMComment( iface );
380 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
381 return node_clone( &This->node, deep, outNode );
384 static HRESULT WINAPI domcomment_get_nodeTypeString(
385 IXMLDOMComment *iface,
388 domcomment *This = impl_from_IXMLDOMComment( iface );
389 static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0};
391 TRACE("(%p)->(%p)\n", This, p);
393 return return_bstr(commentW, p);
396 static HRESULT WINAPI domcomment_get_text(
397 IXMLDOMComment *iface,
400 domcomment *This = impl_from_IXMLDOMComment( iface );
401 TRACE("(%p)->(%p)\n", This, p);
402 return node_get_text(&This->node, p);
405 static HRESULT WINAPI domcomment_put_text(
406 IXMLDOMComment *iface,
409 domcomment *This = impl_from_IXMLDOMComment( iface );
410 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
411 return node_put_text( &This->node, p );
414 static HRESULT WINAPI domcomment_get_specified(
415 IXMLDOMComment *iface,
416 VARIANT_BOOL* isSpecified)
418 domcomment *This = impl_from_IXMLDOMComment( iface );
419 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
420 *isSpecified = VARIANT_TRUE;
424 static HRESULT WINAPI domcomment_get_definition(
425 IXMLDOMComment *iface,
426 IXMLDOMNode** definitionNode)
428 domcomment *This = impl_from_IXMLDOMComment( iface );
429 FIXME("(%p)->(%p)\n", This, definitionNode);
433 static HRESULT WINAPI domcomment_get_nodeTypedValue(
434 IXMLDOMComment *iface,
437 domcomment *This = impl_from_IXMLDOMComment( iface );
438 TRACE("(%p)->(%p)\n", This, v);
439 return node_get_content(&This->node, v);
442 static HRESULT WINAPI domcomment_put_nodeTypedValue(
443 IXMLDOMComment *iface,
446 domcomment *This = impl_from_IXMLDOMComment( iface );
447 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
451 static HRESULT WINAPI domcomment_get_dataType(
452 IXMLDOMComment *iface,
455 domcomment *This = impl_from_IXMLDOMComment( iface );
456 TRACE("(%p)->(%p)\n", This, typename);
457 return return_null_var( typename );
460 static HRESULT WINAPI domcomment_put_dataType(
461 IXMLDOMComment *iface,
464 domcomment *This = impl_from_IXMLDOMComment( iface );
466 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
474 static HRESULT WINAPI domcomment_get_xml(
475 IXMLDOMComment *iface,
478 domcomment *This = impl_from_IXMLDOMComment( iface );
480 TRACE("(%p)->(%p)\n", This, p);
482 return node_get_xml(&This->node, FALSE, FALSE, p);
485 static HRESULT WINAPI domcomment_transformNode(
486 IXMLDOMComment *iface,
487 IXMLDOMNode *node, BSTR *p)
489 domcomment *This = impl_from_IXMLDOMComment( iface );
490 TRACE("(%p)->(%p %p)\n", This, node, p);
491 return node_transform_node(&This->node, node, p);
494 static HRESULT WINAPI domcomment_selectNodes(
495 IXMLDOMComment *iface,
496 BSTR p, IXMLDOMNodeList** outList)
498 domcomment *This = impl_from_IXMLDOMComment( iface );
499 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
500 return node_select_nodes(&This->node, p, outList);
503 static HRESULT WINAPI domcomment_selectSingleNode(
504 IXMLDOMComment *iface,
505 BSTR p, IXMLDOMNode** outNode)
507 domcomment *This = impl_from_IXMLDOMComment( iface );
508 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
509 return node_select_singlenode(&This->node, p, outNode);
512 static HRESULT WINAPI domcomment_get_parsed(
513 IXMLDOMComment *iface,
514 VARIANT_BOOL* isParsed)
516 domcomment *This = impl_from_IXMLDOMComment( iface );
517 FIXME("(%p)->(%p) stub!\n", This, isParsed);
518 *isParsed = VARIANT_TRUE;
522 static HRESULT WINAPI domcomment_get_namespaceURI(
523 IXMLDOMComment *iface,
526 domcomment *This = impl_from_IXMLDOMComment( iface );
527 TRACE("(%p)->(%p)\n", This, p);
528 return node_get_namespaceURI(&This->node, p);
531 static HRESULT WINAPI domcomment_get_prefix(
532 IXMLDOMComment *iface,
535 domcomment *This = impl_from_IXMLDOMComment( iface );
536 TRACE("(%p)->(%p)\n", This, prefix);
537 return return_null_bstr( prefix );
540 static HRESULT WINAPI domcomment_get_baseName(
541 IXMLDOMComment *iface,
544 domcomment *This = impl_from_IXMLDOMComment( iface );
545 TRACE("(%p)->(%p)\n", This, name);
546 return return_null_bstr( name );
549 static HRESULT WINAPI domcomment_transformNodeToObject(
550 IXMLDOMComment *iface,
551 IXMLDOMNode* domNode, VARIANT var1)
553 domcomment *This = impl_from_IXMLDOMComment( iface );
554 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
558 static HRESULT WINAPI domcomment_get_data(
559 IXMLDOMComment *iface,
562 domcomment *This = impl_from_IXMLDOMComment( iface );
566 TRACE("(%p)->(%p)\n", This, p);
571 hr = IXMLDOMComment_get_nodeValue( iface, &vRet );
580 static HRESULT WINAPI domcomment_put_data(
581 IXMLDOMComment *iface,
584 domcomment *This = impl_from_IXMLDOMComment( iface );
587 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
589 V_VT(&val) = VT_BSTR;
591 return node_put_value(&This->node, &val);
594 static HRESULT WINAPI domcomment_get_length(
595 IXMLDOMComment *iface,
598 domcomment *This = impl_from_IXMLDOMComment( iface );
602 TRACE("(%p)->(%p)\n", This, len);
607 hr = IXMLDOMComment_get_data(iface, &data);
610 *len = SysStringLen(data);
617 static HRESULT WINAPI domcomment_substringData(
618 IXMLDOMComment *iface,
619 LONG offset, LONG count, BSTR *p)
621 domcomment *This = impl_from_IXMLDOMComment( iface );
625 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
631 if(offset < 0 || count < 0)
637 hr = IXMLDOMComment_get_data(iface, &data);
640 LONG len = SysStringLen(data);
644 if(offset + count > len)
645 *p = SysAllocString(&data[offset]);
647 *p = SysAllocStringLen(&data[offset], count);
658 static HRESULT WINAPI domcomment_appendData(
659 IXMLDOMComment *iface,
662 domcomment *This = impl_from_IXMLDOMComment( iface );
667 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
669 /* Nothing to do if NULL or an Empty string passed in. */
670 if((p_len = SysStringLen(p)) == 0) return S_OK;
672 hr = IXMLDOMComment_get_data(iface, &data);
675 LONG len = SysStringLen(data);
676 BSTR str = SysAllocStringLen(NULL, p_len + len);
678 memcpy(str, data, len*sizeof(WCHAR));
679 memcpy(&str[len], p, p_len*sizeof(WCHAR));
682 hr = IXMLDOMComment_put_data(iface, str);
691 static HRESULT WINAPI domcomment_insertData(
692 IXMLDOMComment *iface,
695 domcomment *This = impl_from_IXMLDOMComment( iface );
700 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
702 /* If have a NULL or empty string, don't do anything. */
703 if((p_len = SysStringLen(p)) == 0)
711 hr = IXMLDOMComment_get_data(iface, &data);
714 LONG len = SysStringLen(data);
723 str = SysAllocStringLen(NULL, len + p_len);
724 /* start part, supplied string and end part */
725 memcpy(str, data, offset*sizeof(WCHAR));
726 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
727 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
730 hr = IXMLDOMComment_put_data(iface, str);
739 static HRESULT WINAPI domcomment_deleteData(
740 IXMLDOMComment *iface,
741 LONG offset, LONG count)
747 TRACE("(%p)->(%d %d)\n", iface, offset, count);
749 hr = IXMLDOMComment_get_length(iface, &len);
750 if(hr != S_OK) return hr;
752 if((offset < 0) || (offset > len) || (count < 0))
755 if(len == 0) return S_OK;
757 /* cutting start or end */
758 if((offset == 0) || ((count + offset) >= len))
761 IXMLDOMComment_substringData(iface, count, len - count, &str);
763 IXMLDOMComment_substringData(iface, 0, offset, &str);
764 hr = IXMLDOMComment_put_data(iface, str);
767 /* cutting from the inside */
771 IXMLDOMComment_substringData(iface, 0, offset, &str);
772 IXMLDOMComment_substringData(iface, offset + count, len - count, &str_end);
774 hr = IXMLDOMComment_put_data(iface, str);
776 hr = IXMLDOMComment_appendData(iface, str_end);
778 SysFreeString(str_end);
786 static HRESULT WINAPI domcomment_replaceData(
787 IXMLDOMComment *iface,
788 LONG offset, LONG count, BSTR p)
790 domcomment *This = impl_from_IXMLDOMComment( iface );
793 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
795 hr = IXMLDOMComment_deleteData(iface, offset, count);
798 hr = IXMLDOMComment_insertData(iface, offset, p);
803 static const struct IXMLDOMCommentVtbl domcomment_vtbl =
805 domcomment_QueryInterface,
808 domcomment_GetTypeInfoCount,
809 domcomment_GetTypeInfo,
810 domcomment_GetIDsOfNames,
812 domcomment_get_nodeName,
813 domcomment_get_nodeValue,
814 domcomment_put_nodeValue,
815 domcomment_get_nodeType,
816 domcomment_get_parentNode,
817 domcomment_get_childNodes,
818 domcomment_get_firstChild,
819 domcomment_get_lastChild,
820 domcomment_get_previousSibling,
821 domcomment_get_nextSibling,
822 domcomment_get_attributes,
823 domcomment_insertBefore,
824 domcomment_replaceChild,
825 domcomment_removeChild,
826 domcomment_appendChild,
827 domcomment_hasChildNodes,
828 domcomment_get_ownerDocument,
829 domcomment_cloneNode,
830 domcomment_get_nodeTypeString,
833 domcomment_get_specified,
834 domcomment_get_definition,
835 domcomment_get_nodeTypedValue,
836 domcomment_put_nodeTypedValue,
837 domcomment_get_dataType,
838 domcomment_put_dataType,
840 domcomment_transformNode,
841 domcomment_selectNodes,
842 domcomment_selectSingleNode,
843 domcomment_get_parsed,
844 domcomment_get_namespaceURI,
845 domcomment_get_prefix,
846 domcomment_get_baseName,
847 domcomment_transformNodeToObject,
850 domcomment_get_length,
851 domcomment_substringData,
852 domcomment_appendData,
853 domcomment_insertData,
854 domcomment_deleteData,
855 domcomment_replaceData
858 static const tid_t domcomment_iface_tids[] = {
863 static dispex_static_data_t domcomment_dispex = {
867 domcomment_iface_tids
870 IUnknown* create_comment( xmlNodePtr comment )
874 This = heap_alloc( sizeof *This );
878 This->IXMLDOMComment_iface.lpVtbl = &domcomment_vtbl;
881 init_xmlnode(&This->node, comment, (IXMLDOMNode*)&This->IXMLDOMComment_iface, &domcomment_dispex);
883 return (IUnknown*)&This->IXMLDOMComment_iface;