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
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
37 const IHTMLOptionElementVtbl
*lpHTMLOptionElementVtbl
;
39 nsIDOMHTMLOptionElement
*nsoption
;
42 #define HTMLOPTION(x) ((IHTMLOptionElement*) &(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 FIXME("(%p)->(%x)\n", This
, v
);
105 static HRESULT WINAPI
HTMLOptionElement_get_selected(IHTMLOptionElement
*iface
, VARIANT_BOOL
*p
)
107 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
108 FIXME("(%p)->(%p)\n", This
, p
);
112 static HRESULT WINAPI
HTMLOptionElement_put_value(IHTMLOptionElement
*iface
, BSTR v
)
114 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
118 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
120 nsAString_Init(&value_str
, v
);
121 nsres
= nsIDOMHTMLOptionElement_SetValue(This
->nsoption
, &value_str
);
122 nsAString_Finish(&value_str
);
124 ERR("SetValue failed: %08x\n", nsres
);
129 static HRESULT WINAPI
HTMLOptionElement_get_value(IHTMLOptionElement
*iface
, BSTR
*p
)
131 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
133 const PRUnichar
*value
;
136 TRACE("(%p)->(%p)\n", This
, p
);
138 nsAString_Init(&value_str
, NULL
);
139 nsres
= nsIDOMHTMLOptionElement_GetValue(This
->nsoption
, &value_str
);
140 if(NS_SUCCEEDED(nsres
)) {
141 nsAString_GetData(&value_str
, &value
);
142 *p
= SysAllocString(value
);
144 ERR("GetValue failed: %08x\n", nsres
);
147 nsAString_Finish(&value_str
);
152 static HRESULT WINAPI
HTMLOptionElement_put_defaultSelected(IHTMLOptionElement
*iface
, VARIANT_BOOL v
)
154 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
155 FIXME("(%p)->(%x)\n", This
, v
);
159 static HRESULT WINAPI
HTMLOptionElement_get_defaultSelected(IHTMLOptionElement
*iface
, VARIANT_BOOL
*p
)
161 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
162 FIXME("(%p)->(%p)\n", This
, p
);
166 static HRESULT WINAPI
HTMLOptionElement_put_index(IHTMLOptionElement
*iface
, LONG v
)
168 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
169 FIXME("(%p)->(%d)\n", This
, v
);
173 static HRESULT WINAPI
HTMLOptionElement_get_index(IHTMLOptionElement
*iface
, LONG
*p
)
175 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
176 FIXME("(%p)->(%p)\n", This
, p
);
180 static HRESULT WINAPI
HTMLOptionElement_put_text(IHTMLOptionElement
*iface
, BSTR v
)
182 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
183 nsIDOMDocument
*nsdoc
;
184 nsIDOMText
*text_node
;
189 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
194 nsres
= nsIDOMHTMLOptionElement_GetFirstChild(This
->nsoption
, &child
);
195 if(NS_FAILED(nsres
) || !child
)
198 nsres
= nsIDOMHTMLOptionElement_RemoveChild(This
->nsoption
, child
, &tmp
);
199 nsIDOMNode_Release(child
);
200 if(NS_SUCCEEDED(nsres
)) {
201 nsIDOMNode_Release(tmp
);
203 ERR("RemoveChild failed: %08x\n", nsres
);
208 nsres
= nsIWebNavigation_GetDocument(This
->element
.node
.doc
->nscontainer
->navigation
, &nsdoc
);
209 if(NS_FAILED(nsres
)) {
210 ERR("GetDocument failed: %08x\n", nsres
);
214 nsAString_Init(&text_str
, v
);
215 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &text_str
, &text_node
);
216 nsIDOMDocument_Release(nsdoc
);
217 nsAString_Finish(&text_str
);
218 if(NS_FAILED(nsres
)) {
219 ERR("CreateTextNode failed: %08x\n", nsres
);
223 nsres
= nsIDOMHTMLOptionElement_AppendChild(This
->nsoption
, (nsIDOMNode
*)text_node
, &tmp
);
224 if(NS_SUCCEEDED(nsres
))
225 nsIDOMNode_Release(tmp
);
227 ERR("AppendChild failed: %08x\n", nsres
);
232 static HRESULT WINAPI
HTMLOptionElement_get_text(IHTMLOptionElement
*iface
, BSTR
*p
)
234 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
236 const PRUnichar
*text
;
239 TRACE("(%p)->(%p)\n", This
, p
);
241 nsAString_Init(&text_str
, NULL
);
242 nsres
= nsIDOMHTMLOptionElement_GetText(This
->nsoption
, &text_str
);
243 if(NS_SUCCEEDED(nsres
)) {
244 nsAString_GetData(&text_str
, &text
);
245 *p
= SysAllocString(text
);
247 ERR("GetText failed: %08x\n", nsres
);
250 nsAString_Finish(&text_str
);
255 static HRESULT WINAPI
HTMLOptionElement_get_form(IHTMLOptionElement
*iface
, IHTMLFormElement
**p
)
257 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
258 FIXME("(%p)->(%p)\n", This
, p
);
262 #undef HTMLOPTION_THIS
264 static const IHTMLOptionElementVtbl HTMLOptionElementVtbl
= {
265 HTMLOptionElement_QueryInterface
,
266 HTMLOptionElement_AddRef
,
267 HTMLOptionElement_Release
,
268 HTMLOptionElement_GetTypeInfoCount
,
269 HTMLOptionElement_GetTypeInfo
,
270 HTMLOptionElement_GetIDsOfNames
,
271 HTMLOptionElement_Invoke
,
272 HTMLOptionElement_put_selected
,
273 HTMLOptionElement_get_selected
,
274 HTMLOptionElement_put_value
,
275 HTMLOptionElement_get_value
,
276 HTMLOptionElement_put_defaultSelected
,
277 HTMLOptionElement_get_defaultSelected
,
278 HTMLOptionElement_put_index
,
279 HTMLOptionElement_get_index
,
280 HTMLOptionElement_put_text
,
281 HTMLOptionElement_get_text
,
282 HTMLOptionElement_get_form
285 #define HTMLOPTION_NODE_THIS(iface) DEFINE_THIS2(HTMLOptionElement, element.node, iface)
287 static HRESULT
HTMLOptionElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
289 HTMLOptionElement
*This
= HTMLOPTION_NODE_THIS(iface
);
293 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
294 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
295 *ppv
= HTMLOPTION(This
);
296 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
297 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
298 *ppv
= HTMLOPTION(This
);
299 }else if(IsEqualGUID(&IID_IHTMLOptionElement
, riid
)) {
300 TRACE("(%p)->(IID_IHTMLOptionElement %p)\n", This
, ppv
);
301 *ppv
= HTMLOPTION(This
);
305 IUnknown_AddRef((IUnknown
*)*ppv
);
309 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
312 static void HTMLOptionElement_destructor(HTMLDOMNode
*iface
)
314 HTMLOptionElement
*This
= HTMLOPTION_NODE_THIS(iface
);
317 nsIDOMHTMLOptionElement_Release(This
->nsoption
);
319 HTMLElement_destructor(&This
->element
.node
);
322 #undef HTMLOPTION_NODE_THIS
324 static const NodeImplVtbl HTMLOptionElementImplVtbl
= {
325 HTMLOptionElement_QI
,
326 HTMLOptionElement_destructor
329 static const tid_t HTMLOptionElement_iface_tids
[] = {
334 IHTMLOptionElement_tid
,
337 static dispex_static_data_t HTMLOptionElement_dispex
= {
339 DispHTMLOptionElement_tid
,
341 HTMLOptionElement_iface_tids
344 HTMLElement
*HTMLOptionElement_Create(nsIDOMHTMLElement
*nselem
)
346 HTMLOptionElement
*ret
= heap_alloc_zero(sizeof(HTMLOptionElement
));
349 ret
->lpHTMLOptionElementVtbl
= &HTMLOptionElementVtbl
;
350 ret
->element
.node
.vtbl
= &HTMLOptionElementImplVtbl
;
352 HTMLElement_Init(&ret
->element
);
353 init_dispex(&ret
->element
.node
.dispex
, (IUnknown
*)HTMLOPTION(ret
), &HTMLOptionElement_dispex
);
355 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLOptionElement
, (void**)&ret
->nsoption
);
357 ERR("Could not get nsIDOMHTMLOptionElement interface: %08x\n", nsres
);
359 return &ret
->element
;
362 #define HTMLOPTFACTORY_THIS(iface) DEFINE_THIS(HTMLOptionElementFactory, HTMLOptionElementFactory, iface)
364 static HRESULT WINAPI
HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory
*iface
,
365 REFIID riid
, void **ppv
)
367 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
371 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
372 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
373 *ppv
= HTMLOPTFACTORY(This
);
374 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
375 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
376 *ppv
= HTMLOPTFACTORY(This
);
377 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory
, riid
)) {
378 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This
, ppv
);
379 *ppv
= HTMLOPTFACTORY(This
);
383 IUnknown_AddRef((IUnknown
*)*ppv
);
387 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
388 return E_NOINTERFACE
;
391 static ULONG WINAPI
HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory
*iface
)
393 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
394 LONG ref
= InterlockedIncrement(&This
->ref
);
396 TRACE("(%p) ref=%d\n", This
, ref
);
401 static ULONG WINAPI
HTMLOptionElementFactory_Release(IHTMLOptionElementFactory
*iface
)
403 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
404 LONG ref
= InterlockedDecrement(&This
->ref
);
406 TRACE("(%p) ref=%d\n", This
, ref
);
414 static HRESULT WINAPI
HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory
*iface
, UINT
*pctinfo
)
416 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
417 FIXME("(%p)->(%p)\n", This
, pctinfo
);
421 static HRESULT WINAPI
HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory
*iface
, UINT iTInfo
,
422 LCID lcid
, ITypeInfo
**ppTInfo
)
424 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
425 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
429 static HRESULT WINAPI
HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory
*iface
, REFIID riid
,
430 LPOLESTR
*rgszNames
, UINT cNames
,
431 LCID lcid
, DISPID
*rgDispId
)
433 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
434 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
439 static HRESULT WINAPI
HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory
*iface
, DISPID dispIdMember
,
440 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
441 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
443 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
444 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
445 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
449 static HRESULT WINAPI
HTMLOptionElementFactory_create(IHTMLOptionElementFactory
*iface
,
450 VARIANT text
, VARIANT value
, VARIANT defaultselected
, VARIANT selected
,
451 IHTMLOptionElement
**optelem
)
453 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
454 nsIDOMDocument
*nsdoc
;
455 nsIDOMElement
*nselem
;
456 nsAString option_str
;
460 static const PRUnichar optionW
[] = {'O','P','T','I','O','N',0};
462 TRACE("(%p)->(v v v v %p)\n", This
, optelem
);
465 if(!This
->doc
->nscontainer
)
468 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
469 if(NS_FAILED(nsres
)) {
470 ERR("GetDocument failed: %08x\n", nsres
);
474 nsAString_Init(&option_str
, optionW
);
475 nsres
= nsIDOMDocument_CreateElement(nsdoc
, &option_str
, &nselem
);
476 nsIDOMDocument_Release(nsdoc
);
477 nsAString_Finish(&option_str
);
478 if(NS_FAILED(nsres
)) {
479 ERR("CreateElement failed: %08x\n", nsres
);
483 hres
= IHTMLDOMNode_QueryInterface(HTMLDOMNODE(get_node(This
->doc
, (nsIDOMNode
*)nselem
, TRUE
)),
484 &IID_IHTMLOptionElement
, (void**)optelem
);
485 nsIDOMElement_Release(nselem
);
487 if(V_VT(&text
) == VT_BSTR
)
488 IHTMLOptionElement_put_text(*optelem
, V_BSTR(&text
));
489 else if(V_VT(&text
) != VT_EMPTY
)
490 FIXME("Unsupported text vt=%d\n", V_VT(&text
));
492 if(V_VT(&value
) == VT_BSTR
)
493 IHTMLOptionElement_put_value(*optelem
, V_BSTR(&value
));
494 else if(V_VT(&value
) != VT_EMPTY
)
495 FIXME("Unsupported value vt=%d\n", V_VT(&value
));
497 if(V_VT(&defaultselected
) != VT_EMPTY
)
498 FIXME("Unsupported defaultselected vt=%d\n", V_VT(&defaultselected
));
499 if(V_VT(&selected
) != VT_EMPTY
)
500 FIXME("Unsupported selected vt=%d\n", V_VT(&selected
));
505 #undef HTMLOPTFACTORY_THIS
507 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl
= {
508 HTMLOptionElementFactory_QueryInterface
,
509 HTMLOptionElementFactory_AddRef
,
510 HTMLOptionElementFactory_Release
,
511 HTMLOptionElementFactory_GetTypeInfoCount
,
512 HTMLOptionElementFactory_GetTypeInfo
,
513 HTMLOptionElementFactory_GetIDsOfNames
,
514 HTMLOptionElementFactory_Invoke
,
515 HTMLOptionElementFactory_create
518 HTMLOptionElementFactory
*HTMLOptionElementFactory_Create(HTMLDocument
*doc
)
520 HTMLOptionElementFactory
*ret
;
522 ret
= heap_alloc(sizeof(HTMLOptionElementFactory
));
524 ret
->lpHTMLOptionElementFactoryVtbl
= &HTMLOptionElementFactoryVtbl
;