comdlg32: Correct title of "Save As" dialog.
[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     DispatchEx dispex;
48     IXMLDOMParseError IXMLDOMParseError_iface;
49     LONG ref;
50     LONG code, line, linepos, filepos;
51     BSTR url, reason, srcText;
52 } parse_error_t;
53
54 static inline parse_error_t *impl_from_IXMLDOMParseError( IXMLDOMParseError *iface )
55 {
56     return CONTAINING_RECORD(iface, parse_error_t, IXMLDOMParseError_iface);
57 }
58
59 static HRESULT WINAPI parseError_QueryInterface(
60     IXMLDOMParseError *iface,
61     REFIID riid,
62     void** ppvObject )
63 {
64     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
65
66     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
67
68     if ( IsEqualGUID( riid, &IID_IUnknown ) ||
69          IsEqualGUID( riid, &IID_IDispatch ) ||
70          IsEqualGUID( riid, &IID_IXMLDOMParseError ) )
71     {
72         *ppvObject = iface;
73     }
74     else if (dispex_query_interface(&This->dispex, riid, ppvObject))
75     {
76         return *ppvObject ? S_OK : E_NOINTERFACE;
77     }
78     else
79     {
80         FIXME("interface %s not implemented\n", debugstr_guid(riid));
81         *ppvObject = NULL;
82         return E_NOINTERFACE;
83     }
84
85     IXMLDOMParseError_AddRef( iface );
86
87     return S_OK;
88 }
89
90 static ULONG WINAPI parseError_AddRef(
91     IXMLDOMParseError *iface )
92 {
93     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
94     ULONG ref = InterlockedIncrement( &This->ref );
95     TRACE("(%p)->(%d)\n", This, ref);
96     return ref;
97 }
98
99 static ULONG WINAPI parseError_Release(
100     IXMLDOMParseError *iface )
101 {
102     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
103     ULONG ref = InterlockedDecrement( &This->ref );
104
105     TRACE("(%p)->(%d)\n", This, ref);
106     if ( ref == 0 )
107     {
108         SysFreeString(This->url);
109         SysFreeString(This->reason);
110         SysFreeString(This->srcText);
111         release_dispex(&This->dispex);
112         heap_free( This );
113     }
114
115     return ref;
116 }
117
118 static HRESULT WINAPI parseError_GetTypeInfoCount(
119     IXMLDOMParseError *iface,
120     UINT* pctinfo )
121 {
122     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
123     return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
124 }
125
126 static HRESULT WINAPI parseError_GetTypeInfo(
127     IXMLDOMParseError *iface,
128     UINT iTInfo,
129     LCID lcid,
130     ITypeInfo** ppTInfo )
131 {
132     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
133     return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
134         iTInfo, lcid, ppTInfo);
135 }
136
137 static HRESULT WINAPI parseError_GetIDsOfNames(
138     IXMLDOMParseError *iface,
139     REFIID riid,
140     LPOLESTR* rgszNames,
141     UINT cNames,
142     LCID lcid,
143     DISPID* rgDispId )
144 {
145     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
146     return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
147         riid, rgszNames, cNames, lcid, rgDispId);
148 }
149
150 static HRESULT WINAPI parseError_Invoke(
151     IXMLDOMParseError *iface,
152     DISPID dispIdMember,
153     REFIID riid,
154     LCID lcid,
155     WORD wFlags,
156     DISPPARAMS* pDispParams,
157     VARIANT* pVarResult,
158     EXCEPINFO* pExcepInfo,
159     UINT* puArgErr )
160 {
161     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
162     return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
163         dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
164 }
165
166 static HRESULT WINAPI parseError_get_errorCode(
167     IXMLDOMParseError *iface,
168     LONG *code )
169 {
170     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
171     TRACE("(%p)->(%p)\n", This, code);
172
173     *code = This->code;
174
175     if(This->code == 0)
176         return S_FALSE;
177
178     return S_OK;
179 }
180
181 static HRESULT WINAPI parseError_get_url(
182     IXMLDOMParseError *iface,
183     BSTR *url )
184 {
185     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
186     FIXME("(%p)->(%p)\n", This, url);
187     return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI parseError_get_reason(
191     IXMLDOMParseError *iface,
192     BSTR *reason )
193 {
194     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
195     TRACE("(%p)->(%p)\n", This, reason);
196     
197     if(!This->reason)
198     {
199         *reason = NULL;
200         return S_FALSE;
201     }
202     *reason = SysAllocString(This->reason);
203     return S_OK;
204 }
205
206 static HRESULT WINAPI parseError_get_srcText(
207     IXMLDOMParseError *iface,
208     BSTR *srcText )
209 {
210     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
211
212     TRACE("(%p)->(%p)\n", This, srcText);
213
214     if (!srcText) return E_INVALIDARG;
215
216     *srcText = SysAllocString(This->srcText);
217
218     return S_OK;
219 }
220
221 static HRESULT WINAPI parseError_get_line(
222     IXMLDOMParseError *iface,
223     LONG *line )
224 {
225     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
226
227     TRACE("(%p)->(%p): stub\n", This, line);
228
229     if (!line) return E_INVALIDARG;
230
231     *line = This->line;
232     return S_OK;
233 }
234
235 static HRESULT WINAPI parseError_get_linepos(
236     IXMLDOMParseError *iface,
237     LONG *linepos )
238 {
239     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
240
241     TRACE("(%p)->(%p)\n", This, linepos);
242
243     if (!linepos) return E_INVALIDARG;
244
245     *linepos = This->linepos;
246     return S_OK;
247 }
248
249 static HRESULT WINAPI parseError_get_filepos(
250     IXMLDOMParseError *iface,
251     LONG *filepos )
252 {
253     parse_error_t *This = impl_from_IXMLDOMParseError( iface );
254     FIXME("(%p)->(%p)\n", This, filepos);
255     return E_NOTIMPL;
256 }
257
258 static const struct IXMLDOMParseErrorVtbl parseError_vtbl =
259 {
260     parseError_QueryInterface,
261     parseError_AddRef,
262     parseError_Release,
263     parseError_GetTypeInfoCount,
264     parseError_GetTypeInfo,
265     parseError_GetIDsOfNames,
266     parseError_Invoke,
267     parseError_get_errorCode,
268     parseError_get_url,
269     parseError_get_reason,
270     parseError_get_srcText,
271     parseError_get_line,
272     parseError_get_linepos,
273     parseError_get_filepos
274 };
275
276 static const tid_t parseError_iface_tids[] = {
277     IXMLDOMParseError_tid,
278     0
279 };
280
281 static dispex_static_data_t parseError_dispex = {
282     NULL,
283     IXMLDOMParseError_tid,
284     NULL,
285     parseError_iface_tids
286 };
287
288 IXMLDOMParseError *create_parseError( LONG code, BSTR url, BSTR reason, BSTR srcText,
289                                       LONG line, LONG linepos, LONG filepos )
290 {
291     parse_error_t *This;
292
293     This = heap_alloc( sizeof(*This) );
294     if ( !This )
295         return NULL;
296
297     This->IXMLDOMParseError_iface.lpVtbl = &parseError_vtbl;
298     This->ref = 1;
299
300     This->code = code;
301     This->url = url;
302     This->reason = reason;
303     This->srcText = srcText;
304     This->line = line;
305     This->linepos = linepos;
306     This->filepos = filepos;
307
308     init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMParseError_iface, &parseError_dispex);
309
310     return &This->IXMLDOMParseError_iface;
311 }