2 * Copyright 2006 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
);
38 const IHTMLSelectElementVtbl
*lpHTMLSelectElementVtbl
;
40 nsIDOMHTMLSelectElement
*nsselect
;
43 #define HTMLSELECT(x) ((IHTMLSelectElement*) &(x)->lpHTMLSelectElementVtbl)
45 static HRESULT
htmlselect_item(HTMLSelectElement
*This
, int i
, IDispatch
**ret
)
47 nsIDOMHTMLOptionsCollection
*nscol
;
51 nsres
= nsIDOMHTMLSelectElement_GetOptions(This
->nsselect
, &nscol
);
52 if(NS_FAILED(nsres
)) {
53 ERR("GetOptions failed: %08x\n", nsres
);
57 nsres
= nsIDOMHTMLOptionsCollection_Item(nscol
, i
, &nsnode
);
58 nsIDOMHTMLOptionsCollection_Release(nscol
);
59 if(NS_FAILED(nsres
)) {
60 ERR("Item failed: %08x\n", nsres
);
67 node
= get_node(This
->element
.node
.doc
, nsnode
, TRUE
);
68 nsIDOMNode_Release(nsnode
);
70 ERR("Could not find node\n");
74 IHTMLDOMNode_AddRef(HTMLDOMNODE(node
));
75 *ret
= (IDispatch
*)HTMLDOMNODE(node
);
82 #define HTMLSELECT_THIS(iface) DEFINE_THIS(HTMLSelectElement, HTMLSelectElement, iface)
84 static HRESULT WINAPI
HTMLSelectElement_QueryInterface(IHTMLSelectElement
*iface
,
85 REFIID riid
, void **ppv
)
87 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
89 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This
->element
.node
), riid
, ppv
);
92 static ULONG WINAPI
HTMLSelectElement_AddRef(IHTMLSelectElement
*iface
)
94 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
96 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This
->element
.node
));
99 static ULONG WINAPI
HTMLSelectElement_Release(IHTMLSelectElement
*iface
)
101 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
103 return IHTMLDOMNode_Release(HTMLDOMNODE(&This
->element
.node
));
106 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement
*iface
, UINT
*pctinfo
)
108 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
110 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This
->element
.node
.dispex
), pctinfo
);
113 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfo(IHTMLSelectElement
*iface
, UINT iTInfo
,
114 LCID lcid
, ITypeInfo
**ppTInfo
)
116 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
118 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This
->element
.node
.dispex
), iTInfo
, lcid
, ppTInfo
);
121 static HRESULT WINAPI
HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement
*iface
, REFIID riid
,
122 LPOLESTR
*rgszNames
, UINT cNames
,
123 LCID lcid
, DISPID
*rgDispId
)
125 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
127 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This
->element
.node
.dispex
), riid
, rgszNames
, cNames
, lcid
, rgDispId
);
130 static HRESULT WINAPI
HTMLSelectElement_Invoke(IHTMLSelectElement
*iface
, DISPID dispIdMember
,
131 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
132 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
134 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
136 return IDispatchEx_Invoke(DISPATCHEX(&This
->element
.node
.dispex
), dispIdMember
, riid
, lcid
,
137 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
140 static HRESULT WINAPI
HTMLSelectElement_put_size(IHTMLSelectElement
*iface
, LONG v
)
142 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
143 FIXME("(%p)->(%d)\n", This
, v
);
147 static HRESULT WINAPI
HTMLSelectElement_get_size(IHTMLSelectElement
*iface
, LONG
*p
)
149 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
150 FIXME("(%p)->(%p)\n", This
, p
);
154 static HRESULT WINAPI
HTMLSelectElement_put_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
156 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
157 FIXME("(%p)->(%x)\n", This
, v
);
161 static HRESULT WINAPI
HTMLSelectElement_get_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
163 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
164 FIXME("(%p)->(%p)\n", This
, p
);
168 static HRESULT WINAPI
HTMLSelectElement_put_name(IHTMLSelectElement
*iface
, BSTR v
)
170 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
171 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
175 static HRESULT WINAPI
HTMLSelectElement_get_name(IHTMLSelectElement
*iface
, BSTR
*p
)
177 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
179 const PRUnichar
*name
= NULL
;
182 TRACE("(%p)->(%p)\n", This
, p
);
184 nsAString_Init(&name_str
, NULL
);
186 nsres
= nsIDOMHTMLSelectElement_GetName(This
->nsselect
, &name_str
);
187 if(NS_SUCCEEDED(nsres
)) {
188 static const WCHAR wszGarbage
[] = {'g','a','r','b','a','g','e',0};
190 nsAString_GetData(&name_str
, &name
);
193 * Native never returns empty string here. If an element has no name,
194 * name of previous element or ramdom data is returned.
196 *p
= SysAllocString(*name
? name
: wszGarbage
);
198 ERR("GetName failed: %08x\n", nsres
);
201 nsAString_Finish(&name_str
);
203 TRACE("name=%s\n", debugstr_w(*p
));
207 static HRESULT WINAPI
HTMLSelectElement_get_options(IHTMLSelectElement
*iface
, IDispatch
**p
)
209 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
211 TRACE("(%p)->(%p)\n", This
, p
);
213 *p
= (IDispatch
*)HTMLSELECT(This
);
214 IDispatch_AddRef(*p
);
218 static HRESULT WINAPI
HTMLSelectElement_put_onchange(IHTMLSelectElement
*iface
, VARIANT v
)
220 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
222 TRACE("(%p)->()\n", This
);
224 return set_node_event(&This
->element
.node
, EVENTID_CHANGE
, &v
);
227 static HRESULT WINAPI
HTMLSelectElement_get_onchange(IHTMLSelectElement
*iface
, VARIANT
*p
)
229 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
230 FIXME("(%p)->(%p)\n", This
, p
);
234 static HRESULT WINAPI
HTMLSelectElement_put_selectedIndex(IHTMLSelectElement
*iface
, LONG v
)
236 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
239 TRACE("(%p)->(%d)\n", This
, v
);
241 nsres
= nsIDOMHTMLSelectElement_SetSelectedIndex(This
->nsselect
, v
);
243 ERR("SetSelectedIndex failed: %08x\n", nsres
);
248 static HRESULT WINAPI
HTMLSelectElement_get_selectedIndex(IHTMLSelectElement
*iface
, LONG
*p
)
250 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
254 TRACE("(%p)->(%p)\n", This
, p
);
256 nsres
= nsIDOMHTMLSelectElement_GetSelectedIndex(This
->nsselect
, &idx
);
258 ERR("GetSelectedIndex failed: %08x\n", nsres
);
264 static HRESULT WINAPI
HTMLSelectElement_get_type(IHTMLSelectElement
*iface
, BSTR
*p
)
266 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
267 const PRUnichar
*type
;
272 TRACE("(%p)->(%p)\n", This
, p
);
274 nsAString_Init(&type_str
, NULL
);
275 nsres
= nsIDOMHTMLSelectElement_GetType(This
->nsselect
, &type_str
);
276 if(NS_SUCCEEDED(nsres
)) {
277 nsAString_GetData(&type_str
, &type
);
278 *p
= *type
? SysAllocString(type
) : NULL
;
280 ERR("GetType failed: %08x\n", nsres
);
284 nsAString_Finish(&type_str
);
289 static HRESULT WINAPI
HTMLSelectElement_put_value(IHTMLSelectElement
*iface
, BSTR v
)
291 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
295 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
297 nsAString_InitDepend(&value_str
, v
);
298 nsres
= nsIDOMHTMLSelectElement_SetValue(This
->nsselect
, &value_str
);
299 nsAString_Finish(&value_str
);
301 ERR("SetValue failed: %08x\n", nsres
);
306 static HRESULT WINAPI
HTMLSelectElement_get_value(IHTMLSelectElement
*iface
, BSTR
*p
)
308 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
310 const PRUnichar
*value
= NULL
;
313 TRACE("(%p)->(%p)\n", This
, p
);
315 nsAString_Init(&value_str
, NULL
);
317 nsres
= nsIDOMHTMLSelectElement_GetValue(This
->nsselect
, &value_str
);
318 if(NS_SUCCEEDED(nsres
)) {
319 nsAString_GetData(&value_str
, &value
);
320 *p
= *value
? SysAllocString(value
) : NULL
;
322 ERR("GetValue failed: %08x\n", nsres
);
325 nsAString_Finish(&value_str
);
327 TRACE("value=%s\n", debugstr_w(*p
));
331 static HRESULT WINAPI
HTMLSelectElement_put_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
333 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
336 TRACE("(%p)->(%x)\n", This
, v
);
338 nsres
= nsIDOMHTMLSelectElement_SetDisabled(This
->nsselect
, v
!= VARIANT_FALSE
);
339 if(NS_FAILED(nsres
)) {
340 ERR("SetDisabled failed: %08x\n", nsres
);
347 static HRESULT WINAPI
HTMLSelectElement_get_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
349 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
350 PRBool disabled
= FALSE
;
353 TRACE("(%p)->(%p)\n", This
, p
);
355 nsres
= nsIDOMHTMLSelectElement_GetDisabled(This
->nsselect
, &disabled
);
356 if(NS_FAILED(nsres
)) {
357 ERR("GetDisabled failed: %08x\n", nsres
);
361 *p
= disabled
? VARIANT_TRUE
: VARIANT_FALSE
;
365 static HRESULT WINAPI
HTMLSelectElement_get_form(IHTMLSelectElement
*iface
, IHTMLFormElement
**p
)
367 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
368 FIXME("(%p)->(%p)\n", This
, p
);
372 static HRESULT WINAPI
HTMLSelectElement_add(IHTMLSelectElement
*iface
, IHTMLElement
*element
,
375 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
376 IHTMLDOMNode
*node
, *tmp
;
379 FIXME("(%p)->(%p %s): semi-stub\n", This
, element
, debugstr_variant(&before
));
381 if(V_VT(&before
) != VT_EMPTY
) {
382 FIXME("unhandled before %s\n", debugstr_variant(&before
));
386 hres
= IHTMLElement_QueryInterface(element
, &IID_IHTMLDOMNode
, (void**)&node
);
390 hres
= IHTMLDOMNode_appendChild(HTMLDOMNODE(&This
->element
.node
), node
, &tmp
);
391 IHTMLDOMNode_Release(node
);
392 if(SUCCEEDED(hres
) && tmp
)
393 IHTMLDOMNode_Release(tmp
);
398 static HRESULT WINAPI
HTMLSelectElement_remove(IHTMLSelectElement
*iface
, LONG index
)
400 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
401 FIXME("(%p)->(%d)\n", This
, index
);
405 static HRESULT WINAPI
HTMLSelectElement_put_length(IHTMLSelectElement
*iface
, LONG v
)
407 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
410 TRACE("(%p)->(%d)\n", This
, v
);
412 nsres
= nsIDOMHTMLSelectElement_SetLength(This
->nsselect
, v
);
414 ERR("SetLength failed: %08x\n", nsres
);
419 static HRESULT WINAPI
HTMLSelectElement_get_length(IHTMLSelectElement
*iface
, LONG
*p
)
421 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
425 TRACE("(%p)->(%p)\n", This
, p
);
427 nsres
= nsIDOMHTMLSelectElement_GetLength(This
->nsselect
, &length
);
429 ERR("GetLength failed: %08x\n", nsres
);
433 TRACE("ret %d\n", *p
);
437 static HRESULT WINAPI
HTMLSelectElement_get__newEnum(IHTMLSelectElement
*iface
, IUnknown
**p
)
439 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
440 FIXME("(%p)->(%p)\n", This
, p
);
444 static HRESULT WINAPI
HTMLSelectElement_item(IHTMLSelectElement
*iface
, VARIANT name
,
445 VARIANT index
, IDispatch
**pdisp
)
447 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
449 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
455 if(V_VT(&name
) == VT_I4
) {
458 return htmlselect_item(This
, V_I4(&name
), pdisp
);
461 FIXME("Unsupported args\n");
465 static HRESULT WINAPI
HTMLSelectElement_tags(IHTMLSelectElement
*iface
, VARIANT tagName
,
468 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
469 FIXME("(%p)->(v %p)\n", This
, pdisp
);
473 #undef HTMLSELECT_THIS
475 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl
= {
476 HTMLSelectElement_QueryInterface
,
477 HTMLSelectElement_AddRef
,
478 HTMLSelectElement_Release
,
479 HTMLSelectElement_GetTypeInfoCount
,
480 HTMLSelectElement_GetTypeInfo
,
481 HTMLSelectElement_GetIDsOfNames
,
482 HTMLSelectElement_Invoke
,
483 HTMLSelectElement_put_size
,
484 HTMLSelectElement_get_size
,
485 HTMLSelectElement_put_multiple
,
486 HTMLSelectElement_get_multiple
,
487 HTMLSelectElement_put_name
,
488 HTMLSelectElement_get_name
,
489 HTMLSelectElement_get_options
,
490 HTMLSelectElement_put_onchange
,
491 HTMLSelectElement_get_onchange
,
492 HTMLSelectElement_put_selectedIndex
,
493 HTMLSelectElement_get_selectedIndex
,
494 HTMLSelectElement_get_type
,
495 HTMLSelectElement_put_value
,
496 HTMLSelectElement_get_value
,
497 HTMLSelectElement_put_disabled
,
498 HTMLSelectElement_get_disabled
,
499 HTMLSelectElement_get_form
,
500 HTMLSelectElement_add
,
501 HTMLSelectElement_remove
,
502 HTMLSelectElement_put_length
,
503 HTMLSelectElement_get_length
,
504 HTMLSelectElement_get__newEnum
,
505 HTMLSelectElement_item
,
506 HTMLSelectElement_tags
509 #define HTMLSELECT_NODE_THIS(iface) DEFINE_THIS2(HTMLSelectElement, element.node, iface)
511 static HRESULT
HTMLSelectElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
513 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
517 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
518 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
519 *ppv
= HTMLSELECT(This
);
520 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
521 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
522 *ppv
= HTMLSELECT(This
);
523 }else if(IsEqualGUID(&IID_IHTMLSelectElement
, riid
)) {
524 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This
, ppv
);
525 *ppv
= HTMLSELECT(This
);
529 IUnknown_AddRef((IUnknown
*)*ppv
);
533 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
536 static void HTMLSelectElement_destructor(HTMLDOMNode
*iface
)
538 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
540 nsIDOMHTMLSelectElement_Release(This
->nsselect
);
542 HTMLElement_destructor(&This
->element
.node
);
545 static HRESULT
HTMLSelectElementImpl_put_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL v
)
547 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
548 return IHTMLSelectElement_put_disabled(HTMLSELECT(This
), v
);
551 static HRESULT
HTMLSelectElementImpl_get_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL
*p
)
553 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
554 return IHTMLSelectElement_get_disabled(HTMLSELECT(This
), p
);
557 #define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN
559 static HRESULT
HTMLSelectElement_get_dispid(HTMLDOMNode
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
564 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++) {
565 idx
= idx
*10 + (*ptr
-'0');
566 if(idx
> MSHTML_CUSTOM_DISPID_CNT
) {
567 WARN("too big idx\n");
568 return DISP_E_UNKNOWNNAME
;
572 return DISP_E_UNKNOWNNAME
;
574 *dispid
= DISPID_OPTIONCOL_0
+ idx
;
578 static HRESULT
HTMLSelectElement_invoke(HTMLDOMNode
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
579 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
581 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
583 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
586 case DISPATCH_PROPERTYGET
: {
590 hres
= htmlselect_item(This
, id
-DISPID_OPTIONCOL_0
, &ret
);
595 V_VT(res
) = VT_DISPATCH
;
596 V_DISPATCH(res
) = ret
;
604 FIXME("unimplemented flags %x\n", flags
);
611 #undef HTMLSELECT_NODE_THIS
613 static const NodeImplVtbl HTMLSelectElementImplVtbl
= {
614 HTMLSelectElement_QI
,
615 HTMLSelectElement_destructor
,
618 HTMLSelectElementImpl_put_disabled
,
619 HTMLSelectElementImpl_get_disabled
,
622 HTMLSelectElement_get_dispid
,
623 HTMLSelectElement_invoke
626 static const tid_t HTMLSelectElement_tids
[] = {
628 IHTMLSelectElement_tid
,
632 static dispex_static_data_t HTMLSelectElement_dispex
= {
634 DispHTMLSelectElement_tid
,
636 HTMLSelectElement_tids
639 HTMLElement
*HTMLSelectElement_Create(HTMLDocumentNode
*doc
, nsIDOMHTMLElement
*nselem
)
641 HTMLSelectElement
*ret
= heap_alloc_zero(sizeof(HTMLSelectElement
));
644 ret
->lpHTMLSelectElementVtbl
= &HTMLSelectElementVtbl
;
645 ret
->element
.node
.vtbl
= &HTMLSelectElementImplVtbl
;
647 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLSelectElement_dispex
);
649 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLSelectElement
,
650 (void**)&ret
->nsselect
);
652 ERR("Could not get nsIDOMHTMLSelectElement interfce: %08x\n", nsres
);
654 return &ret
->element
;