msxml3: Suppress IID_IRunnableObject FIXME since its not supported.
[wine.git] / dlls / msxml3 / element.c
blobe7f03d676e8f3cb7d32d26c44f2f3296577c8aa6
1 /*
2 * DOM Document implementation
4 * Copyright 2005 Mike McCormack
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
21 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
31 #include "msxml2.h"
33 #include "msxml_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
39 #ifdef HAVE_LIBXML2
41 typedef struct _domelem
43 const struct IXMLDOMElementVtbl *lpVtbl;
44 const struct IUnknownVtbl *lpInternalUnkVtbl;
45 IUnknown *pUnkOuter;
46 LONG ref;
47 IUnknown *node_unk;
48 IXMLDOMNode *node;
49 } domelem;
51 static inline domelem *impl_from_IXMLDOMElement( IXMLDOMElement *iface )
53 return (domelem *)((char*)iface - FIELD_OFFSET(domelem, lpVtbl));
56 static inline domelem *impl_from_InternalUnknown( IUnknown *iface )
58 return (domelem *)((char*)iface - FIELD_OFFSET(domelem, lpInternalUnkVtbl));
61 static inline xmlNodePtr get_element( domelem *This )
63 return xmlNodePtr_from_domnode( This->node, XML_ELEMENT_NODE );
66 static HRESULT WINAPI domelem_QueryInterface(
67 IXMLDOMElement *iface,
68 REFIID riid,
69 void** ppvObject )
71 domelem *This = impl_from_IXMLDOMElement( iface );
72 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
74 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
77 static ULONG WINAPI domelem_AddRef(
78 IXMLDOMElement *iface )
80 domelem *This = impl_from_IXMLDOMElement( iface );
81 return IUnknown_AddRef(This->pUnkOuter);
84 static ULONG WINAPI domelem_Release(
85 IXMLDOMElement *iface )
87 domelem *This = impl_from_IXMLDOMElement( iface );
88 return IUnknown_Release(This->pUnkOuter);
91 static HRESULT WINAPI domelem_GetTypeInfoCount(
92 IXMLDOMElement *iface,
93 UINT* pctinfo )
95 FIXME("\n");
96 return E_NOTIMPL;
99 static HRESULT WINAPI domelem_GetTypeInfo(
100 IXMLDOMElement *iface,
101 UINT iTInfo, LCID lcid,
102 ITypeInfo** ppTInfo )
104 FIXME("\n");
105 return E_NOTIMPL;
108 static HRESULT WINAPI domelem_GetIDsOfNames(
109 IXMLDOMElement *iface,
110 REFIID riid, LPOLESTR* rgszNames,
111 UINT cNames, LCID lcid, DISPID* rgDispId )
113 FIXME("\n");
114 return E_NOTIMPL;
117 static HRESULT WINAPI domelem_Invoke(
118 IXMLDOMElement *iface,
119 DISPID dispIdMember, REFIID riid, LCID lcid,
120 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
121 EXCEPINFO* pExcepInfo, UINT* puArgErr )
123 FIXME("\n");
124 return E_NOTIMPL;
127 static HRESULT WINAPI domelem_get_nodeName(
128 IXMLDOMElement *iface,
129 BSTR* p )
131 domelem *This = impl_from_IXMLDOMElement( iface );
132 return IXMLDOMNode_get_nodeName( This->node, p );
135 static HRESULT WINAPI domelem_get_nodeValue(
136 IXMLDOMElement *iface,
137 VARIANT* var1 )
139 domelem *This = impl_from_IXMLDOMElement( iface );
140 return IXMLDOMNode_get_nodeValue( This->node, var1 );
143 static HRESULT WINAPI domelem_put_nodeValue(
144 IXMLDOMElement *iface,
145 VARIANT var1 )
147 domelem *This = impl_from_IXMLDOMElement( iface );
148 return IXMLDOMNode_put_nodeValue( This->node, var1 );
151 static HRESULT WINAPI domelem_get_nodeType(
152 IXMLDOMElement *iface,
153 DOMNodeType* domNodeType )
155 domelem *This = impl_from_IXMLDOMElement( iface );
156 return IXMLDOMNode_get_nodeType( This->node, domNodeType );
159 static HRESULT WINAPI domelem_get_parentNode(
160 IXMLDOMElement *iface,
161 IXMLDOMNode** parent )
163 domelem *This = impl_from_IXMLDOMElement( iface );
164 return IXMLDOMNode_get_parentNode( This->node, parent );
167 static HRESULT WINAPI domelem_get_childNodes(
168 IXMLDOMElement *iface,
169 IXMLDOMNodeList** outList)
171 domelem *This = impl_from_IXMLDOMElement( iface );
172 return IXMLDOMNode_get_childNodes( This->node, outList );
175 static HRESULT WINAPI domelem_get_firstChild(
176 IXMLDOMElement *iface,
177 IXMLDOMNode** domNode)
179 domelem *This = impl_from_IXMLDOMElement( iface );
180 return IXMLDOMNode_get_firstChild( This->node, domNode );
183 static HRESULT WINAPI domelem_get_lastChild(
184 IXMLDOMElement *iface,
185 IXMLDOMNode** domNode)
187 domelem *This = impl_from_IXMLDOMElement( iface );
188 return IXMLDOMNode_get_lastChild( This->node, domNode );
191 static HRESULT WINAPI domelem_get_previousSibling(
192 IXMLDOMElement *iface,
193 IXMLDOMNode** domNode)
195 domelem *This = impl_from_IXMLDOMElement( iface );
196 return IXMLDOMNode_get_previousSibling( This->node, domNode );
199 static HRESULT WINAPI domelem_get_nextSibling(
200 IXMLDOMElement *iface,
201 IXMLDOMNode** domNode)
203 domelem *This = impl_from_IXMLDOMElement( iface );
204 return IXMLDOMNode_get_nextSibling( This->node, domNode );
207 static HRESULT WINAPI domelem_get_attributes(
208 IXMLDOMElement *iface,
209 IXMLDOMNamedNodeMap** attributeMap)
211 domelem *This = impl_from_IXMLDOMElement( iface );
212 return IXMLDOMNode_get_attributes( This->node, attributeMap );
215 static HRESULT WINAPI domelem_insertBefore(
216 IXMLDOMElement *iface,
217 IXMLDOMNode* newNode, VARIANT var1,
218 IXMLDOMNode** outOldNode)
220 domelem *This = impl_from_IXMLDOMElement( iface );
221 return IXMLDOMNode_insertBefore( This->node, newNode, var1, outOldNode );
224 static HRESULT WINAPI domelem_replaceChild(
225 IXMLDOMElement *iface,
226 IXMLDOMNode* newNode,
227 IXMLDOMNode* oldNode,
228 IXMLDOMNode** outOldNode)
230 domelem *This = impl_from_IXMLDOMElement( iface );
231 return IXMLDOMNode_replaceChild( This->node, newNode, oldNode, outOldNode );
234 static HRESULT WINAPI domelem_removeChild(
235 IXMLDOMElement *iface,
236 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
238 domelem *This = impl_from_IXMLDOMElement( iface );
239 return IXMLDOMNode_removeChild( This->node, domNode, oldNode );
242 static HRESULT WINAPI domelem_appendChild(
243 IXMLDOMElement *iface,
244 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
246 domelem *This = impl_from_IXMLDOMElement( iface );
247 return IXMLDOMNode_appendChild( This->node, newNode, outNewNode );
250 static HRESULT WINAPI domelem_hasChildNodes(
251 IXMLDOMElement *iface,
252 VARIANT_BOOL* pbool)
254 domelem *This = impl_from_IXMLDOMElement( iface );
255 return IXMLDOMNode_hasChildNodes( This->node, pbool );
258 static HRESULT WINAPI domelem_get_ownerDocument(
259 IXMLDOMElement *iface,
260 IXMLDOMDocument** domDocument)
262 domelem *This = impl_from_IXMLDOMElement( iface );
263 return IXMLDOMNode_get_ownerDocument( This->node, domDocument );
266 static HRESULT WINAPI domelem_cloneNode(
267 IXMLDOMElement *iface,
268 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
270 domelem *This = impl_from_IXMLDOMElement( iface );
271 return IXMLDOMNode_cloneNode( This->node, pbool, outNode );
274 static HRESULT WINAPI domelem_get_nodeTypeString(
275 IXMLDOMElement *iface,
276 BSTR* p)
278 domelem *This = impl_from_IXMLDOMElement( iface );
279 return IXMLDOMNode_get_nodeTypeString( This->node, p );
282 static HRESULT WINAPI domelem_get_text(
283 IXMLDOMElement *iface,
284 BSTR* p)
286 domelem *This = impl_from_IXMLDOMElement( iface );
287 return IXMLDOMNode_get_text( This->node, p );
290 static HRESULT WINAPI domelem_put_text(
291 IXMLDOMElement *iface,
292 BSTR p)
294 domelem *This = impl_from_IXMLDOMElement( iface );
295 return IXMLDOMNode_put_text( This->node, p );
298 static HRESULT WINAPI domelem_get_specified(
299 IXMLDOMElement *iface,
300 VARIANT_BOOL* pbool)
302 domelem *This = impl_from_IXMLDOMElement( iface );
303 return IXMLDOMNode_get_specified( This->node, pbool );
306 static HRESULT WINAPI domelem_get_definition(
307 IXMLDOMElement *iface,
308 IXMLDOMNode** domNode)
310 domelem *This = impl_from_IXMLDOMElement( iface );
311 return IXMLDOMNode_get_definition( This->node, domNode );
314 static HRESULT WINAPI domelem_get_nodeTypedValue(
315 IXMLDOMElement *iface,
316 VARIANT* var1)
318 domelem *This = impl_from_IXMLDOMElement( iface );
319 return IXMLDOMNode_get_nodeTypedValue( This->node, var1 );
322 static HRESULT WINAPI domelem_put_nodeTypedValue(
323 IXMLDOMElement *iface,
324 VARIANT var1)
326 domelem *This = impl_from_IXMLDOMElement( iface );
327 return IXMLDOMNode_put_nodeTypedValue( This->node, var1 );
330 static HRESULT WINAPI domelem_get_dataType(
331 IXMLDOMElement *iface,
332 VARIANT* var1)
334 domelem *This = impl_from_IXMLDOMElement( iface );
335 return IXMLDOMNode_get_dataType( This->node, var1 );
338 static HRESULT WINAPI domelem_put_dataType(
339 IXMLDOMElement *iface,
340 BSTR p)
342 domelem *This = impl_from_IXMLDOMElement( iface );
343 return IXMLDOMNode_put_dataType( This->node, p );
346 static HRESULT WINAPI domelem_get_xml(
347 IXMLDOMElement *iface,
348 BSTR* p)
350 domelem *This = impl_from_IXMLDOMElement( iface );
351 return IXMLDOMNode_get_xml( This->node, p );
354 static HRESULT WINAPI domelem_transformNode(
355 IXMLDOMElement *iface,
356 IXMLDOMNode* domNode, BSTR* p)
358 domelem *This = impl_from_IXMLDOMElement( iface );
359 return IXMLDOMNode_transformNode( This->node, domNode, p );
362 static HRESULT WINAPI domelem_selectNodes(
363 IXMLDOMElement *iface,
364 BSTR p, IXMLDOMNodeList** outList)
366 domelem *This = impl_from_IXMLDOMElement( iface );
367 return IXMLDOMNode_selectNodes( This->node, p, outList );
370 static HRESULT WINAPI domelem_selectSingleNode(
371 IXMLDOMElement *iface,
372 BSTR p, IXMLDOMNode** outNode)
374 domelem *This = impl_from_IXMLDOMElement( iface );
375 return IXMLDOMNode_selectSingleNode( This->node, p, outNode );
378 static HRESULT WINAPI domelem_get_parsed(
379 IXMLDOMElement *iface,
380 VARIANT_BOOL* pbool)
382 domelem *This = impl_from_IXMLDOMElement( iface );
383 return IXMLDOMNode_get_parsed( This->node, pbool );
386 static HRESULT WINAPI domelem_get_namespaceURI(
387 IXMLDOMElement *iface,
388 BSTR* p)
390 domelem *This = impl_from_IXMLDOMElement( iface );
391 return IXMLDOMNode_get_namespaceURI( This->node, p );
394 static HRESULT WINAPI domelem_get_prefix(
395 IXMLDOMElement *iface,
396 BSTR* p)
398 domelem *This = impl_from_IXMLDOMElement( iface );
399 return IXMLDOMNode_get_prefix( This->node, p );
402 static HRESULT WINAPI domelem_get_baseName(
403 IXMLDOMElement *iface,
404 BSTR* p)
406 domelem *This = impl_from_IXMLDOMElement( iface );
407 return IXMLDOMNode_get_baseName( This->node, p );
410 static HRESULT WINAPI domelem_transformNodeToObject(
411 IXMLDOMElement *iface,
412 IXMLDOMNode* domNode, VARIANT var1)
414 domelem *This = impl_from_IXMLDOMElement( iface );
415 return IXMLDOMNode_transformNodeToObject( This->node, domNode, var1 );
418 static HRESULT WINAPI domelem_get_tagName(
419 IXMLDOMElement *iface,
420 BSTR* p)
422 domelem *This = impl_from_IXMLDOMElement( iface );
423 xmlNodePtr element;
424 DWORD len;
425 DWORD offset = 0;
426 LPWSTR str;
428 TRACE("%p\n", This );
430 if ( !This->node )
431 return E_FAIL;
433 element = get_element( This );
434 if ( !element )
435 return E_FAIL;
437 len = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, NULL, 0 );
438 if (element->ns)
439 len += MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, NULL, 0 );
440 str = (LPWSTR) HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
441 if ( !str )
442 return E_OUTOFMEMORY;
443 if (element->ns)
445 offset = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, str, len );
446 str[offset - 1] = ':';
448 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, str + offset, len - offset );
449 *p = SysAllocString( str );
450 HeapFree( GetProcessHeap(), 0, str );
452 return S_OK;
455 static HRESULT WINAPI domelem_getAttribute(
456 IXMLDOMElement *iface,
457 BSTR name, VARIANT* value)
459 domelem *This = impl_from_IXMLDOMElement( iface );
460 xmlNodePtr element;
461 xmlChar *xml_name, *xml_value;
462 HRESULT hr = E_FAIL;
464 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), value);
466 element = get_element( This );
467 if ( !element )
468 return E_FAIL;
470 VariantInit(value);
471 xml_name = xmlChar_from_wchar( name );
472 xml_value = xmlGetNsProp(element, xml_name, NULL);
473 HeapFree(GetProcessHeap(), 0, xml_name);
474 if(xml_value)
476 V_VT(value) = VT_BSTR;
477 V_BSTR(value) = bstr_from_xmlChar( xml_value );
478 xmlFree(xml_value);
479 hr = S_OK;
482 return hr;
485 static HRESULT WINAPI domelem_setAttribute(
486 IXMLDOMElement *iface,
487 BSTR name, VARIANT value)
489 domelem *This = impl_from_IXMLDOMElement( iface );
490 xmlNodePtr element;
491 xmlChar *xml_name, *xml_value;
492 HRESULT hr;
493 VARIANT var;
495 TRACE("(%p)->(%s, var)\n", This, debugstr_w(name));
497 element = get_element( This );
498 if ( !element )
499 return E_FAIL;
501 VariantInit(&var);
502 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
503 if(hr != S_OK)
505 FIXME("VariantChangeType failed\n");
506 return hr;
509 xml_name = xmlChar_from_wchar( name );
510 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
512 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
513 hr = E_FAIL;
515 HeapFree(GetProcessHeap(), 0, xml_value);
516 HeapFree(GetProcessHeap(), 0, xml_name);
517 VariantClear(&var);
519 return hr;
522 static HRESULT WINAPI domelem_removeAttribute(
523 IXMLDOMElement *iface,
524 BSTR p)
526 FIXME("\n");
527 return E_NOTIMPL;
530 static HRESULT WINAPI domelem_getAttributeNode(
531 IXMLDOMElement *iface,
532 BSTR p, IXMLDOMAttribute** attributeNode )
534 FIXME("\n");
535 return E_NOTIMPL;
538 static HRESULT WINAPI domelem_setAttributeNode(
539 IXMLDOMElement *iface,
540 IXMLDOMAttribute* domAttribute,
541 IXMLDOMAttribute** attributeNode)
543 FIXME("\n");
544 return E_NOTIMPL;
547 static HRESULT WINAPI domelem_removeAttributeNode(
548 IXMLDOMElement *iface,
549 IXMLDOMAttribute* domAttribute,
550 IXMLDOMAttribute** attributeNode)
552 FIXME("\n");
553 return E_NOTIMPL;
556 static HRESULT WINAPI domelem_getElementsByTagName(
557 IXMLDOMElement *iface,
558 BSTR bstrName, IXMLDOMNodeList** resultList)
560 domelem *This = impl_from_IXMLDOMElement( iface );
561 LPWSTR szPattern;
562 HRESULT hr;
564 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(bstrName), resultList);
566 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(3+lstrlenW(bstrName)+1));
567 szPattern[0] = '.';
568 szPattern[1] = szPattern[2] = '/';
569 lstrcpyW(szPattern+3, bstrName);
570 TRACE("%s\n", debugstr_w(szPattern));
572 hr = queryresult_create(get_element(This), szPattern, resultList);
573 HeapFree(GetProcessHeap(), 0, szPattern);
575 return hr;
578 static HRESULT WINAPI domelem_normalize(
579 IXMLDOMElement *iface )
581 FIXME("\n");
582 return E_NOTIMPL;
585 static const struct IXMLDOMElementVtbl domelem_vtbl =
587 domelem_QueryInterface,
588 domelem_AddRef,
589 domelem_Release,
590 domelem_GetTypeInfoCount,
591 domelem_GetTypeInfo,
592 domelem_GetIDsOfNames,
593 domelem_Invoke,
594 domelem_get_nodeName,
595 domelem_get_nodeValue,
596 domelem_put_nodeValue,
597 domelem_get_nodeType,
598 domelem_get_parentNode,
599 domelem_get_childNodes,
600 domelem_get_firstChild,
601 domelem_get_lastChild,
602 domelem_get_previousSibling,
603 domelem_get_nextSibling,
604 domelem_get_attributes,
605 domelem_insertBefore,
606 domelem_replaceChild,
607 domelem_removeChild,
608 domelem_appendChild,
609 domelem_hasChildNodes,
610 domelem_get_ownerDocument,
611 domelem_cloneNode,
612 domelem_get_nodeTypeString,
613 domelem_get_text,
614 domelem_put_text,
615 domelem_get_specified,
616 domelem_get_definition,
617 domelem_get_nodeTypedValue,
618 domelem_put_nodeTypedValue,
619 domelem_get_dataType,
620 domelem_put_dataType,
621 domelem_get_xml,
622 domelem_transformNode,
623 domelem_selectNodes,
624 domelem_selectSingleNode,
625 domelem_get_parsed,
626 domelem_get_namespaceURI,
627 domelem_get_prefix,
628 domelem_get_baseName,
629 domelem_transformNodeToObject,
630 domelem_get_tagName,
631 domelem_getAttribute,
632 domelem_setAttribute,
633 domelem_removeAttribute,
634 domelem_getAttributeNode,
635 domelem_setAttributeNode,
636 domelem_removeAttributeNode,
637 domelem_getElementsByTagName,
638 domelem_normalize,
641 static HRESULT WINAPI Internal_QueryInterface(
642 IUnknown *iface,
643 REFIID riid,
644 void** ppvObject )
646 domelem *This = impl_from_InternalUnknown( iface );
647 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
649 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
650 IsEqualGUID( riid, &IID_IUnknown ) )
652 *ppvObject = &This->lpVtbl;
654 else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
655 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
657 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
659 else
661 FIXME("interface %s not implemented\n", debugstr_guid(riid));
662 return E_NOINTERFACE;
665 IUnknown_AddRef( (IUnknown*)*ppvObject );
667 return S_OK;
670 static ULONG WINAPI Internal_AddRef(
671 IUnknown *iface )
673 domelem *This = impl_from_InternalUnknown( iface );
674 return InterlockedIncrement( &This->ref );
677 static ULONG WINAPI Internal_Release(
678 IUnknown *iface )
680 domelem *This = impl_from_InternalUnknown( iface );
681 ULONG ref;
683 ref = InterlockedDecrement( &This->ref );
684 if ( ref == 0 )
686 IUnknown_Release( This->node_unk );
687 HeapFree( GetProcessHeap(), 0, This );
690 return ref;
693 static const struct IUnknownVtbl internal_unk_vtbl =
695 Internal_QueryInterface,
696 Internal_AddRef,
697 Internal_Release
700 IUnknown* create_element( xmlNodePtr element, IUnknown *pUnkOuter )
702 domelem *This;
703 HRESULT hr;
705 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
706 if ( !This )
707 return NULL;
709 This->lpVtbl = &domelem_vtbl;
710 This->ref = 1;
711 This->lpInternalUnkVtbl = &internal_unk_vtbl;
713 if(pUnkOuter)
714 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
715 else
716 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
718 This->node_unk = create_basic_node( element, (IUnknown*)&This->lpVtbl );
719 if(!This->node_unk)
721 HeapFree(GetProcessHeap(), 0, This);
722 return NULL;
725 hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
726 if(FAILED(hr))
728 IUnknown_Release(This->node_unk);
729 HeapFree( GetProcessHeap(), 0, This );
730 return NULL;
732 /* The ref on This->node is actually looped back into this object, so release it */
733 IXMLDOMNode_Release(This->node);
735 return (IUnknown*) &This->lpInternalUnkVtbl;
738 #endif