windows.networking.hostname/tests: Add IHostNameFactory::CreateHostName() tests.
[wine.git] / dlls / mshtml / htmlselect.c
blobbbe6fadebba8654cd62a8d2293f25731fdda05fb
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->dom_document) {
256 WARN("NULL dom_document\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 = nsIDOMDocument_CreateTextNode(This->element.node.doc->dom_document, &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 nsIDOMText_Release(text_node);
287 if(NS_SUCCEEDED(nsres))
288 nsIDOMNode_Release(tmp);
289 else
290 ERR("AppendChild failed: %08lx\n", nsres);
292 return S_OK;
295 static HRESULT WINAPI HTMLOptionElement_get_text(IHTMLOptionElement *iface, BSTR *p)
297 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
298 nsAString text_str;
299 nsresult nsres;
301 TRACE("(%p)->(%p)\n", This, p);
303 nsAString_Init(&text_str, NULL);
304 nsres = nsIDOMHTMLOptionElement_GetText(This->nsoption, &text_str);
305 return return_nsstr(nsres, &text_str, p);
308 static HRESULT WINAPI HTMLOptionElement_get_form(IHTMLOptionElement *iface, IHTMLFormElement **p)
310 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
311 nsIDOMHTMLFormElement *nsform;
312 nsresult nsres;
314 TRACE("(%p)->(%p)\n", This, p);
316 if(!p)
317 return E_POINTER;
319 nsres = nsIDOMHTMLOptionElement_GetForm(This->nsoption, &nsform);
320 return return_nsform(nsres, nsform, p);
323 static const IHTMLOptionElementVtbl HTMLOptionElementVtbl = {
324 HTMLOptionElement_QueryInterface,
325 HTMLOptionElement_AddRef,
326 HTMLOptionElement_Release,
327 HTMLOptionElement_GetTypeInfoCount,
328 HTMLOptionElement_GetTypeInfo,
329 HTMLOptionElement_GetIDsOfNames,
330 HTMLOptionElement_Invoke,
331 HTMLOptionElement_put_selected,
332 HTMLOptionElement_get_selected,
333 HTMLOptionElement_put_value,
334 HTMLOptionElement_get_value,
335 HTMLOptionElement_put_defaultSelected,
336 HTMLOptionElement_get_defaultSelected,
337 HTMLOptionElement_put_index,
338 HTMLOptionElement_get_index,
339 HTMLOptionElement_put_text,
340 HTMLOptionElement_get_text,
341 HTMLOptionElement_get_form
344 static inline HTMLOptionElement *HTMLOptionElement_from_HTMLDOMNode(HTMLDOMNode *iface)
346 return CONTAINING_RECORD(iface, HTMLOptionElement, element.node);
349 static HRESULT HTMLOptionElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
351 HTMLOptionElement *This = HTMLOptionElement_from_HTMLDOMNode(iface);
353 *ppv = NULL;
355 if(IsEqualGUID(&IID_IUnknown, riid)) {
356 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
357 *ppv = &This->IHTMLOptionElement_iface;
358 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
359 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
360 *ppv = &This->IHTMLOptionElement_iface;
361 }else if(IsEqualGUID(&IID_IHTMLOptionElement, riid)) {
362 TRACE("(%p)->(IID_IHTMLOptionElement %p)\n", This, ppv);
363 *ppv = &This->IHTMLOptionElement_iface;
366 if(*ppv) {
367 IUnknown_AddRef((IUnknown*)*ppv);
368 return S_OK;
371 return HTMLElement_QI(&This->element.node, riid, ppv);
374 static void HTMLOptionElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
376 HTMLOptionElement *This = HTMLOptionElement_from_HTMLDOMNode(iface);
378 if(This->nsoption)
379 note_cc_edge((nsISupports*)This->nsoption, "This->nsoption", cb);
382 static void HTMLOptionElement_unlink(HTMLDOMNode *iface)
384 HTMLOptionElement *This = HTMLOptionElement_from_HTMLDOMNode(iface);
386 if(This->nsoption) {
387 nsIDOMHTMLOptionElement *nsoption = This->nsoption;
389 This->nsoption = NULL;
390 nsIDOMHTMLOptionElement_Release(nsoption);
394 static const NodeImplVtbl HTMLOptionElementImplVtbl = {
395 &CLSID_HTMLOptionElement,
396 HTMLOptionElement_QI,
397 HTMLElement_destructor,
398 HTMLElement_cpc,
399 HTMLElement_clone,
400 HTMLElement_handle_event,
401 HTMLElement_get_attr_col,
402 NULL,
403 NULL,
404 NULL,
405 NULL,
406 NULL,
407 NULL,
408 NULL,
409 NULL,
410 NULL,
411 HTMLOptionElement_traverse,
412 HTMLOptionElement_unlink
415 static const tid_t HTMLOptionElement_iface_tids[] = {
416 HTMLELEMENT_TIDS,
417 IHTMLOptionElement_tid,
420 static dispex_static_data_t HTMLOptionElement_dispex = {
421 L"HTMLOptionElement",
422 NULL,
423 DispHTMLOptionElement_tid,
424 HTMLOptionElement_iface_tids,
425 HTMLElement_init_dispex_info
428 HRESULT HTMLOptionElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
430 HTMLOptionElement *ret;
431 nsresult nsres;
433 ret = calloc(1, sizeof(HTMLOptionElement));
434 if(!ret)
435 return E_OUTOFMEMORY;
437 ret->IHTMLOptionElement_iface.lpVtbl = &HTMLOptionElementVtbl;
438 ret->element.node.vtbl = &HTMLOptionElementImplVtbl;
440 HTMLElement_Init(&ret->element, doc, nselem, &HTMLOptionElement_dispex);
442 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLOptionElement, (void**)&ret->nsoption);
443 assert(nsres == NS_OK);
445 *elem = &ret->element;
446 return S_OK;
449 static inline HTMLOptionElementFactory *impl_from_IHTMLOptionElementFactory(IHTMLOptionElementFactory *iface)
451 return CONTAINING_RECORD(iface, HTMLOptionElementFactory, IHTMLOptionElementFactory_iface);
454 static HRESULT WINAPI HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory *iface,
455 REFIID riid, void **ppv)
457 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
459 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
461 if(IsEqualGUID(&IID_IUnknown, riid)) {
462 *ppv = &This->IHTMLOptionElementFactory_iface;
463 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
464 *ppv = &This->IHTMLOptionElementFactory_iface;
465 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory, riid)) {
466 *ppv = &This->IHTMLOptionElementFactory_iface;
467 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
468 return *ppv ? S_OK : E_NOINTERFACE;
469 }else {
470 *ppv = NULL;
471 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
472 return E_NOINTERFACE;
475 IUnknown_AddRef((IUnknown*)*ppv);
476 return S_OK;
479 static ULONG WINAPI HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory *iface)
481 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
482 LONG ref = InterlockedIncrement(&This->ref);
484 TRACE("(%p) ref=%ld\n", This, ref);
486 return ref;
489 static ULONG WINAPI HTMLOptionElementFactory_Release(IHTMLOptionElementFactory *iface)
491 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
492 LONG ref = InterlockedDecrement(&This->ref);
494 TRACE("(%p) ref=%ld\n", This, ref);
496 if(!ref) {
497 release_dispex(&This->dispex);
498 free(This);
501 return ref;
504 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory *iface, UINT *pctinfo)
506 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
507 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
510 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory *iface, UINT iTInfo,
511 LCID lcid, ITypeInfo **ppTInfo)
513 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
514 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
517 static HRESULT WINAPI HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory *iface, REFIID riid,
518 LPOLESTR *rgszNames, UINT cNames,
519 LCID lcid, DISPID *rgDispId)
521 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
522 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
525 static HRESULT WINAPI HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory *iface, DISPID dispIdMember,
526 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
527 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
529 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
530 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags, pDispParams,
531 pVarResult, pExcepInfo, puArgErr);
534 static HRESULT WINAPI HTMLOptionElementFactory_create(IHTMLOptionElementFactory *iface,
535 VARIANT text, VARIANT value, VARIANT defaultselected, VARIANT selected,
536 IHTMLOptionElement **optelem)
538 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
539 nsIDOMElement *nselem;
540 HTMLDOMNode *node;
541 HRESULT hres;
543 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_variant(&text), debugstr_variant(&value),
544 debugstr_variant(&defaultselected), debugstr_variant(&selected), optelem);
546 if(!This->window || !This->window->doc) {
547 WARN("NULL doc\n");
548 return E_UNEXPECTED;
551 *optelem = NULL;
553 hres = create_nselem(This->window->doc, L"OPTION", &nselem);
554 if(FAILED(hres))
555 return hres;
557 hres = get_node((nsIDOMNode*)nselem, TRUE, &node);
558 nsIDOMElement_Release(nselem);
559 if(FAILED(hres))
560 return hres;
562 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface,
563 &IID_IHTMLOptionElement, (void**)optelem);
564 node_release(node);
566 if(V_VT(&text) == VT_BSTR)
567 IHTMLOptionElement_put_text(*optelem, V_BSTR(&text));
568 else if(V_VT(&text) != VT_EMPTY)
569 FIXME("Unsupported text %s\n", debugstr_variant(&text));
571 if(V_VT(&value) == VT_BSTR)
572 IHTMLOptionElement_put_value(*optelem, V_BSTR(&value));
573 else if(V_VT(&value) != VT_EMPTY)
574 FIXME("Unsupported value %s\n", debugstr_variant(&value));
576 if(V_VT(&defaultselected) != VT_EMPTY)
577 FIXME("Unsupported defaultselected %s\n", debugstr_variant(&defaultselected));
578 if(V_VT(&selected) != VT_EMPTY)
579 FIXME("Unsupported selected %s\n", debugstr_variant(&selected));
581 return S_OK;
584 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl = {
585 HTMLOptionElementFactory_QueryInterface,
586 HTMLOptionElementFactory_AddRef,
587 HTMLOptionElementFactory_Release,
588 HTMLOptionElementFactory_GetTypeInfoCount,
589 HTMLOptionElementFactory_GetTypeInfo,
590 HTMLOptionElementFactory_GetIDsOfNames,
591 HTMLOptionElementFactory_Invoke,
592 HTMLOptionElementFactory_create
595 static inline HTMLOptionElementFactory *HTMLOptionElementFactory_from_DispatchEx(DispatchEx *iface)
597 return CONTAINING_RECORD(iface, HTMLOptionElementFactory, dispex);
600 static HRESULT HTMLOptionElementFactory_value(DispatchEx *dispex, LCID lcid,
601 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
602 IServiceProvider *caller)
604 HTMLOptionElementFactory *This = HTMLOptionElementFactory_from_DispatchEx(dispex);
605 unsigned int i, argc = params->cArgs - params->cNamedArgs;
606 IHTMLOptionElement *opt;
607 VARIANT empty, *arg[4];
608 HRESULT hres;
610 if(flags != DISPATCH_CONSTRUCT) {
611 FIXME("flags %x not supported\n", flags);
612 return E_NOTIMPL;
615 V_VT(res) = VT_NULL;
616 V_VT(&empty) = VT_EMPTY;
618 for(i = 0; i < ARRAY_SIZE(arg); i++)
619 arg[i] = argc > i ? &params->rgvarg[params->cArgs - 1 - i] : &empty;
621 hres = IHTMLOptionElementFactory_create(&This->IHTMLOptionElementFactory_iface,
622 *arg[0], *arg[1], *arg[2], *arg[3], &opt);
623 if(FAILED(hres))
624 return hres;
626 V_VT(res) = VT_DISPATCH;
627 V_DISPATCH(res) = (IDispatch*)opt;
629 return S_OK;
632 static const tid_t HTMLOptionElementFactory_iface_tids[] = {
633 IHTMLOptionElementFactory_tid,
637 static const dispex_static_data_vtbl_t HTMLOptionElementFactory_dispex_vtbl = {
638 HTMLOptionElementFactory_value,
639 NULL,
640 NULL,
641 NULL
644 static dispex_static_data_t HTMLOptionElementFactory_dispex = {
645 L"Function",
646 &HTMLOptionElementFactory_dispex_vtbl,
647 IHTMLOptionElementFactory_tid,
648 HTMLOptionElementFactory_iface_tids,
651 HRESULT HTMLOptionElementFactory_Create(HTMLInnerWindow *window, HTMLOptionElementFactory **ret_ptr)
653 HTMLOptionElementFactory *ret;
655 ret = malloc(sizeof(*ret));
656 if(!ret)
657 return E_OUTOFMEMORY;
659 ret->IHTMLOptionElementFactory_iface.lpVtbl = &HTMLOptionElementFactoryVtbl;
660 ret->ref = 1;
661 ret->window = window;
663 init_dispatch(&ret->dispex, (IUnknown*)&ret->IHTMLOptionElementFactory_iface,
664 &HTMLOptionElementFactory_dispex, dispex_compat_mode(&window->event_target.dispex));
666 *ret_ptr = ret;
667 return S_OK;
670 struct HTMLSelectElement {
671 HTMLElement element;
673 IHTMLSelectElement IHTMLSelectElement_iface;
675 nsIDOMHTMLSelectElement *nsselect;
678 typedef struct {
679 IEnumVARIANT IEnumVARIANT_iface;
681 LONG ref;
683 ULONG iter;
684 HTMLSelectElement *elem;
685 } HTMLSelectElementEnum;
687 static inline HTMLSelectElement *impl_from_IHTMLSelectElement(IHTMLSelectElement *iface)
689 return CONTAINING_RECORD(iface, HTMLSelectElement, IHTMLSelectElement_iface);
692 static HRESULT htmlselect_item(HTMLSelectElement *This, int i, IDispatch **ret)
694 nsIDOMHTMLOptionsCollection *nscol;
695 nsIDOMNode *nsnode;
696 nsresult nsres;
697 HRESULT hres;
699 nsres = nsIDOMHTMLSelectElement_GetOptions(This->nsselect, &nscol);
700 if(NS_FAILED(nsres)) {
701 ERR("GetOptions failed: %08lx\n", nsres);
702 return E_FAIL;
705 nsres = nsIDOMHTMLOptionsCollection_Item(nscol, i, &nsnode);
706 nsIDOMHTMLOptionsCollection_Release(nscol);
707 if(NS_FAILED(nsres)) {
708 ERR("Item failed: %08lx\n", nsres);
709 return E_FAIL;
712 if(nsnode) {
713 HTMLDOMNode *node;
715 hres = get_node(nsnode, TRUE, &node);
716 nsIDOMNode_Release(nsnode);
717 if(FAILED(hres))
718 return hres;
720 *ret = (IDispatch*)&node->IHTMLDOMNode_iface;
721 }else {
722 *ret = NULL;
724 return S_OK;
727 static inline HTMLSelectElementEnum *impl_from_IEnumVARIANT(IEnumVARIANT *iface)
729 return CONTAINING_RECORD(iface, HTMLSelectElementEnum, IEnumVARIANT_iface);
732 static HRESULT WINAPI HTMLSelectElementEnum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
734 HTMLSelectElementEnum *This = impl_from_IEnumVARIANT(iface);
736 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
738 if(IsEqualGUID(riid, &IID_IUnknown)) {
739 *ppv = &This->IEnumVARIANT_iface;
740 }else if(IsEqualGUID(riid, &IID_IEnumVARIANT)) {
741 *ppv = &This->IEnumVARIANT_iface;
742 }else {
743 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
744 *ppv = NULL;
745 return E_NOINTERFACE;
748 IUnknown_AddRef((IUnknown*)*ppv);
749 return S_OK;
752 static ULONG WINAPI HTMLSelectElementEnum_AddRef(IEnumVARIANT *iface)
754 HTMLSelectElementEnum *This = impl_from_IEnumVARIANT(iface);
755 LONG ref = InterlockedIncrement(&This->ref);
757 TRACE("(%p) ref=%ld\n", This, ref);
759 return ref;
762 static ULONG WINAPI HTMLSelectElementEnum_Release(IEnumVARIANT *iface)
764 HTMLSelectElementEnum *This = impl_from_IEnumVARIANT(iface);
765 LONG ref = InterlockedDecrement(&This->ref);
767 TRACE("(%p) ref=%ld\n", This, ref);
769 if(!ref) {
770 IHTMLSelectElement_Release(&This->elem->IHTMLSelectElement_iface);
771 free(This);
774 return ref;
777 static HRESULT WINAPI HTMLSelectElementEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
779 HTMLSelectElementEnum *This = impl_from_IEnumVARIANT(iface);
780 nsresult nsres;
781 HRESULT hres;
782 ULONG num, i;
783 UINT32 len;
785 TRACE("(%p)->(%lu %p %p)\n", This, celt, rgVar, pCeltFetched);
787 nsres = nsIDOMHTMLSelectElement_GetLength(This->elem->nsselect, &len);
788 if(NS_FAILED(nsres))
789 return E_FAIL;
790 num = min(len - This->iter, celt);
792 for(i = 0; i < num; i++) {
793 hres = htmlselect_item(This->elem, This->iter + i, &V_DISPATCH(&rgVar[i]));
794 if(FAILED(hres)) {
795 while(i--)
796 VariantClear(&rgVar[i]);
797 return hres;
799 V_VT(&rgVar[i]) = VT_DISPATCH;
802 This->iter += num;
803 if(pCeltFetched)
804 *pCeltFetched = num;
805 return num == celt ? S_OK : S_FALSE;
808 static HRESULT WINAPI HTMLSelectElementEnum_Skip(IEnumVARIANT *iface, ULONG celt)
810 HTMLSelectElementEnum *This = impl_from_IEnumVARIANT(iface);
811 nsresult nsres;
812 UINT32 len;
814 TRACE("(%p)->(%lu)\n", This, celt);
816 nsres = nsIDOMHTMLSelectElement_GetLength(This->elem->nsselect, &len);
817 if(NS_FAILED(nsres))
818 return E_FAIL;
820 if(This->iter + celt > len) {
821 This->iter = len;
822 return S_FALSE;
825 This->iter += celt;
826 return S_OK;
829 static HRESULT WINAPI HTMLSelectElementEnum_Reset(IEnumVARIANT *iface)
831 HTMLSelectElementEnum *This = impl_from_IEnumVARIANT(iface);
833 TRACE("(%p)->()\n", This);
835 This->iter = 0;
836 return S_OK;
839 static HRESULT WINAPI HTMLSelectElementEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
841 HTMLSelectElementEnum *This = impl_from_IEnumVARIANT(iface);
842 FIXME("(%p)->(%p)\n", This, ppEnum);
843 return E_NOTIMPL;
846 static const IEnumVARIANTVtbl HTMLSelectElementEnumVtbl = {
847 HTMLSelectElementEnum_QueryInterface,
848 HTMLSelectElementEnum_AddRef,
849 HTMLSelectElementEnum_Release,
850 HTMLSelectElementEnum_Next,
851 HTMLSelectElementEnum_Skip,
852 HTMLSelectElementEnum_Reset,
853 HTMLSelectElementEnum_Clone
856 static HRESULT WINAPI HTMLSelectElement_QueryInterface(IHTMLSelectElement *iface,
857 REFIID riid, void **ppv)
859 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
861 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
864 static ULONG WINAPI HTMLSelectElement_AddRef(IHTMLSelectElement *iface)
866 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
868 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
871 static ULONG WINAPI HTMLSelectElement_Release(IHTMLSelectElement *iface)
873 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
875 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
878 static HRESULT WINAPI HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement *iface, UINT *pctinfo)
880 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
882 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
885 static HRESULT WINAPI HTMLSelectElement_GetTypeInfo(IHTMLSelectElement *iface, UINT iTInfo,
886 LCID lcid, ITypeInfo **ppTInfo)
888 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
890 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
891 ppTInfo);
894 static HRESULT WINAPI HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement *iface, REFIID riid,
895 LPOLESTR *rgszNames, UINT cNames,
896 LCID lcid, DISPID *rgDispId)
898 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
900 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
901 cNames, lcid, rgDispId);
904 static HRESULT WINAPI HTMLSelectElement_Invoke(IHTMLSelectElement *iface, DISPID dispIdMember,
905 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
906 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
908 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
910 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
911 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
914 static HRESULT WINAPI HTMLSelectElement_put_size(IHTMLSelectElement *iface, LONG v)
916 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
917 nsresult nsres;
919 TRACE("(%p)->(%ld)\n", This, v);
920 if(v < 0)
921 return CTL_E_INVALIDPROPERTYVALUE;
923 nsres = nsIDOMHTMLSelectElement_SetSize(This->nsselect, v);
924 if(NS_FAILED(nsres)) {
925 ERR("SetSize failed: %08lx\n", nsres);
926 return E_FAIL;
928 return S_OK;
931 static HRESULT WINAPI HTMLSelectElement_get_size(IHTMLSelectElement *iface, LONG *p)
933 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
934 UINT32 val;
935 nsresult nsres;
937 TRACE("(%p)->(%p)\n", This, p);
938 if(!p)
939 return E_INVALIDARG;
941 nsres = nsIDOMHTMLSelectElement_GetSize(This->nsselect, &val);
942 if(NS_FAILED(nsres)) {
943 ERR("GetSize failed: %08lx\n", nsres);
944 return E_FAIL;
946 *p = val;
947 return S_OK;
950 static HRESULT WINAPI HTMLSelectElement_put_multiple(IHTMLSelectElement *iface, VARIANT_BOOL v)
952 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
953 nsresult nsres;
955 TRACE("(%p)->(%x)\n", This, v);
957 nsres = nsIDOMHTMLSelectElement_SetMultiple(This->nsselect, !!v);
958 assert(nsres == NS_OK);
959 return S_OK;
962 static HRESULT WINAPI HTMLSelectElement_get_multiple(IHTMLSelectElement *iface, VARIANT_BOOL *p)
964 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
965 cpp_bool val;
966 nsresult nsres;
968 TRACE("(%p)->(%p)\n", This, p);
970 nsres = nsIDOMHTMLSelectElement_GetMultiple(This->nsselect, &val);
971 assert(nsres == NS_OK);
973 *p = variant_bool(val);
974 return S_OK;
977 static HRESULT WINAPI HTMLSelectElement_put_name(IHTMLSelectElement *iface, BSTR v)
979 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
980 nsAString str;
981 nsresult nsres;
983 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
984 nsAString_InitDepend(&str, v);
985 nsres = nsIDOMHTMLSelectElement_SetName(This->nsselect, &str);
986 nsAString_Finish(&str);
988 if(NS_FAILED(nsres)) {
989 ERR("SetName failed: %08lx\n", nsres);
990 return E_FAIL;
992 return S_OK;
995 static HRESULT WINAPI HTMLSelectElement_get_name(IHTMLSelectElement *iface, BSTR *p)
997 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
998 nsAString name_str;
999 nsresult nsres;
1001 TRACE("(%p)->(%p)\n", This, p);
1003 nsAString_Init(&name_str, NULL);
1004 nsres = nsIDOMHTMLSelectElement_GetName(This->nsselect, &name_str);
1006 return return_nsstr(nsres, &name_str, p);
1009 static HRESULT WINAPI HTMLSelectElement_get_options(IHTMLSelectElement *iface, IDispatch **p)
1011 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1013 TRACE("(%p)->(%p)\n", This, p);
1015 *p = (IDispatch*)&This->IHTMLSelectElement_iface;
1016 IDispatch_AddRef(*p);
1017 return S_OK;
1020 static HRESULT WINAPI HTMLSelectElement_put_onchange(IHTMLSelectElement *iface, VARIANT v)
1022 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1024 TRACE("(%p)->()\n", This);
1026 return set_node_event(&This->element.node, EVENTID_CHANGE, &v);
1029 static HRESULT WINAPI HTMLSelectElement_get_onchange(IHTMLSelectElement *iface, VARIANT *p)
1031 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1032 FIXME("(%p)->(%p)\n", This, p);
1033 return E_NOTIMPL;
1036 static HRESULT WINAPI HTMLSelectElement_put_selectedIndex(IHTMLSelectElement *iface, LONG v)
1038 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1039 nsresult nsres;
1041 TRACE("(%p)->(%ld)\n", This, v);
1043 nsres = nsIDOMHTMLSelectElement_SetSelectedIndex(This->nsselect, v);
1044 if(NS_FAILED(nsres))
1045 ERR("SetSelectedIndex failed: %08lx\n", nsres);
1047 return S_OK;
1050 static HRESULT WINAPI HTMLSelectElement_get_selectedIndex(IHTMLSelectElement *iface, LONG *p)
1052 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1053 nsresult nsres;
1055 TRACE("(%p)->(%p)\n", This, p);
1057 nsres = nsIDOMHTMLSelectElement_GetSelectedIndex(This->nsselect, p);
1058 if(NS_FAILED(nsres)) {
1059 ERR("GetSelectedIndex failed: %08lx\n", nsres);
1060 return E_FAIL;
1063 return S_OK;
1066 static HRESULT WINAPI HTMLSelectElement_get_type(IHTMLSelectElement *iface, BSTR *p)
1068 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1069 nsAString type_str;
1070 nsresult nsres;
1072 TRACE("(%p)->(%p)\n", This, p);
1074 nsAString_Init(&type_str, NULL);
1075 nsres = nsIDOMHTMLSelectElement_GetType(This->nsselect, &type_str);
1076 return return_nsstr(nsres, &type_str, p);
1079 static HRESULT WINAPI HTMLSelectElement_put_value(IHTMLSelectElement *iface, BSTR v)
1081 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1082 nsAString value_str;
1083 nsresult nsres;
1085 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1087 nsAString_InitDepend(&value_str, v);
1088 nsres = nsIDOMHTMLSelectElement_SetValue(This->nsselect, &value_str);
1089 nsAString_Finish(&value_str);
1090 if(NS_FAILED(nsres))
1091 ERR("SetValue failed: %08lx\n", nsres);
1093 return S_OK;
1096 static HRESULT WINAPI HTMLSelectElement_get_value(IHTMLSelectElement *iface, BSTR *p)
1098 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1099 nsAString value_str;
1100 nsresult nsres;
1102 TRACE("(%p)->(%p)\n", This, p);
1104 nsAString_Init(&value_str, NULL);
1105 nsres = nsIDOMHTMLSelectElement_GetValue(This->nsselect, &value_str);
1106 return return_nsstr(nsres, &value_str, p);
1109 static HRESULT WINAPI HTMLSelectElement_put_disabled(IHTMLSelectElement *iface, VARIANT_BOOL v)
1111 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1112 nsresult nsres;
1114 TRACE("(%p)->(%x)\n", This, v);
1116 nsres = nsIDOMHTMLSelectElement_SetDisabled(This->nsselect, v != VARIANT_FALSE);
1117 if(NS_FAILED(nsres)) {
1118 ERR("SetDisabled failed: %08lx\n", nsres);
1119 return E_FAIL;
1122 return S_OK;
1125 static HRESULT WINAPI HTMLSelectElement_get_disabled(IHTMLSelectElement *iface, VARIANT_BOOL *p)
1127 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1128 cpp_bool disabled = FALSE;
1129 nsresult nsres;
1131 TRACE("(%p)->(%p)\n", This, p);
1133 nsres = nsIDOMHTMLSelectElement_GetDisabled(This->nsselect, &disabled);
1134 if(NS_FAILED(nsres)) {
1135 ERR("GetDisabled failed: %08lx\n", nsres);
1136 return E_FAIL;
1139 *p = variant_bool(disabled);
1140 return S_OK;
1143 static HRESULT WINAPI HTMLSelectElement_get_form(IHTMLSelectElement *iface, IHTMLFormElement **p)
1145 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1146 nsIDOMHTMLFormElement *nsform;
1147 nsresult nsres;
1149 TRACE("(%p)->(%p)\n", This, p);
1151 if(!p)
1152 return E_POINTER;
1154 nsres = nsIDOMHTMLSelectElement_GetForm(This->nsselect, &nsform);
1155 return return_nsform(nsres, nsform, p);
1158 static HRESULT WINAPI HTMLSelectElement_add(IHTMLSelectElement *iface, IHTMLElement *element,
1159 VARIANT before)
1161 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1162 nsIWritableVariant *nsvariant;
1163 HTMLElement *element_obj;
1164 nsresult nsres;
1166 TRACE("(%p)->(%p %s)\n", This, element, debugstr_variant(&before));
1168 element_obj = unsafe_impl_from_IHTMLElement(element);
1169 if(!element_obj) {
1170 FIXME("External IHTMLElement implementation?\n");
1171 return E_INVALIDARG;
1174 if(!element_obj->html_element) {
1175 FIXME("Not HTML element\n");
1176 return E_NOTIMPL;
1179 nsvariant = create_nsvariant();
1180 if(!nsvariant)
1181 return E_FAIL;
1183 switch(V_VT(&before)) {
1184 case VT_EMPTY:
1185 case VT_ERROR:
1186 nsres = nsIWritableVariant_SetAsEmpty(nsvariant);
1187 break;
1188 case VT_I2:
1189 nsres = nsIWritableVariant_SetAsInt16(nsvariant, V_I2(&before));
1190 break;
1191 default:
1192 FIXME("unhandled before %s\n", debugstr_variant(&before));
1193 nsIWritableVariant_Release(nsvariant);
1194 return E_NOTIMPL;
1197 if(NS_SUCCEEDED(nsres))
1198 nsres = nsIDOMHTMLSelectElement_Add(This->nsselect, element_obj->html_element, (nsIVariant*)nsvariant);
1199 nsIWritableVariant_Release(nsvariant);
1200 if(NS_FAILED(nsres)) {
1201 ERR("Add failed: %08lx\n", nsres);
1202 return E_FAIL;
1205 return S_OK;
1208 static HRESULT WINAPI HTMLSelectElement_remove(IHTMLSelectElement *iface, LONG index)
1210 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1211 nsresult nsres;
1212 TRACE("(%p)->(%ld)\n", This, index);
1213 if(index < 0)
1214 return E_INVALIDARG;
1216 nsres = nsIDOMHTMLSelectElement_select_Remove(This->nsselect, index);
1217 if(NS_FAILED(nsres)) {
1218 ERR("Remove failed: %08lx\n", nsres);
1219 return E_FAIL;
1221 return S_OK;
1224 static HRESULT WINAPI HTMLSelectElement_put_length(IHTMLSelectElement *iface, LONG v)
1226 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1227 nsresult nsres;
1229 TRACE("(%p)->(%ld)\n", This, v);
1231 nsres = nsIDOMHTMLSelectElement_SetLength(This->nsselect, v);
1232 if(NS_FAILED(nsres))
1233 ERR("SetLength failed: %08lx\n", nsres);
1235 return S_OK;
1238 static HRESULT WINAPI HTMLSelectElement_get_length(IHTMLSelectElement *iface, LONG *p)
1240 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1241 UINT32 length = 0;
1242 nsresult nsres;
1244 TRACE("(%p)->(%p)\n", This, p);
1246 nsres = nsIDOMHTMLSelectElement_GetLength(This->nsselect, &length);
1247 if(NS_FAILED(nsres))
1248 ERR("GetLength failed: %08lx\n", nsres);
1250 *p = length;
1252 TRACE("ret %ld\n", *p);
1253 return S_OK;
1256 static HRESULT WINAPI HTMLSelectElement_get__newEnum(IHTMLSelectElement *iface, IUnknown **p)
1258 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1259 HTMLSelectElementEnum *ret;
1261 TRACE("(%p)->(%p)\n", This, p);
1263 ret = malloc(sizeof(*ret));
1264 if(!ret)
1265 return E_OUTOFMEMORY;
1267 ret->IEnumVARIANT_iface.lpVtbl = &HTMLSelectElementEnumVtbl;
1268 ret->ref = 1;
1269 ret->iter = 0;
1271 HTMLSelectElement_AddRef(&This->IHTMLSelectElement_iface);
1272 ret->elem = This;
1274 *p = (IUnknown*)&ret->IEnumVARIANT_iface;
1275 return S_OK;
1278 static HRESULT WINAPI HTMLSelectElement_item(IHTMLSelectElement *iface, VARIANT name,
1279 VARIANT index, IDispatch **pdisp)
1281 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1283 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
1285 if(!pdisp)
1286 return E_POINTER;
1287 *pdisp = NULL;
1289 if(V_VT(&name) == VT_I4) {
1290 if(V_I4(&name) < 0)
1291 return E_INVALIDARG;
1292 return htmlselect_item(This, V_I4(&name), pdisp);
1295 FIXME("Unsupported args\n");
1296 return E_NOTIMPL;
1299 static HRESULT WINAPI HTMLSelectElement_tags(IHTMLSelectElement *iface, VARIANT tagName,
1300 IDispatch **pdisp)
1302 HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
1303 FIXME("(%p)->(v %p)\n", This, pdisp);
1304 return E_NOTIMPL;
1307 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl = {
1308 HTMLSelectElement_QueryInterface,
1309 HTMLSelectElement_AddRef,
1310 HTMLSelectElement_Release,
1311 HTMLSelectElement_GetTypeInfoCount,
1312 HTMLSelectElement_GetTypeInfo,
1313 HTMLSelectElement_GetIDsOfNames,
1314 HTMLSelectElement_Invoke,
1315 HTMLSelectElement_put_size,
1316 HTMLSelectElement_get_size,
1317 HTMLSelectElement_put_multiple,
1318 HTMLSelectElement_get_multiple,
1319 HTMLSelectElement_put_name,
1320 HTMLSelectElement_get_name,
1321 HTMLSelectElement_get_options,
1322 HTMLSelectElement_put_onchange,
1323 HTMLSelectElement_get_onchange,
1324 HTMLSelectElement_put_selectedIndex,
1325 HTMLSelectElement_get_selectedIndex,
1326 HTMLSelectElement_get_type,
1327 HTMLSelectElement_put_value,
1328 HTMLSelectElement_get_value,
1329 HTMLSelectElement_put_disabled,
1330 HTMLSelectElement_get_disabled,
1331 HTMLSelectElement_get_form,
1332 HTMLSelectElement_add,
1333 HTMLSelectElement_remove,
1334 HTMLSelectElement_put_length,
1335 HTMLSelectElement_get_length,
1336 HTMLSelectElement_get__newEnum,
1337 HTMLSelectElement_item,
1338 HTMLSelectElement_tags
1341 static inline HTMLSelectElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1343 return CONTAINING_RECORD(iface, HTMLSelectElement, element.node);
1346 static HRESULT HTMLSelectElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1348 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1350 *ppv = NULL;
1352 if(IsEqualGUID(&IID_IUnknown, riid)) {
1353 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1354 *ppv = &This->IHTMLSelectElement_iface;
1355 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1356 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1357 *ppv = &This->IHTMLSelectElement_iface;
1358 }else if(IsEqualGUID(&IID_IHTMLSelectElement, riid)) {
1359 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This, ppv);
1360 *ppv = &This->IHTMLSelectElement_iface;
1363 if(*ppv) {
1364 IUnknown_AddRef((IUnknown*)*ppv);
1365 return S_OK;
1368 return HTMLElement_QI(&This->element.node, riid, ppv);
1371 static HRESULT HTMLSelectElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
1373 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1374 return IHTMLSelectElement_put_disabled(&This->IHTMLSelectElement_iface, v);
1377 static HRESULT HTMLSelectElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
1379 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1380 return IHTMLSelectElement_get_disabled(&This->IHTMLSelectElement_iface, p);
1383 #define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN
1385 static HRESULT HTMLSelectElement_get_dispid(HTMLDOMNode *iface, BSTR name, DWORD flags, DISPID *dispid)
1387 const WCHAR *ptr;
1388 DWORD idx = 0;
1390 for(ptr = name; *ptr && is_digit(*ptr); ptr++) {
1391 idx = idx*10 + (*ptr-'0');
1392 if(idx > MSHTML_CUSTOM_DISPID_CNT) {
1393 WARN("too big idx\n");
1394 return DISP_E_UNKNOWNNAME;
1397 if(*ptr)
1398 return DISP_E_UNKNOWNNAME;
1400 *dispid = DISPID_OPTIONCOL_0 + idx;
1401 return S_OK;
1404 static HRESULT HTMLSelectElement_dispex_get_name(HTMLDOMNode *iface, DISPID id, BSTR *name)
1406 DWORD idx = id - DISPID_OPTIONCOL_0;
1407 WCHAR buf[11];
1408 UINT len;
1410 if(idx > MSHTML_CUSTOM_DISPID_CNT)
1411 return DISP_E_MEMBERNOTFOUND;
1413 len = swprintf(buf, ARRAY_SIZE(buf), L"%u", idx);
1414 return (*name = SysAllocStringLen(buf, len)) ? S_OK : E_OUTOFMEMORY;
1417 static HRESULT HTMLSelectElement_invoke(HTMLDOMNode *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1418 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1420 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1422 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
1424 switch(flags) {
1425 case DISPATCH_PROPERTYGET: {
1426 IDispatch *ret;
1427 HRESULT hres;
1429 hres = htmlselect_item(This, id-DISPID_OPTIONCOL_0, &ret);
1430 if(FAILED(hres))
1431 return hres;
1433 if(ret) {
1434 V_VT(res) = VT_DISPATCH;
1435 V_DISPATCH(res) = ret;
1436 }else {
1437 V_VT(res) = VT_NULL;
1439 break;
1442 default:
1443 FIXME("unimplemented flags %x\n", flags);
1444 return E_NOTIMPL;
1447 return S_OK;
1450 static void HTMLSelectElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
1452 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1454 if(This->nsselect)
1455 note_cc_edge((nsISupports*)This->nsselect, "This->nsselect", cb);
1458 static void HTMLSelectElement_unlink(HTMLDOMNode *iface)
1460 HTMLSelectElement *This = impl_from_HTMLDOMNode(iface);
1462 if(This->nsselect) {
1463 nsIDOMHTMLSelectElement *nsselect = This->nsselect;
1465 This->nsselect = NULL;
1466 nsIDOMHTMLSelectElement_Release(nsselect);
1470 static const NodeImplVtbl HTMLSelectElementImplVtbl = {
1471 &CLSID_HTMLSelectElement,
1472 HTMLSelectElement_QI,
1473 HTMLElement_destructor,
1474 HTMLElement_cpc,
1475 HTMLElement_clone,
1476 HTMLElement_handle_event,
1477 HTMLElement_get_attr_col,
1478 NULL,
1479 HTMLSelectElementImpl_put_disabled,
1480 HTMLSelectElementImpl_get_disabled,
1481 NULL,
1482 NULL,
1483 HTMLSelectElement_get_dispid,
1484 HTMLSelectElement_dispex_get_name,
1485 HTMLSelectElement_invoke,
1486 NULL,
1487 HTMLSelectElement_traverse,
1488 HTMLSelectElement_unlink
1491 static const tid_t HTMLSelectElement_tids[] = {
1492 HTMLELEMENT_TIDS,
1493 IHTMLSelectElement_tid,
1497 static dispex_static_data_t HTMLSelectElement_dispex = {
1498 L"HTMLSelectElement",
1499 NULL,
1500 DispHTMLSelectElement_tid,
1501 HTMLSelectElement_tids,
1502 HTMLElement_init_dispex_info
1505 HRESULT HTMLSelectElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
1507 HTMLSelectElement *ret;
1508 nsresult nsres;
1510 ret = calloc(1, sizeof(HTMLSelectElement));
1511 if(!ret)
1512 return E_OUTOFMEMORY;
1514 ret->IHTMLSelectElement_iface.lpVtbl = &HTMLSelectElementVtbl;
1515 ret->element.node.vtbl = &HTMLSelectElementImplVtbl;
1517 HTMLElement_Init(&ret->element, doc, nselem, &HTMLSelectElement_dispex);
1519 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLSelectElement, (void**)&ret->nsselect);
1520 assert(nsres == NS_OK);
1522 *elem = &ret->element;
1523 return S_OK;