[CMAKE]
[reactos.git] / dll / win32 / 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 nsAString value_str;
109 nsresult nsres;
110
111 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
112
113 nsAString_InitDepend(&value_str, v);
114 nsres = nsIDOMHTMLTextAreaElement_SetValue(This->nstextarea, &value_str);
115 nsAString_Finish(&value_str);
116 if(NS_FAILED(nsres)) {
117 ERR("SetValue failed: %08x\n", nsres);
118 return E_FAIL;
119 }
120
121 return S_OK;
122 }
123
124 static HRESULT WINAPI HTMLTextAreaElement_get_value(IHTMLTextAreaElement *iface, BSTR *p)
125 {
126 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
127 nsAString value_str;
128 const PRUnichar *value;
129 nsresult nsres;
130 HRESULT hres = S_OK;
131
132 TRACE("(%p)->(%p)\n", This, p);
133
134 nsAString_Init(&value_str, NULL);
135
136 nsres = nsIDOMHTMLTextAreaElement_GetValue(This->nstextarea, &value_str);
137 if(NS_SUCCEEDED(nsres)) {
138 nsAString_GetData(&value_str, &value);
139 *p = *value ? SysAllocString(value) : NULL;
140 }else {
141 ERR("GetValue failed: %08x\n", nsres);
142 hres = E_FAIL;
143 }
144
145 nsAString_Finish(&value_str);
146 return hres;
147 }
148
149 static HRESULT WINAPI HTMLTextAreaElement_put_name(IHTMLTextAreaElement *iface, BSTR v)
150 {
151 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
152 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
153 return E_NOTIMPL;
154 }
155
156 static HRESULT WINAPI HTMLTextAreaElement_get_name(IHTMLTextAreaElement *iface, BSTR *p)
157 {
158 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
159 nsAString name_str;
160 const PRUnichar *name;
161 nsresult nsres;
162
163 TRACE("(%p)->(%p)\n", This, p);
164
165 nsAString_Init(&name_str, NULL);
166
167 nsres = nsIDOMHTMLTextAreaElement_GetName(This->nstextarea, &name_str);
168 if(NS_SUCCEEDED(nsres)) {
169 nsAString_GetData(&name_str, &name);
170 *p = SysAllocString(name);
171 }else {
172 ERR("GetName failed: %08x\n", nsres);
173 }
174
175 nsAString_Finish(&name_str);
176
177 TRACE("%s\n", debugstr_w(*p));
178 return S_OK;
179 }
180
181 static HRESULT WINAPI HTMLTextAreaElement_put_status(IHTMLTextAreaElement *iface, VARIANT v)
182 {
183 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
184 FIXME("(%p)->()\n", This);
185 return E_NOTIMPL;
186 }
187
188 static HRESULT WINAPI HTMLTextAreaElement_get_status(IHTMLTextAreaElement *iface, VARIANT *p)
189 {
190 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
191 FIXME("(%p)->(%p)\n", This, p);
192 return E_NOTIMPL;
193 }
194
195 static HRESULT WINAPI HTMLTextAreaElement_put_disabled(IHTMLTextAreaElement *iface, VARIANT_BOOL v)
196 {
197 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
198 FIXME("(%p)->(%x)\n", This, v);
199 return E_NOTIMPL;
200 }
201
202 static HRESULT WINAPI HTMLTextAreaElement_get_disabled(IHTMLTextAreaElement *iface, VARIANT_BOOL *p)
203 {
204 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
205 FIXME("(%p)->(%p)\n", This, p);
206 return E_NOTIMPL;
207 }
208
209 static HRESULT WINAPI HTMLTextAreaElement_get_form(IHTMLTextAreaElement *iface, IHTMLFormElement **p)
210 {
211 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
212 FIXME("(%p)->(%p)\n", This, p);
213 return E_NOTIMPL;
214 }
215
216 static HRESULT WINAPI HTMLTextAreaElement_put_defaultValue(IHTMLTextAreaElement *iface, BSTR v)
217 {
218 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
219 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
220 return E_NOTIMPL;
221 }
222
223 static HRESULT WINAPI HTMLTextAreaElement_get_defaultValue(IHTMLTextAreaElement *iface, BSTR *p)
224 {
225 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
226 FIXME("(%p)->(%p)\n", This, p);
227 return E_NOTIMPL;
228 }
229
230 static HRESULT WINAPI HTMLTextAreaElement_select(IHTMLTextAreaElement *iface)
231 {
232 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
233 FIXME("(%p)\n", This);
234 return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI HTMLTextAreaElement_put_onchange(IHTMLTextAreaElement *iface, VARIANT v)
238 {
239 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
240 FIXME("(%p)->()\n", This);
241 return E_NOTIMPL;
242 }
243
244 static HRESULT WINAPI HTMLTextAreaElement_get_onchange(IHTMLTextAreaElement *iface, VARIANT *p)
245 {
246 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
247 FIXME("(%p)->(%p)\n", This, p);
248 return E_NOTIMPL;
249 }
250
251 static HRESULT WINAPI HTMLTextAreaElement_put_onselect(IHTMLTextAreaElement *iface, VARIANT v)
252 {
253 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
254 FIXME("(%p)->()\n", This);
255 return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI HTMLTextAreaElement_get_onselect(IHTMLTextAreaElement *iface, VARIANT *p)
259 {
260 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
261 FIXME("(%p)->(%p)\n", This, p);
262 return E_NOTIMPL;
263 }
264
265 static HRESULT WINAPI HTMLTextAreaElement_put_readOnly(IHTMLTextAreaElement *iface, VARIANT_BOOL v)
266 {
267 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
268 nsresult nsres;
269
270 TRACE("(%p)->(%x)\n", This, v);
271
272 nsres = nsIDOMHTMLTextAreaElement_SetReadOnly(This->nstextarea, v != VARIANT_FALSE);
273 if(NS_FAILED(nsres)) {
274 ERR("SetReadOnly failed: %08x\n", nsres);
275 return E_FAIL;
276 }
277
278 return S_OK;
279 }
280
281 static HRESULT WINAPI HTMLTextAreaElement_get_readOnly(IHTMLTextAreaElement *iface, VARIANT_BOOL *p)
282 {
283 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
284 PRBool b;
285 nsresult nsres;
286
287 TRACE("(%p)->(%p)\n", This, p);
288
289 nsres = nsIDOMHTMLTextAreaElement_GetReadOnly(This->nstextarea, &b);
290 if(NS_FAILED(nsres)) {
291 ERR("GetReadOnly failed: %08x\n", nsres);
292 return E_FAIL;
293 }
294
295 *p = b ? VARIANT_TRUE : VARIANT_FALSE;
296 return S_OK;
297 }
298
299 static HRESULT WINAPI HTMLTextAreaElement_put_rows(IHTMLTextAreaElement *iface, LONG v)
300 {
301 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
302 FIXME("(%p)->(%d)\n", This, v);
303 return E_NOTIMPL;
304 }
305
306 static HRESULT WINAPI HTMLTextAreaElement_get_rows(IHTMLTextAreaElement *iface, LONG *p)
307 {
308 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
309 FIXME("(%p)->(%p)\n", This, p);
310 return E_NOTIMPL;
311 }
312
313 static HRESULT WINAPI HTMLTextAreaElement_put_cols(IHTMLTextAreaElement *iface, LONG v)
314 {
315 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
316 FIXME("(%p)->(%d)\n", This, v);
317 return E_NOTIMPL;
318 }
319
320 static HRESULT WINAPI HTMLTextAreaElement_get_cols(IHTMLTextAreaElement *iface, LONG *p)
321 {
322 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
323 FIXME("(%p)->(%p)\n", This, p);
324 return E_NOTIMPL;
325 }
326
327 static HRESULT WINAPI HTMLTextAreaElement_put_wrap(IHTMLTextAreaElement *iface, BSTR v)
328 {
329 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
330 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
331 return E_NOTIMPL;
332 }
333
334 static HRESULT WINAPI HTMLTextAreaElement_get_wrap(IHTMLTextAreaElement *iface, BSTR *p)
335 {
336 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
337 FIXME("(%p)->(%p)\n", This, p);
338 return E_NOTIMPL;
339 }
340
341 static HRESULT WINAPI HTMLTextAreaElement_createTextRange(IHTMLTextAreaElement *iface,
342 IHTMLTxtRange **range)
343 {
344 HTMLTextAreaElement *This = HTMLTXTAREA_THIS(iface);
345 FIXME("(%p)->(%p)\n", This, range);
346 return E_NOTIMPL;
347 }
348
349 #undef HTMLTXTAREA_THIS
350
351 static const IHTMLTextAreaElementVtbl HTMLTextAreaElementVtbl = {
352 HTMLTextAreaElement_QueryInterface,
353 HTMLTextAreaElement_AddRef,
354 HTMLTextAreaElement_Release,
355 HTMLTextAreaElement_GetTypeInfoCount,
356 HTMLTextAreaElement_GetTypeInfo,
357 HTMLTextAreaElement_GetIDsOfNames,
358 HTMLTextAreaElement_Invoke,
359 HTMLTextAreaElement_get_type,
360 HTMLTextAreaElement_put_value,
361 HTMLTextAreaElement_get_value,
362 HTMLTextAreaElement_put_name,
363 HTMLTextAreaElement_get_name,
364 HTMLTextAreaElement_put_status,
365 HTMLTextAreaElement_get_status,
366 HTMLTextAreaElement_put_disabled,
367 HTMLTextAreaElement_get_disabled,
368 HTMLTextAreaElement_get_form,
369 HTMLTextAreaElement_put_defaultValue,
370 HTMLTextAreaElement_get_defaultValue,
371 HTMLTextAreaElement_select,
372 HTMLTextAreaElement_put_onchange,
373 HTMLTextAreaElement_get_onchange,
374 HTMLTextAreaElement_put_onselect,
375 HTMLTextAreaElement_get_onselect,
376 HTMLTextAreaElement_put_readOnly,
377 HTMLTextAreaElement_get_readOnly,
378 HTMLTextAreaElement_put_rows,
379 HTMLTextAreaElement_get_rows,
380 HTMLTextAreaElement_put_cols,
381 HTMLTextAreaElement_get_cols,
382 HTMLTextAreaElement_put_wrap,
383 HTMLTextAreaElement_get_wrap,
384 HTMLTextAreaElement_createTextRange
385 };
386
387 #define HTMLTXTAREA_NODE_THIS(iface) DEFINE_THIS2(HTMLTextAreaElement, element.node, iface)
388
389 static HRESULT HTMLTextAreaElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
390 {
391 HTMLTextAreaElement *This = HTMLTXTAREA_NODE_THIS(iface);
392
393 *ppv = NULL;
394
395 if(IsEqualGUID(&IID_IUnknown, riid)) {
396 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
397 *ppv = HTMLTXTAREA(This);
398 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
399 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
400 *ppv = HTMLTXTAREA(This);
401 }else if(IsEqualGUID(&IID_IHTMLTextAreaElement, riid)) {
402 TRACE("(%p)->(IID_IHTMLTextAreaElement %p)\n", This, ppv);
403 *ppv = HTMLTXTAREA(This);
404 }
405
406 if(*ppv) {
407 IUnknown_AddRef((IUnknown*)*ppv);
408 return S_OK;
409 }
410
411 return HTMLElement_QI(&This->element.node, riid, ppv);
412 }
413
414 static void HTMLTextAreaElement_destructor(HTMLDOMNode *iface)
415 {
416 HTMLTextAreaElement *This = HTMLTXTAREA_NODE_THIS(iface);
417
418 nsIDOMHTMLTextAreaElement_Release(This->nstextarea);
419
420 HTMLElement_destructor(&This->element.node);
421 }
422
423 static HRESULT HTMLTextAreaElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
424 {
425 HTMLTextAreaElement *This = HTMLTXTAREA_NODE_THIS(iface);
426 return IHTMLTextAreaElement_put_disabled(HTMLTXTAREA(This), v);
427 }
428
429 static HRESULT HTMLTextAreaElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
430 {
431 HTMLTextAreaElement *This = HTMLTXTAREA_NODE_THIS(iface);
432 return IHTMLTextAreaElement_get_disabled(HTMLTXTAREA(This), p);
433 }
434
435 #undef HTMLTXTAREA_NODE_THIS
436
437 static const NodeImplVtbl HTMLTextAreaElementImplVtbl = {
438 HTMLTextAreaElement_QI,
439 HTMLTextAreaElement_destructor,
440 NULL,
441 NULL,
442 HTMLTextAreaElementImpl_put_disabled,
443 HTMLTextAreaElementImpl_get_disabled
444 };
445
446 static const tid_t HTMLTextAreaElement_iface_tids[] = {
447 HTMLELEMENT_TIDS,
448 IHTMLTextAreaElement_tid,
449 0
450 };
451
452 static dispex_static_data_t HTMLTextAreaElement_dispex = {
453 NULL,
454 DispHTMLTextAreaElement_tid,
455 NULL,
456 HTMLTextAreaElement_iface_tids
457 };
458
459 HTMLElement *HTMLTextAreaElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
460 {
461 HTMLTextAreaElement *ret = heap_alloc_zero(sizeof(HTMLTextAreaElement));
462 nsresult nsres;
463
464 ret->lpHTMLTextAreaElementVtbl = &HTMLTextAreaElementVtbl;
465 ret->element.node.vtbl = &HTMLTextAreaElementImplVtbl;
466
467 HTMLElement_Init(&ret->element, doc, nselem, &HTMLTextAreaElement_dispex);
468
469 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLTextAreaElement,
470 (void**)&ret->nstextarea);
471 if(NS_FAILED(nsres))
472 ERR("Could not get nsDOMHTMLInputElement: %08x\n", nsres);
473
474 return &ret->element;
475 }