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
43 const struct IXMLDOMCommentVtbl
*lpVtbl
;
47 static inline domcomment
*impl_from_IXMLDOMComment( IXMLDOMComment
*iface
)
49 return (domcomment
*)((char*)iface
- FIELD_OFFSET(domcomment
, lpVtbl
));
52 static HRESULT WINAPI
domcomment_QueryInterface(
53 IXMLDOMComment
*iface
,
57 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
58 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
60 if ( IsEqualGUID( riid
, &IID_IXMLDOMComment
) ||
61 IsEqualGUID( riid
, &IID_IXMLDOMCharacterData
) ||
62 IsEqualGUID( riid
, &IID_IDispatch
) ||
63 IsEqualGUID( riid
, &IID_IUnknown
) )
67 else if ( IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
69 *ppvObject
= IXMLDOMNode_from_impl(&This
->node
);
73 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
77 IXMLDOMText_AddRef((IUnknown
*)*ppvObject
);
81 static ULONG WINAPI
domcomment_AddRef(
82 IXMLDOMComment
*iface
)
84 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
85 return InterlockedIncrement( &This
->ref
);
88 static ULONG WINAPI
domcomment_Release(
89 IXMLDOMComment
*iface
)
91 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
94 ref
= InterlockedDecrement( &This
->ref
);
97 destroy_xmlnode(&This
->node
);
98 HeapFree( GetProcessHeap(), 0, This
);
104 static HRESULT WINAPI
domcomment_GetTypeInfoCount(
105 IXMLDOMComment
*iface
,
108 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
110 TRACE("(%p)->(%p)\n", This
, pctinfo
);
117 static HRESULT WINAPI
domcomment_GetTypeInfo(
118 IXMLDOMComment
*iface
,
119 UINT iTInfo
, LCID lcid
,
120 ITypeInfo
** ppTInfo
)
122 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
125 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
127 hr
= get_typeinfo(IXMLDOMComment_tid
, ppTInfo
);
132 static HRESULT WINAPI
domcomment_GetIDsOfNames(
133 IXMLDOMComment
*iface
,
134 REFIID riid
, LPOLESTR
* rgszNames
,
135 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
137 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
141 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
144 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
147 hr
= get_typeinfo(IXMLDOMComment_tid
, &typeinfo
);
150 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
151 ITypeInfo_Release(typeinfo
);
157 static HRESULT WINAPI
domcomment_Invoke(
158 IXMLDOMComment
*iface
,
159 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
160 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
161 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
163 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
167 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
168 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
170 hr
= get_typeinfo(IXMLDOMComment_tid
, &typeinfo
);
173 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
174 pVarResult
, pExcepInfo
, puArgErr
);
175 ITypeInfo_Release(typeinfo
);
181 static HRESULT WINAPI
domcomment_get_nodeName(
182 IXMLDOMComment
*iface
,
185 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
186 return IXMLDOMNode_get_nodeName( IXMLDOMNode_from_impl(&This
->node
), p
);
189 static HRESULT WINAPI
domcomment_get_nodeValue(
190 IXMLDOMComment
*iface
,
193 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
194 return IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This
->node
), var1
);
197 static HRESULT WINAPI
domcomment_put_nodeValue(
198 IXMLDOMComment
*iface
,
201 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
202 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This
->node
), var1
);
205 static HRESULT WINAPI
domcomment_get_nodeType(
206 IXMLDOMComment
*iface
,
207 DOMNodeType
* domNodeType
)
209 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
210 return IXMLDOMNode_get_nodeType( IXMLDOMNode_from_impl(&This
->node
), domNodeType
);
213 static HRESULT WINAPI
domcomment_get_parentNode(
214 IXMLDOMComment
*iface
,
215 IXMLDOMNode
** parent
)
217 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
218 return IXMLDOMNode_get_parentNode( IXMLDOMNode_from_impl(&This
->node
), parent
);
221 static HRESULT WINAPI
domcomment_get_childNodes(
222 IXMLDOMComment
*iface
,
223 IXMLDOMNodeList
** outList
)
225 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
226 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This
->node
), outList
);
229 static HRESULT WINAPI
domcomment_get_firstChild(
230 IXMLDOMComment
*iface
,
231 IXMLDOMNode
** domNode
)
233 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
234 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This
->node
), domNode
);
237 static HRESULT WINAPI
domcomment_get_lastChild(
238 IXMLDOMComment
*iface
,
239 IXMLDOMNode
** domNode
)
241 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
242 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This
->node
), domNode
);
245 static HRESULT WINAPI
domcomment_get_previousSibling(
246 IXMLDOMComment
*iface
,
247 IXMLDOMNode
** domNode
)
249 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
250 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This
->node
), domNode
);
253 static HRESULT WINAPI
domcomment_get_nextSibling(
254 IXMLDOMComment
*iface
,
255 IXMLDOMNode
** domNode
)
257 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
258 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This
->node
), domNode
);
261 static HRESULT WINAPI
domcomment_get_attributes(
262 IXMLDOMComment
*iface
,
263 IXMLDOMNamedNodeMap
** attributeMap
)
265 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
266 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This
->node
), attributeMap
);
269 static HRESULT WINAPI
domcomment_insertBefore(
270 IXMLDOMComment
*iface
,
271 IXMLDOMNode
* newNode
, VARIANT var1
,
272 IXMLDOMNode
** outOldNode
)
274 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
275 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This
->node
), newNode
, var1
, outOldNode
);
278 static HRESULT WINAPI
domcomment_replaceChild(
279 IXMLDOMComment
*iface
,
280 IXMLDOMNode
* newNode
,
281 IXMLDOMNode
* oldNode
,
282 IXMLDOMNode
** outOldNode
)
284 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
285 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This
->node
), newNode
, oldNode
, outOldNode
);
288 static HRESULT WINAPI
domcomment_removeChild(
289 IXMLDOMComment
*iface
,
290 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
292 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
293 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This
->node
), domNode
, oldNode
);
296 static HRESULT WINAPI
domcomment_appendChild(
297 IXMLDOMComment
*iface
,
298 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
300 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
301 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This
->node
), newNode
, outNewNode
);
304 static HRESULT WINAPI
domcomment_hasChildNodes(
305 IXMLDOMComment
*iface
,
308 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
309 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This
->node
), pbool
);
312 static HRESULT WINAPI
domcomment_get_ownerDocument(
313 IXMLDOMComment
*iface
,
314 IXMLDOMDocument
** domDocument
)
316 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
317 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This
->node
), domDocument
);
320 static HRESULT WINAPI
domcomment_cloneNode(
321 IXMLDOMComment
*iface
,
322 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
324 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
325 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This
->node
), pbool
, outNode
);
328 static HRESULT WINAPI
domcomment_get_nodeTypeString(
329 IXMLDOMComment
*iface
,
332 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
333 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This
->node
), p
);
336 static HRESULT WINAPI
domcomment_get_text(
337 IXMLDOMComment
*iface
,
340 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
341 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This
->node
), p
);
344 static HRESULT WINAPI
domcomment_put_text(
345 IXMLDOMComment
*iface
,
348 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
349 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This
->node
), p
);
352 static HRESULT WINAPI
domcomment_get_specified(
353 IXMLDOMComment
*iface
,
356 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
357 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This
->node
), pbool
);
360 static HRESULT WINAPI
domcomment_get_definition(
361 IXMLDOMComment
*iface
,
362 IXMLDOMNode
** domNode
)
364 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
365 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This
->node
), domNode
);
368 static HRESULT WINAPI
domcomment_get_nodeTypedValue(
369 IXMLDOMComment
*iface
,
372 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
373 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This
->node
), var1
);
376 static HRESULT WINAPI
domcomment_put_nodeTypedValue(
377 IXMLDOMComment
*iface
,
380 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
381 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This
->node
), var1
);
384 static HRESULT WINAPI
domcomment_get_dataType(
385 IXMLDOMComment
*iface
,
388 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
389 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This
->node
), var1
);
392 static HRESULT WINAPI
domcomment_put_dataType(
393 IXMLDOMComment
*iface
,
396 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
397 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This
->node
), p
);
400 static HRESULT WINAPI
domcomment_get_xml(
401 IXMLDOMComment
*iface
,
404 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
405 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This
->node
), p
);
408 static HRESULT WINAPI
domcomment_transformNode(
409 IXMLDOMComment
*iface
,
410 IXMLDOMNode
* domNode
, BSTR
* p
)
412 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
413 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This
->node
), domNode
, p
);
416 static HRESULT WINAPI
domcomment_selectNodes(
417 IXMLDOMComment
*iface
,
418 BSTR p
, IXMLDOMNodeList
** outList
)
420 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
421 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This
->node
), p
, outList
);
424 static HRESULT WINAPI
domcomment_selectSingleNode(
425 IXMLDOMComment
*iface
,
426 BSTR p
, IXMLDOMNode
** outNode
)
428 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
429 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This
->node
), p
, outNode
);
432 static HRESULT WINAPI
domcomment_get_parsed(
433 IXMLDOMComment
*iface
,
436 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
437 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This
->node
), pbool
);
440 static HRESULT WINAPI
domcomment_get_namespaceURI(
441 IXMLDOMComment
*iface
,
444 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
445 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This
->node
), p
);
448 static HRESULT WINAPI
domcomment_get_prefix(
449 IXMLDOMComment
*iface
,
452 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
453 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This
->node
), p
);
456 static HRESULT WINAPI
domcomment_get_baseName(
457 IXMLDOMComment
*iface
,
460 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
461 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This
->node
), p
);
464 static HRESULT WINAPI
domcomment_transformNodeToObject(
465 IXMLDOMComment
*iface
,
466 IXMLDOMNode
* domNode
, VARIANT var1
)
468 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
469 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This
->node
), domNode
, var1
);
472 static HRESULT WINAPI
domcomment_get_data(
473 IXMLDOMComment
*iface
,
476 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
483 hr
= IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This
->node
), &vRet
);
492 static HRESULT WINAPI
domcomment_put_data(
493 IXMLDOMComment
*iface
,
496 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
500 TRACE("%p %s\n", This
, debugstr_w(data
) );
502 V_VT(&val
) = VT_BSTR
;
505 hr
= IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This
->node
), val
);
510 static HRESULT WINAPI
domcomment_get_length(
511 IXMLDOMComment
*iface
,
514 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
518 TRACE("%p\n", iface
);
523 pContent
= xmlNodeGetContent(This
->node
.node
);
526 nLength
= xmlStrlen(pContent
);
535 static HRESULT WINAPI
domcomment_substringData(
536 IXMLDOMComment
*iface
,
537 LONG offset
, LONG count
, BSTR
*p
)
539 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
542 HRESULT hr
= S_FALSE
;
544 TRACE("%p\n", iface
);
550 if(offset
< 0 || count
< 0)
556 pContent
= xmlNodeGetContent(This
->node
.node
);
559 nLength
= xmlStrlen(pContent
);
561 if( offset
< nLength
)
563 BSTR sContent
= bstr_from_xmlChar(pContent
);
564 if(offset
+ count
> nLength
)
565 *p
= SysAllocString(&sContent
[offset
]);
567 *p
= SysAllocStringLen(&sContent
[offset
], count
);
569 SysFreeString(sContent
);
579 static HRESULT WINAPI
domcomment_appendData(
580 IXMLDOMComment
*iface
,
583 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
585 HRESULT hr
= S_FALSE
;
587 TRACE("%p\n", iface
);
589 /* Nothing to do if NULL or an Empty string passed in. */
590 if(p
== NULL
|| SysStringLen(p
) == 0)
593 pContent
= xmlChar_from_wchar( p
);
596 /* Older versions of libxml < 2.6.27 didn't correctly support
597 xmlTextConcat on Comment nodes. Fallback to setting the
598 contents directly if xmlTextConcat fails.
600 if(xmlTextConcat(This
->node
.node
, pContent
, SysStringLen(p
) ) == 0)
605 pNew
= xmlStrcat(xmlNodeGetContent(This
->node
.node
), pContent
);
608 xmlNodeSetContent(This
->node
.node
, pNew
);
614 HeapFree( GetProcessHeap(), 0, pContent
);
622 static HRESULT WINAPI
domcomment_insertData(
623 IXMLDOMComment
*iface
,
626 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
627 xmlChar
*pXmlContent
;
629 HRESULT hr
= S_FALSE
;
630 LONG nLength
= 0, nLengthP
= 0;
635 /* If have a NULL or empty string, don't do anything. */
636 if(SysStringLen(p
) == 0)
644 pXmlContent
= xmlNodeGetContent(This
->node
.node
);
647 BSTR sContent
= bstr_from_xmlChar( pXmlContent
);
648 nLength
= SysStringLen(sContent
);
649 nLengthP
= SysStringLen(p
);
653 SysFreeString(sContent
);
654 xmlFree(pXmlContent
);
659 sNewString
= SysAllocStringLen(NULL
, nLength
+ nLengthP
+ 1);
663 memcpy(sNewString
, sContent
, offset
* sizeof(WCHAR
));
665 memcpy(&sNewString
[offset
], p
, nLengthP
* sizeof(WCHAR
));
667 if(offset
+nLengthP
< nLength
)
668 memcpy(&sNewString
[offset
+nLengthP
], &sContent
[offset
], (nLength
-offset
) * sizeof(WCHAR
));
670 sNewString
[nLengthP
+ nLength
] = 0;
672 str
= xmlChar_from_wchar(sNewString
);
675 xmlNodeSetContent(This
->node
.node
, str
);
678 HeapFree( GetProcessHeap(), 0, str
);
680 SysFreeString(sNewString
);
683 SysFreeString(sContent
);
685 xmlFree(pXmlContent
);
691 static HRESULT WINAPI
domcomment_deleteData(
692 IXMLDOMComment
*iface
,
693 LONG offset
, LONG count
)
699 static HRESULT WINAPI
domcomment_replaceData(
700 IXMLDOMComment
*iface
,
701 LONG offset
, LONG count
, BSTR p
)
707 static const struct IXMLDOMCommentVtbl domcomment_vtbl
=
709 domcomment_QueryInterface
,
712 domcomment_GetTypeInfoCount
,
713 domcomment_GetTypeInfo
,
714 domcomment_GetIDsOfNames
,
716 domcomment_get_nodeName
,
717 domcomment_get_nodeValue
,
718 domcomment_put_nodeValue
,
719 domcomment_get_nodeType
,
720 domcomment_get_parentNode
,
721 domcomment_get_childNodes
,
722 domcomment_get_firstChild
,
723 domcomment_get_lastChild
,
724 domcomment_get_previousSibling
,
725 domcomment_get_nextSibling
,
726 domcomment_get_attributes
,
727 domcomment_insertBefore
,
728 domcomment_replaceChild
,
729 domcomment_removeChild
,
730 domcomment_appendChild
,
731 domcomment_hasChildNodes
,
732 domcomment_get_ownerDocument
,
733 domcomment_cloneNode
,
734 domcomment_get_nodeTypeString
,
737 domcomment_get_specified
,
738 domcomment_get_definition
,
739 domcomment_get_nodeTypedValue
,
740 domcomment_put_nodeTypedValue
,
741 domcomment_get_dataType
,
742 domcomment_put_dataType
,
744 domcomment_transformNode
,
745 domcomment_selectNodes
,
746 domcomment_selectSingleNode
,
747 domcomment_get_parsed
,
748 domcomment_get_namespaceURI
,
749 domcomment_get_prefix
,
750 domcomment_get_baseName
,
751 domcomment_transformNodeToObject
,
754 domcomment_get_length
,
755 domcomment_substringData
,
756 domcomment_appendData
,
757 domcomment_insertData
,
758 domcomment_deleteData
,
759 domcomment_replaceData
762 IUnknown
* create_comment( xmlNodePtr comment
)
766 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
770 This
->lpVtbl
= &domcomment_vtbl
;
773 init_xmlnode(&This
->node
, comment
, (IUnknown
*)&This
->lpVtbl
, NULL
);
775 return (IUnknown
*) &This
->lpVtbl
;