kernel32: Update Italian translation.
[wine/testsucceed.git] / dlls / mshtml / htmlform.c
blob8e169170a4b0dc63e1e54e88b57b6770c2974828
1 /*
2 * Copyright 2009 Andrew Eikum for CodeWeavers
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.
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.
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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 struct HTMLFormElement {
35 HTMLElement element;
37 const IHTMLFormElementVtbl *lpHTMLFormElementVtbl;
39 nsIDOMHTMLFormElement *nsform;
42 #define HTMLFORM(x) (&(x)->lpHTMLFormElementVtbl)
44 static HRESULT htmlform_item(HTMLFormElement *This, int i, IDispatch **ret)
46 nsIDOMHTMLCollection *elements;
47 nsIDOMNode *item;
48 HTMLDOMNode *node;
49 nsresult nsres;
51 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
52 if(NS_FAILED(nsres)) {
53 FIXME("GetElements failed: 0x%08x\n", nsres);
54 return E_FAIL;
57 nsres = nsIDOMHTMLCollection_Item(elements, i, &item);
58 nsIDOMHTMLCollection_Release(elements);
59 if(NS_FAILED(nsres)) {
60 FIXME("Item failed: 0x%08x\n", nsres);
61 return E_FAIL;
64 if(item) {
65 node = get_node(This->element.node.doc, item, TRUE);
66 if(!node)
67 return E_OUTOFMEMORY;
69 IHTMLDOMNode_AddRef(HTMLDOMNODE(node));
70 nsIDOMNode_Release(item);
71 *ret = (IDispatch*)HTMLDOMNODE(node);
72 }else {
73 *ret = NULL;
76 return S_OK;
79 #define HTMLFORM_THIS(iface) DEFINE_THIS(HTMLFormElement, HTMLFormElement, iface)
81 static HRESULT WINAPI HTMLFormElement_QueryInterface(IHTMLFormElement *iface,
82 REFIID riid, void **ppv)
84 HTMLFormElement *This = HTMLFORM_THIS(iface);
86 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
89 static ULONG WINAPI HTMLFormElement_AddRef(IHTMLFormElement *iface)
91 HTMLFormElement *This = HTMLFORM_THIS(iface);
93 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
96 static ULONG WINAPI HTMLFormElement_Release(IHTMLFormElement *iface)
98 HTMLFormElement *This = HTMLFORM_THIS(iface);
100 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
103 static HRESULT WINAPI HTMLFormElement_GetTypeInfoCount(IHTMLFormElement *iface, UINT *pctinfo)
105 HTMLFormElement *This = HTMLFORM_THIS(iface);
106 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
109 static HRESULT WINAPI HTMLFormElement_GetTypeInfo(IHTMLFormElement *iface, UINT iTInfo,
110 LCID lcid, ITypeInfo **ppTInfo)
112 HTMLFormElement *This = HTMLFORM_THIS(iface);
113 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
116 static HRESULT WINAPI HTMLFormElement_GetIDsOfNames(IHTMLFormElement *iface, REFIID riid,
117 LPOLESTR *rgszNames, UINT cNames,
118 LCID lcid, DISPID *rgDispId)
120 HTMLFormElement *This = HTMLFORM_THIS(iface);
121 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
124 static HRESULT WINAPI HTMLFormElement_Invoke(IHTMLFormElement *iface, DISPID dispIdMember,
125 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
126 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
128 HTMLFormElement *This = HTMLFORM_THIS(iface);
129 return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
130 pVarResult, pExcepInfo, puArgErr);
133 static HRESULT WINAPI HTMLFormElement_put_action(IHTMLFormElement *iface, BSTR v)
135 HTMLFormElement *This = HTMLFORM_THIS(iface);
136 nsAString action_str;
137 nsresult nsres;
139 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
141 nsAString_InitDepend(&action_str, v);
142 nsres = nsIDOMHTMLFormElement_SetAction(This->nsform, &action_str);
143 nsAString_Finish(&action_str);
144 if(NS_FAILED(nsres)) {
145 ERR("SetAction failed: %08x\n", nsres);
146 return E_FAIL;
149 return S_OK;
152 static HRESULT WINAPI HTMLFormElement_get_action(IHTMLFormElement *iface, BSTR *p)
154 HTMLFormElement *This = HTMLFORM_THIS(iface);
155 nsAString action_str;
156 nsresult nsres;
157 HRESULT hres;
159 TRACE("(%p)->(%p)\n", This, p);
161 nsAString_Init(&action_str, NULL);
162 nsres = nsIDOMHTMLFormElement_GetAction(This->nsform, &action_str);
163 if(NS_SUCCEEDED(nsres)) {
164 const PRUnichar *action;
165 nsAString_GetData(&action_str, &action);
166 hres = nsuri_to_url(action, FALSE, p);
167 }else {
168 ERR("GetAction failed: %08x\n", nsres);
169 hres = E_FAIL;
172 return hres;
175 static HRESULT WINAPI HTMLFormElement_put_dir(IHTMLFormElement *iface, BSTR v)
177 HTMLFormElement *This = HTMLFORM_THIS(iface);
178 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
179 return E_NOTIMPL;
182 static HRESULT WINAPI HTMLFormElement_get_dir(IHTMLFormElement *iface, BSTR *p)
184 HTMLFormElement *This = HTMLFORM_THIS(iface);
185 FIXME("(%p)->(%p)\n", This, p);
186 return E_NOTIMPL;
189 static HRESULT WINAPI HTMLFormElement_put_encoding(IHTMLFormElement *iface, BSTR v)
191 HTMLFormElement *This = HTMLFORM_THIS(iface);
192 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
193 return E_NOTIMPL;
196 static HRESULT WINAPI HTMLFormElement_get_encoding(IHTMLFormElement *iface, BSTR *p)
198 HTMLFormElement *This = HTMLFORM_THIS(iface);
199 FIXME("(%p)->(%p)\n", This, p);
200 return E_NOTIMPL;
203 static HRESULT WINAPI HTMLFormElement_put_method(IHTMLFormElement *iface, BSTR v)
205 HTMLFormElement *This = HTMLFORM_THIS(iface);
206 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
207 return E_NOTIMPL;
210 static HRESULT WINAPI HTMLFormElement_get_method(IHTMLFormElement *iface, BSTR *p)
212 HTMLFormElement *This = HTMLFORM_THIS(iface);
213 FIXME("(%p)->(%p)\n", This, p);
214 return E_NOTIMPL;
217 static HRESULT WINAPI HTMLFormElement_get_elements(IHTMLFormElement *iface, IDispatch **p)
219 HTMLFormElement *This = HTMLFORM_THIS(iface);
220 FIXME("(%p)->(%p)\n", This, p);
221 return E_NOTIMPL;
224 static HRESULT WINAPI HTMLFormElement_put_target(IHTMLFormElement *iface, BSTR v)
226 HTMLFormElement *This = HTMLFORM_THIS(iface);
227 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
228 return E_NOTIMPL;
231 static HRESULT WINAPI HTMLFormElement_get_target(IHTMLFormElement *iface, BSTR *p)
233 HTMLFormElement *This = HTMLFORM_THIS(iface);
234 FIXME("(%p)->(%p)\n", This, p);
235 return E_NOTIMPL;
238 static HRESULT WINAPI HTMLFormElement_put_name(IHTMLFormElement *iface, BSTR v)
240 HTMLFormElement *This = HTMLFORM_THIS(iface);
241 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
242 return E_NOTIMPL;
245 static HRESULT WINAPI HTMLFormElement_get_name(IHTMLFormElement *iface, BSTR *p)
247 HTMLFormElement *This = HTMLFORM_THIS(iface);
248 FIXME("(%p)->(%p)\n", This, p);
249 return E_NOTIMPL;
252 static HRESULT WINAPI HTMLFormElement_put_onsubmit(IHTMLFormElement *iface, VARIANT v)
254 HTMLFormElement *This = HTMLFORM_THIS(iface);
255 FIXME("(%p)->(v)\n", This);
256 return E_NOTIMPL;
259 static HRESULT WINAPI HTMLFormElement_get_onsubmit(IHTMLFormElement *iface, VARIANT *p)
261 HTMLFormElement *This = HTMLFORM_THIS(iface);
262 FIXME("(%p)->(%p)\n", This, p);
263 return E_NOTIMPL;
266 static HRESULT WINAPI HTMLFormElement_put_onreset(IHTMLFormElement *iface, VARIANT v)
268 HTMLFormElement *This = HTMLFORM_THIS(iface);
269 FIXME("(%p)->(v)\n", This);
270 return E_NOTIMPL;
273 static HRESULT WINAPI HTMLFormElement_get_onreset(IHTMLFormElement *iface, VARIANT *p)
275 HTMLFormElement *This = HTMLFORM_THIS(iface);
276 FIXME("(%p)->(%p)\n", This, p);
277 return E_NOTIMPL;
280 static HRESULT WINAPI HTMLFormElement_submit(IHTMLFormElement *iface)
282 HTMLFormElement *This = HTMLFORM_THIS(iface);
283 FIXME("(%p)->()\n", This);
284 return E_NOTIMPL;
287 static HRESULT WINAPI HTMLFormElement_reset(IHTMLFormElement *iface)
289 HTMLFormElement *This = HTMLFORM_THIS(iface);
290 FIXME("(%p)->()\n", This);
291 return E_NOTIMPL;
294 static HRESULT WINAPI HTMLFormElement_put_length(IHTMLFormElement *iface, LONG v)
296 HTMLFormElement *This = HTMLFORM_THIS(iface);
297 FIXME("(%p)->(%d)\n", This, v);
298 return E_NOTIMPL;
301 static HRESULT WINAPI HTMLFormElement_get_length(IHTMLFormElement *iface, LONG *p)
303 HTMLFormElement *This = HTMLFORM_THIS(iface);
304 PRInt32 length;
305 nsresult nsres;
307 TRACE("(%p)->(%p)\n", This, p);
309 nsres = nsIDOMHTMLFormElement_GetLength(This->nsform, &length);
310 if(NS_FAILED(nsres)) {
311 ERR("GetLength failed: %08x\n", nsres);
312 return E_FAIL;
315 *p = length;
316 return S_OK;
319 static HRESULT WINAPI HTMLFormElement__newEnum(IHTMLFormElement *iface, IUnknown **p)
321 HTMLFormElement *This = HTMLFORM_THIS(iface);
322 FIXME("(%p)->(%p)\n", This, p);
323 return E_NOTIMPL;
326 static HRESULT WINAPI HTMLFormElement_item(IHTMLFormElement *iface, VARIANT name,
327 VARIANT index, IDispatch **pdisp)
329 HTMLFormElement *This = HTMLFORM_THIS(iface);
331 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
333 if(!pdisp)
334 return E_INVALIDARG;
335 *pdisp = NULL;
337 if(V_VT(&name) == VT_I4) {
338 if(V_I4(&name) < 0)
339 return E_INVALIDARG;
340 return htmlform_item(This, V_I4(&name), pdisp);
343 FIXME("Unsupported args\n");
344 return E_NOTIMPL;
347 static HRESULT WINAPI HTMLFormElement_tags(IHTMLFormElement *iface, VARIANT tagName,
348 IDispatch **pdisp)
350 HTMLFormElement *This = HTMLFORM_THIS(iface);
351 FIXME("(%p)->(v %p)\n", This, pdisp);
352 return E_NOTIMPL;
355 #undef HTMLFORM_THIS
357 static const IHTMLFormElementVtbl HTMLFormElementVtbl = {
358 HTMLFormElement_QueryInterface,
359 HTMLFormElement_AddRef,
360 HTMLFormElement_Release,
361 HTMLFormElement_GetTypeInfoCount,
362 HTMLFormElement_GetTypeInfo,
363 HTMLFormElement_GetIDsOfNames,
364 HTMLFormElement_Invoke,
365 HTMLFormElement_put_action,
366 HTMLFormElement_get_action,
367 HTMLFormElement_put_dir,
368 HTMLFormElement_get_dir,
369 HTMLFormElement_put_encoding,
370 HTMLFormElement_get_encoding,
371 HTMLFormElement_put_method,
372 HTMLFormElement_get_method,
373 HTMLFormElement_get_elements,
374 HTMLFormElement_put_target,
375 HTMLFormElement_get_target,
376 HTMLFormElement_put_name,
377 HTMLFormElement_get_name,
378 HTMLFormElement_put_onsubmit,
379 HTMLFormElement_get_onsubmit,
380 HTMLFormElement_put_onreset,
381 HTMLFormElement_get_onreset,
382 HTMLFormElement_submit,
383 HTMLFormElement_reset,
384 HTMLFormElement_put_length,
385 HTMLFormElement_get_length,
386 HTMLFormElement__newEnum,
387 HTMLFormElement_item,
388 HTMLFormElement_tags
391 #define HTMLFORM_NODE_THIS(iface) DEFINE_THIS2(HTMLFormElement, element.node, iface)
393 static HRESULT HTMLFormElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
395 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
397 *ppv = NULL;
399 if(IsEqualGUID(&IID_IUnknown, riid)) {
400 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
401 *ppv = HTMLFORM(This);
402 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
403 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
404 *ppv = HTMLFORM(This);
405 }else if(IsEqualGUID(&IID_IHTMLFormElement, riid)) {
406 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This, ppv);
407 *ppv = HTMLFORM(This);
410 if(*ppv) {
411 IUnknown_AddRef((IUnknown*)*ppv);
412 return S_OK;
415 return HTMLElement_QI(&This->element.node, riid, ppv);
418 static void HTMLFormElement_destructor(HTMLDOMNode *iface)
420 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
422 if(This->nsform)
423 nsIDOMHTMLFormElement_Release(This->nsform);
425 HTMLElement_destructor(&This->element.node);
428 static HRESULT HTMLFormElement_get_dispid(HTMLDOMNode *iface,
429 BSTR name, DWORD grfdex, DISPID *pid)
431 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
432 nsIDOMHTMLCollection *elements;
433 nsAString nsname, nsstr;
434 PRUint32 len, i;
435 nsresult nsres;
436 HRESULT hres = DISP_E_UNKNOWNNAME;
438 static const PRUnichar nameW[] = {'n','a','m','e',0};
440 TRACE("(%p)->(%s %x %p)\n", This, wine_dbgstr_w(name), grfdex, pid);
442 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
443 if(NS_FAILED(nsres)) {
444 FIXME("GetElements failed: 0x%08x\n", nsres);
445 return E_FAIL;
448 nsres = nsIDOMHTMLCollection_GetLength(elements, &len);
449 if(NS_FAILED(nsres)) {
450 FIXME("GetLength failed: 0x%08x\n", nsres);
451 nsIDOMHTMLCollection_Release(elements);
452 return E_FAIL;
455 nsAString_InitDepend(&nsname, nameW);
456 nsAString_Init(&nsstr, NULL);
457 for(i = 0; i < len; ++i) {
458 nsIDOMNode *nsitem;
459 nsIDOMHTMLElement *nshtml_elem;
460 const PRUnichar *str;
462 nsres = nsIDOMHTMLCollection_Item(elements, i, &nsitem);
463 if(NS_FAILED(nsres)) {
464 FIXME("Item failed: 0x%08x\n", nsres);
465 hres = E_FAIL;
466 break;
469 nsres = nsIDOMNode_QueryInterface(nsitem, &IID_nsIDOMHTMLElement, (void**)&nshtml_elem);
470 nsIDOMNode_Release(nsitem);
471 if(NS_FAILED(nsres)) {
472 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres);
473 hres = E_FAIL;
474 break;
477 /* compare by id attr */
478 nsres = nsIDOMHTMLElement_GetId(nshtml_elem, &nsstr);
479 if(NS_FAILED(nsres)) {
480 FIXME("GetId failed: 0x%08x\n", nsres);
481 nsIDOMHTMLElement_Release(nshtml_elem);
482 hres = E_FAIL;
483 break;
485 nsAString_GetData(&nsstr, &str);
486 if(!strcmpiW(str, name)) {
487 nsIDOMHTMLElement_Release(nshtml_elem);
488 /* FIXME: using index for dispid */
489 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
490 hres = S_OK;
491 break;
494 /* compare by name attr */
495 nsres = nsIDOMHTMLElement_GetAttribute(nshtml_elem, &nsname, &nsstr);
496 nsIDOMHTMLElement_Release(nshtml_elem);
497 nsAString_GetData(&nsstr, &str);
498 if(!strcmpiW(str, name)) {
499 /* FIXME: using index for dispid */
500 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
501 hres = S_OK;
502 break;
505 nsAString_Finish(&nsname);
506 nsAString_Finish(&nsstr);
508 nsIDOMHTMLCollection_Release(elements);
510 return hres;
513 static HRESULT HTMLFormElement_invoke(HTMLDOMNode *iface,
514 DISPID id, LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *res,
515 EXCEPINFO *ei, IServiceProvider *caller)
517 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
518 IDispatch *ret;
519 HRESULT hres;
521 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
523 hres = htmlform_item(This, id - MSHTML_DISPID_CUSTOM_MIN, &ret);
524 if(FAILED(hres))
525 return hres;
527 if(ret) {
528 V_VT(res) = VT_DISPATCH;
529 V_DISPATCH(res) = ret;
530 }else {
531 V_VT(res) = VT_NULL;
533 return S_OK;
536 #undef HTMLFORM_NODE_THIS
538 static const NodeImplVtbl HTMLFormElementImplVtbl = {
539 HTMLFormElement_QI,
540 HTMLFormElement_destructor,
541 NULL,
542 NULL,
543 NULL,
544 NULL,
545 NULL,
546 NULL,
547 HTMLFormElement_get_dispid,
548 HTMLFormElement_invoke
551 static const tid_t HTMLFormElement_iface_tids[] = {
552 HTMLELEMENT_TIDS,
553 IHTMLFormElement_tid,
557 static dispex_static_data_t HTMLFormElement_dispex = {
558 NULL,
559 DispHTMLFormElement_tid,
560 NULL,
561 HTMLFormElement_iface_tids
564 HTMLElement *HTMLFormElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
566 HTMLFormElement *ret = heap_alloc_zero(sizeof(HTMLFormElement));
567 nsresult nsres;
569 ret->lpHTMLFormElementVtbl = &HTMLFormElementVtbl;
570 ret->element.node.vtbl = &HTMLFormElementImplVtbl;
572 HTMLElement_Init(&ret->element, doc, nselem, &HTMLFormElement_dispex);
574 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFormElement, (void**)&ret->nsform);
575 if(NS_FAILED(nsres))
576 ERR("Could not get nsIDOMHTMLFormElement interface: %08x\n", nsres);
578 return &ret->element;