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 static const PRUnichar optionW
[] = {'O','P','T','I','O','N',0};
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
, optionW
, &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 const tid_t HTMLOptionElementFactory_iface_tids
[] = {
596 IHTMLOptionElementFactory_tid
,
600 static dispex_static_data_t HTMLOptionElementFactory_dispex
= {
602 IHTMLOptionElementFactory_tid
,
603 HTMLOptionElementFactory_iface_tids
,
604 HTMLElement_init_dispex_info
607 HRESULT
HTMLOptionElementFactory_Create(HTMLInnerWindow
*window
, HTMLOptionElementFactory
**ret_ptr
)
609 HTMLOptionElementFactory
*ret
;
611 ret
= heap_alloc(sizeof(*ret
));
613 return E_OUTOFMEMORY
;
615 ret
->IHTMLOptionElementFactory_iface
.lpVtbl
= &HTMLOptionElementFactoryVtbl
;
617 ret
->window
= window
;
619 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLOptionElementFactory_iface
,
620 &HTMLOptionElementFactory_dispex
);
626 struct HTMLSelectElement
{
629 IHTMLSelectElement IHTMLSelectElement_iface
;
631 nsIDOMHTMLSelectElement
*nsselect
;
634 static inline HTMLSelectElement
*impl_from_IHTMLSelectElement(IHTMLSelectElement
*iface
)
636 return CONTAINING_RECORD(iface
, HTMLSelectElement
, IHTMLSelectElement_iface
);
639 static HRESULT
htmlselect_item(HTMLSelectElement
*This
, int i
, IDispatch
**ret
)
641 nsIDOMHTMLOptionsCollection
*nscol
;
646 nsres
= nsIDOMHTMLSelectElement_GetOptions(This
->nsselect
, &nscol
);
647 if(NS_FAILED(nsres
)) {
648 ERR("GetOptions failed: %08x\n", nsres
);
652 nsres
= nsIDOMHTMLOptionsCollection_Item(nscol
, i
, &nsnode
);
653 nsIDOMHTMLOptionsCollection_Release(nscol
);
654 if(NS_FAILED(nsres
)) {
655 ERR("Item failed: %08x\n", nsres
);
662 hres
= get_node(nsnode
, TRUE
, &node
);
663 nsIDOMNode_Release(nsnode
);
667 *ret
= (IDispatch
*)&node
->IHTMLDOMNode_iface
;
674 static HRESULT WINAPI
HTMLSelectElement_QueryInterface(IHTMLSelectElement
*iface
,
675 REFIID riid
, void **ppv
)
677 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
679 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
682 static ULONG WINAPI
HTMLSelectElement_AddRef(IHTMLSelectElement
*iface
)
684 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
686 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
689 static ULONG WINAPI
HTMLSelectElement_Release(IHTMLSelectElement
*iface
)
691 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
693 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
696 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement
*iface
, UINT
*pctinfo
)
698 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
700 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
703 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfo(IHTMLSelectElement
*iface
, UINT iTInfo
,
704 LCID lcid
, ITypeInfo
**ppTInfo
)
706 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
708 return IDispatchEx_GetTypeInfo(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
712 static HRESULT WINAPI
HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement
*iface
, REFIID riid
,
713 LPOLESTR
*rgszNames
, UINT cNames
,
714 LCID lcid
, DISPID
*rgDispId
)
716 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
718 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
719 cNames
, lcid
, rgDispId
);
722 static HRESULT WINAPI
HTMLSelectElement_Invoke(IHTMLSelectElement
*iface
, DISPID dispIdMember
,
723 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
724 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
726 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
728 return IDispatchEx_Invoke(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
729 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
732 static HRESULT WINAPI
HTMLSelectElement_put_size(IHTMLSelectElement
*iface
, LONG v
)
734 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
737 TRACE("(%p)->(%d)\n", This
, v
);
739 return CTL_E_INVALIDPROPERTYVALUE
;
741 nsres
= nsIDOMHTMLSelectElement_SetSize(This
->nsselect
, v
);
742 if(NS_FAILED(nsres
)) {
743 ERR("SetSize failed: %08x\n", nsres
);
749 static HRESULT WINAPI
HTMLSelectElement_get_size(IHTMLSelectElement
*iface
, LONG
*p
)
751 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
755 TRACE("(%p)->(%p)\n", This
, p
);
759 nsres
= nsIDOMHTMLSelectElement_GetSize(This
->nsselect
, &val
);
760 if(NS_FAILED(nsres
)) {
761 ERR("GetSize failed: %08x\n", nsres
);
768 static HRESULT WINAPI
HTMLSelectElement_put_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
770 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
773 TRACE("(%p)->(%x)\n", This
, v
);
775 nsres
= nsIDOMHTMLSelectElement_SetMultiple(This
->nsselect
, !!v
);
776 assert(nsres
== NS_OK
);
780 static HRESULT WINAPI
HTMLSelectElement_get_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
782 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
786 TRACE("(%p)->(%p)\n", This
, p
);
788 nsres
= nsIDOMHTMLSelectElement_GetMultiple(This
->nsselect
, &val
);
789 assert(nsres
== NS_OK
);
791 *p
= variant_bool(val
);
795 static HRESULT WINAPI
HTMLSelectElement_put_name(IHTMLSelectElement
*iface
, BSTR v
)
797 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
801 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
802 nsAString_InitDepend(&str
, v
);
803 nsres
= nsIDOMHTMLSelectElement_SetName(This
->nsselect
, &str
);
804 nsAString_Finish(&str
);
806 if(NS_FAILED(nsres
)) {
807 ERR("SetName failed: %08x\n", nsres
);
813 static HRESULT WINAPI
HTMLSelectElement_get_name(IHTMLSelectElement
*iface
, BSTR
*p
)
815 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
819 TRACE("(%p)->(%p)\n", This
, p
);
821 nsAString_Init(&name_str
, NULL
);
822 nsres
= nsIDOMHTMLSelectElement_GetName(This
->nsselect
, &name_str
);
824 return return_nsstr(nsres
, &name_str
, p
);
827 static HRESULT WINAPI
HTMLSelectElement_get_options(IHTMLSelectElement
*iface
, IDispatch
**p
)
829 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
831 TRACE("(%p)->(%p)\n", This
, p
);
833 *p
= (IDispatch
*)&This
->IHTMLSelectElement_iface
;
834 IDispatch_AddRef(*p
);
838 static HRESULT WINAPI
HTMLSelectElement_put_onchange(IHTMLSelectElement
*iface
, VARIANT v
)
840 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
842 TRACE("(%p)->()\n", This
);
844 return set_node_event(&This
->element
.node
, EVENTID_CHANGE
, &v
);
847 static HRESULT WINAPI
HTMLSelectElement_get_onchange(IHTMLSelectElement
*iface
, VARIANT
*p
)
849 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
850 FIXME("(%p)->(%p)\n", This
, p
);
854 static HRESULT WINAPI
HTMLSelectElement_put_selectedIndex(IHTMLSelectElement
*iface
, LONG v
)
856 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
859 TRACE("(%p)->(%d)\n", This
, v
);
861 nsres
= nsIDOMHTMLSelectElement_SetSelectedIndex(This
->nsselect
, v
);
863 ERR("SetSelectedIndex failed: %08x\n", nsres
);
868 static HRESULT WINAPI
HTMLSelectElement_get_selectedIndex(IHTMLSelectElement
*iface
, LONG
*p
)
870 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
873 TRACE("(%p)->(%p)\n", This
, p
);
875 nsres
= nsIDOMHTMLSelectElement_GetSelectedIndex(This
->nsselect
, p
);
876 if(NS_FAILED(nsres
)) {
877 ERR("GetSelectedIndex failed: %08x\n", nsres
);
884 static HRESULT WINAPI
HTMLSelectElement_get_type(IHTMLSelectElement
*iface
, BSTR
*p
)
886 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
890 TRACE("(%p)->(%p)\n", This
, p
);
892 nsAString_Init(&type_str
, NULL
);
893 nsres
= nsIDOMHTMLSelectElement_GetType(This
->nsselect
, &type_str
);
894 return return_nsstr(nsres
, &type_str
, p
);
897 static HRESULT WINAPI
HTMLSelectElement_put_value(IHTMLSelectElement
*iface
, BSTR v
)
899 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
903 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
905 nsAString_InitDepend(&value_str
, v
);
906 nsres
= nsIDOMHTMLSelectElement_SetValue(This
->nsselect
, &value_str
);
907 nsAString_Finish(&value_str
);
909 ERR("SetValue failed: %08x\n", nsres
);
914 static HRESULT WINAPI
HTMLSelectElement_get_value(IHTMLSelectElement
*iface
, BSTR
*p
)
916 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
920 TRACE("(%p)->(%p)\n", This
, p
);
922 nsAString_Init(&value_str
, NULL
);
923 nsres
= nsIDOMHTMLSelectElement_GetValue(This
->nsselect
, &value_str
);
924 return return_nsstr(nsres
, &value_str
, p
);
927 static HRESULT WINAPI
HTMLSelectElement_put_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
929 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
932 TRACE("(%p)->(%x)\n", This
, v
);
934 nsres
= nsIDOMHTMLSelectElement_SetDisabled(This
->nsselect
, v
!= VARIANT_FALSE
);
935 if(NS_FAILED(nsres
)) {
936 ERR("SetDisabled failed: %08x\n", nsres
);
943 static HRESULT WINAPI
HTMLSelectElement_get_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
945 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
946 cpp_bool disabled
= FALSE
;
949 TRACE("(%p)->(%p)\n", This
, p
);
951 nsres
= nsIDOMHTMLSelectElement_GetDisabled(This
->nsselect
, &disabled
);
952 if(NS_FAILED(nsres
)) {
953 ERR("GetDisabled failed: %08x\n", nsres
);
957 *p
= variant_bool(disabled
);
961 static HRESULT WINAPI
HTMLSelectElement_get_form(IHTMLSelectElement
*iface
, IHTMLFormElement
**p
)
963 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
964 nsIDOMHTMLFormElement
*nsform
;
967 TRACE("(%p)->(%p)\n", This
, p
);
972 nsres
= nsIDOMHTMLSelectElement_GetForm(This
->nsselect
, &nsform
);
973 return return_nsform(nsres
, nsform
, p
);
976 static HRESULT WINAPI
HTMLSelectElement_add(IHTMLSelectElement
*iface
, IHTMLElement
*element
,
979 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
980 nsIWritableVariant
*nsvariant
;
981 HTMLElement
*element_obj
;
984 TRACE("(%p)->(%p %s)\n", This
, element
, debugstr_variant(&before
));
986 element_obj
= unsafe_impl_from_IHTMLElement(element
);
988 FIXME("External IHTMLElement implementation?\n");
992 if(!element_obj
->html_element
) {
993 FIXME("Not HTML element\n");
997 nsvariant
= create_nsvariant();
1001 switch(V_VT(&before
)) {
1004 nsres
= nsIWritableVariant_SetAsEmpty(nsvariant
);
1007 nsres
= nsIWritableVariant_SetAsInt16(nsvariant
, V_I2(&before
));
1010 FIXME("unhandled before %s\n", debugstr_variant(&before
));
1011 nsIWritableVariant_Release(nsvariant
);
1015 if(NS_SUCCEEDED(nsres
))
1016 nsres
= nsIDOMHTMLSelectElement_Add(This
->nsselect
, element_obj
->html_element
, (nsIVariant
*)nsvariant
);
1017 nsIWritableVariant_Release(nsvariant
);
1018 if(NS_FAILED(nsres
)) {
1019 ERR("Add failed: %08x\n", nsres
);
1026 static HRESULT WINAPI
HTMLSelectElement_remove(IHTMLSelectElement
*iface
, LONG index
)
1028 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1030 TRACE("(%p)->(%d)\n", This
, index
);
1032 return E_INVALIDARG
;
1034 nsres
= nsIDOMHTMLSelectElement_select_Remove(This
->nsselect
, index
);
1035 if(NS_FAILED(nsres
)) {
1036 ERR("Remove failed: %08x\n", nsres
);
1042 static HRESULT WINAPI
HTMLSelectElement_put_length(IHTMLSelectElement
*iface
, LONG v
)
1044 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1047 TRACE("(%p)->(%d)\n", This
, v
);
1049 nsres
= nsIDOMHTMLSelectElement_SetLength(This
->nsselect
, v
);
1050 if(NS_FAILED(nsres
))
1051 ERR("SetLength failed: %08x\n", nsres
);
1056 static HRESULT WINAPI
HTMLSelectElement_get_length(IHTMLSelectElement
*iface
, LONG
*p
)
1058 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1062 TRACE("(%p)->(%p)\n", This
, p
);
1064 nsres
= nsIDOMHTMLSelectElement_GetLength(This
->nsselect
, &length
);
1065 if(NS_FAILED(nsres
))
1066 ERR("GetLength failed: %08x\n", nsres
);
1070 TRACE("ret %d\n", *p
);
1074 static HRESULT WINAPI
HTMLSelectElement_get__newEnum(IHTMLSelectElement
*iface
, IUnknown
**p
)
1076 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1077 FIXME("(%p)->(%p)\n", This
, p
);
1081 static HRESULT WINAPI
HTMLSelectElement_item(IHTMLSelectElement
*iface
, VARIANT name
,
1082 VARIANT index
, IDispatch
**pdisp
)
1084 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1086 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
1092 if(V_VT(&name
) == VT_I4
) {
1094 return E_INVALIDARG
;
1095 return htmlselect_item(This
, V_I4(&name
), pdisp
);
1098 FIXME("Unsupported args\n");
1102 static HRESULT WINAPI
HTMLSelectElement_tags(IHTMLSelectElement
*iface
, VARIANT tagName
,
1105 HTMLSelectElement
*This
= impl_from_IHTMLSelectElement(iface
);
1106 FIXME("(%p)->(v %p)\n", This
, pdisp
);
1110 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl
= {
1111 HTMLSelectElement_QueryInterface
,
1112 HTMLSelectElement_AddRef
,
1113 HTMLSelectElement_Release
,
1114 HTMLSelectElement_GetTypeInfoCount
,
1115 HTMLSelectElement_GetTypeInfo
,
1116 HTMLSelectElement_GetIDsOfNames
,
1117 HTMLSelectElement_Invoke
,
1118 HTMLSelectElement_put_size
,
1119 HTMLSelectElement_get_size
,
1120 HTMLSelectElement_put_multiple
,
1121 HTMLSelectElement_get_multiple
,
1122 HTMLSelectElement_put_name
,
1123 HTMLSelectElement_get_name
,
1124 HTMLSelectElement_get_options
,
1125 HTMLSelectElement_put_onchange
,
1126 HTMLSelectElement_get_onchange
,
1127 HTMLSelectElement_put_selectedIndex
,
1128 HTMLSelectElement_get_selectedIndex
,
1129 HTMLSelectElement_get_type
,
1130 HTMLSelectElement_put_value
,
1131 HTMLSelectElement_get_value
,
1132 HTMLSelectElement_put_disabled
,
1133 HTMLSelectElement_get_disabled
,
1134 HTMLSelectElement_get_form
,
1135 HTMLSelectElement_add
,
1136 HTMLSelectElement_remove
,
1137 HTMLSelectElement_put_length
,
1138 HTMLSelectElement_get_length
,
1139 HTMLSelectElement_get__newEnum
,
1140 HTMLSelectElement_item
,
1141 HTMLSelectElement_tags
1144 static inline HTMLSelectElement
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
1146 return CONTAINING_RECORD(iface
, HTMLSelectElement
, element
.node
);
1149 static HRESULT
HTMLSelectElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
1151 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1155 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1156 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1157 *ppv
= &This
->IHTMLSelectElement_iface
;
1158 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1159 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1160 *ppv
= &This
->IHTMLSelectElement_iface
;
1161 }else if(IsEqualGUID(&IID_IHTMLSelectElement
, riid
)) {
1162 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This
, ppv
);
1163 *ppv
= &This
->IHTMLSelectElement_iface
;
1167 IUnknown_AddRef((IUnknown
*)*ppv
);
1171 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
1174 static HRESULT
HTMLSelectElementImpl_put_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL v
)
1176 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1177 return IHTMLSelectElement_put_disabled(&This
->IHTMLSelectElement_iface
, v
);
1180 static HRESULT
HTMLSelectElementImpl_get_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL
*p
)
1182 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1183 return IHTMLSelectElement_get_disabled(&This
->IHTMLSelectElement_iface
, p
);
1186 #define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN
1188 static HRESULT
HTMLSelectElement_get_dispid(HTMLDOMNode
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
1193 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++) {
1194 idx
= idx
*10 + (*ptr
-'0');
1195 if(idx
> MSHTML_CUSTOM_DISPID_CNT
) {
1196 WARN("too big idx\n");
1197 return DISP_E_UNKNOWNNAME
;
1201 return DISP_E_UNKNOWNNAME
;
1203 *dispid
= DISPID_OPTIONCOL_0
+ idx
;
1207 static HRESULT
HTMLSelectElement_invoke(HTMLDOMNode
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
1208 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1210 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1212 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
1215 case DISPATCH_PROPERTYGET
: {
1219 hres
= htmlselect_item(This
, id
-DISPID_OPTIONCOL_0
, &ret
);
1224 V_VT(res
) = VT_DISPATCH
;
1225 V_DISPATCH(res
) = ret
;
1227 V_VT(res
) = VT_NULL
;
1233 FIXME("unimplemented flags %x\n", flags
);
1240 static void HTMLSelectElement_traverse(HTMLDOMNode
*iface
, nsCycleCollectionTraversalCallback
*cb
)
1242 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1245 note_cc_edge((nsISupports
*)This
->nsselect
, "This->nsselect", cb
);
1248 static void HTMLSelectElement_unlink(HTMLDOMNode
*iface
)
1250 HTMLSelectElement
*This
= impl_from_HTMLDOMNode(iface
);
1252 if(This
->nsselect
) {
1253 nsIDOMHTMLSelectElement
*nsselect
= This
->nsselect
;
1255 This
->nsselect
= NULL
;
1256 nsIDOMHTMLSelectElement_Release(nsselect
);
1260 static const NodeImplVtbl HTMLSelectElementImplVtbl
= {
1261 &CLSID_HTMLSelectElement
,
1262 HTMLSelectElement_QI
,
1263 HTMLElement_destructor
,
1266 HTMLElement_handle_event
,
1267 HTMLElement_get_attr_col
,
1269 HTMLSelectElementImpl_put_disabled
,
1270 HTMLSelectElementImpl_get_disabled
,
1273 HTMLSelectElement_get_dispid
,
1274 HTMLSelectElement_invoke
,
1276 HTMLSelectElement_traverse
,
1277 HTMLSelectElement_unlink
1280 static const tid_t HTMLSelectElement_tids
[] = {
1282 IHTMLSelectElement_tid
,
1286 static dispex_static_data_t HTMLSelectElement_dispex
= {
1288 DispHTMLSelectElement_tid
,
1289 HTMLSelectElement_tids
,
1290 HTMLElement_init_dispex_info
1293 HRESULT
HTMLSelectElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
1295 HTMLSelectElement
*ret
;
1298 ret
= heap_alloc_zero(sizeof(HTMLSelectElement
));
1300 return E_OUTOFMEMORY
;
1302 ret
->IHTMLSelectElement_iface
.lpVtbl
= &HTMLSelectElementVtbl
;
1303 ret
->element
.node
.vtbl
= &HTMLSelectElementImplVtbl
;
1305 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLSelectElement_dispex
);
1307 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLSelectElement
, (void**)&ret
->nsselect
);
1308 assert(nsres
== NS_OK
);
1310 *elem
= &ret
->element
;