mshtml: Don't use ITypeInfo for InvokeEx(DISPATCH_PROPERTYPUT) implementation.
[wine] / dlls / mshtml / htmlstyleelem.c
1 /*
2  * Copyright 2010 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
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "winreg.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     IHTMLStyleElement IHTMLStyleElement_iface;
39
40     nsIDOMHTMLStyleElement *nsstyle;
41 } HTMLStyleElement;
42
43 static inline HTMLStyleElement *impl_from_IHTMLStyleElement(IHTMLStyleElement *iface)
44 {
45     return CONTAINING_RECORD(iface, HTMLStyleElement, IHTMLStyleElement_iface);
46 }
47
48 static HRESULT WINAPI HTMLStyleElement_QueryInterface(IHTMLStyleElement *iface,
49         REFIID riid, void **ppv)
50 {
51     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
52
53     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
54 }
55
56 static ULONG WINAPI HTMLStyleElement_AddRef(IHTMLStyleElement *iface)
57 {
58     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
59
60     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
61 }
62
63 static ULONG WINAPI HTMLStyleElement_Release(IHTMLStyleElement *iface)
64 {
65     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
66
67     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
68 }
69
70 static HRESULT WINAPI HTMLStyleElement_GetTypeInfoCount(IHTMLStyleElement *iface, UINT *pctinfo)
71 {
72     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
73     return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
74 }
75
76 static HRESULT WINAPI HTMLStyleElement_GetTypeInfo(IHTMLStyleElement *iface, UINT iTInfo,
77         LCID lcid, ITypeInfo **ppTInfo)
78 {
79     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
80     return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
81             ppTInfo);
82 }
83
84 static HRESULT WINAPI HTMLStyleElement_GetIDsOfNames(IHTMLStyleElement *iface, REFIID riid,
85         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
86 {
87     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
88     return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
89             cNames, lcid, rgDispId);
90 }
91
92 static HRESULT WINAPI HTMLStyleElement_Invoke(IHTMLStyleElement *iface, DISPID dispIdMember,
93         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
94         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
95 {
96     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
97     return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
98             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
99 }
100
101 static HRESULT WINAPI HTMLStyleElement_put_type(IHTMLStyleElement *iface, BSTR v)
102 {
103     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
104     nsAString type_str;
105     nsresult nsres;
106
107     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
108
109     nsAString_InitDepend(&type_str, v);
110     nsres = nsIDOMHTMLStyleElement_SetType(This->nsstyle, &type_str);
111     nsAString_Finish(&type_str);
112     if(NS_FAILED(nsres)) {
113         ERR("SetType failed: %08x\n", nsres);
114         return E_FAIL;
115     }
116
117     return S_OK;
118 }
119
120 static HRESULT WINAPI HTMLStyleElement_get_type(IHTMLStyleElement *iface, BSTR *p)
121 {
122     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
123     nsAString nsstr;
124     nsresult nsres;
125
126     TRACE("(%p)->(%p)\n", This, p);
127
128     nsAString_Init(&nsstr, NULL);
129     nsres = nsIDOMHTMLStyleElement_GetType(This->nsstyle, &nsstr);
130     return return_nsstr(nsres, &nsstr, p);
131 }
132
133 static HRESULT WINAPI HTMLStyleElement_get_readyState(IHTMLStyleElement *iface, BSTR *p)
134 {
135     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
136     FIXME("(%p)->(%p)\n", This, p);
137     return E_NOTIMPL;
138 }
139
140 static HRESULT WINAPI HTMLStyleElement_put_onreadystatechange(IHTMLStyleElement *iface, VARIANT v)
141 {
142     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
143     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
144     return E_NOTIMPL;
145 }
146
147 static HRESULT WINAPI HTMLStyleElement_get_onreadystatechange(IHTMLStyleElement *iface, VARIANT *p)
148 {
149     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
150     FIXME("(%p)->(%p)\n", This, p);
151     return E_NOTIMPL;
152 }
153
154 static HRESULT WINAPI HTMLStyleElement_put_onload(IHTMLStyleElement *iface, VARIANT v)
155 {
156     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
157     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
158     return E_NOTIMPL;
159 }
160
161 static HRESULT WINAPI HTMLStyleElement_get_onload(IHTMLStyleElement *iface, VARIANT *p)
162 {
163     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
164     FIXME("(%p)->(%p)\n", This, p);
165     return E_NOTIMPL;
166 }
167
168 static HRESULT WINAPI HTMLStyleElement_put_onerror(IHTMLStyleElement *iface, VARIANT v)
169 {
170     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
171     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
172     return E_NOTIMPL;
173 }
174
175 static HRESULT WINAPI HTMLStyleElement_get_onerror(IHTMLStyleElement *iface, VARIANT *p)
176 {
177     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
178     FIXME("(%p)->(%p)\n", This, p);
179     return E_NOTIMPL;
180 }
181
182 static HRESULT WINAPI HTMLStyleElement_get_styleSheet(IHTMLStyleElement *iface, IHTMLStyleSheet **p)
183 {
184     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
185     FIXME("(%p)->(%p)\n", This, p);
186     return E_NOTIMPL;
187 }
188
189 static HRESULT WINAPI HTMLStyleElement_put_disabled(IHTMLStyleElement *iface, VARIANT_BOOL v)
190 {
191     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
192     FIXME("(%p)->(%x)\n", This, v);
193     return E_NOTIMPL;
194 }
195
196 static HRESULT WINAPI HTMLStyleElement_get_disabled(IHTMLStyleElement *iface, VARIANT_BOOL *p)
197 {
198     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
199     FIXME("(%p)->(%p)\n", This, p);
200     return E_NOTIMPL;
201 }
202
203 static HRESULT WINAPI HTMLStyleElement_put_media(IHTMLStyleElement *iface, BSTR v)
204 {
205     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
206     nsAString media_str;
207     nsresult nsres;
208
209     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
210
211     nsAString_InitDepend(&media_str, v);
212     nsres = nsIDOMHTMLStyleElement_SetMedia(This->nsstyle, &media_str);
213     nsAString_Finish(&media_str);
214     if(NS_FAILED(nsres)) {
215         ERR("SetMedia failed: %08x\n", nsres);
216         return E_FAIL;
217     }
218
219     return S_OK;
220 }
221
222 static HRESULT WINAPI HTMLStyleElement_get_media(IHTMLStyleElement *iface, BSTR *p)
223 {
224     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
225     nsAString nsstr;
226     nsresult nsres;
227
228     TRACE("(%p)->(%p)\n", This, p);
229
230     nsAString_Init(&nsstr, NULL);
231     nsres = nsIDOMHTMLStyleElement_GetMedia(This->nsstyle, &nsstr);
232     return return_nsstr(nsres, &nsstr, p);
233 }
234
235 static const IHTMLStyleElementVtbl HTMLStyleElementVtbl = {
236     HTMLStyleElement_QueryInterface,
237     HTMLStyleElement_AddRef,
238     HTMLStyleElement_Release,
239     HTMLStyleElement_GetTypeInfoCount,
240     HTMLStyleElement_GetTypeInfo,
241     HTMLStyleElement_GetIDsOfNames,
242     HTMLStyleElement_Invoke,
243     HTMLStyleElement_put_type,
244     HTMLStyleElement_get_type,
245     HTMLStyleElement_get_readyState,
246     HTMLStyleElement_put_onreadystatechange,
247     HTMLStyleElement_get_onreadystatechange,
248     HTMLStyleElement_put_onload,
249     HTMLStyleElement_get_onload,
250     HTMLStyleElement_put_onerror,
251     HTMLStyleElement_get_onerror,
252     HTMLStyleElement_get_styleSheet,
253     HTMLStyleElement_put_disabled,
254     HTMLStyleElement_get_disabled,
255     HTMLStyleElement_put_media,
256     HTMLStyleElement_get_media
257 };
258
259 static inline HTMLStyleElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
260 {
261     return CONTAINING_RECORD(iface, HTMLStyleElement, element.node);
262 }
263
264 static HRESULT HTMLStyleElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
265 {
266     HTMLStyleElement *This = impl_from_HTMLDOMNode(iface);
267
268     if(IsEqualGUID(&IID_IUnknown, riid)) {
269         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
270         *ppv = &This->IHTMLStyleElement_iface;
271     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
272         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
273         *ppv = &This->IHTMLStyleElement_iface;
274     }else if(IsEqualGUID(&IID_IHTMLStyleElement, riid)) {
275         TRACE("(%p)->(IID_IHTMLStyleElement %p)\n", This, ppv);
276         *ppv = &This->IHTMLStyleElement_iface;
277     }else {
278         return HTMLElement_QI(&This->element.node, riid, ppv);
279     }
280
281     IUnknown_AddRef((IUnknown*)*ppv);
282     return S_OK;
283 }
284
285 static void HTMLStyleElement_destructor(HTMLDOMNode *iface)
286 {
287     HTMLStyleElement *This = impl_from_HTMLDOMNode(iface);
288
289     if(This->nsstyle)
290         nsIDOMHTMLStyleElement_Release(This->nsstyle);
291
292     HTMLElement_destructor(&This->element.node);
293 }
294
295 static const NodeImplVtbl HTMLStyleElementImplVtbl = {
296     HTMLStyleElement_QI,
297     HTMLStyleElement_destructor,
298     HTMLElement_clone,
299     HTMLElement_get_attr_col
300 };
301
302 static const tid_t HTMLStyleElement_iface_tids[] = {
303     HTMLELEMENT_TIDS,
304     IHTMLStyleElement_tid,
305     0
306 };
307 static dispex_static_data_t HTMLStyleElement_dispex = {
308     NULL,
309     DispHTMLStyleElement_tid,
310     NULL,
311     HTMLStyleElement_iface_tids
312 };
313
314 HRESULT HTMLStyleElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
315 {
316     HTMLStyleElement *ret;
317     nsresult nsres;
318
319     ret = heap_alloc_zero(sizeof(*ret));
320     if(!ret)
321         return E_OUTOFMEMORY;
322
323     ret->IHTMLStyleElement_iface.lpVtbl = &HTMLStyleElementVtbl;
324     ret->element.node.vtbl = &HTMLStyleElementImplVtbl;
325
326     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLStyleElement, (void**)&ret->nsstyle);
327     if(NS_FAILED(nsres)) {
328         ERR("Could not get nsIDOMHTMLStyleElement iface: %08x\n", nsres);
329         heap_free(ret);
330         return E_FAIL;
331     }
332
333     HTMLElement_Init(&ret->element, doc, nselem, &HTMLStyleElement_dispex);
334     *elem = &ret->element;
335     return S_OK;
336 }