wshom.ocx: Implement IWshCollection::Item() for Desktop folder case.
[wine/multimedia.git] / dlls / mshtml / htmloption.c
blob533a914901f620d38a721b8368537cd5bcfcbdb5
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,
347 HTMLElement_get_attr_col
350 static const tid_t HTMLOptionElement_iface_tids[] = {
351 HTMLELEMENT_TIDS,
352 IHTMLOptionElement_tid,
355 static dispex_static_data_t HTMLOptionElement_dispex = {
356 NULL,
357 DispHTMLOptionElement_tid,
358 NULL,
359 HTMLOptionElement_iface_tids
362 HRESULT HTMLOptionElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
364 HTMLOptionElement *ret;
365 nsresult nsres;
367 ret = heap_alloc_zero(sizeof(HTMLOptionElement));
368 if(!ret)
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);
377 heap_free(ret);
378 return E_FAIL;
381 HTMLElement_Init(&ret->element, doc, nselem, &HTMLOptionElement_dispex);
383 *elem = &ret->element;
384 return S_OK;
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);
397 *ppv = NULL;
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;
410 if(*ppv) {
411 IUnknown_AddRef((IUnknown*)*ppv);
412 return S_OK;
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);
426 return 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);
436 if(!ref)
437 heap_free(This);
439 return 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);
446 return E_NOTIMPL;
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);
454 return E_NOTIMPL;
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,
463 lcid, rgDispId);
464 return E_NOTIMPL;
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);
474 return E_NOTIMPL;
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;
483 HTMLDOMNode *node;
484 HRESULT hres;
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) {
492 WARN("NULL doc\n");
493 return E_UNEXPECTED;
496 *optelem = NULL;
498 hres = create_nselem(This->window->doc, optionW, &nselem);
499 if(FAILED(hres))
500 return hres;
502 hres = get_node(This->window->doc, (nsIDOMNode*)nselem, TRUE, &node);
503 nsIDOMHTMLElement_Release(nselem);
504 if(FAILED(hres))
505 return hres;
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));
525 return S_OK;
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;
546 ret->ref = 1;
547 ret->window = window;
549 return ret;