mshtml: Added IHTMLFormElement::get_length implementation.
[wine/hacks.git] / dlls / mshtml / htmlform.c
blobc33937d13a1acf6d6cae7f391d95c32ddcc3602a
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 #define HTMLFORM_THIS(iface) DEFINE_THIS(HTMLFormElement, HTMLFormElement, iface)
46 static HRESULT WINAPI HTMLFormElement_QueryInterface(IHTMLFormElement *iface,
47 REFIID riid, void **ppv)
49 HTMLFormElement *This = HTMLFORM_THIS(iface);
51 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
54 static ULONG WINAPI HTMLFormElement_AddRef(IHTMLFormElement *iface)
56 HTMLFormElement *This = HTMLFORM_THIS(iface);
58 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
61 static ULONG WINAPI HTMLFormElement_Release(IHTMLFormElement *iface)
63 HTMLFormElement *This = HTMLFORM_THIS(iface);
65 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
68 static HRESULT WINAPI HTMLFormElement_GetTypeInfoCount(IHTMLFormElement *iface, UINT *pctinfo)
70 HTMLFormElement *This = HTMLFORM_THIS(iface);
71 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
74 static HRESULT WINAPI HTMLFormElement_GetTypeInfo(IHTMLFormElement *iface, UINT iTInfo,
75 LCID lcid, ITypeInfo **ppTInfo)
77 HTMLFormElement *This = HTMLFORM_THIS(iface);
78 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
81 static HRESULT WINAPI HTMLFormElement_GetIDsOfNames(IHTMLFormElement *iface, REFIID riid,
82 LPOLESTR *rgszNames, UINT cNames,
83 LCID lcid, DISPID *rgDispId)
85 HTMLFormElement *This = HTMLFORM_THIS(iface);
86 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
89 static HRESULT WINAPI HTMLFormElement_Invoke(IHTMLFormElement *iface, DISPID dispIdMember,
90 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
91 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
93 HTMLFormElement *This = HTMLFORM_THIS(iface);
94 return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
95 pVarResult, pExcepInfo, puArgErr);
98 static HRESULT WINAPI HTMLFormElement_put_action(IHTMLFormElement *iface, BSTR v)
100 HTMLFormElement *This = HTMLFORM_THIS(iface);
101 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
102 return E_NOTIMPL;
105 static HRESULT WINAPI HTMLFormElement_get_action(IHTMLFormElement *iface, BSTR *p)
107 HTMLFormElement *This = HTMLFORM_THIS(iface);
108 FIXME("(%p)->(%p)\n", This, p);
109 return E_NOTIMPL;
112 static HRESULT WINAPI HTMLFormElement_put_dir(IHTMLFormElement *iface, BSTR v)
114 HTMLFormElement *This = HTMLFORM_THIS(iface);
115 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
116 return E_NOTIMPL;
119 static HRESULT WINAPI HTMLFormElement_get_dir(IHTMLFormElement *iface, BSTR *p)
121 HTMLFormElement *This = HTMLFORM_THIS(iface);
122 FIXME("(%p)->(%p)\n", This, p);
123 return E_NOTIMPL;
126 static HRESULT WINAPI HTMLFormElement_put_encoding(IHTMLFormElement *iface, BSTR v)
128 HTMLFormElement *This = HTMLFORM_THIS(iface);
129 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
130 return E_NOTIMPL;
133 static HRESULT WINAPI HTMLFormElement_get_encoding(IHTMLFormElement *iface, BSTR *p)
135 HTMLFormElement *This = HTMLFORM_THIS(iface);
136 FIXME("(%p)->(%p)\n", This, p);
137 return E_NOTIMPL;
140 static HRESULT WINAPI HTMLFormElement_put_method(IHTMLFormElement *iface, BSTR v)
142 HTMLFormElement *This = HTMLFORM_THIS(iface);
143 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
144 return E_NOTIMPL;
147 static HRESULT WINAPI HTMLFormElement_get_method(IHTMLFormElement *iface, BSTR *p)
149 HTMLFormElement *This = HTMLFORM_THIS(iface);
150 FIXME("(%p)->(%p)\n", This, p);
151 return E_NOTIMPL;
154 static HRESULT WINAPI HTMLFormElement_get_elements(IHTMLFormElement *iface, IDispatch **p)
156 HTMLFormElement *This = HTMLFORM_THIS(iface);
157 FIXME("(%p)->(%p)\n", This, p);
158 return E_NOTIMPL;
161 static HRESULT WINAPI HTMLFormElement_put_target(IHTMLFormElement *iface, BSTR v)
163 HTMLFormElement *This = HTMLFORM_THIS(iface);
164 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
165 return E_NOTIMPL;
168 static HRESULT WINAPI HTMLFormElement_get_target(IHTMLFormElement *iface, BSTR *p)
170 HTMLFormElement *This = HTMLFORM_THIS(iface);
171 FIXME("(%p)->(%p)\n", This, p);
172 return E_NOTIMPL;
175 static HRESULT WINAPI HTMLFormElement_put_name(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_name(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_onsubmit(IHTMLFormElement *iface, VARIANT v)
191 HTMLFormElement *This = HTMLFORM_THIS(iface);
192 FIXME("(%p)->(v)\n", This);
193 return E_NOTIMPL;
196 static HRESULT WINAPI HTMLFormElement_get_onsubmit(IHTMLFormElement *iface, VARIANT *p)
198 HTMLFormElement *This = HTMLFORM_THIS(iface);
199 FIXME("(%p)->(%p)\n", This, p);
200 return E_NOTIMPL;
203 static HRESULT WINAPI HTMLFormElement_put_onreset(IHTMLFormElement *iface, VARIANT v)
205 HTMLFormElement *This = HTMLFORM_THIS(iface);
206 FIXME("(%p)->(v)\n", This);
207 return E_NOTIMPL;
210 static HRESULT WINAPI HTMLFormElement_get_onreset(IHTMLFormElement *iface, VARIANT *p)
212 HTMLFormElement *This = HTMLFORM_THIS(iface);
213 FIXME("(%p)->(%p)\n", This, p);
214 return E_NOTIMPL;
217 static HRESULT WINAPI HTMLFormElement_submit(IHTMLFormElement *iface)
219 HTMLFormElement *This = HTMLFORM_THIS(iface);
220 FIXME("(%p)->()\n", This);
221 return E_NOTIMPL;
224 static HRESULT WINAPI HTMLFormElement_reset(IHTMLFormElement *iface)
226 HTMLFormElement *This = HTMLFORM_THIS(iface);
227 FIXME("(%p)->()\n", This);
228 return E_NOTIMPL;
231 static HRESULT WINAPI HTMLFormElement_put_length(IHTMLFormElement *iface, LONG v)
233 HTMLFormElement *This = HTMLFORM_THIS(iface);
234 FIXME("(%p)->(%d)\n", This, v);
235 return E_NOTIMPL;
238 static HRESULT WINAPI HTMLFormElement_get_length(IHTMLFormElement *iface, LONG *p)
240 HTMLFormElement *This = HTMLFORM_THIS(iface);
241 PRInt32 length;
242 nsresult nsres;
244 TRACE("(%p)->(%p)\n", This, p);
246 nsres = nsIDOMHTMLFormElement_GetLength(This->nsform, &length);
247 if(NS_FAILED(nsres)) {
248 ERR("GetLength failed: %08x\n", nsres);
249 return E_FAIL;
252 *p = length;
253 return S_OK;
256 static HRESULT WINAPI HTMLFormElement__newEnum(IHTMLFormElement *iface, IUnknown **p)
258 HTMLFormElement *This = HTMLFORM_THIS(iface);
259 FIXME("(%p)->(%p)\n", This, p);
260 return E_NOTIMPL;
263 static HRESULT WINAPI HTMLFormElement_item(IHTMLFormElement *iface, VARIANT name,
264 VARIANT index, IDispatch **pdisp)
266 HTMLFormElement *This = HTMLFORM_THIS(iface);
267 FIXME("(%p)->(v v %p)\n", This, pdisp);
268 return E_NOTIMPL;
271 static HRESULT WINAPI HTMLFormElement_tags(IHTMLFormElement *iface, VARIANT tagName,
272 IDispatch **pdisp)
274 HTMLFormElement *This = HTMLFORM_THIS(iface);
275 FIXME("(%p)->(v %p)\n", This, pdisp);
276 return E_NOTIMPL;
279 #undef HTMLFORM_THIS
281 static const IHTMLFormElementVtbl HTMLFormElementVtbl = {
282 HTMLFormElement_QueryInterface,
283 HTMLFormElement_AddRef,
284 HTMLFormElement_Release,
285 HTMLFormElement_GetTypeInfoCount,
286 HTMLFormElement_GetTypeInfo,
287 HTMLFormElement_GetIDsOfNames,
288 HTMLFormElement_Invoke,
289 HTMLFormElement_put_action,
290 HTMLFormElement_get_action,
291 HTMLFormElement_put_dir,
292 HTMLFormElement_get_dir,
293 HTMLFormElement_put_encoding,
294 HTMLFormElement_get_encoding,
295 HTMLFormElement_put_method,
296 HTMLFormElement_get_method,
297 HTMLFormElement_get_elements,
298 HTMLFormElement_put_target,
299 HTMLFormElement_get_target,
300 HTMLFormElement_put_name,
301 HTMLFormElement_get_name,
302 HTMLFormElement_put_onsubmit,
303 HTMLFormElement_get_onsubmit,
304 HTMLFormElement_put_onreset,
305 HTMLFormElement_get_onreset,
306 HTMLFormElement_submit,
307 HTMLFormElement_reset,
308 HTMLFormElement_put_length,
309 HTMLFormElement_get_length,
310 HTMLFormElement__newEnum,
311 HTMLFormElement_item,
312 HTMLFormElement_tags
315 #define HTMLFORM_NODE_THIS(iface) DEFINE_THIS2(HTMLFormElement, element.node, iface)
317 static HRESULT HTMLFormElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
319 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
321 *ppv = NULL;
323 if(IsEqualGUID(&IID_IUnknown, riid)) {
324 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
325 *ppv = HTMLFORM(This);
326 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
327 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
328 *ppv = HTMLFORM(This);
329 }else if(IsEqualGUID(&IID_IHTMLFormElement, riid)) {
330 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This, ppv);
331 *ppv = HTMLFORM(This);
334 if(*ppv) {
335 IUnknown_AddRef((IUnknown*)*ppv);
336 return S_OK;
339 return HTMLElement_QI(&This->element.node, riid, ppv);
342 static void HTMLFormElement_destructor(HTMLDOMNode *iface)
344 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
346 if(This->nsform)
347 nsIDOMHTMLFormElement_Release(This->nsform);
349 HTMLElement_destructor(&This->element.node);
352 static HRESULT HTMLFormElement_get_dispid(HTMLDOMNode *iface,
353 BSTR name, DWORD grfdex, DISPID *pid)
355 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
356 nsIDOMHTMLCollection *elements;
357 nsAString nsname, nsstr;
358 PRUint32 len, i;
359 nsresult nsres;
360 HRESULT hres = DISP_E_UNKNOWNNAME;
362 static const PRUnichar nameW[] = {'n','a','m','e',0};
364 TRACE("(%p)->(%s %x %p)\n", This, wine_dbgstr_w(name), grfdex, pid);
366 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
367 if(NS_FAILED(nsres)) {
368 FIXME("GetElements failed: 0x%08x\n", nsres);
369 return E_FAIL;
372 nsres = nsIDOMHTMLCollection_GetLength(elements, &len);
373 if(NS_FAILED(nsres)) {
374 FIXME("GetLength failed: 0x%08x\n", nsres);
375 nsIDOMHTMLCollection_Release(elements);
376 return E_FAIL;
379 nsAString_InitDepend(&nsname, nameW);
380 nsAString_Init(&nsstr, NULL);
381 for(i = 0; i < len; ++i) {
382 nsIDOMNode *nsitem;
383 nsIDOMHTMLElement *nshtml_elem;
384 const PRUnichar *str;
386 nsres = nsIDOMHTMLCollection_Item(elements, i, &nsitem);
387 if(NS_FAILED(nsres)) {
388 FIXME("Item failed: 0x%08x\n", nsres);
389 hres = E_FAIL;
390 break;
393 nsres = nsIDOMNode_QueryInterface(nsitem, &IID_nsIDOMHTMLElement, (void**)&nshtml_elem);
394 nsIDOMNode_Release(nsitem);
395 if(NS_FAILED(nsres)) {
396 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres);
397 hres = E_FAIL;
398 break;
401 /* compare by id attr */
402 nsres = nsIDOMHTMLElement_GetId(nshtml_elem, &nsstr);
403 if(NS_FAILED(nsres)) {
404 FIXME("GetId failed: 0x%08x\n", nsres);
405 nsIDOMHTMLElement_Release(nshtml_elem);
406 hres = E_FAIL;
407 break;
409 nsAString_GetData(&nsstr, &str);
410 if(!strcmpiW(str, name)) {
411 nsIDOMHTMLElement_Release(nshtml_elem);
412 /* FIXME: using index for dispid */
413 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
414 hres = S_OK;
415 break;
418 /* compare by name attr */
419 nsres = nsIDOMHTMLElement_GetAttribute(nshtml_elem, &nsname, &nsstr);
420 nsIDOMHTMLElement_Release(nshtml_elem);
421 nsAString_GetData(&nsstr, &str);
422 if(!strcmpiW(str, name)) {
423 /* FIXME: using index for dispid */
424 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
425 hres = S_OK;
426 break;
429 nsAString_Finish(&nsname);
430 nsAString_Finish(&nsstr);
432 nsIDOMHTMLCollection_Release(elements);
434 return hres;
437 static HRESULT HTMLFormElement_invoke(HTMLDOMNode *iface,
438 DISPID id, LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *res,
439 EXCEPINFO *ei, IServiceProvider *caller)
441 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
442 nsIDOMHTMLCollection *elements;
443 nsIDOMNode *item;
444 HTMLDOMNode *node;
445 nsresult nsres;
447 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
449 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
450 if(NS_FAILED(nsres)) {
451 FIXME("GetElements failed: 0x%08x\n", nsres);
452 return E_FAIL;
455 nsres = nsIDOMHTMLCollection_Item(elements, id - MSHTML_DISPID_CUSTOM_MIN, &item);
456 nsIDOMHTMLCollection_Release(elements);
457 if(NS_FAILED(nsres)) {
458 FIXME("Item failed: 0x%08x\n", nsres);
459 return E_FAIL;
462 node = get_node(This->element.node.doc, item, TRUE);
464 V_VT(res) = VT_DISPATCH;
465 V_DISPATCH(res) = (IDispatch*)node;
467 IHTMLDOMNode_AddRef(HTMLDOMNODE(node));
468 nsIDOMNode_Release(item);
470 return S_OK;
473 #undef HTMLFORM_NODE_THIS
475 static const NodeImplVtbl HTMLFormElementImplVtbl = {
476 HTMLFormElement_QI,
477 HTMLFormElement_destructor,
478 NULL,
479 NULL,
480 NULL,
481 NULL,
482 NULL,
483 NULL,
484 HTMLFormElement_get_dispid,
485 HTMLFormElement_invoke
488 static const tid_t HTMLFormElement_iface_tids[] = {
489 HTMLELEMENT_TIDS,
490 IHTMLFormElement_tid,
494 static dispex_static_data_t HTMLFormElement_dispex = {
495 NULL,
496 DispHTMLFormElement_tid,
497 NULL,
498 HTMLFormElement_iface_tids
501 HTMLElement *HTMLFormElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
503 HTMLFormElement *ret = heap_alloc_zero(sizeof(HTMLFormElement));
504 nsresult nsres;
506 ret->lpHTMLFormElementVtbl = &HTMLFormElementVtbl;
507 ret->element.node.vtbl = &HTMLFormElementImplVtbl;
509 HTMLElement_Init(&ret->element, doc, nselem, &HTMLFormElement_dispex);
511 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFormElement, (void**)&ret->nsform);
512 if(NS_FAILED(nsres))
513 ERR("Could not get nsIDOMHTMLFormElement interface: %08x\n", nsres);
515 return &ret->element;