hlink: Use ifaces instead of vtbl pointers in ExtensionService.
[wine] / dlls / msxml3 / comment.c
1 /*
2  *    DOM comment node implementation
3  *
4  * Copyright 2006 Huw Davies
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COBJMACROS
22
23 #include "config.h"
24
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "msxml6.h"
31
32 #include "msxml_private.h"
33
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
37
38 #ifdef HAVE_LIBXML2
39
40 typedef struct _domcomment
41 {
42     xmlnode node;
43     IXMLDOMComment IXMLDOMComment_iface;
44     LONG ref;
45 } domcomment;
46
47 static inline domcomment *impl_from_IXMLDOMComment( IXMLDOMComment *iface )
48 {
49     return CONTAINING_RECORD(iface, domcomment, IXMLDOMComment_iface);
50 }
51
52 static HRESULT WINAPI domcomment_QueryInterface(
53     IXMLDOMComment *iface,
54     REFIID riid,
55     void** ppvObject )
56 {
57     domcomment *This = impl_from_IXMLDOMComment( iface );
58     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
59
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 ) )
65     {
66         *ppvObject = iface;
67     }
68     else if(node_query_interface(&This->node, riid, ppvObject))
69     {
70         return *ppvObject ? S_OK : E_NOINTERFACE;
71     }
72     else
73     {
74         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
75         return E_NOINTERFACE;
76     }
77
78     IXMLDOMText_AddRef((IUnknown*)*ppvObject);
79     return S_OK;
80 }
81
82 static ULONG WINAPI domcomment_AddRef(
83     IXMLDOMComment *iface )
84 {
85     domcomment *This = impl_from_IXMLDOMComment( iface );
86     return InterlockedIncrement( &This->ref );
87 }
88
89 static ULONG WINAPI domcomment_Release(
90     IXMLDOMComment *iface )
91 {
92     domcomment *This = impl_from_IXMLDOMComment( iface );
93     ULONG ref;
94
95     ref = InterlockedDecrement( &This->ref );
96     if ( ref == 0 )
97     {
98         destroy_xmlnode(&This->node);
99         heap_free( This );
100     }
101
102     return ref;
103 }
104
105 static HRESULT WINAPI domcomment_GetTypeInfoCount(
106     IXMLDOMComment *iface,
107     UINT* pctinfo )
108 {
109     domcomment *This = impl_from_IXMLDOMComment( iface );
110
111     TRACE("(%p)->(%p)\n", This, pctinfo);
112
113     *pctinfo = 1;
114
115     return S_OK;
116 }
117
118 static HRESULT WINAPI domcomment_GetTypeInfo(
119     IXMLDOMComment *iface,
120     UINT iTInfo, LCID lcid,
121     ITypeInfo** ppTInfo )
122 {
123     domcomment *This = impl_from_IXMLDOMComment( iface );
124     HRESULT hr;
125
126     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
127
128     hr = get_typeinfo(IXMLDOMComment_tid, ppTInfo);
129
130     return hr;
131 }
132
133 static HRESULT WINAPI domcomment_GetIDsOfNames(
134     IXMLDOMComment *iface,
135     REFIID riid, LPOLESTR* rgszNames,
136     UINT cNames, LCID lcid, DISPID* rgDispId )
137 {
138     domcomment *This = impl_from_IXMLDOMComment( iface );
139     ITypeInfo *typeinfo;
140     HRESULT hr;
141
142     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
143           lcid, rgDispId);
144
145     if(!rgszNames || cNames == 0 || !rgDispId)
146         return E_INVALIDARG;
147
148     hr = get_typeinfo(IXMLDOMComment_tid, &typeinfo);
149     if(SUCCEEDED(hr))
150     {
151         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
152         ITypeInfo_Release(typeinfo);
153     }
154
155     return hr;
156 }
157
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 )
163 {
164     domcomment *This = impl_from_IXMLDOMComment( iface );
165     ITypeInfo *typeinfo;
166     HRESULT hr;
167
168     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
169           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
170
171     hr = get_typeinfo(IXMLDOMComment_tid, &typeinfo);
172     if(SUCCEEDED(hr))
173     {
174         hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMComment_iface, dispIdMember, wFlags,
175                 pDispParams, pVarResult, pExcepInfo, puArgErr);
176         ITypeInfo_Release(typeinfo);
177     }
178
179     return hr;
180 }
181
182 static HRESULT WINAPI domcomment_get_nodeName(
183     IXMLDOMComment *iface,
184     BSTR* p )
185 {
186     domcomment *This = impl_from_IXMLDOMComment( iface );
187
188     static const WCHAR commentW[] = {'#','c','o','m','m','e','n','t',0};
189
190     TRACE("(%p)->(%p)\n", This, p);
191
192     return return_bstr(commentW, p);
193 }
194
195 static HRESULT WINAPI domcomment_get_nodeValue(
196     IXMLDOMComment *iface,
197     VARIANT* value)
198 {
199     domcomment *This = impl_from_IXMLDOMComment( iface );
200
201     TRACE("(%p)->(%p)\n", This, value);
202
203     return node_get_content(&This->node, value);
204 }
205
206 static HRESULT WINAPI domcomment_put_nodeValue(
207     IXMLDOMComment *iface,
208     VARIANT value)
209 {
210     domcomment *This = impl_from_IXMLDOMComment( iface );
211
212     TRACE("(%p)->(v%d)\n", This, V_VT(&value));
213
214     return node_put_value(&This->node, &value);
215 }
216
217 static HRESULT WINAPI domcomment_get_nodeType(
218     IXMLDOMComment *iface,
219     DOMNodeType* domNodeType )
220 {
221     domcomment *This = impl_from_IXMLDOMComment( iface );
222
223     TRACE("(%p)->(%p)\n", This, domNodeType);
224
225     *domNodeType = NODE_COMMENT;
226     return S_OK;
227 }
228
229 static HRESULT WINAPI domcomment_get_parentNode(
230     IXMLDOMComment *iface,
231     IXMLDOMNode** parent )
232 {
233     domcomment *This = impl_from_IXMLDOMComment( iface );
234
235     TRACE("(%p)->(%p)\n", This, parent);
236
237     return node_get_parent(&This->node, parent);
238 }
239
240 static HRESULT WINAPI domcomment_get_childNodes(
241     IXMLDOMComment *iface,
242     IXMLDOMNodeList** outList)
243 {
244     domcomment *This = impl_from_IXMLDOMComment( iface );
245
246     TRACE("(%p)->(%p)\n", This, outList);
247
248     return node_get_child_nodes(&This->node, outList);
249 }
250
251 static HRESULT WINAPI domcomment_get_firstChild(
252     IXMLDOMComment *iface,
253     IXMLDOMNode** domNode)
254 {
255     domcomment *This = impl_from_IXMLDOMComment( iface );
256
257     TRACE("(%p)->(%p)\n", This, domNode);
258
259     return return_null_node(domNode);
260 }
261
262 static HRESULT WINAPI domcomment_get_lastChild(
263     IXMLDOMComment *iface,
264     IXMLDOMNode** domNode)
265 {
266     domcomment *This = impl_from_IXMLDOMComment( iface );
267
268     TRACE("(%p)->(%p)\n", This, domNode);
269
270     return return_null_node(domNode);
271 }
272
273 static HRESULT WINAPI domcomment_get_previousSibling(
274     IXMLDOMComment *iface,
275     IXMLDOMNode** domNode)
276 {
277     domcomment *This = impl_from_IXMLDOMComment( iface );
278
279     TRACE("(%p)->(%p)\n", This, domNode);
280
281     return node_get_previous_sibling(&This->node, domNode);
282 }
283
284 static HRESULT WINAPI domcomment_get_nextSibling(
285     IXMLDOMComment *iface,
286     IXMLDOMNode** domNode)
287 {
288     domcomment *This = impl_from_IXMLDOMComment( iface );
289
290     TRACE("(%p)->(%p)\n", This, domNode);
291
292     return node_get_next_sibling(&This->node, domNode);
293 }
294
295 static HRESULT WINAPI domcomment_get_attributes(
296     IXMLDOMComment *iface,
297     IXMLDOMNamedNodeMap** attributeMap)
298 {
299     domcomment *This = impl_from_IXMLDOMComment( iface );
300
301     TRACE("(%p)->(%p)\n", This, attributeMap);
302
303     return return_null_ptr((void**)attributeMap);
304 }
305
306 static HRESULT WINAPI domcomment_insertBefore(
307     IXMLDOMComment *iface,
308     IXMLDOMNode* newNode, VARIANT refChild,
309     IXMLDOMNode** outOldNode)
310 {
311     domcomment *This = impl_from_IXMLDOMComment( iface );
312
313     FIXME("(%p)->(%p x%d %p) needs test\n", This, newNode, V_VT(&refChild), outOldNode);
314
315     return node_insert_before(&This->node, newNode, &refChild, outOldNode);
316 }
317
318 static HRESULT WINAPI domcomment_replaceChild(
319     IXMLDOMComment *iface,
320     IXMLDOMNode* newNode,
321     IXMLDOMNode* oldNode,
322     IXMLDOMNode** outOldNode)
323 {
324     domcomment *This = impl_from_IXMLDOMComment( iface );
325
326     FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
327
328     return node_replace_child(&This->node, newNode, oldNode, outOldNode);
329 }
330
331 static HRESULT WINAPI domcomment_removeChild(
332     IXMLDOMComment *iface,
333     IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
334 {
335     domcomment *This = impl_from_IXMLDOMComment( iface );
336     return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
337 }
338
339 static HRESULT WINAPI domcomment_appendChild(
340     IXMLDOMComment *iface,
341     IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
342 {
343     domcomment *This = impl_from_IXMLDOMComment( iface );
344     return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
345 }
346
347 static HRESULT WINAPI domcomment_hasChildNodes(
348     IXMLDOMComment *iface,
349     VARIANT_BOOL* pbool)
350 {
351     domcomment *This = impl_from_IXMLDOMComment( iface );
352     return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
353 }
354
355 static HRESULT WINAPI domcomment_get_ownerDocument(
356     IXMLDOMComment *iface,
357     IXMLDOMDocument** domDocument)
358 {
359     domcomment *This = impl_from_IXMLDOMComment( iface );
360     return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
361 }
362
363 static HRESULT WINAPI domcomment_cloneNode(
364     IXMLDOMComment *iface,
365     VARIANT_BOOL deep, IXMLDOMNode** outNode)
366 {
367     domcomment *This = impl_from_IXMLDOMComment( iface );
368     TRACE("(%p)->(%d %p)\n", This, deep, outNode);
369     return node_clone( &This->node, deep, outNode );
370 }
371
372 static HRESULT WINAPI domcomment_get_nodeTypeString(
373     IXMLDOMComment *iface,
374     BSTR* p)
375 {
376     domcomment *This = impl_from_IXMLDOMComment( iface );
377     static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0};
378
379     TRACE("(%p)->(%p)\n", This, p);
380
381     return return_bstr(commentW, p);
382 }
383
384 static HRESULT WINAPI domcomment_get_text(
385     IXMLDOMComment *iface,
386     BSTR* p)
387 {
388     domcomment *This = impl_from_IXMLDOMComment( iface );
389     return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
390 }
391
392 static HRESULT WINAPI domcomment_put_text(
393     IXMLDOMComment *iface,
394     BSTR p)
395 {
396     domcomment *This = impl_from_IXMLDOMComment( iface );
397     TRACE("(%p)->(%s)\n", This, debugstr_w(p));
398     return node_put_text( &This->node, p );
399 }
400
401 static HRESULT WINAPI domcomment_get_specified(
402     IXMLDOMComment *iface,
403     VARIANT_BOOL* isSpecified)
404 {
405     domcomment *This = impl_from_IXMLDOMComment( iface );
406     FIXME("(%p)->(%p) stub!\n", This, isSpecified);
407     *isSpecified = VARIANT_TRUE;
408     return S_OK;
409 }
410
411 static HRESULT WINAPI domcomment_get_definition(
412     IXMLDOMComment *iface,
413     IXMLDOMNode** definitionNode)
414 {
415     domcomment *This = impl_from_IXMLDOMComment( iface );
416     FIXME("(%p)->(%p)\n", This, definitionNode);
417     return E_NOTIMPL;
418 }
419
420 static HRESULT WINAPI domcomment_get_nodeTypedValue(
421     IXMLDOMComment *iface,
422     VARIANT* var1)
423 {
424     domcomment *This = impl_from_IXMLDOMComment( iface );
425     return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
426 }
427
428 static HRESULT WINAPI domcomment_put_nodeTypedValue(
429     IXMLDOMComment *iface,
430     VARIANT typedValue)
431 {
432     domcomment *This = impl_from_IXMLDOMComment( iface );
433     FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
434     return E_NOTIMPL;
435 }
436
437 static HRESULT WINAPI domcomment_get_dataType(
438     IXMLDOMComment *iface,
439     VARIANT* typename)
440 {
441     domcomment *This = impl_from_IXMLDOMComment( iface );
442     TRACE("(%p)->(%p)\n", This, typename);
443     return return_null_var( typename );
444 }
445
446 static HRESULT WINAPI domcomment_put_dataType(
447     IXMLDOMComment *iface,
448     BSTR p)
449 {
450     domcomment *This = impl_from_IXMLDOMComment( iface );
451
452     FIXME("(%p)->(%s)\n", This, debugstr_w(p));
453
454     if(!p)
455         return E_INVALIDARG;
456
457     return E_FAIL;
458 }
459
460 static HRESULT WINAPI domcomment_get_xml(
461     IXMLDOMComment *iface,
462     BSTR* p)
463 {
464     domcomment *This = impl_from_IXMLDOMComment( iface );
465
466     TRACE("(%p)->(%p)\n", This, p);
467
468     return node_get_xml(&This->node, FALSE, FALSE, p);
469 }
470
471 static HRESULT WINAPI domcomment_transformNode(
472     IXMLDOMComment *iface,
473     IXMLDOMNode* domNode, BSTR* p)
474 {
475     domcomment *This = impl_from_IXMLDOMComment( iface );
476     return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
477 }
478
479 static HRESULT WINAPI domcomment_selectNodes(
480     IXMLDOMComment *iface,
481     BSTR p, IXMLDOMNodeList** outList)
482 {
483     domcomment *This = impl_from_IXMLDOMComment( iface );
484     return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
485 }
486
487 static HRESULT WINAPI domcomment_selectSingleNode(
488     IXMLDOMComment *iface,
489     BSTR p, IXMLDOMNode** outNode)
490 {
491     domcomment *This = impl_from_IXMLDOMComment( iface );
492     return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
493 }
494
495 static HRESULT WINAPI domcomment_get_parsed(
496     IXMLDOMComment *iface,
497     VARIANT_BOOL* isParsed)
498 {
499     domcomment *This = impl_from_IXMLDOMComment( iface );
500     FIXME("(%p)->(%p) stub!\n", This, isParsed);
501     *isParsed = VARIANT_TRUE;
502     return S_OK;
503 }
504
505 static HRESULT WINAPI domcomment_get_namespaceURI(
506     IXMLDOMComment *iface,
507     BSTR* p)
508 {
509     domcomment *This = impl_from_IXMLDOMComment( iface );
510     return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
511 }
512
513 static HRESULT WINAPI domcomment_get_prefix(
514     IXMLDOMComment *iface,
515     BSTR* prefix)
516 {
517     domcomment *This = impl_from_IXMLDOMComment( iface );
518     TRACE("(%p)->(%p)\n", This, prefix);
519     return return_null_bstr( prefix );
520 }
521
522 static HRESULT WINAPI domcomment_get_baseName(
523     IXMLDOMComment *iface,
524     BSTR* name)
525 {
526     domcomment *This = impl_from_IXMLDOMComment( iface );
527     TRACE("(%p)->(%p)\n", This, name);
528     return return_null_bstr( name );
529 }
530
531 static HRESULT WINAPI domcomment_transformNodeToObject(
532     IXMLDOMComment *iface,
533     IXMLDOMNode* domNode, VARIANT var1)
534 {
535     domcomment *This = impl_from_IXMLDOMComment( iface );
536     return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
537 }
538
539 static HRESULT WINAPI domcomment_get_data(
540     IXMLDOMComment *iface,
541     BSTR *p)
542 {
543     domcomment *This = impl_from_IXMLDOMComment( iface );
544     HRESULT hr;
545     VARIANT vRet;
546
547     TRACE("(%p)->(%p)\n", This, p);
548
549     if(!p)
550         return E_INVALIDARG;
551
552     hr = IXMLDOMComment_get_nodeValue( iface, &vRet );
553     if(hr == S_OK)
554     {
555         *p = V_BSTR(&vRet);
556     }
557
558     return hr;
559 }
560
561 static HRESULT WINAPI domcomment_put_data(
562     IXMLDOMComment *iface,
563     BSTR data)
564 {
565     domcomment *This = impl_from_IXMLDOMComment( iface );
566     VARIANT val;
567
568     TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
569
570     V_VT(&val) = VT_BSTR;
571     V_BSTR(&val) = data;
572     return node_put_value(&This->node, &val);
573 }
574
575 static HRESULT WINAPI domcomment_get_length(
576     IXMLDOMComment *iface,
577     LONG *len)
578 {
579     domcomment *This = impl_from_IXMLDOMComment( iface );
580     HRESULT hr;
581     BSTR data;
582
583     TRACE("(%p)->(%p)\n", This, len);
584
585     if(!len)
586         return E_INVALIDARG;
587
588     hr = IXMLDOMComment_get_data(iface, &data);
589     if(hr == S_OK)
590     {
591         *len = SysStringLen(data);
592         SysFreeString(data);
593     }
594
595     return hr;
596 }
597
598 static HRESULT WINAPI domcomment_substringData(
599     IXMLDOMComment *iface,
600     LONG offset, LONG count, BSTR *p)
601 {
602     domcomment *This = impl_from_IXMLDOMComment( iface );
603     HRESULT hr;
604     BSTR data;
605
606     TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
607
608     if(!p)
609         return E_INVALIDARG;
610
611     *p = NULL;
612     if(offset < 0 || count < 0)
613         return E_INVALIDARG;
614
615     if(count == 0)
616         return S_FALSE;
617
618     hr = IXMLDOMComment_get_data(iface, &data);
619     if(hr == S_OK)
620     {
621         LONG len = SysStringLen(data);
622
623         if(offset < len)
624         {
625             if(offset + count > len)
626                 *p = SysAllocString(&data[offset]);
627             else
628                 *p = SysAllocStringLen(&data[offset], count);
629         }
630         else
631             hr = S_FALSE;
632
633         SysFreeString(data);
634     }
635
636     return hr;
637 }
638
639 static HRESULT WINAPI domcomment_appendData(
640     IXMLDOMComment *iface,
641     BSTR p)
642 {
643     domcomment *This = impl_from_IXMLDOMComment( iface );
644     HRESULT hr;
645     BSTR data;
646     LONG p_len;
647
648     TRACE("(%p)->(%s)\n", This, debugstr_w(p));
649
650     /* Nothing to do if NULL or an Empty string passed in. */
651     if((p_len = SysStringLen(p)) == 0) return S_OK;
652
653     hr = IXMLDOMComment_get_data(iface, &data);
654     if(hr == S_OK)
655     {
656         LONG len = SysStringLen(data);
657         BSTR str = SysAllocStringLen(NULL, p_len + len);
658
659         memcpy(str, data, len*sizeof(WCHAR));
660         memcpy(&str[len], p, p_len*sizeof(WCHAR));
661         str[len+p_len] = 0;
662
663         hr = IXMLDOMComment_put_data(iface, str);
664
665         SysFreeString(str);
666         SysFreeString(data);
667     }
668
669     return hr;
670 }
671
672 static HRESULT WINAPI domcomment_insertData(
673     IXMLDOMComment *iface,
674     LONG offset, BSTR p)
675 {
676     domcomment *This = impl_from_IXMLDOMComment( iface );
677     HRESULT hr;
678     BSTR data;
679     LONG p_len;
680
681     TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
682
683     /* If have a NULL or empty string, don't do anything. */
684     if((p_len = SysStringLen(p)) == 0)
685         return S_OK;
686
687     if(offset < 0)
688     {
689         return E_INVALIDARG;
690     }
691
692     hr = IXMLDOMComment_get_data(iface, &data);
693     if(hr == S_OK)
694     {
695         LONG len = SysStringLen(data);
696         BSTR str;
697
698         if(len < offset)
699         {
700             SysFreeString(data);
701             return E_INVALIDARG;
702         }
703
704         str = SysAllocStringLen(NULL, len + p_len);
705         /* start part, supplied string and end part */
706         memcpy(str, data, offset*sizeof(WCHAR));
707         memcpy(&str[offset], p, p_len*sizeof(WCHAR));
708         memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
709         str[len+p_len] = 0;
710
711         hr = IXMLDOMComment_put_data(iface, str);
712
713         SysFreeString(str);
714         SysFreeString(data);
715     }
716
717     return hr;
718 }
719
720 static HRESULT WINAPI domcomment_deleteData(
721     IXMLDOMComment *iface,
722     LONG offset, LONG count)
723 {
724     HRESULT hr;
725     LONG len = -1;
726     BSTR str;
727
728     TRACE("(%p)->(%d %d)\n", iface, offset, count);
729
730     hr = IXMLDOMComment_get_length(iface, &len);
731     if(hr != S_OK) return hr;
732
733     if((offset < 0) || (offset > len) || (count < 0))
734         return E_INVALIDARG;
735
736     if(len == 0) return S_OK;
737
738     /* cutting start or end */
739     if((offset == 0) || ((count + offset) >= len))
740     {
741         if(offset == 0)
742             IXMLDOMComment_substringData(iface, count, len - count, &str);
743         else
744             IXMLDOMComment_substringData(iface, 0, offset, &str);
745         hr = IXMLDOMComment_put_data(iface, str);
746     }
747     else
748     /* cutting from the inside */
749     {
750         BSTR str_end;
751
752         IXMLDOMComment_substringData(iface, 0, offset, &str);
753         IXMLDOMComment_substringData(iface, offset + count, len - count, &str_end);
754
755         hr = IXMLDOMComment_put_data(iface, str);
756         if(hr == S_OK)
757             hr = IXMLDOMComment_appendData(iface, str_end);
758
759         SysFreeString(str_end);
760     }
761
762     SysFreeString(str);
763
764     return hr;
765 }
766
767 static HRESULT WINAPI domcomment_replaceData(
768     IXMLDOMComment *iface,
769     LONG offset, LONG count, BSTR p)
770 {
771     domcomment *This = impl_from_IXMLDOMComment( iface );
772     HRESULT hr;
773
774     TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
775
776     hr = IXMLDOMComment_deleteData(iface, offset, count);
777
778     if (hr == S_OK)
779        hr = IXMLDOMComment_insertData(iface, offset, p);
780
781     return hr;
782 }
783
784 static const struct IXMLDOMCommentVtbl domcomment_vtbl =
785 {
786     domcomment_QueryInterface,
787     domcomment_AddRef,
788     domcomment_Release,
789     domcomment_GetTypeInfoCount,
790     domcomment_GetTypeInfo,
791     domcomment_GetIDsOfNames,
792     domcomment_Invoke,
793     domcomment_get_nodeName,
794     domcomment_get_nodeValue,
795     domcomment_put_nodeValue,
796     domcomment_get_nodeType,
797     domcomment_get_parentNode,
798     domcomment_get_childNodes,
799     domcomment_get_firstChild,
800     domcomment_get_lastChild,
801     domcomment_get_previousSibling,
802     domcomment_get_nextSibling,
803     domcomment_get_attributes,
804     domcomment_insertBefore,
805     domcomment_replaceChild,
806     domcomment_removeChild,
807     domcomment_appendChild,
808     domcomment_hasChildNodes,
809     domcomment_get_ownerDocument,
810     domcomment_cloneNode,
811     domcomment_get_nodeTypeString,
812     domcomment_get_text,
813     domcomment_put_text,
814     domcomment_get_specified,
815     domcomment_get_definition,
816     domcomment_get_nodeTypedValue,
817     domcomment_put_nodeTypedValue,
818     domcomment_get_dataType,
819     domcomment_put_dataType,
820     domcomment_get_xml,
821     domcomment_transformNode,
822     domcomment_selectNodes,
823     domcomment_selectSingleNode,
824     domcomment_get_parsed,
825     domcomment_get_namespaceURI,
826     domcomment_get_prefix,
827     domcomment_get_baseName,
828     domcomment_transformNodeToObject,
829     domcomment_get_data,
830     domcomment_put_data,
831     domcomment_get_length,
832     domcomment_substringData,
833     domcomment_appendData,
834     domcomment_insertData,
835     domcomment_deleteData,
836     domcomment_replaceData
837 };
838
839 IUnknown* create_comment( xmlNodePtr comment )
840 {
841     domcomment *This;
842
843     This = heap_alloc( sizeof *This );
844     if ( !This )
845         return NULL;
846
847     This->IXMLDOMComment_iface.lpVtbl = &domcomment_vtbl;
848     This->ref = 1;
849
850     init_xmlnode(&This->node, comment, (IXMLDOMNode*)&This->IXMLDOMComment_iface, NULL);
851
852     return (IUnknown*)&This->IXMLDOMComment_iface;
853 }
854
855 #endif