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 #define HTMLSELECT_THIS(iface) DEFINE_THIS(HTMLSelectElement, HTMLSelectElement, iface)
47 static HRESULT WINAPI
HTMLSelectElement_QueryInterface(IHTMLSelectElement
*iface
,
48 REFIID riid
, void **ppv
)
50 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
52 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This
->element
.node
), riid
, ppv
);
55 static ULONG WINAPI
HTMLSelectElement_AddRef(IHTMLSelectElement
*iface
)
57 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
59 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This
->element
.node
));
62 static ULONG WINAPI
HTMLSelectElement_Release(IHTMLSelectElement
*iface
)
64 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
66 return IHTMLDOMNode_Release(HTMLDOMNODE(&This
->element
.node
));
69 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement
*iface
, UINT
*pctinfo
)
71 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
73 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This
->element
.node
.dispex
), pctinfo
);
76 static HRESULT WINAPI
HTMLSelectElement_GetTypeInfo(IHTMLSelectElement
*iface
, UINT iTInfo
,
77 LCID lcid
, ITypeInfo
**ppTInfo
)
79 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
81 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This
->element
.node
.dispex
), iTInfo
, lcid
, ppTInfo
);
84 static HRESULT WINAPI
HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement
*iface
, REFIID riid
,
85 LPOLESTR
*rgszNames
, UINT cNames
,
86 LCID lcid
, DISPID
*rgDispId
)
88 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
90 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This
->element
.node
.dispex
), riid
, rgszNames
, cNames
, lcid
, rgDispId
);
93 static HRESULT WINAPI
HTMLSelectElement_Invoke(IHTMLSelectElement
*iface
, DISPID dispIdMember
,
94 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
95 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
97 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
99 return IDispatchEx_Invoke(DISPATCHEX(&This
->element
.node
.dispex
), dispIdMember
, riid
, lcid
,
100 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
103 static HRESULT WINAPI
HTMLSelectElement_put_size(IHTMLSelectElement
*iface
, LONG v
)
105 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
106 FIXME("(%p)->(%d)\n", This
, v
);
110 static HRESULT WINAPI
HTMLSelectElement_get_size(IHTMLSelectElement
*iface
, LONG
*p
)
112 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
113 FIXME("(%p)->(%p)\n", This
, p
);
117 static HRESULT WINAPI
HTMLSelectElement_put_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
119 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
120 FIXME("(%p)->(%x)\n", This
, v
);
124 static HRESULT WINAPI
HTMLSelectElement_get_multiple(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
126 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
127 FIXME("(%p)->(%p)\n", This
, p
);
131 static HRESULT WINAPI
HTMLSelectElement_put_name(IHTMLSelectElement
*iface
, BSTR v
)
133 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
134 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
138 static HRESULT WINAPI
HTMLSelectElement_get_name(IHTMLSelectElement
*iface
, BSTR
*p
)
140 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
142 const PRUnichar
*name
= NULL
;
145 TRACE("(%p)->(%p)\n", This
, p
);
147 nsAString_Init(&name_str
, NULL
);
149 nsres
= nsIDOMHTMLSelectElement_GetName(This
->nsselect
, &name_str
);
150 if(NS_SUCCEEDED(nsres
)) {
151 static const WCHAR wszGarbage
[] = {'g','a','r','b','a','g','e',0};
153 nsAString_GetData(&name_str
, &name
);
156 * Native never returns empty string here. If an element has no name,
157 * name of previous element or ramdom data is returned.
159 *p
= SysAllocString(*name
? name
: wszGarbage
);
161 ERR("GetName failed: %08x\n", nsres
);
164 nsAString_Finish(&name_str
);
166 TRACE("name=%s\n", debugstr_w(*p
));
170 static HRESULT WINAPI
HTMLSelectElement_get_options(IHTMLSelectElement
*iface
, IDispatch
**p
)
172 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
174 TRACE("(%p)->(%p)\n", This
, p
);
176 *p
= (IDispatch
*)HTMLSELECT(This
);
177 IDispatch_AddRef(*p
);
181 static HRESULT WINAPI
HTMLSelectElement_put_onchange(IHTMLSelectElement
*iface
, VARIANT v
)
183 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
185 TRACE("(%p)->()\n", This
);
187 return set_node_event(&This
->element
.node
, EVENTID_CHANGE
, &v
);
190 static HRESULT WINAPI
HTMLSelectElement_get_onchange(IHTMLSelectElement
*iface
, VARIANT
*p
)
192 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
193 FIXME("(%p)->(%p)\n", This
, p
);
197 static HRESULT WINAPI
HTMLSelectElement_put_selectedIndex(IHTMLSelectElement
*iface
, LONG v
)
199 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
202 TRACE("(%p)->(%d)\n", This
, v
);
204 nsres
= nsIDOMHTMLSelectElement_SetSelectedIndex(This
->nsselect
, v
);
206 ERR("SetSelectedIndex failed: %08x\n", nsres
);
211 static HRESULT WINAPI
HTMLSelectElement_get_selectedIndex(IHTMLSelectElement
*iface
, LONG
*p
)
213 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
217 TRACE("(%p)->(%p)\n", This
, p
);
219 nsres
= nsIDOMHTMLSelectElement_GetSelectedIndex(This
->nsselect
, &idx
);
221 ERR("GetSelectedIndex failed: %08x\n", nsres
);
227 static HRESULT WINAPI
HTMLSelectElement_get_type(IHTMLSelectElement
*iface
, BSTR
*p
)
229 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
230 const PRUnichar
*type
;
235 TRACE("(%p)->(%p)\n", This
, p
);
237 nsAString_Init(&type_str
, NULL
);
238 nsres
= nsIDOMHTMLSelectElement_GetType(This
->nsselect
, &type_str
);
239 if(NS_SUCCEEDED(nsres
)) {
240 nsAString_GetData(&type_str
, &type
);
241 *p
= *type
? SysAllocString(type
) : NULL
;
243 ERR("GetType failed: %08x\n", nsres
);
247 nsAString_Finish(&type_str
);
252 static HRESULT WINAPI
HTMLSelectElement_put_value(IHTMLSelectElement
*iface
, BSTR v
)
254 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
258 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
260 nsAString_InitDepend(&value_str
, v
);
261 nsres
= nsIDOMHTMLSelectElement_SetValue(This
->nsselect
, &value_str
);
262 nsAString_Finish(&value_str
);
264 ERR("SetValue failed: %08x\n", nsres
);
269 static HRESULT WINAPI
HTMLSelectElement_get_value(IHTMLSelectElement
*iface
, BSTR
*p
)
271 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
273 const PRUnichar
*value
= NULL
;
276 TRACE("(%p)->(%p)\n", This
, p
);
278 nsAString_Init(&value_str
, NULL
);
280 nsres
= nsIDOMHTMLSelectElement_GetValue(This
->nsselect
, &value_str
);
281 if(NS_SUCCEEDED(nsres
)) {
282 nsAString_GetData(&value_str
, &value
);
283 *p
= *value
? SysAllocString(value
) : NULL
;
285 ERR("GetValue failed: %08x\n", nsres
);
288 nsAString_Finish(&value_str
);
290 TRACE("value=%s\n", debugstr_w(*p
));
294 static HRESULT WINAPI
HTMLSelectElement_put_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL v
)
296 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
299 TRACE("(%p)->(%x)\n", This
, v
);
301 nsres
= nsIDOMHTMLSelectElement_SetDisabled(This
->nsselect
, v
!= VARIANT_FALSE
);
302 if(NS_FAILED(nsres
)) {
303 ERR("SetDisabled failed: %08x\n", nsres
);
310 static HRESULT WINAPI
HTMLSelectElement_get_disabled(IHTMLSelectElement
*iface
, VARIANT_BOOL
*p
)
312 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
313 PRBool disabled
= FALSE
;
316 TRACE("(%p)->(%p)\n", This
, p
);
318 nsres
= nsIDOMHTMLSelectElement_GetDisabled(This
->nsselect
, &disabled
);
319 if(NS_FAILED(nsres
)) {
320 ERR("GetDisabled failed: %08x\n", nsres
);
324 *p
= disabled
? VARIANT_TRUE
: VARIANT_FALSE
;
328 static HRESULT WINAPI
HTMLSelectElement_get_form(IHTMLSelectElement
*iface
, IHTMLFormElement
**p
)
330 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
331 FIXME("(%p)->(%p)\n", This
, p
);
335 static HRESULT WINAPI
HTMLSelectElement_add(IHTMLSelectElement
*iface
, IHTMLElement
*element
,
338 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
339 IHTMLDOMNode
*node
, *tmp
;
342 FIXME("(%p)->(%p %s): semi-stub\n", This
, element
, debugstr_variant(&before
));
344 if(V_VT(&before
) != VT_EMPTY
) {
345 FIXME("unhandled before %s\n", debugstr_variant(&before
));
349 hres
= IHTMLElement_QueryInterface(element
, &IID_IHTMLDOMNode
, (void**)&node
);
353 hres
= IHTMLDOMNode_appendChild(HTMLDOMNODE(&This
->element
.node
), node
, &tmp
);
354 IHTMLDOMNode_Release(node
);
355 if(SUCCEEDED(hres
) && tmp
)
356 IHTMLDOMNode_Release(tmp
);
361 static HRESULT WINAPI
HTMLSelectElement_remove(IHTMLSelectElement
*iface
, LONG index
)
363 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
364 FIXME("(%p)->(%d)\n", This
, index
);
368 static HRESULT WINAPI
HTMLSelectElement_put_length(IHTMLSelectElement
*iface
, LONG v
)
370 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
373 TRACE("(%p)->(%d)\n", This
, v
);
375 nsres
= nsIDOMHTMLSelectElement_SetLength(This
->nsselect
, v
);
377 ERR("SetLength failed: %08x\n", nsres
);
382 static HRESULT WINAPI
HTMLSelectElement_get_length(IHTMLSelectElement
*iface
, LONG
*p
)
384 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
388 TRACE("(%p)->(%p)\n", This
, p
);
390 nsres
= nsIDOMHTMLSelectElement_GetLength(This
->nsselect
, &length
);
392 ERR("GetLength failed: %08x\n", nsres
);
396 TRACE("ret %d\n", *p
);
400 static HRESULT WINAPI
HTMLSelectElement_get__newEnum(IHTMLSelectElement
*iface
, IUnknown
**p
)
402 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
403 FIXME("(%p)->(%p)\n", This
, p
);
407 static HRESULT WINAPI
HTMLSelectElement_item(IHTMLSelectElement
*iface
, VARIANT name
,
408 VARIANT index
, IDispatch
**pdisp
)
410 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
411 FIXME("(%p)->(v v %p)\n", This
, pdisp
);
415 static HRESULT WINAPI
HTMLSelectElement_tags(IHTMLSelectElement
*iface
, VARIANT tagName
,
418 HTMLSelectElement
*This
= HTMLSELECT_THIS(iface
);
419 FIXME("(%p)->(v %p)\n", This
, pdisp
);
423 #undef HTMLSELECT_THIS
425 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl
= {
426 HTMLSelectElement_QueryInterface
,
427 HTMLSelectElement_AddRef
,
428 HTMLSelectElement_Release
,
429 HTMLSelectElement_GetTypeInfoCount
,
430 HTMLSelectElement_GetTypeInfo
,
431 HTMLSelectElement_GetIDsOfNames
,
432 HTMLSelectElement_Invoke
,
433 HTMLSelectElement_put_size
,
434 HTMLSelectElement_get_size
,
435 HTMLSelectElement_put_multiple
,
436 HTMLSelectElement_get_multiple
,
437 HTMLSelectElement_put_name
,
438 HTMLSelectElement_get_name
,
439 HTMLSelectElement_get_options
,
440 HTMLSelectElement_put_onchange
,
441 HTMLSelectElement_get_onchange
,
442 HTMLSelectElement_put_selectedIndex
,
443 HTMLSelectElement_get_selectedIndex
,
444 HTMLSelectElement_get_type
,
445 HTMLSelectElement_put_value
,
446 HTMLSelectElement_get_value
,
447 HTMLSelectElement_put_disabled
,
448 HTMLSelectElement_get_disabled
,
449 HTMLSelectElement_get_form
,
450 HTMLSelectElement_add
,
451 HTMLSelectElement_remove
,
452 HTMLSelectElement_put_length
,
453 HTMLSelectElement_get_length
,
454 HTMLSelectElement_get__newEnum
,
455 HTMLSelectElement_item
,
456 HTMLSelectElement_tags
459 #define HTMLSELECT_NODE_THIS(iface) DEFINE_THIS2(HTMLSelectElement, element.node, iface)
461 static HRESULT
HTMLSelectElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
463 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
467 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
468 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
469 *ppv
= HTMLSELECT(This
);
470 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
471 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
472 *ppv
= HTMLSELECT(This
);
473 }else if(IsEqualGUID(&IID_IHTMLSelectElement
, riid
)) {
474 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This
, ppv
);
475 *ppv
= HTMLSELECT(This
);
479 IUnknown_AddRef((IUnknown
*)*ppv
);
483 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
486 static void HTMLSelectElement_destructor(HTMLDOMNode
*iface
)
488 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
490 nsIDOMHTMLSelectElement_Release(This
->nsselect
);
492 HTMLElement_destructor(&This
->element
.node
);
495 static HRESULT
HTMLSelectElementImpl_put_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL v
)
497 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
498 return IHTMLSelectElement_put_disabled(HTMLSELECT(This
), v
);
501 static HRESULT
HTMLSelectElementImpl_get_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL
*p
)
503 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
504 return IHTMLSelectElement_get_disabled(HTMLSELECT(This
), p
);
507 #define DISPID_OPTIONCOL_0 MSHTML_DISPID_CUSTOM_MIN
509 static HRESULT
HTMLSelectElement_get_dispid(HTMLDOMNode
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
514 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++) {
515 idx
= idx
*10 + (*ptr
-'0');
516 if(idx
> MSHTML_CUSTOM_DISPID_CNT
) {
517 WARN("too big idx\n");
518 return DISP_E_UNKNOWNNAME
;
522 return DISP_E_UNKNOWNNAME
;
524 *dispid
= DISPID_OPTIONCOL_0
+ idx
;
528 static HRESULT
HTMLSelectElement_invoke(HTMLDOMNode
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
529 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
531 HTMLSelectElement
*This
= HTMLSELECT_NODE_THIS(iface
);
533 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
536 case DISPATCH_PROPERTYGET
: {
537 nsIDOMHTMLOptionsCollection
*nscol
;
541 nsres
= nsIDOMHTMLSelectElement_GetOptions(This
->nsselect
, &nscol
);
542 if(NS_FAILED(nsres
)) {
543 ERR("GetOptions failed: %08x\n", nsres
);
547 nsres
= nsIDOMHTMLOptionsCollection_Item(nscol
, id
-DISPID_OPTIONCOL_0
, &nsnode
);
548 nsIDOMHTMLOptionsCollection_Release(nscol
);
549 if(NS_FAILED(nsres
)) {
550 ERR("Item failed: %08x\n", nsres
);
557 node
= get_node(This
->element
.node
.doc
, nsnode
, TRUE
);
558 nsIDOMNode_Release(nsnode
);
560 ERR("Could not find node\n");
564 IHTMLDOMNode_AddRef(HTMLDOMNODE(node
));
565 V_VT(res
) = VT_DISPATCH
;
566 V_DISPATCH(res
) = (IDispatch
*)HTMLDOMNODE(node
);
574 FIXME("unimplemented flags %x\n", flags
);
581 #undef HTMLSELECT_NODE_THIS
583 static const NodeImplVtbl HTMLSelectElementImplVtbl
= {
584 HTMLSelectElement_QI
,
585 HTMLSelectElement_destructor
,
588 HTMLSelectElementImpl_put_disabled
,
589 HTMLSelectElementImpl_get_disabled
,
592 HTMLSelectElement_get_dispid
,
593 HTMLSelectElement_invoke
596 static const tid_t HTMLSelectElement_tids
[] = {
598 IHTMLSelectElement_tid
,
602 static dispex_static_data_t HTMLSelectElement_dispex
= {
604 DispHTMLSelectElement_tid
,
606 HTMLSelectElement_tids
609 HTMLElement
*HTMLSelectElement_Create(HTMLDocumentNode
*doc
, nsIDOMHTMLElement
*nselem
)
611 HTMLSelectElement
*ret
= heap_alloc_zero(sizeof(HTMLSelectElement
));
614 ret
->lpHTMLSelectElementVtbl
= &HTMLSelectElementVtbl
;
615 ret
->element
.node
.vtbl
= &HTMLSelectElementImplVtbl
;
617 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLSelectElement_dispex
);
619 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLSelectElement
,
620 (void**)&ret
->nsselect
);
622 ERR("Could not get nsIDOMHTMLSelectElement interfce: %08x\n", nsres
);
624 return &ret
->element
;