gdi32: Implement PaintRgn().
[wine] / dlls / msxml3 / parseerror.c
1 /*
2  *    ParseError implementation
3  *
4  * Copyright 2005 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
22 #define COBJMACROS
23
24 #include "config.h"
25
26 #include <stdarg.h>
27 #ifdef HAVE_LIBXML2
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
30 #endif
31
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winerror.h"
35 #include "winuser.h"
36 #include "ole2.h"
37 #include "msxml6.h"
38
39 #include "msxml_private.h"
40
41 #include "wine/debug.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
44
45 typedef struct
46 {
47     IXMLDOMParseError IXMLDOMParseError_iface;
48     LONG ref;
49     LONG code, line, linepos, filepos;
50     BSTR url, reason, srcText;
51 } parse_error_t;
52
53 static inline parse_error_t *impl_from_IXMLDOMParseError( IXMLDOMParseError *iface )
54 {
55     return CONTAINING_RECORD(iface, parse_error_t, IXMLDOMParseError_iface);
56 }
57
58 static HRESULT WINAPI parseError_QueryInterface(
59     IXMLDOMParseError *iface,
60     REFIID riid,
61     void** ppvObject )
62 {
63     TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
64
65     if ( IsEqualGUID( riid, &IID_IUnknown ) ||
66          IsEqualGUID( riid, &IID_IDispatch ) ||
67          IsEqualGUID( riid, &IID_IXMLDOMParseError ) )
68     {
69         *ppvObject = iface;
70     }
71     else
72     {
73         FIXME("interface %s not implemented\n", debugstr_guid(riid));
74         *ppvObject = NULL;
75         return E_NOINTERFACE;
76     }
77
78     IXMLDOMParseError_AddRef( iface );
79
80     return S_OK;
81 }
82
83 static ULONG WINAPI parseError_AddRef(
84     IXMLDOMParseError *iface )
85 {
86     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
87     ULONG ref = InterlockedIncrement( &This->ref );
88     TRACE("(%p) ref now %d\n", This, ref);
89     return ref;
90 }
91
92 static ULONG WINAPI parseError_Release(
93     IXMLDOMParseError *iface )
94 {
95     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
96     ULONG ref;
97
98     ref = InterlockedDecrement( &This->ref );
99     TRACE("(%p) ref now %d\n", This, ref);
100     if ( ref == 0 )
101     {
102         SysFreeString(This->url);
103         SysFreeString(This->reason);
104         SysFreeString(This->srcText);
105         heap_free( This );
106     }
107
108     return ref;
109 }
110
111 static HRESULT WINAPI parseError_GetTypeInfoCount(
112     IXMLDOMParseError *iface,
113     UINT* pctinfo )
114 {
115     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
116
117     TRACE("(%p)->(%p)\n", This, pctinfo);
118
119     *pctinfo = 1;
120
121     return S_OK;
122 }
123
124 static HRESULT WINAPI parseError_GetTypeInfo(
125     IXMLDOMParseError *iface,
126     UINT iTInfo,
127     LCID lcid,
128     ITypeInfo** ppTInfo )
129 {
130     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
131     HRESULT hr;
132
133     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
134
135     hr = get_typeinfo(IXMLDOMParseError_tid, ppTInfo);
136
137     return hr;
138 }
139
140 static HRESULT WINAPI parseError_GetIDsOfNames(
141     IXMLDOMParseError *iface,
142     REFIID riid,
143     LPOLESTR* rgszNames,
144     UINT cNames,
145     LCID lcid,
146     DISPID* rgDispId )
147 {
148     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
149     ITypeInfo *typeinfo;
150     HRESULT hr;
151
152     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
153           lcid, rgDispId);
154
155     if(!rgszNames || cNames == 0 || !rgDispId)
156         return E_INVALIDARG;
157
158     hr = get_typeinfo(IXMLDOMParseError_tid, &typeinfo);
159     if(SUCCEEDED(hr))
160     {
161         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
162         ITypeInfo_Release(typeinfo);
163     }
164
165     return hr;
166 }
167
168 static HRESULT WINAPI parseError_Invoke(
169     IXMLDOMParseError *iface,
170     DISPID dispIdMember,
171     REFIID riid,
172     LCID lcid,
173     WORD wFlags,
174     DISPPARAMS* pDispParams,
175     VARIANT* pVarResult,
176     EXCEPINFO* pExcepInfo,
177     UINT* puArgErr )
178 {
179     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
180     ITypeInfo *typeinfo;
181     HRESULT hr;
182
183     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
184           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
185
186     hr = get_typeinfo(IXMLDOMParseError_tid, &typeinfo);
187     if(SUCCEEDED(hr))
188     {
189         hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMParseError_iface, dispIdMember, wFlags,
190                 pDispParams, pVarResult, pExcepInfo, puArgErr);
191         ITypeInfo_Release(typeinfo);
192     }
193
194     return hr;
195 }
196
197 static HRESULT WINAPI parseError_get_errorCode(
198     IXMLDOMParseError *iface,
199     LONG *code )
200 {
201     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
202     TRACE("(%p)->(%p)\n", This, code);
203
204     *code = This->code;
205
206     if(This->code == 0)
207         return S_FALSE;
208
209     return S_OK;
210 }
211
212 static HRESULT WINAPI parseError_get_url(
213     IXMLDOMParseError *iface,
214     BSTR *url )
215 {
216     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
217     FIXME("(%p)->(%p)\n", This, url);
218     return E_NOTIMPL;
219 }
220
221 static HRESULT WINAPI parseError_get_reason(
222     IXMLDOMParseError *iface,
223     BSTR *reason )
224 {
225     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
226     TRACE("(%p)->(%p)\n", This, reason);
227     
228     if(!This->reason)
229     {
230         *reason = NULL;
231         return S_FALSE;
232     }
233     *reason = SysAllocString(This->reason);
234     return S_OK;
235 }
236
237 static HRESULT WINAPI parseError_get_srcText(
238     IXMLDOMParseError *iface,
239     BSTR *srcText )
240 {
241     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
242     FIXME("(%p)->(%p)\n", This, srcText);
243     return E_NOTIMPL;
244 }
245
246 static HRESULT WINAPI parseError_get_line(
247     IXMLDOMParseError *iface,
248     LONG *line )
249 {
250     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
251     FIXME("(%p)->(%p)\n", This, line);
252     return E_NOTIMPL;
253 }
254
255 static HRESULT WINAPI parseError_get_linepos(
256     IXMLDOMParseError *iface,
257     LONG *linepos )
258 {
259     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
260     FIXME("(%p)->(%p)\n", This, linepos);
261     return E_NOTIMPL;
262 }
263
264 static HRESULT WINAPI parseError_get_filepos(
265     IXMLDOMParseError *iface,
266     LONG *filepos )
267 {
268     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
269     FIXME("(%p)->(%p)\n", This, filepos);
270     return E_NOTIMPL;
271 }
272
273 static const struct IXMLDOMParseErrorVtbl parseError_vtbl =
274 {
275     parseError_QueryInterface,
276     parseError_AddRef,
277     parseError_Release,
278     parseError_GetTypeInfoCount,
279     parseError_GetTypeInfo,
280     parseError_GetIDsOfNames,
281     parseError_Invoke,
282     parseError_get_errorCode,
283     parseError_get_url,
284     parseError_get_reason,
285     parseError_get_srcText,
286     parseError_get_line,
287     parseError_get_linepos,
288     parseError_get_filepos
289 };
290
291 IXMLDOMParseError *create_parseError( LONG code, BSTR url, BSTR reason, BSTR srcText,
292                                       LONG line, LONG linepos, LONG filepos )
293 {
294     parse_error_t *This;
295
296     This = heap_alloc( sizeof(*This) );
297     if ( !This )
298         return NULL;
299
300     This->IXMLDOMParseError_iface.lpVtbl = &parseError_vtbl;
301     This->ref = 1;
302
303     This->code = code;
304     This->url = url;
305     This->reason = reason;
306     This->srcText = srcText;
307     This->line = line;
308     This->linepos = linepos;
309     This->filepos = filepos;
310
311     return &This->IXMLDOMParseError_iface;
312 }