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);
158 TRACE("(%p)->(%p)\n", This, p);
160 nsAString_Init(&value_str, NULL);
161 nsres = nsIDOMHTMLOptionElement_GetValue(This->nsoption, &value_str);
162 return return_nsstr(nsres, &value_str, p);
165 static HRESULT WINAPI HTMLOptionElement_put_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL v)
167 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
168 FIXME("(%p)->(%x)\n", This, v);
172 static HRESULT WINAPI HTMLOptionElement_get_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
174 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
175 FIXME("(%p)->(%p)\n", This, p);
179 static HRESULT WINAPI HTMLOptionElement_put_index(IHTMLOptionElement *iface, LONG v)
181 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
182 FIXME("(%p)->(%d)\n", This, v);
186 static HRESULT WINAPI HTMLOptionElement_get_index(IHTMLOptionElement *iface, LONG *p)
188 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
189 FIXME("(%p)->(%p)\n", This, p);
193 static HRESULT WINAPI HTMLOptionElement_put_text(IHTMLOptionElement *iface, BSTR v)
195 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
196 nsIDOMText *text_node;
201 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
203 if(!This->element.node.doc->nsdoc) {
204 WARN("NULL nsdoc\n");
211 nsres = nsIDOMHTMLOptionElement_GetFirstChild(This->nsoption, &child);
212 if(NS_FAILED(nsres) || !child)
215 nsres = nsIDOMHTMLOptionElement_RemoveChild(This->nsoption, child, &tmp);
216 nsIDOMNode_Release(child);
217 if(NS_SUCCEEDED(nsres)) {
218 nsIDOMNode_Release(tmp);
220 ERR("RemoveChild failed: %08x\n", nsres);
225 nsAString_InitDepend(&text_str, v);
226 nsres = nsIDOMHTMLDocument_CreateTextNode(This->element.node.doc->nsdoc, &text_str, &text_node);
227 nsAString_Finish(&text_str);
228 if(NS_FAILED(nsres)) {
229 ERR("CreateTextNode failed: %08x\n", nsres);
233 nsres = nsIDOMHTMLOptionElement_AppendChild(This->nsoption, (nsIDOMNode*)text_node, &tmp);
234 if(NS_SUCCEEDED(nsres))
235 nsIDOMNode_Release(tmp);
237 ERR("AppendChild failed: %08x\n", nsres);
242 static HRESULT WINAPI HTMLOptionElement_get_text(IHTMLOptionElement *iface, BSTR *p)
244 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
248 TRACE("(%p)->(%p)\n", This, p);
250 nsAString_Init(&text_str, NULL);
251 nsres = nsIDOMHTMLOptionElement_GetText(This->nsoption, &text_str);
252 return return_nsstr(nsres, &text_str, p);
255 static HRESULT WINAPI HTMLOptionElement_get_form(IHTMLOptionElement *iface, IHTMLFormElement **p)
257 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
258 FIXME("(%p)->(%p)\n", This, p);
262 static const IHTMLOptionElementVtbl HTMLOptionElementVtbl = {
263 HTMLOptionElement_QueryInterface,
264 HTMLOptionElement_AddRef,
265 HTMLOptionElement_Release,
266 HTMLOptionElement_GetTypeInfoCount,
267 HTMLOptionElement_GetTypeInfo,
268 HTMLOptionElement_GetIDsOfNames,
269 HTMLOptionElement_Invoke,
270 HTMLOptionElement_put_selected,
271 HTMLOptionElement_get_selected,
272 HTMLOptionElement_put_value,
273 HTMLOptionElement_get_value,
274 HTMLOptionElement_put_defaultSelected,
275 HTMLOptionElement_get_defaultSelected,
276 HTMLOptionElement_put_index,
277 HTMLOptionElement_get_index,
278 HTMLOptionElement_put_text,
279 HTMLOptionElement_get_text,
280 HTMLOptionElement_get_form
283 static inline HTMLOptionElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
285 return CONTAINING_RECORD(iface, HTMLOptionElement, element.node);
288 static HRESULT HTMLOptionElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
290 HTMLOptionElement *This = impl_from_HTMLDOMNode(iface);
294 if(IsEqualGUID(&IID_IUnknown, riid)) {
295 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
296 *ppv = &This->IHTMLOptionElement_iface;
297 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
298 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
299 *ppv = &This->IHTMLOptionElement_iface;
300 }else if(IsEqualGUID(&IID_IHTMLOptionElement, riid)) {
301 TRACE("(%p)->(IID_IHTMLOptionElement %p)\n", This, ppv);
302 *ppv = &This->IHTMLOptionElement_iface;
306 IUnknown_AddRef((IUnknown*)*ppv);
310 return HTMLElement_QI(&This->element.node, riid, ppv);
313 static void HTMLOptionElement_destructor(HTMLDOMNode *iface)
315 HTMLOptionElement *This = impl_from_HTMLDOMNode(iface);
318 nsIDOMHTMLOptionElement_Release(This->nsoption);
320 HTMLElement_destructor(&This->element.node);
323 static const NodeImplVtbl HTMLOptionElementImplVtbl = {
324 HTMLOptionElement_QI,
325 HTMLOptionElement_destructor,
327 HTMLElement_get_attr_col
330 static const tid_t HTMLOptionElement_iface_tids[] = {
332 IHTMLOptionElement_tid,
335 static dispex_static_data_t HTMLOptionElement_dispex = {
337 DispHTMLOptionElement_tid,
339 HTMLOptionElement_iface_tids
342 HRESULT HTMLOptionElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
344 HTMLOptionElement *ret;
347 ret = heap_alloc_zero(sizeof(HTMLOptionElement));
349 return E_OUTOFMEMORY;
351 ret->IHTMLOptionElement_iface.lpVtbl = &HTMLOptionElementVtbl;
352 ret->element.node.vtbl = &HTMLOptionElementImplVtbl;
354 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLOptionElement, (void**)&ret->nsoption);
355 if(NS_FAILED(nsres)) {
356 ERR("Could not get nsIDOMHTMLOptionElement interface: %08x\n", nsres);
361 HTMLElement_Init(&ret->element, doc, nselem, &HTMLOptionElement_dispex);
363 *elem = &ret->element;
367 static inline HTMLOptionElementFactory *impl_from_IHTMLOptionElementFactory(IHTMLOptionElementFactory *iface)
369 return CONTAINING_RECORD(iface, HTMLOptionElementFactory, IHTMLOptionElementFactory_iface);
372 static HRESULT WINAPI HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory *iface,
373 REFIID riid, void **ppv)
375 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
379 if(IsEqualGUID(&IID_IUnknown, riid)) {
380 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
381 *ppv = &This->IHTMLOptionElementFactory_iface;
382 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
383 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
384 *ppv = &This->IHTMLOptionElementFactory_iface;
385 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory, riid)) {
386 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This, ppv);
387 *ppv = &This->IHTMLOptionElementFactory_iface;
391 IUnknown_AddRef((IUnknown*)*ppv);
395 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
396 return E_NOINTERFACE;
399 static ULONG WINAPI HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory *iface)
401 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
402 LONG ref = InterlockedIncrement(&This->ref);
404 TRACE("(%p) ref=%d\n", This, ref);
409 static ULONG WINAPI HTMLOptionElementFactory_Release(IHTMLOptionElementFactory *iface)
411 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
412 LONG ref = InterlockedDecrement(&This->ref);
414 TRACE("(%p) ref=%d\n", This, ref);
422 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory *iface, UINT *pctinfo)
424 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
425 FIXME("(%p)->(%p)\n", This, pctinfo);
429 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory *iface, UINT iTInfo,
430 LCID lcid, ITypeInfo **ppTInfo)
432 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
433 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
437 static HRESULT WINAPI HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory *iface, REFIID riid,
438 LPOLESTR *rgszNames, UINT cNames,
439 LCID lcid, DISPID *rgDispId)
441 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
442 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
447 static HRESULT WINAPI HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory *iface, DISPID dispIdMember,
448 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
449 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
451 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
452 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
453 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
457 static HRESULT WINAPI HTMLOptionElementFactory_create(IHTMLOptionElementFactory *iface,
458 VARIANT text, VARIANT value, VARIANT defaultselected, VARIANT selected,
459 IHTMLOptionElement **optelem)
461 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
462 nsIDOMHTMLElement *nselem;
466 static const PRUnichar optionW[] = {'O','P','T','I','O','N',0};
468 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_variant(&text), debugstr_variant(&value),
469 debugstr_variant(&defaultselected), debugstr_variant(&selected), optelem);
471 if(!This->window || !This->window->doc) {
478 hres = create_nselem(This->window->doc, optionW, &nselem);
482 hres = get_node(This->window->doc, (nsIDOMNode*)nselem, TRUE, &node);
483 nsIDOMHTMLElement_Release(nselem);
487 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface,
488 &IID_IHTMLOptionElement, (void**)optelem);
490 if(V_VT(&text) == VT_BSTR)
491 IHTMLOptionElement_put_text(*optelem, V_BSTR(&text));
492 else if(V_VT(&text) != VT_EMPTY)
493 FIXME("Unsupported text %s\n", debugstr_variant(&text));
495 if(V_VT(&value) == VT_BSTR)
496 IHTMLOptionElement_put_value(*optelem, V_BSTR(&value));
497 else if(V_VT(&value) != VT_EMPTY)
498 FIXME("Unsupported value %s\n", debugstr_variant(&value));
500 if(V_VT(&defaultselected) != VT_EMPTY)
501 FIXME("Unsupported defaultselected %s\n", debugstr_variant(&defaultselected));
502 if(V_VT(&selected) != VT_EMPTY)
503 FIXME("Unsupported selected %s\n", debugstr_variant(&selected));
508 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl = {
509 HTMLOptionElementFactory_QueryInterface,
510 HTMLOptionElementFactory_AddRef,
511 HTMLOptionElementFactory_Release,
512 HTMLOptionElementFactory_GetTypeInfoCount,
513 HTMLOptionElementFactory_GetTypeInfo,
514 HTMLOptionElementFactory_GetIDsOfNames,
515 HTMLOptionElementFactory_Invoke,
516 HTMLOptionElementFactory_create
519 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow *window)
521 HTMLOptionElementFactory *ret;
523 ret = heap_alloc(sizeof(HTMLOptionElementFactory));
525 ret->IHTMLOptionElementFactory_iface.lpVtbl = &HTMLOptionElementFactoryVtbl;
527 ret->window = window;