2 * Copyright 2006 Jacek Caban 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
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 IHTMLSelectElement IHTMLSelectElement_iface;
40 nsIDOMHTMLSelectElement *nsselect;
43 static inline HTMLSelectElement *impl_from_IHTMLSelectElement(IHTMLSelectElement *iface)
45 return CONTAINING_RECORD(iface, HTMLSelectElement, IHTMLSelectElement_iface);
48 static HRESULT htmlselect_item(HTMLSelectElement *This, int i, IDispatch **ret)
50 nsIDOMHTMLOptionsCollection *nscol;
55 nsres = nsIDOMHTMLSelectElement_GetOptions(This->nsselect, &nscol);
56 if(NS_FAILED(nsres)) {
57 ERR("GetOptions failed: %08x\n", nsres);
61 nsres = nsIDOMHTMLOptionsCollection_Item(nscol, i, &nsnode);
62 nsIDOMHTMLOptionsCollection_Release(nscol);
63 if(NS_FAILED(nsres)) {
64 ERR("Item failed: %08x\n", nsres);
71 hres = get_node(This->element.node.doc, nsnode, TRUE, &node);
72 nsIDOMNode_Release(nsnode);
76 *ret = (IDispatch*)&node->IHTMLDOMNode_iface;
83 static HRESULT WINAPI HTMLSelectElement_QueryInterface(IHTMLSelectElement *iface,
84 REFIID riid, void **ppv)
86 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
88 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
91 static ULONG WINAPI HTMLSelectElement_AddRef(IHTMLSelectElement *iface)
93 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
95 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
98 static ULONG WINAPI HTMLSelectElement_Release(IHTMLSelectElement *iface)
100 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
102 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
105 static HRESULT WINAPI HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement *iface, UINT *pctinfo)
107 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
109 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
112 static HRESULT WINAPI HTMLSelectElement_GetTypeInfo(IHTMLSelectElement *iface, UINT iTInfo,
113 LCID lcid, ITypeInfo **ppTInfo)
115 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
117 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
121 static HRESULT WINAPI HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement *iface, REFIID riid,
122 LPOLESTR *rgszNames, UINT cNames,
123 LCID lcid, DISPID *rgDispId)
125 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
127 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
128 cNames, lcid, rgDispId);
131 static HRESULT WINAPI HTMLSelectElement_Invoke(IHTMLSelectElement *iface, DISPID dispIdMember,
132 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
133 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
135 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
137 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
138 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
141 static HRESULT WINAPI HTMLSelectElement_put_size(IHTMLSelectElement *iface, LONG v)
143 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
144 FIXME("(%p)->(%d)\n", This, v);
148 static HRESULT WINAPI HTMLSelectElement_get_size(IHTMLSelectElement *iface, LONG *p)
150 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
151 FIXME("(%p)->(%p)\n", This, p);
155 static HRESULT WINAPI HTMLSelectElement_put_multiple(IHTMLSelectElement *iface, VARIANT_BOOL v)
157 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
158 FIXME("(%p)->(%x)\n", This, v);
162 static HRESULT WINAPI HTMLSelectElement_get_multiple(IHTMLSelectElement *iface, VARIANT_BOOL *p)
164 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
165 FIXME("(%p)->(%p)\n", This, p);
169 static HRESULT WINAPI HTMLSelectElement_put_name(IHTMLSelectElement *iface, BSTR v)
171 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
172 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
176 static HRESULT WINAPI HTMLSelectElement_get_name(IHTMLSelectElement *iface, BSTR *p)
178 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
180 const PRUnichar *name = NULL;
183 TRACE("(%p)->(%p)\n", This, p);
185 nsAString_Init(&name_str, NULL);
187 nsres = nsIDOMHTMLSelectElement_GetName(This->nsselect, &name_str);
188 if(NS_SUCCEEDED(nsres)) {
189 static const WCHAR wszGarbage[] = {'g','a','r','b','a','g','e',0};
191 nsAString_GetData(&name_str, &name);
194 * Native never returns empty string here. If an element has no name,
195 * name of previous element or ramdom data is returned.
197 *p = SysAllocString(*name ? name : wszGarbage);
199 ERR("GetName failed: %08x\n", nsres);
202 nsAString_Finish(&name_str);
204 TRACE("name=%s\n", debugstr_w(*p));
208 static HRESULT WINAPI HTMLSelectElement_get_options(IHTMLSelectElement *iface, IDispatch **p)
210 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
212 TRACE("(%p)->(%p)\n", This, p);
214 *p = (IDispatch*)&This->IHTMLSelectElement_iface;
215 IDispatch_AddRef(*p);
219 static HRESULT WINAPI HTMLSelectElement_put_onchange(IHTMLSelectElement *iface, VARIANT v)
221 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
223 TRACE("(%p)->()\n", This);
225 return set_node_event(&This->element.node, EVENTID_CHANGE, &v);
228 static HRESULT WINAPI HTMLSelectElement_get_onchange(IHTMLSelectElement *iface, VARIANT *p)
230 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
231 FIXME("(%p)->(%p)\n", This, p);
235 static HRESULT WINAPI HTMLSelectElement_put_selectedIndex(IHTMLSelectElement *iface, LONG v)
237 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
240 TRACE("(%p)->(%d)\n", This, v);
242 nsres = nsIDOMHTMLSelectElement_SetSelectedIndex(This->nsselect, v);
244 ERR("SetSelectedIndex failed: %08x\n", nsres);
249 static HRESULT WINAPI HTMLSelectElement_get_selectedIndex(IHTMLSelectElement *iface, LONG *p)
251 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
255 TRACE("(%p)->(%p)\n", This, p);
257 nsres = nsIDOMHTMLSelectElement_GetSelectedIndex(This->nsselect, &idx);
259 ERR("GetSelectedIndex failed: %08x\n", nsres);
265 static HRESULT WINAPI HTMLSelectElement_get_type(IHTMLSelectElement *iface, BSTR *p)
267 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
271 TRACE("(%p)->(%p)\n", This, p);
273 nsAString_Init(&type_str, NULL);
274 nsres = nsIDOMHTMLSelectElement_GetType(This->nsselect, &type_str);
275 return return_nsstr(nsres, &type_str, p);
278 static HRESULT WINAPI HTMLSelectElement_put_value(IHTMLSelectElement *iface, BSTR v)
280 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
284 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
286 nsAString_InitDepend(&value_str, v);
287 nsres = nsIDOMHTMLSelectElement_SetValue(This->nsselect, &value_str);
288 nsAString_Finish(&value_str);
290 ERR("SetValue failed: %08x\n", nsres);
295 static HRESULT WINAPI HTMLSelectElement_get_value(IHTMLSelectElement *iface, BSTR *p)
297 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
301 TRACE("(%p)->(%p)\n", This, p);
303 nsAString_Init(&value_str, NULL);
304 nsres = nsIDOMHTMLSelectElement_GetValue(This->nsselect, &value_str);
305 return return_nsstr(nsres, &value_str, p);
308 static HRESULT WINAPI HTMLSelectElement_put_disabled(IHTMLSelectElement *iface, VARIANT_BOOL v)
310 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
313 TRACE("(%p)->(%x)\n", This, v);
315 nsres = nsIDOMHTMLSelectElement_SetDisabled(This->nsselect, v != VARIANT_FALSE);
316 if(NS_FAILED(nsres)) {
317 ERR("SetDisabled failed: %08x\n", nsres);
324 static HRESULT WINAPI HTMLSelectElement_get_disabled(IHTMLSelectElement *iface, VARIANT_BOOL *p)
326 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
327 cpp_bool disabled = FALSE;
330 TRACE("(%p)->(%p)\n", This, p);
332 nsres = nsIDOMHTMLSelectElement_GetDisabled(This->nsselect, &disabled);
333 if(NS_FAILED(nsres)) {
334 ERR("GetDisabled failed: %08x\n", nsres);
338 *p = disabled ? VARIANT_TRUE : VARIANT_FALSE;
342 static HRESULT WINAPI HTMLSelectElement_get_form(IHTMLSelectElement *iface, IHTMLFormElement **p)
344 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
345 FIXME("(%p)->(%p)\n", This, p);
349 static HRESULT WINAPI HTMLSelectElement_add(IHTMLSelectElement *iface, IHTMLElement *element,
352 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
353 nsIWritableVariant *nsvariant;
354 HTMLElement *element_obj;
357 TRACE("(%p)->(%p %s)\n", This, element, debugstr_variant(&before));
359 element_obj = unsafe_impl_from_IHTMLElement(element);
361 FIXME("External IHTMLElement implementation?\n");
365 nsvariant = create_nsvariant();
369 switch(V_VT(&before)) {
371 nsres = nsIWritableVariant_SetAsEmpty(nsvariant);
374 nsres = nsIWritableVariant_SetAsInt16(nsvariant, V_I2(&before));
377 FIXME("unhandled before %s\n", debugstr_variant(&before));
378 nsIWritableVariant_Release(nsvariant);
382 if(NS_SUCCEEDED(nsres))
383 nsres = nsIDOMHTMLSelectElement_Add(This->nsselect, element_obj->nselem, (nsIVariant*)nsvariant);
384 nsIWritableVariant_Release(nsvariant);
385 if(NS_FAILED(nsres)) {
386 ERR("Add failed: %08x\n", nsres);
393 static HRESULT WINAPI HTMLSelectElement_remove(IHTMLSelectElement *iface, LONG index)
395 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
396 FIXME("(%p)->(%d)\n", This, index);
400 static HRESULT WINAPI HTMLSelectElement_put_length(IHTMLSelectElement *iface, LONG v)
402 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
405 TRACE("(%p)->(%d)\n", This, v);
407 nsres = nsIDOMHTMLSelectElement_SetLength(This->nsselect, v);
409 ERR("SetLength failed: %08x\n", nsres);
414 static HRESULT WINAPI HTMLSelectElement_get_length(IHTMLSelectElement *iface, LONG *p)
416 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
420 TRACE("(%p)->(%p)\n", This, p);
422 nsres = nsIDOMHTMLSelectElement_GetLength(This->nsselect, &length);
424 ERR("GetLength failed: %08x\n", nsres);
428 TRACE("ret %d\n", *p);
432 static HRESULT WINAPI HTMLSelectElement_get__newEnum(IHTMLSelectElement *iface, IUnknown **p)
434 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
435 FIXME("(%p)->(%p)\n", This, p);
439 static HRESULT WINAPI HTMLSelectElement_item(IHTMLSelectElement *iface, VARIANT name,
440 VARIANT index, IDispatch **pdisp)
442 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
444 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
450 if(V_VT(&name) == VT_I4) {
453 return htmlselect_item(This, V_I4(&name), pdisp);
456 FIXME("Unsupported args\n");
460 static HRESULT WINAPI HTMLSelectElement_tags(IHTMLSelectElement *iface, VARIANT tagName,
463 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
464 FIXME("(%p)->(v %p)\n", This, pdisp);
468 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl = {
469 HTMLSelectElement_QueryInterface,
470 HTMLSelectElement_AddRef,
471 HTMLSelectElement_Release,
472 HTMLSelectElement_GetTypeInfoCount,
473 HTMLSelectElement_GetTypeInfo,
474 HTMLSelectElement_GetIDsOfNames,
475 HTMLSelectElement_Invoke,
476 HTMLSelectElement_put_size,
477 HTMLSelectElement_get_size,
478 HTMLSelectElement_put_multiple,
479 HTMLSelectElement_get_multiple,
480 HTMLSelectElement_put_name,
481 HTMLSelectElement_get_name,
482 HTMLSelectElement_get_options,
483 HTMLSelectElement_put_onchange,
484 HTMLSelectElement_get_onchange,
485 HTMLSelectElement_put_selectedIndex,
486 HTMLSelectElement_get_selectedIndex,
487 HTMLSelectElement_get_type,
488 HTMLSelectElement_put_value,
489 HTMLSelectElement_get_value,
490 HTMLSelectElement_put_disabled,
491 HTMLSelectElement_get_disabled,
492 HTMLSelectElement_get_form,
493 HTMLSelectElement_add,
494 HTMLSelectElement_remove,
495 HTMLSelectElement_put_length,
496 HTMLSelectElement_get_length,
497 HTMLSelectElement_get__newEnum,
498 HTMLSelectElement_item,
499 HTMLSelectElement_tags
502 static inline HTMLSelectElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
504 return CONTAINING_RECORD(iface, HTMLSelectElement, element.node);
507 static HRESULT HTMLSelectElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
509 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
513 if(IsEqualGUID(&IID_IUnknown, riid)) {
514 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
515 *ppv = &This->IHTMLSelectElement_iface;
516 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
517 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
518 *ppv = &This->IHTMLSelectElement_iface;
519 }else if(IsEqualGUID(&IID_IHTMLSelectElement, riid)) {
520 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This, ppv);
521 *ppv = &This->IHTMLSelectElement_iface;
525 IUnknown_AddRef((IUnknown*)*ppv);
529 return HTMLElement_QI(&This->element.node, riid, ppv);
532 static void HTMLSelectElement_destructor(HTMLDOMNode *iface)
534 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
536 nsIDOMHTMLSelectElement_Release(This->nsselect);
538 HTMLElement_destructor(&This->element.node);
541 static HRESULT HTMLSelectElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
543 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
544 return IHTMLSelectElement_put_disabled(&This->IHTMLSelectElement_iface, v);
547 static HRESULT HTMLSelectElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
549 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
550 return IHTMLSelectElement_get_disabled(&This->IHTMLSelectElement_iface, p);
553 #define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN
555 static HRESULT HTMLSelectElement_get_dispid(HTMLDOMNode *iface, BSTR name, DWORD flags, DISPID *dispid)
560 for(ptr = name; *ptr && isdigitW(*ptr); ptr++) {
561 idx = idx*10 + (*ptr-'0');
562 if(idx > MSHTML_CUSTOM_DISPID_CNT) {
563 WARN("too big idx\n");
564 return DISP_E_UNKNOWNNAME;
568 return DISP_E_UNKNOWNNAME;
570 *dispid = DISPID_OPTIONCOL_0 + idx;
574 static HRESULT HTMLSelectElement_invoke(HTMLDOMNode *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
575 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
577 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
579 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
582 case DISPATCH_PROPERTYGET: {
586 hres = htmlselect_item(This, id-DISPID_OPTIONCOL_0, &ret);
591 V_VT(res) = VT_DISPATCH;
592 V_DISPATCH(res) = ret;
600 FIXME("unimplemented flags %x\n", flags);
607 static const NodeImplVtbl HTMLSelectElementImplVtbl = {
608 HTMLSelectElement_QI,
609 HTMLSelectElement_destructor,
611 HTMLElement_get_attr_col,
615 HTMLSelectElementImpl_put_disabled,
616 HTMLSelectElementImpl_get_disabled,
619 HTMLSelectElement_get_dispid,
620 HTMLSelectElement_invoke
623 static const tid_t HTMLSelectElement_tids[] = {
625 IHTMLSelectElement_tid,
629 static dispex_static_data_t HTMLSelectElement_dispex = {
631 DispHTMLSelectElement_tid,
633 HTMLSelectElement_tids
636 HRESULT HTMLSelectElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
638 HTMLSelectElement *ret;
641 ret = heap_alloc_zero(sizeof(HTMLSelectElement));
643 return E_OUTOFMEMORY;
645 ret->IHTMLSelectElement_iface.lpVtbl = &HTMLSelectElementVtbl;
646 ret->element.node.vtbl = &HTMLSelectElementImplVtbl;
648 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLSelectElement,
649 (void**)&ret->nsselect);
650 if(NS_FAILED(nsres)) {
651 ERR("Could not get nsIDOMHTMLSelectElement interfce: %08x\n", nsres);
656 HTMLElement_Init(&ret->element, doc, nselem, &HTMLSelectElement_dispex);
658 *elem = &ret->element;