kernel32: Avoid returning the same name when GetTempFileName is called twice in a...
[wine/multimedia.git] / dlls / mshtml / htmloption.c
blobb8166341bd40d4115bad037e430eb62cd95b19cd
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 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(HTMLDOMNODE(&This->element.node), riid, ppv);
54 static ULONG WINAPI HTMLOptionElement_AddRef(IHTMLOptionElement *iface)
56 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
58 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
61 static ULONG WINAPI HTMLOptionElement_Release(IHTMLOptionElement *iface)
63 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
65 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
68 static HRESULT WINAPI HTMLOptionElement_GetTypeInfoCount(IHTMLOptionElement *iface, UINT *pctinfo)
70 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
71 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), 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(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
81 static HRESULT WINAPI HTMLOptionElement_GetIDsOfNames(IHTMLOptionElement *iface, REFIID riid,
82 LPOLESTR *rgszNames, UINT cNames,
83 LCID lcid, DISPID *rgDispId)
85 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
86 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
89 static HRESULT WINAPI HTMLOptionElement_Invoke(IHTMLOptionElement *iface, DISPID dispIdMember,
90 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
91 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
93 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
94 return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
95 pVarResult, pExcepInfo, puArgErr);
98 static HRESULT WINAPI HTMLOptionElement_put_selected(IHTMLOptionElement *iface, VARIANT_BOOL v)
100 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
101 nsresult nsres;
103 TRACE("(%p)->(%x)\n", This, v);
105 nsres = nsIDOMHTMLOptionElement_SetSelected(This->nsoption, v != VARIANT_FALSE);
106 if(NS_FAILED(nsres)) {
107 ERR("SetSelected failed: %08x\n", nsres);
108 return E_FAIL;
111 return S_OK;
114 static HRESULT WINAPI HTMLOptionElement_get_selected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
116 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
117 PRBool selected;
118 nsresult nsres;
120 TRACE("(%p)->(%p)\n", This, p);
122 nsres = nsIDOMHTMLOptionElement_GetSelected(This->nsoption, &selected);
123 if(NS_FAILED(nsres)) {
124 ERR("GetSelected failed: %08x\n", nsres);
125 return E_FAIL;
128 *p = selected ? VARIANT_TRUE : VARIANT_FALSE;
129 return S_OK;
132 static HRESULT WINAPI HTMLOptionElement_put_value(IHTMLOptionElement *iface, BSTR v)
134 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
135 nsAString value_str;
136 nsresult nsres;
138 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
140 nsAString_InitDepend(&value_str, v);
141 nsres = nsIDOMHTMLOptionElement_SetValue(This->nsoption, &value_str);
142 nsAString_Finish(&value_str);
143 if(NS_FAILED(nsres))
144 ERR("SetValue failed: %08x\n", nsres);
146 return S_OK;
149 static HRESULT WINAPI HTMLOptionElement_get_value(IHTMLOptionElement *iface, BSTR *p)
151 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
152 nsAString value_str;
153 const PRUnichar *value;
154 nsresult nsres;
156 TRACE("(%p)->(%p)\n", This, p);
158 nsAString_Init(&value_str, NULL);
159 nsres = nsIDOMHTMLOptionElement_GetValue(This->nsoption, &value_str);
160 if(NS_SUCCEEDED(nsres)) {
161 nsAString_GetData(&value_str, &value);
162 *p = SysAllocString(value);
163 }else {
164 ERR("GetValue failed: %08x\n", nsres);
165 *p = NULL;
167 nsAString_Finish(&value_str);
169 return S_OK;
172 static HRESULT WINAPI HTMLOptionElement_put_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL v)
174 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
175 FIXME("(%p)->(%x)\n", This, v);
176 return E_NOTIMPL;
179 static HRESULT WINAPI HTMLOptionElement_get_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
181 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
182 FIXME("(%p)->(%p)\n", This, p);
183 return E_NOTIMPL;
186 static HRESULT WINAPI HTMLOptionElement_put_index(IHTMLOptionElement *iface, LONG v)
188 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
189 FIXME("(%p)->(%d)\n", This, v);
190 return E_NOTIMPL;
193 static HRESULT WINAPI HTMLOptionElement_get_index(IHTMLOptionElement *iface, LONG *p)
195 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
196 FIXME("(%p)->(%p)\n", This, p);
197 return E_NOTIMPL;
200 static HRESULT WINAPI HTMLOptionElement_put_text(IHTMLOptionElement *iface, BSTR v)
202 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
203 nsIDOMText *text_node;
204 nsAString text_str;
205 nsIDOMNode *tmp;
206 nsresult nsres;
208 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
210 if(!This->element.node.doc->nsdoc) {
211 WARN("NULL nsdoc\n");
212 return E_UNEXPECTED;
215 while(1) {
216 nsIDOMNode *child;
218 nsres = nsIDOMHTMLOptionElement_GetFirstChild(This->nsoption, &child);
219 if(NS_FAILED(nsres) || !child)
220 break;
222 nsres = nsIDOMHTMLOptionElement_RemoveChild(This->nsoption, child, &tmp);
223 nsIDOMNode_Release(child);
224 if(NS_SUCCEEDED(nsres)) {
225 nsIDOMNode_Release(tmp);
226 }else {
227 ERR("RemoveChild failed: %08x\n", nsres);
228 break;
232 nsAString_InitDepend(&text_str, v);
233 nsres = nsIDOMHTMLDocument_CreateTextNode(This->element.node.doc->nsdoc, &text_str, &text_node);
234 nsAString_Finish(&text_str);
235 if(NS_FAILED(nsres)) {
236 ERR("CreateTextNode failed: %08x\n", nsres);
237 return E_FAIL;
240 nsres = nsIDOMHTMLOptionElement_AppendChild(This->nsoption, (nsIDOMNode*)text_node, &tmp);
241 if(NS_SUCCEEDED(nsres))
242 nsIDOMNode_Release(tmp);
243 else
244 ERR("AppendChild failed: %08x\n", nsres);
246 return S_OK;
249 static HRESULT WINAPI HTMLOptionElement_get_text(IHTMLOptionElement *iface, BSTR *p)
251 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
252 nsAString text_str;
253 const PRUnichar *text;
254 nsresult nsres;
256 TRACE("(%p)->(%p)\n", This, p);
258 nsAString_Init(&text_str, NULL);
259 nsres = nsIDOMHTMLOptionElement_GetText(This->nsoption, &text_str);
260 if(NS_SUCCEEDED(nsres)) {
261 nsAString_GetData(&text_str, &text);
262 *p = SysAllocString(text);
263 }else {
264 ERR("GetText failed: %08x\n", nsres);
265 *p = NULL;
267 nsAString_Finish(&text_str);
269 return S_OK;
272 static HRESULT WINAPI HTMLOptionElement_get_form(IHTMLOptionElement *iface, IHTMLFormElement **p)
274 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
275 FIXME("(%p)->(%p)\n", This, p);
276 return E_NOTIMPL;
279 #undef HTMLOPTION_THIS
281 static const IHTMLOptionElementVtbl HTMLOptionElementVtbl = {
282 HTMLOptionElement_QueryInterface,
283 HTMLOptionElement_AddRef,
284 HTMLOptionElement_Release,
285 HTMLOptionElement_GetTypeInfoCount,
286 HTMLOptionElement_GetTypeInfo,
287 HTMLOptionElement_GetIDsOfNames,
288 HTMLOptionElement_Invoke,
289 HTMLOptionElement_put_selected,
290 HTMLOptionElement_get_selected,
291 HTMLOptionElement_put_value,
292 HTMLOptionElement_get_value,
293 HTMLOptionElement_put_defaultSelected,
294 HTMLOptionElement_get_defaultSelected,
295 HTMLOptionElement_put_index,
296 HTMLOptionElement_get_index,
297 HTMLOptionElement_put_text,
298 HTMLOptionElement_get_text,
299 HTMLOptionElement_get_form
302 #define HTMLOPTION_NODE_THIS(iface) DEFINE_THIS2(HTMLOptionElement, element.node, iface)
304 static HRESULT HTMLOptionElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
306 HTMLOptionElement *This = HTMLOPTION_NODE_THIS(iface);
308 *ppv = NULL;
310 if(IsEqualGUID(&IID_IUnknown, riid)) {
311 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
312 *ppv = HTMLOPTION(This);
313 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
314 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
315 *ppv = HTMLOPTION(This);
316 }else if(IsEqualGUID(&IID_IHTMLOptionElement, riid)) {
317 TRACE("(%p)->(IID_IHTMLOptionElement %p)\n", This, ppv);
318 *ppv = HTMLOPTION(This);
321 if(*ppv) {
322 IUnknown_AddRef((IUnknown*)*ppv);
323 return S_OK;
326 return HTMLElement_QI(&This->element.node, riid, ppv);
329 static void HTMLOptionElement_destructor(HTMLDOMNode *iface)
331 HTMLOptionElement *This = HTMLOPTION_NODE_THIS(iface);
333 if(This->nsoption)
334 nsIDOMHTMLOptionElement_Release(This->nsoption);
336 HTMLElement_destructor(&This->element.node);
339 #undef HTMLOPTION_NODE_THIS
341 static const NodeImplVtbl HTMLOptionElementImplVtbl = {
342 HTMLOptionElement_QI,
343 HTMLOptionElement_destructor
346 static const tid_t HTMLOptionElement_iface_tids[] = {
347 HTMLELEMENT_TIDS,
348 IHTMLOptionElement_tid,
351 static dispex_static_data_t HTMLOptionElement_dispex = {
352 NULL,
353 DispHTMLOptionElement_tid,
354 NULL,
355 HTMLOptionElement_iface_tids
358 HTMLElement *HTMLOptionElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
360 HTMLOptionElement *ret = heap_alloc_zero(sizeof(HTMLOptionElement));
361 nsresult nsres;
363 ret->lpHTMLOptionElementVtbl = &HTMLOptionElementVtbl;
364 ret->element.node.vtbl = &HTMLOptionElementImplVtbl;
366 HTMLElement_Init(&ret->element, doc, nselem, &HTMLOptionElement_dispex);
368 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLOptionElement, (void**)&ret->nsoption);
369 if(NS_FAILED(nsres))
370 ERR("Could not get nsIDOMHTMLOptionElement interface: %08x\n", nsres);
372 return &ret->element;
375 #define HTMLOPTFACTORY_THIS(iface) DEFINE_THIS(HTMLOptionElementFactory, HTMLOptionElementFactory, iface)
377 static HRESULT WINAPI HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory *iface,
378 REFIID riid, void **ppv)
380 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
382 *ppv = NULL;
384 if(IsEqualGUID(&IID_IUnknown, riid)) {
385 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
386 *ppv = HTMLOPTFACTORY(This);
387 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
388 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
389 *ppv = HTMLOPTFACTORY(This);
390 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory, riid)) {
391 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This, ppv);
392 *ppv = HTMLOPTFACTORY(This);
395 if(*ppv) {
396 IUnknown_AddRef((IUnknown*)*ppv);
397 return S_OK;
400 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
401 return E_NOINTERFACE;
404 static ULONG WINAPI HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory *iface)
406 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
407 LONG ref = InterlockedIncrement(&This->ref);
409 TRACE("(%p) ref=%d\n", This, ref);
411 return ref;
414 static ULONG WINAPI HTMLOptionElementFactory_Release(IHTMLOptionElementFactory *iface)
416 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
417 LONG ref = InterlockedDecrement(&This->ref);
419 TRACE("(%p) ref=%d\n", This, ref);
421 if(!ref)
422 heap_free(This);
424 return ref;
427 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory *iface, UINT *pctinfo)
429 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
430 FIXME("(%p)->(%p)\n", This, pctinfo);
431 return E_NOTIMPL;
434 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory *iface, UINT iTInfo,
435 LCID lcid, ITypeInfo **ppTInfo)
437 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
438 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
439 return E_NOTIMPL;
442 static HRESULT WINAPI HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory *iface, REFIID riid,
443 LPOLESTR *rgszNames, UINT cNames,
444 LCID lcid, DISPID *rgDispId)
446 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
447 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
448 lcid, rgDispId);
449 return E_NOTIMPL;
452 static HRESULT WINAPI HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory *iface, DISPID dispIdMember,
453 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
454 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
456 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
457 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
458 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
459 return E_NOTIMPL;
462 static HRESULT WINAPI HTMLOptionElementFactory_create(IHTMLOptionElementFactory *iface,
463 VARIANT text, VARIANT value, VARIANT defaultselected, VARIANT selected,
464 IHTMLOptionElement **optelem)
466 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
467 nsIDOMHTMLElement *nselem;
468 HRESULT hres;
470 static const PRUnichar optionW[] = {'O','P','T','I','O','N',0};
472 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_variant(&text), debugstr_variant(&value),
473 debugstr_variant(&defaultselected), debugstr_variant(&selected), optelem);
475 if(!This->window || !This->window->doc) {
476 WARN("NULL doc\n");
477 return E_UNEXPECTED;
480 *optelem = NULL;
482 hres = create_nselem(This->window->doc, optionW, &nselem);
483 if(FAILED(hres))
484 return hres;
486 hres = IHTMLDOMNode_QueryInterface(HTMLDOMNODE(get_node(This->window->doc, (nsIDOMNode*)nselem, TRUE)),
487 &IID_IHTMLOptionElement, (void**)optelem);
488 nsIDOMHTMLElement_Release(nselem);
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 vt=%d\n", V_VT(&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 vt=%d\n", V_VT(&value));
500 if(V_VT(&defaultselected) != VT_EMPTY)
501 FIXME("Unsupported defaultselected vt=%d\n", V_VT(&defaultselected));
502 if(V_VT(&selected) != VT_EMPTY)
503 FIXME("Unsupported selected vt=%d\n", V_VT(&selected));
505 return S_OK;
508 #undef HTMLOPTFACTORY_THIS
510 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl = {
511 HTMLOptionElementFactory_QueryInterface,
512 HTMLOptionElementFactory_AddRef,
513 HTMLOptionElementFactory_Release,
514 HTMLOptionElementFactory_GetTypeInfoCount,
515 HTMLOptionElementFactory_GetTypeInfo,
516 HTMLOptionElementFactory_GetIDsOfNames,
517 HTMLOptionElementFactory_Invoke,
518 HTMLOptionElementFactory_create
521 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow *window)
523 HTMLOptionElementFactory *ret;
525 ret = heap_alloc(sizeof(HTMLOptionElementFactory));
527 ret->lpHTMLOptionElementFactoryVtbl = &HTMLOptionElementFactoryVtbl;
528 ret->ref = 1;
529 ret->window = window;
531 return ret;