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
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
41 const IHTMLOptionElementVtbl
*lpHTMLOptionElementVtbl
;
43 nsIDOMHTMLOptionElement
*nsoption
;
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
);
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
);
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
,
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
);
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
);
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
);
121 static HRESULT WINAPI
HTMLOptionElement_put_value(IHTMLOptionElement
*iface
, BSTR v
)
123 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
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
);
133 ERR("SetValue failed: %08x\n", nsres
);
138 static HRESULT WINAPI
HTMLOptionElement_get_value(IHTMLOptionElement
*iface
, BSTR
*p
)
140 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
142 const PRUnichar
*value
;
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
);
153 ERR("GetValue failed: %08x\n", nsres
);
156 nsAString_Finish(&value_str
);
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
);
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
);
175 static HRESULT WINAPI
HTMLOptionElement_put_index(IHTMLOptionElement
*iface
, LONG v
)
177 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
178 FIXME("(%p)->(%d)\n", This
, v
);
182 static HRESULT WINAPI
HTMLOptionElement_get_index(IHTMLOptionElement
*iface
, LONG
*p
)
184 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
185 FIXME("(%p)->(%p)\n", This
, p
);
189 static HRESULT WINAPI
HTMLOptionElement_put_text(IHTMLOptionElement
*iface
, BSTR v
)
191 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
192 nsIDOMDocument
*nsdoc
;
193 nsIDOMText
*text_node
;
198 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
203 nsres
= nsIDOMHTMLOptionElement_GetFirstChild(This
->nsoption
, &child
);
204 if(NS_FAILED(nsres
) || !child
)
207 nsres
= nsIDOMHTMLOptionElement_RemoveChild(This
->nsoption
, child
, &tmp
);
208 nsIDOMNode_Release(child
);
209 if(NS_SUCCEEDED(nsres
)) {
210 nsIDOMNode_Release(tmp
);
212 ERR("RemoveChild failed: %08x\n", nsres
);
217 nsres
= nsIWebNavigation_GetDocument(This
->element
.node
.doc
->nscontainer
->navigation
, &nsdoc
);
218 if(NS_FAILED(nsres
)) {
219 ERR("GetDocument failed: %08x\n", nsres
);
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
);
232 nsres
= nsIDOMHTMLOptionElement_AppendChild(This
->nsoption
, (nsIDOMNode
*)text_node
, &tmp
);
233 if(NS_SUCCEEDED(nsres
))
234 nsIDOMNode_Release(tmp
);
236 ERR("AppendChild failed: %08x\n", nsres
);
241 static HRESULT WINAPI
HTMLOptionElement_get_text(IHTMLOptionElement
*iface
, BSTR
*p
)
243 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
245 const PRUnichar
*text
;
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
);
256 ERR("GetText failed: %08x\n", nsres
);
259 nsAString_Finish(&text_str
);
264 static HRESULT WINAPI
HTMLOptionElement_get_form(IHTMLOptionElement
*iface
, IHTMLFormElement
**p
)
266 HTMLOptionElement
*This
= HTMLOPTION_THIS(iface
);
267 FIXME("(%p)->(%p)\n", This
, p
);
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
);
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
);
314 IUnknown_AddRef((IUnknown
*)*ppv
);
318 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
321 static void HTMLOptionElement_destructor(HTMLDOMNode
*iface
)
323 HTMLOptionElement
*This
= HTMLOPTION_NODE_THIS(iface
);
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
));
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
);
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
);
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
);
376 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
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
);
407 static HRESULT WINAPI
HTMLOptionElementFactory_GetTypeInfoCount(IHTMLOptionElementFactory
*iface
, UINT
*pctinfo
)
409 HTMLOptionElementFactory
*This
= HTMLOPTFACTORY_THIS(iface
);
410 FIXME("(%p)->(%p)\n", This
, pctinfo
);
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
);
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
,
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
);
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
;
453 static const PRUnichar optionW
[] = {'O','P','T','I','O','N',0};
455 TRACE("(%p)->(v v v v %p)\n", This
, optelem
);
458 if(!This
->doc
->nscontainer
)
461 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
462 if(NS_FAILED(nsres
)) {
463 ERR("GetDocument failed: %08x\n", nsres
);
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
);
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
));
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
;