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
);
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
);
480 TRACE("(%p)->(%p)\n", This
, p
);
485 hr
= IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This
->node
), &vRet
);
494 static HRESULT WINAPI
domcomment_put_data(
495 IXMLDOMComment
*iface
,
498 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
501 TRACE("(%p)->(%s)\n", This
, debugstr_w(data
) );
503 V_VT(&val
) = VT_BSTR
;
506 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This
->node
), val
);
509 static HRESULT WINAPI
domcomment_get_length(
510 IXMLDOMComment
*iface
,
513 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
517 TRACE("(%p)->(%p)\n", This
, len
);
522 hr
= IXMLDOMComment_get_data(iface
, &data
);
525 *len
= SysStringLen(data
);
532 static HRESULT WINAPI
domcomment_substringData(
533 IXMLDOMComment
*iface
,
534 LONG offset
, LONG count
, BSTR
*p
)
536 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
540 TRACE("(%p)->(%d %d %p)\n", This
, offset
, count
, p
);
546 if(offset
< 0 || count
< 0)
552 hr
= IXMLDOMComment_get_data(iface
, &data
);
555 LONG len
= SysStringLen(data
);
559 if(offset
+ count
> len
)
560 *p
= SysAllocString(&data
[offset
]);
562 *p
= SysAllocStringLen(&data
[offset
], count
);
573 static HRESULT WINAPI
domcomment_appendData(
574 IXMLDOMComment
*iface
,
577 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
582 TRACE("(%p)->(%s)\n", This
, debugstr_w(p
));
584 /* Nothing to do if NULL or an Empty string passed in. */
585 if((p_len
= SysStringLen(p
)) == 0) return S_OK
;
587 hr
= IXMLDOMComment_get_data(iface
, &data
);
590 LONG len
= SysStringLen(data
);
591 BSTR str
= SysAllocStringLen(NULL
, p_len
+ len
);
593 memcpy(str
, data
, len
*sizeof(WCHAR
));
594 memcpy(&str
[len
], p
, p_len
*sizeof(WCHAR
));
597 hr
= IXMLDOMComment_put_data(iface
, str
);
606 static HRESULT WINAPI
domcomment_insertData(
607 IXMLDOMComment
*iface
,
610 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
615 TRACE("(%p)->(%d %s)\n", This
, offset
, debugstr_w(p
));
617 /* If have a NULL or empty string, don't do anything. */
618 if((p_len
= SysStringLen(p
)) == 0)
626 hr
= IXMLDOMComment_get_data(iface
, &data
);
629 LONG len
= SysStringLen(data
);
638 str
= SysAllocStringLen(NULL
, len
+ p_len
);
639 /* start part, supplied string and end part */
640 memcpy(str
, data
, offset
*sizeof(WCHAR
));
641 memcpy(&str
[offset
], p
, p_len
*sizeof(WCHAR
));
642 memcpy(&str
[offset
+p_len
], &data
[offset
], (len
-offset
)*sizeof(WCHAR
));
645 hr
= IXMLDOMComment_put_data(iface
, str
);
654 static HRESULT WINAPI
domcomment_deleteData(
655 IXMLDOMComment
*iface
,
656 LONG offset
, LONG count
)
662 TRACE("(%p)->(%d %d)\n", iface
, offset
, count
);
664 hr
= IXMLDOMComment_get_length(iface
, &len
);
665 if(hr
!= S_OK
) return hr
;
667 if((offset
< 0) || (offset
> len
) || (count
< 0))
670 if(len
== 0) return S_OK
;
672 /* cutting start or end */
673 if((offset
== 0) || ((count
+ offset
) >= len
))
676 IXMLDOMComment_substringData(iface
, count
, len
- count
, &str
);
678 IXMLDOMComment_substringData(iface
, 0, offset
, &str
);
679 hr
= IXMLDOMComment_put_data(iface
, str
);
682 /* cutting from the inside */
686 IXMLDOMComment_substringData(iface
, 0, offset
, &str
);
687 IXMLDOMComment_substringData(iface
, offset
+ count
, len
- count
, &str_end
);
689 hr
= IXMLDOMComment_put_data(iface
, str
);
691 hr
= IXMLDOMComment_appendData(iface
, str_end
);
693 SysFreeString(str_end
);
701 static HRESULT WINAPI
domcomment_replaceData(
702 IXMLDOMComment
*iface
,
703 LONG offset
, LONG count
, BSTR p
)
705 domcomment
*This
= impl_from_IXMLDOMComment( iface
);
708 TRACE("(%p)->(%d %d %s)\n", This
, offset
, count
, debugstr_w(p
));
710 hr
= IXMLDOMComment_deleteData(iface
, offset
, count
);
713 hr
= IXMLDOMComment_insertData(iface
, offset
, 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
)
777 This
= heap_alloc( sizeof *This
);
781 This
->lpVtbl
= &domcomment_vtbl
;
784 init_xmlnode(&This
->node
, comment
, (IUnknown
*)&This
->lpVtbl
, NULL
);
786 return (IUnknown
*) &This
->lpVtbl
;