msxml3: Implemented IDispatch for IXMLDOMNamedNodeMap.
[wine] / dlls / msxml3 / domimpl.c
1 /*
2  *    DOM Document Implementation implementation
3  *
4  * Copyright 2007 Alistair Leslie-Hughes
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 "msxml2.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 _domimpl
41 {
42     const struct IXMLDOMImplementationVtbl *lpVtbl;
43     LONG ref;
44 } domimpl;
45
46 static inline domimpl *impl_from_IXMLDOMImplementation( IXMLDOMImplementation *iface )
47 {
48     return (domimpl *)((char*)iface - FIELD_OFFSET(domimpl, lpVtbl));
49 }
50
51 static HRESULT WINAPI dimimpl_QueryInterface(
52     IXMLDOMImplementation *iface,
53     REFIID riid,
54     void** ppvObject )
55 {
56     domimpl *This = impl_from_IXMLDOMImplementation( iface );
57     TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
58
59     if ( IsEqualGUID( riid, &IID_IXMLDOMImplementation ) ||
60          IsEqualGUID( riid, &IID_IDispatch ) ||
61          IsEqualGUID( riid, &IID_IUnknown ) )
62     {
63         *ppvObject = iface;
64     }
65     else
66     {
67         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
68         return E_NOINTERFACE;
69     }
70
71     IXMLDOMImplementation_AddRef( iface );
72
73     return S_OK;
74 }
75
76 static ULONG WINAPI dimimpl_AddRef(
77     IXMLDOMImplementation *iface )
78 {
79     domimpl *This = impl_from_IXMLDOMImplementation( iface );
80     return InterlockedIncrement( &This->ref );
81 }
82
83 static ULONG WINAPI dimimpl_Release(
84     IXMLDOMImplementation *iface )
85 {
86     domimpl *This = impl_from_IXMLDOMImplementation( iface );
87     ULONG ref;
88
89     ref = InterlockedDecrement( &This->ref );
90     if ( ref == 0 )
91     {
92         HeapFree( GetProcessHeap(), 0, This );
93     }
94
95     return ref;
96 }
97
98 static HRESULT WINAPI dimimpl_GetTypeInfoCount(
99     IXMLDOMImplementation *iface,
100     UINT* pctinfo )
101 {
102     FIXME("\n");
103     return E_NOTIMPL;
104 }
105
106 static HRESULT WINAPI dimimpl_GetTypeInfo(
107     IXMLDOMImplementation *iface,
108     UINT iTInfo, LCID lcid,
109     ITypeInfo** ppTInfo )
110 {
111     FIXME("\n");
112     return E_NOTIMPL;
113 }
114
115 static HRESULT WINAPI dimimpl_GetIDsOfNames(
116     IXMLDOMImplementation *iface,
117     REFIID riid, LPOLESTR* rgszNames,
118     UINT cNames, LCID lcid, DISPID* rgDispId )
119 {
120     FIXME("\n");
121     return E_NOTIMPL;
122 }
123
124 static HRESULT WINAPI dimimpl_Invoke(
125     IXMLDOMImplementation *iface,
126     DISPID dispIdMember, REFIID riid, LCID lcid,
127     WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
128     EXCEPINFO* pExcepInfo, UINT* puArgErr )
129 {
130     FIXME("\n");
131     return E_NOTIMPL;
132 }
133
134 static HRESULT WINAPI dimimpl_hasFeature(IXMLDOMImplementation* This, BSTR feature, BSTR version, VARIANT_BOOL *hasFeature)
135 {
136     static WCHAR bVersion[] = {'1','.','0',0};
137     static WCHAR bXML[] = {'X','M','L',0};
138     static WCHAR bDOM[] = {'D','O','M',0};
139     static WCHAR bMSDOM[] = {'M','S','-','D','O','M',0};
140     BOOL bValidFeature = FALSE;
141     BOOL bValidVersion = FALSE;
142
143     TRACE("feature(%s) version (%s)\n", debugstr_w(feature), debugstr_w(version));
144
145     if(!feature || !hasFeature)
146         return E_INVALIDARG;
147
148     *hasFeature = VARIANT_FALSE;
149
150     if(!version || lstrcmpiW(version, bVersion) == 0)
151         bValidVersion = TRUE;
152
153     if(lstrcmpiW(feature, bXML) == 0 || lstrcmpiW(feature, bDOM) == 0 || lstrcmpiW(feature, bMSDOM) == 0)
154         bValidFeature = TRUE;
155
156     if(bValidVersion && bValidFeature)
157         *hasFeature = VARIANT_TRUE;
158
159     return S_OK;
160 }
161
162 static const struct IXMLDOMImplementationVtbl dimimpl_vtbl =
163 {
164     dimimpl_QueryInterface,
165     dimimpl_AddRef,
166     dimimpl_Release,
167     dimimpl_GetTypeInfoCount,
168     dimimpl_GetTypeInfo,
169     dimimpl_GetIDsOfNames,
170     dimimpl_Invoke,
171     dimimpl_hasFeature
172 };
173
174 IUnknown* create_doc_Implementation()
175 {
176     domimpl *This;
177
178     This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
179     if ( !This )
180         return NULL;
181
182     This->lpVtbl = &dimimpl_vtbl;
183     This->ref = 1;
184
185     return (IUnknown*) &This->lpVtbl;
186 }
187
188 #endif