user32: Move unpack_message call to User32CallWindowProc.
[wine.git] / dlls / mshtml / htmlselect.c
blob44981a51d3c613d61e3a63bdcf4c426078ecb4ce
1 /*
2 * Copyright 2006,2007 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
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"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 struct HTMLOptionElement {
36 HTMLElement element;
38 IHTMLOptionElement IHTMLOptionElement_iface;
40 nsIDOMHTMLOptionElement *nsoption;
43 static inline HTMLOptionElement *impl_from_IHTMLOptionElement(IHTMLOptionElement *iface)
45 return CONTAINING_RECORD(iface, HTMLOptionElement, IHTMLOptionElement_iface);
48 static HRESULT WINAPI HTMLOptionElement_QueryInterface(IHTMLOptionElement *iface,
49 REFIID riid, void **ppv)
51 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
53 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
56 static ULONG WINAPI HTMLOptionElement_AddRef(IHTMLOptionElement *iface)
58 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
60 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
63 static ULONG WINAPI HTMLOptionElement_Release(IHTMLOptionElement *iface)
65 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
67 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
70 static HRESULT WINAPI HTMLOptionElement_GetTypeInfoCount(IHTMLOptionElement *iface, UINT *pctinfo)
72 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
73 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
76 static HRESULT WINAPI HTMLOptionElement_GetTypeInfo(IHTMLOptionElement *iface, UINT iTInfo,
77 LCID lcid, ITypeInfo **ppTInfo)
79 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
80 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
81 ppTInfo);
84 static HRESULT WINAPI HTMLOptionElement_GetIDsOfNames(IHTMLOptionElement *iface, REFIID riid,
85 LPOLESTR *rgszNames, UINT cNames,
86 LCID lcid, DISPID *rgDispId)
88 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
89 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
90 cNames, lcid, rgDispId);
93 static HRESULT WINAPI HTMLOptionElement_Invoke(IHTMLOptionElement *iface, DISPID dispIdMember,
94 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
95 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
97 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
98 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
99 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
102 static HRESULT WINAPI HTMLOptionElement_put_selected(IHTMLOptionElement *iface, VARIANT_BOOL v)
104 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
105 nsresult nsres;
107 TRACE("(%p)->(%x)\n", This, v);
109 nsres = nsIDOMHTMLOptionElement_SetSelected(This->nsoption, v != VARIANT_FALSE);
110 if(NS_FAILED(nsres)) {
111 ERR("SetSelected failed: %08lx\n", nsres);
112 return E_FAIL;
115 return S_OK;
118 static HRESULT WINAPI HTMLOptionElement_get_selected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
120 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
121 cpp_bool selected;
122 nsresult nsres;
124 TRACE("(%p)->(%p)\n", This, p);
126 nsres = nsIDOMHTMLOptionElement_GetSelected(This->nsoption, &selected);
127 if(NS_FAILED(nsres)) {
128 ERR("GetSelected failed: %08lx\n", nsres);
129 return E_FAIL;
132 *p = variant_bool(selected);
133 return S_OK;
136 static HRESULT WINAPI HTMLOptionElement_put_value(IHTMLOptionElement *iface, BSTR v)
138 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
139 nsAString value_str;
140 nsresult nsres;
142 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
144 nsAString_InitDepend(&value_str, v);
145 nsres = nsIDOMHTMLOptionElement_SetValue(This->nsoption, &value_str);
146 nsAString_Finish(&value_str);
147 if(NS_FAILED(nsres))
148 ERR("SetValue failed: %08lx\n", nsres);
150 return S_OK;
153 static HRESULT WINAPI HTMLOptionElement_get_value(IHTMLOptionElement *iface, BSTR *p)
155 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
156 nsAString value_str;
157 nsresult nsres;
159 TRACE("(%p)->(%p)\n", This, p);
161 nsAString_Init(&value_str, NULL);
162 nsres = nsIDOMHTMLOptionElement_GetValue(This->nsoption, &value_str);
163 return return_nsstr(nsres, &value_str, p);
166 static HRESULT WINAPI HTMLOptionElement_put_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL v)
168 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
169 cpp_bool val, selected;
170 nsresult nsres;
172 TRACE("(%p)->(%x)\n", This, v);
174 val = (v == VARIANT_TRUE);
176 nsres = nsIDOMHTMLOptionElement_GetSelected(This->nsoption, &selected);
177 if(NS_FAILED(nsres)) {
178 ERR("GetSelected failed: %08lx\n", nsres);
179 return E_FAIL;
182 nsres = nsIDOMHTMLOptionElement_SetDefaultSelected(This->nsoption, val);
183 if(NS_FAILED(nsres)) {
184 ERR("SetDefaultSelected failed: %08lx\n", nsres);
185 return E_FAIL;
188 if(val != selected) {
189 nsres = nsIDOMHTMLOptionElement_SetSelected(This->nsoption, selected); /* WinAPI will reserve selected property */
190 if(NS_FAILED(nsres)) {
191 ERR("SetSelected failed: %08lx\n", nsres);
192 return E_FAIL;
196 return S_OK;
199 static HRESULT WINAPI HTMLOptionElement_get_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
201 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
202 cpp_bool val;
203 nsresult nsres;
205 TRACE("(%p)->(%p)\n", This, p);
206 if(!p)
207 return E_POINTER;
208 nsres = nsIDOMHTMLOptionElement_GetDefaultSelected(This->nsoption, &val);
209 if(NS_FAILED(nsres)) {
210 ERR("GetDefaultSelected failed: %08lx\n", nsres);
211 return E_FAIL;
214 *p = variant_bool(val);
215 return S_OK;
218 static HRESULT WINAPI HTMLOptionElement_put_index(IHTMLOptionElement *iface, LONG v)
220 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
221 FIXME("(%p)->(%ld)\n", This, v);
222 return E_NOTIMPL;
225 static HRESULT WINAPI HTMLOptionElement_get_index(IHTMLOptionElement *iface, LONG *p)
227 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
228 LONG val;
229 nsresult nsres;
231 TRACE("(%p)->(%p)\n", This, p);
233 if(!p)
234 return E_INVALIDARG;
236 nsres = nsIDOMHTMLOptionElement_GetIndex(This->nsoption, &val);
237 if(NS_FAILED(nsres)) {
238 ERR("GetIndex failed: %08lx\n", nsres);
239 return E_FAIL;
241 *p = val;
242 return S_OK;
245 static HRESULT WINAPI HTMLOptionElement_put_text(IHTMLOptionElement *iface, BSTR v)
247 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
248 nsIDOMText *text_node;
249 nsAString text_str;
250 nsIDOMNode *tmp;
251 nsresult nsres;
253 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
255 if(!This->element.node.doc->nsdoc) {
256 WARN("NULL nsdoc\n");
257 return E_UNEXPECTED;
260 while(1) {
261 nsIDOMNode *child;
263 nsres = nsIDOMElement_GetFirstChild(This->element.dom_element, &child);
264 if(NS_FAILED(nsres) || !child)
265 break;
267 nsres = nsIDOMElement_RemoveChild(This->element.dom_element, child, &tmp);
268 nsIDOMNode_Release(child);
269 if(NS_SUCCEEDED(nsres)) {
270 nsIDOMNode_Release(tmp);
271 }else {
272 ERR("RemoveChild failed: %08lx\n", nsres);
273 break;
277 nsAString_InitDepend(&text_str, v);
278 nsres = nsIDOMHTMLDocument_CreateTextNode(This->element.node.doc->nsdoc, &text_str, &text_node);
279 nsAString_Finish(&text_str);
280 if(NS_FAILED(nsres)) {
281 ERR("CreateTextNode failed: %08lx\n", nsres);
282 return E_FAIL;
285 nsres = nsIDOMElement_AppendChild(This->element.dom_element, (nsIDOMNode*)text_node, &tmp);
286 if(NS_SUCCEEDED(nsres))
287 nsIDOMNode_Release(tmp);
288 else
289 ERR("AppendChild failed: %08lx\n", nsres);
291 return S_OK;
294 static HRESULT WINAPI HTMLOptionElement_get_text(IHTMLOptionElement *iface, BSTR *p)
296 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
297 nsAString text_str;
298 nsresult nsres;
300 TRACE("(%p)->(%p)\n", This, p);
302 nsAString_Init(&text_str, NULL);
303 nsres = nsIDOMHTMLOptionElement_GetText(This->nsoption, &text_str);
304 return return_nsstr(nsres, &text_str, p);
307 static HRESULT WINAPI HTMLOptionElement_get_form(IHTMLOptionElement *iface, IHTMLFormElement **p)
309 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
310 nsIDOMHTMLFormElement *nsform;
311 nsresult nsres;
313 TRACE("(%p)->(%p)\n", This, p);
315 if(!p)
316 return E_POINTER;
318 nsres = nsIDOMHTMLOptionElement_GetForm(This->nsoption, &nsform);
319 return return_nsform(nsres, nsform, p);
322 static const IHTMLOptionElementVtbl HTMLOptionElementVtbl = {
323 HTMLOptionElement_QueryInterface,
324 HTMLOptionElement_AddRef,
325 HTMLOptionElement_Release,
326 HTMLOptionElement_GetTypeInfoCount,
327 HTMLOptionElement_GetTypeInfo,
328 HTMLOptionElement_GetIDsOfNames,
329 HTMLOptionElement_Invoke,
330 HTMLOptionElement_put_selected,
331 HTMLOptionElement_get_selected,
332 HTMLOptionElement_put_value,
333 HTMLOptionElement_get_value,
334 HTMLOptionElement_put_defaultSelected,
335 HTMLOptionElement_get_defaultSelected,
336 HTMLOptionElement_put_index,
337 HTMLOptionElement_get_index,
338 HTMLOptionElement_put_text,
339 HTMLOptionElement_get_text,
340 HTMLOptionElement_get_form
343 static inline HTMLOptionElement *HTMLOptionElement_from_HTMLDOMNode(HTMLDOMNode *iface)
345 return CONTAINING_RECORD(iface, HTMLOptionElement, element.node);
348 static HRESULT HTMLOptionElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
350 HTMLOptionElement *This = HTMLOptionElement_from_HTMLDOMNode(iface);
352 *ppv = NULL;
354 if(IsEqualGUID(&IID_IUnknown, riid)) {
355 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
356 *ppv = &This->IHTMLOptionElement_iface;
357 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
358 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
359 *ppv = &This->IHTMLOptionElement_iface;
360 }else if(IsEqualGUID(&IID_IHTMLOptionElement, riid)) {
361 TRACE("(%p)->(IID_IHTMLOptionElement %p)\n", This, ppv);
362 *ppv = &This->IHTMLOptionElement_iface;
365 if(*ppv) {
366 IUnknown_AddRef((IUnknown*)*ppv);
367 return S_OK;
370 return HTMLElement_QI(&This->element.node, riid, ppv);
373 static void HTMLOptionElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
375 HTMLOptionElement *This = HTMLOptionElement_from_HTMLDOMNode(iface);
377 if(This->nsoption)
378 note_cc_edge((nsISupports*)This->nsoption, "This->nsoption", cb);
381 static void HTMLOptionElement_unlink(HTMLDOMNode *iface)
383 HTMLOptionElement *This = HTMLOptionElement_from_HTMLDOMNode(iface);
385 if(This->nsoption) {
386 nsIDOMHTMLOptionElement *nsoption = This->nsoption;
388 This->nsoption = NULL;
389 nsIDOMHTMLOptionElement_Release(nsoption);
393 static const NodeImplVtbl HTMLOptionElementImplVtbl = {
394 &CLSID_HTMLOptionElement,
395 HTMLOptionElement_QI,
396 HTMLElement_destructor,
397 HTMLElement_cpc,
398 HTMLElement_clone,
399 HTMLElement_handle_event,
400 HTMLElement_get_attr_col,
401 NULL,
402 NULL,
403 NULL,
404 NULL,
405 NULL,
406 NULL,
407 NULL,
408 NULL,
409 HTMLOptionElement_traverse,
410 HTMLOptionElement_unlink
413 static const tid_t HTMLOptionElement_iface_tids[] = {
414 HTMLELEMENT_TIDS,
415 IHTMLOptionElement_tid,
418 static dispex_static_data_t HTMLOptionElement_dispex = {
419 L"HTMLOptionElement",
420 NULL,
421 DispHTMLOptionElement_tid,
422 HTMLOptionElement_iface_tids,
423 HTMLElement_init_dispex_info
426 HRESULT HTMLOptionElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
428 HTMLOptionElement *ret;
429 nsresult nsres;
431 ret = heap_alloc_zero(sizeof(HTMLOptionElement));
432 if(!ret)
433 return E_OUTOFMEMORY;
435 ret->IHTMLOptionElement_iface.lpVtbl = &HTMLOptionElementVtbl;
436 ret->element.node.vtbl = &HTMLOptionElementImplVtbl;
438 HTMLElement_Init(&ret->element, doc, nselem, &HTMLOptionElement_dispex);
440 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLOptionElement, (void**)&ret->nsoption);
441 assert(nsres == NS_OK);
443 *elem = &ret->element;
444 return S_OK;
447 static inline HTMLOptionElementFactory *impl_from_IHTMLOptionElementFactory(IHTMLOptionElementFactory *iface)
449 return CONTAINING_RECORD(iface, HTMLOptionElementFactory, IHTMLOptionElementFactory_iface);
452 static HRESULT WINAPI HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory *iface,
453 REFIID riid, void **ppv)
455 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
457 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
459 if(IsEqualGUID(&IID_IUnknown, riid)) {
460 *ppv = &This->IHTMLOptionElementFactory_iface;
461 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
462 *ppv = &This->IHTMLOptionElementFactory_iface;
463 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory, riid)) {
464 *ppv = &This->IHTMLOptionElementFactory_iface;
465 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
466 return *ppv ? S_OK : E_NOINTERFACE;
467 }else {
468 *ppv = NULL;
469 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
470 return E_NOINTERFACE;
473 IUnknown_AddRef((IUnknown*)*ppv);
474 return S_OK;
477 static ULONG WINAPI HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory *iface)
479 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
480 LONG ref = InterlockedIncrement(&This->ref);
482 TRACE("(%p) ref=%ld\n", This, ref);
484 return ref;
487 static ULONG WINAPI HTMLOptionElementFactory_Release(IHTMLOptionElementFactory *iface)
489 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
490 LONG ref = InterlockedDecrement(&This->ref);
492 TRACE("(%p) ref=%ld\n", This, ref);
494 if(!ref) {
495 release_dispex(&This->dispex);
496 heap_free(This);
499 return ref;
502 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory *iface, UINT *pctinfo)
504 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
505 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
508 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory *iface, UINT iTInfo,
509 LCID lcid, ITypeInfo **ppTInfo)
511 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
512 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
515 static HRESULT WINAPI HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory *iface, REFIID riid,
516 LPOLESTR *rgszNames, UINT cNames,
517 LCID lcid, DISPID *rgDispId)
519 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
520 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
523 static HRESULT WINAPI HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory *iface, DISPID dispIdMember,
524 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
525 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
527 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
528 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags, pDispParams,
529 pVarResult, pExcepInfo, puArgErr);
532 static HRESULT WINAPI HTMLOptionElementFactory_create(IHTMLOptionElementFactory *iface,
533 VARIANT text, VARIANT value, VARIANT defaultselected, VARIANT selected,
534 IHTMLOptionElement **optelem)
536 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
537 nsIDOMElement *nselem;
538 HTMLDOMNode *node;
539 HRESULT hres;
541 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_variant(&text), debugstr_variant(&value),
542 debugstr_variant(&defaultselected), debugstr_variant(&selected), optelem);
544 if(!This->window || !This->window->doc) {
545 WARN("NULL doc\n");
546 return E_UNEXPECTED;
549 *optelem = NULL;
551 hres = create_nselem(This->window->doc, L"OPTION", &nselem);
552 if(FAILED(hres))
553 return hres;
555 hres = get_node((nsIDOMNode*)nselem, TRUE, &node);
556 nsIDOMElement_Release(nselem);
557 if(FAILED(hres))
558 return hres;
560 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface,
561 &IID_IHTMLOptionElement, (void**)optelem);
562 node_release(node);
564 if(V_VT(&text) == VT_BSTR)
565 IHTMLOptionElement_put_text(*optelem, V_BSTR(&text));
566 else if(V_VT(&text) != VT_EMPTY)
567 FIXME("Unsupported text %s\n", debugstr_variant(&text));
569 if(V_VT(&value) == VT_BSTR)
570 IHTMLOptionElement_put_value(*optelem, V_BSTR(&value));
571 else if(V_VT(&value) != VT_EMPTY)
572 FIXME("Unsupported value %s\n", debugstr_variant(&value));
574 if(V_VT(&defaultselected) != VT_EMPTY)
575 FIXME("Unsupported defaultselected %s\n", debugstr_variant(&defaultselected));
576 if(V_VT(&selected) != VT_EMPTY)
577 FIXME("Unsupported selected %s\n", debugstr_variant(&selected));
579 return S_OK;
582 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl = {
583 HTMLOptionElementFactory_QueryInterface,
584 HTMLOptionElementFactory_AddRef,
585 HTMLOptionElementFactory_Release,
586 HTMLOptionElementFactory_GetTypeInfoCount,
587 HTMLOptionElementFactory_GetTypeInfo,
588 HTMLOptionElementFactory_GetIDsOfNames,
589 HTMLOptionElementFactory_Invoke,
590 HTMLOptionElementFactory_create
593 static inline HTMLOptionElementFactory *HTMLOptionElementFactory_from_DispatchEx(DispatchEx *iface)
595 return CONTAINING_RECORD(iface, HTMLOptionElementFactory, dispex);
598 static HRESULT HTMLOptionElementFactory_value(DispatchEx *dispex, LCID lcid,
599 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
600 IServiceProvider *caller)
602 HTMLOptionElementFactory *This = HTMLOptionElementFactory_from_DispatchEx(dispex);
603 unsigned int i, argc = params->cArgs - params->cNamedArgs;
604 IHTMLOptionElement *opt;
605 VARIANT empty, *arg[4];
606 HRESULT hres;
608 if(flags != DISPATCH_CONSTRUCT) {
609 FIXME("flags %x not supported\n", flags);
610 return E_NOTIMPL;
613 V_VT(res) = VT_NULL;
614 V_VT(&empty) = VT_EMPTY;
616 for(i = 0; i < ARRAY_SIZE(arg); i++)
617 arg[i] = argc > i ? &params->rgvarg[params->cArgs - 1 - i] : &empty;
619 hres = IHTMLOptionElementFactory_create(&This->IHTMLOptionElementFactory_iface,
620 *arg[0], *arg[1], *arg[2], *arg[3], &opt);
621 if(FAILED(hres))
622 return hres;
624 V_VT(res) = VT_DISPATCH;
625 V_DISPATCH(res) = (IDispatch*)opt;
627 return S_OK;
630 static const tid_t HTMLOptionElementFactory_iface_tids[] = {
631 IHTMLOptionElementFactory_tid,
635 static const dispex_static_data_vtbl_t HTMLOptionElementFactory_dispex_vtbl = {
636 HTMLOptionElementFactory_value,
637 NULL,
638 NULL,
639 NULL
642 static dispex_static_data_t HTMLOptionElementFactory_dispex = {
643 L"Function",
644 &HTMLOptionElementFactory_dispex_vtbl,
645 IHTMLOptionElementFactory_tid,
646 HTMLOptionElementFactory_iface_tids,
647 HTMLElement_init_dispex_info
650 HRESULT HTMLOptionElementFactory_Create(HTMLInnerWindow *window, HTMLOptionElementFactory **ret_ptr)
652 HTMLOptionElementFactory *ret;
654 ret = heap_alloc(sizeof(*ret));
655 if(!ret)
656 return E_OUTOFMEMORY;
658 ret->IHTMLOptionElementFactory_iface.lpVtbl = &HTMLOptionElementFactoryVtbl;
659 ret->ref = 1;
660 ret->window = window;
662 init_dispatch(&ret->dispex, (IUnknown*)&ret->IHTMLOptionElementFactory_iface,
663 &HTMLOptionElementFactory_dispex, dispex_compat_mode(&window->event_target.dispex));
665 *ret_ptr = ret;
666 return S_OK;
669 struct HTMLSelectElement {
670 HTMLElement element;
672 IHTMLSelectElement IHTMLSelectElement_iface;
674 nsIDOMHTMLSelectElement *nsselect;
677 static inline HTMLSelectElement *impl_from_IHTMLSelectElement(IHTMLSelectElement *iface)
679 return CONTAINING_RECORD(iface, HTMLSelectElement, IHTMLSelectElement_iface);
682 static HRESULT htmlselect_item(HTMLSelectElement *This, int i, IDispatch **ret)
684 nsIDOMHTMLOptionsCollection *nscol;
685 nsIDOMNode *nsnode;
686 nsresult nsres;
687 HRESULT hres;
689 nsres = nsIDOMHTMLSelectElement_GetOptions(This->nsselect, &nscol);
690 if(NS_FAILED(nsres)) {
691 ERR("GetOptions failed: %08lx\n", nsres);
692 return E_FAIL;
695 nsres = nsIDOMHTMLOptionsCollection_Item(nscol, i, &nsnode);
696 nsIDOMHTMLOptionsCollection_Release(nscol);
697 if(NS_FAILED(nsres)) {
698 ERR("Item failed: %08lx\n", nsres);
699 return E_FAIL;
702 if(nsnode) {
703 HTMLDOMNode *node;
705 hres = get_node(nsnode, TRUE, &node);
706 nsIDOMNode_Release(nsnode);
707 if(FAILED(hres))
708 return hres;
710 *ret = (IDispatch*)&node->IHTMLDOMNode_iface;
711 }else {
712 *ret = NULL;
714 return S_OK;
717 static HRESULT WINAPI HTMLSelectElement_QueryInterface(IHTMLSelectElement *iface,
718 REFIID riid, void **ppv)
720 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
722 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
725 static ULONG WINAPI HTMLSelectElement_AddRef(IHTMLSelectElement *iface)
727 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
729 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
732 static ULONG WINAPI HTMLSelectElement_Release(IHTMLSelectElement *iface)
734 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
736 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
739 static HRESULT WINAPI HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement *iface, UINT *pctinfo)
741 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
743 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
746 static HRESULT WINAPI HTMLSelectElement_GetTypeInfo(IHTMLSelectElement *iface, UINT iTInfo,
747 LCID lcid, ITypeInfo **ppTInfo)
749 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
751 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
752 ppTInfo);
755 static HRESULT WINAPI HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement *iface, REFIID riid,
756 LPOLESTR *rgszNames, UINT cNames,
757 LCID lcid, DISPID *rgDispId)
759 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
761 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
762 cNames, lcid, rgDispId);
765 static HRESULT WINAPI HTMLSelectElement_Invoke(IHTMLSelectElement *iface, DISPID dispIdMember,
766 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
767 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
769 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
771 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
772 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
775 static HRESULT WINAPI HTMLSelectElement_put_size(IHTMLSelectElement *iface, LONG v)
777 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
778 nsresult nsres;
780 TRACE("(%p)->(%ld)\n", This, v);
781 if(v < 0)
782 return CTL_E_INVALIDPROPERTYVALUE;
784 nsres = nsIDOMHTMLSelectElement_SetSize(This->nsselect, v);
785 if(NS_FAILED(nsres)) {
786 ERR("SetSize failed: %08lx\n", nsres);
787 return E_FAIL;
789 return S_OK;
792 static HRESULT WINAPI HTMLSelectElement_get_size(IHTMLSelectElement *iface, LONG *p)
794 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
795 UINT32 val;
796 nsresult nsres;
798 TRACE("(%p)->(%p)\n", This, p);
799 if(!p)
800 return E_INVALIDARG;
802 nsres = nsIDOMHTMLSelectElement_GetSize(This->nsselect, &val);
803 if(NS_FAILED(nsres)) {
804 ERR("GetSize failed: %08lx\n", nsres);
805 return E_FAIL;
807 *p = val;
808 return S_OK;
811 static HRESULT WINAPI HTMLSelectElement_put_multiple(IHTMLSelectElement *iface, VARIANT_BOOL v)
813 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
814 nsresult nsres;
816 TRACE("(%p)->(%x)\n", This, v);
818 nsres = nsIDOMHTMLSelectElement_SetMultiple(This->nsselect, !!v);
819 assert(nsres == NS_OK);
820 return S_OK;
823 static HRESULT WINAPI HTMLSelectElement_get_multiple(IHTMLSelectElement *iface, VARIANT_BOOL *p)
825 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
826 cpp_bool val;
827 nsresult nsres;
829 TRACE("(%p)->(%p)\n", This, p);
831 nsres = nsIDOMHTMLSelectElement_GetMultiple(This->nsselect, &val);
832 assert(nsres == NS_OK);
834 *p = variant_bool(val);
835 return S_OK;
838 static HRESULT WINAPI HTMLSelectElement_put_name(IHTMLSelectElement *iface, BSTR v)
840 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
841 nsAString str;
842 nsresult nsres;
844 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
845 nsAString_InitDepend(&str, v);
846 nsres = nsIDOMHTMLSelectElement_SetName(This->nsselect, &str);
847 nsAString_Finish(&str);
849 if(NS_FAILED(nsres)) {
850 ERR("SetName failed: %08lx\n", nsres);
851 return E_FAIL;
853 return S_OK;
856 static HRESULT WINAPI HTMLSelectElement_get_name(IHTMLSelectElement *iface, BSTR *p)
858 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
859 nsAString name_str;
860 nsresult nsres;
862 TRACE("(%p)->(%p)\n", This, p);
864 nsAString_Init(&name_str, NULL);
865 nsres = nsIDOMHTMLSelectElement_GetName(This->nsselect, &name_str);
867 return return_nsstr(nsres, &name_str, p);
870 static HRESULT WINAPI HTMLSelectElement_get_options(IHTMLSelectElement *iface, IDispatch **p)
872 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
874 TRACE("(%p)->(%p)\n", This, p);
876 *p = (IDispatch*)&This->IHTMLSelectElement_iface;
877 IDispatch_AddRef(*p);
878 return S_OK;
881 static HRESULT WINAPI HTMLSelectElement_put_onchange(IHTMLSelectElement *iface, VARIANT v)
883 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
885 TRACE("(%p)->()\n", This);
887 return set_node_event(&This->element.node, EVENTID_CHANGE, &v);
890 static HRESULT WINAPI HTMLSelectElement_get_onchange(IHTMLSelectElement *iface, VARIANT *p)
892 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
893 FIXME("(%p)->(%p)\n", This, p);
894 return E_NOTIMPL;
897 static HRESULT WINAPI HTMLSelectElement_put_selectedIndex(IHTMLSelectElement *iface, LONG v)
899 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
900 nsresult nsres;
902 TRACE("(%p)->(%ld)\n", This, v);
904 nsres = nsIDOMHTMLSelectElement_SetSelectedIndex(This->nsselect, v);
905 if(NS_FAILED(nsres))
906 ERR("SetSelectedIndex failed: %08lx\n", nsres);
908 return S_OK;
911 static HRESULT WINAPI HTMLSelectElement_get_selectedIndex(IHTMLSelectElement *iface, LONG *p)
913 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
914 nsresult nsres;
916 TRACE("(%p)->(%p)\n", This, p);
918 nsres = nsIDOMHTMLSelectElement_GetSelectedIndex(This->nsselect, p);
919 if(NS_FAILED(nsres)) {
920 ERR("GetSelectedIndex failed: %08lx\n", nsres);
921 return E_FAIL;
924 return S_OK;
927 static HRESULT WINAPI HTMLSelectElement_get_type(IHTMLSelectElement *iface, BSTR *p)
929 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
930 nsAString type_str;
931 nsresult nsres;
933 TRACE("(%p)->(%p)\n", This, p);
935 nsAString_Init(&type_str, NULL);
936 nsres = nsIDOMHTMLSelectElement_GetType(This->nsselect, &type_str);
937 return return_nsstr(nsres, &type_str, p);
940 static HRESULT WINAPI HTMLSelectElement_put_value(IHTMLSelectElement *iface, BSTR v)
942 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
943 nsAString value_str;
944 nsresult nsres;
946 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
948 nsAString_InitDepend(&value_str, v);
949 nsres = nsIDOMHTMLSelectElement_SetValue(This->nsselect, &value_str);
950 nsAString_Finish(&value_str);
951 if(NS_FAILED(nsres))
952 ERR("SetValue failed: %08lx\n", nsres);
954 return S_OK;
957 static HRESULT WINAPI HTMLSelectElement_get_value(IHTMLSelectElement *iface, BSTR *p)
959 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
960 nsAString value_str;
961 nsresult nsres;
963 TRACE("(%p)->(%p)\n", This, p);
965 nsAString_Init(&value_str, NULL);
966 nsres = nsIDOMHTMLSelectElement_GetValue(This->nsselect, &value_str);
967 return return_nsstr(nsres, &value_str, p);
970 static HRESULT WINAPI HTMLSelectElement_put_disabled(IHTMLSelectElement *iface, VARIANT_BOOL v)
972 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
973 nsresult nsres;
975 TRACE("(%p)->(%x)\n", This, v);
977 nsres = nsIDOMHTMLSelectElement_SetDisabled(This->nsselect, v != VARIANT_FALSE);
978 if(NS_FAILED(nsres)) {
979 ERR("SetDisabled failed: %08lx\n", nsres);
980 return E_FAIL;
983 return S_OK;
986 static HRESULT WINAPI HTMLSelectElement_get_disabled(IHTMLSelectElement *iface, VARIANT_BOOL *p)
988 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
989 cpp_bool disabled = FALSE;
990 nsresult nsres;
992 TRACE("(%p)->(%p)\n", This, p);
994 nsres = nsIDOMHTMLSelectElement_GetDisabled(This->nsselect, &disabled);
995 if(NS_FAILED(nsres)) {
996 ERR("GetDisabled failed: %08lx\n", nsres);
997 return E_FAIL;
1000 *p = variant_bool(disabled);
1001 return S_OK;
1004 static HRESULT WINAPI HTMLSelectElement_get_form(IHTMLSelectElement *iface, IHTMLFormElement **p)
1006 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1007 nsIDOMHTMLFormElement *nsform;
1008 nsresult nsres;
1010 TRACE("(%p)->(%p)\n", This, p);
1012 if(!p)
1013 return E_POINTER;
1015 nsres = nsIDOMHTMLSelectElement_GetForm(This->nsselect, &nsform);
1016 return return_nsform(nsres, nsform, p);
1019 static HRESULT WINAPI HTMLSelectElement_add(IHTMLSelectElement *iface, IHTMLElement *element,
1020 VARIANT before)
1022 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1023 nsIWritableVariant *nsvariant;
1024 HTMLElement *element_obj;
1025 nsresult nsres;
1027 TRACE("(%p)->(%p %s)\n", This, element, debugstr_variant(&before));
1029 element_obj = unsafe_impl_from_IHTMLElement(element);
1030 if(!element_obj) {
1031 FIXME("External IHTMLElement implementation?\n");
1032 return E_INVALIDARG;
1035 if(!element_obj->html_element) {
1036 FIXME("Not HTML element\n");
1037 return E_NOTIMPL;
1040 nsvariant = create_nsvariant();
1041 if(!nsvariant)
1042 return E_FAIL;
1044 switch(V_VT(&before)) {
1045 case VT_EMPTY:
1046 case VT_ERROR:
1047 nsres = nsIWritableVariant_SetAsEmpty(nsvariant);
1048 break;
1049 case VT_I2:
1050 nsres = nsIWritableVariant_SetAsInt16(nsvariant, V_I2(&before));
1051 break;
1052 default:
1053 FIXME("unhandled before %s\n", debugstr_variant(&before));
1054 nsIWritableVariant_Release(nsvariant);
1055 return E_NOTIMPL;
1058 if(NS_SUCCEEDED(nsres))
1059 nsres = nsIDOMHTMLSelectElement_Add(This->nsselect, element_obj->html_element, (nsIVariant*)nsvariant);
1060 nsIWritableVariant_Release(nsvariant);
1061 if(NS_FAILED(nsres)) {
1062 ERR("Add failed: %08lx\n", nsres);
1063 return E_FAIL;
1066 return S_OK;
1069 static HRESULT WINAPI HTMLSelectElement_remove(IHTMLSelectElement *iface, LONG index)
1071 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1072 nsresult nsres;
1073 TRACE("(%p)->(%ld)\n", This, index);
1074 if(index < 0)
1075 return E_INVALIDARG;
1077 nsres = nsIDOMHTMLSelectElement_select_Remove(This->nsselect, index);
1078 if(NS_FAILED(nsres)) {
1079 ERR("Remove failed: %08lx\n", nsres);
1080 return E_FAIL;
1082 return S_OK;
1085 static HRESULT WINAPI HTMLSelectElement_put_length(IHTMLSelectElement *iface, LONG v)
1087 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1088 nsresult nsres;
1090 TRACE("(%p)->(%ld)\n", This, v);
1092 nsres = nsIDOMHTMLSelectElement_SetLength(This->nsselect, v);
1093 if(NS_FAILED(nsres))
1094 ERR("SetLength failed: %08lx\n", nsres);
1096 return S_OK;
1099 static HRESULT WINAPI HTMLSelectElement_get_length(IHTMLSelectElement *iface, LONG *p)
1101 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1102 UINT32 length = 0;
1103 nsresult nsres;
1105 TRACE("(%p)->(%p)\n", This, p);
1107 nsres = nsIDOMHTMLSelectElement_GetLength(This->nsselect, &length);
1108 if(NS_FAILED(nsres))
1109 ERR("GetLength failed: %08lx\n", nsres);
1111 *p = length;
1113 TRACE("ret %ld\n", *p);
1114 return S_OK;
1117 static HRESULT WINAPI HTMLSelectElement_get__newEnum(IHTMLSelectElement *iface, IUnknown **p)
1119 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1120 FIXME("(%p)->(%p)\n", This, p);
1121 return E_NOTIMPL;
1124 static HRESULT WINAPI HTMLSelectElement_item(IHTMLSelectElement *iface, VARIANT name,
1125 VARIANT index, IDispatch **pdisp)
1127 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1129 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
1131 if(!pdisp)
1132 return E_POINTER;
1133 *pdisp = NULL;
1135 if(V_VT(&name) == VT_I4) {
1136 if(V_I4(&name) < 0)
1137 return E_INVALIDARG;
1138 return htmlselect_item(This, V_I4(&name), pdisp);
1141 FIXME("Unsupported args\n");
1142 return E_NOTIMPL;
1145 static HRESULT WINAPI HTMLSelectElement_tags(IHTMLSelectElement *iface, VARIANT tagName,
1146 IDispatch **pdisp)
1148 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1149 FIXME("(%p)->(v %p)\n", This, pdisp);
1150 return E_NOTIMPL;
1153 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl = {
1154 HTMLSelectElement_QueryInterface,
1155 HTMLSelectElement_AddRef,
1156 HTMLSelectElement_Release,
1157 HTMLSelectElement_GetTypeInfoCount,
1158 HTMLSelectElement_GetTypeInfo,
1159 HTMLSelectElement_GetIDsOfNames,
1160 HTMLSelectElement_Invoke,
1161 HTMLSelectElement_put_size,
1162 HTMLSelectElement_get_size,
1163 HTMLSelectElement_put_multiple,
1164 HTMLSelectElement_get_multiple,
1165 HTMLSelectElement_put_name,
1166 HTMLSelectElement_get_name,
1167 HTMLSelectElement_get_options,
1168 HTMLSelectElement_put_onchange,
1169 HTMLSelectElement_get_onchange,
1170 HTMLSelectElement_put_selectedIndex,
1171 HTMLSelectElement_get_selectedIndex,
1172 HTMLSelectElement_get_type,
1173 HTMLSelectElement_put_value,
1174 HTMLSelectElement_get_value,
1175 HTMLSelectElement_put_disabled,
1176 HTMLSelectElement_get_disabled,
1177 HTMLSelectElement_get_form,
1178 HTMLSelectElement_add,
1179 HTMLSelectElement_remove,
1180 HTMLSelectElement_put_length,
1181 HTMLSelectElement_get_length,
1182 HTMLSelectElement_get__newEnum,
1183 HTMLSelectElement_item,
1184 HTMLSelectElement_tags
1187 static inline HTMLSelectElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1189 return CONTAINING_RECORD(iface, HTMLSelectElement, element.node);
1192 static HRESULT HTMLSelectElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1194 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1196 *ppv = NULL;
1198 if(IsEqualGUID(&IID_IUnknown, riid)) {
1199 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1200 *ppv = &This->IHTMLSelectElement_iface;
1201 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1202 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1203 *ppv = &This->IHTMLSelectElement_iface;
1204 }else if(IsEqualGUID(&IID_IHTMLSelectElement, riid)) {
1205 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This, ppv);
1206 *ppv = &This->IHTMLSelectElement_iface;
1209 if(*ppv) {
1210 IUnknown_AddRef((IUnknown*)*ppv);
1211 return S_OK;
1214 return HTMLElement_QI(&This->element.node, riid, ppv);
1217 static HRESULT HTMLSelectElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
1219 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1220 return IHTMLSelectElement_put_disabled(&This->IHTMLSelectElement_iface, v);
1223 static HRESULT HTMLSelectElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
1225 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1226 return IHTMLSelectElement_get_disabled(&This->IHTMLSelectElement_iface, p);
1229 #define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN
1231 static HRESULT HTMLSelectElement_get_dispid(HTMLDOMNode *iface, BSTR name, DWORD flags, DISPID *dispid)
1233 const WCHAR *ptr;
1234 DWORD idx = 0;
1236 for(ptr = name; *ptr && is_digit(*ptr); ptr++) {
1237 idx = idx*10 + (*ptr-'0');
1238 if(idx > MSHTML_CUSTOM_DISPID_CNT) {
1239 WARN("too big idx\n");
1240 return DISP_E_UNKNOWNNAME;
1243 if(*ptr)
1244 return DISP_E_UNKNOWNNAME;
1246 *dispid = DISPID_OPTIONCOL_0 + idx;
1247 return S_OK;
1250 static HRESULT HTMLSelectElement_invoke(HTMLDOMNode *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1251 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1253 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1255 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
1257 switch(flags) {
1258 case DISPATCH_PROPERTYGET: {
1259 IDispatch *ret;
1260 HRESULT hres;
1262 hres = htmlselect_item(This, id-DISPID_OPTIONCOL_0, &ret);
1263 if(FAILED(hres))
1264 return hres;
1266 if(ret) {
1267 V_VT(res) = VT_DISPATCH;
1268 V_DISPATCH(res) = ret;
1269 }else {
1270 V_VT(res) = VT_NULL;
1272 break;
1275 default:
1276 FIXME("unimplemented flags %x\n", flags);
1277 return E_NOTIMPL;
1280 return S_OK;
1283 static void HTMLSelectElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
1285 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1287 if(This->nsselect)
1288 note_cc_edge((nsISupports*)This->nsselect, "This->nsselect", cb);
1291 static void HTMLSelectElement_unlink(HTMLDOMNode *iface)
1293 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1295 if(This->nsselect) {
1296 nsIDOMHTMLSelectElement *nsselect = This->nsselect;
1298 This->nsselect = NULL;
1299 nsIDOMHTMLSelectElement_Release(nsselect);
1303 static const NodeImplVtbl HTMLSelectElementImplVtbl = {
1304 &CLSID_HTMLSelectElement,
1305 HTMLSelectElement_QI,
1306 HTMLElement_destructor,
1307 HTMLElement_cpc,
1308 HTMLElement_clone,
1309 HTMLElement_handle_event,
1310 HTMLElement_get_attr_col,
1311 NULL,
1312 HTMLSelectElementImpl_put_disabled,
1313 HTMLSelectElementImpl_get_disabled,
1314 NULL,
1315 NULL,
1316 HTMLSelectElement_get_dispid,
1317 HTMLSelectElement_invoke,
1318 NULL,
1319 HTMLSelectElement_traverse,
1320 HTMLSelectElement_unlink
1323 static const tid_t HTMLSelectElement_tids[] = {
1324 HTMLELEMENT_TIDS,
1325 IHTMLSelectElement_tid,
1329 static dispex_static_data_t HTMLSelectElement_dispex = {
1330 L"HTMLSelectElement",
1331 NULL,
1332 DispHTMLSelectElement_tid,
1333 HTMLSelectElement_tids,
1334 HTMLElement_init_dispex_info
1337 HRESULT HTMLSelectElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
1339 HTMLSelectElement *ret;
1340 nsresult nsres;
1342 ret = heap_alloc_zero(sizeof(HTMLSelectElement));
1343 if(!ret)
1344 return E_OUTOFMEMORY;
1346 ret->IHTMLSelectElement_iface.lpVtbl = &HTMLSelectElementVtbl;
1347 ret->element.node.vtbl = &HTMLSelectElementImplVtbl;
1349 HTMLElement_Init(&ret->element, doc, nselem, &HTMLSelectElement_dispex);
1351 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLSelectElement, (void**)&ret->nsselect);
1352 assert(nsres == NS_OK);
1354 *elem = &ret->element;
1355 return S_OK;