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_IXMLDOMNode ) ||
63 IsEqualGUID( riid, &IID_IDispatch ) ||
64 IsEqualGUID( riid, &IID_IUnknown ) )
68 else if(node_query_interface(&This->node, riid, ppvObject))
70 return *ppvObject ? S_OK : E_NOINTERFACE;
74 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
78 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
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 destroy_xmlnode(&This->node);
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 );
188 static const WCHAR commentW[] = {'#','c','o','m','m','e','n','t',0};
190 TRACE("(%p)->(%p)\n", This, p);
192 return return_bstr(commentW, p);
195 static HRESULT WINAPI domcomment_get_nodeValue(
196 IXMLDOMComment *iface,
199 domcomment *This = impl_from_IXMLDOMComment( iface );
201 TRACE("(%p)->(%p)\n", This, value);
203 return node_get_content(&This->node, value);
206 static HRESULT WINAPI domcomment_put_nodeValue(
207 IXMLDOMComment *iface,
210 domcomment *This = impl_from_IXMLDOMComment( iface );
212 TRACE("(%p)->(v%d)\n", This, V_VT(&value));
214 return node_put_value(&This->node, &value);
217 static HRESULT WINAPI domcomment_get_nodeType(
218 IXMLDOMComment *iface,
219 DOMNodeType* domNodeType )
221 domcomment *This = impl_from_IXMLDOMComment( iface );
223 TRACE("(%p)->(%p)\n", This, domNodeType);
225 *domNodeType = NODE_COMMENT;
229 static HRESULT WINAPI domcomment_get_parentNode(
230 IXMLDOMComment *iface,
231 IXMLDOMNode** parent )
233 domcomment *This = impl_from_IXMLDOMComment( iface );
235 TRACE("(%p)->(%p)\n", This, parent);
237 return node_get_parent(&This->node, parent);
240 static HRESULT WINAPI domcomment_get_childNodes(
241 IXMLDOMComment *iface,
242 IXMLDOMNodeList** outList)
244 domcomment *This = impl_from_IXMLDOMComment( iface );
246 TRACE("(%p)->(%p)\n", This, outList);
248 return node_get_child_nodes(&This->node, outList);
251 static HRESULT WINAPI domcomment_get_firstChild(
252 IXMLDOMComment *iface,
253 IXMLDOMNode** domNode)
255 domcomment *This = impl_from_IXMLDOMComment( iface );
257 TRACE("(%p)->(%p)\n", This, domNode);
259 return return_null_node(domNode);
262 static HRESULT WINAPI domcomment_get_lastChild(
263 IXMLDOMComment *iface,
264 IXMLDOMNode** domNode)
266 domcomment *This = impl_from_IXMLDOMComment( iface );
268 TRACE("(%p)->(%p)\n", This, domNode);
270 return return_null_node(domNode);
273 static HRESULT WINAPI domcomment_get_previousSibling(
274 IXMLDOMComment *iface,
275 IXMLDOMNode** domNode)
277 domcomment *This = impl_from_IXMLDOMComment( iface );
279 TRACE("(%p)->(%p)\n", This, domNode);
281 return node_get_previous_sibling(&This->node, domNode);
284 static HRESULT WINAPI domcomment_get_nextSibling(
285 IXMLDOMComment *iface,
286 IXMLDOMNode** domNode)
288 domcomment *This = impl_from_IXMLDOMComment( iface );
290 TRACE("(%p)->(%p)\n", This, domNode);
292 return node_get_next_sibling(&This->node, domNode);
295 static HRESULT WINAPI domcomment_get_attributes(
296 IXMLDOMComment *iface,
297 IXMLDOMNamedNodeMap** attributeMap)
299 domcomment *This = impl_from_IXMLDOMComment( iface );
301 TRACE("(%p)->(%p)\n", This, attributeMap);
303 return return_null_ptr((void**)attributeMap);
306 static HRESULT WINAPI domcomment_insertBefore(
307 IXMLDOMComment *iface,
308 IXMLDOMNode* newNode, VARIANT refChild,
309 IXMLDOMNode** outOldNode)
311 domcomment *This = impl_from_IXMLDOMComment( iface );
313 FIXME("(%p)->(%p x%d %p) needs test\n", This, newNode, V_VT(&refChild), outOldNode);
315 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
318 static HRESULT WINAPI domcomment_replaceChild(
319 IXMLDOMComment *iface,
320 IXMLDOMNode* newNode,
321 IXMLDOMNode* oldNode,
322 IXMLDOMNode** outOldNode)
324 domcomment *This = impl_from_IXMLDOMComment( iface );
325 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
328 static HRESULT WINAPI domcomment_removeChild(
329 IXMLDOMComment *iface,
330 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
332 domcomment *This = impl_from_IXMLDOMComment( iface );
333 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
336 static HRESULT WINAPI domcomment_appendChild(
337 IXMLDOMComment *iface,
338 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
340 domcomment *This = impl_from_IXMLDOMComment( iface );
341 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
344 static HRESULT WINAPI domcomment_hasChildNodes(
345 IXMLDOMComment *iface,
348 domcomment *This = impl_from_IXMLDOMComment( iface );
349 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
352 static HRESULT WINAPI domcomment_get_ownerDocument(
353 IXMLDOMComment *iface,
354 IXMLDOMDocument** domDocument)
356 domcomment *This = impl_from_IXMLDOMComment( iface );
357 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
360 static HRESULT WINAPI domcomment_cloneNode(
361 IXMLDOMComment *iface,
362 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
364 domcomment *This = impl_from_IXMLDOMComment( iface );
365 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
368 static HRESULT WINAPI domcomment_get_nodeTypeString(
369 IXMLDOMComment *iface,
372 domcomment *This = impl_from_IXMLDOMComment( iface );
373 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
376 static HRESULT WINAPI domcomment_get_text(
377 IXMLDOMComment *iface,
380 domcomment *This = impl_from_IXMLDOMComment( iface );
381 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
384 static HRESULT WINAPI domcomment_put_text(
385 IXMLDOMComment *iface,
388 domcomment *This = impl_from_IXMLDOMComment( iface );
389 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
392 static HRESULT WINAPI domcomment_get_specified(
393 IXMLDOMComment *iface,
396 domcomment *This = impl_from_IXMLDOMComment( iface );
397 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
400 static HRESULT WINAPI domcomment_get_definition(
401 IXMLDOMComment *iface,
402 IXMLDOMNode** domNode)
404 domcomment *This = impl_from_IXMLDOMComment( iface );
405 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
408 static HRESULT WINAPI domcomment_get_nodeTypedValue(
409 IXMLDOMComment *iface,
412 domcomment *This = impl_from_IXMLDOMComment( iface );
413 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
416 static HRESULT WINAPI domcomment_put_nodeTypedValue(
417 IXMLDOMComment *iface,
420 domcomment *This = impl_from_IXMLDOMComment( iface );
421 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
424 static HRESULT WINAPI domcomment_get_dataType(
425 IXMLDOMComment *iface,
428 domcomment *This = impl_from_IXMLDOMComment( iface );
429 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
432 static HRESULT WINAPI domcomment_put_dataType(
433 IXMLDOMComment *iface,
436 domcomment *This = impl_from_IXMLDOMComment( iface );
437 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
440 static HRESULT WINAPI domcomment_get_xml(
441 IXMLDOMComment *iface,
444 domcomment *This = impl_from_IXMLDOMComment( iface );
445 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
448 static HRESULT WINAPI domcomment_transformNode(
449 IXMLDOMComment *iface,
450 IXMLDOMNode* domNode, BSTR* p)
452 domcomment *This = impl_from_IXMLDOMComment( iface );
453 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
456 static HRESULT WINAPI domcomment_selectNodes(
457 IXMLDOMComment *iface,
458 BSTR p, IXMLDOMNodeList** outList)
460 domcomment *This = impl_from_IXMLDOMComment( iface );
461 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
464 static HRESULT WINAPI domcomment_selectSingleNode(
465 IXMLDOMComment *iface,
466 BSTR p, IXMLDOMNode** outNode)
468 domcomment *This = impl_from_IXMLDOMComment( iface );
469 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
472 static HRESULT WINAPI domcomment_get_parsed(
473 IXMLDOMComment *iface,
476 domcomment *This = impl_from_IXMLDOMComment( iface );
477 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
480 static HRESULT WINAPI domcomment_get_namespaceURI(
481 IXMLDOMComment *iface,
484 domcomment *This = impl_from_IXMLDOMComment( iface );
485 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
488 static HRESULT WINAPI domcomment_get_prefix(
489 IXMLDOMComment *iface,
492 domcomment *This = impl_from_IXMLDOMComment( iface );
493 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
496 static HRESULT WINAPI domcomment_get_baseName(
497 IXMLDOMComment *iface,
500 domcomment *This = impl_from_IXMLDOMComment( iface );
501 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
504 static HRESULT WINAPI domcomment_transformNodeToObject(
505 IXMLDOMComment *iface,
506 IXMLDOMNode* domNode, VARIANT var1)
508 domcomment *This = impl_from_IXMLDOMComment( iface );
509 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
512 static HRESULT WINAPI domcomment_get_data(
513 IXMLDOMComment *iface,
516 domcomment *This = impl_from_IXMLDOMComment( iface );
520 TRACE("(%p)->(%p)\n", This, p);
525 hr = IXMLDOMComment_get_nodeValue( iface, &vRet );
534 static HRESULT WINAPI domcomment_put_data(
535 IXMLDOMComment *iface,
538 domcomment *This = impl_from_IXMLDOMComment( iface );
541 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
543 V_VT(&val) = VT_BSTR;
545 return node_put_value(&This->node, &val);
548 static HRESULT WINAPI domcomment_get_length(
549 IXMLDOMComment *iface,
552 domcomment *This = impl_from_IXMLDOMComment( iface );
556 TRACE("(%p)->(%p)\n", This, len);
561 hr = IXMLDOMComment_get_data(iface, &data);
564 *len = SysStringLen(data);
571 static HRESULT WINAPI domcomment_substringData(
572 IXMLDOMComment *iface,
573 LONG offset, LONG count, BSTR *p)
575 domcomment *This = impl_from_IXMLDOMComment( iface );
579 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
585 if(offset < 0 || count < 0)
591 hr = IXMLDOMComment_get_data(iface, &data);
594 LONG len = SysStringLen(data);
598 if(offset + count > len)
599 *p = SysAllocString(&data[offset]);
601 *p = SysAllocStringLen(&data[offset], count);
612 static HRESULT WINAPI domcomment_appendData(
613 IXMLDOMComment *iface,
616 domcomment *This = impl_from_IXMLDOMComment( iface );
621 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
623 /* Nothing to do if NULL or an Empty string passed in. */
624 if((p_len = SysStringLen(p)) == 0) return S_OK;
626 hr = IXMLDOMComment_get_data(iface, &data);
629 LONG len = SysStringLen(data);
630 BSTR str = SysAllocStringLen(NULL, p_len + len);
632 memcpy(str, data, len*sizeof(WCHAR));
633 memcpy(&str[len], p, p_len*sizeof(WCHAR));
636 hr = IXMLDOMComment_put_data(iface, str);
645 static HRESULT WINAPI domcomment_insertData(
646 IXMLDOMComment *iface,
649 domcomment *This = impl_from_IXMLDOMComment( iface );
654 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
656 /* If have a NULL or empty string, don't do anything. */
657 if((p_len = SysStringLen(p)) == 0)
665 hr = IXMLDOMComment_get_data(iface, &data);
668 LONG len = SysStringLen(data);
677 str = SysAllocStringLen(NULL, len + p_len);
678 /* start part, supplied string and end part */
679 memcpy(str, data, offset*sizeof(WCHAR));
680 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
681 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
684 hr = IXMLDOMComment_put_data(iface, str);
693 static HRESULT WINAPI domcomment_deleteData(
694 IXMLDOMComment *iface,
695 LONG offset, LONG count)
701 TRACE("(%p)->(%d %d)\n", iface, offset, count);
703 hr = IXMLDOMComment_get_length(iface, &len);
704 if(hr != S_OK) return hr;
706 if((offset < 0) || (offset > len) || (count < 0))
709 if(len == 0) return S_OK;
711 /* cutting start or end */
712 if((offset == 0) || ((count + offset) >= len))
715 IXMLDOMComment_substringData(iface, count, len - count, &str);
717 IXMLDOMComment_substringData(iface, 0, offset, &str);
718 hr = IXMLDOMComment_put_data(iface, str);
721 /* cutting from the inside */
725 IXMLDOMComment_substringData(iface, 0, offset, &str);
726 IXMLDOMComment_substringData(iface, offset + count, len - count, &str_end);
728 hr = IXMLDOMComment_put_data(iface, str);
730 hr = IXMLDOMComment_appendData(iface, str_end);
732 SysFreeString(str_end);
740 static HRESULT WINAPI domcomment_replaceData(
741 IXMLDOMComment *iface,
742 LONG offset, LONG count, BSTR p)
744 domcomment *This = impl_from_IXMLDOMComment( iface );
747 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
749 hr = IXMLDOMComment_deleteData(iface, offset, count);
752 hr = IXMLDOMComment_insertData(iface, offset, p);
757 static const struct IXMLDOMCommentVtbl domcomment_vtbl =
759 domcomment_QueryInterface,
762 domcomment_GetTypeInfoCount,
763 domcomment_GetTypeInfo,
764 domcomment_GetIDsOfNames,
766 domcomment_get_nodeName,
767 domcomment_get_nodeValue,
768 domcomment_put_nodeValue,
769 domcomment_get_nodeType,
770 domcomment_get_parentNode,
771 domcomment_get_childNodes,
772 domcomment_get_firstChild,
773 domcomment_get_lastChild,
774 domcomment_get_previousSibling,
775 domcomment_get_nextSibling,
776 domcomment_get_attributes,
777 domcomment_insertBefore,
778 domcomment_replaceChild,
779 domcomment_removeChild,
780 domcomment_appendChild,
781 domcomment_hasChildNodes,
782 domcomment_get_ownerDocument,
783 domcomment_cloneNode,
784 domcomment_get_nodeTypeString,
787 domcomment_get_specified,
788 domcomment_get_definition,
789 domcomment_get_nodeTypedValue,
790 domcomment_put_nodeTypedValue,
791 domcomment_get_dataType,
792 domcomment_put_dataType,
794 domcomment_transformNode,
795 domcomment_selectNodes,
796 domcomment_selectSingleNode,
797 domcomment_get_parsed,
798 domcomment_get_namespaceURI,
799 domcomment_get_prefix,
800 domcomment_get_baseName,
801 domcomment_transformNodeToObject,
804 domcomment_get_length,
805 domcomment_substringData,
806 domcomment_appendData,
807 domcomment_insertData,
808 domcomment_deleteData,
809 domcomment_replaceData
812 IUnknown* create_comment( xmlNodePtr comment )
816 This = heap_alloc( sizeof *This );
820 This->lpVtbl = &domcomment_vtbl;
823 init_xmlnode(&This->node, comment, (IXMLDOMNode*)&This->lpVtbl, NULL);
825 return (IUnknown*) &This->lpVtbl;