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 const IHTMLSelectElementVtbl *lpHTMLSelectElementVtbl;
40 nsIDOMHTMLSelectElement *nsselect;
43 #define HTMLSELECT(x) ((IHTMLSelectElement*) &(x)->lpHTMLSelectElementVtbl)
45 static HRESULT htmlselect_item(HTMLSelectElement *This, int i, IDispatch **ret)
47 nsIDOMHTMLOptionsCollection *nscol;
52 nsres = nsIDOMHTMLSelectElement_GetOptions(This->nsselect, &nscol);
53 if(NS_FAILED(nsres)) {
54 ERR("GetOptions failed: %08x\n", nsres);
58 nsres = nsIDOMHTMLOptionsCollection_Item(nscol, i, &nsnode);
59 nsIDOMHTMLOptionsCollection_Release(nscol);
60 if(NS_FAILED(nsres)) {
61 ERR("Item failed: %08x\n", nsres);
68 hres = get_node(This->element.node.doc, nsnode, TRUE, &node);
69 nsIDOMNode_Release(nsnode);
73 IHTMLDOMNode_AddRef(HTMLDOMNODE(node));
74 *ret = (IDispatch*)HTMLDOMNODE(node);
81 #define HTMLSELECT_THIS(iface) DEFINE_THIS(HTMLSelectElement, HTMLSelectElement, iface)
83 static HRESULT WINAPI HTMLSelectElement_QueryInterface(IHTMLSelectElement *iface,
84 REFIID riid, void **ppv)
86 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
88 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
91 static ULONG WINAPI HTMLSelectElement_AddRef(IHTMLSelectElement *iface)
93 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
95 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
98 static ULONG WINAPI HTMLSelectElement_Release(IHTMLSelectElement *iface)
100 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
102 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
105 static HRESULT WINAPI HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement *iface, UINT *pctinfo)
107 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
109 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
112 static HRESULT WINAPI HTMLSelectElement_GetTypeInfo(IHTMLSelectElement *iface, UINT iTInfo,
113 LCID lcid, ITypeInfo **ppTInfo)
115 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
117 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
120 static HRESULT WINAPI HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement *iface, REFIID riid,
121 LPOLESTR *rgszNames, UINT cNames,
122 LCID lcid, DISPID *rgDispId)
124 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
126 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
129 static HRESULT WINAPI HTMLSelectElement_Invoke(IHTMLSelectElement *iface, DISPID dispIdMember,
130 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
131 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
133 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
135 return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid,
136 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
139 static HRESULT WINAPI HTMLSelectElement_put_size(IHTMLSelectElement *iface, LONG v)
141 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
142 FIXME("(%p)->(%d)\n", This, v);
146 static HRESULT WINAPI HTMLSelectElement_get_size(IHTMLSelectElement *iface, LONG *p)
148 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
149 FIXME("(%p)->(%p)\n", This, p);
153 static HRESULT WINAPI HTMLSelectElement_put_multiple(IHTMLSelectElement *iface, VARIANT_BOOL v)
155 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
156 FIXME("(%p)->(%x)\n", This, v);
160 static HRESULT WINAPI HTMLSelectElement_get_multiple(IHTMLSelectElement *iface, VARIANT_BOOL *p)
162 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
163 FIXME("(%p)->(%p)\n", This, p);
167 static HRESULT WINAPI HTMLSelectElement_put_name(IHTMLSelectElement *iface, BSTR v)
169 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
170 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
174 static HRESULT WINAPI HTMLSelectElement_get_name(IHTMLSelectElement *iface, BSTR *p)
176 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
178 const PRUnichar *name = NULL;
181 TRACE("(%p)->(%p)\n", This, p);
183 nsAString_Init(&name_str, NULL);
185 nsres = nsIDOMHTMLSelectElement_GetName(This->nsselect, &name_str);
186 if(NS_SUCCEEDED(nsres)) {
187 static const WCHAR wszGarbage[] = {'g','a','r','b','a','g','e',0};
189 nsAString_GetData(&name_str, &name);
192 * Native never returns empty string here. If an element has no name,
193 * name of previous element or ramdom data is returned.
195 *p = SysAllocString(*name ? name : wszGarbage);
197 ERR("GetName failed: %08x\n", nsres);
200 nsAString_Finish(&name_str);
202 TRACE("name=%s\n", debugstr_w(*p));
206 static HRESULT WINAPI HTMLSelectElement_get_options(IHTMLSelectElement *iface, IDispatch **p)
208 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
210 TRACE("(%p)->(%p)\n", This, p);
212 *p = (IDispatch*)HTMLSELECT(This);
213 IDispatch_AddRef(*p);
217 static HRESULT WINAPI HTMLSelectElement_put_onchange(IHTMLSelectElement *iface, VARIANT v)
219 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
221 TRACE("(%p)->()\n", This);
223 return set_node_event(&This->element.node, EVENTID_CHANGE, &v);
226 static HRESULT WINAPI HTMLSelectElement_get_onchange(IHTMLSelectElement *iface, VARIANT *p)
228 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
229 FIXME("(%p)->(%p)\n", This, p);
233 static HRESULT WINAPI HTMLSelectElement_put_selectedIndex(IHTMLSelectElement *iface, LONG v)
235 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
238 TRACE("(%p)->(%d)\n", This, v);
240 nsres = nsIDOMHTMLSelectElement_SetSelectedIndex(This->nsselect, v);
242 ERR("SetSelectedIndex failed: %08x\n", nsres);
247 static HRESULT WINAPI HTMLSelectElement_get_selectedIndex(IHTMLSelectElement *iface, LONG *p)
249 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
253 TRACE("(%p)->(%p)\n", This, p);
255 nsres = nsIDOMHTMLSelectElement_GetSelectedIndex(This->nsselect, &idx);
257 ERR("GetSelectedIndex failed: %08x\n", nsres);
263 static HRESULT WINAPI HTMLSelectElement_get_type(IHTMLSelectElement *iface, BSTR *p)
265 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
266 const PRUnichar *type;
271 TRACE("(%p)->(%p)\n", This, p);
273 nsAString_Init(&type_str, NULL);
274 nsres = nsIDOMHTMLSelectElement_GetType(This->nsselect, &type_str);
275 if(NS_SUCCEEDED(nsres)) {
276 nsAString_GetData(&type_str, &type);
277 *p = *type ? SysAllocString(type) : NULL;
279 ERR("GetType failed: %08x\n", nsres);
283 nsAString_Finish(&type_str);
288 static HRESULT WINAPI HTMLSelectElement_put_value(IHTMLSelectElement *iface, BSTR v)
290 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
294 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
296 nsAString_InitDepend(&value_str, v);
297 nsres = nsIDOMHTMLSelectElement_SetValue(This->nsselect, &value_str);
298 nsAString_Finish(&value_str);
300 ERR("SetValue failed: %08x\n", nsres);
305 static HRESULT WINAPI HTMLSelectElement_get_value(IHTMLSelectElement *iface, BSTR *p)
307 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
309 const PRUnichar *value = NULL;
312 TRACE("(%p)->(%p)\n", This, p);
314 nsAString_Init(&value_str, NULL);
316 nsres = nsIDOMHTMLSelectElement_GetValue(This->nsselect, &value_str);
317 if(NS_SUCCEEDED(nsres)) {
318 nsAString_GetData(&value_str, &value);
319 *p = *value ? SysAllocString(value) : NULL;
321 ERR("GetValue failed: %08x\n", nsres);
324 nsAString_Finish(&value_str);
326 TRACE("value=%s\n", debugstr_w(*p));
330 static HRESULT WINAPI HTMLSelectElement_put_disabled(IHTMLSelectElement *iface, VARIANT_BOOL v)
332 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
335 TRACE("(%p)->(%x)\n", This, v);
337 nsres = nsIDOMHTMLSelectElement_SetDisabled(This->nsselect, v != VARIANT_FALSE);
338 if(NS_FAILED(nsres)) {
339 ERR("SetDisabled failed: %08x\n", nsres);
346 static HRESULT WINAPI HTMLSelectElement_get_disabled(IHTMLSelectElement *iface, VARIANT_BOOL *p)
348 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
349 PRBool disabled = FALSE;
352 TRACE("(%p)->(%p)\n", This, p);
354 nsres = nsIDOMHTMLSelectElement_GetDisabled(This->nsselect, &disabled);
355 if(NS_FAILED(nsres)) {
356 ERR("GetDisabled failed: %08x\n", nsres);
360 *p = disabled ? VARIANT_TRUE : VARIANT_FALSE;
364 static HRESULT WINAPI HTMLSelectElement_get_form(IHTMLSelectElement *iface, IHTMLFormElement **p)
366 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
367 FIXME("(%p)->(%p)\n", This, p);
371 static HRESULT WINAPI HTMLSelectElement_add(IHTMLSelectElement *iface, IHTMLElement *element,
374 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
375 IHTMLDOMNode *node, *tmp;
378 FIXME("(%p)->(%p %s): semi-stub\n", This, element, debugstr_variant(&before));
380 if(V_VT(&before) != VT_EMPTY) {
381 FIXME("unhandled before %s\n", debugstr_variant(&before));
385 hres = IHTMLElement_QueryInterface(element, &IID_IHTMLDOMNode, (void**)&node);
389 hres = IHTMLDOMNode_appendChild(HTMLDOMNODE(&This->element.node), node, &tmp);
390 IHTMLDOMNode_Release(node);
391 if(SUCCEEDED(hres) && tmp)
392 IHTMLDOMNode_Release(tmp);
397 static HRESULT WINAPI HTMLSelectElement_remove(IHTMLSelectElement *iface, LONG index)
399 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
400 FIXME("(%p)->(%d)\n", This, index);
404 static HRESULT WINAPI HTMLSelectElement_put_length(IHTMLSelectElement *iface, LONG v)
406 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
409 TRACE("(%p)->(%d)\n", This, v);
411 nsres = nsIDOMHTMLSelectElement_SetLength(This->nsselect, v);
413 ERR("SetLength failed: %08x\n", nsres);
418 static HRESULT WINAPI HTMLSelectElement_get_length(IHTMLSelectElement *iface, LONG *p)
420 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
424 TRACE("(%p)->(%p)\n", This, p);
426 nsres = nsIDOMHTMLSelectElement_GetLength(This->nsselect, &length);
428 ERR("GetLength failed: %08x\n", nsres);
432 TRACE("ret %d\n", *p);
436 static HRESULT WINAPI HTMLSelectElement_get__newEnum(IHTMLSelectElement *iface, IUnknown **p)
438 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
439 FIXME("(%p)->(%p)\n", This, p);
443 static HRESULT WINAPI HTMLSelectElement_item(IHTMLSelectElement *iface, VARIANT name,
444 VARIANT index, IDispatch **pdisp)
446 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
448 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
454 if(V_VT(&name) == VT_I4) {
457 return htmlselect_item(This, V_I4(&name), pdisp);
460 FIXME("Unsupported args\n");
464 static HRESULT WINAPI HTMLSelectElement_tags(IHTMLSelectElement *iface, VARIANT tagName,
467 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
468 FIXME("(%p)->(v %p)\n", This, pdisp);
472 #undef HTMLSELECT_THIS
474 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl = {
475 HTMLSelectElement_QueryInterface,
476 HTMLSelectElement_AddRef,
477 HTMLSelectElement_Release,
478 HTMLSelectElement_GetTypeInfoCount,
479 HTMLSelectElement_GetTypeInfo,
480 HTMLSelectElement_GetIDsOfNames,
481 HTMLSelectElement_Invoke,
482 HTMLSelectElement_put_size,
483 HTMLSelectElement_get_size,
484 HTMLSelectElement_put_multiple,
485 HTMLSelectElement_get_multiple,
486 HTMLSelectElement_put_name,
487 HTMLSelectElement_get_name,
488 HTMLSelectElement_get_options,
489 HTMLSelectElement_put_onchange,
490 HTMLSelectElement_get_onchange,
491 HTMLSelectElement_put_selectedIndex,
492 HTMLSelectElement_get_selectedIndex,
493 HTMLSelectElement_get_type,
494 HTMLSelectElement_put_value,
495 HTMLSelectElement_get_value,
496 HTMLSelectElement_put_disabled,
497 HTMLSelectElement_get_disabled,
498 HTMLSelectElement_get_form,
499 HTMLSelectElement_add,
500 HTMLSelectElement_remove,
501 HTMLSelectElement_put_length,
502 HTMLSelectElement_get_length,
503 HTMLSelectElement_get__newEnum,
504 HTMLSelectElement_item,
505 HTMLSelectElement_tags
508 #define HTMLSELECT_NODE_THIS(iface) DEFINE_THIS2(HTMLSelectElement, element.node, iface)
510 static HRESULT HTMLSelectElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
512 HTMLSelectElement *This = HTMLSELECT_NODE_THIS(iface);
516 if(IsEqualGUID(&IID_IUnknown, riid)) {
517 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
518 *ppv = HTMLSELECT(This);
519 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
520 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
521 *ppv = HTMLSELECT(This);
522 }else if(IsEqualGUID(&IID_IHTMLSelectElement, riid)) {
523 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This, ppv);
524 *ppv = HTMLSELECT(This);
528 IUnknown_AddRef((IUnknown*)*ppv);
532 return HTMLElement_QI(&This->element.node, riid, ppv);
535 static void HTMLSelectElement_destructor(HTMLDOMNode *iface)
537 HTMLSelectElement *This = HTMLSELECT_NODE_THIS(iface);
539 nsIDOMHTMLSelectElement_Release(This->nsselect);
541 HTMLElement_destructor(&This->element.node);
544 static HRESULT HTMLSelectElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
546 HTMLSelectElement *This = HTMLSELECT_NODE_THIS(iface);
547 return IHTMLSelectElement_put_disabled(HTMLSELECT(This), v);
550 static HRESULT HTMLSelectElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
552 HTMLSelectElement *This = HTMLSELECT_NODE_THIS(iface);
553 return IHTMLSelectElement_get_disabled(HTMLSELECT(This), p);
556 #define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN
558 static HRESULT HTMLSelectElement_get_dispid(HTMLDOMNode *iface, BSTR name, DWORD flags, DISPID *dispid)
563 for(ptr = name; *ptr && isdigitW(*ptr); ptr++) {
564 idx = idx*10 + (*ptr-'0');
565 if(idx > MSHTML_CUSTOM_DISPID_CNT) {
566 WARN("too big idx\n");
567 return DISP_E_UNKNOWNNAME;
571 return DISP_E_UNKNOWNNAME;
573 *dispid = DISPID_OPTIONCOL_0 + idx;
577 static HRESULT HTMLSelectElement_invoke(HTMLDOMNode *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
578 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
580 HTMLSelectElement *This = HTMLSELECT_NODE_THIS(iface);
582 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
585 case DISPATCH_PROPERTYGET: {
589 hres = htmlselect_item(This, id-DISPID_OPTIONCOL_0, &ret);
594 V_VT(res) = VT_DISPATCH;
595 V_DISPATCH(res) = ret;
603 FIXME("unimplemented flags %x\n", flags);
610 #undef HTMLSELECT_NODE_THIS
612 static const NodeImplVtbl HTMLSelectElementImplVtbl = {
613 HTMLSelectElement_QI,
614 HTMLSelectElement_destructor,
618 HTMLSelectElementImpl_put_disabled,
619 HTMLSelectElementImpl_get_disabled,
622 HTMLSelectElement_get_dispid,
623 HTMLSelectElement_invoke
626 static const tid_t HTMLSelectElement_tids[] = {
628 IHTMLSelectElement_tid,
632 static dispex_static_data_t HTMLSelectElement_dispex = {
634 DispHTMLSelectElement_tid,
636 HTMLSelectElement_tids
639 HTMLElement *HTMLSelectElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
641 HTMLSelectElement *ret = heap_alloc_zero(sizeof(HTMLSelectElement));
644 ret->lpHTMLSelectElementVtbl = &HTMLSelectElementVtbl;
645 ret->element.node.vtbl = &HTMLSelectElementImplVtbl;
647 HTMLElement_Init(&ret->element, doc, nselem, &HTMLSelectElement_dispex);
649 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLSelectElement,
650 (void**)&ret->nsselect);
652 ERR("Could not get nsIDOMHTMLSelectElement interfce: %08x\n", nsres);
654 return &ret->element;