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