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
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
32 #include "htmlevent.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
36 struct HTMLOptionElement
{
39 IHTMLOptionElement IHTMLOptionElement_iface
;
41 nsIDOMHTMLOptionElement
*nsoption
;
44 static inline HTMLOptionElement
*impl_from_IHTMLOptionElement(IHTMLOptionElement
*iface
)
46 return CONTAINING_RECORD(iface
, HTMLOptionElement
, IHTMLOptionElement_iface
);
49 static HRESULT WINAPI
HTMLOptionElement_QueryInterface(IHTMLOptionElement
*iface
,
50 REFIID riid
, void **ppv
)
52 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
54 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
57 static ULONG WINAPI
HTMLOptionElement_AddRef(IHTMLOptionElement
*iface
)
59 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
61 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
64 static ULONG WINAPI
HTMLOptionElement_Release(IHTMLOptionElement
*iface
)
66 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
68 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
71 static HRESULT WINAPI
HTMLOptionElement_GetTypeInfoCount(IHTMLOptionElement
*iface
, UINT
*pctinfo
)
73 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
74 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
77 static HRESULT WINAPI
HTMLOptionElement_GetTypeInfo(IHTMLOptionElement
*iface
, UINT iTInfo
,
78 LCID lcid
, ITypeInfo
**ppTInfo
)
80 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
81 return IDispatchEx_GetTypeInfo(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
85 static HRESULT WINAPI
HTMLOptionElement_GetIDsOfNames(IHTMLOptionElement
*iface
, REFIID riid
,
86 LPOLESTR
*rgszNames
, UINT cNames
,
87 LCID lcid
, DISPID
*rgDispId
)
89 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
90 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
91 cNames
, lcid
, rgDispId
);
94 static HRESULT WINAPI
HTMLOptionElement_Invoke(IHTMLOptionElement
*iface
, DISPID dispIdMember
,
95 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
96 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
98 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
99 return IDispatchEx_Invoke(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
100 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
103 static HRESULT WINAPI
HTMLOptionElement_put_selected(IHTMLOptionElement
*iface
, VARIANT_BOOL v
)
105 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
108 TRACE("(%p)->(%x)\n", This
, v
);
110 nsres
= nsIDOMHTMLOptionElement_SetSelected(This
->nsoption
, v
!= VARIANT_FALSE
);
111 if(NS_FAILED(nsres
)) {
112 ERR("SetSelected failed: %08x\n", nsres
);
119 static HRESULT WINAPI
HTMLOptionElement_get_selected(IHTMLOptionElement
*iface
, VARIANT_BOOL
*p
)
121 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
125 TRACE("(%p)->(%p)\n", This
, p
);
127 nsres
= nsIDOMHTMLOptionElement_GetSelected(This
->nsoption
, &selected
);
128 if(NS_FAILED(nsres
)) {
129 ERR("GetSelected failed: %08x\n", nsres
);
133 *p
= variant_bool(selected
);
137 static HRESULT WINAPI
HTMLOptionElement_put_value(IHTMLOptionElement
*iface
, BSTR v
)
139 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
143 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
145 nsAString_InitDepend(&value_str
, v
);
146 nsres
= nsIDOMHTMLOptionElement_SetValue(This
->nsoption
, &value_str
);
147 nsAString_Finish(&value_str
);
149 ERR("SetValue failed: %08x\n", nsres
);
154 static HRESULT WINAPI
HTMLOptionElement_get_value(IHTMLOptionElement
*iface
, BSTR
*p
)
156 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
160 TRACE("(%p)->(%p)\n", This
, p
);
162 nsAString_Init(&value_str
, NULL
);
163 nsres
= nsIDOMHTMLOptionElement_GetValue(This
->nsoption
, &value_str
);
164 return return_nsstr(nsres
, &value_str
, p
);
167 static HRESULT WINAPI
HTMLOptionElement_put_defaultSelected(IHTMLOptionElement
*iface
, VARIANT_BOOL v
)
169 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
170 cpp_bool val
, selected
;
173 TRACE("(%p)->(%x)\n", This
, v
);
175 val
= (v
== VARIANT_TRUE
);
177 nsres
= nsIDOMHTMLOptionElement_GetSelected(This
->nsoption
, &selected
);
178 if(NS_FAILED(nsres
)) {
179 ERR("GetSelected failed: %08x\n", nsres
);
183 nsres
= nsIDOMHTMLOptionElement_SetDefaultSelected(This
->nsoption
, val
);
184 if(NS_FAILED(nsres
)) {
185 ERR("SetDefaultSelected failed: %08x\n", nsres
);
189 if(val
!= selected
) {
190 nsres
= nsIDOMHTMLOptionElement_SetSelected(This
->nsoption
, selected
); /* WinAPI will reserve selected property */
191 if(NS_FAILED(nsres
)) {
192 ERR("SetSelected failed: %08x\n", nsres
);
200 static HRESULT WINAPI
HTMLOptionElement_get_defaultSelected(IHTMLOptionElement
*iface
, VARIANT_BOOL
*p
)
202 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
206 TRACE("(%p)->(%p)\n", This
, p
);
209 nsres
= nsIDOMHTMLOptionElement_GetDefaultSelected(This
->nsoption
, &val
);
210 if(NS_FAILED(nsres
)) {
211 ERR("GetDefaultSelected failed: %08x\n", nsres
);
215 *p
= variant_bool(val
);
219 static HRESULT WINAPI
HTMLOptionElement_put_index(IHTMLOptionElement
*iface
, LONG v
)
221 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
222 FIXME("(%p)->(%d)\n", This
, v
);
226 static HRESULT WINAPI
HTMLOptionElement_get_index(IHTMLOptionElement
*iface
, LONG
*p
)
228 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
232 TRACE("(%p)->(%p)\n", This
, p
);
237 nsres
= nsIDOMHTMLOptionElement_GetIndex(This
->nsoption
, &val
);
238 if(NS_FAILED(nsres
)) {
239 ERR("GetIndex failed: %08x\n", nsres
);
246 static HRESULT WINAPI
HTMLOptionElement_put_text(IHTMLOptionElement
*iface
, BSTR v
)
248 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
249 nsIDOMText
*text_node
;
254 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
256 if(!This
->element
.node
.doc
->nsdoc
) {
257 WARN("NULL nsdoc\n");
264 nsres
= nsIDOMElement_GetFirstChild(This
->element
.dom_element
, &child
);
265 if(NS_FAILED(nsres
) || !child
)
268 nsres
= nsIDOMElement_RemoveChild(This
->element
.dom_element
, child
, &tmp
);
269 nsIDOMNode_Release(child
);
270 if(NS_SUCCEEDED(nsres
)) {
271 nsIDOMNode_Release(tmp
);
273 ERR("RemoveChild failed: %08x\n", nsres
);
278 nsAString_InitDepend(&text_str
, v
);
279 nsres
= nsIDOMHTMLDocument_CreateTextNode(This
->element
.node
.doc
->nsdoc
, &text_str
, &text_node
);
280 nsAString_Finish(&text_str
);
281 if(NS_FAILED(nsres
)) {
282 ERR("CreateTextNode failed: %08x\n", nsres
);
286 nsres
= nsIDOMElement_AppendChild(This
->element
.dom_element
, (nsIDOMNode
*)text_node
, &tmp
);
287 if(NS_SUCCEEDED(nsres
))
288 nsIDOMNode_Release(tmp
);
290 ERR("AppendChild failed: %08x\n", nsres
);
295 static HRESULT WINAPI
HTMLOptionElement_get_text(IHTMLOptionElement
*iface
, BSTR
*p
)
297 HTMLOptionElement
*This
= impl_from_IHTMLOptionElement(iface
);
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
;
314 TRACE("(%p)->(%p)\n", This
, p
);
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
);
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
;
367 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
379 note_cc_edge((nsISupports
*)This
->nsoption
, "This->nsoption", cb
);
382 static void HTMLOptionElement_unlink(HTMLDOMNode
*iface
)
384 HTMLOptionElement
*This
= HTMLOptionElement_from_HTMLDOMNode(iface
);
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
,
400 HTMLElement_handle_event
,
401 HTMLElement_get_attr_col
,
410 HTMLOptionElement_traverse
,
411 HTMLOptionElement_unlink
414 static const tid_t HTMLOptionElement_iface_tids
[] = {
416 IHTMLOptionElement_tid
,
419 static dispex_static_data_t HTMLOptionElement_dispex
= {
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
;
431 ret
= heap_alloc_zero(sizeof(HTMLOptionElement
));
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
;
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
;
469 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
470 return E_NOINTERFACE
;
473 IUnknown_AddRef((IUnknown
*)*ppv
);
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=%d\n", This
, 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=%d\n", This
, ref
);
495 release_dispex(&This
->dispex
);
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
;
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
) {
551 hres
= create_nselem(This
->window
->doc
, L
"OPTION", &nselem
);
555 hres
= get_node((nsIDOMNode
*)nselem
, TRUE
, &node
);
556 nsIDOMElement_Release(nselem
);
560 hres
= IHTMLDOMNode_QueryInterface(&node
->IHTMLDOMNode_iface
,
561 &IID_IHTMLOptionElement
, (void**)optelem
);
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
));
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 const tid_t HTMLOptionElementFactory_iface_tids
[] = {
594 IHTMLOptionElementFactory_tid
,
598 static dispex_static_data_t HTMLOptionElementFactory_dispex
= {
600 IHTMLOptionElementFactory_tid
,
601 HTMLOptionElementFactory_iface_tids
,
602 HTMLElement_init_dispex_info
605 HRESULT
HTMLOptionElementFactory_Create(HTMLInnerWindow
*window
, HTMLOptionElementFactory
**ret_ptr
)
607 HTMLOptionElementFactory
*ret
;
609 ret
= heap_alloc(sizeof(*ret
));
611 return E_OUTOFMEMORY
;
613 ret
->IHTMLOptionElementFactory_iface
.lpVtbl
= &HTMLOptionElementFactoryVtbl
;
615 ret
->window
= window
;
617 init_dispatch(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLOptionElementFactory_iface
,
618 &HTMLOptionElementFactory_dispex
, dispex_compat_mode(&window
->event_target
.dispex
));
624 struct HTMLSelectElement
{
627 IHTMLSelectElement IHTMLSelectElement_iface
;
629 nsIDOMHTMLSelectElement
*nsselect
;
632 static inline HTMLSelectElement
*impl_from_IHTMLSelectElement(IHTMLSelectElement
*iface
)
634 return CONTAINING_RECORD(iface
, HTMLSelectElement
, IHTMLSelectElement_iface
);
637 static HRESULT
htmlselect_item(HTMLSelectElement
*This
, int i
, IDispatch
**ret
)
639 nsIDOMHTMLOptionsCollection
*nscol
;
644 nsres
= nsIDOMHTMLSelectElement_GetOptions(This
->nsselect
, &nscol
);
645 if(NS_FAILED(nsres
)) {
646 ERR("GetOptions failed: %08x\n", nsres
);
650 nsres
= nsIDOMHTMLOptionsCollection_Item(nscol
, i
, &nsnode
);
651 nsIDOMHTMLOptionsCollection_Release(nscol
);
652 if(NS_FAILED(nsres
)) {
653 ERR("Item failed: %08x\n", nsres
);
660 hres
= get_node(nsnode
, TRUE
, &node
);
661 nsIDOMNode_Release(nsnode
);
665 *ret
= (IDispatch
*)&node
->IHTMLDOMNode_iface
;
672 static HRESULT WINAPI
HTMLSelectElement_QueryInterface(IHTMLSelectElement
*iface
,
673 REFIID riid
, void **ppv
)
675 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
677 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
680 static ULONG WINAPI
HTMLSelectElement_AddRef(IHTMLSelectElement
*iface
)
682 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
684 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
687 static ULONG WINAPI
HTMLSelectElement_Release(IHTMLSelectElement
*iface
)
689 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
691 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
694 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement
*iface
, UINT
*pctinfo
)
696 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
698 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
701 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfo(IHTMLSelectElement
*iface
, UINT iTInfo
,
702 LCID lcid
, ITypeInfo
**ppTInfo
)
704 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
706 return IDispatchEx_GetTypeInfo(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
710 static HRESULT WINAPI
HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement
*iface
, REFIID riid
,
711 LPOLESTR
*rgszNames
, UINT cNames
,
712 LCID lcid
, DISPID
*rgDispId
)
714 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
716 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
717 cNames
, lcid
, rgDispId
);
720 static HRESULT WINAPI
HTMLSelectElement_Invoke(IHTMLSelectElement
*iface
, DISPID dispIdMember
,
721 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
722 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
724 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
726 return IDispatchEx_Invoke(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
727 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
730 static HRESULT WINAPI
HTMLSelectElement_put_size(IHTMLSelectElement
*iface
, LONG v
)
732 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
735 TRACE("(%p)->(%d)\n", This
, v
);
737 return CTL_E_INVALIDPROPERTYVALUE
;
739 nsres
= nsIDOMHTMLSelectElement_SetSize(This
->nsselect
, v
);
740 if(NS_FAILED(nsres
)) {
741 ERR("SetSize failed: %08x\n", nsres
);
747 static HRESULT WINAPI
HTMLSelectElement_get_size(IHTMLSelectElement
*iface
, LONG
*p
)
749 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
753 TRACE("(%p)->(%p)\n", This
, p
);
757 nsres
= nsIDOMHTMLSelectElement_GetSize(This
->nsselect
, &val
);
758 if(NS_FAILED(nsres
)) {
759 ERR("GetSize failed: %08x\n", nsres
);
766 static HRESULT WINAPI
HTMLSelectElement_put_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
768 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
771 TRACE("(%p)->(%x)\n", This
, v
);
773 nsres
= nsIDOMHTMLSelectElement_SetMultiple(This
->nsselect
, !!v
);
774 assert(nsres
== NS_OK
);
778 static HRESULT WINAPI
HTMLSelectElement_get_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
780 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
784 TRACE("(%p)->(%p)\n", This
, p
);
786 nsres
= nsIDOMHTMLSelectElement_GetMultiple(This
->nsselect
, &val
);
787 assert(nsres
== NS_OK
);
789 *p
= variant_bool(val
);
793 static HRESULT WINAPI
HTMLSelectElement_put_name(IHTMLSelectElement
*iface
, BSTR v
)
795 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
799 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
800 nsAString_InitDepend(&str
, v
);
801 nsres
= nsIDOMHTMLSelectElement_SetName(This
->nsselect
, &str
);
802 nsAString_Finish(&str
);
804 if(NS_FAILED(nsres
)) {
805 ERR("SetName failed: %08x\n", nsres
);
811 static HRESULT WINAPI
HTMLSelectElement_get_name(IHTMLSelectElement
*iface
, BSTR
*p
)
813 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
817 TRACE("(%p)->(%p)\n", This
, p
);
819 nsAString_Init(&name_str
, NULL
);
820 nsres
= nsIDOMHTMLSelectElement_GetName(This
->nsselect
, &name_str
);
822 return return_nsstr(nsres
, &name_str
, p
);
825 static HRESULT WINAPI
HTMLSelectElement_get_options(IHTMLSelectElement
*iface
, IDispatch
**p
)
827 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
829 TRACE("(%p)->(%p)\n", This
, p
);
831 *p
= (IDispatch
*)&This
->IHTMLSelectElement_iface
;
832 IDispatch_AddRef(*p
);
836 static HRESULT WINAPI
HTMLSelectElement_put_onchange(IHTMLSelectElement
*iface
, VARIANT v
)
838 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
840 TRACE("(%p)->()\n", This
);
842 return set_node_event(&This
->element
.node
, EVENTID_CHANGE
, &v
);
845 static HRESULT WINAPI
HTMLSelectElement_get_onchange(IHTMLSelectElement
*iface
, VARIANT
*p
)
847 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
848 FIXME("(%p)->(%p)\n", This
, p
);
852 static HRESULT WINAPI
HTMLSelectElement_put_selectedIndex(IHTMLSelectElement
*iface
, LONG v
)
854 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
857 TRACE("(%p)->(%d)\n", This
, v
);
859 nsres
= nsIDOMHTMLSelectElement_SetSelectedIndex(This
->nsselect
, v
);
861 ERR("SetSelectedIndex failed: %08x\n", nsres
);
866 static HRESULT WINAPI
HTMLSelectElement_get_selectedIndex(IHTMLSelectElement
*iface
, LONG
*p
)
868 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
871 TRACE("(%p)->(%p)\n", This
, p
);
873 nsres
= nsIDOMHTMLSelectElement_GetSelectedIndex(This
->nsselect
, p
);
874 if(NS_FAILED(nsres
)) {
875 ERR("GetSelectedIndex failed: %08x\n", nsres
);
882 static HRESULT WINAPI
HTMLSelectElement_get_type(IHTMLSelectElement
*iface
, BSTR
*p
)
884 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
888 TRACE("(%p)->(%p)\n", This
, p
);
890 nsAString_Init(&type_str
, NULL
);
891 nsres
= nsIDOMHTMLSelectElement_GetType(This
->nsselect
, &type_str
);
892 return return_nsstr(nsres
, &type_str
, p
);
895 static HRESULT WINAPI
HTMLSelectElement_put_value(IHTMLSelectElement
*iface
, BSTR v
)
897 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
901 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
903 nsAString_InitDepend(&value_str
, v
);
904 nsres
= nsIDOMHTMLSelectElement_SetValue(This
->nsselect
, &value_str
);
905 nsAString_Finish(&value_str
);
907 ERR("SetValue failed: %08x\n", nsres
);
912 static HRESULT WINAPI
HTMLSelectElement_get_value(IHTMLSelectElement
*iface
, BSTR
*p
)
914 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
918 TRACE("(%p)->(%p)\n", This
, p
);
920 nsAString_Init(&value_str
, NULL
);
921 nsres
= nsIDOMHTMLSelectElement_GetValue(This
->nsselect
, &value_str
);
922 return return_nsstr(nsres
, &value_str
, p
);
925 static HRESULT WINAPI
HTMLSelectElement_put_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
927 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
930 TRACE("(%p)->(%x)\n", This
, v
);
932 nsres
= nsIDOMHTMLSelectElement_SetDisabled(This
->nsselect
, v
!= VARIANT_FALSE
);
933 if(NS_FAILED(nsres
)) {
934 ERR("SetDisabled failed: %08x\n", nsres
);
941 static HRESULT WINAPI
HTMLSelectElement_get_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
943 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
944 cpp_bool disabled
= FALSE
;
947 TRACE("(%p)->(%p)\n", This
, p
);
949 nsres
= nsIDOMHTMLSelectElement_GetDisabled(This
->nsselect
, &disabled
);
950 if(NS_FAILED(nsres
)) {
951 ERR("GetDisabled failed: %08x\n", nsres
);
955 *p
= variant_bool(disabled
);
959 static HRESULT WINAPI
HTMLSelectElement_get_form(IHTMLSelectElement
*iface
, IHTMLFormElement
**p
)
961 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
962 nsIDOMHTMLFormElement
*nsform
;
965 TRACE("(%p)->(%p)\n", This
, p
);
970 nsres
= nsIDOMHTMLSelectElement_GetForm(This
->nsselect
, &nsform
);
971 return return_nsform(nsres
, nsform
, p
);
974 static HRESULT WINAPI
HTMLSelectElement_add(IHTMLSelectElement
*iface
, IHTMLElement
*element
,
977 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
978 nsIWritableVariant
*nsvariant
;
979 HTMLElement
*element_obj
;
982 TRACE("(%p)->(%p %s)\n", This
, element
, debugstr_variant(&before
));
984 element_obj
= unsafe_impl_from_IHTMLElement(element
);
986 FIXME("External IHTMLElement implementation?\n");
990 if(!element_obj
->html_element
) {
991 FIXME("Not HTML element\n");
995 nsvariant
= create_nsvariant();
999 switch(V_VT(&before
)) {
1002 nsres
= nsIWritableVariant_SetAsEmpty(nsvariant
);
1005 nsres
= nsIWritableVariant_SetAsInt16(nsvariant
, V_I2(&before
));
1008 FIXME("unhandled before %s\n", debugstr_variant(&before
));
1009 nsIWritableVariant_Release(nsvariant
);
1013 if(NS_SUCCEEDED(nsres
))
1014 nsres
= nsIDOMHTMLSelectElement_Add(This
->nsselect
, element_obj
->html_element
, (nsIVariant
*)nsvariant
);
1015 nsIWritableVariant_Release(nsvariant
);
1016 if(NS_FAILED(nsres
)) {
1017 ERR("Add failed: %08x\n", nsres
);
1024 static HRESULT WINAPI
HTMLSelectElement_remove(IHTMLSelectElement
*iface
, LONG index
)
1026 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1028 TRACE("(%p)->(%d)\n", This
, index
);
1030 return E_INVALIDARG
;
1032 nsres
= nsIDOMHTMLSelectElement_select_Remove(This
->nsselect
, index
);
1033 if(NS_FAILED(nsres
)) {
1034 ERR("Remove failed: %08x\n", nsres
);
1040 static HRESULT WINAPI
HTMLSelectElement_put_length(IHTMLSelectElement
*iface
, LONG v
)
1042 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1045 TRACE("(%p)->(%d)\n", This
, v
);
1047 nsres
= nsIDOMHTMLSelectElement_SetLength(This
->nsselect
, v
);
1048 if(NS_FAILED(nsres
))
1049 ERR("SetLength failed: %08x\n", nsres
);
1054 static HRESULT WINAPI
HTMLSelectElement_get_length(IHTMLSelectElement
*iface
, LONG
*p
)
1056 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1060 TRACE("(%p)->(%p)\n", This
, p
);
1062 nsres
= nsIDOMHTMLSelectElement_GetLength(This
->nsselect
, &length
);
1063 if(NS_FAILED(nsres
))
1064 ERR("GetLength failed: %08x\n", nsres
);
1068 TRACE("ret %d\n", *p
);
1072 static HRESULT WINAPI
HTMLSelectElement_get__newEnum(IHTMLSelectElement
*iface
, IUnknown
**p
)
1074 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1075 FIXME("(%p)->(%p)\n", This
, p
);
1079 static HRESULT WINAPI
HTMLSelectElement_item(IHTMLSelectElement
*iface
, VARIANT name
,
1080 VARIANT index
, IDispatch
**pdisp
)
1082 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1084 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
1090 if(V_VT(&name
) == VT_I4
) {
1092 return E_INVALIDARG
;
1093 return htmlselect_item(This
, V_I4(&name
), pdisp
);
1096 FIXME("Unsupported args\n");
1100 static HRESULT WINAPI
HTMLSelectElement_tags(IHTMLSelectElement
*iface
, VARIANT tagName
,
1103 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1104 FIXME("(%p)->(v %p)\n", This
, pdisp
);
1108 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl
= {
1109 HTMLSelectElement_QueryInterface
,
1110 HTMLSelectElement_AddRef
,
1111 HTMLSelectElement_Release
,
1112 HTMLSelectElement_GetTypeInfoCount
,
1113 HTMLSelectElement_GetTypeInfo
,
1114 HTMLSelectElement_GetIDsOfNames
,
1115 HTMLSelectElement_Invoke
,
1116 HTMLSelectElement_put_size
,
1117 HTMLSelectElement_get_size
,
1118 HTMLSelectElement_put_multiple
,
1119 HTMLSelectElement_get_multiple
,
1120 HTMLSelectElement_put_name
,
1121 HTMLSelectElement_get_name
,
1122 HTMLSelectElement_get_options
,
1123 HTMLSelectElement_put_onchange
,
1124 HTMLSelectElement_get_onchange
,
1125 HTMLSelectElement_put_selectedIndex
,
1126 HTMLSelectElement_get_selectedIndex
,
1127 HTMLSelectElement_get_type
,
1128 HTMLSelectElement_put_value
,
1129 HTMLSelectElement_get_value
,
1130 HTMLSelectElement_put_disabled
,
1131 HTMLSelectElement_get_disabled
,
1132 HTMLSelectElement_get_form
,
1133 HTMLSelectElement_add
,
1134 HTMLSelectElement_remove
,
1135 HTMLSelectElement_put_length
,
1136 HTMLSelectElement_get_length
,
1137 HTMLSelectElement_get__newEnum
,
1138 HTMLSelectElement_item
,
1139 HTMLSelectElement_tags
1142 static inline HTMLSelectElement
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
1144 return CONTAINING_RECORD(iface
, HTMLSelectElement
, element
.node
);
1147 static HRESULT
HTMLSelectElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
1149 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1153 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1154 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1155 *ppv
= &This
->IHTMLSelectElement_iface
;
1156 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1157 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1158 *ppv
= &This
->IHTMLSelectElement_iface
;
1159 }else if(IsEqualGUID(&IID_IHTMLSelectElement
, riid
)) {
1160 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This
, ppv
);
1161 *ppv
= &This
->IHTMLSelectElement_iface
;
1165 IUnknown_AddRef((IUnknown
*)*ppv
);
1169 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
1172 static HRESULT
HTMLSelectElementImpl_put_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL v
)
1174 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1175 return IHTMLSelectElement_put_disabled(&This
->IHTMLSelectElement_iface
, v
);
1178 static HRESULT
HTMLSelectElementImpl_get_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL
*p
)
1180 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1181 return IHTMLSelectElement_get_disabled(&This
->IHTMLSelectElement_iface
, p
);
1184 #define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN
1186 static HRESULT
HTMLSelectElement_get_dispid(HTMLDOMNode
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
1191 for(ptr
= name
; *ptr
&& is_digit(*ptr
); ptr
++) {
1192 idx
= idx
*10 + (*ptr
-'0');
1193 if(idx
> MSHTML_CUSTOM_DISPID_CNT
) {
1194 WARN("too big idx\n");
1195 return DISP_E_UNKNOWNNAME
;
1199 return DISP_E_UNKNOWNNAME
;
1201 *dispid
= DISPID_OPTIONCOL_0
+ idx
;
1205 static HRESULT
HTMLSelectElement_invoke(HTMLDOMNode
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
1206 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1208 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1210 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
1213 case DISPATCH_PROPERTYGET
: {
1217 hres
= htmlselect_item(This
, id
-DISPID_OPTIONCOL_0
, &ret
);
1222 V_VT(res
) = VT_DISPATCH
;
1223 V_DISPATCH(res
) = ret
;
1225 V_VT(res
) = VT_NULL
;
1231 FIXME("unimplemented flags %x\n", flags
);
1238 static void HTMLSelectElement_traverse(HTMLDOMNode
*iface
, nsCycleCollectionTraversalCallback
*cb
)
1240 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1243 note_cc_edge((nsISupports
*)This
->nsselect
, "This->nsselect", cb
);
1246 static void HTMLSelectElement_unlink(HTMLDOMNode
*iface
)
1248 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1250 if(This
->nsselect
) {
1251 nsIDOMHTMLSelectElement
*nsselect
= This
->nsselect
;
1253 This
->nsselect
= NULL
;
1254 nsIDOMHTMLSelectElement_Release(nsselect
);
1258 static const NodeImplVtbl HTMLSelectElementImplVtbl
= {
1259 &CLSID_HTMLSelectElement
,
1260 HTMLSelectElement_QI
,
1261 HTMLElement_destructor
,
1264 HTMLElement_handle_event
,
1265 HTMLElement_get_attr_col
,
1267 HTMLSelectElementImpl_put_disabled
,
1268 HTMLSelectElementImpl_get_disabled
,
1271 HTMLSelectElement_get_dispid
,
1272 HTMLSelectElement_invoke
,
1274 HTMLSelectElement_traverse
,
1275 HTMLSelectElement_unlink
1278 static const tid_t HTMLSelectElement_tids
[] = {
1280 IHTMLSelectElement_tid
,
1284 static dispex_static_data_t HTMLSelectElement_dispex
= {
1286 DispHTMLSelectElement_tid
,
1287 HTMLSelectElement_tids
,
1288 HTMLElement_init_dispex_info
1291 HRESULT
HTMLSelectElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
1293 HTMLSelectElement
*ret
;
1296 ret
= heap_alloc_zero(sizeof(HTMLSelectElement
));
1298 return E_OUTOFMEMORY
;
1300 ret
->IHTMLSelectElement_iface
.lpVtbl
= &HTMLSelectElementVtbl
;
1301 ret
->element
.node
.vtbl
= &HTMLSelectElementImplVtbl
;
1303 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLSelectElement_dispex
);
1305 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLSelectElement
, (void**)&ret
->nsselect
);
1306 assert(nsres
== NS_OK
);
1308 *elem
= &ret
->element
;