strmbase: Implement BaseControlWindow.
[wine/multimedia.git] / dlls / mshtml / htmlscript.c
blobcb5cbedc447db78b2e2934bad7f1e81788a96459
1 /*
2 * Copyright 2008 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 <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 typedef struct {
35 HTMLElement element;
37 IHTMLScriptElement IHTMLScriptElement_iface;
39 nsIDOMHTMLScriptElement *nsscript;
40 } HTMLScriptElement;
42 static inline HTMLScriptElement *impl_from_IHTMLScriptElement(IHTMLScriptElement *iface)
44 return CONTAINING_RECORD(iface, HTMLScriptElement, IHTMLScriptElement_iface);
47 static HRESULT WINAPI HTMLScriptElement_QueryInterface(IHTMLScriptElement *iface,
48 REFIID riid, void **ppv)
50 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
52 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
55 static ULONG WINAPI HTMLScriptElement_AddRef(IHTMLScriptElement *iface)
57 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
59 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
62 static ULONG WINAPI HTMLScriptElement_Release(IHTMLScriptElement *iface)
64 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
66 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
69 static HRESULT WINAPI HTMLScriptElement_GetTypeInfoCount(IHTMLScriptElement *iface, UINT *pctinfo)
71 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
72 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
75 static HRESULT WINAPI HTMLScriptElement_GetTypeInfo(IHTMLScriptElement *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
79 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
80 ppTInfo);
83 static HRESULT WINAPI HTMLScriptElement_GetIDsOfNames(IHTMLScriptElement *iface, REFIID riid,
84 LPOLESTR *rgszNames, UINT cNames,
85 LCID lcid, DISPID *rgDispId)
87 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
88 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
89 cNames, lcid, rgDispId);
92 static HRESULT WINAPI HTMLScriptElement_Invoke(IHTMLScriptElement *iface, DISPID dispIdMember,
93 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
94 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
96 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
97 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
98 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
101 static HRESULT WINAPI HTMLScriptElement_put_src(IHTMLScriptElement *iface, BSTR v)
103 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
104 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
105 return E_NOTIMPL;
108 static HRESULT WINAPI HTMLScriptElement_get_src(IHTMLScriptElement *iface, BSTR *p)
110 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
111 nsAString src_str;
112 nsresult nsres;
114 TRACE("(%p)->(%p)\n", This, p);
116 nsAString_Init(&src_str, NULL);
117 nsres = nsIDOMHTMLScriptElement_GetSrc(This->nsscript, &src_str);
118 return return_nsstr(nsres, &src_str, p);
121 static HRESULT WINAPI HTMLScriptElement_put_htmlFor(IHTMLScriptElement *iface, BSTR v)
123 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
124 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
125 return E_NOTIMPL;
128 static HRESULT WINAPI HTMLScriptElement_get_htmlFor(IHTMLScriptElement *iface, BSTR *p)
130 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
131 FIXME("(%p)->(%p)\n", This, p);
132 return E_NOTIMPL;
135 static HRESULT WINAPI HTMLScriptElement_put_event(IHTMLScriptElement *iface, BSTR v)
137 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
138 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
139 return E_NOTIMPL;
142 static HRESULT WINAPI HTMLScriptElement_get_event(IHTMLScriptElement *iface, BSTR *p)
144 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
145 FIXME("(%p)->(%p)\n", This, p);
146 return E_NOTIMPL;
149 static HRESULT WINAPI HTMLScriptElement_put_text(IHTMLScriptElement *iface, BSTR v)
151 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
152 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
153 return E_NOTIMPL;
156 static HRESULT WINAPI HTMLScriptElement_get_text(IHTMLScriptElement *iface, BSTR *p)
158 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
159 FIXME("(%p)->(%p)\n", This, p);
160 return E_NOTIMPL;
163 static HRESULT WINAPI HTMLScriptElement_put_defer(IHTMLScriptElement *iface, VARIANT_BOOL v)
165 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
166 HRESULT hr = S_OK;
167 nsresult nsres;
169 TRACE("(%p)->(%x)\n", This, v);
171 nsres = nsIDOMHTMLScriptElement_SetDefer(This->nsscript, v != VARIANT_FALSE);
172 if(NS_FAILED(nsres))
174 hr = E_FAIL;
177 return hr;
180 static HRESULT WINAPI HTMLScriptElement_get_defer(IHTMLScriptElement *iface, VARIANT_BOOL *p)
182 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
183 cpp_bool defer = FALSE;
184 nsresult nsres;
186 TRACE("(%p)->(%p)\n", This, p);
188 if(!p)
189 return E_INVALIDARG;
191 nsres = nsIDOMHTMLScriptElement_GetDefer(This->nsscript, &defer);
192 if(NS_FAILED(nsres)) {
193 ERR("GetSrc failed: %08x\n", nsres);
196 *p = defer ? VARIANT_TRUE : VARIANT_FALSE;
198 TRACE("*p = %d\n", *p);
199 return S_OK;
202 static HRESULT WINAPI HTMLScriptElement_get_readyState(IHTMLScriptElement *iface, BSTR *p)
204 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
205 FIXME("(%p)->(%p)\n", This, p);
206 return E_NOTIMPL;
209 static HRESULT WINAPI HTMLScriptElement_put_onerror(IHTMLScriptElement *iface, VARIANT v)
211 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
212 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
213 return E_NOTIMPL;
216 static HRESULT WINAPI HTMLScriptElement_get_onerror(IHTMLScriptElement *iface, VARIANT *p)
218 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
219 FIXME("(%p)->(%p)\n", This, p);
220 return E_NOTIMPL;
223 static HRESULT WINAPI HTMLScriptElement_put_type(IHTMLScriptElement *iface, BSTR v)
225 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
226 nsAString nstype_str;
227 nsresult nsres;
229 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
231 nsAString_Init(&nstype_str, v);
232 nsres = nsIDOMHTMLScriptElement_SetType(This->nsscript, &nstype_str);
233 if (NS_FAILED(nsres))
234 ERR("SetType failed: %08x\n", nsres);
235 nsAString_Finish (&nstype_str);
237 return S_OK;
240 static HRESULT WINAPI HTMLScriptElement_get_type(IHTMLScriptElement *iface, BSTR *p)
242 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
243 const PRUnichar *nstype;
244 nsAString nstype_str;
245 nsresult nsres;
247 TRACE("(%p)->(%p)\n", This, p);
249 nsAString_Init(&nstype_str, NULL);
250 nsres = nsIDOMHTMLScriptElement_GetType(This->nsscript, &nstype_str);
251 if(NS_FAILED(nsres))
252 ERR("GetType failed: %08x\n", nsres);
254 nsAString_GetData(&nstype_str, &nstype);
255 *p = *nstype ? SysAllocString(nstype) : NULL;
256 nsAString_Finish(&nstype_str);
258 return S_OK;
261 static const IHTMLScriptElementVtbl HTMLScriptElementVtbl = {
262 HTMLScriptElement_QueryInterface,
263 HTMLScriptElement_AddRef,
264 HTMLScriptElement_Release,
265 HTMLScriptElement_GetTypeInfoCount,
266 HTMLScriptElement_GetTypeInfo,
267 HTMLScriptElement_GetIDsOfNames,
268 HTMLScriptElement_Invoke,
269 HTMLScriptElement_put_src,
270 HTMLScriptElement_get_src,
271 HTMLScriptElement_put_htmlFor,
272 HTMLScriptElement_get_htmlFor,
273 HTMLScriptElement_put_event,
274 HTMLScriptElement_get_event,
275 HTMLScriptElement_put_text,
276 HTMLScriptElement_get_text,
277 HTMLScriptElement_put_defer,
278 HTMLScriptElement_get_defer,
279 HTMLScriptElement_get_readyState,
280 HTMLScriptElement_put_onerror,
281 HTMLScriptElement_get_onerror,
282 HTMLScriptElement_put_type,
283 HTMLScriptElement_get_type
286 static inline HTMLScriptElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
288 return CONTAINING_RECORD(iface, HTMLScriptElement, element.node);
291 static HRESULT HTMLScriptElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
293 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
295 *ppv = NULL;
297 if(IsEqualGUID(&IID_IUnknown, riid)) {
298 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
299 *ppv = &This->IHTMLScriptElement_iface;
300 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
301 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
302 *ppv = &This->IHTMLScriptElement_iface;
303 }else if(IsEqualGUID(&IID_IHTMLScriptElement, riid)) {
304 TRACE("(%p)->(IID_IHTMLScriptElement %p)\n", This, ppv);
305 *ppv = &This->IHTMLScriptElement_iface;
308 if(*ppv) {
309 IUnknown_AddRef((IUnknown*)*ppv);
310 return S_OK;
313 return HTMLElement_QI(&This->element.node, riid, ppv);
316 static void HTMLScriptElement_destructor(HTMLDOMNode *iface)
318 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
319 HTMLElement_destructor(&This->element.node);
322 static HRESULT HTMLScriptElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
324 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
326 return IHTMLScriptElement_get_readyState(&This->IHTMLScriptElement_iface, p);
329 static const NodeImplVtbl HTMLScriptElementImplVtbl = {
330 HTMLScriptElement_QI,
331 HTMLScriptElement_destructor,
332 HTMLElement_clone,
333 HTMLElement_get_attr_col,
334 NULL,
335 NULL,
336 NULL,
337 NULL,
338 NULL,
339 NULL,
340 HTMLScriptElement_get_readystate
343 static const tid_t HTMLScriptElement_iface_tids[] = {
344 HTMLELEMENT_TIDS,
345 IHTMLScriptElement_tid,
349 static dispex_static_data_t HTMLScriptElement_dispex = {
350 NULL,
351 DispHTMLScriptElement_tid,
352 NULL,
353 HTMLScriptElement_iface_tids
356 HRESULT HTMLScriptElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
358 HTMLScriptElement *ret;
359 nsresult nsres;
361 ret = heap_alloc_zero(sizeof(HTMLScriptElement));
362 if(!ret)
363 return E_OUTOFMEMORY;
365 ret->IHTMLScriptElement_iface.lpVtbl = &HTMLScriptElementVtbl;
366 ret->element.node.vtbl = &HTMLScriptElementImplVtbl;
368 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLScriptElement, (void**)&ret->nsscript);
369 if(NS_FAILED(nsres)) {
370 ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres);
371 heap_free(ret);
372 return E_FAIL;
375 HTMLElement_Init(&ret->element, doc, nselem, &HTMLScriptElement_dispex);
377 *elem = &ret->element;
378 return S_OK;