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
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36 HTMLTextContainer textcont;
38 const IHTMLBodyElementVtbl *lpHTMLBodyElementVtbl;
40 ConnectionPoint cp_propnotif;
42 nsIDOMHTMLBodyElement *nsbody;
45 #define HTMLBODY(x) (&(x)->lpHTMLBodyElementVtbl)
47 static BOOL variant_to_nscolor(const VARIANT *v, nsAString *nsstr)
51 nsAString_Init(nsstr, V_BSTR(v));
56 static const WCHAR formatW[] = {'#','%','x',0};
58 wsprintfW(buf, formatW, V_I4(v));
59 nsAString_Init(nsstr, buf);
64 FIXME("invalid vt=%d\n", V_VT(v));
71 static void nscolor_to_variant(const nsAString *nsstr, VARIANT *p)
73 const PRUnichar *color;
75 nsAString_GetData(nsstr, &color);
79 V_I4(p) = strtolW(color+1, NULL, 16);
82 V_BSTR(p) = SysAllocString(color);
86 #define HTMLBODY_THIS(iface) DEFINE_THIS(HTMLBodyElement, HTMLBodyElement, iface)
88 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
89 REFIID riid, void **ppv)
91 HTMLBodyElement *This = HTMLBODY_THIS(iface);
93 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->textcont.element.node), riid, ppv);
96 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
98 HTMLBodyElement *This = HTMLBODY_THIS(iface);
100 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->textcont.element.node));
103 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
105 HTMLBodyElement *This = HTMLBODY_THIS(iface);
107 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->textcont.element.node));
110 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
112 HTMLBodyElement *This = HTMLBODY_THIS(iface);
113 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->textcont.element.node.dispex), pctinfo);
116 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
117 LCID lcid, ITypeInfo **ppTInfo)
119 HTMLBodyElement *This = HTMLBODY_THIS(iface);
120 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->textcont.element.node.dispex), iTInfo, lcid, ppTInfo);
123 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
124 LPOLESTR *rgszNames, UINT cNames,
125 LCID lcid, DISPID *rgDispId)
127 HTMLBodyElement *This = HTMLBODY_THIS(iface);
128 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->textcont.element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
131 static HRESULT WINAPI HTMLBodyElement_Invoke(IHTMLBodyElement *iface, DISPID dispIdMember,
132 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
133 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
135 HTMLBodyElement *This = HTMLBODY_THIS(iface);
136 return IDispatchEx_Invoke(DISPATCHEX(&This->textcont.element.node.dispex), dispIdMember, riid, lcid,
137 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
140 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
142 HTMLBodyElement *This = HTMLBODY_THIS(iface);
147 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
149 nsAString_Init(&nsstr, v);
151 nsres = nsIDOMHTMLBodyElement_SetBackground(This->nsbody, &nsstr);
152 if(!NS_SUCCEEDED(nsres))
157 nsAString_Finish(&nsstr);
162 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
164 HTMLBodyElement *This = HTMLBODY_THIS(iface);
165 nsAString background_str;
168 TRACE("(%p)->(%p)\n", This, p);
170 nsAString_Init(&background_str, NULL);
172 nsres = nsIDOMHTMLBodyElement_GetBackground(This->nsbody, &background_str);
173 if(NS_SUCCEEDED(nsres)) {
174 const PRUnichar *background;
175 nsAString_GetData(&background_str, &background);
176 *p = *background ? SysAllocString(background) : NULL;
178 ERR("GetBackground failed: %08x\n", nsres);
182 nsAString_Finish(&background_str);
184 TRACE("*p = %s\n", debugstr_w(*p));
188 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
190 HTMLBodyElement *This = HTMLBODY_THIS(iface);
191 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
195 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
197 HTMLBodyElement *This = HTMLBODY_THIS(iface);
198 FIXME("(%p)->(%p)\n", This, p);
202 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
204 HTMLBodyElement *This = HTMLBODY_THIS(iface);
205 FIXME("(%p)->()\n", This);
209 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
211 HTMLBodyElement *This = HTMLBODY_THIS(iface);
212 FIXME("(%p)->(%p)\n", This, p);
216 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
218 HTMLBodyElement *This = HTMLBODY_THIS(iface);
219 FIXME("(%p)->()\n", This);
223 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
225 HTMLBodyElement *This = HTMLBODY_THIS(iface);
226 FIXME("(%p)->(%p)\n", This, p);
230 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
232 HTMLBodyElement *This = HTMLBODY_THIS(iface);
233 FIXME("(%p)->()\n", This);
237 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
239 HTMLBodyElement *This = HTMLBODY_THIS(iface);
240 FIXME("(%p)->(%p)\n", This, p);
244 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
246 HTMLBodyElement *This = HTMLBODY_THIS(iface);
247 FIXME("(%p)->()\n", This);
251 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
253 HTMLBodyElement *This = HTMLBODY_THIS(iface);
254 FIXME("(%p)->(%p)\n", This, p);
258 static HRESULT WINAPI HTMLBodyElement_put_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
260 HTMLBodyElement *This = HTMLBODY_THIS(iface);
261 FIXME("(%p)->(%x)\n", This, v);
265 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *p)
267 HTMLBodyElement *This = HTMLBODY_THIS(iface);
268 FIXME("(%p)->(%p)\n", This, p);
272 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
274 HTMLBodyElement *This = HTMLBODY_THIS(iface);
278 TRACE("(%p)->()\n", This);
280 if(!variant_to_nscolor(&v, &strColor))
283 nsres = nsIDOMHTMLBodyElement_SetBgColor(This->nsbody, &strColor);
284 nsAString_Finish(&strColor);
286 ERR("SetBgColor failed: %08x\n", nsres);
291 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
293 HTMLBodyElement *This = HTMLBODY_THIS(iface);
296 const PRUnichar *color;
298 TRACE("(%p)->(%p)\n", This, p);
300 nsAString_Init(&strColor, NULL);
301 nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &strColor);
303 ERR("SetBgColor failed: %08x\n", nsres);
305 nsAString_GetData(&strColor, &color);
308 V_BSTR(p) = SysAllocString(color);
310 nsAString_Finish(&strColor);
315 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
317 HTMLBodyElement *This = HTMLBODY_THIS(iface);
321 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
323 if(!variant_to_nscolor(&v, &text))
326 nsres = nsIDOMHTMLBodyElement_SetText(This->nsbody, &text);
327 nsAString_Finish(&text);
332 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
334 HTMLBodyElement *This = HTMLBODY_THIS(iface);
338 TRACE("(%p)->(%p)\n", This, p);
340 nsAString_Init(&text, NULL);
345 nsres = nsIDOMHTMLBodyElement_GetText(This->nsbody, &text);
346 if(NS_SUCCEEDED(nsres))
348 const PRUnichar *sText;
349 nsAString_GetData(&text, &sText);
352 V_BSTR(p) = SysAllocString(sText);
355 nsAString_Finish(&text);
360 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
362 HTMLBodyElement *This = HTMLBODY_THIS(iface);
366 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
368 if(!variant_to_nscolor(&v, &link_str))
371 nsres = nsIDOMHTMLBodyElement_SetLink(This->nsbody, &link_str);
372 nsAString_Finish(&link_str);
374 ERR("SetLink failed: %08x\n", nsres);
379 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
381 HTMLBodyElement *This = HTMLBODY_THIS(iface);
385 TRACE("(%p)->(%p)\n", This, p);
387 nsAString_Init(&link_str, NULL);
388 nsres = nsIDOMHTMLBodyElement_GetLink(This->nsbody, &link_str);
390 ERR("GetLink failed: %08x\n", nsres);
392 nscolor_to_variant(&link_str, p);
393 nsAString_Finish(&link_str);
398 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
400 HTMLBodyElement *This = HTMLBODY_THIS(iface);
404 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
406 if(!variant_to_nscolor(&v, &vlink_str))
409 nsres = nsIDOMHTMLBodyElement_SetVLink(This->nsbody, &vlink_str);
410 nsAString_Finish(&vlink_str);
412 ERR("SetLink failed: %08x\n", nsres);
417 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
419 HTMLBodyElement *This = HTMLBODY_THIS(iface);
423 TRACE("(%p)->(%p)\n", This, p);
425 nsAString_Init(&vlink_str, NULL);
426 nsres = nsIDOMHTMLBodyElement_GetVLink(This->nsbody, &vlink_str);
428 ERR("GetLink failed: %08x\n", nsres);
430 nscolor_to_variant(&vlink_str, p);
431 nsAString_Finish(&vlink_str);
436 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
438 HTMLBodyElement *This = HTMLBODY_THIS(iface);
442 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
444 if(!variant_to_nscolor(&v, &alink_str))
447 nsres = nsIDOMHTMLBodyElement_SetALink(This->nsbody, &alink_str);
448 nsAString_Finish(&alink_str);
450 ERR("SetALink failed: %08x\n", nsres);
455 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
457 HTMLBodyElement *This = HTMLBODY_THIS(iface);
461 TRACE("(%p)->(%p)\n", This, p);
463 nsAString_Init(&alink_str, NULL);
464 nsres = nsIDOMHTMLBodyElement_GetALink(This->nsbody, &alink_str);
466 ERR("GetALink failed: %08x\n", nsres);
468 nscolor_to_variant(&alink_str, p);
469 nsAString_Finish(&alink_str);
474 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
476 HTMLBodyElement *This = HTMLBODY_THIS(iface);
477 FIXME("(%p)->()\n", This);
481 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
483 HTMLBodyElement *This = HTMLBODY_THIS(iface);
484 FIXME("(%p)->(%p)\n", This, p);
488 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
490 HTMLBodyElement *This = HTMLBODY_THIS(iface);
491 FIXME("(%p)->()\n", This);
495 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
497 HTMLBodyElement *This = HTMLBODY_THIS(iface);
498 FIXME("(%p)->(%p)\n", This, p);
502 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
504 HTMLBodyElement *This = HTMLBODY_THIS(iface);
505 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
509 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
511 HTMLBodyElement *This = HTMLBODY_THIS(iface);
512 FIXME("(%p)->(%p)\n", This, p);
516 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
518 HTMLBodyElement *This = HTMLBODY_THIS(iface);
519 FIXME("(%p)->()\n", This);
523 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
525 HTMLBodyElement *This = HTMLBODY_THIS(iface);
526 FIXME("(%p)->(%p)\n", This, p);
530 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
532 HTMLBodyElement *This = HTMLBODY_THIS(iface);
533 FIXME("(%p)->()\n", This);
537 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
539 HTMLBodyElement *This = HTMLBODY_THIS(iface);
540 FIXME("(%p)->(%p)\n", This, p);
544 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
546 HTMLBodyElement *This = HTMLBODY_THIS(iface);
547 nsIDOMDocumentRange *nsdocrange;
548 nsIDOMRange *nsrange = NULL;
551 TRACE("(%p)->(%p)\n", This, range);
553 if(!This->textcont.element.node.doc->nsdoc) {
558 nsres = nsIDOMDocument_QueryInterface(This->textcont.element.node.doc->nsdoc, &IID_nsIDOMDocumentRange,
559 (void**)&nsdocrange);
560 if(NS_FAILED(nsres)) {
561 ERR("Could not get nsIDOMDocumentRabge iface: %08x\n", nsres);
565 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &nsrange);
566 if(NS_SUCCEEDED(nsres)) {
567 nsres = nsIDOMRange_SelectNodeContents(nsrange, This->textcont.element.node.nsnode);
569 ERR("SelectNodeContents failed: %08x\n", nsres);
571 ERR("CreateRange failed: %08x\n", nsres);
574 nsIDOMDocumentRange_Release(nsdocrange);
576 *range = HTMLTxtRange_Create(This->textcont.element.node.doc, nsrange);
582 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
583 HTMLBodyElement_QueryInterface,
584 HTMLBodyElement_AddRef,
585 HTMLBodyElement_Release,
586 HTMLBodyElement_GetTypeInfoCount,
587 HTMLBodyElement_GetTypeInfo,
588 HTMLBodyElement_GetIDsOfNames,
589 HTMLBodyElement_Invoke,
590 HTMLBodyElement_put_background,
591 HTMLBodyElement_get_background,
592 HTMLBodyElement_put_bgProperties,
593 HTMLBodyElement_get_bgProperties,
594 HTMLBodyElement_put_leftMargin,
595 HTMLBodyElement_get_leftMargin,
596 HTMLBodyElement_put_topMargin,
597 HTMLBodyElement_get_topMargin,
598 HTMLBodyElement_put_rightMargin,
599 HTMLBodyElement_get_rightMargin,
600 HTMLBodyElement_put_bottomMargin,
601 HTMLBodyElement_get_bottomMargin,
602 HTMLBodyElement_put_noWrap,
603 HTMLBodyElement_get_noWrap,
604 HTMLBodyElement_put_bgColor,
605 HTMLBodyElement_get_bgColor,
606 HTMLBodyElement_put_text,
607 HTMLBodyElement_get_text,
608 HTMLBodyElement_put_link,
609 HTMLBodyElement_get_link,
610 HTMLBodyElement_put_vLink,
611 HTMLBodyElement_get_vLink,
612 HTMLBodyElement_put_aLink,
613 HTMLBodyElement_get_aLink,
614 HTMLBodyElement_put_onload,
615 HTMLBodyElement_get_onload,
616 HTMLBodyElement_put_onunload,
617 HTMLBodyElement_get_onunload,
618 HTMLBodyElement_put_scroll,
619 HTMLBodyElement_get_scroll,
620 HTMLBodyElement_put_onselect,
621 HTMLBodyElement_get_onselect,
622 HTMLBodyElement_put_onbeforeunload,
623 HTMLBodyElement_get_onbeforeunload,
624 HTMLBodyElement_createTextRange
627 #define HTMLBODY_NODE_THIS(iface) DEFINE_THIS2(HTMLBodyElement, textcont.element.node, iface)
629 static HRESULT HTMLBodyElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
631 HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface);
635 if(IsEqualGUID(&IID_IUnknown, riid)) {
636 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
637 *ppv = HTMLBODY(This);
638 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
639 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
640 *ppv = HTMLBODY(This);
641 }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
642 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
643 *ppv = HTMLBODY(This);
644 }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
645 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", &This->textcont, ppv);
646 *ppv = HTMLTEXTCONT(&This->textcont);
650 IUnknown_AddRef((IUnknown*)*ppv);
654 return HTMLElement_QI(&This->textcont.element.node, riid, ppv);
657 static void HTMLBodyElement_destructor(HTMLDOMNode *iface)
659 HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface);
661 nsIDOMHTMLBodyElement_Release(This->nsbody);
663 HTMLElement_destructor(&This->textcont.element.node);
666 #undef HTMLBODY_NODE_THIS
668 static const NodeImplVtbl HTMLBodyElementImplVtbl = {
670 HTMLBodyElement_destructor
673 static const tid_t HTMLBodyElement_iface_tids[] = {
674 IHTMLBodyElement_tid,
675 IHTMLBodyElement2_tid,
682 IHTMLTextContainer_tid,
687 static dispex_static_data_t HTMLBodyElement_dispex = {
691 HTMLBodyElement_iface_tids
694 HTMLElement *HTMLBodyElement_Create(nsIDOMHTMLElement *nselem)
696 HTMLBodyElement *ret = heap_alloc_zero(sizeof(HTMLBodyElement));
699 TRACE("(%p)->(%p)\n", ret, nselem);
701 HTMLTextContainer_Init(&ret->textcont);
703 ret->lpHTMLBodyElementVtbl = &HTMLBodyElementVtbl;
705 init_dispex(&ret->textcont.element.node.dispex, (IUnknown*)HTMLBODY(ret), &HTMLBodyElement_dispex);
706 ret->textcont.element.node.vtbl = &HTMLBodyElementImplVtbl;
708 ConnectionPoint_Init(&ret->cp_propnotif, &ret->textcont.element.cp_container, &IID_IPropertyNotifySink);
710 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLBodyElement,
711 (void**)&ret->nsbody);
713 ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres);
715 return &ret->textcont.element;