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
32 #include "msxml_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
40 typedef struct _domcomment
42 const struct IXMLDOMCommentVtbl *lpVtbl;
48 static inline domcomment *impl_from_IXMLDOMComment( IXMLDOMComment *iface )
50 return (domcomment *)((char*)iface - FIELD_OFFSET(domcomment, lpVtbl));
53 static HRESULT WINAPI domcomment_QueryInterface(
54 IXMLDOMComment *iface,
58 domcomment *This = impl_from_IXMLDOMComment( iface );
59 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
61 if ( IsEqualGUID( riid, &IID_IXMLDOMComment ) ||
62 IsEqualGUID( riid, &IID_IDispatch ) ||
63 IsEqualGUID( riid, &IID_IUnknown ) )
67 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
69 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
73 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
77 IXMLDOMComment_AddRef( iface );
82 static ULONG WINAPI domcomment_AddRef(
83 IXMLDOMComment *iface )
85 domcomment *This = impl_from_IXMLDOMComment( iface );
86 return InterlockedIncrement( &This->ref );
89 static ULONG WINAPI domcomment_Release(
90 IXMLDOMComment *iface )
92 domcomment *This = impl_from_IXMLDOMComment( iface );
95 ref = InterlockedDecrement( &This->ref );
98 IUnknown_Release( This->node_unk );
99 HeapFree( GetProcessHeap(), 0, This );
105 static HRESULT WINAPI domcomment_GetTypeInfoCount(
106 IXMLDOMComment *iface,
109 domcomment *This = impl_from_IXMLDOMComment( iface );
111 TRACE("(%p)->(%p)\n", This, pctinfo);
118 static HRESULT WINAPI domcomment_GetTypeInfo(
119 IXMLDOMComment *iface,
120 UINT iTInfo, LCID lcid,
121 ITypeInfo** ppTInfo )
123 domcomment *This = impl_from_IXMLDOMComment( iface );
126 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
128 hr = get_typeinfo(IXMLDOMComment_tid, ppTInfo);
133 static HRESULT WINAPI domcomment_GetIDsOfNames(
134 IXMLDOMComment *iface,
135 REFIID riid, LPOLESTR* rgszNames,
136 UINT cNames, LCID lcid, DISPID* rgDispId )
138 domcomment *This = impl_from_IXMLDOMComment( iface );
142 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
145 if(!rgszNames || cNames == 0 || !rgDispId)
148 hr = get_typeinfo(IXMLDOMComment_tid, &typeinfo);
151 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
152 ITypeInfo_Release(typeinfo);
158 static HRESULT WINAPI domcomment_Invoke(
159 IXMLDOMComment *iface,
160 DISPID dispIdMember, REFIID riid, LCID lcid,
161 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
162 EXCEPINFO* pExcepInfo, UINT* puArgErr )
164 domcomment *This = impl_from_IXMLDOMComment( iface );
168 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
169 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
171 hr = get_typeinfo(IXMLDOMComment_tid, &typeinfo);
174 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
175 pVarResult, pExcepInfo, puArgErr);
176 ITypeInfo_Release(typeinfo);
182 static HRESULT WINAPI domcomment_get_nodeName(
183 IXMLDOMComment *iface,
186 domcomment *This = impl_from_IXMLDOMComment( iface );
187 return IXMLDOMNode_get_nodeName( This->node, p );
190 static HRESULT WINAPI domcomment_get_nodeValue(
191 IXMLDOMComment *iface,
194 domcomment *This = impl_from_IXMLDOMComment( iface );
195 return IXMLDOMNode_get_nodeValue( This->node, var1 );
198 static HRESULT WINAPI domcomment_put_nodeValue(
199 IXMLDOMComment *iface,
202 domcomment *This = impl_from_IXMLDOMComment( iface );
203 return IXMLDOMNode_put_nodeValue( This->node, var1 );
206 static HRESULT WINAPI domcomment_get_nodeType(
207 IXMLDOMComment *iface,
208 DOMNodeType* domNodeType )
210 domcomment *This = impl_from_IXMLDOMComment( iface );
211 return IXMLDOMNode_get_nodeType( This->node, domNodeType );
214 static HRESULT WINAPI domcomment_get_parentNode(
215 IXMLDOMComment *iface,
216 IXMLDOMNode** parent )
218 domcomment *This = impl_from_IXMLDOMComment( iface );
219 return IXMLDOMNode_get_parentNode( This->node, parent );
222 static HRESULT WINAPI domcomment_get_childNodes(
223 IXMLDOMComment *iface,
224 IXMLDOMNodeList** outList)
226 domcomment *This = impl_from_IXMLDOMComment( iface );
227 return IXMLDOMNode_get_childNodes( This->node, outList );
230 static HRESULT WINAPI domcomment_get_firstChild(
231 IXMLDOMComment *iface,
232 IXMLDOMNode** domNode)
234 domcomment *This = impl_from_IXMLDOMComment( iface );
235 return IXMLDOMNode_get_firstChild( This->node, domNode );
238 static HRESULT WINAPI domcomment_get_lastChild(
239 IXMLDOMComment *iface,
240 IXMLDOMNode** domNode)
242 domcomment *This = impl_from_IXMLDOMComment( iface );
243 return IXMLDOMNode_get_lastChild( This->node, domNode );
246 static HRESULT WINAPI domcomment_get_previousSibling(
247 IXMLDOMComment *iface,
248 IXMLDOMNode** domNode)
250 domcomment *This = impl_from_IXMLDOMComment( iface );
251 return IXMLDOMNode_get_previousSibling( This->node, domNode );
254 static HRESULT WINAPI domcomment_get_nextSibling(
255 IXMLDOMComment *iface,
256 IXMLDOMNode** domNode)
258 domcomment *This = impl_from_IXMLDOMComment( iface );
259 return IXMLDOMNode_get_nextSibling( This->node, domNode );
262 static HRESULT WINAPI domcomment_get_attributes(
263 IXMLDOMComment *iface,
264 IXMLDOMNamedNodeMap** attributeMap)
266 domcomment *This = impl_from_IXMLDOMComment( iface );
267 return IXMLDOMNode_get_attributes( This->node, attributeMap );
270 static HRESULT WINAPI domcomment_insertBefore(
271 IXMLDOMComment *iface,
272 IXMLDOMNode* newNode, VARIANT var1,
273 IXMLDOMNode** outOldNode)
275 domcomment *This = impl_from_IXMLDOMComment( iface );
276 return IXMLDOMNode_insertBefore( This->node, newNode, var1, outOldNode );
279 static HRESULT WINAPI domcomment_replaceChild(
280 IXMLDOMComment *iface,
281 IXMLDOMNode* newNode,
282 IXMLDOMNode* oldNode,
283 IXMLDOMNode** outOldNode)
285 domcomment *This = impl_from_IXMLDOMComment( iface );
286 return IXMLDOMNode_replaceChild( This->node, newNode, oldNode, outOldNode );
289 static HRESULT WINAPI domcomment_removeChild(
290 IXMLDOMComment *iface,
291 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
293 domcomment *This = impl_from_IXMLDOMComment( iface );
294 return IXMLDOMNode_removeChild( This->node, domNode, oldNode );
297 static HRESULT WINAPI domcomment_appendChild(
298 IXMLDOMComment *iface,
299 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
301 domcomment *This = impl_from_IXMLDOMComment( iface );
302 return IXMLDOMNode_appendChild( This->node, newNode, outNewNode );
305 static HRESULT WINAPI domcomment_hasChildNodes(
306 IXMLDOMComment *iface,
309 domcomment *This = impl_from_IXMLDOMComment( iface );
310 return IXMLDOMNode_hasChildNodes( This->node, pbool );
313 static HRESULT WINAPI domcomment_get_ownerDocument(
314 IXMLDOMComment *iface,
315 IXMLDOMDocument** domDocument)
317 domcomment *This = impl_from_IXMLDOMComment( iface );
318 return IXMLDOMNode_get_ownerDocument( This->node, domDocument );
321 static HRESULT WINAPI domcomment_cloneNode(
322 IXMLDOMComment *iface,
323 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
325 domcomment *This = impl_from_IXMLDOMComment( iface );
326 return IXMLDOMNode_cloneNode( This->node, pbool, outNode );
329 static HRESULT WINAPI domcomment_get_nodeTypeString(
330 IXMLDOMComment *iface,
333 domcomment *This = impl_from_IXMLDOMComment( iface );
334 return IXMLDOMNode_get_nodeTypeString( This->node, p );
337 static HRESULT WINAPI domcomment_get_text(
338 IXMLDOMComment *iface,
341 domcomment *This = impl_from_IXMLDOMComment( iface );
342 return IXMLDOMNode_get_text( This->node, p );
345 static HRESULT WINAPI domcomment_put_text(
346 IXMLDOMComment *iface,
349 domcomment *This = impl_from_IXMLDOMComment( iface );
350 return IXMLDOMNode_put_text( This->node, p );
353 static HRESULT WINAPI domcomment_get_specified(
354 IXMLDOMComment *iface,
357 domcomment *This = impl_from_IXMLDOMComment( iface );
358 return IXMLDOMNode_get_specified( This->node, pbool );
361 static HRESULT WINAPI domcomment_get_definition(
362 IXMLDOMComment *iface,
363 IXMLDOMNode** domNode)
365 domcomment *This = impl_from_IXMLDOMComment( iface );
366 return IXMLDOMNode_get_definition( This->node, domNode );
369 static HRESULT WINAPI domcomment_get_nodeTypedValue(
370 IXMLDOMComment *iface,
373 domcomment *This = impl_from_IXMLDOMComment( iface );
374 return IXMLDOMNode_get_nodeTypedValue( This->node, var1 );
377 static HRESULT WINAPI domcomment_put_nodeTypedValue(
378 IXMLDOMComment *iface,
381 domcomment *This = impl_from_IXMLDOMComment( iface );
382 return IXMLDOMNode_put_nodeTypedValue( This->node, var1 );
385 static HRESULT WINAPI domcomment_get_dataType(
386 IXMLDOMComment *iface,
389 domcomment *This = impl_from_IXMLDOMComment( iface );
390 return IXMLDOMNode_get_dataType( This->node, var1 );
393 static HRESULT WINAPI domcomment_put_dataType(
394 IXMLDOMComment *iface,
397 domcomment *This = impl_from_IXMLDOMComment( iface );
398 return IXMLDOMNode_put_dataType( This->node, p );
401 static HRESULT WINAPI domcomment_get_xml(
402 IXMLDOMComment *iface,
405 domcomment *This = impl_from_IXMLDOMComment( iface );
406 return IXMLDOMNode_get_xml( This->node, p );
409 static HRESULT WINAPI domcomment_transformNode(
410 IXMLDOMComment *iface,
411 IXMLDOMNode* domNode, BSTR* p)
413 domcomment *This = impl_from_IXMLDOMComment( iface );
414 return IXMLDOMNode_transformNode( This->node, domNode, p );
417 static HRESULT WINAPI domcomment_selectNodes(
418 IXMLDOMComment *iface,
419 BSTR p, IXMLDOMNodeList** outList)
421 domcomment *This = impl_from_IXMLDOMComment( iface );
422 return IXMLDOMNode_selectNodes( This->node, p, outList );
425 static HRESULT WINAPI domcomment_selectSingleNode(
426 IXMLDOMComment *iface,
427 BSTR p, IXMLDOMNode** outNode)
429 domcomment *This = impl_from_IXMLDOMComment( iface );
430 return IXMLDOMNode_selectSingleNode( This->node, p, outNode );
433 static HRESULT WINAPI domcomment_get_parsed(
434 IXMLDOMComment *iface,
437 domcomment *This = impl_from_IXMLDOMComment( iface );
438 return IXMLDOMNode_get_parsed( This->node, pbool );
441 static HRESULT WINAPI domcomment_get_namespaceURI(
442 IXMLDOMComment *iface,
445 domcomment *This = impl_from_IXMLDOMComment( iface );
446 return IXMLDOMNode_get_namespaceURI( This->node, p );
449 static HRESULT WINAPI domcomment_get_prefix(
450 IXMLDOMComment *iface,
453 domcomment *This = impl_from_IXMLDOMComment( iface );
454 return IXMLDOMNode_get_prefix( This->node, p );
457 static HRESULT WINAPI domcomment_get_baseName(
458 IXMLDOMComment *iface,
461 domcomment *This = impl_from_IXMLDOMComment( iface );
462 return IXMLDOMNode_get_baseName( This->node, p );
465 static HRESULT WINAPI domcomment_transformNodeToObject(
466 IXMLDOMComment *iface,
467 IXMLDOMNode* domNode, VARIANT var1)
469 domcomment *This = impl_from_IXMLDOMComment( iface );
470 return IXMLDOMNode_transformNodeToObject( This->node, domNode, var1 );
473 static HRESULT WINAPI domcomment_get_data(
474 IXMLDOMComment *iface,
477 domcomment *This = impl_from_IXMLDOMComment( iface );
484 hr = IXMLDOMNode_get_nodeValue( This->node, &vRet );
493 static HRESULT WINAPI domcomment_put_data(
494 IXMLDOMComment *iface,
497 domcomment *This = impl_from_IXMLDOMComment( iface );
501 TRACE("%p %s\n", This, debugstr_w(data) );
503 V_VT(&val) = VT_BSTR;
506 hr = IXMLDOMNode_put_nodeValue( This->node, val );
511 static HRESULT WINAPI domcomment_get_length(
512 IXMLDOMComment *iface,
515 domcomment *This = impl_from_IXMLDOMComment( iface );
516 xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
520 TRACE("%p\n", iface);
525 pContent = xmlNodeGetContent(pDOMNode->node);
528 nLength = xmlStrlen(pContent);
537 static HRESULT WINAPI domcomment_substringData(
538 IXMLDOMComment *iface,
539 long offset, long count, BSTR *p)
541 domcomment *This = impl_from_IXMLDOMComment( iface );
542 xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
545 HRESULT hr = S_FALSE;
547 TRACE("%p\n", iface);
553 if(offset < 0 || count < 0)
559 pContent = xmlNodeGetContent(pDOMNode->node);
562 nLength = xmlStrlen(pContent);
564 if( offset < nLength)
566 BSTR sContent = bstr_from_xmlChar(pContent);
567 if(offset + count > nLength)
568 *p = SysAllocString(&sContent[offset]);
570 *p = SysAllocStringLen(&sContent[offset], count);
572 SysFreeString(sContent);
582 static HRESULT WINAPI domcomment_appendData(
583 IXMLDOMComment *iface,
586 domcomment *This = impl_from_IXMLDOMComment( iface );
587 xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
589 HRESULT hr = S_FALSE;
591 TRACE("%p\n", iface);
593 /* Nothing to do if NULL or an Empty string passed in. */
594 if(p == NULL || SysStringLen(p) == 0)
597 pContent = xmlChar_from_wchar( (WCHAR*)p );
600 /* Older versions of libxml < 2.6.27 didn't correctly support
601 xmlTextConcat on Comment nodes. Fallback to setting the
602 contents directly if xmlTextConcat fails.
604 NOTE: if xmlTextConcat fails, pContent is destroyed.
606 if(xmlTextConcat(pDOMNode->node, pContent, SysStringLen(p) ) == 0)
611 pContent = xmlChar_from_wchar( (WCHAR*)p );
614 pNew = xmlStrcat(xmlNodeGetContent(pDOMNode->node), pContent);
617 xmlNodeSetContent(pDOMNode->node, pNew);
633 static HRESULT WINAPI domcomment_insertData(
634 IXMLDOMComment *iface,
637 domcomment *This = impl_from_IXMLDOMComment( iface );
638 xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
639 xmlChar *pXmlContent;
641 HRESULT hr = S_FALSE;
642 long nLength = 0, nLengthP = 0;
647 /* If have a NULL or empty string, don't do anything. */
648 if(SysStringLen(p) == 0)
656 pXmlContent = xmlNodeGetContent(pDOMNode->node);
659 BSTR sContent = bstr_from_xmlChar( pXmlContent );
660 nLength = SysStringLen(sContent);
661 nLengthP = SysStringLen(p);
665 SysFreeString(sContent);
666 xmlFree(pXmlContent);
671 sNewString = SysAllocStringLen(NULL, nLength + nLengthP + 1);
675 memcpy(sNewString, sContent, offset * sizeof(WCHAR));
677 memcpy(&sNewString[offset], p, nLengthP * sizeof(WCHAR));
679 if(offset+nLengthP < nLength)
680 memcpy(&sNewString[offset+nLengthP], &sContent[offset], (nLength-offset) * sizeof(WCHAR));
682 sNewString[nLengthP + nLength] = 0;
684 str = xmlChar_from_wchar((WCHAR*)sNewString);
687 xmlNodeSetContent(pDOMNode->node, str);
691 SysFreeString(sNewString);
694 SysFreeString(sContent);
696 xmlFree(pXmlContent);
702 static HRESULT WINAPI domcomment_deleteData(
703 IXMLDOMComment *iface,
704 long offset, long count)
710 static HRESULT WINAPI domcomment_replaceData(
711 IXMLDOMComment *iface,
712 long offset, long count, BSTR p)
718 static const struct IXMLDOMCommentVtbl domcomment_vtbl =
720 domcomment_QueryInterface,
723 domcomment_GetTypeInfoCount,
724 domcomment_GetTypeInfo,
725 domcomment_GetIDsOfNames,
727 domcomment_get_nodeName,
728 domcomment_get_nodeValue,
729 domcomment_put_nodeValue,
730 domcomment_get_nodeType,
731 domcomment_get_parentNode,
732 domcomment_get_childNodes,
733 domcomment_get_firstChild,
734 domcomment_get_lastChild,
735 domcomment_get_previousSibling,
736 domcomment_get_nextSibling,
737 domcomment_get_attributes,
738 domcomment_insertBefore,
739 domcomment_replaceChild,
740 domcomment_removeChild,
741 domcomment_appendChild,
742 domcomment_hasChildNodes,
743 domcomment_get_ownerDocument,
744 domcomment_cloneNode,
745 domcomment_get_nodeTypeString,
748 domcomment_get_specified,
749 domcomment_get_definition,
750 domcomment_get_nodeTypedValue,
751 domcomment_put_nodeTypedValue,
752 domcomment_get_dataType,
753 domcomment_put_dataType,
755 domcomment_transformNode,
756 domcomment_selectNodes,
757 domcomment_selectSingleNode,
758 domcomment_get_parsed,
759 domcomment_get_namespaceURI,
760 domcomment_get_prefix,
761 domcomment_get_baseName,
762 domcomment_transformNodeToObject,
765 domcomment_get_length,
766 domcomment_substringData,
767 domcomment_appendData,
768 domcomment_insertData,
769 domcomment_deleteData,
770 domcomment_replaceData
773 IUnknown* create_comment( xmlNodePtr comment )
778 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
782 This->lpVtbl = &domcomment_vtbl;
785 This->node_unk = create_basic_node( comment, (IUnknown*)&This->lpVtbl );
788 HeapFree(GetProcessHeap(), 0, This);
792 hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
795 IUnknown_Release(This->node_unk);
796 HeapFree( GetProcessHeap(), 0, This );
799 /* The ref on This->node is actually looped back into this object, so release it */
800 IXMLDOMNode_Release(This->node);
802 return (IUnknown*) &This->lpVtbl;