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 HTMLElement
*HTMLOptionElement_Create(nsIDOMHTMLElement
*nselem
)
336 HTMLOptionElement
*ret
= heap_alloc(sizeof(HTMLOptionElement
));
339 HTMLElement_Init(&ret
->element
);
341 ret
->lpHTMLOptionElementVtbl
= &HTMLOptionElementVtbl
;
342 ret
->element
.node
.vtbl
= &HTMLOptionElementImplVtbl
;
344 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLOptionElement
, (void**)&ret
->nsoption
);
346 ERR("Could not get nsIDOMHTMLOptionElement interface: %08x\n", nsres
);
348 return &ret
->element
;
351 #define HTMLOPTFACTORY_THIS(iface) DEFINE_THIS(HTMLOptionElementFactory, HTMLOptionElementFactory, iface)
353 static HRESULT WINAPI
HTMLOptionElementFactory_QueryInterface(IHTMLOptionElementFactory
*iface
,
354 REFIID riid
, void **ppv
)
356 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
360 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
361 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
362 *ppv
= HTMLOPTFACTORY(This
);
363 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
364 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
365 *ppv
= HTMLOPTFACTORY(This
);
366 }else if(IsEqualGUID(&IID_IHTMLOptionElementFactory
, riid
)) {
367 TRACE("(%p)->(IID_IHTMLOptionElementFactory %p)\n", This
, ppv
);
368 *ppv
= HTMLOPTFACTORY(This
);
372 IUnknown_AddRef((IUnknown
*)*ppv
);
376 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
377 return E_NOINTERFACE
;
380 static ULONG WINAPI
HTMLOptionElementFactory_AddRef(IHTMLOptionElementFactory
*iface
)
382 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
383 LONG ref
= InterlockedIncrement(&This
->ref
);
385 TRACE("(%p) ref=%d\n", This
, ref
);
390 static ULONG WINAPI
HTMLOptionElementFactory_Release(IHTMLOptionElementFactory
*iface
)
392 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
393 LONG ref
= InterlockedDecrement(&This
->ref
);
395 TRACE("(%p) ref=%d\n", This
, ref
);
403 static HRESULT WINAPI
HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory
*iface
, UINT
*pctinfo
)
405 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
406 FIXME("(%p)->(%p)\n", This
, pctinfo
);
410 static HRESULT WINAPI
HTMLOptionElementFactory_GetTypeInfo(IHTMLOptionElementFactory
*iface
, UINT iTInfo
,
411 LCID lcid
, ITypeInfo
**ppTInfo
)
413 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
414 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
418 static HRESULT WINAPI
HTMLOptionElementFactory_GetIDsOfNames(IHTMLOptionElementFactory
*iface
, REFIID riid
,
419 LPOLESTR
*rgszNames
, UINT cNames
,
420 LCID lcid
, DISPID
*rgDispId
)
422 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
423 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
428 static HRESULT WINAPI
HTMLOptionElementFactory_Invoke(IHTMLOptionElementFactory
*iface
, DISPID dispIdMember
,
429 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
430 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
432 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
433 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
434 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
438 static HRESULT WINAPI
HTMLOptionElementFactory_create(IHTMLOptionElementFactory
*iface
,
439 VARIANT text
, VARIANT value
, VARIANT defaultselected
, VARIANT selected
,
440 IHTMLOptionElement
**optelem
)
442 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
443 nsIDOMDocument
*nsdoc
;
444 nsIDOMElement
*nselem
;
445 nsAString option_str
;
449 static const PRUnichar optionW
[] = {'O','P','T','I','O','N',0};
451 TRACE("(%p)->(v v v v %p)\n", This
, optelem
);
454 if(!This
->doc
->nscontainer
)
457 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
458 if(NS_FAILED(nsres
)) {
459 ERR("GetDocument failed: %08x\n", nsres
);
463 nsAString_Init(&option_str
, optionW
);
464 nsres
= nsIDOMDocument_CreateElement(nsdoc
, &option_str
, &nselem
);
465 nsIDOMDocument_Release(nsdoc
);
466 nsAString_Finish(&option_str
);
467 if(NS_FAILED(nsres
)) {
468 ERR("CreateElement failed: %08x\n", nsres
);
472 hres
= IHTMLDOMNode_QueryInterface(HTMLDOMNODE(get_node(This
->doc
, (nsIDOMNode
*)nselem
)),
473 &IID_IHTMLOptionElement
, (void**)optelem
);
474 nsIDOMElement_Release(nselem
);
476 if(V_VT(&text
) == VT_BSTR
)
477 IHTMLOptionElement_put_text(*optelem
, V_BSTR(&text
));
478 else if(V_VT(&text
) != VT_EMPTY
)
479 FIXME("Unsupported text vt=%d\n", V_VT(&text
));
481 if(V_VT(&value
) == VT_BSTR
)
482 IHTMLOptionElement_put_value(*optelem
, V_BSTR(&value
));
483 else if(V_VT(&value
) != VT_EMPTY
)
484 FIXME("Unsupported value vt=%d\n", V_VT(&value
));
486 if(V_VT(&defaultselected
) != VT_EMPTY
)
487 FIXME("Unsupported defaultselected vt=%d\n", V_VT(&defaultselected
));
488 if(V_VT(&selected
) != VT_EMPTY
)
489 FIXME("Unsupported selected vt=%d\n", V_VT(&selected
));
494 #undef HTMLOPTFACTORY_THIS
496 static const IHTMLOptionElementFactoryVtbl HTMLOptionElementFactoryVtbl
= {
497 HTMLOptionElementFactory_QueryInterface
,
498 HTMLOptionElementFactory_AddRef
,
499 HTMLOptionElementFactory_Release
,
500 HTMLOptionElementFactory_GetTypeInfoCount
,
501 HTMLOptionElementFactory_GetTypeInfo
,
502 HTMLOptionElementFactory_GetIDsOfNames
,
503 HTMLOptionElementFactory_Invoke
,
504 HTMLOptionElementFactory_create
507 HTMLOptionElementFactory
*HTMLOptionElementFactory_Create(HTMLDocument
*doc
)
509 HTMLOptionElementFactory
*ret
;
511 ret
= heap_alloc(sizeof(HTMLOptionElementFactory
));
513 ret
->lpHTMLOptionElementFactoryVtbl
= &HTMLOptionElementFactoryVtbl
;