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 );
326 FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
328 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
331 static HRESULT WINAPI domcomment_removeChild(
332 IXMLDOMComment *iface,
333 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
335 domcomment *This = impl_from_IXMLDOMComment( iface );
336 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
339 static HRESULT WINAPI domcomment_appendChild(
340 IXMLDOMComment *iface,
341 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
343 domcomment *This = impl_from_IXMLDOMComment( iface );
344 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
347 static HRESULT WINAPI domcomment_hasChildNodes(
348 IXMLDOMComment *iface,
351 domcomment *This = impl_from_IXMLDOMComment( iface );
352 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
355 static HRESULT WINAPI domcomment_get_ownerDocument(
356 IXMLDOMComment *iface,
357 IXMLDOMDocument** domDocument)
359 domcomment *This = impl_from_IXMLDOMComment( iface );
360 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
363 static HRESULT WINAPI domcomment_cloneNode(
364 IXMLDOMComment *iface,
365 VARIANT_BOOL deep, IXMLDOMNode** outNode)
367 domcomment *This = impl_from_IXMLDOMComment( iface );
368 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
369 return node_clone( &This->node, deep, outNode );
372 static HRESULT WINAPI domcomment_get_nodeTypeString(
373 IXMLDOMComment *iface,
376 domcomment *This = impl_from_IXMLDOMComment( iface );
377 static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0};
379 TRACE("(%p)->(%p)\n", This, p);
381 return return_bstr(commentW, p);
384 static HRESULT WINAPI domcomment_get_text(
385 IXMLDOMComment *iface,
388 domcomment *This = impl_from_IXMLDOMComment( iface );
389 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
392 static HRESULT WINAPI domcomment_put_text(
393 IXMLDOMComment *iface,
396 domcomment *This = impl_from_IXMLDOMComment( iface );
397 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
398 return node_put_text( &This->node, p );
401 static HRESULT WINAPI domcomment_get_specified(
402 IXMLDOMComment *iface,
403 VARIANT_BOOL* isSpecified)
405 domcomment *This = impl_from_IXMLDOMComment( iface );
406 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
407 *isSpecified = VARIANT_TRUE;
411 static HRESULT WINAPI domcomment_get_definition(
412 IXMLDOMComment *iface,
413 IXMLDOMNode** definitionNode)
415 domcomment *This = impl_from_IXMLDOMComment( iface );
416 FIXME("(%p)->(%p)\n", This, definitionNode);
420 static HRESULT WINAPI domcomment_get_nodeTypedValue(
421 IXMLDOMComment *iface,
424 domcomment *This = impl_from_IXMLDOMComment( iface );
425 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
428 static HRESULT WINAPI domcomment_put_nodeTypedValue(
429 IXMLDOMComment *iface,
432 domcomment *This = impl_from_IXMLDOMComment( iface );
433 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
436 static HRESULT WINAPI domcomment_get_dataType(
437 IXMLDOMComment *iface,
440 domcomment *This = impl_from_IXMLDOMComment( iface );
441 TRACE("(%p)->(%p)\n", This, typename);
442 return return_null_var( typename );
445 static HRESULT WINAPI domcomment_put_dataType(
446 IXMLDOMComment *iface,
449 domcomment *This = impl_from_IXMLDOMComment( iface );
450 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
453 static HRESULT WINAPI domcomment_get_xml(
454 IXMLDOMComment *iface,
457 domcomment *This = impl_from_IXMLDOMComment( iface );
459 TRACE("(%p)->(%p)\n", This, p);
461 return node_get_xml(&This->node, FALSE, FALSE, p);
464 static HRESULT WINAPI domcomment_transformNode(
465 IXMLDOMComment *iface,
466 IXMLDOMNode* domNode, BSTR* p)
468 domcomment *This = impl_from_IXMLDOMComment( iface );
469 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
472 static HRESULT WINAPI domcomment_selectNodes(
473 IXMLDOMComment *iface,
474 BSTR p, IXMLDOMNodeList** outList)
476 domcomment *This = impl_from_IXMLDOMComment( iface );
477 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
480 static HRESULT WINAPI domcomment_selectSingleNode(
481 IXMLDOMComment *iface,
482 BSTR p, IXMLDOMNode** outNode)
484 domcomment *This = impl_from_IXMLDOMComment( iface );
485 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
488 static HRESULT WINAPI domcomment_get_parsed(
489 IXMLDOMComment *iface,
490 VARIANT_BOOL* isParsed)
492 domcomment *This = impl_from_IXMLDOMComment( iface );
493 FIXME("(%p)->(%p) stub!\n", This, isParsed);
494 *isParsed = VARIANT_TRUE;
498 static HRESULT WINAPI domcomment_get_namespaceURI(
499 IXMLDOMComment *iface,
502 domcomment *This = impl_from_IXMLDOMComment( iface );
503 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
506 static HRESULT WINAPI domcomment_get_prefix(
507 IXMLDOMComment *iface,
510 domcomment *This = impl_from_IXMLDOMComment( iface );
511 TRACE("(%p)->(%p)\n", This, prefix);
512 return return_null_bstr( prefix );
515 static HRESULT WINAPI domcomment_get_baseName(
516 IXMLDOMComment *iface,
519 domcomment *This = impl_from_IXMLDOMComment( iface );
520 TRACE("(%p)->(%p)\n", This, name);
521 return return_null_bstr( name );
524 static HRESULT WINAPI domcomment_transformNodeToObject(
525 IXMLDOMComment *iface,
526 IXMLDOMNode* domNode, VARIANT var1)
528 domcomment *This = impl_from_IXMLDOMComment( iface );
529 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
532 static HRESULT WINAPI domcomment_get_data(
533 IXMLDOMComment *iface,
536 domcomment *This = impl_from_IXMLDOMComment( iface );
540 TRACE("(%p)->(%p)\n", This, p);
545 hr = IXMLDOMComment_get_nodeValue( iface, &vRet );
554 static HRESULT WINAPI domcomment_put_data(
555 IXMLDOMComment *iface,
558 domcomment *This = impl_from_IXMLDOMComment( iface );
561 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
563 V_VT(&val) = VT_BSTR;
565 return node_put_value(&This->node, &val);
568 static HRESULT WINAPI domcomment_get_length(
569 IXMLDOMComment *iface,
572 domcomment *This = impl_from_IXMLDOMComment( iface );
576 TRACE("(%p)->(%p)\n", This, len);
581 hr = IXMLDOMComment_get_data(iface, &data);
584 *len = SysStringLen(data);
591 static HRESULT WINAPI domcomment_substringData(
592 IXMLDOMComment *iface,
593 LONG offset, LONG count, BSTR *p)
595 domcomment *This = impl_from_IXMLDOMComment( iface );
599 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
605 if(offset < 0 || count < 0)
611 hr = IXMLDOMComment_get_data(iface, &data);
614 LONG len = SysStringLen(data);
618 if(offset + count > len)
619 *p = SysAllocString(&data[offset]);
621 *p = SysAllocStringLen(&data[offset], count);
632 static HRESULT WINAPI domcomment_appendData(
633 IXMLDOMComment *iface,
636 domcomment *This = impl_from_IXMLDOMComment( iface );
641 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
643 /* Nothing to do if NULL or an Empty string passed in. */
644 if((p_len = SysStringLen(p)) == 0) return S_OK;
646 hr = IXMLDOMComment_get_data(iface, &data);
649 LONG len = SysStringLen(data);
650 BSTR str = SysAllocStringLen(NULL, p_len + len);
652 memcpy(str, data, len*sizeof(WCHAR));
653 memcpy(&str[len], p, p_len*sizeof(WCHAR));
656 hr = IXMLDOMComment_put_data(iface, str);
665 static HRESULT WINAPI domcomment_insertData(
666 IXMLDOMComment *iface,
669 domcomment *This = impl_from_IXMLDOMComment( iface );
674 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
676 /* If have a NULL or empty string, don't do anything. */
677 if((p_len = SysStringLen(p)) == 0)
685 hr = IXMLDOMComment_get_data(iface, &data);
688 LONG len = SysStringLen(data);
697 str = SysAllocStringLen(NULL, len + p_len);
698 /* start part, supplied string and end part */
699 memcpy(str, data, offset*sizeof(WCHAR));
700 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
701 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
704 hr = IXMLDOMComment_put_data(iface, str);
713 static HRESULT WINAPI domcomment_deleteData(
714 IXMLDOMComment *iface,
715 LONG offset, LONG count)
721 TRACE("(%p)->(%d %d)\n", iface, offset, count);
723 hr = IXMLDOMComment_get_length(iface, &len);
724 if(hr != S_OK) return hr;
726 if((offset < 0) || (offset > len) || (count < 0))
729 if(len == 0) return S_OK;
731 /* cutting start or end */
732 if((offset == 0) || ((count + offset) >= len))
735 IXMLDOMComment_substringData(iface, count, len - count, &str);
737 IXMLDOMComment_substringData(iface, 0, offset, &str);
738 hr = IXMLDOMComment_put_data(iface, str);
741 /* cutting from the inside */
745 IXMLDOMComment_substringData(iface, 0, offset, &str);
746 IXMLDOMComment_substringData(iface, offset + count, len - count, &str_end);
748 hr = IXMLDOMComment_put_data(iface, str);
750 hr = IXMLDOMComment_appendData(iface, str_end);
752 SysFreeString(str_end);
760 static HRESULT WINAPI domcomment_replaceData(
761 IXMLDOMComment *iface,
762 LONG offset, LONG count, BSTR p)
764 domcomment *This = impl_from_IXMLDOMComment( iface );
767 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
769 hr = IXMLDOMComment_deleteData(iface, offset, count);
772 hr = IXMLDOMComment_insertData(iface, offset, p);
777 static const struct IXMLDOMCommentVtbl domcomment_vtbl =
779 domcomment_QueryInterface,
782 domcomment_GetTypeInfoCount,
783 domcomment_GetTypeInfo,
784 domcomment_GetIDsOfNames,
786 domcomment_get_nodeName,
787 domcomment_get_nodeValue,
788 domcomment_put_nodeValue,
789 domcomment_get_nodeType,
790 domcomment_get_parentNode,
791 domcomment_get_childNodes,
792 domcomment_get_firstChild,
793 domcomment_get_lastChild,
794 domcomment_get_previousSibling,
795 domcomment_get_nextSibling,
796 domcomment_get_attributes,
797 domcomment_insertBefore,
798 domcomment_replaceChild,
799 domcomment_removeChild,
800 domcomment_appendChild,
801 domcomment_hasChildNodes,
802 domcomment_get_ownerDocument,
803 domcomment_cloneNode,
804 domcomment_get_nodeTypeString,
807 domcomment_get_specified,
808 domcomment_get_definition,
809 domcomment_get_nodeTypedValue,
810 domcomment_put_nodeTypedValue,
811 domcomment_get_dataType,
812 domcomment_put_dataType,
814 domcomment_transformNode,
815 domcomment_selectNodes,
816 domcomment_selectSingleNode,
817 domcomment_get_parsed,
818 domcomment_get_namespaceURI,
819 domcomment_get_prefix,
820 domcomment_get_baseName,
821 domcomment_transformNodeToObject,
824 domcomment_get_length,
825 domcomment_substringData,
826 domcomment_appendData,
827 domcomment_insertData,
828 domcomment_deleteData,
829 domcomment_replaceData
832 IUnknown* create_comment( xmlNodePtr comment )
836 This = heap_alloc( sizeof *This );
840 This->lpVtbl = &domcomment_vtbl;
843 init_xmlnode(&This->node, comment, (IXMLDOMNode*)&This->lpVtbl, NULL);
845 return (IUnknown*) &This->lpVtbl;