mshtml: Remove an extra quote in the pngfile registration.
[wine] / dlls / mshtml / htmltextarea.c
1 /*
2  * Copyright 2006 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "wine/debug.h"
29
30 #include "mshtml_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
33
34 typedef struct {
35     HTMLElement element;
36
37     IHTMLTextAreaElement IHTMLTextAreaElement_iface;
38
39     nsIDOMHTMLTextAreaElement *nstextarea;
40 } HTMLTextAreaElement;
41
42 static inline HTMLTextAreaElement *impl_from_IHTMLTextAreaElement(IHTMLTextAreaElement *iface)
43 {
44     return CONTAINING_RECORD(iface, HTMLTextAreaElement, IHTMLTextAreaElement_iface);
45 }
46
47 static HRESULT WINAPI HTMLTextAreaElement_QueryInterface(IHTMLTextAreaElement *iface,
48                                                          REFIID riid, void **ppv)
49 {
50     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
51
52     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
53 }
54
55 static ULONG WINAPI HTMLTextAreaElement_AddRef(IHTMLTextAreaElement *iface)
56 {
57     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
58
59     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
60 }
61
62 static ULONG WINAPI HTMLTextAreaElement_Release(IHTMLTextAreaElement *iface)
63 {
64     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
65
66     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
67 }
68
69 static HRESULT WINAPI HTMLTextAreaElement_GetTypeInfoCount(IHTMLTextAreaElement *iface, UINT *pctinfo)
70 {
71     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
72     return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
73 }
74
75 static HRESULT WINAPI HTMLTextAreaElement_GetTypeInfo(IHTMLTextAreaElement *iface, UINT iTInfo,
76                                               LCID lcid, ITypeInfo **ppTInfo)
77 {
78     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
79     return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
80             ppTInfo);
81 }
82
83 static HRESULT WINAPI HTMLTextAreaElement_GetIDsOfNames(IHTMLTextAreaElement *iface, REFIID riid,
84                                                 LPOLESTR *rgszNames, UINT cNames,
85                                                 LCID lcid, DISPID *rgDispId)
86 {
87     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
88     return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
89             cNames, lcid, rgDispId);
90 }
91
92 static HRESULT WINAPI HTMLTextAreaElement_Invoke(IHTMLTextAreaElement *iface, DISPID dispIdMember,
93                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
94                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
95 {
96     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
97     return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
98             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
99 }
100
101 static HRESULT WINAPI HTMLTextAreaElement_get_type(IHTMLTextAreaElement *iface, BSTR *p)
102 {
103     static const WCHAR textareaW[] = {'t','e','x','t','a','r','e','a',0};
104
105     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
106
107     TRACE("(%p)->(%p)\n", This, p);
108
109     *p = SysAllocString(textareaW);
110     if(!*p)
111         return E_OUTOFMEMORY;
112     return S_OK;
113 }
114
115 static HRESULT WINAPI HTMLTextAreaElement_put_value(IHTMLTextAreaElement *iface, BSTR v)
116 {
117     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
118     nsAString value_str;
119     nsresult nsres;
120
121     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
122
123     nsAString_InitDepend(&value_str, v);
124     nsres = nsIDOMHTMLTextAreaElement_SetValue(This->nstextarea, &value_str);
125     nsAString_Finish(&value_str);
126     if(NS_FAILED(nsres)) {
127         ERR("SetValue failed: %08x\n", nsres);
128         return E_FAIL;
129     }
130
131     return S_OK;
132 }
133
134 static HRESULT WINAPI HTMLTextAreaElement_get_value(IHTMLTextAreaElement *iface, BSTR *p)
135 {
136     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
137     nsAString value_str;
138     const PRUnichar *value;
139     nsresult nsres;
140     HRESULT hres = S_OK;
141
142     TRACE("(%p)->(%p)\n", This, p);
143
144     nsAString_Init(&value_str, NULL);
145
146     nsres = nsIDOMHTMLTextAreaElement_GetValue(This->nstextarea, &value_str);
147     if(NS_SUCCEEDED(nsres)) {
148         nsAString_GetData(&value_str, &value);
149         *p = *value ? SysAllocString(value) : NULL;
150     }else {
151         ERR("GetValue failed: %08x\n", nsres);
152         hres = E_FAIL;
153     }
154
155     nsAString_Finish(&value_str);
156     return hres;
157 }
158
159 static HRESULT WINAPI HTMLTextAreaElement_put_name(IHTMLTextAreaElement *iface, BSTR v)
160 {
161     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
162     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
163     return E_NOTIMPL;
164 }
165
166 static HRESULT WINAPI HTMLTextAreaElement_get_name(IHTMLTextAreaElement *iface, BSTR *p)
167 {
168     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
169     nsAString name_str;
170     const PRUnichar *name;
171     nsresult nsres;
172
173     TRACE("(%p)->(%p)\n", This, p);
174
175     nsAString_Init(&name_str, NULL);
176
177     nsres = nsIDOMHTMLTextAreaElement_GetName(This->nstextarea, &name_str);
178     if(NS_SUCCEEDED(nsres)) {
179         nsAString_GetData(&name_str, &name);
180         *p = SysAllocString(name);
181     }else {
182         ERR("GetName failed: %08x\n", nsres);
183     }
184
185     nsAString_Finish(&name_str);
186
187     TRACE("%s\n", debugstr_w(*p));
188     return S_OK;
189 }
190
191 static HRESULT WINAPI HTMLTextAreaElement_put_status(IHTMLTextAreaElement *iface, VARIANT v)
192 {
193     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
194     FIXME("(%p)->()\n", This);
195     return E_NOTIMPL;
196 }
197
198 static HRESULT WINAPI HTMLTextAreaElement_get_status(IHTMLTextAreaElement *iface, VARIANT *p)
199 {
200     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
201     FIXME("(%p)->(%p)\n", This, p);
202     return E_NOTIMPL;
203 }
204
205 static HRESULT WINAPI HTMLTextAreaElement_put_disabled(IHTMLTextAreaElement *iface, VARIANT_BOOL v)
206 {
207     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
208     FIXME("(%p)->(%x)\n", This, v);
209     return E_NOTIMPL;
210 }
211
212 static HRESULT WINAPI HTMLTextAreaElement_get_disabled(IHTMLTextAreaElement *iface, VARIANT_BOOL *p)
213 {
214     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
215     FIXME("(%p)->(%p)\n", This, p);
216     return E_NOTIMPL;
217 }
218
219 static HRESULT WINAPI HTMLTextAreaElement_get_form(IHTMLTextAreaElement *iface, IHTMLFormElement **p)
220 {
221     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
222     FIXME("(%p)->(%p)\n", This, p);
223     return E_NOTIMPL;
224 }
225
226 static HRESULT WINAPI HTMLTextAreaElement_put_defaultValue(IHTMLTextAreaElement *iface, BSTR v)
227 {
228     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
229     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
230     return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI HTMLTextAreaElement_get_defaultValue(IHTMLTextAreaElement *iface, BSTR *p)
234 {
235     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
236     FIXME("(%p)->(%p)\n", This, p);
237     return E_NOTIMPL;
238 }
239
240 static HRESULT WINAPI HTMLTextAreaElement_select(IHTMLTextAreaElement *iface)
241 {
242     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
243     FIXME("(%p)\n", This);
244     return E_NOTIMPL;
245 }
246
247 static HRESULT WINAPI HTMLTextAreaElement_put_onchange(IHTMLTextAreaElement *iface, VARIANT v)
248 {
249     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
250     FIXME("(%p)->()\n", This);
251     return E_NOTIMPL;
252 }
253
254 static HRESULT WINAPI HTMLTextAreaElement_get_onchange(IHTMLTextAreaElement *iface, VARIANT *p)
255 {
256     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
257     FIXME("(%p)->(%p)\n", This, p);
258     return E_NOTIMPL;
259 }
260
261 static HRESULT WINAPI HTMLTextAreaElement_put_onselect(IHTMLTextAreaElement *iface, VARIANT v)
262 {
263     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
264     FIXME("(%p)->()\n", This);
265     return E_NOTIMPL;
266 }
267
268 static HRESULT WINAPI HTMLTextAreaElement_get_onselect(IHTMLTextAreaElement *iface, VARIANT *p)
269 {
270     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
271     FIXME("(%p)->(%p)\n", This, p);
272     return E_NOTIMPL;
273 }
274
275 static HRESULT WINAPI HTMLTextAreaElement_put_readOnly(IHTMLTextAreaElement *iface, VARIANT_BOOL v)
276 {
277     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
278     nsresult nsres;
279
280     TRACE("(%p)->(%x)\n", This, v);
281
282     nsres = nsIDOMHTMLTextAreaElement_SetReadOnly(This->nstextarea, v != VARIANT_FALSE);
283     if(NS_FAILED(nsres)) {
284         ERR("SetReadOnly failed: %08x\n", nsres);
285         return E_FAIL;
286     }
287
288     return S_OK;
289 }
290
291 static HRESULT WINAPI HTMLTextAreaElement_get_readOnly(IHTMLTextAreaElement *iface, VARIANT_BOOL *p)
292 {
293     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
294     PRBool b;
295     nsresult nsres;
296
297     TRACE("(%p)->(%p)\n", This, p);
298
299     nsres = nsIDOMHTMLTextAreaElement_GetReadOnly(This->nstextarea, &b);
300     if(NS_FAILED(nsres)) {
301         ERR("GetReadOnly failed: %08x\n", nsres);
302         return E_FAIL;
303     }
304
305     *p = b ? VARIANT_TRUE : VARIANT_FALSE;
306     return S_OK;
307 }
308
309 static HRESULT WINAPI HTMLTextAreaElement_put_rows(IHTMLTextAreaElement *iface, LONG v)
310 {
311     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
312     FIXME("(%p)->(%d)\n", This, v);
313     return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI HTMLTextAreaElement_get_rows(IHTMLTextAreaElement *iface, LONG *p)
317 {
318     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
319     FIXME("(%p)->(%p)\n", This, p);
320     return E_NOTIMPL;
321 }
322
323 static HRESULT WINAPI HTMLTextAreaElement_put_cols(IHTMLTextAreaElement *iface, LONG v)
324 {
325     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
326     FIXME("(%p)->(%d)\n", This, v);
327     return E_NOTIMPL;
328 }
329
330 static HRESULT WINAPI HTMLTextAreaElement_get_cols(IHTMLTextAreaElement *iface, LONG *p)
331 {
332     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
333     FIXME("(%p)->(%p)\n", This, p);
334     return E_NOTIMPL;
335 }
336
337 static HRESULT WINAPI HTMLTextAreaElement_put_wrap(IHTMLTextAreaElement *iface, BSTR v)
338 {
339     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
340     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
341     return E_NOTIMPL;
342 }
343
344 static HRESULT WINAPI HTMLTextAreaElement_get_wrap(IHTMLTextAreaElement *iface, BSTR *p)
345 {
346     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
347     FIXME("(%p)->(%p)\n", This, p);
348     return E_NOTIMPL;
349 }
350
351 static HRESULT WINAPI HTMLTextAreaElement_createTextRange(IHTMLTextAreaElement *iface,
352                                                           IHTMLTxtRange **range)
353 {
354     HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
355     FIXME("(%p)->(%p)\n", This, range);
356     return E_NOTIMPL;
357 }
358
359 static const IHTMLTextAreaElementVtbl HTMLTextAreaElementVtbl = {
360     HTMLTextAreaElement_QueryInterface,
361     HTMLTextAreaElement_AddRef,
362     HTMLTextAreaElement_Release,
363     HTMLTextAreaElement_GetTypeInfoCount,
364     HTMLTextAreaElement_GetTypeInfo,
365     HTMLTextAreaElement_GetIDsOfNames,
366     HTMLTextAreaElement_Invoke,
367     HTMLTextAreaElement_get_type,
368     HTMLTextAreaElement_put_value,
369     HTMLTextAreaElement_get_value,
370     HTMLTextAreaElement_put_name,
371     HTMLTextAreaElement_get_name,
372     HTMLTextAreaElement_put_status,
373     HTMLTextAreaElement_get_status,
374     HTMLTextAreaElement_put_disabled,
375     HTMLTextAreaElement_get_disabled,
376     HTMLTextAreaElement_get_form,
377     HTMLTextAreaElement_put_defaultValue,
378     HTMLTextAreaElement_get_defaultValue,
379     HTMLTextAreaElement_select,
380     HTMLTextAreaElement_put_onchange,
381     HTMLTextAreaElement_get_onchange,
382     HTMLTextAreaElement_put_onselect,
383     HTMLTextAreaElement_get_onselect,
384     HTMLTextAreaElement_put_readOnly,
385     HTMLTextAreaElement_get_readOnly,
386     HTMLTextAreaElement_put_rows,
387     HTMLTextAreaElement_get_rows,
388     HTMLTextAreaElement_put_cols,
389     HTMLTextAreaElement_get_cols,
390     HTMLTextAreaElement_put_wrap,
391     HTMLTextAreaElement_get_wrap,
392     HTMLTextAreaElement_createTextRange
393 };
394
395 static inline HTMLTextAreaElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
396 {
397     return CONTAINING_RECORD(iface, HTMLTextAreaElement, element.node);
398 }
399
400 static HRESULT HTMLTextAreaElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
401 {
402     HTMLTextAreaElement *This = impl_from_HTMLDOMNode(iface);
403
404     *ppv = NULL;
405
406     if(IsEqualGUID(&IID_IUnknown, riid)) {
407         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
408         *ppv = &This->IHTMLTextAreaElement_iface;
409     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
410         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
411         *ppv = &This->IHTMLTextAreaElement_iface;
412     }else if(IsEqualGUID(&IID_IHTMLTextAreaElement, riid)) {
413         TRACE("(%p)->(IID_IHTMLTextAreaElement %p)\n", This, ppv);
414         *ppv = &This->IHTMLTextAreaElement_iface;
415     }
416
417     if(*ppv) {
418         IUnknown_AddRef((IUnknown*)*ppv);
419         return S_OK;
420     }
421
422     return HTMLElement_QI(&This->element.node, riid, ppv);
423 }
424
425 static void HTMLTextAreaElement_destructor(HTMLDOMNode *iface)
426 {
427     HTMLTextAreaElement *This = impl_from_HTMLDOMNode(iface);
428
429     nsIDOMHTMLTextAreaElement_Release(This->nstextarea);
430
431     HTMLElement_destructor(&This->element.node);
432 }
433
434 static HRESULT HTMLTextAreaElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
435 {
436     HTMLTextAreaElement *This = impl_from_HTMLDOMNode(iface);
437     return IHTMLTextAreaElement_put_disabled(&This->IHTMLTextAreaElement_iface, v);
438 }
439
440 static HRESULT HTMLTextAreaElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
441 {
442     HTMLTextAreaElement *This = impl_from_HTMLDOMNode(iface);
443     return IHTMLTextAreaElement_get_disabled(&This->IHTMLTextAreaElement_iface, p);
444 }
445
446 static const NodeImplVtbl HTMLTextAreaElementImplVtbl = {
447     HTMLTextAreaElement_QI,
448     HTMLTextAreaElement_destructor,
449     HTMLElement_clone,
450     NULL,
451     NULL,
452     HTMLTextAreaElementImpl_put_disabled,
453     HTMLTextAreaElementImpl_get_disabled
454 };
455
456 static const tid_t HTMLTextAreaElement_iface_tids[] = {
457     HTMLELEMENT_TIDS,
458     IHTMLTextAreaElement_tid,
459     0
460 };
461
462 static dispex_static_data_t HTMLTextAreaElement_dispex = {
463     NULL,
464     DispHTMLTextAreaElement_tid,
465     NULL,
466     HTMLTextAreaElement_iface_tids
467 };
468
469 HRESULT HTMLTextAreaElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
470 {
471     HTMLTextAreaElement *ret;
472     nsresult nsres;
473
474     ret = heap_alloc_zero(sizeof(HTMLTextAreaElement));
475     if(!ret)
476         return E_OUTOFMEMORY;
477
478     ret->IHTMLTextAreaElement_iface.lpVtbl = &HTMLTextAreaElementVtbl;
479     ret->element.node.vtbl = &HTMLTextAreaElementImplVtbl;
480
481     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLTextAreaElement,
482                                              (void**)&ret->nstextarea);
483     if(NS_FAILED(nsres)) {
484         ERR("Could not get nsDOMHTMLInputElement: %08x\n", nsres);
485         heap_free(ret);
486         return E_FAIL;
487     }
488
489     HTMLElement_Init(&ret->element, doc, nselem, &HTMLTextAreaElement_dispex);
490
491     *elem = &ret->element;
492     return S_OK;
493 }