riched20/tests: Avoid using flaky method of simulating typing.
[wine] / dlls / xmllite / writer.c
1 /*
2  * IXmlWriter implementation
3  *
4  * Copyright 2011 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 #define COBJMACROS
21
22 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "xmllite.h"
27
28 #include "wine/debug.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(xmllite);
31
32 typedef struct _xmlwriter
33 {
34     IXmlWriter IXmlWriter_iface;
35     LONG ref;
36 } xmlwriter;
37
38 static inline xmlwriter *impl_from_IXmlWriter(IXmlWriter *iface)
39 {
40     return CONTAINING_RECORD(iface, xmlwriter, IXmlWriter_iface);
41 }
42
43 static HRESULT WINAPI xmlwriter_QueryInterface(IXmlWriter *iface, REFIID riid, void **ppvObject)
44 {
45     xmlwriter *This = impl_from_IXmlWriter(iface);
46
47     TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
48
49     if (IsEqualGUID(riid, &IID_IUnknown) ||
50         IsEqualGUID(riid, &IID_IXmlWriter))
51     {
52         *ppvObject = iface;
53     }
54
55     IXmlWriter_AddRef(iface);
56
57     return S_OK;
58 }
59
60 static ULONG WINAPI xmlwriter_AddRef(IXmlWriter *iface)
61 {
62     xmlwriter *This = impl_from_IXmlWriter(iface);
63     TRACE("%p\n", This);
64     return InterlockedIncrement(&This->ref);
65 }
66
67 static ULONG WINAPI xmlwriter_Release(IXmlWriter *iface)
68 {
69     xmlwriter *This = impl_from_IXmlWriter(iface);
70     LONG ref;
71
72     TRACE("%p\n", This);
73
74     ref = InterlockedDecrement(&This->ref);
75     if (ref == 0)
76     {
77         HeapFree(GetProcessHeap(), 0, This);
78     }
79
80     return ref;
81 }
82
83 /*** IXmlWriter methods ***/
84 static HRESULT WINAPI xmlwriter_SetOutput(IXmlWriter *iface, IUnknown *pOutput)
85 {
86     xmlwriter *This = impl_from_IXmlWriter(iface);
87
88     FIXME("%p %p\n", This, pOutput);
89
90     return E_NOTIMPL;
91 }
92
93 static HRESULT WINAPI xmlwriter_GetProperty(IXmlWriter *iface, UINT nProperty, LONG_PTR *ppValue)
94 {
95     xmlwriter *This = impl_from_IXmlWriter(iface);
96
97     FIXME("%p %u %p\n", This, nProperty, ppValue);
98
99     return E_NOTIMPL;
100 }
101
102 static HRESULT WINAPI xmlwriter_SetProperty(IXmlWriter *iface, UINT nProperty, LONG_PTR pValue)
103 {
104     xmlwriter *This = impl_from_IXmlWriter(iface);
105
106     FIXME("%p %u %lu\n", This, nProperty, pValue);
107
108     return E_NOTIMPL;
109 }
110
111 static HRESULT WINAPI xmlwriter_WriteAttributes(IXmlWriter *iface, IXmlReader *pReader,
112                                   BOOL fWriteDefaultAttributes)
113 {
114     xmlwriter *This = impl_from_IXmlWriter(iface);
115
116     FIXME("%p %p %d\n", This, pReader, fWriteDefaultAttributes);
117
118     return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR pwszPrefix,
122                                        LPCWSTR pwszLocalName, LPCWSTR pwszNamespaceUri,
123                                        LPCWSTR pwszValue)
124 {
125     xmlwriter *This = impl_from_IXmlWriter(iface);
126
127     FIXME("%p %s %s %s %s\n", This, wine_dbgstr_w(pwszPrefix), wine_dbgstr_w(pwszLocalName),
128                         wine_dbgstr_w(pwszNamespaceUri), wine_dbgstr_w(pwszValue));
129
130     return E_NOTIMPL;
131 }
132
133 static HRESULT WINAPI xmlwriter_WriteCData(IXmlWriter *iface, LPCWSTR pwszText)
134 {
135     xmlwriter *This = impl_from_IXmlWriter(iface);
136
137     FIXME("%p %s\n", This, wine_dbgstr_w(pwszText));
138
139     return E_NOTIMPL;
140 }
141
142 static HRESULT WINAPI xmlwriter_WriteCharEntity(IXmlWriter *iface, WCHAR wch)
143 {
144     return E_NOTIMPL;
145 }
146
147 static HRESULT WINAPI xmlwriter_WriteChars(IXmlWriter *iface, const WCHAR *pwch, UINT cwch)
148 {
149     xmlwriter *This = impl_from_IXmlWriter(iface);
150
151     FIXME("%p %s %d\n", This, wine_dbgstr_w(pwch), cwch);
152
153     return E_NOTIMPL;
154 }
155
156 static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR pwszComment)
157 {
158     return E_NOTIMPL;
159 }
160
161 static HRESULT WINAPI xmlwriter_WriteDocType(IXmlWriter *iface, LPCWSTR pwszName, LPCWSTR pwszPublicId,
162                                LPCWSTR pwszSystemId, LPCWSTR pwszSubset)
163 {
164     xmlwriter *This = impl_from_IXmlWriter(iface);
165
166     FIXME("%p %s %s %s %s\n", This, wine_dbgstr_w(pwszName), wine_dbgstr_w(pwszPublicId),
167                         wine_dbgstr_w(pwszSystemId), wine_dbgstr_w(pwszSubset));
168
169     return E_NOTIMPL;
170 }
171
172 static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pwszPrefix,
173                                      LPCWSTR pwszLocalName, LPCWSTR pwszNamespaceUri,
174                                      LPCWSTR pwszValue)
175 {
176     xmlwriter *This = impl_from_IXmlWriter(iface);
177
178     FIXME("%p %s %s %s %s\n", This, wine_dbgstr_w(pwszPrefix), wine_dbgstr_w(pwszLocalName),
179                         wine_dbgstr_w(pwszNamespaceUri), wine_dbgstr_w(pwszValue));
180
181     return E_NOTIMPL;
182 }
183
184 static HRESULT WINAPI xmlwriter_WriteEndDocument(IXmlWriter *iface)
185 {
186     xmlwriter *This = impl_from_IXmlWriter(iface);
187
188     FIXME("%p\n", This);
189
190     return E_NOTIMPL;
191 }
192
193 static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface)
194 {
195     xmlwriter *This = impl_from_IXmlWriter(iface);
196
197     FIXME("%p\n", This);
198
199     return E_NOTIMPL;
200 }
201
202 static HRESULT WINAPI xmlwriter_WriteEntityRef(IXmlWriter *iface, LPCWSTR pwszName)
203 {
204     xmlwriter *This = impl_from_IXmlWriter(iface);
205
206     FIXME("%p %s\n", This, wine_dbgstr_w(pwszName));
207
208     return E_NOTIMPL;
209 }
210
211 static HRESULT WINAPI xmlwriter_WriteFullEndElement(IXmlWriter *iface)
212 {
213     xmlwriter *This = impl_from_IXmlWriter(iface);
214
215     FIXME("%p\n", This);
216
217     return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI xmlwriter_WriteName(IXmlWriter *iface, LPCWSTR pwszName)
221 {
222     xmlwriter *This = impl_from_IXmlWriter(iface);
223
224     FIXME("%p %s\n", This, wine_dbgstr_w(pwszName));
225
226     return E_NOTIMPL;
227 }
228
229 static HRESULT WINAPI xmlwriter_WriteNmToken(IXmlWriter *iface, LPCWSTR pwszNmToken)
230 {
231     xmlwriter *This = impl_from_IXmlWriter(iface);
232
233     FIXME("%p %s\n", This, wine_dbgstr_w(pwszNmToken));
234
235     return E_NOTIMPL;
236 }
237
238 static HRESULT WINAPI xmlwriter_WriteNode(IXmlWriter *iface, IXmlReader *pReader,
239                             BOOL fWriteDefaultAttributes)
240 {
241     xmlwriter *This = impl_from_IXmlWriter(iface);
242
243     FIXME("%p %p %d\n", This, pReader, fWriteDefaultAttributes);
244
245     return E_NOTIMPL;
246 }
247
248 static HRESULT WINAPI xmlwriter_WriteNodeShallow(IXmlWriter *iface, IXmlReader *pReader,
249                                    BOOL fWriteDefaultAttributes)
250 {
251     xmlwriter *This = impl_from_IXmlWriter(iface);
252
253     FIXME("%p %p %d\n", This, pReader, fWriteDefaultAttributes);
254
255     return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LPCWSTR pwszName,
259                                              LPCWSTR pwszText)
260 {
261     xmlwriter *This = impl_from_IXmlWriter(iface);
262
263     FIXME("%p %s %s\n", This, wine_dbgstr_w(pwszName), wine_dbgstr_w(pwszText));
264
265     return E_NOTIMPL;
266 }
267
268 static HRESULT WINAPI xmlwriter_WriteQualifiedName(IXmlWriter *iface, LPCWSTR pwszLocalName,
269                                      LPCWSTR pwszNamespaceUri)
270 {
271     xmlwriter *This = impl_from_IXmlWriter(iface);
272
273     FIXME("%p %s %s\n", This, wine_dbgstr_w(pwszLocalName), wine_dbgstr_w(pwszNamespaceUri));
274
275     return E_NOTIMPL;
276 }
277
278 static HRESULT WINAPI xmlwriter_WriteRaw(IXmlWriter *iface, LPCWSTR pwszData)
279 {
280     xmlwriter *This = impl_from_IXmlWriter(iface);
281
282     FIXME("%p %s\n", This, wine_dbgstr_w(pwszData));
283
284     return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI xmlwriter_WriteRawChars(IXmlWriter *iface,  const WCHAR *pwch, UINT cwch)
288 {
289     xmlwriter *This = impl_from_IXmlWriter(iface);
290
291     FIXME("%p %s %d\n", This, wine_dbgstr_w(pwch), cwch);
292
293     return E_NOTIMPL;
294 }
295
296 static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandalone standalone)
297 {
298     xmlwriter *This = impl_from_IXmlWriter(iface);
299
300     FIXME("%p\n", This);
301
302     return E_NOTIMPL;
303 }
304
305 static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pwszPrefix,
306                                     LPCWSTR pwszLocalName, LPCWSTR pwszNamespaceUri)
307 {
308     xmlwriter *This = impl_from_IXmlWriter(iface);
309
310     FIXME("%p %s %s %s\n", This, wine_dbgstr_w(pwszPrefix), wine_dbgstr_w(pwszLocalName),
311                 wine_dbgstr_w(pwszNamespaceUri));
312
313     return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI xmlwriter_WriteString(IXmlWriter *iface, LPCWSTR pwszText)
317 {
318     xmlwriter *This = impl_from_IXmlWriter(iface);
319
320     FIXME("%p %s\n", This, wine_dbgstr_w(pwszText));
321
322     return E_NOTIMPL;
323 }
324
325 static HRESULT WINAPI xmlwriter_WriteSurrogateCharEntity(IXmlWriter *iface, WCHAR wchLow, WCHAR wchHigh)
326 {
327     xmlwriter *This = impl_from_IXmlWriter(iface);
328
329     FIXME("%p %d %d\n", This, wchLow, wchHigh);
330
331     return E_NOTIMPL;
332 }
333
334 static HRESULT WINAPI xmlwriter_WriteWhitespace(IXmlWriter *iface, LPCWSTR pwszWhitespace)
335 {
336     xmlwriter *This = impl_from_IXmlWriter(iface);
337
338     FIXME("%p %s\n", This, wine_dbgstr_w(pwszWhitespace));
339
340     return E_NOTIMPL;
341 }
342
343 static HRESULT WINAPI xmlwriter_Flush(IXmlWriter *iface)
344 {
345     xmlwriter *This = impl_from_IXmlWriter(iface);
346
347     FIXME("%p\n", This);
348
349     return E_NOTIMPL;
350 }
351
352 static const struct IXmlWriterVtbl xmlwriter_vtbl =
353 {
354     xmlwriter_QueryInterface,
355     xmlwriter_AddRef,
356     xmlwriter_Release,
357     xmlwriter_SetOutput,
358     xmlwriter_GetProperty,
359     xmlwriter_SetProperty,
360     xmlwriter_WriteAttributes,
361     xmlwriter_WriteAttributeString,
362     xmlwriter_WriteCData,
363     xmlwriter_WriteCharEntity,
364     xmlwriter_WriteChars,
365     xmlwriter_WriteComment,
366     xmlwriter_WriteDocType,
367     xmlwriter_WriteElementString,
368     xmlwriter_WriteEndDocument,
369     xmlwriter_WriteEndElement,
370     xmlwriter_WriteEntityRef,
371     xmlwriter_WriteFullEndElement,
372     xmlwriter_WriteName,
373     xmlwriter_WriteNmToken,
374     xmlwriter_WriteNode,
375     xmlwriter_WriteNodeShallow,
376     xmlwriter_WriteProcessingInstruction,
377     xmlwriter_WriteQualifiedName,
378     xmlwriter_WriteRaw,
379     xmlwriter_WriteRawChars,
380     xmlwriter_WriteStartDocument,
381     xmlwriter_WriteStartElement,
382     xmlwriter_WriteString,
383     xmlwriter_WriteSurrogateCharEntity,
384     xmlwriter_WriteWhitespace,
385     xmlwriter_Flush
386 };
387
388 HRESULT WINAPI CreateXmlWriter(REFIID riid, void **pObject, IMalloc *pMalloc)
389 {
390     xmlwriter *writer;
391
392     TRACE("(%s, %p, %p)\n", wine_dbgstr_guid(riid), pObject, pMalloc);
393
394     if (pMalloc) FIXME("custom IMalloc not supported yet\n");
395
396     if (!IsEqualGUID(riid, &IID_IXmlWriter))
397     {
398         ERR("Unexpected IID requested -> (%s)\n", wine_dbgstr_guid(riid));
399         return E_FAIL;
400     }
401
402     writer = HeapAlloc(GetProcessHeap(), 0, sizeof (*writer));
403     if(!writer) return E_OUTOFMEMORY;
404
405     writer->IXmlWriter_iface.lpVtbl = &xmlwriter_vtbl;
406     writer->ref = 1;
407
408     *pObject = &writer->IXmlWriter_iface;
409
410     TRACE("returning iface %p\n", *pObject);
411
412     return S_OK;
413 }