directmanipulation: Return S_OK form viewport_SetViewportOptions stub.
[wine/zf.git] / dlls / mshtml / htmlstylesheet.c
bloba4e3254100b94f4a974ef215239d3959f2318a63
1 /*
2 * Copyright 2006 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>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 struct HTMLStyleSheet {
36 DispatchEx dispex;
37 IHTMLStyleSheet IHTMLStyleSheet_iface;
39 LONG ref;
41 nsIDOMCSSStyleSheet *nsstylesheet;
44 struct HTMLStyleSheetsCollection {
45 DispatchEx dispex;
46 IHTMLStyleSheetsCollection IHTMLStyleSheetsCollection_iface;
48 LONG ref;
50 nsIDOMStyleSheetList *nslist;
53 struct HTMLStyleSheetRulesCollection {
54 DispatchEx dispex;
55 IHTMLStyleSheetRulesCollection IHTMLStyleSheetRulesCollection_iface;
57 LONG ref;
59 nsIDOMCSSRuleList *nslist;
62 struct HTMLStyleSheetRule {
63 DispatchEx dispex;
64 IHTMLStyleSheetRule IHTMLStyleSheetRule_iface;
66 LONG ref;
68 nsIDOMCSSRule *nsstylesheetrule;
71 static inline HTMLStyleSheetRule *impl_from_IHTMLStyleSheetRule(IHTMLStyleSheetRule *iface)
73 return CONTAINING_RECORD(iface, HTMLStyleSheetRule, IHTMLStyleSheetRule_iface);
76 static HRESULT WINAPI HTMLStyleSheetRule_QueryInterface(IHTMLStyleSheetRule *iface,
77 REFIID riid, void **ppv)
79 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
81 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
83 if (IsEqualGUID(&IID_IUnknown, riid))
84 *ppv = &This->IHTMLStyleSheetRule_iface;
85 else if (IsEqualGUID(&IID_IHTMLStyleSheetRule, riid))
86 *ppv = &This->IHTMLStyleSheetRule_iface;
87 else if (dispex_query_interface(&This->dispex, riid, ppv))
88 return *ppv ? S_OK : E_NOINTERFACE;
89 else
91 *ppv = NULL;
92 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
93 return E_NOINTERFACE;
96 IUnknown_AddRef((IUnknown *)*ppv);
97 return S_OK;
100 static ULONG WINAPI HTMLStyleSheetRule_AddRef(IHTMLStyleSheetRule *iface)
102 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
103 LONG ref = InterlockedIncrement(&This->ref);
105 TRACE("(%p) ref=%d\n", This, ref);
107 return ref;
110 static ULONG WINAPI HTMLStyleSheetRule_Release(IHTMLStyleSheetRule *iface)
112 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
113 LONG ref = InterlockedDecrement(&This->ref);
115 TRACE("(%p) ref=%d\n", This, ref);
117 if(!ref) {
118 release_dispex(&This->dispex);
119 if(This->nsstylesheetrule)
120 nsIDOMCSSRule_Release(This->nsstylesheetrule);
121 heap_free(This);
124 return ref;
127 static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfoCount(
128 IHTMLStyleSheetRule *iface, UINT *pctinfo)
130 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
131 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
134 static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfo(IHTMLStyleSheetRule *iface,
135 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
137 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
138 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
141 static HRESULT WINAPI HTMLStyleSheetRule_GetIDsOfNames(IHTMLStyleSheetRule *iface,
142 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
144 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
145 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
146 lcid, rgDispId);
149 static HRESULT WINAPI HTMLStyleSheetRule_Invoke(IHTMLStyleSheetRule *iface,
150 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
151 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
153 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
154 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
155 pDispParams, pVarResult, pExcepInfo, puArgErr);
158 static HRESULT WINAPI HTMLStyleSheetRule_put_selectorText(IHTMLStyleSheetRule *iface, BSTR v)
160 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
161 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
162 return E_NOTIMPL;
165 static HRESULT WINAPI HTMLStyleSheetRule_get_selectorText(IHTMLStyleSheetRule *iface, BSTR *p)
167 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
168 FIXME("(%p)->(%p)\n", This, p);
169 return E_NOTIMPL;
172 static HRESULT WINAPI HTMLStyleSheetRule_get_style(IHTMLStyleSheetRule *iface, IHTMLRuleStyle **p)
174 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
175 FIXME("(%p)->(%p)\n", This, p);
176 return E_NOTIMPL;
179 static HRESULT WINAPI HTMLStyleSheetRule_get_readOnly(IHTMLStyleSheetRule *iface, VARIANT_BOOL *p)
181 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
182 FIXME("(%p)->(%p)\n", This, p);
183 return E_NOTIMPL;
186 static const IHTMLStyleSheetRuleVtbl HTMLStyleSheetRuleVtbl = {
187 HTMLStyleSheetRule_QueryInterface,
188 HTMLStyleSheetRule_AddRef,
189 HTMLStyleSheetRule_Release,
190 HTMLStyleSheetRule_GetTypeInfoCount,
191 HTMLStyleSheetRule_GetTypeInfo,
192 HTMLStyleSheetRule_GetIDsOfNames,
193 HTMLStyleSheetRule_Invoke,
194 HTMLStyleSheetRule_put_selectorText,
195 HTMLStyleSheetRule_get_selectorText,
196 HTMLStyleSheetRule_get_style,
197 HTMLStyleSheetRule_get_readOnly
200 static const tid_t HTMLStyleSheetRule_iface_tids[] = {
201 IHTMLStyleSheetRule_tid,
204 static dispex_static_data_t HTMLStyleSheetRule_dispex = {
205 NULL,
206 DispHTMLStyleSheetRule_tid,
207 HTMLStyleSheetRule_iface_tids
210 static IHTMLStyleSheetRule *HTMLStyleSheetRule_Create(nsIDOMCSSRule *nsstylesheetrule)
212 HTMLStyleSheetRule *ret;
213 nsresult nsres;
215 if(!(ret = heap_alloc(sizeof(*ret))))
216 return NULL;
218 ret->IHTMLStyleSheetRule_iface.lpVtbl = &HTMLStyleSheetRuleVtbl;
219 ret->ref = 1;
220 ret->nsstylesheetrule = NULL;
222 init_dispex(&ret->dispex, (IUnknown *)&ret->IHTMLStyleSheetRule_iface, &HTMLStyleSheetRule_dispex);
224 if (nsstylesheetrule)
226 nsres = nsIDOMCSSRule_QueryInterface(nsstylesheetrule, &IID_nsIDOMCSSRule,
227 (void **)&ret->nsstylesheetrule);
228 if (NS_FAILED(nsres))
229 ERR("Could not get nsIDOMCSSRule interface: %08x\n", nsres);
232 return &ret->IHTMLStyleSheetRule_iface;
235 static inline HTMLStyleSheetRulesCollection *impl_from_IHTMLStyleSheetRulesCollection(IHTMLStyleSheetRulesCollection *iface)
237 return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, IHTMLStyleSheetRulesCollection_iface);
240 static HRESULT WINAPI HTMLStyleSheetRulesCollection_QueryInterface(IHTMLStyleSheetRulesCollection *iface,
241 REFIID riid, void **ppv)
243 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
245 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
247 if(IsEqualGUID(&IID_IUnknown, riid)) {
248 *ppv = &This->IHTMLStyleSheetRulesCollection_iface;
249 }else if(IsEqualGUID(&IID_IHTMLStyleSheetRulesCollection, riid)) {
250 *ppv = &This->IHTMLStyleSheetRulesCollection_iface;
251 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
252 return *ppv ? S_OK : E_NOINTERFACE;
253 }else {
254 *ppv = NULL;
255 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
256 return E_NOINTERFACE;
259 IUnknown_AddRef((IUnknown*)*ppv);
260 return S_OK;
263 static ULONG WINAPI HTMLStyleSheetRulesCollection_AddRef(IHTMLStyleSheetRulesCollection *iface)
265 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
266 LONG ref = InterlockedIncrement(&This->ref);
268 TRACE("(%p) ref=%d\n", This, ref);
270 return ref;
273 static ULONG WINAPI HTMLStyleSheetRulesCollection_Release(IHTMLStyleSheetRulesCollection *iface)
275 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
276 LONG ref = InterlockedDecrement(&This->ref);
278 TRACE("(%p) ref=%d\n", This, ref);
280 if(!ref) {
281 release_dispex(&This->dispex);
282 if(This->nslist)
283 nsIDOMCSSRuleList_Release(This->nslist);
284 heap_free(This);
287 return ref;
290 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfoCount(
291 IHTMLStyleSheetRulesCollection *iface, UINT *pctinfo)
293 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
294 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
297 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfo(IHTMLStyleSheetRulesCollection *iface,
298 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
300 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
301 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
304 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetIDsOfNames(IHTMLStyleSheetRulesCollection *iface,
305 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
307 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
308 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
309 lcid, rgDispId);
312 static HRESULT WINAPI HTMLStyleSheetRulesCollection_Invoke(IHTMLStyleSheetRulesCollection *iface,
313 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
314 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
316 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
317 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
318 pDispParams, pVarResult, pExcepInfo, puArgErr);
321 static HRESULT WINAPI HTMLStyleSheetRulesCollection_get_length(IHTMLStyleSheetRulesCollection *iface,
322 LONG *p)
324 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
325 UINT32 len = 0;
327 TRACE("(%p)->(%p)\n", This, p);
329 if(This->nslist) {
330 nsresult nsres;
332 nsres = nsIDOMCSSRuleList_GetLength(This->nslist, &len);
333 if(NS_FAILED(nsres))
334 ERR("GetLength failed: %08x\n", nsres);
337 *p = len;
338 return S_OK;
341 static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCollection *iface,
342 LONG index, IHTMLStyleSheetRule **ppHTMLStyleSheetRule)
344 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
345 nsIDOMCSSRule *nsstylesheetrule;
346 nsresult nsres;
348 TRACE("(%p)->(%d %p)\n", This, index, ppHTMLStyleSheetRule);
350 nsres = nsIDOMCSSRuleList_Item(This->nslist, index, &nsstylesheetrule);
351 if(NS_FAILED(nsres))
352 return map_nsresult(nsres);
353 if(!nsstylesheetrule)
354 return E_INVALIDARG;
356 *ppHTMLStyleSheetRule = HTMLStyleSheetRule_Create(nsstylesheetrule);
357 return *ppHTMLStyleSheetRule ? S_OK : E_OUTOFMEMORY;
360 static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
361 HTMLStyleSheetRulesCollection_QueryInterface,
362 HTMLStyleSheetRulesCollection_AddRef,
363 HTMLStyleSheetRulesCollection_Release,
364 HTMLStyleSheetRulesCollection_GetTypeInfoCount,
365 HTMLStyleSheetRulesCollection_GetTypeInfo,
366 HTMLStyleSheetRulesCollection_GetIDsOfNames,
367 HTMLStyleSheetRulesCollection_Invoke,
368 HTMLStyleSheetRulesCollection_get_length,
369 HTMLStyleSheetRulesCollection_item
372 static const tid_t HTMLStyleSheetRulesCollection_iface_tids[] = {
373 IHTMLStyleSheetRulesCollection_tid,
376 static dispex_static_data_t HTMLStyleSheetRulesCollection_dispex = {
377 NULL,
378 DispHTMLStyleSheetRulesCollection_tid,
379 HTMLStyleSheetRulesCollection_iface_tids
382 static IHTMLStyleSheetRulesCollection *HTMLStyleSheetRulesCollection_Create(nsIDOMCSSRuleList *nslist)
384 HTMLStyleSheetRulesCollection *ret;
386 ret = heap_alloc(sizeof(*ret));
387 ret->IHTMLStyleSheetRulesCollection_iface.lpVtbl = &HTMLStyleSheetRulesCollectionVtbl;
388 ret->ref = 1;
389 ret->nslist = nslist;
391 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLStyleSheetRulesCollection_iface, &HTMLStyleSheetRulesCollection_dispex);
393 if(nslist)
394 nsIDOMCSSRuleList_AddRef(nslist);
396 return &ret->IHTMLStyleSheetRulesCollection_iface;
399 static inline HTMLStyleSheetsCollection *impl_from_IHTMLStyleSheetsCollection(IHTMLStyleSheetsCollection *iface)
401 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, IHTMLStyleSheetsCollection_iface);
404 static HRESULT WINAPI HTMLStyleSheetsCollection_QueryInterface(IHTMLStyleSheetsCollection *iface,
405 REFIID riid, void **ppv)
407 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
409 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
411 if(IsEqualGUID(&IID_IUnknown, riid)) {
412 *ppv = &This->IHTMLStyleSheetsCollection_iface;
413 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
414 *ppv = &This->IHTMLStyleSheetsCollection_iface;
415 }else if(IsEqualGUID(&IID_IHTMLStyleSheetsCollection, riid)) {
416 *ppv = &This->IHTMLStyleSheetsCollection_iface;
417 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
418 return *ppv ? S_OK : E_NOINTERFACE;
419 }else {
420 *ppv = NULL;
421 WARN("unsupported %s\n", debugstr_mshtml_guid(riid));
422 return E_NOINTERFACE;
425 IUnknown_AddRef((IUnknown*)*ppv);
426 return S_OK;
429 static ULONG WINAPI HTMLStyleSheetsCollection_AddRef(IHTMLStyleSheetsCollection *iface)
431 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
432 LONG ref = InterlockedIncrement(&This->ref);
434 TRACE("(%p) ref=%d\n", This, ref);
436 return ref;
439 static ULONG WINAPI HTMLStyleSheetsCollection_Release(IHTMLStyleSheetsCollection *iface)
441 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
442 LONG ref = InterlockedDecrement(&This->ref);
444 TRACE("(%p) ref=%d\n", This, ref);
446 if(!ref) {
447 release_dispex(&This->dispex);
448 if(This->nslist)
449 nsIDOMStyleSheetList_Release(This->nslist);
450 heap_free(This);
453 return ref;
456 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfoCount(IHTMLStyleSheetsCollection *iface,
457 UINT *pctinfo)
459 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
460 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
463 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfo(IHTMLStyleSheetsCollection *iface,
464 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
466 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
467 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
470 static HRESULT WINAPI HTMLStyleSheetsCollection_GetIDsOfNames(IHTMLStyleSheetsCollection *iface,
471 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
473 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
474 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
475 lcid, rgDispId);
478 static HRESULT WINAPI HTMLStyleSheetsCollection_Invoke(IHTMLStyleSheetsCollection *iface,
479 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
480 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
482 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
483 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
484 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
487 static HRESULT WINAPI HTMLStyleSheetsCollection_get_length(IHTMLStyleSheetsCollection *iface,
488 LONG *p)
490 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
491 UINT32 len = 0;
493 TRACE("(%p)->(%p)\n", This, p);
495 if(This->nslist)
496 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
498 *p = len;
499 return S_OK;
502 static HRESULT WINAPI HTMLStyleSheetsCollection_get__newEnum(IHTMLStyleSheetsCollection *iface,
503 IUnknown **p)
505 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
506 FIXME("(%p)->(%p)\n", This, p);
507 return E_NOTIMPL;
510 static HRESULT WINAPI HTMLStyleSheetsCollection_item(IHTMLStyleSheetsCollection *iface,
511 VARIANT *pvarIndex, VARIANT *pvarResult)
513 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
515 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(pvarIndex), pvarResult);
517 switch(V_VT(pvarIndex)) {
518 case VT_I4: {
519 nsIDOMStyleSheet *nsstylesheet;
520 nsresult nsres;
522 TRACE("index=%d\n", V_I4(pvarIndex));
524 nsres = nsIDOMStyleSheetList_Item(This->nslist, V_I4(pvarIndex), &nsstylesheet);
525 if(NS_FAILED(nsres) || !nsstylesheet) {
526 WARN("Item failed: %08x\n", nsres);
527 V_VT(pvarResult) = VT_EMPTY;
528 return E_INVALIDARG;
531 V_VT(pvarResult) = VT_DISPATCH;
532 V_DISPATCH(pvarResult) = (IDispatch*)HTMLStyleSheet_Create(nsstylesheet);
534 return S_OK;
537 case VT_BSTR:
538 FIXME("id=%s not implemented\n", debugstr_w(V_BSTR(pvarResult)));
539 return E_NOTIMPL;
541 default:
542 WARN("Invalid index %s\n", debugstr_variant(pvarIndex));
545 return E_INVALIDARG;
548 static const IHTMLStyleSheetsCollectionVtbl HTMLStyleSheetsCollectionVtbl = {
549 HTMLStyleSheetsCollection_QueryInterface,
550 HTMLStyleSheetsCollection_AddRef,
551 HTMLStyleSheetsCollection_Release,
552 HTMLStyleSheetsCollection_GetTypeInfoCount,
553 HTMLStyleSheetsCollection_GetTypeInfo,
554 HTMLStyleSheetsCollection_GetIDsOfNames,
555 HTMLStyleSheetsCollection_Invoke,
556 HTMLStyleSheetsCollection_get_length,
557 HTMLStyleSheetsCollection_get__newEnum,
558 HTMLStyleSheetsCollection_item
561 static const tid_t HTMLStyleSheetsCollection_iface_tids[] = {
562 IHTMLStyleSheetsCollection_tid,
565 static dispex_static_data_t HTMLStyleSheetsCollection_dispex = {
566 NULL,
567 DispHTMLStyleSheetsCollection_tid,
568 HTMLStyleSheetsCollection_iface_tids
571 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList *nslist)
573 HTMLStyleSheetsCollection *ret = heap_alloc(sizeof(HTMLStyleSheetsCollection));
575 ret->IHTMLStyleSheetsCollection_iface.lpVtbl = &HTMLStyleSheetsCollectionVtbl;
576 ret->ref = 1;
578 if(nslist)
579 nsIDOMStyleSheetList_AddRef(nslist);
580 ret->nslist = nslist;
582 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLStyleSheetsCollection_iface,
583 &HTMLStyleSheetsCollection_dispex);
585 return &ret->IHTMLStyleSheetsCollection_iface;
588 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet(IHTMLStyleSheet *iface)
590 return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet_iface);
593 static HRESULT WINAPI HTMLStyleSheet_QueryInterface(IHTMLStyleSheet *iface, REFIID riid, void **ppv)
595 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
597 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
599 if(IsEqualGUID(&IID_IUnknown, riid)) {
600 *ppv = &This->IHTMLStyleSheet_iface;
601 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
602 *ppv = &This->IHTMLStyleSheet_iface;
603 }else if(IsEqualGUID(&IID_IHTMLStyleSheet, riid)) {
604 *ppv = &This->IHTMLStyleSheet_iface;
605 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
606 return *ppv ? S_OK : E_NOINTERFACE;
607 }else {
608 *ppv = NULL;
609 WARN("unsupported %s\n", debugstr_mshtml_guid(riid));
610 return E_NOINTERFACE;
613 IUnknown_AddRef((IUnknown*)*ppv);
614 return S_OK;
617 static ULONG WINAPI HTMLStyleSheet_AddRef(IHTMLStyleSheet *iface)
619 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
620 LONG ref = InterlockedIncrement(&This->ref);
622 TRACE("(%p) ref=%d\n", This, ref);
624 return ref;
627 static ULONG WINAPI HTMLStyleSheet_Release(IHTMLStyleSheet *iface)
629 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
630 LONG ref = InterlockedDecrement(&This->ref);
632 TRACE("(%p) ref=%d\n", This, ref);
634 if(!ref) {
635 release_dispex(&This->dispex);
636 if(This->nsstylesheet)
637 nsIDOMCSSStyleSheet_Release(This->nsstylesheet);
638 heap_free(This);
641 return ref;
644 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfoCount(IHTMLStyleSheet *iface, UINT *pctinfo)
646 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
647 TRACE("(%p)->(%p)\n", This, pctinfo);
648 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
651 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfo(IHTMLStyleSheet *iface, UINT iTInfo,
652 LCID lcid, ITypeInfo **ppTInfo)
654 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
655 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
658 static HRESULT WINAPI HTMLStyleSheet_GetIDsOfNames(IHTMLStyleSheet *iface, REFIID riid,
659 LPOLESTR *rgszNames, UINT cNames,
660 LCID lcid, DISPID *rgDispId)
662 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
663 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
666 static HRESULT WINAPI HTMLStyleSheet_Invoke(IHTMLStyleSheet *iface, DISPID dispIdMember,
667 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
668 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
670 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
671 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags, pDispParams,
672 pVarResult, pExcepInfo, puArgErr);
675 static HRESULT WINAPI HTMLStyleSheet_put_title(IHTMLStyleSheet *iface, BSTR v)
677 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
678 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
679 return E_NOTIMPL;
682 static HRESULT WINAPI HTMLStyleSheet_get_title(IHTMLStyleSheet *iface, BSTR *p)
684 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
685 FIXME("(%p)->(%p)\n", This, p);
686 return E_NOTIMPL;
689 static HRESULT WINAPI HTMLStyleSheet_get_parentStyleSheet(IHTMLStyleSheet *iface,
690 IHTMLStyleSheet **p)
692 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
693 FIXME("(%p)->(%p)\n", This, p);
694 return E_NOTIMPL;
697 static HRESULT WINAPI HTMLStyleSheet_get_owningElement(IHTMLStyleSheet *iface, IHTMLElement **p)
699 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
700 FIXME("(%p)->(%p)\n", This, p);
701 return E_NOTIMPL;
704 static HRESULT WINAPI HTMLStyleSheet_put_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL v)
706 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
707 FIXME("(%p)->(%x)\n", This, v);
708 return E_NOTIMPL;
711 static HRESULT WINAPI HTMLStyleSheet_get_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
713 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
714 FIXME("(%p)->(%p)\n", This, p);
715 return E_NOTIMPL;
718 static HRESULT WINAPI HTMLStyleSheet_get_readOnly(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
720 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
721 FIXME("(%p)->(%p)\n", This, p);
722 return E_NOTIMPL;
725 static HRESULT WINAPI HTMLStyleSheet_get_imports(IHTMLStyleSheet *iface,
726 IHTMLStyleSheetsCollection **p)
728 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
729 FIXME("(%p)->(%p)\n", This, p);
730 return E_NOTIMPL;
733 static HRESULT WINAPI HTMLStyleSheet_put_href(IHTMLStyleSheet *iface, BSTR v)
735 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
736 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
737 return E_NOTIMPL;
740 static HRESULT WINAPI HTMLStyleSheet_get_href(IHTMLStyleSheet *iface, BSTR *p)
742 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
743 nsAString href_str;
744 nsresult nsres;
746 TRACE("(%p)->(%p)\n", This, p);
748 nsAString_Init(&href_str, NULL);
749 nsres = nsIDOMCSSStyleSheet_GetHref(This->nsstylesheet, &href_str);
750 return return_nsstr(nsres, &href_str, p);
753 static HRESULT WINAPI HTMLStyleSheet_get_type(IHTMLStyleSheet *iface, BSTR *p)
755 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
756 FIXME("(%p)->(%p)\n", This, p);
757 return E_NOTIMPL;
760 static HRESULT WINAPI HTMLStyleSheet_get_id(IHTMLStyleSheet *iface, BSTR *p)
762 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
763 FIXME("(%p)->(%p)\n", This, p);
764 return E_NOTIMPL;
767 static HRESULT WINAPI HTMLStyleSheet_addImport(IHTMLStyleSheet *iface, BSTR bstrURL,
768 LONG lIndex, LONG *plIndex)
770 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
771 FIXME("(%p)->(%s %d %p)\n", This, debugstr_w(bstrURL), lIndex, plIndex);
772 return E_NOTIMPL;
775 static HRESULT WINAPI HTMLStyleSheet_addRule(IHTMLStyleSheet *iface, BSTR bstrSelector,
776 BSTR bstrStyle, LONG lIndex, LONG *plIndex)
778 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
779 FIXME("(%p)->(%s %s %d %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
780 lIndex, plIndex);
781 return E_NOTIMPL;
784 static HRESULT WINAPI HTMLStyleSheet_removeImport(IHTMLStyleSheet *iface, LONG lIndex)
786 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
787 FIXME("(%p)->(%d)\n", This, lIndex);
788 return E_NOTIMPL;
791 static HRESULT WINAPI HTMLStyleSheet_removeRule(IHTMLStyleSheet *iface, LONG lIndex)
793 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
794 FIXME("(%p)->(%d)\n", This, lIndex);
795 return E_NOTIMPL;
798 static HRESULT WINAPI HTMLStyleSheet_put_media(IHTMLStyleSheet *iface, BSTR v)
800 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
801 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
802 return E_NOTIMPL;
805 static HRESULT WINAPI HTMLStyleSheet_get_media(IHTMLStyleSheet *iface, BSTR *p)
807 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
808 FIXME("(%p)->(%p)\n", This, p);
809 return E_NOTIMPL;
812 static HRESULT WINAPI HTMLStyleSheet_put_cssText(IHTMLStyleSheet *iface, BSTR v)
814 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
815 nsresult nsres;
817 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
819 do {
820 nsres = nsIDOMCSSStyleSheet_DeleteRule(This->nsstylesheet, 0);
821 }while(NS_SUCCEEDED(nsres));
823 if(v && *v) {
824 nsAString nsstr;
825 UINT32 idx;
827 /* FIXME: This won't work for multiple rules in the string. */
828 nsAString_InitDepend(&nsstr, v);
829 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, 0, &idx);
830 nsAString_Finish(&nsstr);
831 if(NS_FAILED(nsres)) {
832 FIXME("InsertRule failed for string %s. Probably multiple rules passed.\n", debugstr_w(v));
833 return E_FAIL;
837 return S_OK;
840 static HRESULT WINAPI HTMLStyleSheet_get_cssText(IHTMLStyleSheet *iface, BSTR *p)
842 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
843 nsIDOMCSSRuleList *nslist = NULL;
844 nsIDOMCSSRule *nsrule;
845 nsAString nsstr;
846 UINT32 len;
847 nsresult nsres;
849 TRACE("(%p)->(%p)\n", This, p);
851 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
852 if(NS_FAILED(nsres)) {
853 ERR("GetCssRules failed: %08x\n", nsres);
854 return E_FAIL;
857 nsres = nsIDOMCSSRuleList_GetLength(nslist, &len);
858 assert(nsres == NS_OK);
860 if(len) {
861 nsres = nsIDOMCSSRuleList_Item(nslist, 0, &nsrule);
862 if(NS_FAILED(nsres))
863 ERR("Item failed: %08x\n", nsres);
866 nsIDOMCSSRuleList_Release(nslist);
867 if(NS_FAILED(nsres))
868 return E_FAIL;
870 if(!len) {
871 *p = NULL;
872 return S_OK;
875 nsAString_Init(&nsstr, NULL);
876 nsres = nsIDOMCSSRule_GetCssText(nsrule, &nsstr);
877 nsIDOMCSSRule_Release(nsrule);
878 return return_nsstr(nsres, &nsstr, p);
881 static HRESULT WINAPI HTMLStyleSheet_get_rules(IHTMLStyleSheet *iface,
882 IHTMLStyleSheetRulesCollection **p)
884 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
885 nsIDOMCSSRuleList *nslist = NULL;
886 nsresult nsres;
888 TRACE("(%p)->(%p)\n", This, p);
890 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
891 if(NS_FAILED(nsres)) {
892 ERR("GetCssRules failed: %08x\n", nsres);
893 return E_FAIL;
896 *p = HTMLStyleSheetRulesCollection_Create(nslist);
897 return S_OK;
900 static const IHTMLStyleSheetVtbl HTMLStyleSheetVtbl = {
901 HTMLStyleSheet_QueryInterface,
902 HTMLStyleSheet_AddRef,
903 HTMLStyleSheet_Release,
904 HTMLStyleSheet_GetTypeInfoCount,
905 HTMLStyleSheet_GetTypeInfo,
906 HTMLStyleSheet_GetIDsOfNames,
907 HTMLStyleSheet_Invoke,
908 HTMLStyleSheet_put_title,
909 HTMLStyleSheet_get_title,
910 HTMLStyleSheet_get_parentStyleSheet,
911 HTMLStyleSheet_get_owningElement,
912 HTMLStyleSheet_put_disabled,
913 HTMLStyleSheet_get_disabled,
914 HTMLStyleSheet_get_readOnly,
915 HTMLStyleSheet_get_imports,
916 HTMLStyleSheet_put_href,
917 HTMLStyleSheet_get_href,
918 HTMLStyleSheet_get_type,
919 HTMLStyleSheet_get_id,
920 HTMLStyleSheet_addImport,
921 HTMLStyleSheet_addRule,
922 HTMLStyleSheet_removeImport,
923 HTMLStyleSheet_removeRule,
924 HTMLStyleSheet_put_media,
925 HTMLStyleSheet_get_media,
926 HTMLStyleSheet_put_cssText,
927 HTMLStyleSheet_get_cssText,
928 HTMLStyleSheet_get_rules
931 static const tid_t HTMLStyleSheet_iface_tids[] = {
932 IHTMLStyleSheet_tid,
935 static dispex_static_data_t HTMLStyleSheet_dispex = {
936 NULL,
937 DispHTMLStyleSheet_tid,
938 HTMLStyleSheet_iface_tids
941 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet *nsstylesheet)
943 HTMLStyleSheet *ret = heap_alloc(sizeof(HTMLStyleSheet));
944 nsresult nsres;
946 ret->IHTMLStyleSheet_iface.lpVtbl = &HTMLStyleSheetVtbl;
947 ret->ref = 1;
948 ret->nsstylesheet = NULL;
950 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLStyleSheet_iface, &HTMLStyleSheet_dispex);
952 if(nsstylesheet) {
953 nsres = nsIDOMStyleSheet_QueryInterface(nsstylesheet, &IID_nsIDOMCSSStyleSheet,
954 (void**)&ret->nsstylesheet);
955 if(NS_FAILED(nsres))
956 ERR("Could not get nsICSSStyleSheet interface: %08x\n", nsres);
959 return &ret->IHTMLStyleSheet_iface;