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 const IHTMLOptionElementVtbl *lpHTMLOptionElementVtbl;
39 nsIDOMHTMLOptionElement *nsoption;
42 #define HTMLOPTION(x) (&(x)->lpHTMLOptionElementVtbl)
44 #define HTMLOPTION_THIS(iface) DEFINE_THIS(HTMLOptionElement, HTMLOptionElement, iface)
46 static HRESULT WINAPI HTMLOptionElement_QueryInterface(IHTMLOptionElement *iface,
47 REFIID riid, void **ppv)
49 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
51 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
54 static ULONG WINAPI HTMLOptionElement_AddRef(IHTMLOptionElement *iface)
56 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
58 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
61 static ULONG WINAPI HTMLOptionElement_Release(IHTMLOptionElement *iface)
63 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
65 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
68 static HRESULT WINAPI HTMLOptionElement_GetTypeInfoCount(IHTMLOptionElement *iface, UINT *pctinfo)
70 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
71 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
74 static HRESULT WINAPI HTMLOptionElement_GetTypeInfo(IHTMLOptionElement *iface, UINT iTInfo,
75 LCID lcid, ITypeInfo **ppTInfo)
77 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
78 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
82 static HRESULT WINAPI HTMLOptionElement_GetIDsOfNames(IHTMLOptionElement *iface, REFIID riid,
83 LPOLESTR *rgszNames, UINT cNames,
84 LCID lcid, DISPID *rgDispId)
86 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
87 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
88 cNames, lcid, rgDispId);
91 static HRESULT WINAPI HTMLOptionElement_Invoke(IHTMLOptionElement *iface, DISPID dispIdMember,
92 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
93 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
95 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
96 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
97 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
100 static HRESULT WINAPI HTMLOptionElement_put_selected(IHTMLOptionElement *iface, VARIANT_BOOL v)
102 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
105 TRACE("(%p)->(%x)\n", This, v);
107 nsres = nsIDOMHTMLOptionElement_SetSelected(This->nsoption, v != VARIANT_FALSE);
108 if(NS_FAILED(nsres)) {
109 ERR("SetSelected failed: %08x\n", nsres);
116 static HRESULT WINAPI HTMLOptionElement_get_selected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
118 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
122 TRACE("(%p)->(%p)\n", This, p);
124 nsres = nsIDOMHTMLOptionElement_GetSelected(This->nsoption, &selected);
125 if(NS_FAILED(nsres)) {
126 ERR("GetSelected failed: %08x\n", nsres);
130 *p = selected ? VARIANT_TRUE : VARIANT_FALSE;
134 static HRESULT WINAPI HTMLOptionElement_put_value(IHTMLOptionElement *iface, BSTR v)
136 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
140 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
142 nsAString_InitDepend(&value_str, v);
143 nsres = nsIDOMHTMLOptionElement_SetValue(This->nsoption, &value_str);
144 nsAString_Finish(&value_str);
146 ERR("SetValue failed: %08x\n", nsres);
151 static HRESULT WINAPI HTMLOptionElement_get_value(IHTMLOptionElement *iface, BSTR *p)
153 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
155 const PRUnichar *value;
158 TRACE("(%p)->(%p)\n", This, p);
160 nsAString_Init(&value_str, NULL);
161 nsres = nsIDOMHTMLOptionElement_GetValue(This->nsoption, &value_str);
162 if(NS_SUCCEEDED(nsres)) {
163 nsAString_GetData(&value_str, &value);
164 *p = SysAllocString(value);
166 ERR("GetValue failed: %08x\n", nsres);
169 nsAString_Finish(&value_str);
174 static HRESULT WINAPI HTMLOptionElement_put_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL v)
176 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
177 FIXME("(%p)->(%x)\n", This, v);
181 static HRESULT WINAPI HTMLOptionElement_get_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
183 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
184 FIXME("(%p)->(%p)\n", This, p);
188 static HRESULT WINAPI HTMLOptionElement_put_index(IHTMLOptionElement *iface, LONG v)
190 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
191 FIXME("(%p)->(%d)\n", This, v);
195 static HRESULT WINAPI HTMLOptionElement_get_index(IHTMLOptionElement *iface, LONG *p)
197 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
198 FIXME("(%p)->(%p)\n", This, p);
202 static HRESULT WINAPI HTMLOptionElement_put_text(IHTMLOptionElement *iface, BSTR v)
204 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
205 nsIDOMText *text_node;
210 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
212 if(!This->element.node.doc->nsdoc) {
213 WARN("NULL nsdoc\n");
220 nsres = nsIDOMHTMLOptionElement_GetFirstChild(This->nsoption, &child);
221 if(NS_FAILED(nsres) || !child)
224 nsres = nsIDOMHTMLOptionElement_RemoveChild(This->nsoption, child, &tmp);
225 nsIDOMNode_Release(child);
226 if(NS_SUCCEEDED(nsres)) {
227 nsIDOMNode_Release(tmp);
229 ERR("RemoveChild failed: %08x\n", nsres);
234 nsAString_InitDepend(&text_str, v);
235 nsres = nsIDOMHTMLDocument_CreateTextNode(This->element.node.doc->nsdoc, &text_str, &text_node);
236 nsAString_Finish(&text_str);
237 if(NS_FAILED(nsres)) {
238 ERR("CreateTextNode failed: %08x\n", nsres);
242 nsres = nsIDOMHTMLOptionElement_AppendChild(This->nsoption, (nsIDOMNode*)text_node, &tmp);
243 if(NS_SUCCEEDED(nsres))
244 nsIDOMNode_Release(tmp);
246 ERR("AppendChild failed: %08x\n", nsres);
251 static HRESULT WINAPI HTMLOptionElement_get_text(IHTMLOptionElement *iface, BSTR *p)
253 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
255 const PRUnichar *text;
258 TRACE("(%p)->(%p)\n", This, p);
260 nsAString_Init(&text_str, NULL);
261 nsres = nsIDOMHTMLOptionElement_GetText(This->nsoption, &text_str);
262 if(NS_SUCCEEDED(nsres)) {
263 nsAString_GetData(&text_str, &text);
264 *p = SysAllocString(text);
266 ERR("GetText failed: %08x\n", nsres);
269 nsAString_Finish(&text_str);
274 static HRESULT WINAPI HTMLOptionElement_get_form(IHTMLOptionElement *iface, IHTMLFormElement **p)
276 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
277 FIXME("(%p)->(%p)\n", This, p);
281 #undef HTMLOPTION_THIS
283 static const IHTMLOptionElementVtbl HTMLOptionElementVtbl = {
284 HTMLOptionElement_QueryInterface,
285 HTMLOptionElement_AddRef,
286 HTMLOptionElement_Release,
287 HTMLOptionElement_GetTypeInfoCount,
288 HTMLOptionElement_GetTypeInfo,
289 HTMLOptionElement_GetIDsOfNames,
290 HTMLOptionElement_Invoke,
291 HTMLOptionElement_put_selected,
292 HTMLOptionElement_get_selected,
293 HTMLOptionElement_put_value,
294 HTMLOptionElement_get_value,
295 HTMLOptionElement_put_defaultSelected,
296 HTMLOptionElement_get_defaultSelected,
297 HTMLOptionElement_put_index,
298 HTMLOptionElement_get_index,
299 HTMLOptionElement_put_text,
300 HTMLOptionElement_get_text,
301 HTMLOptionElement_get_form
304 static inline HTMLOptionElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
306 return CONTAINING_RECORD(iface, HTMLOptionElement, element.node);
309 static HRESULT HTMLOptionElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
311 HTMLOptionElement *This = impl_from_HTMLDOMNode(iface);
315 if(IsEqualGUID(&IID_IUnknown, riid)) {
316 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
317 *ppv = HTMLOPTION(This);
318 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
319 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
320 *ppv = HTMLOPTION(This);
321 }else if(IsEqualGUID(&IID_IHTMLOptionElement, riid)) {
322 TRACE("(%p)->(IID_IHTMLOptionElement %p)\n", This, ppv);
323 *ppv = HTMLOPTION(This);
327 IUnknown_AddRef((IUnknown*)*ppv);
331 return HTMLElement_QI(&This->element.node, riid, ppv);
334 static void HTMLOptionElement_destructor(HTMLDOMNode *iface)
336 HTMLOptionElement *This = impl_from_HTMLDOMNode(iface);
339 nsIDOMHTMLOptionElement_Release(This->nsoption);
341 HTMLElement_destructor(&This->element.node);
344 static const NodeImplVtbl HTMLOptionElementImplVtbl = {
345 HTMLOptionElement_QI,
346 HTMLOptionElement_destructor,
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->lpHTMLOptionElementVtbl = &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 #define HTMLOPTFACTORY_THIS(iface) DEFINE_THIS(HTMLOptionElementFactory, HTMLOptionElementFactory, iface)
389 static HRESULT WINAPI HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory *iface,
390 REFIID riid, void **ppv)
392 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
396 if(IsEqualGUID(&IID_IUnknown, riid)) {
397 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
398 *ppv = HTMLOPTFACTORY(This);
399 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
400 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
401 *ppv = HTMLOPTFACTORY(This);
402 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory, riid)) {
403 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This, ppv);
404 *ppv = HTMLOPTFACTORY(This);
408 IUnknown_AddRef((IUnknown*)*ppv);
412 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
413 return E_NOINTERFACE;
416 static ULONG WINAPI HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory *iface)
418 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
419 LONG ref = InterlockedIncrement(&This->ref);
421 TRACE("(%p) ref=%d\n", This, ref);
426 static ULONG WINAPI HTMLOptionElementFactory_Release(IHTMLOptionElementFactory *iface)
428 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
429 LONG ref = InterlockedDecrement(&This->ref);
431 TRACE("(%p) ref=%d\n", This, ref);
439 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory *iface, UINT *pctinfo)
441 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
442 FIXME("(%p)->(%p)\n", This, pctinfo);
446 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory *iface, UINT iTInfo,
447 LCID lcid, ITypeInfo **ppTInfo)
449 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
450 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
454 static HRESULT WINAPI HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory *iface, REFIID riid,
455 LPOLESTR *rgszNames, UINT cNames,
456 LCID lcid, DISPID *rgDispId)
458 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
459 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
464 static HRESULT WINAPI HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory *iface, DISPID dispIdMember,
465 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
466 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
468 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
469 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
470 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
474 static HRESULT WINAPI HTMLOptionElementFactory_create(IHTMLOptionElementFactory *iface,
475 VARIANT text, VARIANT value, VARIANT defaultselected, VARIANT selected,
476 IHTMLOptionElement **optelem)
478 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
479 nsIDOMHTMLElement *nselem;
483 static const PRUnichar optionW[] = {'O','P','T','I','O','N',0};
485 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_variant(&text), debugstr_variant(&value),
486 debugstr_variant(&defaultselected), debugstr_variant(&selected), optelem);
488 if(!This->window || !This->window->doc) {
495 hres = create_nselem(This->window->doc, optionW, &nselem);
499 hres = get_node(This->window->doc, (nsIDOMNode*)nselem, TRUE, &node);
500 nsIDOMHTMLElement_Release(nselem);
504 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface,
505 &IID_IHTMLOptionElement, (void**)optelem);
507 if(V_VT(&text) == VT_BSTR)
508 IHTMLOptionElement_put_text(*optelem, V_BSTR(&text));
509 else if(V_VT(&text) != VT_EMPTY)
510 FIXME("Unsupported text vt=%d\n", V_VT(&text));
512 if(V_VT(&value) == VT_BSTR)
513 IHTMLOptionElement_put_value(*optelem, V_BSTR(&value));
514 else if(V_VT(&value) != VT_EMPTY)
515 FIXME("Unsupported value vt=%d\n", V_VT(&value));
517 if(V_VT(&defaultselected) != VT_EMPTY)
518 FIXME("Unsupported defaultselected vt=%d\n", V_VT(&defaultselected));
519 if(V_VT(&selected) != VT_EMPTY)
520 FIXME("Unsupported selected vt=%d\n", V_VT(&selected));
525 #undef HTMLOPTFACTORY_THIS
527 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl = {
528 HTMLOptionElementFactory_QueryInterface,
529 HTMLOptionElementFactory_AddRef,
530 HTMLOptionElementFactory_Release,
531 HTMLOptionElementFactory_GetTypeInfoCount,
532 HTMLOptionElementFactory_GetTypeInfo,
533 HTMLOptionElementFactory_GetIDsOfNames,
534 HTMLOptionElementFactory_Invoke,
535 HTMLOptionElementFactory_create
538 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow *window)
540 HTMLOptionElementFactory *ret;
542 ret = heap_alloc(sizeof(HTMLOptionElementFactory));
544 ret->lpHTMLOptionElementFactoryVtbl = &HTMLOptionElementFactoryVtbl;
546 ret->window = window;