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_IXMLDOMCharacterData) ||
63 IsEqualGUID( riid, &IID_IDispatch ) ||
64 IsEqualGUID( riid, &IID_IUnknown ) )
68 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
70 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
74 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
78 IXMLDOMComment_AddRef( iface );
83 static ULONG WINAPI domcomment_AddRef(
84 IXMLDOMComment *iface )
86 domcomment *This = impl_from_IXMLDOMComment( iface );
87 return InterlockedIncrement( &This->ref );
90 static ULONG WINAPI domcomment_Release(
91 IXMLDOMComment *iface )
93 domcomment *This = impl_from_IXMLDOMComment( iface );
96 ref = InterlockedDecrement( &This->ref );
99 IUnknown_Release( This->node_unk );
100 HeapFree( GetProcessHeap(), 0, This );
106 static HRESULT WINAPI domcomment_GetTypeInfoCount(
107 IXMLDOMComment *iface,
110 domcomment *This = impl_from_IXMLDOMComment( iface );
112 TRACE("(%p)->(%p)\n", This, pctinfo);
119 static HRESULT WINAPI domcomment_GetTypeInfo(
120 IXMLDOMComment *iface,
121 UINT iTInfo, LCID lcid,
122 ITypeInfo** ppTInfo )
124 domcomment *This = impl_from_IXMLDOMComment( iface );
127 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
129 hr = get_typeinfo(IXMLDOMComment_tid, ppTInfo);
134 static HRESULT WINAPI domcomment_GetIDsOfNames(
135 IXMLDOMComment *iface,
136 REFIID riid, LPOLESTR* rgszNames,
137 UINT cNames, LCID lcid, DISPID* rgDispId )
139 domcomment *This = impl_from_IXMLDOMComment( iface );
143 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
146 if(!rgszNames || cNames == 0 || !rgDispId)
149 hr = get_typeinfo(IXMLDOMComment_tid, &typeinfo);
152 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
153 ITypeInfo_Release(typeinfo);
159 static HRESULT WINAPI domcomment_Invoke(
160 IXMLDOMComment *iface,
161 DISPID dispIdMember, REFIID riid, LCID lcid,
162 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
163 EXCEPINFO* pExcepInfo, UINT* puArgErr )
165 domcomment *This = impl_from_IXMLDOMComment( iface );
169 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
170 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
172 hr = get_typeinfo(IXMLDOMComment_tid, &typeinfo);
175 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
176 pVarResult, pExcepInfo, puArgErr);
177 ITypeInfo_Release(typeinfo);
183 static HRESULT WINAPI domcomment_get_nodeName(
184 IXMLDOMComment *iface,
187 domcomment *This = impl_from_IXMLDOMComment( iface );
188 return IXMLDOMNode_get_nodeName( This->node, p );
191 static HRESULT WINAPI domcomment_get_nodeValue(
192 IXMLDOMComment *iface,
195 domcomment *This = impl_from_IXMLDOMComment( iface );
196 return IXMLDOMNode_get_nodeValue( This->node, var1 );
199 static HRESULT WINAPI domcomment_put_nodeValue(
200 IXMLDOMComment *iface,
203 domcomment *This = impl_from_IXMLDOMComment( iface );
204 return IXMLDOMNode_put_nodeValue( This->node, var1 );
207 static HRESULT WINAPI domcomment_get_nodeType(
208 IXMLDOMComment *iface,
209 DOMNodeType* domNodeType )
211 domcomment *This = impl_from_IXMLDOMComment( iface );
212 return IXMLDOMNode_get_nodeType( This->node, domNodeType );
215 static HRESULT WINAPI domcomment_get_parentNode(
216 IXMLDOMComment *iface,
217 IXMLDOMNode** parent )
219 domcomment *This = impl_from_IXMLDOMComment( iface );
220 return IXMLDOMNode_get_parentNode( This->node, parent );
223 static HRESULT WINAPI domcomment_get_childNodes(
224 IXMLDOMComment *iface,
225 IXMLDOMNodeList** outList)
227 domcomment *This = impl_from_IXMLDOMComment( iface );
228 return IXMLDOMNode_get_childNodes( This->node, outList );
231 static HRESULT WINAPI domcomment_get_firstChild(
232 IXMLDOMComment *iface,
233 IXMLDOMNode** domNode)
235 domcomment *This = impl_from_IXMLDOMComment( iface );
236 return IXMLDOMNode_get_firstChild( This->node, domNode );
239 static HRESULT WINAPI domcomment_get_lastChild(
240 IXMLDOMComment *iface,
241 IXMLDOMNode** domNode)
243 domcomment *This = impl_from_IXMLDOMComment( iface );
244 return IXMLDOMNode_get_lastChild( This->node, domNode );
247 static HRESULT WINAPI domcomment_get_previousSibling(
248 IXMLDOMComment *iface,
249 IXMLDOMNode** domNode)
251 domcomment *This = impl_from_IXMLDOMComment( iface );
252 return IXMLDOMNode_get_previousSibling( This->node, domNode );
255 static HRESULT WINAPI domcomment_get_nextSibling(
256 IXMLDOMComment *iface,
257 IXMLDOMNode** domNode)
259 domcomment *This = impl_from_IXMLDOMComment( iface );
260 return IXMLDOMNode_get_nextSibling( This->node, domNode );
263 static HRESULT WINAPI domcomment_get_attributes(
264 IXMLDOMComment *iface,
265 IXMLDOMNamedNodeMap** attributeMap)
267 domcomment *This = impl_from_IXMLDOMComment( iface );
268 return IXMLDOMNode_get_attributes( This->node, attributeMap );
271 static HRESULT WINAPI domcomment_insertBefore(
272 IXMLDOMComment *iface,
273 IXMLDOMNode* newNode, VARIANT var1,
274 IXMLDOMNode** outOldNode)
276 domcomment *This = impl_from_IXMLDOMComment( iface );
277 return IXMLDOMNode_insertBefore( This->node, newNode, var1, outOldNode );
280 static HRESULT WINAPI domcomment_replaceChild(
281 IXMLDOMComment *iface,
282 IXMLDOMNode* newNode,
283 IXMLDOMNode* oldNode,
284 IXMLDOMNode** outOldNode)
286 domcomment *This = impl_from_IXMLDOMComment( iface );
287 return IXMLDOMNode_replaceChild( This->node, newNode, oldNode, outOldNode );
290 static HRESULT WINAPI domcomment_removeChild(
291 IXMLDOMComment *iface,
292 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
294 domcomment *This = impl_from_IXMLDOMComment( iface );
295 return IXMLDOMNode_removeChild( This->node, domNode, oldNode );
298 static HRESULT WINAPI domcomment_appendChild(
299 IXMLDOMComment *iface,
300 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
302 domcomment *This = impl_from_IXMLDOMComment( iface );
303 return IXMLDOMNode_appendChild( This->node, newNode, outNewNode );
306 static HRESULT WINAPI domcomment_hasChildNodes(
307 IXMLDOMComment *iface,
310 domcomment *This = impl_from_IXMLDOMComment( iface );
311 return IXMLDOMNode_hasChildNodes( This->node, pbool );
314 static HRESULT WINAPI domcomment_get_ownerDocument(
315 IXMLDOMComment *iface,
316 IXMLDOMDocument** domDocument)
318 domcomment *This = impl_from_IXMLDOMComment( iface );
319 return IXMLDOMNode_get_ownerDocument( This->node, domDocument );
322 static HRESULT WINAPI domcomment_cloneNode(
323 IXMLDOMComment *iface,
324 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
326 domcomment *This = impl_from_IXMLDOMComment( iface );
327 return IXMLDOMNode_cloneNode( This->node, pbool, outNode );
330 static HRESULT WINAPI domcomment_get_nodeTypeString(
331 IXMLDOMComment *iface,
334 domcomment *This = impl_from_IXMLDOMComment( iface );
335 return IXMLDOMNode_get_nodeTypeString( This->node, p );
338 static HRESULT WINAPI domcomment_get_text(
339 IXMLDOMComment *iface,
342 domcomment *This = impl_from_IXMLDOMComment( iface );
343 return IXMLDOMNode_get_text( This->node, p );
346 static HRESULT WINAPI domcomment_put_text(
347 IXMLDOMComment *iface,
350 domcomment *This = impl_from_IXMLDOMComment( iface );
351 return IXMLDOMNode_put_text( This->node, p );
354 static HRESULT WINAPI domcomment_get_specified(
355 IXMLDOMComment *iface,
358 domcomment *This = impl_from_IXMLDOMComment( iface );
359 return IXMLDOMNode_get_specified( This->node, pbool );
362 static HRESULT WINAPI domcomment_get_definition(
363 IXMLDOMComment *iface,
364 IXMLDOMNode** domNode)
366 domcomment *This = impl_from_IXMLDOMComment( iface );
367 return IXMLDOMNode_get_definition( This->node, domNode );
370 static HRESULT WINAPI domcomment_get_nodeTypedValue(
371 IXMLDOMComment *iface,
374 domcomment *This = impl_from_IXMLDOMComment( iface );
375 return IXMLDOMNode_get_nodeTypedValue( This->node, var1 );
378 static HRESULT WINAPI domcomment_put_nodeTypedValue(
379 IXMLDOMComment *iface,
382 domcomment *This = impl_from_IXMLDOMComment( iface );
383 return IXMLDOMNode_put_nodeTypedValue( This->node, var1 );
386 static HRESULT WINAPI domcomment_get_dataType(
387 IXMLDOMComment *iface,
390 domcomment *This = impl_from_IXMLDOMComment( iface );
391 return IXMLDOMNode_get_dataType( This->node, var1 );
394 static HRESULT WINAPI domcomment_put_dataType(
395 IXMLDOMComment *iface,
398 domcomment *This = impl_from_IXMLDOMComment( iface );
399 return IXMLDOMNode_put_dataType( This->node, p );
402 static HRESULT WINAPI domcomment_get_xml(
403 IXMLDOMComment *iface,
406 domcomment *This = impl_from_IXMLDOMComment( iface );
407 return IXMLDOMNode_get_xml( This->node, p );
410 static HRESULT WINAPI domcomment_transformNode(
411 IXMLDOMComment *iface,
412 IXMLDOMNode* domNode, BSTR* p)
414 domcomment *This = impl_from_IXMLDOMComment( iface );
415 return IXMLDOMNode_transformNode( This->node, domNode, p );
418 static HRESULT WINAPI domcomment_selectNodes(
419 IXMLDOMComment *iface,
420 BSTR p, IXMLDOMNodeList** outList)
422 domcomment *This = impl_from_IXMLDOMComment( iface );
423 return IXMLDOMNode_selectNodes( This->node, p, outList );
426 static HRESULT WINAPI domcomment_selectSingleNode(
427 IXMLDOMComment *iface,
428 BSTR p, IXMLDOMNode** outNode)
430 domcomment *This = impl_from_IXMLDOMComment( iface );
431 return IXMLDOMNode_selectSingleNode( This->node, p, outNode );
434 static HRESULT WINAPI domcomment_get_parsed(
435 IXMLDOMComment *iface,
438 domcomment *This = impl_from_IXMLDOMComment( iface );
439 return IXMLDOMNode_get_parsed( This->node, pbool );
442 static HRESULT WINAPI domcomment_get_namespaceURI(
443 IXMLDOMComment *iface,
446 domcomment *This = impl_from_IXMLDOMComment( iface );
447 return IXMLDOMNode_get_namespaceURI( This->node, p );
450 static HRESULT WINAPI domcomment_get_prefix(
451 IXMLDOMComment *iface,
454 domcomment *This = impl_from_IXMLDOMComment( iface );
455 return IXMLDOMNode_get_prefix( This->node, p );
458 static HRESULT WINAPI domcomment_get_baseName(
459 IXMLDOMComment *iface,
462 domcomment *This = impl_from_IXMLDOMComment( iface );
463 return IXMLDOMNode_get_baseName( This->node, p );
466 static HRESULT WINAPI domcomment_transformNodeToObject(
467 IXMLDOMComment *iface,
468 IXMLDOMNode* domNode, VARIANT var1)
470 domcomment *This = impl_from_IXMLDOMComment( iface );
471 return IXMLDOMNode_transformNodeToObject( This->node, domNode, var1 );
474 static HRESULT WINAPI domcomment_get_data(
475 IXMLDOMComment *iface,
478 domcomment *This = impl_from_IXMLDOMComment( iface );
485 hr = IXMLDOMNode_get_nodeValue( This->node, &vRet );
494 static HRESULT WINAPI domcomment_put_data(
495 IXMLDOMComment *iface,
498 domcomment *This = impl_from_IXMLDOMComment( iface );
502 TRACE("%p %s\n", This, debugstr_w(data) );
504 V_VT(&val) = VT_BSTR;
507 hr = IXMLDOMNode_put_nodeValue( This->node, val );
512 static HRESULT WINAPI domcomment_get_length(
513 IXMLDOMComment *iface,
516 domcomment *This = impl_from_IXMLDOMComment( iface );
517 xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
521 TRACE("%p\n", iface);
526 pContent = xmlNodeGetContent(pDOMNode->node);
529 nLength = xmlStrlen(pContent);
538 static HRESULT WINAPI domcomment_substringData(
539 IXMLDOMComment *iface,
540 long offset, long count, BSTR *p)
542 domcomment *This = impl_from_IXMLDOMComment( iface );
543 xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
546 HRESULT hr = S_FALSE;
548 TRACE("%p\n", iface);
554 if(offset < 0 || count < 0)
560 pContent = xmlNodeGetContent(pDOMNode->node);
563 nLength = xmlStrlen(pContent);
565 if( offset < nLength)
567 BSTR sContent = bstr_from_xmlChar(pContent);
568 if(offset + count > nLength)
569 *p = SysAllocString(&sContent[offset]);
571 *p = SysAllocStringLen(&sContent[offset], count);
573 SysFreeString(sContent);
583 static HRESULT WINAPI domcomment_appendData(
584 IXMLDOMComment *iface,
587 domcomment *This = impl_from_IXMLDOMComment( iface );
588 xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
590 HRESULT hr = S_FALSE;
592 TRACE("%p\n", iface);
594 /* Nothing to do if NULL or an Empty string passed in. */
595 if(p == NULL || SysStringLen(p) == 0)
598 pContent = xmlChar_from_wchar( (WCHAR*)p );
601 /* Older versions of libxml < 2.6.27 didn't correctly support
602 xmlTextConcat on Comment nodes. Fallback to setting the
603 contents directly if xmlTextConcat fails.
605 NOTE: if xmlTextConcat fails, pContent is destroyed.
607 if(xmlTextConcat(pDOMNode->node, pContent, SysStringLen(p) ) == 0)
612 pContent = xmlChar_from_wchar( (WCHAR*)p );
615 pNew = xmlStrcat(xmlNodeGetContent(pDOMNode->node), pContent);
618 xmlNodeSetContent(pDOMNode->node, pNew);
634 static HRESULT WINAPI domcomment_insertData(
635 IXMLDOMComment *iface,
638 domcomment *This = impl_from_IXMLDOMComment( iface );
639 xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
640 xmlChar *pXmlContent;
642 HRESULT hr = S_FALSE;
643 long nLength = 0, nLengthP = 0;
648 /* If have a NULL or empty string, don't do anything. */
649 if(SysStringLen(p) == 0)
657 pXmlContent = xmlNodeGetContent(pDOMNode->node);
660 BSTR sContent = bstr_from_xmlChar( pXmlContent );
661 nLength = SysStringLen(sContent);
662 nLengthP = SysStringLen(p);
666 SysFreeString(sContent);
667 xmlFree(pXmlContent);
672 sNewString = SysAllocStringLen(NULL, nLength + nLengthP + 1);
676 memcpy(sNewString, sContent, offset * sizeof(WCHAR));
678 memcpy(&sNewString[offset], p, nLengthP * sizeof(WCHAR));
680 if(offset+nLengthP < nLength)
681 memcpy(&sNewString[offset+nLengthP], &sContent[offset], (nLength-offset) * sizeof(WCHAR));
683 sNewString[nLengthP + nLength] = 0;
685 str = xmlChar_from_wchar((WCHAR*)sNewString);
688 xmlNodeSetContent(pDOMNode->node, str);
692 SysFreeString(sNewString);
695 SysFreeString(sContent);
697 xmlFree(pXmlContent);
703 static HRESULT WINAPI domcomment_deleteData(
704 IXMLDOMComment *iface,
705 long offset, long count)
711 static HRESULT WINAPI domcomment_replaceData(
712 IXMLDOMComment *iface,
713 long offset, long count, BSTR p)
719 static const struct IXMLDOMCommentVtbl domcomment_vtbl =
721 domcomment_QueryInterface,
724 domcomment_GetTypeInfoCount,
725 domcomment_GetTypeInfo,
726 domcomment_GetIDsOfNames,
728 domcomment_get_nodeName,
729 domcomment_get_nodeValue,
730 domcomment_put_nodeValue,
731 domcomment_get_nodeType,
732 domcomment_get_parentNode,
733 domcomment_get_childNodes,
734 domcomment_get_firstChild,
735 domcomment_get_lastChild,
736 domcomment_get_previousSibling,
737 domcomment_get_nextSibling,
738 domcomment_get_attributes,
739 domcomment_insertBefore,
740 domcomment_replaceChild,
741 domcomment_removeChild,
742 domcomment_appendChild,
743 domcomment_hasChildNodes,
744 domcomment_get_ownerDocument,
745 domcomment_cloneNode,
746 domcomment_get_nodeTypeString,
749 domcomment_get_specified,
750 domcomment_get_definition,
751 domcomment_get_nodeTypedValue,
752 domcomment_put_nodeTypedValue,
753 domcomment_get_dataType,
754 domcomment_put_dataType,
756 domcomment_transformNode,
757 domcomment_selectNodes,
758 domcomment_selectSingleNode,
759 domcomment_get_parsed,
760 domcomment_get_namespaceURI,
761 domcomment_get_prefix,
762 domcomment_get_baseName,
763 domcomment_transformNodeToObject,
766 domcomment_get_length,
767 domcomment_substringData,
768 domcomment_appendData,
769 domcomment_insertData,
770 domcomment_deleteData,
771 domcomment_replaceData
774 IUnknown* create_comment( xmlNodePtr comment )
779 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
783 This->lpVtbl = &domcomment_vtbl;
786 This->node_unk = create_basic_node( comment, (IUnknown*)&This->lpVtbl );
789 HeapFree(GetProcessHeap(), 0, This);
793 hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
796 IUnknown_Release(This->node_unk);
797 HeapFree( GetProcessHeap(), 0, This );
800 /* The ref on This->node is actually looped back into this object, so release it */
801 IXMLDOMNode_Release(This->node);
803 return (IUnknown*) &This->lpVtbl;