msxml3: Improve namespace tests to highlight get nodeName issue.
[wine.git] / dlls / mshtml / htmloption.c
blob9137765136e36acfea8412517adf0b23d443b84c
1 /*
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
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 struct HTMLOptionElement {
35 HTMLElement element;
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,
80 ppTInfo);
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);
104 nsresult nsres;
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);
111 return E_FAIL;
114 return S_OK;
117 static HRESULT WINAPI HTMLOptionElement_get_selected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
119 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
120 PRBool selected;
121 nsresult nsres;
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);
128 return E_FAIL;
131 *p = selected ? VARIANT_TRUE : VARIANT_FALSE;
132 return S_OK;
135 static HRESULT WINAPI HTMLOptionElement_put_value(IHTMLOptionElement *iface, BSTR v)
137 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
138 nsAString value_str;
139 nsresult nsres;
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);
146 if(NS_FAILED(nsres))
147 ERR("SetValue failed: %08x\n", nsres);
149 return S_OK;
152 static HRESULT WINAPI HTMLOptionElement_get_value(IHTMLOptionElement *iface, BSTR *p)
154 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
155 nsAString value_str;
156 const PRUnichar *value;
157 nsresult nsres;
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);
166 }else {
167 ERR("GetValue failed: %08x\n", nsres);
168 *p = NULL;
170 nsAString_Finish(&value_str);
172 return S_OK;
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);
179 return E_NOTIMPL;
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);
186 return E_NOTIMPL;
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);
193 return E_NOTIMPL;
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);
200 return E_NOTIMPL;
203 static HRESULT WINAPI HTMLOptionElement_put_text(IHTMLOptionElement *iface, BSTR v)
205 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
206 nsIDOMText *text_node;
207 nsAString text_str;
208 nsIDOMNode *tmp;
209 nsresult nsres;
211 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
213 if(!This->element.node.doc->nsdoc) {
214 WARN("NULL nsdoc\n");
215 return E_UNEXPECTED;
218 while(1) {
219 nsIDOMNode *child;
221 nsres = nsIDOMHTMLOptionElement_GetFirstChild(This->nsoption, &child);
222 if(NS_FAILED(nsres) || !child)
223 break;
225 nsres = nsIDOMHTMLOptionElement_RemoveChild(This->nsoption, child, &tmp);
226 nsIDOMNode_Release(child);
227 if(NS_SUCCEEDED(nsres)) {
228 nsIDOMNode_Release(tmp);
229 }else {
230 ERR("RemoveChild failed: %08x\n", nsres);
231 break;
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);
240 return E_FAIL;
243 nsres = nsIDOMHTMLOptionElement_AppendChild(This->nsoption, (nsIDOMNode*)text_node, &tmp);
244 if(NS_SUCCEEDED(nsres))
245 nsIDOMNode_Release(tmp);
246 else
247 ERR("AppendChild failed: %08x\n", nsres);
249 return S_OK;
252 static HRESULT WINAPI HTMLOptionElement_get_text(IHTMLOptionElement *iface, BSTR *p)
254 HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
255 nsAString text_str;
256 const PRUnichar *text;
257 nsresult nsres;
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);
266 }else {
267 ERR("GetText failed: %08x\n", nsres);
268 *p = NULL;
270 nsAString_Finish(&text_str);
272 return S_OK;
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);
279 return E_NOTIMPL;
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);
312 *ppv = NULL;
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;
325 if(*ppv) {
326 IUnknown_AddRef((IUnknown*)*ppv);
327 return S_OK;
330 return HTMLElement_QI(&This->element.node, riid, ppv);
333 static void HTMLOptionElement_destructor(HTMLDOMNode *iface)
335 HTMLOptionElement *This = impl_from_HTMLDOMNode(iface);
337 if(This->nsoption)
338 nsIDOMHTMLOptionElement_Release(This->nsoption);
340 HTMLElement_destructor(&This->element.node);
343 static const NodeImplVtbl HTMLOptionElementImplVtbl = {
344 HTMLOptionElement_QI,
345 HTMLOptionElement_destructor,
346 HTMLElement_clone
349 static const tid_t HTMLOptionElement_iface_tids[] = {
350 HTMLELEMENT_TIDS,
351 IHTMLOptionElement_tid,
354 static dispex_static_data_t HTMLOptionElement_dispex = {
355 NULL,
356 DispHTMLOptionElement_tid,
357 NULL,
358 HTMLOptionElement_iface_tids
361 HRESULT HTMLOptionElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
363 HTMLOptionElement *ret;
364 nsresult nsres;
366 ret = heap_alloc_zero(sizeof(HTMLOptionElement));
367 if(!ret)
368 return E_OUTOFMEMORY;
370 ret->IHTMLOptionElement_iface.lpVtbl = &HTMLOptionElementVtbl;
371 ret->element.node.vtbl = &HTMLOptionElementImplVtbl;
373 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLOptionElement, (void**)&ret->nsoption);
374 if(NS_FAILED(nsres)) {
375 ERR("Could not get nsIDOMHTMLOptionElement interface: %08x\n", nsres);
376 heap_free(ret);
377 return E_FAIL;
380 HTMLElement_Init(&ret->element, doc, nselem, &HTMLOptionElement_dispex);
382 *elem = &ret->element;
383 return S_OK;
386 static inline HTMLOptionElementFactory *impl_from_IHTMLOptionElementFactory(IHTMLOptionElementFactory *iface)
388 return CONTAINING_RECORD(iface, HTMLOptionElementFactory, IHTMLOptionElementFactory_iface);
391 static HRESULT WINAPI HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory *iface,
392 REFIID riid, void **ppv)
394 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
396 *ppv = NULL;
398 if(IsEqualGUID(&IID_IUnknown, riid)) {
399 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
400 *ppv = &This->IHTMLOptionElementFactory_iface;
401 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
402 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
403 *ppv = &This->IHTMLOptionElementFactory_iface;
404 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory, riid)) {
405 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This, ppv);
406 *ppv = &This->IHTMLOptionElementFactory_iface;
409 if(*ppv) {
410 IUnknown_AddRef((IUnknown*)*ppv);
411 return S_OK;
414 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
415 return E_NOINTERFACE;
418 static ULONG WINAPI HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory *iface)
420 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
421 LONG ref = InterlockedIncrement(&This->ref);
423 TRACE("(%p) ref=%d\n", This, ref);
425 return ref;
428 static ULONG WINAPI HTMLOptionElementFactory_Release(IHTMLOptionElementFactory *iface)
430 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
431 LONG ref = InterlockedDecrement(&This->ref);
433 TRACE("(%p) ref=%d\n", This, ref);
435 if(!ref)
436 heap_free(This);
438 return ref;
441 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory *iface, UINT *pctinfo)
443 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
444 FIXME("(%p)->(%p)\n", This, pctinfo);
445 return E_NOTIMPL;
448 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory *iface, UINT iTInfo,
449 LCID lcid, ITypeInfo **ppTInfo)
451 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
452 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
453 return E_NOTIMPL;
456 static HRESULT WINAPI HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory *iface, REFIID riid,
457 LPOLESTR *rgszNames, UINT cNames,
458 LCID lcid, DISPID *rgDispId)
460 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
461 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
462 lcid, rgDispId);
463 return E_NOTIMPL;
466 static HRESULT WINAPI HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory *iface, DISPID dispIdMember,
467 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
468 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
470 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
471 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
472 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
473 return E_NOTIMPL;
476 static HRESULT WINAPI HTMLOptionElementFactory_create(IHTMLOptionElementFactory *iface,
477 VARIANT text, VARIANT value, VARIANT defaultselected, VARIANT selected,
478 IHTMLOptionElement **optelem)
480 HTMLOptionElementFactory *This = impl_from_IHTMLOptionElementFactory(iface);
481 nsIDOMHTMLElement *nselem;
482 HTMLDOMNode *node;
483 HRESULT hres;
485 static const PRUnichar optionW[] = {'O','P','T','I','O','N',0};
487 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_variant(&text), debugstr_variant(&value),
488 debugstr_variant(&defaultselected), debugstr_variant(&selected), optelem);
490 if(!This->window || !This->window->doc) {
491 WARN("NULL doc\n");
492 return E_UNEXPECTED;
495 *optelem = NULL;
497 hres = create_nselem(This->window->doc, optionW, &nselem);
498 if(FAILED(hres))
499 return hres;
501 hres = get_node(This->window->doc, (nsIDOMNode*)nselem, TRUE, &node);
502 nsIDOMHTMLElement_Release(nselem);
503 if(FAILED(hres))
504 return hres;
506 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface,
507 &IID_IHTMLOptionElement, (void**)optelem);
509 if(V_VT(&text) == VT_BSTR)
510 IHTMLOptionElement_put_text(*optelem, V_BSTR(&text));
511 else if(V_VT(&text) != VT_EMPTY)
512 FIXME("Unsupported text vt=%d\n", V_VT(&text));
514 if(V_VT(&value) == VT_BSTR)
515 IHTMLOptionElement_put_value(*optelem, V_BSTR(&value));
516 else if(V_VT(&value) != VT_EMPTY)
517 FIXME("Unsupported value vt=%d\n", V_VT(&value));
519 if(V_VT(&defaultselected) != VT_EMPTY)
520 FIXME("Unsupported defaultselected vt=%d\n", V_VT(&defaultselected));
521 if(V_VT(&selected) != VT_EMPTY)
522 FIXME("Unsupported selected vt=%d\n", V_VT(&selected));
524 return S_OK;
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->IHTMLOptionElementFactory_iface.lpVtbl = &HTMLOptionElementFactoryVtbl;
545 ret->ref = 1;
546 ret->window = window;
548 return ret;