wined3d: Make SRGB write correction working with 1.x shaders in arb.
[wine] / dlls / mshtml / htmlstylesheet.c
1 /*
2  * Copyright 2006 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 "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
31
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
34
35 #include "mshtml_private.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38
39 typedef struct {
40     const IHTMLStyleSheetVtbl *lpHTMLStyleSheetVtbl;
41
42     LONG ref;
43
44     nsIDOMCSSStyleSheet *nsstylesheet;
45 } HTMLStyleSheet;
46
47 typedef struct {
48     const IHTMLStyleSheetsCollectionVtbl *lpHTMLStyleSheetsCollectionVtbl;
49
50     LONG ref;
51
52     nsIDOMStyleSheetList *nslist;
53 } HTMLStyleSheetsCollection;
54
55 #define HTMLSTYLESHEET(x)      ((IHTMLStyleSheet*)             &(x)->lpHTMLStyleSheetVtbl);
56 #define HTMLSTYLESHEETSCOL(x)  ((IHTMLStyleSheetsCollection*)  &(x)->lpHTMLStyleSheetsCollectionVtbl);
57
58 #define HTMLSTYLESHEETSCOL_THIS(iface) \
59     DEFINE_THIS(HTMLStyleSheetsCollection, HTMLStyleSheetsCollection, iface)
60
61 static HRESULT WINAPI HTMLStyleSheetsCollection_QueryInterface(IHTMLStyleSheetsCollection *iface,
62          REFIID riid, void **ppv)
63 {
64     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
65
66     *ppv = NULL;
67
68     if(IsEqualGUID(&IID_IUnknown, riid)) {
69         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
70         *ppv = HTMLSTYLESHEETSCOL(This);
71     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
72         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
73         *ppv = HTMLSTYLESHEETSCOL(This);
74     }else if(IsEqualGUID(&IID_IHTMLStyleSheetsCollection, riid)) {
75         TRACE("(%p)->(IID_IHTMLStyleSheetsCollection %p)\n", This, ppv);
76         *ppv = HTMLSTYLESHEETSCOL(This);
77     }
78
79     if(*ppv) {
80         IUnknown_AddRef((IUnknown*)*ppv);
81         return S_OK;
82     }
83
84     WARN("unsupported %s\n", debugstr_guid(riid));
85     return E_NOINTERFACE;
86 }
87
88 static ULONG WINAPI HTMLStyleSheetsCollection_AddRef(IHTMLStyleSheetsCollection *iface)
89 {
90     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
91     LONG ref = InterlockedIncrement(&This->ref);
92
93     TRACE("(%p) ref=%d\n", This, ref);
94
95     return ref;
96 }
97
98 static ULONG WINAPI HTMLStyleSheetsCollection_Release(IHTMLStyleSheetsCollection *iface)
99 {
100     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
101     LONG ref = InterlockedDecrement(&This->ref);
102
103     TRACE("(%p) ref=%d\n", This, ref);
104
105     if(!ref)
106         mshtml_free(This);
107
108     return ref;
109 }
110
111 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfoCount(IHTMLStyleSheetsCollection *iface,
112         UINT *pctinfo)
113 {
114     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
115     FIXME("(%p)->(%p)\n", This, pctinfo);
116     return E_NOTIMPL;
117 }
118
119 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfo(IHTMLStyleSheetsCollection *iface,
120         UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
121 {
122     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
123     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
124     return E_NOTIMPL;
125 }
126
127 static HRESULT WINAPI HTMLStyleSheetsCollection_GetIDsOfNames(IHTMLStyleSheetsCollection *iface,
128         REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
129 {
130     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
131     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
132           lcid, rgDispId);
133     return E_NOTIMPL;
134 }
135
136 static HRESULT WINAPI HTMLStyleSheetsCollection_Invoke(IHTMLStyleSheetsCollection *iface,
137         DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
138         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
139 {
140     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
141     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
142           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
143     return E_NOTIMPL;
144 }
145
146 static HRESULT WINAPI HTMLStyleSheetsCollection_get_length(IHTMLStyleSheetsCollection *iface,
147         long *p)
148 {
149     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
150     PRUint32 len = 0;
151
152     TRACE("(%p)->(%p)\n", This, p);
153
154     if(This->nslist)
155         nsIDOMStyleSheetList_GetLength(This->nslist, &len);
156
157     *p = len;
158     return S_OK;
159 }
160
161 static HRESULT WINAPI HTMLStyleSheetsCollection_get__newEnum(IHTMLStyleSheetsCollection *iface,
162         IUnknown **p)
163 {
164     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
165     FIXME("(%p)->(%p)\n", This, p);
166     return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI HTMLStyleSheetsCollection_item(IHTMLStyleSheetsCollection *iface,
170         VARIANT *pvarIndex, VARIANT *pvarResult)
171 {
172     HTMLStyleSheetsCollection *This = HTMLSTYLESHEETSCOL_THIS(iface);
173
174     TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
175
176     switch(V_VT(pvarIndex)) {
177     case VT_I4: {
178         nsIDOMStyleSheet *nsstylesheet;
179         nsresult nsres;
180
181         TRACE("index=%d\n", V_I4(pvarIndex));
182
183         nsres = nsIDOMStyleSheetList_Item(This->nslist, V_I4(pvarIndex), &nsstylesheet);
184         if(NS_FAILED(nsres) || !nsstylesheet) {
185             WARN("Item failed: %08x\n", nsres);
186             V_VT(pvarResult) = VT_EMPTY;
187             return E_INVALIDARG;
188         }
189
190         V_VT(pvarResult) = VT_DISPATCH;
191         V_DISPATCH(pvarResult) = (IDispatch*)HTMLStyleSheet_Create(nsstylesheet);
192
193         return S_OK;
194     }
195
196     case VT_BSTR:
197         FIXME("id=%s not implemented\n", debugstr_w(V_BSTR(pvarResult)));
198         return E_NOTIMPL;
199
200     default:
201         WARN("Invalid vt=%d\n", V_VT(pvarIndex));
202     }
203
204     return E_INVALIDARG;
205 }
206
207 #undef HTMLSTYLESHEETSCOL_THIS
208
209 static const IHTMLStyleSheetsCollectionVtbl HTMLStyleSheetsCollectionVtbl = {
210     HTMLStyleSheetsCollection_QueryInterface,
211     HTMLStyleSheetsCollection_AddRef,
212     HTMLStyleSheetsCollection_Release,
213     HTMLStyleSheetsCollection_GetTypeInfoCount,
214     HTMLStyleSheetsCollection_GetTypeInfo,
215     HTMLStyleSheetsCollection_GetIDsOfNames,
216     HTMLStyleSheetsCollection_Invoke,
217     HTMLStyleSheetsCollection_get_length,
218     HTMLStyleSheetsCollection_get__newEnum,
219     HTMLStyleSheetsCollection_item
220 };
221
222 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList *nslist)
223 {
224     HTMLStyleSheetsCollection *ret = mshtml_alloc(sizeof(HTMLStyleSheetsCollection));
225
226     ret->lpHTMLStyleSheetsCollectionVtbl = &HTMLStyleSheetsCollectionVtbl;
227     ret->ref = 1;
228
229     if(nslist)
230         nsIDOMStyleSheetList_AddRef(nslist);
231     ret->nslist = nslist;
232
233     return HTMLSTYLESHEETSCOL(ret);
234 }
235
236 #define HTMLSTYLESHEET_THIS(iface) DEFINE_THIS(HTMLStyleSheet, HTMLStyleSheet, iface)
237
238 static HRESULT WINAPI HTMLStyleSheet_QueryInterface(IHTMLStyleSheet *iface, REFIID riid, void **ppv)
239 {
240     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
241
242     *ppv = NULL;
243
244     if(IsEqualGUID(&IID_IUnknown, riid)) {
245         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
246         *ppv = HTMLSTYLESHEET(This);
247     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
248         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
249         *ppv = HTMLSTYLESHEET(This);
250     }else if(IsEqualGUID(&IID_IHTMLStyleSheet, riid)) {
251         TRACE("(%p)->(IID_IHTMLStyleSheet %p)\n", This, ppv);
252         *ppv = HTMLSTYLESHEET(This);
253     }
254
255     if(*ppv) {
256         IUnknown_AddRef((IUnknown*)*ppv);
257         return S_OK;
258     }
259
260     WARN("unsupported %s\n", debugstr_guid(riid));
261     return E_NOINTERFACE;
262 }
263
264 static ULONG WINAPI HTMLStyleSheet_AddRef(IHTMLStyleSheet *iface)
265 {
266     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
267     LONG ref = InterlockedIncrement(&This->ref);
268
269     TRACE("(%p) ref=%d\n", This, ref);
270
271     return ref;
272 }
273
274 static ULONG WINAPI HTMLStyleSheet_Release(IHTMLStyleSheet *iface)
275 {
276     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
277     LONG ref = InterlockedDecrement(&This->ref);
278
279     TRACE("(%p) ref=%d\n", This, ref);
280
281     if(!ref)
282         mshtml_free(This);
283
284     return ref;
285 }
286
287 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfoCount(IHTMLStyleSheet *iface, UINT *pctinfo)
288 {
289     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
290     FIXME("(%p)->(%p)\n", This, pctinfo);
291     return E_NOTIMPL;
292 }
293
294 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfo(IHTMLStyleSheet *iface, UINT iTInfo,
295                                               LCID lcid, ITypeInfo **ppTInfo)
296 {
297     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
298     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
299     return E_NOTIMPL;
300 }
301
302 static HRESULT WINAPI HTMLStyleSheet_GetIDsOfNames(IHTMLStyleSheet *iface, REFIID riid,
303                                                 LPOLESTR *rgszNames, UINT cNames,
304                                                 LCID lcid, DISPID *rgDispId)
305 {
306     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
307     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
308           lcid, rgDispId);
309     return E_NOTIMPL;
310 }
311
312 static HRESULT WINAPI HTMLStyleSheet_Invoke(IHTMLStyleSheet *iface, DISPID dispIdMember,
313                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
314                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
315 {
316     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
317     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
318           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
319     return E_NOTIMPL;
320 }
321
322 static HRESULT WINAPI HTMLStyleSheet_put_title(IHTMLStyleSheet *iface, BSTR v)
323 {
324     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
325     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
326     return E_NOTIMPL;
327 }
328
329 static HRESULT WINAPI HTMLStyleSheet_get_title(IHTMLStyleSheet *iface, BSTR *p)
330 {
331     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
332     FIXME("(%p)->(%p)\n", This, p);
333     return E_NOTIMPL;
334 }
335
336 static HRESULT WINAPI HTMLStyleSheet_get_parentStyleSheet(IHTMLStyleSheet *iface,
337                                                           IHTMLStyleSheet **p)
338 {
339     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
340     FIXME("(%p)->(%p)\n", This, p);
341     return E_NOTIMPL;
342 }
343
344 static HRESULT WINAPI HTMLStyleSheet_get_owningElement(IHTMLStyleSheet *iface, IHTMLElement **p)
345 {
346     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
347     FIXME("(%p)->(%p)\n", This, p);
348     return E_NOTIMPL;
349 }
350
351 static HRESULT WINAPI HTMLStyleSheet_put_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL v)
352 {
353     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
354     FIXME("(%p)->(%x)\n", This, v);
355     return E_NOTIMPL;
356 }
357
358 static HRESULT WINAPI HTMLStyleSheet_get_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
359 {
360     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
361     FIXME("(%p)->(%p)\n", This, p);
362     return E_NOTIMPL;
363 }
364
365 static HRESULT WINAPI HTMLStyleSheet_get_readOnly(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
366 {
367     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
368     FIXME("(%p)->(%p)\n", This, p);
369     return E_NOTIMPL;
370 }
371
372 static HRESULT WINAPI HTMLStyleSheet_get_imports(IHTMLStyleSheet *iface,
373                                                  IHTMLStyleSheetsCollection **p)
374 {
375     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
376     FIXME("(%p)->(%p)\n", This, p);
377     return E_NOTIMPL;
378 }
379
380 static HRESULT WINAPI HTMLStyleSheet_put_href(IHTMLStyleSheet *iface, BSTR v)
381 {
382     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
383     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
384     return E_NOTIMPL;
385 }
386
387 static HRESULT WINAPI HTMLStyleSheet_get_href(IHTMLStyleSheet *iface, BSTR *p)
388 {
389     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
390     FIXME("(%p)->(%p)\n", This, p);
391     return E_NOTIMPL;
392 }
393
394 static HRESULT WINAPI HTMLStyleSheet_get_type(IHTMLStyleSheet *iface, BSTR *p)
395 {
396     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
397     FIXME("(%p)->(%p)\n", This, p);
398     return E_NOTIMPL;
399 }
400
401 static HRESULT WINAPI HTMLStyleSheet_get_id(IHTMLStyleSheet *iface, BSTR *p)
402 {
403     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
404     FIXME("(%p)->(%p)\n", This, p);
405     return E_NOTIMPL;
406 }
407
408 static HRESULT WINAPI HTMLStyleSheet_addImport(IHTMLStyleSheet *iface, BSTR bstrURL,
409                                                long lIndex, long *plIndex)
410 {
411     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
412     FIXME("(%p)->(%s %ld %p)\n", This, debugstr_w(bstrURL), lIndex, plIndex);
413     return E_NOTIMPL;
414 }
415
416 static HRESULT WINAPI HTMLStyleSheet_addRule(IHTMLStyleSheet *iface, BSTR bstrSelector,
417                                              BSTR bstrStyle, long lIndex, long *plIndex)
418 {
419     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
420     FIXME("(%p)->(%s %s %ld %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
421           lIndex, plIndex);
422     return E_NOTIMPL;
423 }
424
425 static HRESULT WINAPI HTMLStyleSheet_removeImport(IHTMLStyleSheet *iface, long lIndex)
426 {
427     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
428     FIXME("(%p)->(%ld)\n", This, lIndex);
429     return E_NOTIMPL;
430 }
431
432 static HRESULT WINAPI HTMLStyleSheet_removeRule(IHTMLStyleSheet *iface, long lIndex)
433 {
434     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
435     FIXME("(%p)->(%ld)\n", This, lIndex);
436     return E_NOTIMPL;
437 }
438
439 static HRESULT WINAPI HTMLStyleSheet_put_media(IHTMLStyleSheet *iface, BSTR v)
440 {
441     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
442     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
443     return E_NOTIMPL;
444 }
445
446 static HRESULT WINAPI HTMLStyleSheet_get_media(IHTMLStyleSheet *iface, BSTR *p)
447 {
448     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
449     FIXME("(%p)->(%p)\n", This, p);
450     return E_NOTIMPL;
451 }
452
453 static HRESULT WINAPI HTMLStyleSheet_put_cssText(IHTMLStyleSheet *iface, BSTR v)
454 {
455     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
456     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
457     return E_NOTIMPL;
458 }
459
460 static HRESULT WINAPI HTMLStyleSheet_get_cssText(IHTMLStyleSheet *iface, BSTR *p)
461 {
462     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
463     FIXME("(%p)->(%p)\n", This, p);
464     return E_NOTIMPL;
465 }
466
467 static HRESULT WINAPI HTMLStyleSheet_get_rules(IHTMLStyleSheet *iface,
468                                                IHTMLStyleSheetRulesCollection **p)
469 {
470     HTMLStyleSheet *This = HTMLSTYLESHEET_THIS(iface);
471     FIXME("(%p)->(%p)\n", This, p);
472     return E_NOTIMPL;
473 }
474
475 static const IHTMLStyleSheetVtbl HTMLStyleSheetVtbl = {
476     HTMLStyleSheet_QueryInterface,
477     HTMLStyleSheet_AddRef,
478     HTMLStyleSheet_Release,
479     HTMLStyleSheet_GetTypeInfoCount,
480     HTMLStyleSheet_GetTypeInfo,
481     HTMLStyleSheet_GetIDsOfNames,
482     HTMLStyleSheet_Invoke,
483     HTMLStyleSheet_put_title,
484     HTMLStyleSheet_get_title,
485     HTMLStyleSheet_get_parentStyleSheet,
486     HTMLStyleSheet_get_owningElement,
487     HTMLStyleSheet_put_disabled,
488     HTMLStyleSheet_get_disabled,
489     HTMLStyleSheet_get_readOnly,
490     HTMLStyleSheet_get_imports,
491     HTMLStyleSheet_put_href,
492     HTMLStyleSheet_get_href,
493     HTMLStyleSheet_get_type,
494     HTMLStyleSheet_get_id,
495     HTMLStyleSheet_addImport,
496     HTMLStyleSheet_addRule,
497     HTMLStyleSheet_removeImport,
498     HTMLStyleSheet_removeRule,
499     HTMLStyleSheet_put_media,
500     HTMLStyleSheet_get_media,
501     HTMLStyleSheet_put_cssText,
502     HTMLStyleSheet_get_cssText,
503     HTMLStyleSheet_get_rules
504 };
505
506 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet *nsstylesheet)
507 {
508     HTMLStyleSheet *ret = mshtml_alloc(sizeof(HTMLStyleSheet));
509     nsresult nsres;
510
511     ret->lpHTMLStyleSheetVtbl = &HTMLStyleSheetVtbl;
512     ret->ref = 1;
513     ret->nsstylesheet = NULL;
514
515     if(nsstylesheet) {
516         nsres = nsIDOMStyleSheet_QueryInterface(nsstylesheet, &IID_nsIDOMCSSStyleSheet,
517                 (void**)&ret->nsstylesheet);
518         if(NS_FAILED(nsres))
519             ERR("Could not get nsICSSStyleSheet interface: %08x\n", nsres);
520     }
521
522     return HTMLSTYLESHEET(ret);
523 }