windowscodecs: Add support for color table sort flag to the GIF decoder.
[wine] / dlls / mshtml / htmlscript.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20 #include <assert.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28
29 #include "wine/debug.h"
30
31 #include "mshtml_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34
35 typedef struct {
36     HTMLElement element;
37
38     IHTMLScriptElement IHTMLScriptElement_iface;
39
40     nsIDOMHTMLScriptElement *nsscript;
41 } HTMLScriptElement;
42
43 static inline HTMLScriptElement *impl_from_IHTMLScriptElement(IHTMLScriptElement *iface)
44 {
45     return CONTAINING_RECORD(iface, HTMLScriptElement, IHTMLScriptElement_iface);
46 }
47
48 static HRESULT WINAPI HTMLScriptElement_QueryInterface(IHTMLScriptElement *iface,
49         REFIID riid, void **ppv)
50 {
51     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
52
53     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
54 }
55
56 static ULONG WINAPI HTMLScriptElement_AddRef(IHTMLScriptElement *iface)
57 {
58     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
59
60     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
61 }
62
63 static ULONG WINAPI HTMLScriptElement_Release(IHTMLScriptElement *iface)
64 {
65     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
66
67     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
68 }
69
70 static HRESULT WINAPI HTMLScriptElement_GetTypeInfoCount(IHTMLScriptElement *iface, UINT *pctinfo)
71 {
72     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
73     return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
74 }
75
76 static HRESULT WINAPI HTMLScriptElement_GetTypeInfo(IHTMLScriptElement *iface, UINT iTInfo,
77                                               LCID lcid, ITypeInfo **ppTInfo)
78 {
79     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
80     return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
81             ppTInfo);
82 }
83
84 static HRESULT WINAPI HTMLScriptElement_GetIDsOfNames(IHTMLScriptElement *iface, REFIID riid,
85                                                 LPOLESTR *rgszNames, UINT cNames,
86                                                 LCID lcid, DISPID *rgDispId)
87 {
88     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
89     return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
90             cNames, lcid, rgDispId);
91 }
92
93 static HRESULT WINAPI HTMLScriptElement_Invoke(IHTMLScriptElement *iface, DISPID dispIdMember,
94                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
95                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
96 {
97     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
98     return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
99             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
100 }
101
102 static HRESULT WINAPI HTMLScriptElement_put_src(IHTMLScriptElement *iface, BSTR v)
103 {
104     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
105     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
106     return E_NOTIMPL;
107 }
108
109 static HRESULT WINAPI HTMLScriptElement_get_src(IHTMLScriptElement *iface, BSTR *p)
110 {
111     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
112     nsAString src_str;
113     nsresult nsres;
114
115     TRACE("(%p)->(%p)\n", This, p);
116
117     nsAString_Init(&src_str, NULL);
118     nsres = nsIDOMHTMLScriptElement_GetSrc(This->nsscript, &src_str);
119     return return_nsstr(nsres, &src_str, p);
120 }
121
122 static HRESULT WINAPI HTMLScriptElement_put_htmlFor(IHTMLScriptElement *iface, BSTR v)
123 {
124     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
125     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI HTMLScriptElement_get_htmlFor(IHTMLScriptElement *iface, BSTR *p)
130 {
131     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
132     FIXME("(%p)->(%p)\n", This, p);
133     return E_NOTIMPL;
134 }
135
136 static HRESULT WINAPI HTMLScriptElement_put_event(IHTMLScriptElement *iface, BSTR v)
137 {
138     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
139     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
140     return E_NOTIMPL;
141 }
142
143 static HRESULT WINAPI HTMLScriptElement_get_event(IHTMLScriptElement *iface, BSTR *p)
144 {
145     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
146     FIXME("(%p)->(%p)\n", This, p);
147     return E_NOTIMPL;
148 }
149
150 static HRESULT WINAPI HTMLScriptElement_put_text(IHTMLScriptElement *iface, BSTR v)
151 {
152     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
153     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
154     return E_NOTIMPL;
155 }
156
157 static HRESULT WINAPI HTMLScriptElement_get_text(IHTMLScriptElement *iface, BSTR *p)
158 {
159     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
160     FIXME("(%p)->(%p)\n", This, p);
161     return E_NOTIMPL;
162 }
163
164 static HRESULT WINAPI HTMLScriptElement_put_defer(IHTMLScriptElement *iface, VARIANT_BOOL v)
165 {
166     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
167     HRESULT hr = S_OK;
168     nsresult nsres;
169
170     TRACE("(%p)->(%x)\n", This, v);
171
172     nsres = nsIDOMHTMLScriptElement_SetDefer(This->nsscript, v != VARIANT_FALSE);
173     if(NS_FAILED(nsres))
174     {
175         hr = E_FAIL;
176     }
177
178     return hr;
179 }
180
181 static HRESULT WINAPI HTMLScriptElement_get_defer(IHTMLScriptElement *iface, VARIANT_BOOL *p)
182 {
183     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
184     cpp_bool defer = FALSE;
185     nsresult nsres;
186
187     TRACE("(%p)->(%p)\n", This, p);
188
189     if(!p)
190         return E_INVALIDARG;
191
192     nsres = nsIDOMHTMLScriptElement_GetDefer(This->nsscript, &defer);
193     if(NS_FAILED(nsres)) {
194         ERR("GetSrc failed: %08x\n", nsres);
195     }
196
197     *p = defer ? VARIANT_TRUE : VARIANT_FALSE;
198
199     TRACE("*p = %d\n", *p);
200     return S_OK;
201 }
202
203 static HRESULT WINAPI HTMLScriptElement_get_readyState(IHTMLScriptElement *iface, BSTR *p)
204 {
205     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
206     FIXME("(%p)->(%p)\n", This, p);
207     return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI HTMLScriptElement_put_onerror(IHTMLScriptElement *iface, VARIANT v)
211 {
212     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
213     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
214     return E_NOTIMPL;
215 }
216
217 static HRESULT WINAPI HTMLScriptElement_get_onerror(IHTMLScriptElement *iface, VARIANT *p)
218 {
219     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
220     FIXME("(%p)->(%p)\n", This, p);
221     return E_NOTIMPL;
222 }
223
224 static HRESULT WINAPI HTMLScriptElement_put_type(IHTMLScriptElement *iface, BSTR v)
225 {
226     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
227     nsAString nstype_str;
228     nsresult nsres;
229
230     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
231
232     nsAString_Init(&nstype_str, v);
233     nsres = nsIDOMHTMLScriptElement_SetType(This->nsscript, &nstype_str);
234     if (NS_FAILED(nsres))
235         ERR("SetType failed: %08x\n", nsres);
236     nsAString_Finish (&nstype_str);
237
238     return S_OK;
239 }
240
241 static HRESULT WINAPI HTMLScriptElement_get_type(IHTMLScriptElement *iface, BSTR *p)
242 {
243     HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
244     nsAString nstype_str;
245     nsresult nsres;
246
247     TRACE("(%p)->(%p)\n", This, p);
248
249     nsAString_Init(&nstype_str, NULL);
250     nsres = nsIDOMHTMLScriptElement_GetType(This->nsscript, &nstype_str);
251     return return_nsstr(nsres, &nstype_str, p);
252 }
253
254 static const IHTMLScriptElementVtbl HTMLScriptElementVtbl = {
255     HTMLScriptElement_QueryInterface,
256     HTMLScriptElement_AddRef,
257     HTMLScriptElement_Release,
258     HTMLScriptElement_GetTypeInfoCount,
259     HTMLScriptElement_GetTypeInfo,
260     HTMLScriptElement_GetIDsOfNames,
261     HTMLScriptElement_Invoke,
262     HTMLScriptElement_put_src,
263     HTMLScriptElement_get_src,
264     HTMLScriptElement_put_htmlFor,
265     HTMLScriptElement_get_htmlFor,
266     HTMLScriptElement_put_event,
267     HTMLScriptElement_get_event,
268     HTMLScriptElement_put_text,
269     HTMLScriptElement_get_text,
270     HTMLScriptElement_put_defer,
271     HTMLScriptElement_get_defer,
272     HTMLScriptElement_get_readyState,
273     HTMLScriptElement_put_onerror,
274     HTMLScriptElement_get_onerror,
275     HTMLScriptElement_put_type,
276     HTMLScriptElement_get_type
277 };
278
279 static inline HTMLScriptElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
280 {
281     return CONTAINING_RECORD(iface, HTMLScriptElement, element.node);
282 }
283
284 static HRESULT HTMLScriptElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
285 {
286     HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
287
288     *ppv = NULL;
289
290     if(IsEqualGUID(&IID_IUnknown, riid)) {
291         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
292         *ppv = &This->IHTMLScriptElement_iface;
293     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
294         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
295         *ppv = &This->IHTMLScriptElement_iface;
296     }else if(IsEqualGUID(&IID_IHTMLScriptElement, riid)) {
297         TRACE("(%p)->(IID_IHTMLScriptElement %p)\n", This, ppv);
298         *ppv = &This->IHTMLScriptElement_iface;
299     }
300
301     if(*ppv) {
302         IUnknown_AddRef((IUnknown*)*ppv);
303         return S_OK;
304     }
305
306     return HTMLElement_QI(&This->element.node, riid, ppv);
307 }
308
309 static HRESULT HTMLScriptElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
310 {
311     HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
312
313     return IHTMLScriptElement_get_readyState(&This->IHTMLScriptElement_iface, p);
314 }
315
316 static const NodeImplVtbl HTMLScriptElementImplVtbl = {
317     HTMLScriptElement_QI,
318     HTMLElement_destructor,
319     HTMLElement_clone,
320     HTMLElement_handle_event,
321     HTMLElement_get_attr_col,
322     NULL,
323     NULL,
324     NULL,
325     NULL,
326     NULL,
327     HTMLScriptElement_get_readystate
328 };
329
330 static const tid_t HTMLScriptElement_iface_tids[] = {
331     HTMLELEMENT_TIDS,
332     IHTMLScriptElement_tid,
333     0
334 };
335
336 static dispex_static_data_t HTMLScriptElement_dispex = {
337     NULL,
338     DispHTMLScriptElement_tid,
339     NULL,
340     HTMLScriptElement_iface_tids
341 };
342
343 HRESULT HTMLScriptElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
344 {
345     HTMLScriptElement *ret;
346     nsresult nsres;
347
348     ret = heap_alloc_zero(sizeof(HTMLScriptElement));
349     if(!ret)
350         return E_OUTOFMEMORY;
351
352     ret->IHTMLScriptElement_iface.lpVtbl = &HTMLScriptElementVtbl;
353     ret->element.node.vtbl = &HTMLScriptElementImplVtbl;
354
355     HTMLElement_Init(&ret->element, doc, nselem, &HTMLScriptElement_dispex);
356
357     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLScriptElement, (void**)&ret->nsscript);
358
359     /* Share nsscript reference with nsnode */
360     assert(nsres == NS_OK && (nsIDOMNode*)ret->nsscript == ret->element.node.nsnode);
361     nsIDOMNode_Release(ret->element.node.nsnode);
362
363     *elem = &ret->element;
364     return S_OK;
365 }