dsound: Don't specify period size for the IAudioClient.
[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 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 #endif
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "ole2.h"
35 #include "msxml6.h"
36
37 #include "msxml_private.h"
38
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
42
43 #ifdef HAVE_LIBXML2
44
45 typedef struct _domimpl
46 {
47     DispatchEx dispex;
48     IXMLDOMImplementation IXMLDOMImplementation_iface;
49     LONG ref;
50 } domimpl;
51
52 static inline domimpl *impl_from_IXMLDOMImplementation( IXMLDOMImplementation *iface )
53 {
54     return CONTAINING_RECORD(iface, domimpl, IXMLDOMImplementation_iface);
55 }
56
57 static HRESULT WINAPI dimimpl_QueryInterface(
58     IXMLDOMImplementation *iface,
59     REFIID riid,
60     void** ppvObject )
61 {
62     domimpl *This = impl_from_IXMLDOMImplementation( iface );
63     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
64
65     if ( IsEqualGUID( riid, &IID_IXMLDOMImplementation ) ||
66          IsEqualGUID( riid, &IID_IDispatch ) ||
67          IsEqualGUID( riid, &IID_IUnknown ) )
68     {
69         *ppvObject = iface;
70     }
71     else if (dispex_query_interface(&This->dispex, riid, ppvObject))
72     {
73         return *ppvObject ? S_OK : E_NOINTERFACE;
74     }
75     else
76     {
77         TRACE("Unsupported interface %s\n", debugstr_guid(riid));
78         *ppvObject = NULL;
79         return E_NOINTERFACE;
80     }
81
82     IXMLDOMImplementation_AddRef( iface );
83
84     return S_OK;
85 }
86
87 static ULONG WINAPI dimimpl_AddRef(
88     IXMLDOMImplementation *iface )
89 {
90     domimpl *This = impl_from_IXMLDOMImplementation( iface );
91     ULONG ref = InterlockedIncrement( &This->ref );
92     TRACE("(%p)->(%d)\n", This, ref);
93     return ref;
94 }
95
96 static ULONG WINAPI dimimpl_Release(
97     IXMLDOMImplementation *iface )
98 {
99     domimpl *This = impl_from_IXMLDOMImplementation( iface );
100     ULONG ref = InterlockedDecrement( &This->ref );
101
102     TRACE("(%p)->(%d)\n", This, ref);
103     if ( ref == 0 )
104     {
105         release_dispex(&This->dispex);
106         heap_free( This );
107     }
108
109     return ref;
110 }
111
112 static HRESULT WINAPI dimimpl_GetTypeInfoCount(
113     IXMLDOMImplementation *iface,
114     UINT* pctinfo )
115 {
116     domimpl *This = impl_from_IXMLDOMImplementation( iface );
117
118     TRACE("(%p)->(%p)\n", This, pctinfo);
119
120     *pctinfo = 1;
121
122     return S_OK;
123 }
124
125 static HRESULT WINAPI dimimpl_GetTypeInfo(
126     IXMLDOMImplementation *iface,
127     UINT iTInfo, LCID lcid,
128     ITypeInfo** ppTInfo )
129 {
130     domimpl *This = impl_from_IXMLDOMImplementation( iface );
131
132     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
133
134     return get_typeinfo(IXMLDOMImplementation_tid, ppTInfo);
135 }
136
137 static HRESULT WINAPI dimimpl_GetIDsOfNames(
138     IXMLDOMImplementation *iface,
139     REFIID riid, LPOLESTR* rgszNames,
140     UINT cNames, LCID lcid, DISPID* rgDispId )
141 {
142     domimpl *This = impl_from_IXMLDOMImplementation( iface );
143     ITypeInfo *typeinfo;
144     HRESULT hr;
145
146     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
147           lcid, rgDispId);
148
149     if(!rgszNames || cNames == 0 || !rgDispId)
150         return E_INVALIDARG;
151
152     hr = get_typeinfo(IXMLDOMImplementation_tid, &typeinfo);
153     if(SUCCEEDED(hr))
154     {
155         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
156         ITypeInfo_Release(typeinfo);
157     }
158
159     return hr;
160 }
161
162 static HRESULT WINAPI dimimpl_Invoke(
163     IXMLDOMImplementation *iface,
164     DISPID dispIdMember, REFIID riid, LCID lcid,
165     WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
166     EXCEPINFO* pExcepInfo, UINT* puArgErr )
167 {
168     domimpl *This = impl_from_IXMLDOMImplementation( iface );
169     ITypeInfo *typeinfo;
170     HRESULT hr;
171
172     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
173           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
174
175     hr = get_typeinfo(IXMLDOMImplementation_tid, &typeinfo);
176     if(SUCCEEDED(hr))
177     {
178         hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMImplementation_iface, dispIdMember, wFlags,
179                 pDispParams, pVarResult, pExcepInfo, puArgErr);
180         ITypeInfo_Release(typeinfo);
181     }
182
183     return hr;
184 }
185
186 static HRESULT WINAPI dimimpl_hasFeature(IXMLDOMImplementation* This, BSTR feature, BSTR version, VARIANT_BOOL *hasFeature)
187 {
188     static const WCHAR bVersion[] = {'1','.','0',0};
189     static const WCHAR bXML[] = {'X','M','L',0};
190     static const WCHAR bDOM[] = {'D','O','M',0};
191     static const WCHAR bMSDOM[] = {'M','S','-','D','O','M',0};
192     BOOL bValidFeature = FALSE;
193     BOOL bValidVersion = FALSE;
194
195     TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(feature), debugstr_w(version), hasFeature);
196
197     if(!feature || !hasFeature)
198         return E_INVALIDARG;
199
200     *hasFeature = VARIANT_FALSE;
201
202     if(!version || lstrcmpiW(version, bVersion) == 0)
203         bValidVersion = TRUE;
204
205     if(lstrcmpiW(feature, bXML) == 0 || lstrcmpiW(feature, bDOM) == 0 || lstrcmpiW(feature, bMSDOM) == 0)
206         bValidFeature = TRUE;
207
208     if(bValidVersion && bValidFeature)
209         *hasFeature = VARIANT_TRUE;
210
211     return S_OK;
212 }
213
214 static const struct IXMLDOMImplementationVtbl dimimpl_vtbl =
215 {
216     dimimpl_QueryInterface,
217     dimimpl_AddRef,
218     dimimpl_Release,
219     dimimpl_GetTypeInfoCount,
220     dimimpl_GetTypeInfo,
221     dimimpl_GetIDsOfNames,
222     dimimpl_Invoke,
223     dimimpl_hasFeature
224 };
225
226 static const tid_t dimimpl_iface_tids[] = {
227     IXMLDOMImplementation_tid,
228     0
229 };
230
231 static dispex_static_data_t dimimpl_dispex = {
232     NULL,
233     IXMLDOMImplementation_tid,
234     NULL,
235     dimimpl_iface_tids
236 };
237
238 IUnknown* create_doc_Implementation(void)
239 {
240     domimpl *This;
241
242     This = heap_alloc( sizeof *This );
243     if ( !This )
244         return NULL;
245
246     This->IXMLDOMImplementation_iface.lpVtbl = &dimimpl_vtbl;
247     This->ref = 1;
248     init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMImplementation_iface, &dimimpl_dispex);
249
250     return (IUnknown*)&This->IXMLDOMImplementation_iface;
251 }
252
253 #endif