push 88671f85dcf7a7cd89c63d6e9f34ad6b6ad2ae64
[wine/hacks.git] / dlls / mshtml / htmloption.c
blob0c849892277668d2d801596fbe5cebc8dd2ac52f
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 "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 typedef struct {
39 HTMLElement element;
41 const IHTMLOptionElementVtbl *lpHTMLOptionElementVtbl;
43 nsIDOMHTMLOptionElement *nsoption;
44 } HTMLOptionElement;
46 #define HTMLOPTION(x) ((IHTMLOptionElement*) &(x)->lpHTMLOptionElementVtbl)
48 #define HTMLOPTION_THIS(iface) DEFINE_THIS(HTMLOptionElement, HTMLOptionElement, iface)
50 static HRESULT WINAPI HTMLOptionElement_QueryInterface(IHTMLOptionElement *iface,
51 REFIID riid, void **ppv)
53 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
55 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
58 static ULONG WINAPI HTMLOptionElement_AddRef(IHTMLOptionElement *iface)
60 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
62 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
65 static ULONG WINAPI HTMLOptionElement_Release(IHTMLOptionElement *iface)
67 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
69 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
72 static HRESULT WINAPI HTMLOptionElement_GetTypeInfoCount(IHTMLOptionElement *iface, UINT *pctinfo)
74 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
75 FIXME("(%p)->(%p)\n", This, pctinfo);
76 return E_NOTIMPL;
79 static HRESULT WINAPI HTMLOptionElement_GetTypeInfo(IHTMLOptionElement *iface, UINT iTInfo,
80 LCID lcid, ITypeInfo **ppTInfo)
82 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
83 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
84 return E_NOTIMPL;
87 static HRESULT WINAPI HTMLOptionElement_GetIDsOfNames(IHTMLOptionElement *iface, REFIID riid,
88 LPOLESTR *rgszNames, UINT cNames,
89 LCID lcid, DISPID *rgDispId)
91 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
92 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
93 lcid, rgDispId);
94 return E_NOTIMPL;
97 static HRESULT WINAPI HTMLOptionElement_Invoke(IHTMLOptionElement *iface, DISPID dispIdMember,
98 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
99 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
101 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
102 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
103 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
104 return E_NOTIMPL;
107 static HRESULT WINAPI HTMLOptionElement_put_selected(IHTMLOptionElement *iface, VARIANT_BOOL v)
109 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
110 FIXME("(%p)->(%x)\n", This, v);
111 return E_NOTIMPL;
114 static HRESULT WINAPI HTMLOptionElement_get_selected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
116 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
117 FIXME("(%p)->(%p)\n", This, p);
118 return E_NOTIMPL;
121 static HRESULT WINAPI HTMLOptionElement_put_value(IHTMLOptionElement *iface, BSTR v)
123 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
124 nsAString value_str;
125 nsresult nsres;
127 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
129 nsAString_Init(&value_str, v);
130 nsres = nsIDOMHTMLOptionElement_SetValue(This->nsoption, &value_str);
131 nsAString_Finish(&value_str);
132 if(NS_FAILED(nsres))
133 ERR("SetValue failed: %08x\n", nsres);
135 return S_OK;
138 static HRESULT WINAPI HTMLOptionElement_get_value(IHTMLOptionElement *iface, BSTR *p)
140 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
141 nsAString value_str;
142 const PRUnichar *value;
143 nsresult nsres;
145 TRACE("(%p)->(%p)\n", This, p);
147 nsAString_Init(&value_str, NULL);
148 nsres = nsIDOMHTMLOptionElement_GetValue(This->nsoption, &value_str);
149 if(NS_SUCCEEDED(nsres)) {
150 nsAString_GetData(&value_str, &value);
151 *p = SysAllocString(value);
152 }else {
153 ERR("GetValue failed: %08x\n", nsres);
154 *p = NULL;
156 nsAString_Finish(&value_str);
158 return S_OK;
161 static HRESULT WINAPI HTMLOptionElement_put_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL v)
163 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
164 FIXME("(%p)->(%x)\n", This, v);
165 return E_NOTIMPL;
168 static HRESULT WINAPI HTMLOptionElement_get_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
170 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
171 FIXME("(%p)->(%p)\n", This, p);
172 return E_NOTIMPL;
175 static HRESULT WINAPI HTMLOptionElement_put_index(IHTMLOptionElement *iface, LONG v)
177 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
178 FIXME("(%p)->(%d)\n", This, v);
179 return E_NOTIMPL;
182 static HRESULT WINAPI HTMLOptionElement_get_index(IHTMLOptionElement *iface, LONG *p)
184 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
185 FIXME("(%p)->(%p)\n", This, p);
186 return E_NOTIMPL;
189 static HRESULT WINAPI HTMLOptionElement_put_text(IHTMLOptionElement *iface, BSTR v)
191 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
192 nsIDOMDocument *nsdoc;
193 nsIDOMText *text_node;
194 nsAString text_str;
195 nsIDOMNode *tmp;
196 nsresult nsres;
198 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
200 while(1) {
201 nsIDOMNode *child;
203 nsres = nsIDOMHTMLOptionElement_GetFirstChild(This->nsoption, &child);
204 if(NS_FAILED(nsres) || !child)
205 break;
207 nsres = nsIDOMHTMLOptionElement_RemoveChild(This->nsoption, child, &tmp);
208 nsIDOMNode_Release(child);
209 if(NS_SUCCEEDED(nsres)) {
210 nsIDOMNode_Release(tmp);
211 }else {
212 ERR("RemoveChild failed: %08x\n", nsres);
213 break;
217 nsres = nsIWebNavigation_GetDocument(This->element.node.doc->nscontainer->navigation, &nsdoc);
218 if(NS_FAILED(nsres)) {
219 ERR("GetDocument failed: %08x\n", nsres);
220 return S_OK;
223 nsAString_Init(&text_str, v);
224 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &text_str, &text_node);
225 nsIDOMDocument_Release(nsdoc);
226 nsAString_Finish(&text_str);
227 if(NS_FAILED(nsres)) {
228 ERR("CreateTextNode failed: %08x\n", nsres);
229 return S_OK;
232 nsres = nsIDOMHTMLOptionElement_AppendChild(This->nsoption, (nsIDOMNode*)text_node, &tmp);
233 if(NS_SUCCEEDED(nsres))
234 nsIDOMNode_Release(tmp);
235 else
236 ERR("AppendChild failed: %08x\n", nsres);
238 return S_OK;
241 static HRESULT WINAPI HTMLOptionElement_get_text(IHTMLOptionElement *iface, BSTR *p)
243 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
244 nsAString text_str;
245 const PRUnichar *text;
246 nsresult nsres;
248 TRACE("(%p)->(%p)\n", This, p);
250 nsAString_Init(&text_str, NULL);
251 nsres = nsIDOMHTMLOptionElement_GetText(This->nsoption, &text_str);
252 if(NS_SUCCEEDED(nsres)) {
253 nsAString_GetData(&text_str, &text);
254 *p = SysAllocString(text);
255 }else {
256 ERR("GetText failed: %08x\n", nsres);
257 *p = NULL;
259 nsAString_Finish(&text_str);
261 return S_OK;
264 static HRESULT WINAPI HTMLOptionElement_get_form(IHTMLOptionElement *iface, IHTMLFormElement **p)
266 HTMLOptionElement *This = HTMLOPTION_THIS(iface);
267 FIXME("(%p)->(%p)\n", This, p);
268 return E_NOTIMPL;
271 #undef HTMLOPTION_THIS
273 static const IHTMLOptionElementVtbl HTMLOptionElementVtbl = {
274 HTMLOptionElement_QueryInterface,
275 HTMLOptionElement_AddRef,
276 HTMLOptionElement_Release,
277 HTMLOptionElement_GetTypeInfoCount,
278 HTMLOptionElement_GetTypeInfo,
279 HTMLOptionElement_GetIDsOfNames,
280 HTMLOptionElement_Invoke,
281 HTMLOptionElement_put_selected,
282 HTMLOptionElement_get_selected,
283 HTMLOptionElement_put_value,
284 HTMLOptionElement_get_value,
285 HTMLOptionElement_put_defaultSelected,
286 HTMLOptionElement_get_defaultSelected,
287 HTMLOptionElement_put_index,
288 HTMLOptionElement_get_index,
289 HTMLOptionElement_put_text,
290 HTMLOptionElement_get_text,
291 HTMLOptionElement_get_form
294 #define HTMLOPTION_NODE_THIS(iface) DEFINE_THIS2(HTMLOptionElement, element.node, iface)
296 static HRESULT HTMLOptionElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
298 HTMLOptionElement *This = HTMLOPTION_NODE_THIS(iface);
300 *ppv = NULL;
302 if(IsEqualGUID(&IID_IUnknown, riid)) {
303 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
304 *ppv = HTMLOPTION(This);
305 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
306 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
307 *ppv = HTMLOPTION(This);
308 }else if(IsEqualGUID(&IID_IHTMLOptionElement, riid)) {
309 TRACE("(%p)->(IID_IHTMLOptionElement %p)\n", This, ppv);
310 *ppv = HTMLOPTION(This);
313 if(*ppv) {
314 IUnknown_AddRef((IUnknown*)*ppv);
315 return S_OK;
318 return HTMLElement_QI(&This->element.node, riid, ppv);
321 static void HTMLOptionElement_destructor(HTMLDOMNode *iface)
323 HTMLOptionElement *This = HTMLOPTION_NODE_THIS(iface);
325 if(This->nsoption)
326 nsIDOMHTMLOptionElement_Release(This->nsoption);
328 HTMLElement_destructor(&This->element.node);
331 #undef HTMLOPTION_NODE_THIS
333 static const NodeImplVtbl HTMLOptionElementImplVtbl = {
334 HTMLOptionElement_QI,
335 HTMLOptionElement_destructor
338 HTMLElement *HTMLOptionElement_Create(nsIDOMHTMLElement *nselem)
340 HTMLOptionElement *ret = heap_alloc(sizeof(HTMLOptionElement));
341 nsresult nsres;
343 HTMLElement_Init(&ret->element);
345 ret->lpHTMLOptionElementVtbl = &HTMLOptionElementVtbl;
346 ret->element.node.vtbl = &HTMLOptionElementImplVtbl;
348 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLOptionElement, (void**)&ret->nsoption);
349 if(NS_FAILED(nsres))
350 ERR("Could not get nsIDOMHTMLOptionElement interface: %08x\n", nsres);
352 return &ret->element;
355 #define HTMLOPTFACTORY_THIS(iface) DEFINE_THIS(HTMLOptionElementFactory, HTMLOptionElementFactory, iface)
357 static HRESULT WINAPI HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory *iface,
358 REFIID riid, void **ppv)
360 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
362 *ppv = NULL;
364 if(IsEqualGUID(&IID_IUnknown, riid)) {
365 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
366 *ppv = HTMLOPTFACTORY(This);
367 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
368 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
369 *ppv = HTMLOPTFACTORY(This);
370 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory, riid)) {
371 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This, ppv);
372 *ppv = HTMLOPTFACTORY(This);
375 if(*ppv) {
376 IUnknown_AddRef((IUnknown*)*ppv);
377 return S_OK;
380 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
381 return E_NOINTERFACE;
384 static ULONG WINAPI HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory *iface)
386 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
387 LONG ref = InterlockedIncrement(&This->ref);
389 TRACE("(%p) ref=%d\n", This, ref);
391 return ref;
394 static ULONG WINAPI HTMLOptionElementFactory_Release(IHTMLOptionElementFactory *iface)
396 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
397 LONG ref = InterlockedDecrement(&This->ref);
399 TRACE("(%p) ref=%d\n", This, ref);
401 if(!ref)
402 heap_free(This);
404 return ref;
407 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory *iface, UINT *pctinfo)
409 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
410 FIXME("(%p)->(%p)\n", This, pctinfo);
411 return E_NOTIMPL;
414 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory *iface, UINT iTInfo,
415 LCID lcid, ITypeInfo **ppTInfo)
417 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
418 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
419 return E_NOTIMPL;
422 static HRESULT WINAPI HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory *iface, REFIID riid,
423 LPOLESTR *rgszNames, UINT cNames,
424 LCID lcid, DISPID *rgDispId)
426 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
427 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
428 lcid, rgDispId);
429 return E_NOTIMPL;
432 static HRESULT WINAPI HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory *iface, DISPID dispIdMember,
433 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
434 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
436 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
437 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
438 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
439 return E_NOTIMPL;
442 static HRESULT WINAPI HTMLOptionElementFactory_create(IHTMLOptionElementFactory *iface,
443 VARIANT text, VARIANT value, VARIANT defaultselected, VARIANT selected,
444 IHTMLOptionElement **optelem)
446 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
447 nsIDOMDocument *nsdoc;
448 nsIDOMElement *nselem;
449 nsAString option_str;
450 nsresult nsres;
451 HRESULT hres;
453 static const PRUnichar optionW[] = {'O','P','T','I','O','N',0};
455 TRACE("(%p)->(v v v v %p)\n", This, optelem);
457 *optelem = NULL;
458 if(!This->doc->nscontainer)
459 return E_FAIL;
461 nsres = nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc);
462 if(NS_FAILED(nsres)) {
463 ERR("GetDocument failed: %08x\n", nsres);
464 return E_FAIL;
467 nsAString_Init(&option_str, optionW);
468 nsres = nsIDOMDocument_CreateElement(nsdoc, &option_str, &nselem);
469 nsIDOMDocument_Release(nsdoc);
470 nsAString_Finish(&option_str);
471 if(NS_FAILED(nsres)) {
472 ERR("CreateElement failed: %08x\n", nsres);
473 return E_FAIL;
476 hres = IHTMLDOMNode_QueryInterface(HTMLDOMNODE(get_node(This->doc, (nsIDOMNode*)nselem)),
477 &IID_IHTMLOptionElement, (void**)optelem);
478 nsIDOMElement_Release(nselem);
480 if(V_VT(&text) == VT_BSTR)
481 IHTMLOptionElement_put_text(*optelem, V_BSTR(&text));
482 else if(V_VT(&text) != VT_EMPTY)
483 FIXME("Unsupported text vt=%d\n", V_VT(&text));
485 if(V_VT(&value) == VT_BSTR)
486 IHTMLOptionElement_put_value(*optelem, V_BSTR(&value));
487 else if(V_VT(&value) != VT_EMPTY)
488 FIXME("Unsupported value vt=%d\n", V_VT(&value));
490 if(V_VT(&defaultselected) != VT_EMPTY)
491 FIXME("Unsupported defaultselected vt=%d\n", V_VT(&defaultselected));
492 if(V_VT(&selected) != VT_EMPTY)
493 FIXME("Unsupported selected vt=%d\n", V_VT(&selected));
495 return S_OK;
498 #undef HTMLOPTFACTORY_THIS
500 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl = {
501 HTMLOptionElementFactory_QueryInterface,
502 HTMLOptionElementFactory_AddRef,
503 HTMLOptionElementFactory_Release,
504 HTMLOptionElementFactory_GetTypeInfoCount,
505 HTMLOptionElementFactory_GetTypeInfo,
506 HTMLOptionElementFactory_GetIDsOfNames,
507 HTMLOptionElementFactory_Invoke,
508 HTMLOptionElementFactory_create
511 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLDocument *doc)
513 HTMLOptionElementFactory *ret;
515 ret = heap_alloc(sizeof(HTMLOptionElementFactory));
517 ret->lpHTMLOptionElementFactoryVtbl = &HTMLOptionElementFactoryVtbl;
518 ret->ref = 1;
519 ret->doc = doc;
521 return ret;