push b79aff4f9e064e6702329573e5ebb8548e254b61
[wine/hacks.git] / dlls / mshtml / htmloption.c
blobf800fed68e9316bb5be9ff7cd78a079dfc9afa6f
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, NULL);
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, NULL);
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 = mshtml_alloc(sizeof(HTMLOptionElement));
341 nsresult nsres;
343 ret->lpHTMLOptionElementVtbl = &HTMLOptionElementVtbl;
344 ret->element.node.vtbl = &HTMLOptionElementImplVtbl;
346 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLOptionElement, (void**)&ret->nsoption);
347 if(NS_FAILED(nsres))
348 ERR("Could not get nsIDOMHTMLOptionElement interface: %08x\n", nsres);
350 return &ret->element;
353 #define HTMLOPTFACTORY_THIS(iface) DEFINE_THIS(HTMLOptionElementFactory, HTMLOptionElementFactory, iface)
355 static HRESULT WINAPI HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory *iface,
356 REFIID riid, void **ppv)
358 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
360 *ppv = NULL;
362 if(IsEqualGUID(&IID_IUnknown, riid)) {
363 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
364 *ppv = HTMLOPTFACTORY(This);
365 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
366 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
367 *ppv = HTMLOPTFACTORY(This);
368 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory, riid)) {
369 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This, ppv);
370 *ppv = HTMLOPTFACTORY(This);
373 if(*ppv) {
374 IUnknown_AddRef((IUnknown*)*ppv);
375 return S_OK;
378 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
379 return E_NOINTERFACE;
382 static ULONG WINAPI HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory *iface)
384 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
385 LONG ref = InterlockedIncrement(&This->ref);
387 TRACE("(%p) ref=%d\n", This, ref);
389 return ref;
392 static ULONG WINAPI HTMLOptionElementFactory_Release(IHTMLOptionElementFactory *iface)
394 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
395 LONG ref = InterlockedDecrement(&This->ref);
397 TRACE("(%p) ref=%d\n", This, ref);
399 if(!ref)
400 mshtml_free(This);
402 return ref;
405 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory *iface, UINT *pctinfo)
407 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
408 FIXME("(%p)->(%p)\n", This, pctinfo);
409 return E_NOTIMPL;
412 static HRESULT WINAPI HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory *iface, UINT iTInfo,
413 LCID lcid, ITypeInfo **ppTInfo)
415 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
416 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
417 return E_NOTIMPL;
420 static HRESULT WINAPI HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory *iface, REFIID riid,
421 LPOLESTR *rgszNames, UINT cNames,
422 LCID lcid, DISPID *rgDispId)
424 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
425 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
426 lcid, rgDispId);
427 return E_NOTIMPL;
430 static HRESULT WINAPI HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory *iface, DISPID dispIdMember,
431 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
432 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
434 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
435 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
436 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
437 return E_NOTIMPL;
440 static HRESULT WINAPI HTMLOptionElementFactory_create(IHTMLOptionElementFactory *iface,
441 VARIANT text, VARIANT value, VARIANT defaultselected, VARIANT selected,
442 IHTMLOptionElement **optelem)
444 HTMLOptionElementFactory *This = HTMLOPTFACTORY_THIS(iface);
445 nsIDOMDocument *nsdoc;
446 nsIDOMElement *nselem;
447 nsAString option_str;
448 nsresult nsres;
449 HRESULT hres;
451 static const PRUnichar optionW[] = {'O','P','T','I','O','N',0};
453 TRACE("(%p)->(v v v v %p)\n", This, optelem);
455 *optelem = NULL;
456 if(!This->doc->nscontainer)
457 return E_FAIL;
459 nsres = nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc);
460 if(NS_FAILED(nsres)) {
461 ERR("GetDocument failed: %08x\n", nsres);
462 return E_FAIL;
465 nsAString_Init(&option_str, optionW);
466 nsres = nsIDOMDocument_CreateElement(nsdoc, &option_str, &nselem);
467 nsIDOMDocument_Release(nsdoc);
468 nsAString_Finish(&option_str);
469 if(NS_FAILED(nsres)) {
470 ERR("CreateElement failed: %08x\n", nsres);
471 return E_FAIL;
474 hres = IHTMLDOMNode_QueryInterface(HTMLDOMNODE(get_node(This->doc, (nsIDOMNode*)nselem)),
475 &IID_IHTMLOptionElement, (void**)optelem);
476 nsIDOMElement_Release(nselem);
478 if(V_VT(&text) == VT_BSTR)
479 IHTMLOptionElement_put_text(*optelem, V_BSTR(&text));
480 else if(V_VT(&text) != VT_EMPTY)
481 FIXME("Unsupported text vt=%d\n", V_VT(&text));
483 if(V_VT(&value) == VT_BSTR)
484 IHTMLOptionElement_put_value(*optelem, V_BSTR(&value));
485 else if(V_VT(&value) != VT_EMPTY)
486 FIXME("Unsupported value vt=%d\n", V_VT(&value));
488 if(V_VT(&defaultselected) != VT_EMPTY)
489 FIXME("Unsupported defaultselected vt=%d\n", V_VT(&defaultselected));
490 if(V_VT(&selected) != VT_EMPTY)
491 FIXME("Unsupported selected vt=%d\n", V_VT(&selected));
493 return S_OK;
496 #undef HTMLOPTFACTORY_THIS
498 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl = {
499 HTMLOptionElementFactory_QueryInterface,
500 HTMLOptionElementFactory_AddRef,
501 HTMLOptionElementFactory_Release,
502 HTMLOptionElementFactory_GetTypeInfoCount,
503 HTMLOptionElementFactory_GetTypeInfo,
504 HTMLOptionElementFactory_GetIDsOfNames,
505 HTMLOptionElementFactory_Invoke,
506 HTMLOptionElementFactory_create
509 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLDocument *doc)
511 HTMLOptionElementFactory *ret;
513 ret = mshtml_alloc(sizeof(HTMLOptionElementFactory));
514 ret->lpHTMLOptionElementFactoryVtbl = &HTMLOptionElementFactoryVtbl;
515 ret->ref = 1;
516 ret->doc = doc;
518 return ret;