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
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
37 #include "msxml_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
45 typedef struct _domcomment
48 IXMLDOMComment IXMLDOMComment_iface;
52 static const tid_t domcomment_se_tids[] = {
58 static inline domcomment *impl_from_IXMLDOMComment( IXMLDOMComment *iface )
60 return CONTAINING_RECORD(iface, domcomment, IXMLDOMComment_iface);
63 static HRESULT WINAPI domcomment_QueryInterface(
64 IXMLDOMComment *iface,
68 domcomment *This = impl_from_IXMLDOMComment( iface );
69 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
71 if ( IsEqualGUID( riid, &IID_IXMLDOMComment ) ||
72 IsEqualGUID( riid, &IID_IXMLDOMCharacterData) ||
73 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
74 IsEqualGUID( riid, &IID_IDispatch ) ||
75 IsEqualGUID( riid, &IID_IUnknown ) )
79 else if(node_query_interface(&This->node, riid, ppvObject))
81 return *ppvObject ? S_OK : E_NOINTERFACE;
83 else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
85 return node_create_supporterrorinfo(domcomment_se_tids, ppvObject);
89 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
94 IXMLDOMComment_AddRef(iface);
98 static ULONG WINAPI domcomment_AddRef(
99 IXMLDOMComment *iface )
101 domcomment *This = impl_from_IXMLDOMComment( iface );
102 ULONG ref = InterlockedIncrement( &This->ref );
103 TRACE("(%p)->(%d)\n", This, ref);
107 static ULONG WINAPI domcomment_Release(
108 IXMLDOMComment *iface )
110 domcomment *This = impl_from_IXMLDOMComment( iface );
111 ULONG ref = InterlockedDecrement( &This->ref );
113 TRACE("(%p)->(%d)\n", This, ref);
116 destroy_xmlnode(&This->node);
123 static HRESULT WINAPI domcomment_GetTypeInfoCount(
124 IXMLDOMComment *iface,
127 domcomment *This = impl_from_IXMLDOMComment( iface );
128 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
131 static HRESULT WINAPI domcomment_GetTypeInfo(
132 IXMLDOMComment *iface,
133 UINT iTInfo, LCID lcid,
134 ITypeInfo** ppTInfo )
136 domcomment *This = impl_from_IXMLDOMComment( iface );
137 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
138 iTInfo, lcid, ppTInfo);
141 static HRESULT WINAPI domcomment_GetIDsOfNames(
142 IXMLDOMComment *iface,
143 REFIID riid, LPOLESTR* rgszNames,
144 UINT cNames, LCID lcid, DISPID* rgDispId )
146 domcomment *This = impl_from_IXMLDOMComment( iface );
147 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
148 riid, rgszNames, cNames, lcid, rgDispId);
151 static HRESULT WINAPI domcomment_Invoke(
152 IXMLDOMComment *iface,
153 DISPID dispIdMember, REFIID riid, LCID lcid,
154 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
155 EXCEPINFO* pExcepInfo, UINT* puArgErr )
157 domcomment *This = impl_from_IXMLDOMComment( iface );
158 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
159 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
162 static HRESULT WINAPI domcomment_get_nodeName(
163 IXMLDOMComment *iface,
166 domcomment *This = impl_from_IXMLDOMComment( iface );
168 static const WCHAR commentW[] = {'#','c','o','m','m','e','n','t',0};
170 TRACE("(%p)->(%p)\n", This, p);
172 return return_bstr(commentW, p);
175 static HRESULT WINAPI domcomment_get_nodeValue(
176 IXMLDOMComment *iface,
179 domcomment *This = impl_from_IXMLDOMComment( iface );
181 TRACE("(%p)->(%p)\n", This, value);
183 return node_get_content(&This->node, value);
186 static HRESULT WINAPI domcomment_put_nodeValue(
187 IXMLDOMComment *iface,
190 domcomment *This = impl_from_IXMLDOMComment( iface );
192 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
194 return node_put_value(&This->node, &value);
197 static HRESULT WINAPI domcomment_get_nodeType(
198 IXMLDOMComment *iface,
199 DOMNodeType* domNodeType )
201 domcomment *This = impl_from_IXMLDOMComment( iface );
203 TRACE("(%p)->(%p)\n", This, domNodeType);
205 *domNodeType = NODE_COMMENT;
209 static HRESULT WINAPI domcomment_get_parentNode(
210 IXMLDOMComment *iface,
211 IXMLDOMNode** parent )
213 domcomment *This = impl_from_IXMLDOMComment( iface );
215 TRACE("(%p)->(%p)\n", This, parent);
217 return node_get_parent(&This->node, parent);
220 static HRESULT WINAPI domcomment_get_childNodes(
221 IXMLDOMComment *iface,
222 IXMLDOMNodeList** outList)
224 domcomment *This = impl_from_IXMLDOMComment( iface );
226 TRACE("(%p)->(%p)\n", This, outList);
228 return node_get_child_nodes(&This->node, outList);
231 static HRESULT WINAPI domcomment_get_firstChild(
232 IXMLDOMComment *iface,
233 IXMLDOMNode** domNode)
235 domcomment *This = impl_from_IXMLDOMComment( iface );
237 TRACE("(%p)->(%p)\n", This, domNode);
239 return return_null_node(domNode);
242 static HRESULT WINAPI domcomment_get_lastChild(
243 IXMLDOMComment *iface,
244 IXMLDOMNode** domNode)
246 domcomment *This = impl_from_IXMLDOMComment( iface );
248 TRACE("(%p)->(%p)\n", This, domNode);
250 return return_null_node(domNode);
253 static HRESULT WINAPI domcomment_get_previousSibling(
254 IXMLDOMComment *iface,
255 IXMLDOMNode** domNode)
257 domcomment *This = impl_from_IXMLDOMComment( iface );
259 TRACE("(%p)->(%p)\n", This, domNode);
261 return node_get_previous_sibling(&This->node, domNode);
264 static HRESULT WINAPI domcomment_get_nextSibling(
265 IXMLDOMComment *iface,
266 IXMLDOMNode** domNode)
268 domcomment *This = impl_from_IXMLDOMComment( iface );
270 TRACE("(%p)->(%p)\n", This, domNode);
272 return node_get_next_sibling(&This->node, domNode);
275 static HRESULT WINAPI domcomment_get_attributes(
276 IXMLDOMComment *iface,
277 IXMLDOMNamedNodeMap** attributeMap)
279 domcomment *This = impl_from_IXMLDOMComment( iface );
281 TRACE("(%p)->(%p)\n", This, attributeMap);
283 return return_null_ptr((void**)attributeMap);
286 static HRESULT WINAPI domcomment_insertBefore(
287 IXMLDOMComment *iface,
288 IXMLDOMNode* newNode, VARIANT refChild,
289 IXMLDOMNode** outOldNode)
291 domcomment *This = impl_from_IXMLDOMComment( iface );
293 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
295 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
298 static HRESULT WINAPI domcomment_replaceChild(
299 IXMLDOMComment *iface,
300 IXMLDOMNode* newNode,
301 IXMLDOMNode* oldNode,
302 IXMLDOMNode** outOldNode)
304 domcomment *This = impl_from_IXMLDOMComment( iface );
306 FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
308 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
311 static HRESULT WINAPI domcomment_removeChild(
312 IXMLDOMComment *iface,
313 IXMLDOMNode *child, IXMLDOMNode **oldChild)
315 domcomment *This = impl_from_IXMLDOMComment( iface );
316 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
317 return node_remove_child(&This->node, child, oldChild);
320 static HRESULT WINAPI domcomment_appendChild(
321 IXMLDOMComment *iface,
322 IXMLDOMNode *child, IXMLDOMNode **outChild)
324 domcomment *This = impl_from_IXMLDOMComment( iface );
325 TRACE("(%p)->(%p %p)\n", This, child, outChild);
326 return node_append_child(&This->node, child, outChild);
329 static HRESULT WINAPI domcomment_hasChildNodes(
330 IXMLDOMComment *iface,
333 domcomment *This = impl_from_IXMLDOMComment( iface );
334 TRACE("(%p)->(%p)\n", This, ret);
335 return node_has_childnodes(&This->node, ret);
338 static HRESULT WINAPI domcomment_get_ownerDocument(
339 IXMLDOMComment *iface,
340 IXMLDOMDocument **doc)
342 domcomment *This = impl_from_IXMLDOMComment( iface );
343 TRACE("(%p)->(%p)\n", This, doc);
344 return node_get_owner_doc(&This->node, doc);
347 static HRESULT WINAPI domcomment_cloneNode(
348 IXMLDOMComment *iface,
349 VARIANT_BOOL deep, IXMLDOMNode** outNode)
351 domcomment *This = impl_from_IXMLDOMComment( iface );
352 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
353 return node_clone( &This->node, deep, outNode );
356 static HRESULT WINAPI domcomment_get_nodeTypeString(
357 IXMLDOMComment *iface,
360 domcomment *This = impl_from_IXMLDOMComment( iface );
361 static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0};
363 TRACE("(%p)->(%p)\n", This, p);
365 return return_bstr(commentW, p);
368 static HRESULT WINAPI domcomment_get_text(
369 IXMLDOMComment *iface,
372 domcomment *This = impl_from_IXMLDOMComment( iface );
373 TRACE("(%p)->(%p)\n", This, p);
374 return node_get_text(&This->node, p);
377 static HRESULT WINAPI domcomment_put_text(
378 IXMLDOMComment *iface,
381 domcomment *This = impl_from_IXMLDOMComment( iface );
382 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
383 return node_put_text( &This->node, p );
386 static HRESULT WINAPI domcomment_get_specified(
387 IXMLDOMComment *iface,
388 VARIANT_BOOL* isSpecified)
390 domcomment *This = impl_from_IXMLDOMComment( iface );
391 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
392 *isSpecified = VARIANT_TRUE;
396 static HRESULT WINAPI domcomment_get_definition(
397 IXMLDOMComment *iface,
398 IXMLDOMNode** definitionNode)
400 domcomment *This = impl_from_IXMLDOMComment( iface );
401 FIXME("(%p)->(%p)\n", This, definitionNode);
405 static HRESULT WINAPI domcomment_get_nodeTypedValue(
406 IXMLDOMComment *iface,
409 domcomment *This = impl_from_IXMLDOMComment( iface );
410 TRACE("(%p)->(%p)\n", This, v);
411 return node_get_content(&This->node, v);
414 static HRESULT WINAPI domcomment_put_nodeTypedValue(
415 IXMLDOMComment *iface,
418 domcomment *This = impl_from_IXMLDOMComment( iface );
419 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
423 static HRESULT WINAPI domcomment_get_dataType(
424 IXMLDOMComment *iface,
427 domcomment *This = impl_from_IXMLDOMComment( iface );
428 TRACE("(%p)->(%p)\n", This, typename);
429 return return_null_var( typename );
432 static HRESULT WINAPI domcomment_put_dataType(
433 IXMLDOMComment *iface,
436 domcomment *This = impl_from_IXMLDOMComment( iface );
438 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
446 static HRESULT WINAPI domcomment_get_xml(
447 IXMLDOMComment *iface,
450 domcomment *This = impl_from_IXMLDOMComment( iface );
452 TRACE("(%p)->(%p)\n", This, p);
454 return node_get_xml(&This->node, FALSE, p);
457 static HRESULT WINAPI domcomment_transformNode(
458 IXMLDOMComment *iface,
459 IXMLDOMNode *node, BSTR *p)
461 domcomment *This = impl_from_IXMLDOMComment( iface );
462 TRACE("(%p)->(%p %p)\n", This, node, p);
463 return node_transform_node(&This->node, node, p);
466 static HRESULT WINAPI domcomment_selectNodes(
467 IXMLDOMComment *iface,
468 BSTR p, IXMLDOMNodeList** outList)
470 domcomment *This = impl_from_IXMLDOMComment( iface );
471 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
472 return node_select_nodes(&This->node, p, outList);
475 static HRESULT WINAPI domcomment_selectSingleNode(
476 IXMLDOMComment *iface,
477 BSTR p, IXMLDOMNode** outNode)
479 domcomment *This = impl_from_IXMLDOMComment( iface );
480 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
481 return node_select_singlenode(&This->node, p, outNode);
484 static HRESULT WINAPI domcomment_get_parsed(
485 IXMLDOMComment *iface,
486 VARIANT_BOOL* isParsed)
488 domcomment *This = impl_from_IXMLDOMComment( iface );
489 FIXME("(%p)->(%p) stub!\n", This, isParsed);
490 *isParsed = VARIANT_TRUE;
494 static HRESULT WINAPI domcomment_get_namespaceURI(
495 IXMLDOMComment *iface,
498 domcomment *This = impl_from_IXMLDOMComment( iface );
499 TRACE("(%p)->(%p)\n", This, p);
500 return node_get_namespaceURI(&This->node, p);
503 static HRESULT WINAPI domcomment_get_prefix(
504 IXMLDOMComment *iface,
507 domcomment *This = impl_from_IXMLDOMComment( iface );
508 TRACE("(%p)->(%p)\n", This, prefix);
509 return return_null_bstr( prefix );
512 static HRESULT WINAPI domcomment_get_baseName(
513 IXMLDOMComment *iface,
516 domcomment *This = impl_from_IXMLDOMComment( iface );
517 TRACE("(%p)->(%p)\n", This, name);
518 return return_null_bstr( name );
521 static HRESULT WINAPI domcomment_transformNodeToObject(
522 IXMLDOMComment *iface,
523 IXMLDOMNode* domNode, VARIANT var1)
525 domcomment *This = impl_from_IXMLDOMComment( iface );
526 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
530 static HRESULT WINAPI domcomment_get_data(
531 IXMLDOMComment *iface,
534 domcomment *This = impl_from_IXMLDOMComment( iface );
538 TRACE("(%p)->(%p)\n", This, p);
543 hr = IXMLDOMComment_get_nodeValue( iface, &vRet );
552 static HRESULT WINAPI domcomment_put_data(
553 IXMLDOMComment *iface,
556 domcomment *This = impl_from_IXMLDOMComment( iface );
557 TRACE("(%p)->(%s)\n", This, debugstr_w(data));
558 return node_set_content(&This->node, data);
561 static HRESULT WINAPI domcomment_get_length(
562 IXMLDOMComment *iface,
565 domcomment *This = impl_from_IXMLDOMComment( iface );
569 TRACE("(%p)->(%p)\n", This, len);
574 hr = IXMLDOMComment_get_data(iface, &data);
577 *len = SysStringLen(data);
584 static HRESULT WINAPI domcomment_substringData(
585 IXMLDOMComment *iface,
586 LONG offset, LONG count, BSTR *p)
588 domcomment *This = impl_from_IXMLDOMComment( iface );
592 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
598 if(offset < 0 || count < 0)
604 hr = IXMLDOMComment_get_data(iface, &data);
607 LONG len = SysStringLen(data);
611 if(offset + count > len)
612 *p = SysAllocString(&data[offset]);
614 *p = SysAllocStringLen(&data[offset], count);
625 static HRESULT WINAPI domcomment_appendData(
626 IXMLDOMComment *iface,
629 domcomment *This = impl_from_IXMLDOMComment( iface );
634 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
636 /* Nothing to do if NULL or an Empty string passed in. */
637 if((p_len = SysStringLen(p)) == 0) return S_OK;
639 hr = IXMLDOMComment_get_data(iface, &data);
642 LONG len = SysStringLen(data);
643 BSTR str = SysAllocStringLen(NULL, p_len + len);
645 memcpy(str, data, len*sizeof(WCHAR));
646 memcpy(&str[len], p, p_len*sizeof(WCHAR));
649 hr = IXMLDOMComment_put_data(iface, str);
658 static HRESULT WINAPI domcomment_insertData(
659 IXMLDOMComment *iface,
662 domcomment *This = impl_from_IXMLDOMComment( iface );
667 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
669 /* If have a NULL or empty string, don't do anything. */
670 if((p_len = SysStringLen(p)) == 0)
678 hr = IXMLDOMComment_get_data(iface, &data);
681 LONG len = SysStringLen(data);
690 str = SysAllocStringLen(NULL, len + p_len);
691 /* start part, supplied string and end part */
692 memcpy(str, data, offset*sizeof(WCHAR));
693 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
694 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
697 hr = IXMLDOMComment_put_data(iface, str);
706 static HRESULT WINAPI domcomment_deleteData(
707 IXMLDOMComment *iface,
708 LONG offset, LONG count)
714 TRACE("(%p)->(%d %d)\n", iface, offset, count);
716 hr = IXMLDOMComment_get_length(iface, &len);
717 if(hr != S_OK) return hr;
719 if((offset < 0) || (offset > len) || (count < 0))
722 if(len == 0) return S_OK;
724 /* cutting start or end */
725 if((offset == 0) || ((count + offset) >= len))
728 IXMLDOMComment_substringData(iface, count, len - count, &str);
730 IXMLDOMComment_substringData(iface, 0, offset, &str);
731 hr = IXMLDOMComment_put_data(iface, str);
734 /* cutting from the inside */
738 IXMLDOMComment_substringData(iface, 0, offset, &str);
739 IXMLDOMComment_substringData(iface, offset + count, len - count, &str_end);
741 hr = IXMLDOMComment_put_data(iface, str);
743 hr = IXMLDOMComment_appendData(iface, str_end);
745 SysFreeString(str_end);
753 static HRESULT WINAPI domcomment_replaceData(
754 IXMLDOMComment *iface,
755 LONG offset, LONG count, BSTR p)
757 domcomment *This = impl_from_IXMLDOMComment( iface );
760 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
762 hr = IXMLDOMComment_deleteData(iface, offset, count);
765 hr = IXMLDOMComment_insertData(iface, offset, p);
770 static const struct IXMLDOMCommentVtbl domcomment_vtbl =
772 domcomment_QueryInterface,
775 domcomment_GetTypeInfoCount,
776 domcomment_GetTypeInfo,
777 domcomment_GetIDsOfNames,
779 domcomment_get_nodeName,
780 domcomment_get_nodeValue,
781 domcomment_put_nodeValue,
782 domcomment_get_nodeType,
783 domcomment_get_parentNode,
784 domcomment_get_childNodes,
785 domcomment_get_firstChild,
786 domcomment_get_lastChild,
787 domcomment_get_previousSibling,
788 domcomment_get_nextSibling,
789 domcomment_get_attributes,
790 domcomment_insertBefore,
791 domcomment_replaceChild,
792 domcomment_removeChild,
793 domcomment_appendChild,
794 domcomment_hasChildNodes,
795 domcomment_get_ownerDocument,
796 domcomment_cloneNode,
797 domcomment_get_nodeTypeString,
800 domcomment_get_specified,
801 domcomment_get_definition,
802 domcomment_get_nodeTypedValue,
803 domcomment_put_nodeTypedValue,
804 domcomment_get_dataType,
805 domcomment_put_dataType,
807 domcomment_transformNode,
808 domcomment_selectNodes,
809 domcomment_selectSingleNode,
810 domcomment_get_parsed,
811 domcomment_get_namespaceURI,
812 domcomment_get_prefix,
813 domcomment_get_baseName,
814 domcomment_transformNodeToObject,
817 domcomment_get_length,
818 domcomment_substringData,
819 domcomment_appendData,
820 domcomment_insertData,
821 domcomment_deleteData,
822 domcomment_replaceData
825 static const tid_t domcomment_iface_tids[] = {
830 static dispex_static_data_t domcomment_dispex = {
834 domcomment_iface_tids
837 IUnknown* create_comment( xmlNodePtr comment )
841 This = heap_alloc( sizeof *This );
845 This->IXMLDOMComment_iface.lpVtbl = &domcomment_vtbl;
848 init_xmlnode(&This->node, comment, (IXMLDOMNode*)&This->IXMLDOMComment_iface, &domcomment_dispex);
850 return (IUnknown*)&This->IXMLDOMComment_iface;