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
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 struct HTMLOptionElement {
37 IHTMLOptionElement IHTMLOptionElement_iface;
39 nsIDOMHTMLOptionElement *nsoption;
42 static inline HTMLOptionElement *impl_from_IHTMLOptionElement(IHTMLOptionElement *iface)
44 return CONTAINING_RECORD(iface, HTMLOptionElement, IHTMLOptionElement_iface);
47 static HRESULT WINAPI HTMLOptionElement_QueryInterface(IHTMLOptionElement *iface,
48 REFIID riid, void **ppv)
50 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
52 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
55 static ULONG WINAPI HTMLOptionElement_AddRef(IHTMLOptionElement *iface)
57 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
59 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
62 static ULONG WINAPI HTMLOptionElement_Release(IHTMLOptionElement *iface)
64 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
66 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
69 static HRESULT WINAPI HTMLOptionElement_GetTypeInfoCount(IHTMLOptionElement *iface, UINT *pctinfo)
71 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
72 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
75 static HRESULT WINAPI HTMLOptionElement_GetTypeInfo(IHTMLOptionElement *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
79 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
83 static HRESULT WINAPI HTMLOptionElement_GetIDsOfNames(IHTMLOptionElement *iface, REFIID riid,
84 LPOLESTR *rgszNames, UINT cNames,
85 LCID lcid, DISPID *rgDispId)
87 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
88 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
89 cNames, lcid, rgDispId);
92 static HRESULT WINAPI HTMLOptionElement_Invoke(IHTMLOptionElement *iface, DISPID dispIdMember,
93 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
94 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
96 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
97 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
98 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
101 static HRESULT WINAPI HTMLOptionElement_put_selected(IHTMLOptionElement *iface, VARIANT_BOOL v)
103 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
106 TRACE("(%p)->(%x)\n", This, v);
108 nsres = nsIDOMHTMLOptionElement_SetSelected(This->nsoption, v != VARIANT_FALSE);
109 if(NS_FAILED(nsres)) {
110 ERR("SetSelected failed: %08x\n", nsres);
117 static HRESULT WINAPI HTMLOptionElement_get_selected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
119 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
123 TRACE("(%p)->(%p)\n", This, p);
125 nsres = nsIDOMHTMLOptionElement_GetSelected(This->nsoption, &selected);
126 if(NS_FAILED(nsres)) {
127 ERR("GetSelected failed: %08x\n", nsres);
131 *p = selected ? VARIANT_TRUE : VARIANT_FALSE;
135 static HRESULT WINAPI HTMLOptionElement_put_value(IHTMLOptionElement *iface, BSTR v)
137 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
141 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
143 nsAString_InitDepend(&value_str, v);
144 nsres = nsIDOMHTMLOptionElement_SetValue(This->nsoption, &value_str);
145 nsAString_Finish(&value_str);
147 ERR("SetValue failed: %08x\n", nsres);
152 static HRESULT WINAPI HTMLOptionElement_get_value(IHTMLOptionElement *iface, BSTR *p)
154 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
156 const PRUnichar *value;
159 TRACE("(%p)->(%p)\n", This, p);
161 nsAString_Init(&value_str, NULL);
162 nsres = nsIDOMHTMLOptionElement_GetValue(This->nsoption, &value_str);
163 if(NS_SUCCEEDED(nsres)) {
164 nsAString_GetData(&value_str, &value);
165 *p = SysAllocString(value);
167 ERR("GetValue failed: %08x\n", nsres);
170 nsAString_Finish(&value_str);
175 static HRESULT WINAPI HTMLOptionElement_put_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL v)
177 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
178 FIXME("(%p)->(%x)\n", This, v);
182 static HRESULT WINAPI HTMLOptionElement_get_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
184 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
185 FIXME("(%p)->(%p)\n", This, p);
189 static HRESULT WINAPI HTMLOptionElement_put_index(IHTMLOptionElement *iface, LONG v)
191 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
192 FIXME("(%p)->(%d)\n", This, v);
196 static HRESULT WINAPI HTMLOptionElement_get_index(IHTMLOptionElement *iface, LONG *p)
198 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
199 FIXME("(%p)->(%p)\n", This, p);
203 static HRESULT WINAPI HTMLOptionElement_put_text(IHTMLOptionElement *iface, BSTR v)
205 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
206 nsIDOMText *text_node;
211 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
213 if(!This->element.node.doc->nsdoc) {
214 WARN("NULL nsdoc\n");
221 nsres = nsIDOMHTMLOptionElement_GetFirstChild(This->nsoption, &child);
222 if(NS_FAILED(nsres) || !child)
225 nsres = nsIDOMHTMLOptionElement_RemoveChild(This->nsoption, child, &tmp);
226 nsIDOMNode_Release(child);
227 if(NS_SUCCEEDED(nsres)) {
228 nsIDOMNode_Release(tmp);
230 ERR("RemoveChild failed: %08x\n", nsres);
235 nsAString_InitDepend(&text_str, v);
236 nsres = nsIDOMHTMLDocument_CreateTextNode(This->element.node.doc->nsdoc, &text_str, &text_node);
237 nsAString_Finish(&text_str);
238 if(NS_FAILED(nsres)) {
239 ERR("CreateTextNode failed: %08x\n", nsres);
243 nsres = nsIDOMHTMLOptionElement_AppendChild(This->nsoption, (nsIDOMNode*)text_node, &tmp);
244 if(NS_SUCCEEDED(nsres))
245 nsIDOMNode_Release(tmp);
247 ERR("AppendChild failed: %08x\n", nsres);
252 static HRESULT WINAPI HTMLOptionElement_get_text(IHTMLOptionElement *iface, BSTR *p)
254 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
256 const PRUnichar *text;
259 TRACE("(%p)->(%p)\n", This, p);
261 nsAString_Init(&text_str, NULL);
262 nsres = nsIDOMHTMLOptionElement_GetText(This->nsoption, &text_str);
263 if(NS_SUCCEEDED(nsres)) {
264 nsAString_GetData(&text_str, &text);
265 *p = SysAllocString(text);
267 ERR("GetText failed: %08x\n", nsres);
270 nsAString_Finish(&text_str);
275 static HRESULT WINAPI HTMLOptionElement_get_form(IHTMLOptionElement *iface, IHTMLFormElement **p)
277 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
278 FIXME("(%p)->(%p)\n", This, p);
282 static const IHTMLOptionElementVtbl HTMLOptionElementVtbl = {
283 HTMLOptionElement_QueryInterface,
284 HTMLOptionElement_AddRef,
285 HTMLOptionElement_Release,
286 HTMLOptionElement_GetTypeInfoCount,
287 HTMLOptionElement_GetTypeInfo,
288 HTMLOptionElement_GetIDsOfNames,
289 HTMLOptionElement_Invoke,
290 HTMLOptionElement_put_selected,
291 HTMLOptionElement_get_selected,
292 HTMLOptionElement_put_value,
293 HTMLOptionElement_get_value,
294 HTMLOptionElement_put_defaultSelected,
295 HTMLOptionElement_get_defaultSelected,
296 HTMLOptionElement_put_index,
297 HTMLOptionElement_get_index,
298 HTMLOptionElement_put_text,
299 HTMLOptionElement_get_text,
300 HTMLOptionElement_get_form
303 static inline HTMLOptionElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
305 return CONTAINING_RECORD(iface, HTMLOptionElement, element.node);
308 static HRESULT HTMLOptionElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
310 HTMLOptionElement *This = impl_from_HTMLDOMNode(iface);
314 if(IsEqualGUID(&IID_IUnknown, riid)) {
315 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
316 *ppv = &This->IHTMLOptionElement_iface;
317 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
318 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
319 *ppv = &This->IHTMLOptionElement_iface;
320 }else if(IsEqualGUID(&IID_IHTMLOptionElement, riid)) {
321 TRACE("(%p)->(IID_IHTMLOptionElement %p)\n", This, ppv);
322 *ppv = &This->IHTMLOptionElement_iface;
326 IUnknown_AddRef((IUnknown*)*ppv);
330 return HTMLElement_QI(&This->element.node, riid, ppv);
333 static void HTMLOptionElement_destructor(HTMLDOMNode *iface)
335 HTMLOptionElement *This = impl_from_HTMLDOMNode(iface);
338 nsIDOMHTMLOptionElement_Release(This->nsoption);
340 HTMLElement_destructor(&This->element.node);
343 static const NodeImplVtbl HTMLOptionElementImplVtbl = {
344 HTMLOptionElement_QI,
345 HTMLOptionElement_destructor,
347 HTMLElement_get_attr_col
350 static const tid_t HTMLOptionElement_iface_tids[] = {
352 IHTMLOptionElement_tid,
355 static dispex_static_data_t HTMLOptionElement_dispex = {
357 DispHTMLOptionElement_tid,
359 HTMLOptionElement_iface_tids
362 HRESULT HTMLOptionElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
364 HTMLOptionElement *ret;
367 ret = heap_alloc_zero(sizeof(HTMLOptionElement));
369 return E_OUTOFMEMORY;
371 ret->IHTMLOptionElement_iface.lpVtbl = &HTMLOptionElementVtbl;
372 ret->element.node.vtbl = &HTMLOptionElementImplVtbl;
374 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLOptionElement, (void**)&ret->nsoption);
375 if(NS_FAILED(nsres)) {
376 ERR("Could not get nsIDOMHTMLOptionElement interface: %08x\n", nsres);
381 HTMLElement_Init(&ret->element, doc, nselem, &HTMLOptionElement_dispex);
383 *elem = &ret->element;
387 static inline HTMLOptionElementFactory *impl_from_IHTMLOptionElementFactory(IHTMLOptionElementFactory *iface)
389 return CONTAINING_RECORD(iface, HTMLOptionElementFactory, IHTMLOptionElementFactory_iface);
392 static HRESULT WINAPI HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory *iface,
393 REFIID riid, void **ppv)
395 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
399 if(IsEqualGUID(&IID_IUnknown, riid)) {
400 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
401 *ppv = &This->IHTMLOptionElementFactory_iface;
402 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
403 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
404 *ppv = &This->IHTMLOptionElementFactory_iface;
405 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory, riid)) {
406 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This, ppv);
407 *ppv = &This->IHTMLOptionElementFactory_iface;
411 IUnknown_AddRef((IUnknown*)*ppv);
415 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
416 return E_NOINTERFACE;
419 static ULONG WINAPI HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory *iface)
421 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
422 LONG ref = InterlockedIncrement(&This->ref);
424 TRACE("(%p) ref=%d\n", This, ref);
429 static ULONG WINAPI HTMLOptionElementFactory_Release(IHTMLOptionElementFactory *iface)
431 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
432 LONG ref = InterlockedDecrement(&This->ref);
434 TRACE("(%p) ref=%d\n", This, ref);
442 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory *iface, UINT *pctinfo)
444 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
445 FIXME("(%p)->(%p)\n", This, pctinfo);
449 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory *iface, UINT iTInfo,
450 LCID lcid, ITypeInfo **ppTInfo)
452 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
453 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
457 static HRESULT WINAPI HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory *iface, REFIID riid,
458 LPOLESTR *rgszNames, UINT cNames,
459 LCID lcid, DISPID *rgDispId)
461 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
462 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
467 static HRESULT WINAPI HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory *iface, DISPID dispIdMember,
468 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
469 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
471 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
472 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
473 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
477 static HRESULT WINAPI HTMLOptionElementFactory_create(IHTMLOptionElementFactory *iface,
478 VARIANT text, VARIANT value, VARIANT defaultselected, VARIANT selected,
479 IHTMLOptionElement **optelem)
481 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
482 nsIDOMHTMLElement *nselem;
486 static const PRUnichar optionW[] = {'O','P','T','I','O','N',0};
488 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_variant(&text), debugstr_variant(&value),
489 debugstr_variant(&defaultselected), debugstr_variant(&selected), optelem);
491 if(!This->window || !This->window->doc) {
498 hres = create_nselem(This->window->doc, optionW, &nselem);
502 hres = get_node(This->window->doc, (nsIDOMNode*)nselem, TRUE, &node);
503 nsIDOMHTMLElement_Release(nselem);
507 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface,
508 &IID_IHTMLOptionElement, (void**)optelem);
510 if(V_VT(&text) == VT_BSTR)
511 IHTMLOptionElement_put_text(*optelem, V_BSTR(&text));
512 else if(V_VT(&text) != VT_EMPTY)
513 FIXME("Unsupported text vt=%d\n", V_VT(&text));
515 if(V_VT(&value) == VT_BSTR)
516 IHTMLOptionElement_put_value(*optelem, V_BSTR(&value));
517 else if(V_VT(&value) != VT_EMPTY)
518 FIXME("Unsupported value vt=%d\n", V_VT(&value));
520 if(V_VT(&defaultselected) != VT_EMPTY)
521 FIXME("Unsupported defaultselected vt=%d\n", V_VT(&defaultselected));
522 if(V_VT(&selected) != VT_EMPTY)
523 FIXME("Unsupported selected vt=%d\n", V_VT(&selected));
528 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl = {
529 HTMLOptionElementFactory_QueryInterface,
530 HTMLOptionElementFactory_AddRef,
531 HTMLOptionElementFactory_Release,
532 HTMLOptionElementFactory_GetTypeInfoCount,
533 HTMLOptionElementFactory_GetTypeInfo,
534 HTMLOptionElementFactory_GetIDsOfNames,
535 HTMLOptionElementFactory_Invoke,
536 HTMLOptionElementFactory_create
539 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow *window)
541 HTMLOptionElementFactory *ret;
543 ret = heap_alloc(sizeof(HTMLOptionElementFactory));
545 ret->IHTMLOptionElementFactory_iface.lpVtbl = &HTMLOptionElementFactoryVtbl;
547 ret->window = window;