2 * Copyright 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"
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: %08x\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: %08x\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: %08x\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: %08x\n", nsres
);
182 nsres
= nsIDOMHTMLOptionElement_SetDefaultSelected(This
->nsoption
, val
);
183 if(NS_FAILED(nsres
)) {
184 ERR("SetDefaultSelected failed: %08x\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: %08x\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: %08x\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)->(%d)\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: %08x\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
->nsdoc
) {
256 WARN("NULL nsdoc\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: %08x\n", nsres
);
277 nsAString_InitDepend(&text_str
, v
);
278 nsres
= nsIDOMHTMLDocument_CreateTextNode(This
->element
.node
.doc
->nsdoc
, &text_str
, &text_node
);
279 nsAString_Finish(&text_str
);
280 if(NS_FAILED(nsres
)) {
281 ERR("CreateTextNode failed: %08x\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: %08x\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
*impl_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
= impl_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
= impl_from_HTMLDOMNode(iface
);
378 note_cc_edge((nsISupports
*)This
->nsoption
, "This->nsoption", cb
);
381 static void HTMLOptionElement_unlink(HTMLDOMNode
*iface
)
383 HTMLOptionElement
*This
= impl_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_handle_event
,
400 HTMLElement_get_attr_col
,
409 HTMLOptionElement_traverse
,
410 HTMLOptionElement_unlink
413 static const tid_t HTMLOptionElement_iface_tids
[] = {
415 IHTMLOptionElement_tid
,
418 static dispex_static_data_t HTMLOptionElement_dispex
= {
420 DispHTMLOptionElement_tid
,
421 HTMLOptionElement_iface_tids
,
422 HTMLElement_init_dispex_info
425 HRESULT
HTMLOptionElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
427 HTMLOptionElement
*ret
;
430 ret
= heap_alloc_zero(sizeof(HTMLOptionElement
));
432 return E_OUTOFMEMORY
;
434 ret
->IHTMLOptionElement_iface
.lpVtbl
= &HTMLOptionElementVtbl
;
435 ret
->element
.node
.vtbl
= &HTMLOptionElementImplVtbl
;
437 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLOptionElement_dispex
);
439 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLOptionElement
, (void**)&ret
->nsoption
);
440 assert(nsres
== NS_OK
);
442 *elem
= &ret
->element
;
446 static inline HTMLOptionElementFactory
*impl_from_IHTMLOptionElementFactory(IHTMLOptionElementFactory
*iface
)
448 return CONTAINING_RECORD(iface
, HTMLOptionElementFactory
, IHTMLOptionElementFactory_iface
);
451 static HRESULT WINAPI
HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory
*iface
,
452 REFIID riid
, void **ppv
)
454 HTMLOptionElementFactory
*This
= impl_from_IHTMLOptionElementFactory(iface
);
456 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
458 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
459 *ppv
= &This
->IHTMLOptionElementFactory_iface
;
460 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
461 *ppv
= &This
->IHTMLOptionElementFactory_iface
;
462 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory
, riid
)) {
463 *ppv
= &This
->IHTMLOptionElementFactory_iface
;
464 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
465 return *ppv
? S_OK
: E_NOINTERFACE
;
468 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
469 return E_NOINTERFACE
;
472 IUnknown_AddRef((IUnknown
*)*ppv
);
476 static ULONG WINAPI
HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory
*iface
)
478 HTMLOptionElementFactory
*This
= impl_from_IHTMLOptionElementFactory(iface
);
479 LONG ref
= InterlockedIncrement(&This
->ref
);
481 TRACE("(%p) ref=%d\n", This
, ref
);
486 static ULONG WINAPI
HTMLOptionElementFactory_Release(IHTMLOptionElementFactory
*iface
)
488 HTMLOptionElementFactory
*This
= impl_from_IHTMLOptionElementFactory(iface
);
489 LONG ref
= InterlockedDecrement(&This
->ref
);
491 TRACE("(%p) ref=%d\n", This
, ref
);
494 release_dispex(&This
->dispex
);
501 static HRESULT WINAPI
HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory
*iface
, UINT
*pctinfo
)
503 HTMLOptionElementFactory
*This
= impl_from_IHTMLOptionElementFactory(iface
);
504 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
507 static HRESULT WINAPI
HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory
*iface
, UINT iTInfo
,
508 LCID lcid
, ITypeInfo
**ppTInfo
)
510 HTMLOptionElementFactory
*This
= impl_from_IHTMLOptionElementFactory(iface
);
511 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
514 static HRESULT WINAPI
HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory
*iface
, REFIID riid
,
515 LPOLESTR
*rgszNames
, UINT cNames
,
516 LCID lcid
, DISPID
*rgDispId
)
518 HTMLOptionElementFactory
*This
= impl_from_IHTMLOptionElementFactory(iface
);
519 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
, lcid
, rgDispId
);
522 static HRESULT WINAPI
HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory
*iface
, DISPID dispIdMember
,
523 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
524 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
526 HTMLOptionElementFactory
*This
= impl_from_IHTMLOptionElementFactory(iface
);
527 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
, wFlags
, pDispParams
,
528 pVarResult
, pExcepInfo
, puArgErr
);
531 static HRESULT WINAPI
HTMLOptionElementFactory_create(IHTMLOptionElementFactory
*iface
,
532 VARIANT text
, VARIANT value
, VARIANT defaultselected
, VARIANT selected
,
533 IHTMLOptionElement
**optelem
)
535 HTMLOptionElementFactory
*This
= impl_from_IHTMLOptionElementFactory(iface
);
536 nsIDOMElement
*nselem
;
540 static const PRUnichar optionW
[] = {'O','P','T','I','O','N',0};
542 TRACE("(%p)->(%s %s %s %s %p)\n", This
, debugstr_variant(&text
), debugstr_variant(&value
),
543 debugstr_variant(&defaultselected
), debugstr_variant(&selected
), optelem
);
545 if(!This
->window
|| !This
->window
->doc
) {
552 hres
= create_nselem(This
->window
->doc
, optionW
, &nselem
);
556 hres
= get_node((nsIDOMNode
*)nselem
, TRUE
, &node
);
557 nsIDOMElement_Release(nselem
);
561 hres
= IHTMLDOMNode_QueryInterface(&node
->IHTMLDOMNode_iface
,
562 &IID_IHTMLOptionElement
, (void**)optelem
);
565 if(V_VT(&text
) == VT_BSTR
)
566 IHTMLOptionElement_put_text(*optelem
, V_BSTR(&text
));
567 else if(V_VT(&text
) != VT_EMPTY
)
568 FIXME("Unsupported text %s\n", debugstr_variant(&text
));
570 if(V_VT(&value
) == VT_BSTR
)
571 IHTMLOptionElement_put_value(*optelem
, V_BSTR(&value
));
572 else if(V_VT(&value
) != VT_EMPTY
)
573 FIXME("Unsupported value %s\n", debugstr_variant(&value
));
575 if(V_VT(&defaultselected
) != VT_EMPTY
)
576 FIXME("Unsupported defaultselected %s\n", debugstr_variant(&defaultselected
));
577 if(V_VT(&selected
) != VT_EMPTY
)
578 FIXME("Unsupported selected %s\n", debugstr_variant(&selected
));
583 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl
= {
584 HTMLOptionElementFactory_QueryInterface
,
585 HTMLOptionElementFactory_AddRef
,
586 HTMLOptionElementFactory_Release
,
587 HTMLOptionElementFactory_GetTypeInfoCount
,
588 HTMLOptionElementFactory_GetTypeInfo
,
589 HTMLOptionElementFactory_GetIDsOfNames
,
590 HTMLOptionElementFactory_Invoke
,
591 HTMLOptionElementFactory_create
594 static const tid_t HTMLOptionElementFactory_iface_tids
[] = {
595 IHTMLOptionElementFactory_tid
,
599 static dispex_static_data_t HTMLOptionElementFactory_dispex
= {
601 IHTMLOptionElementFactory_tid
,
602 HTMLOptionElementFactory_iface_tids
,
603 HTMLElement_init_dispex_info
606 HRESULT
HTMLOptionElementFactory_Create(HTMLInnerWindow
*window
, HTMLOptionElementFactory
**ret_ptr
)
608 HTMLOptionElementFactory
*ret
;
610 ret
= heap_alloc(sizeof(*ret
));
612 return E_OUTOFMEMORY
;
614 ret
->IHTMLOptionElementFactory_iface
.lpVtbl
= &HTMLOptionElementFactoryVtbl
;
616 ret
->window
= window
;
618 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLOptionElementFactory_iface
,
619 &HTMLOptionElementFactory_dispex
);