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 FIXME("(%p)->(%p)\n", This
, pctinfo
);
75 static HRESULT WINAPI
HTMLOptionElement_GetTypeInfo(IHTMLOptionElement
*iface
, UINT iTInfo
,
76 LCID lcid
, ITypeInfo
**ppTInfo
)
78 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
79 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
83 static HRESULT WINAPI
HTMLOptionElement_GetIDsOfNames(IHTMLOptionElement
*iface
, REFIID riid
,
84 LPOLESTR
*rgszNames
, UINT cNames
,
85 LCID lcid
, DISPID
*rgDispId
)
87 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
88 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
93 static HRESULT WINAPI
HTMLOptionElement_Invoke(IHTMLOptionElement
*iface
, DISPID dispIdMember
,
94 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
95 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
97 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
98 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
99 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
103 static HRESULT WINAPI
HTMLOptionElement_put_selected(IHTMLOptionElement
*iface
, VARIANT_BOOL v
)
105 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
106 FIXME("(%p)->(%x)\n", This
, v
);
110 static HRESULT WINAPI
HTMLOptionElement_get_selected(IHTMLOptionElement
*iface
, VARIANT_BOOL
*p
)
112 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
113 FIXME("(%p)->(%p)\n", This
, p
);
117 static HRESULT WINAPI
HTMLOptionElement_put_value(IHTMLOptionElement
*iface
, BSTR v
)
119 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
123 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
125 nsAString_Init(&value_str
, v
);
126 nsres
= nsIDOMHTMLOptionElement_SetValue(This
->nsoption
, &value_str
);
127 nsAString_Finish(&value_str
);
129 ERR("SetValue failed: %08x\n", nsres
);
134 static HRESULT WINAPI
HTMLOptionElement_get_value(IHTMLOptionElement
*iface
, BSTR
*p
)
136 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
138 const PRUnichar
*value
;
141 TRACE("(%p)->(%p)\n", This
, p
);
143 nsAString_Init(&value_str
, NULL
);
144 nsres
= nsIDOMHTMLOptionElement_GetValue(This
->nsoption
, &value_str
);
145 if(NS_SUCCEEDED(nsres
)) {
146 nsAString_GetData(&value_str
, &value
);
147 *p
= SysAllocString(value
);
149 ERR("GetValue failed: %08x\n", nsres
);
152 nsAString_Finish(&value_str
);
157 static HRESULT WINAPI
HTMLOptionElement_put_defaultSelected(IHTMLOptionElement
*iface
, VARIANT_BOOL v
)
159 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
160 FIXME("(%p)->(%x)\n", This
, v
);
164 static HRESULT WINAPI
HTMLOptionElement_get_defaultSelected(IHTMLOptionElement
*iface
, VARIANT_BOOL
*p
)
166 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
167 FIXME("(%p)->(%p)\n", This
, p
);
171 static HRESULT WINAPI
HTMLOptionElement_put_index(IHTMLOptionElement
*iface
, LONG v
)
173 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
174 FIXME("(%p)->(%d)\n", This
, v
);
178 static HRESULT WINAPI
HTMLOptionElement_get_index(IHTMLOptionElement
*iface
, LONG
*p
)
180 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
181 FIXME("(%p)->(%p)\n", This
, p
);
185 static HRESULT WINAPI
HTMLOptionElement_put_text(IHTMLOptionElement
*iface
, BSTR v
)
187 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
188 nsIDOMDocument
*nsdoc
;
189 nsIDOMText
*text_node
;
194 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
199 nsres
= nsIDOMHTMLOptionElement_GetFirstChild(This
->nsoption
, &child
);
200 if(NS_FAILED(nsres
) || !child
)
203 nsres
= nsIDOMHTMLOptionElement_RemoveChild(This
->nsoption
, child
, &tmp
);
204 nsIDOMNode_Release(child
);
205 if(NS_SUCCEEDED(nsres
)) {
206 nsIDOMNode_Release(tmp
);
208 ERR("RemoveChild failed: %08x\n", nsres
);
213 nsres
= nsIWebNavigation_GetDocument(This
->element
.node
.doc
->nscontainer
->navigation
, &nsdoc
);
214 if(NS_FAILED(nsres
)) {
215 ERR("GetDocument failed: %08x\n", nsres
);
219 nsAString_Init(&text_str
, v
);
220 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &text_str
, &text_node
);
221 nsIDOMDocument_Release(nsdoc
);
222 nsAString_Finish(&text_str
);
223 if(NS_FAILED(nsres
)) {
224 ERR("CreateTextNode failed: %08x\n", nsres
);
228 nsres
= nsIDOMHTMLOptionElement_AppendChild(This
->nsoption
, (nsIDOMNode
*)text_node
, &tmp
);
229 if(NS_SUCCEEDED(nsres
))
230 nsIDOMNode_Release(tmp
);
232 ERR("AppendChild failed: %08x\n", nsres
);
237 static HRESULT WINAPI
HTMLOptionElement_get_text(IHTMLOptionElement
*iface
, BSTR
*p
)
239 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
241 const PRUnichar
*text
;
244 TRACE("(%p)->(%p)\n", This
, p
);
246 nsAString_Init(&text_str
, NULL
);
247 nsres
= nsIDOMHTMLOptionElement_GetText(This
->nsoption
, &text_str
);
248 if(NS_SUCCEEDED(nsres
)) {
249 nsAString_GetData(&text_str
, &text
);
250 *p
= SysAllocString(text
);
252 ERR("GetText failed: %08x\n", nsres
);
255 nsAString_Finish(&text_str
);
260 static HRESULT WINAPI
HTMLOptionElement_get_form(IHTMLOptionElement
*iface
, IHTMLFormElement
**p
)
262 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
263 FIXME("(%p)->(%p)\n", This
, p
);
267 #undef HTMLOPTION_THIS
269 static const IHTMLOptionElementVtbl HTMLOptionElementVtbl
= {
270 HTMLOptionElement_QueryInterface
,
271 HTMLOptionElement_AddRef
,
272 HTMLOptionElement_Release
,
273 HTMLOptionElement_GetTypeInfoCount
,
274 HTMLOptionElement_GetTypeInfo
,
275 HTMLOptionElement_GetIDsOfNames
,
276 HTMLOptionElement_Invoke
,
277 HTMLOptionElement_put_selected
,
278 HTMLOptionElement_get_selected
,
279 HTMLOptionElement_put_value
,
280 HTMLOptionElement_get_value
,
281 HTMLOptionElement_put_defaultSelected
,
282 HTMLOptionElement_get_defaultSelected
,
283 HTMLOptionElement_put_index
,
284 HTMLOptionElement_get_index
,
285 HTMLOptionElement_put_text
,
286 HTMLOptionElement_get_text
,
287 HTMLOptionElement_get_form
290 #define HTMLOPTION_NODE_THIS(iface) DEFINE_THIS2(HTMLOptionElement, element.node, iface)
292 static HRESULT
HTMLOptionElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
294 HTMLOptionElement
*This
= HTMLOPTION_NODE_THIS(iface
);
298 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
299 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
300 *ppv
= HTMLOPTION(This
);
301 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
302 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
303 *ppv
= HTMLOPTION(This
);
304 }else if(IsEqualGUID(&IID_IHTMLOptionElement
, riid
)) {
305 TRACE("(%p)->(IID_IHTMLOptionElement %p)\n", This
, ppv
);
306 *ppv
= HTMLOPTION(This
);
310 IUnknown_AddRef((IUnknown
*)*ppv
);
314 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
317 static void HTMLOptionElement_destructor(HTMLDOMNode
*iface
)
319 HTMLOptionElement
*This
= HTMLOPTION_NODE_THIS(iface
);
322 nsIDOMHTMLOptionElement_Release(This
->nsoption
);
324 HTMLElement_destructor(&This
->element
.node
);
327 #undef HTMLOPTION_NODE_THIS
329 static const NodeImplVtbl HTMLOptionElementImplVtbl
= {
330 HTMLOptionElement_QI
,
331 HTMLOptionElement_destructor
334 static const tid_t HTMLOptionElement_iface_tids
[] = {
339 IHTMLOptionElement_tid
,
342 static dispex_static_data_t HTMLOptionElement_dispex
= {
344 DispHTMLOptionElement_tid
,
346 HTMLOptionElement_iface_tids
349 HTMLElement
*HTMLOptionElement_Create(nsIDOMHTMLElement
*nselem
)
351 HTMLOptionElement
*ret
= heap_alloc_zero(sizeof(HTMLOptionElement
));
354 ret
->lpHTMLOptionElementVtbl
= &HTMLOptionElementVtbl
;
355 ret
->element
.node
.vtbl
= &HTMLOptionElementImplVtbl
;
357 HTMLElement_Init(&ret
->element
);
358 init_dispex(&ret
->element
.node
.dispex
, (IUnknown
*)HTMLOPTION(ret
), &HTMLOptionElement_dispex
);
360 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLOptionElement
, (void**)&ret
->nsoption
);
362 ERR("Could not get nsIDOMHTMLOptionElement interface: %08x\n", nsres
);
364 return &ret
->element
;
367 #define HTMLOPTFACTORY_THIS(iface) DEFINE_THIS(HTMLOptionElementFactory, HTMLOptionElementFactory, iface)
369 static HRESULT WINAPI
HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory
*iface
,
370 REFIID riid
, void **ppv
)
372 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
376 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
377 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
378 *ppv
= HTMLOPTFACTORY(This
);
379 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
380 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
381 *ppv
= HTMLOPTFACTORY(This
);
382 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory
, riid
)) {
383 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This
, ppv
);
384 *ppv
= HTMLOPTFACTORY(This
);
388 IUnknown_AddRef((IUnknown
*)*ppv
);
392 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
393 return E_NOINTERFACE
;
396 static ULONG WINAPI
HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory
*iface
)
398 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
399 LONG ref
= InterlockedIncrement(&This
->ref
);
401 TRACE("(%p) ref=%d\n", This
, ref
);
406 static ULONG WINAPI
HTMLOptionElementFactory_Release(IHTMLOptionElementFactory
*iface
)
408 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
409 LONG ref
= InterlockedDecrement(&This
->ref
);
411 TRACE("(%p) ref=%d\n", This
, ref
);
419 static HRESULT WINAPI
HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory
*iface
, UINT
*pctinfo
)
421 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
422 FIXME("(%p)->(%p)\n", This
, pctinfo
);
426 static HRESULT WINAPI
HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory
*iface
, UINT iTInfo
,
427 LCID lcid
, ITypeInfo
**ppTInfo
)
429 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
430 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
434 static HRESULT WINAPI
HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory
*iface
, REFIID riid
,
435 LPOLESTR
*rgszNames
, UINT cNames
,
436 LCID lcid
, DISPID
*rgDispId
)
438 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
439 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
444 static HRESULT WINAPI
HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory
*iface
, DISPID dispIdMember
,
445 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
446 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
448 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
449 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
450 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
454 static HRESULT WINAPI
HTMLOptionElementFactory_create(IHTMLOptionElementFactory
*iface
,
455 VARIANT text
, VARIANT value
, VARIANT defaultselected
, VARIANT selected
,
456 IHTMLOptionElement
**optelem
)
458 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
459 nsIDOMDocument
*nsdoc
;
460 nsIDOMElement
*nselem
;
461 nsAString option_str
;
465 static const PRUnichar optionW
[] = {'O','P','T','I','O','N',0};
467 TRACE("(%p)->(v v v v %p)\n", This
, optelem
);
470 if(!This
->doc
->nscontainer
)
473 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
474 if(NS_FAILED(nsres
)) {
475 ERR("GetDocument failed: %08x\n", nsres
);
479 nsAString_Init(&option_str
, optionW
);
480 nsres
= nsIDOMDocument_CreateElement(nsdoc
, &option_str
, &nselem
);
481 nsIDOMDocument_Release(nsdoc
);
482 nsAString_Finish(&option_str
);
483 if(NS_FAILED(nsres
)) {
484 ERR("CreateElement failed: %08x\n", nsres
);
488 hres
= IHTMLDOMNode_QueryInterface(HTMLDOMNODE(get_node(This
->doc
, (nsIDOMNode
*)nselem
, TRUE
)),
489 &IID_IHTMLOptionElement
, (void**)optelem
);
490 nsIDOMElement_Release(nselem
);
492 if(V_VT(&text
) == VT_BSTR
)
493 IHTMLOptionElement_put_text(*optelem
, V_BSTR(&text
));
494 else if(V_VT(&text
) != VT_EMPTY
)
495 FIXME("Unsupported text vt=%d\n", V_VT(&text
));
497 if(V_VT(&value
) == VT_BSTR
)
498 IHTMLOptionElement_put_value(*optelem
, V_BSTR(&value
));
499 else if(V_VT(&value
) != VT_EMPTY
)
500 FIXME("Unsupported value vt=%d\n", V_VT(&value
));
502 if(V_VT(&defaultselected
) != VT_EMPTY
)
503 FIXME("Unsupported defaultselected vt=%d\n", V_VT(&defaultselected
));
504 if(V_VT(&selected
) != VT_EMPTY
)
505 FIXME("Unsupported selected vt=%d\n", V_VT(&selected
));
510 #undef HTMLOPTFACTORY_THIS
512 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl
= {
513 HTMLOptionElementFactory_QueryInterface
,
514 HTMLOptionElementFactory_AddRef
,
515 HTMLOptionElementFactory_Release
,
516 HTMLOptionElementFactory_GetTypeInfoCount
,
517 HTMLOptionElementFactory_GetTypeInfo
,
518 HTMLOptionElementFactory_GetIDsOfNames
,
519 HTMLOptionElementFactory_Invoke
,
520 HTMLOptionElementFactory_create
523 HTMLOptionElementFactory
*HTMLOptionElementFactory_Create(HTMLDocument
*doc
)
525 HTMLOptionElementFactory
*ret
;
527 ret
= heap_alloc(sizeof(HTMLOptionElementFactory
));
529 ret
->lpHTMLOptionElementFactoryVtbl
= &HTMLOptionElementFactoryVtbl
;