ddrawex/tests: Don't crash on some Win98/WinMe boxes.
[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     const IHTMLTextAreaElementVtbl *lpHTMLTextAreaElementVtbl;
38
39     nsIDOMHTMLTextAreaElement *nstextarea;
40 } HTMLTextAreaElement;
41
42 #define HTMLTXTAREA(x)  ((IHTMLTextAreaElement*)  &(x)->lpHTMLTextAreaElementVtbl)
43
44 #define HTMLTXTAREA_THIS(iface) DEFINE_THIS(HTMLTextAreaElement, HTMLTextAreaElement, iface)
45
46 static HRESULT WINAPI HTMLTextAreaElement_QueryInterface(IHTMLTextAreaElement *iface,
47                                                          REFIID riid, void **ppv)
48 {
49     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
50
51     return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
52 }
53
54 static ULONG WINAPI HTMLTextAreaElement_AddRef(IHTMLTextAreaElement *iface)
55 {
56     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
57
58     return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
59 }
60
61 static ULONG WINAPI HTMLTextAreaElement_Release(IHTMLTextAreaElement *iface)
62 {
63     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
64
65     return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
66 }
67
68 static HRESULT WINAPI HTMLTextAreaElement_GetTypeInfoCount(IHTMLTextAreaElement *iface, UINT *pctinfo)
69 {
70     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
71     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
72 }
73
74 static HRESULT WINAPI HTMLTextAreaElement_GetTypeInfo(IHTMLTextAreaElement *iface, UINT iTInfo,
75                                               LCID lcid, ITypeInfo **ppTInfo)
76 {
77     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
78     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
79 }
80
81 static HRESULT WINAPI HTMLTextAreaElement_GetIDsOfNames(IHTMLTextAreaElement *iface, REFIID riid,
82                                                 LPOLESTR *rgszNames, UINT cNames,
83                                                 LCID lcid, DISPID *rgDispId)
84 {
85     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
86     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
87 }
88
89 static HRESULT WINAPI HTMLTextAreaElement_Invoke(IHTMLTextAreaElement *iface, DISPID dispIdMember,
90                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
91                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
92 {
93     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
94     return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
95             pVarResult, pExcepInfo, puArgErr);
96 }
97
98 static HRESULT WINAPI HTMLTextAreaElement_get_type(IHTMLTextAreaElement *iface, BSTR *p)
99 {
100     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
101     FIXME("(%p)->(%p)\n", This, p);
102     return E_NOTIMPL;
103 }
104
105 static HRESULT WINAPI HTMLTextAreaElement_put_value(IHTMLTextAreaElement *iface, BSTR v)
106 {
107     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
108     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
109     return E_NOTIMPL;
110 }
111
112 static HRESULT WINAPI HTMLTextAreaElement_get_value(IHTMLTextAreaElement *iface, BSTR *p)
113 {
114     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
115     nsAString value_str;
116     const PRUnichar *value;
117     nsresult nsres;
118
119     TRACE("(%p)->(%p)\n", This, p);
120
121     nsAString_Init(&value_str, NULL);
122
123     nsres = nsIDOMHTMLTextAreaElement_GetValue(This->nstextarea, &value_str);
124     if(NS_SUCCEEDED(nsres)) {
125         nsAString_GetData(&value_str, &value);
126         *p = SysAllocString(value);
127     }else {
128         ERR("GetValue failed: %08x\n", nsres);
129     }
130
131     nsAString_Finish(&value_str);
132
133     TRACE("%s\n", debugstr_w(*p));
134     return S_OK;
135 }
136
137 static HRESULT WINAPI HTMLTextAreaElement_put_name(IHTMLTextAreaElement *iface, BSTR v)
138 {
139     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
140     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
141     return E_NOTIMPL;
142 }
143
144 static HRESULT WINAPI HTMLTextAreaElement_get_name(IHTMLTextAreaElement *iface, BSTR *p)
145 {
146     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
147     nsAString name_str;
148     const PRUnichar *name;
149     nsresult nsres;
150
151     TRACE("(%p)->(%p)\n", This, p);
152
153     nsAString_Init(&name_str, NULL);
154
155     nsres = nsIDOMHTMLTextAreaElement_GetName(This->nstextarea, &name_str);
156     if(NS_SUCCEEDED(nsres)) {
157         nsAString_GetData(&name_str, &name);
158         *p = SysAllocString(name);
159     }else {
160         ERR("GetName failed: %08x\n", nsres);
161     }
162
163     nsAString_Finish(&name_str);
164
165     TRACE("%s\n", debugstr_w(*p));
166     return S_OK;
167 }
168
169 static HRESULT WINAPI HTMLTextAreaElement_put_status(IHTMLTextAreaElement *iface, VARIANT v)
170 {
171     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
172     FIXME("(%p)->()\n", This);
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI HTMLTextAreaElement_get_status(IHTMLTextAreaElement *iface, VARIANT *p)
177 {
178     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
179     FIXME("(%p)->(%p)\n", This, p);
180     return E_NOTIMPL;
181 }
182
183 static HRESULT WINAPI HTMLTextAreaElement_put_disabled(IHTMLTextAreaElement *iface, VARIANT_BOOL v)
184 {
185     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
186     FIXME("(%p)->(%x)\n", This, v);
187     return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI HTMLTextAreaElement_get_disabled(IHTMLTextAreaElement *iface, VARIANT_BOOL *p)
191 {
192     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
193     FIXME("(%p)->(%p)\n", This, p);
194     return E_NOTIMPL;
195 }
196
197 static HRESULT WINAPI HTMLTextAreaElement_get_form(IHTMLTextAreaElement *iface, IHTMLFormElement **p)
198 {
199     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
200     FIXME("(%p)->(%p)\n", This, p);
201     return E_NOTIMPL;
202 }
203
204 static HRESULT WINAPI HTMLTextAreaElement_put_defaultValue(IHTMLTextAreaElement *iface, BSTR v)
205 {
206     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
207     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
208     return E_NOTIMPL;
209 }
210
211 static HRESULT WINAPI HTMLTextAreaElement_get_defaultValue(IHTMLTextAreaElement *iface, BSTR *p)
212 {
213     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
214     FIXME("(%p)->(%p)\n", This, p);
215     return E_NOTIMPL;
216 }
217
218 static HRESULT WINAPI HTMLTextAreaElement_select(IHTMLTextAreaElement *iface)
219 {
220     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
221     FIXME("(%p)\n", This);
222     return E_NOTIMPL;
223 }
224
225 static HRESULT WINAPI HTMLTextAreaElement_put_onchange(IHTMLTextAreaElement *iface, VARIANT v)
226 {
227     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
228     FIXME("(%p)->()\n", This);
229     return E_NOTIMPL;
230 }
231
232 static HRESULT WINAPI HTMLTextAreaElement_get_onchange(IHTMLTextAreaElement *iface, VARIANT *p)
233 {
234     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
235     FIXME("(%p)->(%p)\n", This, p);
236     return E_NOTIMPL;
237 }
238
239 static HRESULT WINAPI HTMLTextAreaElement_put_onselect(IHTMLTextAreaElement *iface, VARIANT v)
240 {
241     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
242     FIXME("(%p)->()\n", This);
243     return E_NOTIMPL;
244 }
245
246 static HRESULT WINAPI HTMLTextAreaElement_get_onselect(IHTMLTextAreaElement *iface, VARIANT *p)
247 {
248     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
249     FIXME("(%p)->(%p)\n", This, p);
250     return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI HTMLTextAreaElement_put_readOnly(IHTMLTextAreaElement *iface, VARIANT_BOOL v)
254 {
255     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
256     FIXME("(%p)->(%x)\n", This, v);
257     return E_NOTIMPL;
258 }
259
260 static HRESULT WINAPI HTMLTextAreaElement_get_readOnly(IHTMLTextAreaElement *iface, VARIANT_BOOL *p)
261 {
262     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
263     FIXME("(%p)->(%p)\n", This, p);
264     return E_NOTIMPL;
265 }
266
267 static HRESULT WINAPI HTMLTextAreaElement_put_rows(IHTMLTextAreaElement *iface, LONG v)
268 {
269     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
270     FIXME("(%p)->(%d)\n", This, v);
271     return E_NOTIMPL;
272 }
273
274 static HRESULT WINAPI HTMLTextAreaElement_get_rows(IHTMLTextAreaElement *iface, LONG *p)
275 {
276     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
277     FIXME("(%p)->(%p)\n", This, p);
278     return E_NOTIMPL;
279 }
280
281 static HRESULT WINAPI HTMLTextAreaElement_put_cols(IHTMLTextAreaElement *iface, LONG v)
282 {
283     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
284     FIXME("(%p)->(%d)\n", This, v);
285     return E_NOTIMPL;
286 }
287
288 static HRESULT WINAPI HTMLTextAreaElement_get_cols(IHTMLTextAreaElement *iface, LONG *p)
289 {
290     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
291     FIXME("(%p)->(%p)\n", This, p);
292     return E_NOTIMPL;
293 }
294
295 static HRESULT WINAPI HTMLTextAreaElement_put_wrap(IHTMLTextAreaElement *iface, BSTR v)
296 {
297     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
298     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
299     return E_NOTIMPL;
300 }
301
302 static HRESULT WINAPI HTMLTextAreaElement_get_wrap(IHTMLTextAreaElement *iface, BSTR *p)
303 {
304     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
305     FIXME("(%p)->(%p)\n", This, p);
306     return E_NOTIMPL;
307 }
308
309 static HRESULT WINAPI HTMLTextAreaElement_createTextRange(IHTMLTextAreaElement *iface,
310                                                           IHTMLTxtRange **range)
311 {
312     HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
313     FIXME("(%p)->(%p)\n", This, range);
314     return E_NOTIMPL;
315 }
316
317 #undef HTMLTXTAREA_THIS
318
319 static const IHTMLTextAreaElementVtbl HTMLTextAreaElementVtbl = {
320     HTMLTextAreaElement_QueryInterface,
321     HTMLTextAreaElement_AddRef,
322     HTMLTextAreaElement_Release,
323     HTMLTextAreaElement_GetTypeInfoCount,
324     HTMLTextAreaElement_GetTypeInfo,
325     HTMLTextAreaElement_GetIDsOfNames,
326     HTMLTextAreaElement_Invoke,
327     HTMLTextAreaElement_get_type,
328     HTMLTextAreaElement_put_value,
329     HTMLTextAreaElement_get_value,
330     HTMLTextAreaElement_put_name,
331     HTMLTextAreaElement_get_name,
332     HTMLTextAreaElement_put_status,
333     HTMLTextAreaElement_get_status,
334     HTMLTextAreaElement_put_disabled,
335     HTMLTextAreaElement_get_disabled,
336     HTMLTextAreaElement_get_form,
337     HTMLTextAreaElement_put_defaultValue,
338     HTMLTextAreaElement_get_defaultValue,
339     HTMLTextAreaElement_select,
340     HTMLTextAreaElement_put_onchange,
341     HTMLTextAreaElement_get_onchange,
342     HTMLTextAreaElement_put_onselect,
343     HTMLTextAreaElement_get_onselect,
344     HTMLTextAreaElement_put_readOnly,
345     HTMLTextAreaElement_get_readOnly,
346     HTMLTextAreaElement_put_rows,
347     HTMLTextAreaElement_get_rows,
348     HTMLTextAreaElement_put_cols,
349     HTMLTextAreaElement_get_cols,
350     HTMLTextAreaElement_put_wrap,
351     HTMLTextAreaElement_get_wrap,
352     HTMLTextAreaElement_createTextRange
353 };
354
355 #define HTMLTXTAREA_NODE_THIS(iface) DEFINE_THIS2(HTMLTextAreaElement, element.node, iface)
356
357 static HRESULT HTMLTextAreaElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
358 {
359     HTMLTextAreaElement *This = HTMLTXTAREA_NODE_THIS(iface);
360
361     *ppv = NULL;
362
363     if(IsEqualGUID(&IID_IUnknown, riid)) {
364         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
365         *ppv = HTMLTXTAREA(This);
366     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
367         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
368         *ppv = HTMLTXTAREA(This);
369     }else if(IsEqualGUID(&IID_IHTMLTextAreaElement, riid)) {
370         TRACE("(%p)->(IID_IHTMLTextAreaElement %p)\n", This, ppv);
371         *ppv = HTMLTXTAREA(This);
372     }
373
374     if(*ppv) {
375         IUnknown_AddRef((IUnknown*)*ppv);
376         return S_OK;
377     }
378
379     return HTMLElement_QI(&This->element.node, riid, ppv);
380 }
381
382 static void HTMLTextAreaElement_destructor(HTMLDOMNode *iface)
383 {
384     HTMLTextAreaElement *This = HTMLTXTAREA_NODE_THIS(iface);
385
386     nsIDOMHTMLTextAreaElement_Release(This->nstextarea);
387
388     HTMLElement_destructor(&This->element.node);
389 }
390
391 static HRESULT HTMLTextAreaElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
392 {
393     HTMLTextAreaElement *This = HTMLTXTAREA_NODE_THIS(iface);
394     return IHTMLTextAreaElement_put_disabled(HTMLTXTAREA(This), v);
395 }
396
397 static HRESULT HTMLTextAreaElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
398 {
399     HTMLTextAreaElement *This = HTMLTXTAREA_NODE_THIS(iface);
400     return IHTMLTextAreaElement_get_disabled(HTMLTXTAREA(This), p);
401 }
402
403 #undef HTMLTXTAREA_NODE_THIS
404
405 static const NodeImplVtbl HTMLTextAreaElementImplVtbl = {
406     HTMLTextAreaElement_QI,
407     HTMLTextAreaElement_destructor,
408     NULL,
409     NULL,
410     HTMLTextAreaElementImpl_put_disabled,
411     HTMLTextAreaElementImpl_get_disabled
412 };
413
414 static const tid_t HTMLTextAreaElement_iface_tids[] = {
415     HTMLELEMENT_TIDS,
416     IHTMLTextAreaElement_tid,
417     0
418 };
419
420 static dispex_static_data_t HTMLTextAreaElement_dispex = {
421     NULL,
422     DispHTMLTextAreaElement_tid,
423     NULL,
424     HTMLTextAreaElement_iface_tids
425 };
426
427 HTMLElement *HTMLTextAreaElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
428 {
429     HTMLTextAreaElement *ret = heap_alloc_zero(sizeof(HTMLTextAreaElement));
430     nsresult nsres;
431
432     ret->lpHTMLTextAreaElementVtbl = &HTMLTextAreaElementVtbl;
433     ret->element.node.vtbl = &HTMLTextAreaElementImplVtbl;
434
435     HTMLElement_Init(&ret->element, doc, nselem, &HTMLTextAreaElement_dispex);
436
437     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLTextAreaElement,
438                                              (void**)&ret->nstextarea);
439     if(NS_FAILED(nsres))
440         ERR("Could not get nsDOMHTMLInputElement: %08x\n", nsres);
441
442     return &ret->element;
443 }