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
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
35 struct HTMLOptionElement
{
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
,
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
);
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
);
118 static HRESULT WINAPI
HTMLOptionElement_get_selected(IHTMLOptionElement
*iface
, VARIANT_BOOL
*p
)
120 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
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
);
132 *p
= variant_bool(selected
);
136 static HRESULT WINAPI
HTMLOptionElement_put_value(IHTMLOptionElement
*iface
, BSTR v
)
138 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
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
);
148 ERR("SetValue failed: %08lx\n", nsres
);
153 static HRESULT WINAPI
HTMLOptionElement_get_value(IHTMLOptionElement
*iface
, BSTR
*p
)
155 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
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
;
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
);
182 nsres
= nsIDOMHTMLOptionElement_SetDefaultSelected(This
->nsoption
, val
);
183 if(NS_FAILED(nsres
)) {
184 ERR("SetDefaultSelected failed: %08lx\n", nsres
);
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
);
199 static HRESULT WINAPI
HTMLOptionElement_get_defaultSelected(IHTMLOptionElement
*iface
, VARIANT_BOOL
*p
)
201 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
205 TRACE("(%p)->(%p)\n", This
, p
);
208 nsres
= nsIDOMHTMLOptionElement_GetDefaultSelected(This
->nsoption
, &val
);
209 if(NS_FAILED(nsres
)) {
210 ERR("GetDefaultSelected failed: %08lx\n", nsres
);
214 *p
= variant_bool(val
);
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
);
225 static HRESULT WINAPI
HTMLOptionElement_get_index(IHTMLOptionElement
*iface
, LONG
*p
)
227 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
231 TRACE("(%p)->(%p)\n", This
, p
);
236 nsres
= nsIDOMHTMLOptionElement_GetIndex(This
->nsoption
, &val
);
237 if(NS_FAILED(nsres
)) {
238 ERR("GetIndex failed: %08lx\n", nsres
);
245 static HRESULT WINAPI
HTMLOptionElement_put_text(IHTMLOptionElement
*iface
, BSTR v
)
247 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
248 nsIDOMText
*text_node
;
253 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
255 if(!This
->element
.node
.doc
->dom_document
) {
256 WARN("NULL dom_document\n");
263 nsres
= nsIDOMElement_GetFirstChild(This
->element
.dom_element
, &child
);
264 if(NS_FAILED(nsres
) || !child
)
267 nsres
= nsIDOMElement_RemoveChild(This
->element
.dom_element
, child
, &tmp
);
268 nsIDOMNode_Release(child
);
269 if(NS_SUCCEEDED(nsres
)) {
270 nsIDOMNode_Release(tmp
);
272 ERR("RemoveChild failed: %08lx\n", nsres
);
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
);
285 nsres
= nsIDOMElement_AppendChild(This
->element
.dom_element
, (nsIDOMNode
*)text_node
, &tmp
);
286 if(NS_SUCCEEDED(nsres
))
287 nsIDOMNode_Release(tmp
);
289 ERR("AppendChild failed: %08lx\n", nsres
);
294 static HRESULT WINAPI
HTMLOptionElement_get_text(IHTMLOptionElement
*iface
, BSTR
*p
)
296 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
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
;
313 TRACE("(%p)->(%p)\n", This
, p
);
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
);
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
;
366 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
378 note_cc_edge((nsISupports
*)This
->nsoption
, "This->nsoption", cb
);
381 static void HTMLOptionElement_unlink(HTMLDOMNode
*iface
)
383 HTMLOptionElement
*This
= HTMLOptionElement_from_HTMLDOMNode(iface
);
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
,
399 HTMLElement_dispatch_nsevent_hook
,
400 HTMLElement_handle_event
,
401 HTMLElement_get_attr_col
,
411 HTMLOptionElement_traverse
,
412 HTMLOptionElement_unlink
415 static const tid_t HTMLOptionElement_iface_tids
[] = {
417 IHTMLOptionElement_tid
,
420 static dispex_static_data_t HTMLOptionElement_dispex
= {
421 L
"HTMLOptionElement",
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
;
433 ret
= calloc(1, sizeof(HTMLOptionElement
));
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
;
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
;
471 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
472 return E_NOINTERFACE
;
475 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
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
);
497 release_dispex(&This
->dispex
);
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
;
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
) {
553 hres
= create_nselem(This
->window
->doc
, L
"OPTION", &nselem
);
557 hres
= get_node((nsIDOMNode
*)nselem
, TRUE
, &node
);
558 nsIDOMElement_Release(nselem
);
562 hres
= IHTMLDOMNode_QueryInterface(&node
->IHTMLDOMNode_iface
,
563 &IID_IHTMLOptionElement
, (void**)optelem
);
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
));
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];
610 if(flags
!= DISPATCH_CONSTRUCT
) {
611 FIXME("flags %x not supported\n", flags
);
616 V_VT(&empty
) = VT_EMPTY
;
618 for(i
= 0; i
< ARRAY_SIZE(arg
); i
++)
619 arg
[i
] = argc
> i
? ¶ms
->rgvarg
[params
->cArgs
- 1 - i
] : &empty
;
621 hres
= IHTMLOptionElementFactory_create(&This
->IHTMLOptionElementFactory_iface
,
622 *arg
[0], *arg
[1], *arg
[2], *arg
[3], &opt
);
626 V_VT(res
) = VT_DISPATCH
;
627 V_DISPATCH(res
) = (IDispatch
*)opt
;
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
,
644 static dispex_static_data_t HTMLOptionElementFactory_dispex
= {
646 &HTMLOptionElementFactory_dispex_vtbl
,
647 IHTMLOptionElementFactory_tid
,
648 HTMLOptionElementFactory_iface_tids
,
649 HTMLElement_init_dispex_info
652 HRESULT
HTMLOptionElementFactory_Create(HTMLInnerWindow
*window
, HTMLOptionElementFactory
**ret_ptr
)
654 HTMLOptionElementFactory
*ret
;
656 ret
= malloc(sizeof(*ret
));
658 return E_OUTOFMEMORY
;
660 ret
->IHTMLOptionElementFactory_iface
.lpVtbl
= &HTMLOptionElementFactoryVtbl
;
662 ret
->window
= window
;
664 init_dispatch(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLOptionElementFactory_iface
,
665 &HTMLOptionElementFactory_dispex
, dispex_compat_mode(&window
->event_target
.dispex
));
671 struct HTMLSelectElement
{
674 IHTMLSelectElement IHTMLSelectElement_iface
;
676 nsIDOMHTMLSelectElement
*nsselect
;
680 IEnumVARIANT IEnumVARIANT_iface
;
685 HTMLSelectElement
*elem
;
686 } HTMLSelectElementEnum
;
688 static inline HTMLSelectElement
*impl_from_IHTMLSelectElement(IHTMLSelectElement
*iface
)
690 return CONTAINING_RECORD(iface
, HTMLSelectElement
, IHTMLSelectElement_iface
);
693 static HRESULT
htmlselect_item(HTMLSelectElement
*This
, int i
, IDispatch
**ret
)
695 nsIDOMHTMLOptionsCollection
*nscol
;
700 nsres
= nsIDOMHTMLSelectElement_GetOptions(This
->nsselect
, &nscol
);
701 if(NS_FAILED(nsres
)) {
702 ERR("GetOptions failed: %08lx\n", nsres
);
706 nsres
= nsIDOMHTMLOptionsCollection_Item(nscol
, i
, &nsnode
);
707 nsIDOMHTMLOptionsCollection_Release(nscol
);
708 if(NS_FAILED(nsres
)) {
709 ERR("Item failed: %08lx\n", nsres
);
716 hres
= get_node(nsnode
, TRUE
, &node
);
717 nsIDOMNode_Release(nsnode
);
721 *ret
= (IDispatch
*)&node
->IHTMLDOMNode_iface
;
728 static inline HTMLSelectElementEnum
*impl_from_IEnumVARIANT(IEnumVARIANT
*iface
)
730 return CONTAINING_RECORD(iface
, HTMLSelectElementEnum
, IEnumVARIANT_iface
);
733 static HRESULT WINAPI
HTMLSelectElementEnum_QueryInterface(IEnumVARIANT
*iface
, REFIID riid
, void **ppv
)
735 HTMLSelectElementEnum
*This
= impl_from_IEnumVARIANT(iface
);
737 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
739 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
740 *ppv
= &This
->IEnumVARIANT_iface
;
741 }else if(IsEqualGUID(riid
, &IID_IEnumVARIANT
)) {
742 *ppv
= &This
->IEnumVARIANT_iface
;
744 FIXME("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
746 return E_NOINTERFACE
;
749 IUnknown_AddRef((IUnknown
*)*ppv
);
753 static ULONG WINAPI
HTMLSelectElementEnum_AddRef(IEnumVARIANT
*iface
)
755 HTMLSelectElementEnum
*This
= impl_from_IEnumVARIANT(iface
);
756 LONG ref
= InterlockedIncrement(&This
->ref
);
758 TRACE("(%p) ref=%ld\n", This
, ref
);
763 static ULONG WINAPI
HTMLSelectElementEnum_Release(IEnumVARIANT
*iface
)
765 HTMLSelectElementEnum
*This
= impl_from_IEnumVARIANT(iface
);
766 LONG ref
= InterlockedDecrement(&This
->ref
);
768 TRACE("(%p) ref=%ld\n", This
, ref
);
771 IHTMLSelectElement_Release(&This
->elem
->IHTMLSelectElement_iface
);
778 static HRESULT WINAPI
HTMLSelectElementEnum_Next(IEnumVARIANT
*iface
, ULONG celt
, VARIANT
*rgVar
, ULONG
*pCeltFetched
)
780 HTMLSelectElementEnum
*This
= impl_from_IEnumVARIANT(iface
);
786 TRACE("(%p)->(%lu %p %p)\n", This
, celt
, rgVar
, pCeltFetched
);
788 nsres
= nsIDOMHTMLSelectElement_GetLength(This
->elem
->nsselect
, &len
);
791 num
= min(len
- This
->iter
, celt
);
793 for(i
= 0; i
< num
; i
++) {
794 hres
= htmlselect_item(This
->elem
, This
->iter
+ i
, &V_DISPATCH(&rgVar
[i
]));
797 VariantClear(&rgVar
[i
]);
800 V_VT(&rgVar
[i
]) = VT_DISPATCH
;
806 return num
== celt
? S_OK
: S_FALSE
;
809 static HRESULT WINAPI
HTMLSelectElementEnum_Skip(IEnumVARIANT
*iface
, ULONG celt
)
811 HTMLSelectElementEnum
*This
= impl_from_IEnumVARIANT(iface
);
815 TRACE("(%p)->(%lu)\n", This
, celt
);
817 nsres
= nsIDOMHTMLSelectElement_GetLength(This
->elem
->nsselect
, &len
);
821 if(This
->iter
+ celt
> len
) {
830 static HRESULT WINAPI
HTMLSelectElementEnum_Reset(IEnumVARIANT
*iface
)
832 HTMLSelectElementEnum
*This
= impl_from_IEnumVARIANT(iface
);
834 TRACE("(%p)->()\n", This
);
840 static HRESULT WINAPI
HTMLSelectElementEnum_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**ppEnum
)
842 HTMLSelectElementEnum
*This
= impl_from_IEnumVARIANT(iface
);
843 FIXME("(%p)->(%p)\n", This
, ppEnum
);
847 static const IEnumVARIANTVtbl HTMLSelectElementEnumVtbl
= {
848 HTMLSelectElementEnum_QueryInterface
,
849 HTMLSelectElementEnum_AddRef
,
850 HTMLSelectElementEnum_Release
,
851 HTMLSelectElementEnum_Next
,
852 HTMLSelectElementEnum_Skip
,
853 HTMLSelectElementEnum_Reset
,
854 HTMLSelectElementEnum_Clone
857 static HRESULT WINAPI
HTMLSelectElement_QueryInterface(IHTMLSelectElement
*iface
,
858 REFIID riid
, void **ppv
)
860 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
862 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
865 static ULONG WINAPI
HTMLSelectElement_AddRef(IHTMLSelectElement
*iface
)
867 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
869 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
872 static ULONG WINAPI
HTMLSelectElement_Release(IHTMLSelectElement
*iface
)
874 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
876 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
879 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement
*iface
, UINT
*pctinfo
)
881 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
883 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
886 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfo(IHTMLSelectElement
*iface
, UINT iTInfo
,
887 LCID lcid
, ITypeInfo
**ppTInfo
)
889 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
891 return IDispatchEx_GetTypeInfo(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
895 static HRESULT WINAPI
HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement
*iface
, REFIID riid
,
896 LPOLESTR
*rgszNames
, UINT cNames
,
897 LCID lcid
, DISPID
*rgDispId
)
899 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
901 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
902 cNames
, lcid
, rgDispId
);
905 static HRESULT WINAPI
HTMLSelectElement_Invoke(IHTMLSelectElement
*iface
, DISPID dispIdMember
,
906 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
907 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
909 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
911 return IDispatchEx_Invoke(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
912 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
915 static HRESULT WINAPI
HTMLSelectElement_put_size(IHTMLSelectElement
*iface
, LONG v
)
917 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
920 TRACE("(%p)->(%ld)\n", This
, v
);
922 return CTL_E_INVALIDPROPERTYVALUE
;
924 nsres
= nsIDOMHTMLSelectElement_SetSize(This
->nsselect
, v
);
925 if(NS_FAILED(nsres
)) {
926 ERR("SetSize failed: %08lx\n", nsres
);
932 static HRESULT WINAPI
HTMLSelectElement_get_size(IHTMLSelectElement
*iface
, LONG
*p
)
934 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
938 TRACE("(%p)->(%p)\n", This
, p
);
942 nsres
= nsIDOMHTMLSelectElement_GetSize(This
->nsselect
, &val
);
943 if(NS_FAILED(nsres
)) {
944 ERR("GetSize failed: %08lx\n", nsres
);
951 static HRESULT WINAPI
HTMLSelectElement_put_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
953 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
956 TRACE("(%p)->(%x)\n", This
, v
);
958 nsres
= nsIDOMHTMLSelectElement_SetMultiple(This
->nsselect
, !!v
);
959 assert(nsres
== NS_OK
);
963 static HRESULT WINAPI
HTMLSelectElement_get_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
965 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
969 TRACE("(%p)->(%p)\n", This
, p
);
971 nsres
= nsIDOMHTMLSelectElement_GetMultiple(This
->nsselect
, &val
);
972 assert(nsres
== NS_OK
);
974 *p
= variant_bool(val
);
978 static HRESULT WINAPI
HTMLSelectElement_put_name(IHTMLSelectElement
*iface
, BSTR v
)
980 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
984 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
985 nsAString_InitDepend(&str
, v
);
986 nsres
= nsIDOMHTMLSelectElement_SetName(This
->nsselect
, &str
);
987 nsAString_Finish(&str
);
989 if(NS_FAILED(nsres
)) {
990 ERR("SetName failed: %08lx\n", nsres
);
996 static HRESULT WINAPI
HTMLSelectElement_get_name(IHTMLSelectElement
*iface
, BSTR
*p
)
998 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1002 TRACE("(%p)->(%p)\n", This
, p
);
1004 nsAString_Init(&name_str
, NULL
);
1005 nsres
= nsIDOMHTMLSelectElement_GetName(This
->nsselect
, &name_str
);
1007 return return_nsstr(nsres
, &name_str
, p
);
1010 static HRESULT WINAPI
HTMLSelectElement_get_options(IHTMLSelectElement
*iface
, IDispatch
**p
)
1012 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1014 TRACE("(%p)->(%p)\n", This
, p
);
1016 *p
= (IDispatch
*)&This
->IHTMLSelectElement_iface
;
1017 IDispatch_AddRef(*p
);
1021 static HRESULT WINAPI
HTMLSelectElement_put_onchange(IHTMLSelectElement
*iface
, VARIANT v
)
1023 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1025 TRACE("(%p)->()\n", This
);
1027 return set_node_event(&This
->element
.node
, EVENTID_CHANGE
, &v
);
1030 static HRESULT WINAPI
HTMLSelectElement_get_onchange(IHTMLSelectElement
*iface
, VARIANT
*p
)
1032 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1033 FIXME("(%p)->(%p)\n", This
, p
);
1037 static HRESULT WINAPI
HTMLSelectElement_put_selectedIndex(IHTMLSelectElement
*iface
, LONG v
)
1039 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1042 TRACE("(%p)->(%ld)\n", This
, v
);
1044 nsres
= nsIDOMHTMLSelectElement_SetSelectedIndex(This
->nsselect
, v
);
1045 if(NS_FAILED(nsres
))
1046 ERR("SetSelectedIndex failed: %08lx\n", nsres
);
1051 static HRESULT WINAPI
HTMLSelectElement_get_selectedIndex(IHTMLSelectElement
*iface
, LONG
*p
)
1053 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1056 TRACE("(%p)->(%p)\n", This
, p
);
1058 nsres
= nsIDOMHTMLSelectElement_GetSelectedIndex(This
->nsselect
, p
);
1059 if(NS_FAILED(nsres
)) {
1060 ERR("GetSelectedIndex failed: %08lx\n", nsres
);
1067 static HRESULT WINAPI
HTMLSelectElement_get_type(IHTMLSelectElement
*iface
, BSTR
*p
)
1069 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1073 TRACE("(%p)->(%p)\n", This
, p
);
1075 nsAString_Init(&type_str
, NULL
);
1076 nsres
= nsIDOMHTMLSelectElement_GetType(This
->nsselect
, &type_str
);
1077 return return_nsstr(nsres
, &type_str
, p
);
1080 static HRESULT WINAPI
HTMLSelectElement_put_value(IHTMLSelectElement
*iface
, BSTR v
)
1082 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1083 nsAString value_str
;
1086 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
1088 nsAString_InitDepend(&value_str
, v
);
1089 nsres
= nsIDOMHTMLSelectElement_SetValue(This
->nsselect
, &value_str
);
1090 nsAString_Finish(&value_str
);
1091 if(NS_FAILED(nsres
))
1092 ERR("SetValue failed: %08lx\n", nsres
);
1097 static HRESULT WINAPI
HTMLSelectElement_get_value(IHTMLSelectElement
*iface
, BSTR
*p
)
1099 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1100 nsAString value_str
;
1103 TRACE("(%p)->(%p)\n", This
, p
);
1105 nsAString_Init(&value_str
, NULL
);
1106 nsres
= nsIDOMHTMLSelectElement_GetValue(This
->nsselect
, &value_str
);
1107 return return_nsstr(nsres
, &value_str
, p
);
1110 static HRESULT WINAPI
HTMLSelectElement_put_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
1112 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1115 TRACE("(%p)->(%x)\n", This
, v
);
1117 nsres
= nsIDOMHTMLSelectElement_SetDisabled(This
->nsselect
, v
!= VARIANT_FALSE
);
1118 if(NS_FAILED(nsres
)) {
1119 ERR("SetDisabled failed: %08lx\n", nsres
);
1126 static HRESULT WINAPI
HTMLSelectElement_get_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
1128 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1129 cpp_bool disabled
= FALSE
;
1132 TRACE("(%p)->(%p)\n", This
, p
);
1134 nsres
= nsIDOMHTMLSelectElement_GetDisabled(This
->nsselect
, &disabled
);
1135 if(NS_FAILED(nsres
)) {
1136 ERR("GetDisabled failed: %08lx\n", nsres
);
1140 *p
= variant_bool(disabled
);
1144 static HRESULT WINAPI
HTMLSelectElement_get_form(IHTMLSelectElement
*iface
, IHTMLFormElement
**p
)
1146 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1147 nsIDOMHTMLFormElement
*nsform
;
1150 TRACE("(%p)->(%p)\n", This
, p
);
1155 nsres
= nsIDOMHTMLSelectElement_GetForm(This
->nsselect
, &nsform
);
1156 return return_nsform(nsres
, nsform
, p
);
1159 static HRESULT WINAPI
HTMLSelectElement_add(IHTMLSelectElement
*iface
, IHTMLElement
*element
,
1162 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1163 nsIWritableVariant
*nsvariant
;
1164 HTMLElement
*element_obj
;
1167 TRACE("(%p)->(%p %s)\n", This
, element
, debugstr_variant(&before
));
1169 element_obj
= unsafe_impl_from_IHTMLElement(element
);
1171 FIXME("External IHTMLElement implementation?\n");
1172 return E_INVALIDARG
;
1175 if(!element_obj
->html_element
) {
1176 FIXME("Not HTML element\n");
1180 nsvariant
= create_nsvariant();
1184 switch(V_VT(&before
)) {
1187 nsres
= nsIWritableVariant_SetAsEmpty(nsvariant
);
1190 nsres
= nsIWritableVariant_SetAsInt16(nsvariant
, V_I2(&before
));
1193 FIXME("unhandled before %s\n", debugstr_variant(&before
));
1194 nsIWritableVariant_Release(nsvariant
);
1198 if(NS_SUCCEEDED(nsres
))
1199 nsres
= nsIDOMHTMLSelectElement_Add(This
->nsselect
, element_obj
->html_element
, (nsIVariant
*)nsvariant
);
1200 nsIWritableVariant_Release(nsvariant
);
1201 if(NS_FAILED(nsres
)) {
1202 ERR("Add failed: %08lx\n", nsres
);
1209 static HRESULT WINAPI
HTMLSelectElement_remove(IHTMLSelectElement
*iface
, LONG index
)
1211 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1213 TRACE("(%p)->(%ld)\n", This
, index
);
1215 return E_INVALIDARG
;
1217 nsres
= nsIDOMHTMLSelectElement_select_Remove(This
->nsselect
, index
);
1218 if(NS_FAILED(nsres
)) {
1219 ERR("Remove failed: %08lx\n", nsres
);
1225 static HRESULT WINAPI
HTMLSelectElement_put_length(IHTMLSelectElement
*iface
, LONG v
)
1227 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1230 TRACE("(%p)->(%ld)\n", This
, v
);
1232 nsres
= nsIDOMHTMLSelectElement_SetLength(This
->nsselect
, v
);
1233 if(NS_FAILED(nsres
))
1234 ERR("SetLength failed: %08lx\n", nsres
);
1239 static HRESULT WINAPI
HTMLSelectElement_get_length(IHTMLSelectElement
*iface
, LONG
*p
)
1241 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1245 TRACE("(%p)->(%p)\n", This
, p
);
1247 nsres
= nsIDOMHTMLSelectElement_GetLength(This
->nsselect
, &length
);
1248 if(NS_FAILED(nsres
))
1249 ERR("GetLength failed: %08lx\n", nsres
);
1253 TRACE("ret %ld\n", *p
);
1257 static HRESULT WINAPI
HTMLSelectElement_get__newEnum(IHTMLSelectElement
*iface
, IUnknown
**p
)
1259 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1260 HTMLSelectElementEnum
*ret
;
1262 TRACE("(%p)->(%p)\n", This
, p
);
1264 ret
= malloc(sizeof(*ret
));
1266 return E_OUTOFMEMORY
;
1268 ret
->IEnumVARIANT_iface
.lpVtbl
= &HTMLSelectElementEnumVtbl
;
1272 HTMLSelectElement_AddRef(&This
->IHTMLSelectElement_iface
);
1275 *p
= (IUnknown
*)&ret
->IEnumVARIANT_iface
;
1279 static HRESULT WINAPI
HTMLSelectElement_item(IHTMLSelectElement
*iface
, VARIANT name
,
1280 VARIANT index
, IDispatch
**pdisp
)
1282 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1284 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
1290 if(V_VT(&name
) == VT_I4
) {
1292 return E_INVALIDARG
;
1293 return htmlselect_item(This
, V_I4(&name
), pdisp
);
1296 FIXME("Unsupported args\n");
1300 static HRESULT WINAPI
HTMLSelectElement_tags(IHTMLSelectElement
*iface
, VARIANT tagName
,
1303 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1304 FIXME("(%p)->(v %p)\n", This
, pdisp
);
1308 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl
= {
1309 HTMLSelectElement_QueryInterface
,
1310 HTMLSelectElement_AddRef
,
1311 HTMLSelectElement_Release
,
1312 HTMLSelectElement_GetTypeInfoCount
,
1313 HTMLSelectElement_GetTypeInfo
,
1314 HTMLSelectElement_GetIDsOfNames
,
1315 HTMLSelectElement_Invoke
,
1316 HTMLSelectElement_put_size
,
1317 HTMLSelectElement_get_size
,
1318 HTMLSelectElement_put_multiple
,
1319 HTMLSelectElement_get_multiple
,
1320 HTMLSelectElement_put_name
,
1321 HTMLSelectElement_get_name
,
1322 HTMLSelectElement_get_options
,
1323 HTMLSelectElement_put_onchange
,
1324 HTMLSelectElement_get_onchange
,
1325 HTMLSelectElement_put_selectedIndex
,
1326 HTMLSelectElement_get_selectedIndex
,
1327 HTMLSelectElement_get_type
,
1328 HTMLSelectElement_put_value
,
1329 HTMLSelectElement_get_value
,
1330 HTMLSelectElement_put_disabled
,
1331 HTMLSelectElement_get_disabled
,
1332 HTMLSelectElement_get_form
,
1333 HTMLSelectElement_add
,
1334 HTMLSelectElement_remove
,
1335 HTMLSelectElement_put_length
,
1336 HTMLSelectElement_get_length
,
1337 HTMLSelectElement_get__newEnum
,
1338 HTMLSelectElement_item
,
1339 HTMLSelectElement_tags
1342 static inline HTMLSelectElement
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
1344 return CONTAINING_RECORD(iface
, HTMLSelectElement
, element
.node
);
1347 static HRESULT
HTMLSelectElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
1349 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1353 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1354 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1355 *ppv
= &This
->IHTMLSelectElement_iface
;
1356 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1357 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1358 *ppv
= &This
->IHTMLSelectElement_iface
;
1359 }else if(IsEqualGUID(&IID_IHTMLSelectElement
, riid
)) {
1360 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This
, ppv
);
1361 *ppv
= &This
->IHTMLSelectElement_iface
;
1365 IUnknown_AddRef((IUnknown
*)*ppv
);
1369 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
1372 static HRESULT
HTMLSelectElementImpl_put_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL v
)
1374 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1375 return IHTMLSelectElement_put_disabled(&This
->IHTMLSelectElement_iface
, v
);
1378 static HRESULT
HTMLSelectElementImpl_get_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL
*p
)
1380 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1381 return IHTMLSelectElement_get_disabled(&This
->IHTMLSelectElement_iface
, p
);
1384 #define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN
1386 static HRESULT
HTMLSelectElement_get_dispid(HTMLDOMNode
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
1391 for(ptr
= name
; *ptr
&& is_digit(*ptr
); ptr
++) {
1392 idx
= idx
*10 + (*ptr
-'0');
1393 if(idx
> MSHTML_CUSTOM_DISPID_CNT
) {
1394 WARN("too big idx\n");
1395 return DISP_E_UNKNOWNNAME
;
1399 return DISP_E_UNKNOWNNAME
;
1401 *dispid
= DISPID_OPTIONCOL_0
+ idx
;
1405 static HRESULT
HTMLSelectElement_dispex_get_name(HTMLDOMNode
*iface
, DISPID id
, BSTR
*name
)
1407 DWORD idx
= id
- DISPID_OPTIONCOL_0
;
1411 if(idx
> MSHTML_CUSTOM_DISPID_CNT
)
1412 return DISP_E_MEMBERNOTFOUND
;
1414 len
= swprintf(buf
, ARRAY_SIZE(buf
), L
"%u", idx
);
1415 return (*name
= SysAllocStringLen(buf
, len
)) ? S_OK
: E_OUTOFMEMORY
;
1418 static HRESULT
HTMLSelectElement_invoke(HTMLDOMNode
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
1419 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1421 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1423 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
1426 case DISPATCH_PROPERTYGET
: {
1430 hres
= htmlselect_item(This
, id
-DISPID_OPTIONCOL_0
, &ret
);
1435 V_VT(res
) = VT_DISPATCH
;
1436 V_DISPATCH(res
) = ret
;
1438 V_VT(res
) = VT_NULL
;
1444 FIXME("unimplemented flags %x\n", flags
);
1451 static void HTMLSelectElement_traverse(HTMLDOMNode
*iface
, nsCycleCollectionTraversalCallback
*cb
)
1453 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1456 note_cc_edge((nsISupports
*)This
->nsselect
, "This->nsselect", cb
);
1459 static void HTMLSelectElement_unlink(HTMLDOMNode
*iface
)
1461 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1463 if(This
->nsselect
) {
1464 nsIDOMHTMLSelectElement
*nsselect
= This
->nsselect
;
1466 This
->nsselect
= NULL
;
1467 nsIDOMHTMLSelectElement_Release(nsselect
);
1471 static const NodeImplVtbl HTMLSelectElementImplVtbl
= {
1472 &CLSID_HTMLSelectElement
,
1473 HTMLSelectElement_QI
,
1474 HTMLElement_destructor
,
1477 HTMLElement_dispatch_nsevent_hook
,
1478 HTMLElement_handle_event
,
1479 HTMLElement_get_attr_col
,
1481 HTMLSelectElementImpl_put_disabled
,
1482 HTMLSelectElementImpl_get_disabled
,
1485 HTMLSelectElement_get_dispid
,
1486 HTMLSelectElement_dispex_get_name
,
1487 HTMLSelectElement_invoke
,
1489 HTMLSelectElement_traverse
,
1490 HTMLSelectElement_unlink
1493 static const tid_t HTMLSelectElement_tids
[] = {
1495 IHTMLSelectElement_tid
,
1499 static dispex_static_data_t HTMLSelectElement_dispex
= {
1500 L
"HTMLSelectElement",
1502 DispHTMLSelectElement_tid
,
1503 HTMLSelectElement_tids
,
1504 HTMLElement_init_dispex_info
1507 HRESULT
HTMLSelectElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
1509 HTMLSelectElement
*ret
;
1512 ret
= calloc(1, sizeof(HTMLSelectElement
));
1514 return E_OUTOFMEMORY
;
1516 ret
->IHTMLSelectElement_iface
.lpVtbl
= &HTMLSelectElementVtbl
;
1517 ret
->element
.node
.vtbl
= &HTMLSelectElementImplVtbl
;
1519 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLSelectElement_dispex
);
1521 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLSelectElement
, (void**)&ret
->nsselect
);
1522 assert(nsres
== NS_OK
);
1524 *elem
= &ret
->element
;