mshtml: Added IHTMLSelectElement::put_onchange implementation.
[wine/dcerpc.git] / dlls / mshtml / htmlselect.c
blob9bd269336fd17373b180d6bfdc68cc873a5a35f3
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"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 typedef struct {
35 HTMLElement element;
37 const IHTMLSelectElementVtbl *lpHTMLSelectElementVtbl;
39 nsIDOMHTMLSelectElement *nsselect;
40 } HTMLSelectElement;
42 #define HTMLSELECT(x) ((IHTMLSelectElement*) &(x)->lpHTMLSelectElementVtbl)
44 #define HTMLSELECT_THIS(iface) DEFINE_THIS(HTMLSelectElement, HTMLSelectElement, iface)
46 static HRESULT WINAPI HTMLSelectElement_QueryInterface(IHTMLSelectElement *iface,
47 REFIID riid, void **ppv)
49 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
51 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
54 static ULONG WINAPI HTMLSelectElement_AddRef(IHTMLSelectElement *iface)
56 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
58 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
61 static ULONG WINAPI HTMLSelectElement_Release(IHTMLSelectElement *iface)
63 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
65 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
68 static HRESULT WINAPI HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement *iface, UINT *pctinfo)
70 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
71 FIXME("(%p)->(%p)\n", This, pctinfo);
72 return E_NOTIMPL;
75 static HRESULT WINAPI HTMLSelectElement_GetTypeInfo(IHTMLSelectElement *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
79 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
80 return E_NOTIMPL;
83 static HRESULT WINAPI HTMLSelectElement_GetIDsOfNames(IHTMLSelectElement *iface, REFIID riid,
84 LPOLESTR *rgszNames, UINT cNames,
85 LCID lcid, DISPID *rgDispId)
87 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
88 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
89 lcid, rgDispId);
90 return E_NOTIMPL;
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);
98 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
99 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
100 return E_NOTIMPL;
103 static HRESULT WINAPI HTMLSelectElement_put_size(IHTMLSelectElement *iface, long v)
105 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
106 FIXME("(%p)->(%ld)\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);
173 FIXME("(%p)->(%p)\n", This, p);
174 return E_NOTIMPL;
177 static HRESULT WINAPI HTMLSelectElement_put_onchange(IHTMLSelectElement *iface, VARIANT v)
179 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
181 TRACE("(%p)->()\n", This);
183 return set_node_event(&This->element.node, EVENTID_CHANGE, &v);
186 static HRESULT WINAPI HTMLSelectElement_get_onchange(IHTMLSelectElement *iface, VARIANT *p)
188 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
189 FIXME("(%p)->(%p)\n", This, p);
190 return E_NOTIMPL;
193 static HRESULT WINAPI HTMLSelectElement_put_selectedIndex(IHTMLSelectElement *iface, long v)
195 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
196 nsresult nsres;
198 TRACE("(%p)->(%ld)\n", This, v);
200 nsres = nsIDOMHTMLSelectElement_SetSelectedIndex(This->nsselect, v);
201 if(NS_FAILED(nsres))
202 ERR("SetSelectedIndex failed: %08x\n", nsres);
204 return S_OK;
207 static HRESULT WINAPI HTMLSelectElement_get_selectedIndex(IHTMLSelectElement *iface, long *p)
209 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
210 PRInt32 idx = 0;
211 nsresult nsres;
213 TRACE("(%p)->(%p)\n", This, p);
215 nsres = nsIDOMHTMLSelectElement_GetSelectedIndex(This->nsselect, &idx);
216 if(NS_FAILED(nsres))
217 ERR("GetSelectedIndex failed: %08x\n", nsres);
219 *p = idx;
220 return S_OK;
223 static HRESULT WINAPI HTMLSelectElement_get_type(IHTMLSelectElement *iface, BSTR *p)
225 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
226 FIXME("(%p)->(%p)\n", This, p);
227 return E_NOTIMPL;
230 static HRESULT WINAPI HTMLSelectElement_put_value(IHTMLSelectElement *iface, BSTR v)
232 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
233 nsAString value_str;
234 nsresult nsres;
236 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
238 nsAString_Init(&value_str, v);
239 nsres = nsIDOMHTMLSelectElement_SetValue(This->nsselect, &value_str);
240 nsAString_Finish(&value_str);
241 if(NS_FAILED(nsres))
242 ERR("SetValue failed: %08x\n", nsres);
244 return S_OK;
247 static HRESULT WINAPI HTMLSelectElement_get_value(IHTMLSelectElement *iface, BSTR *p)
249 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
250 nsAString value_str;
251 const PRUnichar *value = NULL;
252 nsresult nsres;
254 TRACE("(%p)->(%p)\n", This, p);
256 nsAString_Init(&value_str, NULL);
258 nsres = nsIDOMHTMLSelectElement_GetValue(This->nsselect, &value_str);
259 if(NS_SUCCEEDED(nsres)) {
260 nsAString_GetData(&value_str, &value);
261 *p = *value ? SysAllocString(value) : NULL;
262 }else {
263 ERR("GetValue failed: %08x\n", nsres);
266 nsAString_Finish(&value_str);
268 TRACE("value=%s\n", debugstr_w(*p));
269 return S_OK;
272 static HRESULT WINAPI HTMLSelectElement_put_disabled(IHTMLSelectElement *iface, VARIANT_BOOL v)
274 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
275 FIXME("(%p)->(%x)\n", This, v);
276 return E_NOTIMPL;
279 static HRESULT WINAPI HTMLSelectElement_get_disabled(IHTMLSelectElement *iface, VARIANT_BOOL *p)
281 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
282 FIXME("(%p)->(%p)\n", This, p);
283 return E_NOTIMPL;
286 static HRESULT WINAPI HTMLSelectElement_get_form(IHTMLSelectElement *iface, IHTMLFormElement **p)
288 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
289 FIXME("(%p)->(%p)\n", This, p);
290 return E_NOTIMPL;
293 static HRESULT WINAPI HTMLSelectElement_add(IHTMLSelectElement *iface, IHTMLElement *element,
294 VARIANT before)
296 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
297 FIXME("(%p)->(%p v)\n", This, element);
298 return E_NOTIMPL;
301 static HRESULT WINAPI HTMLSelectElement_remove(IHTMLSelectElement *iface, long index)
303 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
304 FIXME("(%p)->(%ld)\n", This, index);
305 return E_NOTIMPL;
308 static HRESULT WINAPI HTMLSelectElement_put_length(IHTMLSelectElement *iface, long v)
310 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
311 FIXME("(%p)->(%ld)\n", This, v);
312 return E_NOTIMPL;
315 static HRESULT WINAPI HTMLSelectElement_get_length(IHTMLSelectElement *iface, long *p)
317 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
318 PRUint32 length = 0;
319 nsresult nsres;
321 TRACE("(%p)->(%p)\n", This, p);
323 nsres = nsIDOMHTMLSelectElement_GetLength(This->nsselect, &length);
324 if(NS_FAILED(nsres))
325 ERR("GetLength failed: %08x\n", nsres);
327 *p = length;
329 TRACE("ret %ld\n", *p);
330 return S_OK;
333 static HRESULT WINAPI HTMLSelectElement_get__newEnum(IHTMLSelectElement *iface, IUnknown **p)
335 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
336 FIXME("(%p)->(%p)\n", This, p);
337 return E_NOTIMPL;
340 static HRESULT WINAPI HTMLSelectElement_item(IHTMLSelectElement *iface, VARIANT name,
341 VARIANT index, IDispatch **pdisp)
343 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
344 FIXME("(%p)->(v v %p)\n", This, pdisp);
345 return E_NOTIMPL;
348 static HRESULT WINAPI HTMLSelectElement_tags(IHTMLSelectElement *iface, VARIANT tagName,
349 IDispatch **pdisp)
351 HTMLSelectElement *This = HTMLSELECT_THIS(iface);
352 FIXME("(%p)->(v %p)\n", This, pdisp);
353 return E_NOTIMPL;
356 #undef HTMLSELECT_THIS
358 static const IHTMLSelectElementVtbl HTMLSelectElementVtbl = {
359 HTMLSelectElement_QueryInterface,
360 HTMLSelectElement_AddRef,
361 HTMLSelectElement_Release,
362 HTMLSelectElement_GetTypeInfoCount,
363 HTMLSelectElement_GetTypeInfo,
364 HTMLSelectElement_GetIDsOfNames,
365 HTMLSelectElement_Invoke,
366 HTMLSelectElement_put_size,
367 HTMLSelectElement_get_size,
368 HTMLSelectElement_put_multiple,
369 HTMLSelectElement_get_multiple,
370 HTMLSelectElement_put_name,
371 HTMLSelectElement_get_name,
372 HTMLSelectElement_get_options,
373 HTMLSelectElement_put_onchange,
374 HTMLSelectElement_get_onchange,
375 HTMLSelectElement_put_selectedIndex,
376 HTMLSelectElement_get_selectedIndex,
377 HTMLSelectElement_get_type,
378 HTMLSelectElement_put_value,
379 HTMLSelectElement_get_value,
380 HTMLSelectElement_put_disabled,
381 HTMLSelectElement_get_disabled,
382 HTMLSelectElement_get_form,
383 HTMLSelectElement_add,
384 HTMLSelectElement_remove,
385 HTMLSelectElement_put_length,
386 HTMLSelectElement_get_length,
387 HTMLSelectElement_get__newEnum,
388 HTMLSelectElement_item,
389 HTMLSelectElement_tags
392 #define HTMLSELECT_NODE_THIS(iface) DEFINE_THIS2(HTMLSelectElement, element.node, iface)
394 static HRESULT HTMLSelectElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
396 HTMLSelectElement *This = HTMLSELECT_NODE_THIS(iface);
398 *ppv = NULL;
400 if(IsEqualGUID(&IID_IUnknown, riid)) {
401 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
402 *ppv = HTMLSELECT(This);
403 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
404 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
405 *ppv = HTMLSELECT(This);
406 }else if(IsEqualGUID(&IID_IHTMLSelectElement, riid)) {
407 TRACE("(%p)->(IID_IHTMLSelectElement %p)\n", This, ppv);
408 *ppv = HTMLSELECT(This);
411 if(*ppv) {
412 IUnknown_AddRef((IUnknown*)*ppv);
413 return S_OK;
416 return HTMLElement_QI(&This->element.node, riid, ppv);
419 static void HTMLSelectElement_destructor(HTMLDOMNode *iface)
421 HTMLSelectElement *This = HTMLSELECT_NODE_THIS(iface);
423 nsIDOMHTMLSelectElement_Release(This->nsselect);
425 HTMLElement_destructor(&This->element.node);
428 #undef HTMLSELECT_NODE_THIS
430 static const NodeImplVtbl HTMLSelectElementImplVtbl = {
431 HTMLSelectElement_QI,
432 HTMLSelectElement_destructor
435 static const tid_t HTMLSelectElement_tids[] = {
436 IHTMLDOMNode_tid,
437 IHTMLDOMNode2_tid,
438 IHTMLElement_tid,
439 IHTMLElement2_tid,
440 IHTMLSelectElement_tid,
444 static dispex_static_data_t HTMLSelectElement_dispex = {
445 NULL,
446 DispHTMLSelectElement_tid,
447 NULL,
448 HTMLSelectElement_tids
451 HTMLElement *HTMLSelectElement_Create(nsIDOMHTMLElement *nselem)
453 HTMLSelectElement *ret = heap_alloc_zero(sizeof(HTMLSelectElement));
454 nsresult nsres;
456 ret->lpHTMLSelectElementVtbl = &HTMLSelectElementVtbl;
457 ret->element.node.vtbl = &HTMLSelectElementImplVtbl;
459 init_dispex(&ret->element.node.dispex, (IUnknown*)HTMLSELECT(ret), &HTMLSelectElement_dispex);
460 HTMLElement_Init(&ret->element);
462 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLSelectElement,
463 (void**)&ret->nsselect);
464 if(NS_FAILED(nsres))
465 ERR("Could not get nsIDOMHTMLSelectElement interfce: %08x\n", nsres);
467 return &ret->element;