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 const tid_t domcomment_se_tids[] = {
58 static inline domcomment *impl_from_IXMLDOMComment( IXMLDOMComment *iface )
60 return CONTAINING_RECORD(iface, domcomment, IXMLDOMComment_iface);
63 static HRESULT WINAPI domcomment_QueryInterface(
64 IXMLDOMComment *iface,
68 domcomment *This = impl_from_IXMLDOMComment( iface );
69 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
71 if ( IsEqualGUID( riid, &IID_IXMLDOMComment ) ||
72 IsEqualGUID( riid, &IID_IXMLDOMCharacterData) ||
73 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
74 IsEqualGUID( riid, &IID_IDispatch ) ||
75 IsEqualGUID( riid, &IID_IUnknown ) )
79 else if(node_query_interface(&This->node, riid, ppvObject))
81 return *ppvObject ? S_OK : E_NOINTERFACE;
83 else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
85 return node_create_supporterrorinfo(domcomment_se_tids, ppvObject);
89 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
94 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
98 static ULONG WINAPI domcomment_AddRef(
99 IXMLDOMComment *iface )
101 domcomment *This = impl_from_IXMLDOMComment( iface );
102 ULONG ref = InterlockedIncrement( &This->ref );
103 TRACE("(%p)->(%d)\n", This, ref);
107 static ULONG WINAPI domcomment_Release(
108 IXMLDOMComment *iface )
110 domcomment *This = impl_from_IXMLDOMComment( iface );
111 ULONG ref = InterlockedDecrement( &This->ref );
113 TRACE("(%p)->(%d)\n", This, ref);
116 destroy_xmlnode(&This->node);
123 static HRESULT WINAPI domcomment_GetTypeInfoCount(
124 IXMLDOMComment *iface,
127 domcomment *This = impl_from_IXMLDOMComment( iface );
128 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
131 static HRESULT WINAPI domcomment_GetTypeInfo(
132 IXMLDOMComment *iface,
133 UINT iTInfo, LCID lcid,
134 ITypeInfo** ppTInfo )
136 domcomment *This = impl_from_IXMLDOMComment( iface );
137 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
138 iTInfo, lcid, 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 );
147 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
148 riid, rgszNames, cNames, lcid, rgDispId);
151 static HRESULT WINAPI domcomment_Invoke(
152 IXMLDOMComment *iface,
153 DISPID dispIdMember, REFIID riid, LCID lcid,
154 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
155 EXCEPINFO* pExcepInfo, UINT* puArgErr )
157 domcomment *This = impl_from_IXMLDOMComment( iface );
158 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
159 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
162 static HRESULT WINAPI domcomment_get_nodeName(
163 IXMLDOMComment *iface,
166 domcomment *This = impl_from_IXMLDOMComment( iface );
168 static const WCHAR commentW[] = {'#','c','o','m','m','e','n','t',0};
170 TRACE("(%p)->(%p)\n", This, p);
172 return return_bstr(commentW, p);
175 static HRESULT WINAPI domcomment_get_nodeValue(
176 IXMLDOMComment *iface,
179 domcomment *This = impl_from_IXMLDOMComment( iface );
181 TRACE("(%p)->(%p)\n", This, value);
183 return node_get_content(&This->node, value);
186 static HRESULT WINAPI domcomment_put_nodeValue(
187 IXMLDOMComment *iface,
190 domcomment *This = impl_from_IXMLDOMComment( iface );
192 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
194 return node_put_value(&This->node, &value);
197 static HRESULT WINAPI domcomment_get_nodeType(
198 IXMLDOMComment *iface,
199 DOMNodeType* domNodeType )
201 domcomment *This = impl_from_IXMLDOMComment( iface );
203 TRACE("(%p)->(%p)\n", This, domNodeType);
205 *domNodeType = NODE_COMMENT;
209 static HRESULT WINAPI domcomment_get_parentNode(
210 IXMLDOMComment *iface,
211 IXMLDOMNode** parent )
213 domcomment *This = impl_from_IXMLDOMComment( iface );
215 TRACE("(%p)->(%p)\n", This, parent);
217 return node_get_parent(&This->node, parent);
220 static HRESULT WINAPI domcomment_get_childNodes(
221 IXMLDOMComment *iface,
222 IXMLDOMNodeList** outList)
224 domcomment *This = impl_from_IXMLDOMComment( iface );
226 TRACE("(%p)->(%p)\n", This, outList);
228 return node_get_child_nodes(&This->node, outList);
231 static HRESULT WINAPI domcomment_get_firstChild(
232 IXMLDOMComment *iface,
233 IXMLDOMNode** domNode)
235 domcomment *This = impl_from_IXMLDOMComment( iface );
237 TRACE("(%p)->(%p)\n", This, domNode);
239 return return_null_node(domNode);
242 static HRESULT WINAPI domcomment_get_lastChild(
243 IXMLDOMComment *iface,
244 IXMLDOMNode** domNode)
246 domcomment *This = impl_from_IXMLDOMComment( iface );
248 TRACE("(%p)->(%p)\n", This, domNode);
250 return return_null_node(domNode);
253 static HRESULT WINAPI domcomment_get_previousSibling(
254 IXMLDOMComment *iface,
255 IXMLDOMNode** domNode)
257 domcomment *This = impl_from_IXMLDOMComment( iface );
259 TRACE("(%p)->(%p)\n", This, domNode);
261 return node_get_previous_sibling(&This->node, domNode);
264 static HRESULT WINAPI domcomment_get_nextSibling(
265 IXMLDOMComment *iface,
266 IXMLDOMNode** domNode)
268 domcomment *This = impl_from_IXMLDOMComment( iface );
270 TRACE("(%p)->(%p)\n", This, domNode);
272 return node_get_next_sibling(&This->node, domNode);
275 static HRESULT WINAPI domcomment_get_attributes(
276 IXMLDOMComment *iface,
277 IXMLDOMNamedNodeMap** attributeMap)
279 domcomment *This = impl_from_IXMLDOMComment( iface );
281 TRACE("(%p)->(%p)\n", This, attributeMap);
283 return return_null_ptr((void**)attributeMap);
286 static HRESULT WINAPI domcomment_insertBefore(
287 IXMLDOMComment *iface,
288 IXMLDOMNode* newNode, VARIANT refChild,
289 IXMLDOMNode** outOldNode)
291 domcomment *This = impl_from_IXMLDOMComment( iface );
293 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
295 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
298 static HRESULT WINAPI domcomment_replaceChild(
299 IXMLDOMComment *iface,
300 IXMLDOMNode* newNode,
301 IXMLDOMNode* oldNode,
302 IXMLDOMNode** outOldNode)
304 domcomment *This = impl_from_IXMLDOMComment( iface );
306 FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
308 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
311 static HRESULT WINAPI domcomment_removeChild(
312 IXMLDOMComment *iface,
313 IXMLDOMNode *child, IXMLDOMNode **oldChild)
315 domcomment *This = impl_from_IXMLDOMComment( iface );
316 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
317 return node_remove_child(&This->node, child, oldChild);
320 static HRESULT WINAPI domcomment_appendChild(
321 IXMLDOMComment *iface,
322 IXMLDOMNode *child, IXMLDOMNode **outChild)
324 domcomment *This = impl_from_IXMLDOMComment( iface );
325 TRACE("(%p)->(%p %p)\n", This, child, outChild);
326 return node_append_child(&This->node, child, outChild);
329 static HRESULT WINAPI domcomment_hasChildNodes(
330 IXMLDOMComment *iface,
333 domcomment *This = impl_from_IXMLDOMComment( iface );
334 TRACE("(%p)->(%p)\n", This, ret);
335 return node_has_childnodes(&This->node, ret);
338 static HRESULT WINAPI domcomment_get_ownerDocument(
339 IXMLDOMComment *iface,
340 IXMLDOMDocument **doc)
342 domcomment *This = impl_from_IXMLDOMComment( iface );
343 TRACE("(%p)->(%p)\n", This, doc);
344 return node_get_owner_doc(&This->node, doc);
347 static HRESULT WINAPI domcomment_cloneNode(
348 IXMLDOMComment *iface,
349 VARIANT_BOOL deep, IXMLDOMNode** outNode)
351 domcomment *This = impl_from_IXMLDOMComment( iface );
352 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
353 return node_clone( &This->node, deep, outNode );
356 static HRESULT WINAPI domcomment_get_nodeTypeString(
357 IXMLDOMComment *iface,
360 domcomment *This = impl_from_IXMLDOMComment( iface );
361 static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0};
363 TRACE("(%p)->(%p)\n", This, p);
365 return return_bstr(commentW, p);
368 static HRESULT WINAPI domcomment_get_text(
369 IXMLDOMComment *iface,
372 domcomment *This = impl_from_IXMLDOMComment( iface );
373 TRACE("(%p)->(%p)\n", This, p);
374 return node_get_text(&This->node, p);
377 static HRESULT WINAPI domcomment_put_text(
378 IXMLDOMComment *iface,
381 domcomment *This = impl_from_IXMLDOMComment( iface );
382 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
383 return node_put_text( &This->node, p );
386 static HRESULT WINAPI domcomment_get_specified(
387 IXMLDOMComment *iface,
388 VARIANT_BOOL* isSpecified)
390 domcomment *This = impl_from_IXMLDOMComment( iface );
391 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
392 *isSpecified = VARIANT_TRUE;
396 static HRESULT WINAPI domcomment_get_definition(
397 IXMLDOMComment *iface,
398 IXMLDOMNode** definitionNode)
400 domcomment *This = impl_from_IXMLDOMComment( iface );
401 FIXME("(%p)->(%p)\n", This, definitionNode);
405 static HRESULT WINAPI domcomment_get_nodeTypedValue(
406 IXMLDOMComment *iface,
409 domcomment *This = impl_from_IXMLDOMComment( iface );
410 TRACE("(%p)->(%p)\n", This, v);
411 return node_get_content(&This->node, v);
414 static HRESULT WINAPI domcomment_put_nodeTypedValue(
415 IXMLDOMComment *iface,
418 domcomment *This = impl_from_IXMLDOMComment( iface );
419 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
423 static HRESULT WINAPI domcomment_get_dataType(
424 IXMLDOMComment *iface,
427 domcomment *This = impl_from_IXMLDOMComment( iface );
428 TRACE("(%p)->(%p)\n", This, typename);
429 return return_null_var( typename );
432 static HRESULT WINAPI domcomment_put_dataType(
433 IXMLDOMComment *iface,
436 domcomment *This = impl_from_IXMLDOMComment( iface );
438 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
446 static HRESULT WINAPI domcomment_get_xml(
447 IXMLDOMComment *iface,
450 domcomment *This = impl_from_IXMLDOMComment( iface );
452 TRACE("(%p)->(%p)\n", This, p);
454 return node_get_xml(&This->node, FALSE, FALSE, p);
457 static HRESULT WINAPI domcomment_transformNode(
458 IXMLDOMComment *iface,
459 IXMLDOMNode *node, BSTR *p)
461 domcomment *This = impl_from_IXMLDOMComment( iface );
462 TRACE("(%p)->(%p %p)\n", This, node, p);
463 return node_transform_node(&This->node, node, p);
466 static HRESULT WINAPI domcomment_selectNodes(
467 IXMLDOMComment *iface,
468 BSTR p, IXMLDOMNodeList** outList)
470 domcomment *This = impl_from_IXMLDOMComment( iface );
471 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
472 return node_select_nodes(&This->node, p, outList);
475 static HRESULT WINAPI domcomment_selectSingleNode(
476 IXMLDOMComment *iface,
477 BSTR p, IXMLDOMNode** outNode)
479 domcomment *This = impl_from_IXMLDOMComment( iface );
480 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
481 return node_select_singlenode(&This->node, p, outNode);
484 static HRESULT WINAPI domcomment_get_parsed(
485 IXMLDOMComment *iface,
486 VARIANT_BOOL* isParsed)
488 domcomment *This = impl_from_IXMLDOMComment( iface );
489 FIXME("(%p)->(%p) stub!\n", This, isParsed);
490 *isParsed = VARIANT_TRUE;
494 static HRESULT WINAPI domcomment_get_namespaceURI(
495 IXMLDOMComment *iface,
498 domcomment *This = impl_from_IXMLDOMComment( iface );
499 TRACE("(%p)->(%p)\n", This, p);
500 return node_get_namespaceURI(&This->node, p);
503 static HRESULT WINAPI domcomment_get_prefix(
504 IXMLDOMComment *iface,
507 domcomment *This = impl_from_IXMLDOMComment( iface );
508 TRACE("(%p)->(%p)\n", This, prefix);
509 return return_null_bstr( prefix );
512 static HRESULT WINAPI domcomment_get_baseName(
513 IXMLDOMComment *iface,
516 domcomment *This = impl_from_IXMLDOMComment( iface );
517 TRACE("(%p)->(%p)\n", This, name);
518 return return_null_bstr( name );
521 static HRESULT WINAPI domcomment_transformNodeToObject(
522 IXMLDOMComment *iface,
523 IXMLDOMNode* domNode, VARIANT var1)
525 domcomment *This = impl_from_IXMLDOMComment( iface );
526 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
530 static HRESULT WINAPI domcomment_get_data(
531 IXMLDOMComment *iface,
534 domcomment *This = impl_from_IXMLDOMComment( iface );
538 TRACE("(%p)->(%p)\n", This, p);
543 hr = IXMLDOMComment_get_nodeValue( iface, &vRet );
552 static HRESULT WINAPI domcomment_put_data(
553 IXMLDOMComment *iface,
556 domcomment *This = impl_from_IXMLDOMComment( iface );
559 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
561 V_VT(&val) = VT_BSTR;
563 return node_put_value(&This->node, &val);
566 static HRESULT WINAPI domcomment_get_length(
567 IXMLDOMComment *iface,
570 domcomment *This = impl_from_IXMLDOMComment( iface );
574 TRACE("(%p)->(%p)\n", This, len);
579 hr = IXMLDOMComment_get_data(iface, &data);
582 *len = SysStringLen(data);
589 static HRESULT WINAPI domcomment_substringData(
590 IXMLDOMComment *iface,
591 LONG offset, LONG count, BSTR *p)
593 domcomment *This = impl_from_IXMLDOMComment( iface );
597 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
603 if(offset < 0 || count < 0)
609 hr = IXMLDOMComment_get_data(iface, &data);
612 LONG len = SysStringLen(data);
616 if(offset + count > len)
617 *p = SysAllocString(&data[offset]);
619 *p = SysAllocStringLen(&data[offset], count);
630 static HRESULT WINAPI domcomment_appendData(
631 IXMLDOMComment *iface,
634 domcomment *This = impl_from_IXMLDOMComment( iface );
639 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
641 /* Nothing to do if NULL or an Empty string passed in. */
642 if((p_len = SysStringLen(p)) == 0) return S_OK;
644 hr = IXMLDOMComment_get_data(iface, &data);
647 LONG len = SysStringLen(data);
648 BSTR str = SysAllocStringLen(NULL, p_len + len);
650 memcpy(str, data, len*sizeof(WCHAR));
651 memcpy(&str[len], p, p_len*sizeof(WCHAR));
654 hr = IXMLDOMComment_put_data(iface, str);
663 static HRESULT WINAPI domcomment_insertData(
664 IXMLDOMComment *iface,
667 domcomment *This = impl_from_IXMLDOMComment( iface );
672 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
674 /* If have a NULL or empty string, don't do anything. */
675 if((p_len = SysStringLen(p)) == 0)
683 hr = IXMLDOMComment_get_data(iface, &data);
686 LONG len = SysStringLen(data);
695 str = SysAllocStringLen(NULL, len + p_len);
696 /* start part, supplied string and end part */
697 memcpy(str, data, offset*sizeof(WCHAR));
698 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
699 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
702 hr = IXMLDOMComment_put_data(iface, str);
711 static HRESULT WINAPI domcomment_deleteData(
712 IXMLDOMComment *iface,
713 LONG offset, LONG count)
719 TRACE("(%p)->(%d %d)\n", iface, offset, count);
721 hr = IXMLDOMComment_get_length(iface, &len);
722 if(hr != S_OK) return hr;
724 if((offset < 0) || (offset > len) || (count < 0))
727 if(len == 0) return S_OK;
729 /* cutting start or end */
730 if((offset == 0) || ((count + offset) >= len))
733 IXMLDOMComment_substringData(iface, count, len - count, &str);
735 IXMLDOMComment_substringData(iface, 0, offset, &str);
736 hr = IXMLDOMComment_put_data(iface, str);
739 /* cutting from the inside */
743 IXMLDOMComment_substringData(iface, 0, offset, &str);
744 IXMLDOMComment_substringData(iface, offset + count, len - count, &str_end);
746 hr = IXMLDOMComment_put_data(iface, str);
748 hr = IXMLDOMComment_appendData(iface, str_end);
750 SysFreeString(str_end);
758 static HRESULT WINAPI domcomment_replaceData(
759 IXMLDOMComment *iface,
760 LONG offset, LONG count, BSTR p)
762 domcomment *This = impl_from_IXMLDOMComment( iface );
765 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
767 hr = IXMLDOMComment_deleteData(iface, offset, count);
770 hr = IXMLDOMComment_insertData(iface, offset, p);
775 static const struct IXMLDOMCommentVtbl domcomment_vtbl =
777 domcomment_QueryInterface,
780 domcomment_GetTypeInfoCount,
781 domcomment_GetTypeInfo,
782 domcomment_GetIDsOfNames,
784 domcomment_get_nodeName,
785 domcomment_get_nodeValue,
786 domcomment_put_nodeValue,
787 domcomment_get_nodeType,
788 domcomment_get_parentNode,
789 domcomment_get_childNodes,
790 domcomment_get_firstChild,
791 domcomment_get_lastChild,
792 domcomment_get_previousSibling,
793 domcomment_get_nextSibling,
794 domcomment_get_attributes,
795 domcomment_insertBefore,
796 domcomment_replaceChild,
797 domcomment_removeChild,
798 domcomment_appendChild,
799 domcomment_hasChildNodes,
800 domcomment_get_ownerDocument,
801 domcomment_cloneNode,
802 domcomment_get_nodeTypeString,
805 domcomment_get_specified,
806 domcomment_get_definition,
807 domcomment_get_nodeTypedValue,
808 domcomment_put_nodeTypedValue,
809 domcomment_get_dataType,
810 domcomment_put_dataType,
812 domcomment_transformNode,
813 domcomment_selectNodes,
814 domcomment_selectSingleNode,
815 domcomment_get_parsed,
816 domcomment_get_namespaceURI,
817 domcomment_get_prefix,
818 domcomment_get_baseName,
819 domcomment_transformNodeToObject,
822 domcomment_get_length,
823 domcomment_substringData,
824 domcomment_appendData,
825 domcomment_insertData,
826 domcomment_deleteData,
827 domcomment_replaceData
830 static const tid_t domcomment_iface_tids[] = {
835 static dispex_static_data_t domcomment_dispex = {
839 domcomment_iface_tids
842 IUnknown* create_comment( xmlNodePtr comment )
846 This = heap_alloc( sizeof *This );
850 This->IXMLDOMComment_iface.lpVtbl = &domcomment_vtbl;
853 init_xmlnode(&This->node, comment, (IXMLDOMNode*)&This->IXMLDOMComment_iface, &domcomment_dispex);
855 return (IUnknown*)&This->IXMLDOMComment_iface;