wined3d: Make sure all fields of the fragment pipe caps are always initialized.
[wine.git] / dlls / mshtml / htmlselect.c
blobee5d214bd1e316f92d122e877bfea8ad32617df2
1 /*
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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 typedef struct {
36 HTMLElement element;
38 const IHTMLSelectElementVtbl *lpHTMLSelectElementVtbl;
40 nsIDOMHTMLSelectElement *nsselect;
41 } HTMLSelectElement;
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);
107 return E_NOTIMPL;
110 static HRESULT WINAPI HTMLSelectElement_get_size(IHTMLSelectElement *iface, LONG *p)
112 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
113 FIXME("(%p)->(%p)\n", This, p);
114 return E_NOTIMPL;
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);
121 return E_NOTIMPL;
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);
128 return E_NOTIMPL;
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));
135 return E_NOTIMPL;
138 static HRESULT WINAPI HTMLSelectElement_get_name(IHTMLSelectElement *iface, BSTR *p)
140 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
141 nsAString name_str;
142 const PRUnichar *name = NULL;
143 nsresult nsres;
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);
160 }else {
161 ERR("GetName failed: %08x\n", nsres);
164 nsAString_Finish(&name_str);
166 TRACE("name=%s\n", debugstr_w(*p));
167 return S_OK;
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);
178 return S_OK;
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);
194 return E_NOTIMPL;
197 static HRESULT WINAPI HTMLSelectElement_put_selectedIndex(IHTMLSelectElement *iface, LONG v)
199 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
200 nsresult nsres;
202 TRACE("(%p)->(%d)\n", This, v);
204 nsres = nsIDOMHTMLSelectElement_SetSelectedIndex(This->nsselect, v);
205 if(NS_FAILED(nsres))
206 ERR("SetSelectedIndex failed: %08x\n", nsres);
208 return S_OK;
211 static HRESULT WINAPI HTMLSelectElement_get_selectedIndex(IHTMLSelectElement *iface, LONG *p)
213 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
214 PRInt32 idx = 0;
215 nsresult nsres;
217 TRACE("(%p)->(%p)\n", This, p);
219 nsres = nsIDOMHTMLSelectElement_GetSelectedIndex(This->nsselect, &idx);
220 if(NS_FAILED(nsres))
221 ERR("GetSelectedIndex failed: %08x\n", nsres);
223 *p = idx;
224 return S_OK;
227 static HRESULT WINAPI HTMLSelectElement_get_type(IHTMLSelectElement *iface, BSTR *p)
229 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
230 const PRUnichar *type;
231 nsAString type_str;
232 nsresult nsres;
233 HRESULT hres = S_OK;
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;
242 }else {
243 ERR("GetType failed: %08x\n", nsres);
244 hres = E_FAIL;
247 nsAString_Finish(&type_str);
249 return hres;
252 static HRESULT WINAPI HTMLSelectElement_put_value(IHTMLSelectElement *iface, BSTR v)
254 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
255 nsAString value_str;
256 nsresult nsres;
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);
263 if(NS_FAILED(nsres))
264 ERR("SetValue failed: %08x\n", nsres);
266 return S_OK;
269 static HRESULT WINAPI HTMLSelectElement_get_value(IHTMLSelectElement *iface, BSTR *p)
271 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
272 nsAString value_str;
273 const PRUnichar *value = NULL;
274 nsresult nsres;
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;
284 }else {
285 ERR("GetValue failed: %08x\n", nsres);
288 nsAString_Finish(&value_str);
290 TRACE("value=%s\n", debugstr_w(*p));
291 return S_OK;
294 static HRESULT WINAPI HTMLSelectElement_put_disabled(IHTMLSelectElement *iface, VARIANT_BOOL v)
296 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
297 nsresult nsres;
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);
304 return E_FAIL;
307 return S_OK;
310 static HRESULT WINAPI HTMLSelectElement_get_disabled(IHTMLSelectElement *iface, VARIANT_BOOL *p)
312 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
313 PRBool disabled = FALSE;
314 nsresult nsres;
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);
321 return E_FAIL;
324 *p = disabled ? VARIANT_TRUE : VARIANT_FALSE;
325 return S_OK;
328 static HRESULT WINAPI HTMLSelectElement_get_form(IHTMLSelectElement *iface, IHTMLFormElement **p)
330 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
331 FIXME("(%p)->(%p)\n", This, p);
332 return E_NOTIMPL;
335 static HRESULT WINAPI HTMLSelectElement_add(IHTMLSelectElement *iface, IHTMLElement *element,
336 VARIANT before)
338 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
339 IHTMLDOMNode *node, *tmp;
340 HRESULT hres;
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));
346 return E_NOTIMPL;
349 hres = IHTMLElement_QueryInterface(element, &IID_IHTMLDOMNode, (void**)&node);
350 if(FAILED(hres))
351 return hres;
353 hres = IHTMLDOMNode_appendChild(HTMLDOMNODE(&This->element.node), node, &tmp);
354 IHTMLDOMNode_Release(node);
355 if(SUCCEEDED(hres) && tmp)
356 IHTMLDOMNode_Release(tmp);
358 return hres;
361 static HRESULT WINAPI HTMLSelectElement_remove(IHTMLSelectElement *iface, LONG index)
363 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
364 FIXME("(%p)->(%d)\n", This, index);
365 return E_NOTIMPL;
368 static HRESULT WINAPI HTMLSelectElement_put_length(IHTMLSelectElement *iface, LONG v)
370 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
371 nsresult nsres;
373 TRACE("(%p)->(%d)\n", This, v);
375 nsres = nsIDOMHTMLSelectElement_SetLength(This->nsselect, v);
376 if(NS_FAILED(nsres))
377 ERR("SetLength failed: %08x\n", nsres);
379 return S_OK;
382 static HRESULT WINAPI HTMLSelectElement_get_length(IHTMLSelectElement *iface, LONG *p)
384 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
385 PRUint32 length = 0;
386 nsresult nsres;
388 TRACE("(%p)->(%p)\n", This, p);
390 nsres = nsIDOMHTMLSelectElement_GetLength(This->nsselect, &length);
391 if(NS_FAILED(nsres))
392 ERR("GetLength failed: %08x\n", nsres);
394 *p = length;
396 TRACE("ret %d\n", *p);
397 return S_OK;
400 static HRESULT WINAPI HTMLSelectElement_get__newEnum(IHTMLSelectElement *iface, IUnknown **p)
402 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
403 FIXME("(%p)->(%p)\n", This, p);
404 return E_NOTIMPL;
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);
412 return E_NOTIMPL;
415 static HRESULT WINAPI HTMLSelectElement_tags(IHTMLSelectElement *iface, VARIANT tagName,
416 IDispatch **pdisp)
418 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
419 FIXME("(%p)->(v %p)\n", This, pdisp);
420 return E_NOTIMPL;
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);
465 *ppv = NULL;
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);
478 if(*ppv) {
479 IUnknown_AddRef((IUnknown*)*ppv);
480 return S_OK;
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)
511 const WCHAR *ptr;
512 DWORD idx = 0;
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;
521 if(*ptr)
522 return DISP_E_UNKNOWNNAME;
524 *dispid = DISPID_OPTIONCOL_0 + idx;
525 return S_OK;
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);
535 switch(flags) {
536 case DISPATCH_PROPERTYGET: {
537 nsIDOMHTMLOptionsCollection *nscol;
538 nsIDOMNode *nsnode;
539 nsresult nsres;
541 nsres = nsIDOMHTMLSelectElement_GetOptions(This->nsselect, &nscol);
542 if(NS_FAILED(nsres)) {
543 ERR("GetOptions failed: %08x\n", nsres);
544 return E_FAIL;
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);
551 return E_FAIL;
554 if(nsnode) {
555 HTMLDOMNode *node;
557 node = get_node(This->element.node.doc, nsnode, TRUE);
558 nsIDOMNode_Release(nsnode);
559 if(!node) {
560 ERR("Could not find node\n");
561 return E_FAIL;
564 IHTMLDOMNode_AddRef(HTMLDOMNODE(node));
565 V_VT(res) = VT_DISPATCH;
566 V_DISPATCH(res) = (IDispatch*)HTMLDOMNODE(node);
567 }else {
568 V_VT(res) = VT_NULL;
570 break;
573 default:
574 FIXME("unimplemented flags %x\n", flags);
575 return E_NOTIMPL;
578 return S_OK;
581 #undef HTMLSELECT_NODE_THIS
583 static const NodeImplVtbl HTMLSelectElementImplVtbl = {
584 HTMLSelectElement_QI,
585 HTMLSelectElement_destructor,
586 NULL,
587 NULL,
588 HTMLSelectElementImpl_put_disabled,
589 HTMLSelectElementImpl_get_disabled,
590 NULL,
591 NULL,
592 HTMLSelectElement_get_dispid,
593 HTMLSelectElement_invoke
596 static const tid_t HTMLSelectElement_tids[] = {
597 HTMLELEMENT_TIDS,
598 IHTMLSelectElement_tid,
602 static dispex_static_data_t HTMLSelectElement_dispex = {
603 NULL,
604 DispHTMLSelectElement_tid,
605 NULL,
606 HTMLSelectElement_tids
609 HTMLElement *HTMLSelectElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
611 HTMLSelectElement *ret = heap_alloc_zero(sizeof(HTMLSelectElement));
612 nsresult nsres;
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);
621 if(NS_FAILED(nsres))
622 ERR("Could not get nsIDOMHTMLSelectElement interfce: %08x\n", nsres);
624 return &ret->element;