conhost: Use more standard hide cursor sequence.
[wine.git] / dlls / mshtml / htmlbody.c
bloba49f8162c08261759fe4bd4b9cd12a422121add0
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 <stdio.h>
21 #include <assert.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29 #include "mshtmdid.h"
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
34 #include "htmlevent.h"
35 #include "htmlstyle.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 typedef struct {
40 HTMLElement element;
42 IHTMLBodyElement IHTMLBodyElement_iface;
43 IHTMLTextContainer IHTMLTextContainer_iface;
45 nsIDOMHTMLBodyElement *nsbody;
46 } HTMLBodyElement;
48 static const WCHAR aquaW[] = {'a','q','u','a',0};
49 static const WCHAR blackW[] = {'b','l','a','c','k',0};
50 static const WCHAR blueW[] = {'b','l','u','e',0};
51 static const WCHAR fuchsiaW[] = {'f','u','s','h','s','i','a',0};
52 static const WCHAR grayW[] = {'g','r','a','y',0};
53 static const WCHAR greenW[] = {'g','r','e','e','n',0};
54 static const WCHAR limeW[] = {'l','i','m','e',0};
55 static const WCHAR maroonW[] = {'m','a','r','o','o','n',0};
56 static const WCHAR navyW[] = {'n','a','v','y',0};
57 static const WCHAR oliveW[] = {'o','l','i','v','e',0};
58 static const WCHAR purpleW[] = {'p','u','r','p','l','e',0};
59 static const WCHAR redW[] = {'r','e','d',0};
60 static const WCHAR silverW[] = {'s','i','l','v','e','r',0};
61 static const WCHAR tealW[] = {'t','e','a','l',0};
62 static const WCHAR whiteW[] = {'w','h','i','t','e',0};
63 static const WCHAR yellowW[] = {'y','e','l','l','o','w',0};
65 static const struct {
66 LPCWSTR keyword;
67 DWORD rgb;
68 } keyword_table[] = {
69 {aquaW, 0x00ffff},
70 {blackW, 0x000000},
71 {blueW, 0x0000ff},
72 {fuchsiaW, 0xff00ff},
73 {grayW, 0x808080},
74 {greenW, 0x008000},
75 {limeW, 0x00ff00},
76 {maroonW, 0x800000},
77 {navyW, 0x000080},
78 {oliveW, 0x808000},
79 {purpleW, 0x800080},
80 {redW, 0xff0000},
81 {silverW, 0xc0c0c0},
82 {tealW, 0x008080},
83 {whiteW, 0xffffff},
84 {yellowW, 0xffff00}
87 static int comp_value(const WCHAR *ptr, int dpc)
89 int ret = 0;
90 WCHAR ch;
92 if(dpc > 2)
93 dpc = 2;
95 while(dpc--) {
96 if(!*ptr)
97 ret *= 16;
98 else if(is_digit(ch = *ptr++))
99 ret = ret*16 + (ch-'0');
100 else if('a' <= ch && ch <= 'f')
101 ret = ret*16 + (ch-'a') + 10;
102 else if('A' <= ch && ch <= 'F')
103 ret = ret*16 + (ch-'A') + 10;
104 else
105 ret *= 16;
108 return ret;
111 /* Based on Gecko NS_LooseHexToRGB */
112 static int loose_hex_to_rgb(const WCHAR *hex)
114 int len, dpc;
116 len = lstrlenW(hex);
117 if(*hex == '#') {
118 hex++;
119 len--;
121 if(len <= 3)
122 return 0;
124 dpc = min(len/3 + (len%3 ? 1 : 0), 4);
125 return (comp_value(hex, dpc) << 16)
126 | (comp_value(hex+dpc, dpc) << 8)
127 | comp_value(hex+2*dpc, dpc);
130 HRESULT nscolor_to_str(LPCWSTR color, BSTR *ret)
132 unsigned int i;
133 int rgb = -1;
135 static const WCHAR formatW[] = {'#','%','0','2','x','%','0','2','x','%','0','2','x',0};
137 if(!color || !*color) {
138 *ret = NULL;
139 return S_OK;
142 if(*color != '#') {
143 for(i=0; i < ARRAY_SIZE(keyword_table); i++) {
144 if(!wcsicmp(color, keyword_table[i].keyword))
145 rgb = keyword_table[i].rgb;
148 if(rgb == -1)
149 rgb = loose_hex_to_rgb(color);
151 *ret = SysAllocStringLen(NULL, 7);
152 if(!*ret)
153 return E_OUTOFMEMORY;
155 swprintf(*ret, 8, formatW, rgb>>16, (rgb>>8)&0xff, rgb&0xff);
157 TRACE("%s -> %s\n", debugstr_w(color), debugstr_w(*ret));
158 return S_OK;
161 BOOL variant_to_nscolor(const VARIANT *v, nsAString *nsstr)
163 switch(V_VT(v)) {
164 case VT_BSTR:
165 nsAString_Init(nsstr, V_BSTR(v));
166 return TRUE;
168 case VT_I4: {
169 PRUnichar buf[10];
170 static const WCHAR formatW[] = {'#','%','x',0};
172 wsprintfW(buf, formatW, V_I4(v));
173 nsAString_Init(nsstr, buf);
174 return TRUE;
177 default:
178 FIXME("invalid color %s\n", debugstr_variant(v));
181 return FALSE;
185 static HRESULT return_nscolor(nsresult nsres, nsAString *nsstr, VARIANT *p)
187 const PRUnichar *color;
189 if(NS_FAILED(nsres)) {
190 ERR("failed: %08x\n", nsres);
191 nsAString_Finish(nsstr);
192 return E_FAIL;
195 nsAString_GetData(nsstr, &color);
197 if(*color == '#') {
198 V_VT(p) = VT_I4;
199 V_I4(p) = wcstol(color+1, NULL, 16);
200 }else {
201 V_VT(p) = VT_BSTR;
202 V_BSTR(p) = SysAllocString(color);
203 if(!V_BSTR(p)) {
204 nsAString_Finish(nsstr);
205 return E_OUTOFMEMORY;
209 nsAString_Finish(nsstr);
210 TRACE("ret %s\n", debugstr_variant(p));
211 return S_OK;
214 static inline HTMLBodyElement *impl_from_IHTMLBodyElement(IHTMLBodyElement *iface)
216 return CONTAINING_RECORD(iface, HTMLBodyElement, IHTMLBodyElement_iface);
219 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
220 REFIID riid, void **ppv)
222 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
224 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
227 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
229 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
231 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
234 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
236 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
238 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
241 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
243 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
244 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface,
245 pctinfo);
248 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
249 LCID lcid, ITypeInfo **ppTInfo)
251 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
252 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo,
253 lcid, ppTInfo);
256 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
257 LPOLESTR *rgszNames, UINT cNames,
258 LCID lcid, DISPID *rgDispId)
260 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
261 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid,
262 rgszNames, cNames, lcid, rgDispId);
265 static HRESULT WINAPI HTMLBodyElement_Invoke(IHTMLBodyElement *iface, DISPID dispIdMember,
266 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
267 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
269 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
270 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember,
271 riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
274 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
276 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
277 nsAString nsstr;
278 nsresult nsres;
280 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
282 nsAString_InitDepend(&nsstr, v);
283 nsres = nsIDOMHTMLBodyElement_SetBackground(This->nsbody, &nsstr);
284 nsAString_Finish(&nsstr);
285 if(NS_FAILED(nsres))
286 return E_FAIL;
288 return S_OK;
291 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
293 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
294 nsAString background_str;
295 nsresult nsres;
297 TRACE("(%p)->(%p)\n", This, p);
299 nsAString_Init(&background_str, NULL);
300 nsres = nsIDOMHTMLBodyElement_GetBackground(This->nsbody, &background_str);
301 return return_nsstr(nsres, &background_str, p);
304 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
306 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
307 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
308 return E_NOTIMPL;
311 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
313 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
314 FIXME("(%p)->(%p)\n", This, p);
315 return E_NOTIMPL;
318 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
320 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
321 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
322 return E_NOTIMPL;
325 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
327 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
328 FIXME("(%p)->(%p)\n", This, p);
329 return E_NOTIMPL;
332 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
334 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
335 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
336 return E_NOTIMPL;
339 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
341 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
342 FIXME("(%p)->(%p)\n", This, p);
343 return E_NOTIMPL;
346 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
348 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
349 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
350 return E_NOTIMPL;
353 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
355 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
356 FIXME("(%p)->(%p)\n", This, p);
357 return E_NOTIMPL;
360 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
362 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
363 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
364 return E_NOTIMPL;
367 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
369 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
370 FIXME("(%p)->(%p)\n", This, p);
371 return E_NOTIMPL;
374 static HRESULT WINAPI HTMLBodyElement_put_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
376 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
377 FIXME("(%p)->(%x)\n", This, v);
378 return E_NOTIMPL;
381 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *p)
383 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
384 FIXME("(%p)->(%p)\n", This, p);
385 return E_NOTIMPL;
388 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
390 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
391 nsAString strColor;
392 nsresult nsres;
394 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
396 if(!variant_to_nscolor(&v, &strColor))
397 return S_OK;
399 nsres = nsIDOMHTMLBodyElement_SetBgColor(This->nsbody, &strColor);
400 nsAString_Finish(&strColor);
401 if(NS_FAILED(nsres))
402 ERR("SetBgColor failed: %08x\n", nsres);
404 return S_OK;
407 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
409 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
410 nsAString nsstr;
411 nsresult nsres;
413 TRACE("(%p)->(%p)\n", This, p);
415 nsAString_Init(&nsstr, NULL);
416 nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &nsstr);
417 return return_nsstr_variant(nsres, &nsstr, NSSTR_COLOR, p);
420 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
422 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
423 nsAString text;
424 nsresult nsres;
426 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
428 if(!variant_to_nscolor(&v, &text))
429 return S_OK;
431 nsres = nsIDOMHTMLBodyElement_SetText(This->nsbody, &text);
432 nsAString_Finish(&text);
433 if(NS_FAILED(nsres)) {
434 ERR("SetText failed: %08x\n", nsres);
435 return E_FAIL;
438 return S_OK;
441 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
443 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
444 nsAString text;
445 nsresult nsres;
446 HRESULT hres;
448 TRACE("(%p)->(%p)\n", This, p);
450 nsAString_Init(&text, NULL);
451 nsres = nsIDOMHTMLBodyElement_GetText(This->nsbody, &text);
452 if(NS_SUCCEEDED(nsres)) {
453 const PRUnichar *color;
455 nsAString_GetData(&text, &color);
456 V_VT(p) = VT_BSTR;
457 hres = nscolor_to_str(color, &V_BSTR(p));
458 }else {
459 ERR("GetText failed: %08x\n", nsres);
460 hres = E_FAIL;
463 nsAString_Finish(&text);
465 return hres;
468 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
470 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
471 nsAString link_str;
472 nsresult nsres;
474 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
476 if(!variant_to_nscolor(&v, &link_str))
477 return S_OK;
479 nsres = nsIDOMHTMLBodyElement_SetLink(This->nsbody, &link_str);
480 nsAString_Finish(&link_str);
481 if(NS_FAILED(nsres))
482 ERR("SetLink failed: %08x\n", nsres);
484 return S_OK;
487 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
489 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
490 nsAString link_str;
491 nsresult nsres;
493 TRACE("(%p)->(%p)\n", This, p);
495 nsAString_Init(&link_str, NULL);
496 nsres = nsIDOMHTMLBodyElement_GetLink(This->nsbody, &link_str);
497 return return_nscolor(nsres, &link_str, p);
500 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
502 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
503 nsAString vlink_str;
504 nsresult nsres;
506 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
508 if(!variant_to_nscolor(&v, &vlink_str))
509 return S_OK;
511 nsres = nsIDOMHTMLBodyElement_SetVLink(This->nsbody, &vlink_str);
512 nsAString_Finish(&vlink_str);
513 if(NS_FAILED(nsres))
514 ERR("SetLink failed: %08x\n", nsres);
516 return S_OK;
519 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
521 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
522 nsAString vlink_str;
523 nsresult nsres;
525 TRACE("(%p)->(%p)\n", This, p);
527 nsAString_Init(&vlink_str, NULL);
528 nsres = nsIDOMHTMLBodyElement_GetVLink(This->nsbody, &vlink_str);
529 return return_nscolor(nsres, &vlink_str, p);
532 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
534 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
535 nsAString alink_str;
536 nsresult nsres;
538 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
540 if(!variant_to_nscolor(&v, &alink_str))
541 return S_OK;
543 nsres = nsIDOMHTMLBodyElement_SetALink(This->nsbody, &alink_str);
544 nsAString_Finish(&alink_str);
545 if(NS_FAILED(nsres))
546 ERR("SetALink failed: %08x\n", nsres);
548 return S_OK;
551 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
553 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
554 nsAString alink_str;
555 nsresult nsres;
557 TRACE("(%p)->(%p)\n", This, p);
559 nsAString_Init(&alink_str, NULL);
560 nsres = nsIDOMHTMLBodyElement_GetALink(This->nsbody, &alink_str);
561 return return_nscolor(nsres, &alink_str, p);
564 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
566 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
568 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
570 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
573 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
575 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
577 TRACE("(%p)->(%p)\n", This, p);
579 return get_node_event(&This->element.node, EVENTID_LOAD, p);
582 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
584 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
585 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
586 return E_NOTIMPL;
589 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
591 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
592 FIXME("(%p)->(%p)\n", This, p);
593 return E_NOTIMPL;
596 static const WCHAR autoW[] = {'a','u','t','o',0};
597 static const WCHAR hiddenW[] = {'h','i','d','d','e','n',0};
598 static const WCHAR scrollW[] = {'s','c','r','o','l','l',0};
599 static const WCHAR visibleW[] = {'v','i','s','i','b','l','e',0};
600 static const WCHAR yesW[] = {'y','e','s',0};
601 static const WCHAR noW[] = {'n','o',0};
603 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
605 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
606 static const WCHAR *val;
608 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
610 /* Emulate with CSS visibility attribute */
611 if(!wcscmp(v, yesW)) {
612 val = scrollW;
613 }else if(!wcscmp(v, autoW)) {
614 val = visibleW;
615 }else if(!wcscmp(v, noW)) {
616 val = hiddenW;
617 }else {
618 WARN("Invalid argument %s\n", debugstr_w(v));
619 return E_INVALIDARG;
622 return set_elem_style(&This->element, STYLEID_OVERFLOW, val);
625 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
627 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
628 const WCHAR *ret = NULL;
629 BSTR overflow;
630 HRESULT hres;
632 TRACE("(%p)->(%p)\n", This, p);
634 /* Emulate with CSS visibility attribute */
635 hres = get_elem_style(&This->element, STYLEID_OVERFLOW, &overflow);
636 if(FAILED(hres))
637 return hres;
639 if(!overflow || !*overflow) {
640 *p = NULL;
641 hres = S_OK;
642 }else if(!wcscmp(overflow, visibleW) || !wcscmp(overflow, autoW)) {
643 ret = autoW;
644 }else if(!wcscmp(overflow, scrollW)) {
645 ret = yesW;
646 }else if(!wcscmp(overflow, hiddenW)) {
647 ret = noW;
648 }else {
649 TRACE("Defaulting %s to NULL\n", debugstr_w(overflow));
650 *p = NULL;
651 hres = S_OK;
654 SysFreeString(overflow);
655 if(ret) {
656 *p = SysAllocString(ret);
657 hres = *p ? S_OK : E_OUTOFMEMORY;
660 return hres;
663 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
665 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
666 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
667 return E_NOTIMPL;
670 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
672 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
673 FIXME("(%p)->(%p)\n", This, p);
674 return E_NOTIMPL;
677 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
679 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
680 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
681 return E_NOTIMPL;
684 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
686 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
687 FIXME("(%p)->(%p)\n", This, p);
688 return E_NOTIMPL;
691 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
693 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
694 nsIDOMRange *nsrange = NULL;
695 nsresult nsres;
696 HRESULT hres;
698 TRACE("(%p)->(%p)\n", This, range);
700 if(!This->element.node.doc->nsdoc) {
701 WARN("No nsdoc\n");
702 return E_UNEXPECTED;
705 nsres = nsIDOMHTMLDocument_CreateRange(This->element.node.doc->nsdoc, &nsrange);
706 if(NS_SUCCEEDED(nsres)) {
707 nsres = nsIDOMRange_SelectNodeContents(nsrange, This->element.node.nsnode);
708 if(NS_FAILED(nsres))
709 ERR("SelectNodeContents failed: %08x\n", nsres);
710 }else {
711 ERR("CreateRange failed: %08x\n", nsres);
714 hres = HTMLTxtRange_Create(This->element.node.doc->basedoc.doc_node, nsrange, range);
716 nsIDOMRange_Release(nsrange);
717 return hres;
720 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
721 HTMLBodyElement_QueryInterface,
722 HTMLBodyElement_AddRef,
723 HTMLBodyElement_Release,
724 HTMLBodyElement_GetTypeInfoCount,
725 HTMLBodyElement_GetTypeInfo,
726 HTMLBodyElement_GetIDsOfNames,
727 HTMLBodyElement_Invoke,
728 HTMLBodyElement_put_background,
729 HTMLBodyElement_get_background,
730 HTMLBodyElement_put_bgProperties,
731 HTMLBodyElement_get_bgProperties,
732 HTMLBodyElement_put_leftMargin,
733 HTMLBodyElement_get_leftMargin,
734 HTMLBodyElement_put_topMargin,
735 HTMLBodyElement_get_topMargin,
736 HTMLBodyElement_put_rightMargin,
737 HTMLBodyElement_get_rightMargin,
738 HTMLBodyElement_put_bottomMargin,
739 HTMLBodyElement_get_bottomMargin,
740 HTMLBodyElement_put_noWrap,
741 HTMLBodyElement_get_noWrap,
742 HTMLBodyElement_put_bgColor,
743 HTMLBodyElement_get_bgColor,
744 HTMLBodyElement_put_text,
745 HTMLBodyElement_get_text,
746 HTMLBodyElement_put_link,
747 HTMLBodyElement_get_link,
748 HTMLBodyElement_put_vLink,
749 HTMLBodyElement_get_vLink,
750 HTMLBodyElement_put_aLink,
751 HTMLBodyElement_get_aLink,
752 HTMLBodyElement_put_onload,
753 HTMLBodyElement_get_onload,
754 HTMLBodyElement_put_onunload,
755 HTMLBodyElement_get_onunload,
756 HTMLBodyElement_put_scroll,
757 HTMLBodyElement_get_scroll,
758 HTMLBodyElement_put_onselect,
759 HTMLBodyElement_get_onselect,
760 HTMLBodyElement_put_onbeforeunload,
761 HTMLBodyElement_get_onbeforeunload,
762 HTMLBodyElement_createTextRange
765 static inline HTMLBodyElement *impl_from_IHTMLTextContainer(IHTMLTextContainer *iface)
767 return CONTAINING_RECORD(iface, HTMLBodyElement, IHTMLTextContainer_iface);
770 static HRESULT WINAPI HTMLTextContainer_QueryInterface(IHTMLTextContainer *iface,
771 REFIID riid, void **ppv)
773 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
774 return IHTMLElement_QueryInterface(&This->element.IHTMLElement_iface, riid, ppv);
777 static ULONG WINAPI HTMLTextContainer_AddRef(IHTMLTextContainer *iface)
779 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
780 return IHTMLElement_AddRef(&This->element.IHTMLElement_iface);
783 static ULONG WINAPI HTMLTextContainer_Release(IHTMLTextContainer *iface)
785 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
786 return IHTMLElement_Release(&This->element.IHTMLElement_iface);
789 static HRESULT WINAPI HTMLTextContainer_GetTypeInfoCount(IHTMLTextContainer *iface, UINT *pctinfo)
791 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
792 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
795 static HRESULT WINAPI HTMLTextContainer_GetTypeInfo(IHTMLTextContainer *iface, UINT iTInfo,
796 LCID lcid, ITypeInfo **ppTInfo)
798 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
799 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
800 ppTInfo);
803 static HRESULT WINAPI HTMLTextContainer_GetIDsOfNames(IHTMLTextContainer *iface, REFIID riid,
804 LPOLESTR *rgszNames, UINT cNames,
805 LCID lcid, DISPID *rgDispId)
807 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
808 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
809 cNames, lcid, rgDispId);
812 static HRESULT WINAPI HTMLTextContainer_Invoke(IHTMLTextContainer *iface, DISPID dispIdMember,
813 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
814 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
816 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
817 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
818 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
821 static HRESULT WINAPI HTMLTextContainer_createControlRange(IHTMLTextContainer *iface,
822 IDispatch **range)
824 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
825 FIXME("(%p)->(%p)\n", This, range);
826 return E_NOTIMPL;
829 static HRESULT WINAPI HTMLTextContainer_get_scrollHeight(IHTMLTextContainer *iface, LONG *p)
831 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
833 TRACE("(%p)->(%p)\n", This, p);
835 return IHTMLElement2_get_scrollHeight(&This->element.IHTMLElement2_iface, p);
838 static HRESULT WINAPI HTMLTextContainer_get_scrollWidth(IHTMLTextContainer *iface, LONG *p)
840 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
842 TRACE("(%p)->(%p)\n", This, p);
844 return IHTMLElement2_get_scrollWidth(&This->element.IHTMLElement2_iface, p);
847 static HRESULT WINAPI HTMLTextContainer_put_scrollTop(IHTMLTextContainer *iface, LONG v)
849 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
851 TRACE("(%p)->(%d)\n", This, v);
853 return IHTMLElement2_put_scrollTop(&This->element.IHTMLElement2_iface, v);
856 static HRESULT WINAPI HTMLTextContainer_get_scrollTop(IHTMLTextContainer *iface, LONG *p)
858 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
860 TRACE("(%p)->(%p)\n", This, p);
862 return IHTMLElement2_get_scrollTop(&This->element.IHTMLElement2_iface, p);
865 static HRESULT WINAPI HTMLTextContainer_put_scrollLeft(IHTMLTextContainer *iface, LONG v)
867 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
869 TRACE("(%p)->(%d)\n", This, v);
871 return IHTMLElement2_put_scrollLeft(&This->element.IHTMLElement2_iface, v);
874 static HRESULT WINAPI HTMLTextContainer_get_scrollLeft(IHTMLTextContainer *iface, LONG *p)
876 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
878 TRACE("(%p)->(%p)\n", This, p);
880 return IHTMLElement2_get_scrollLeft(&This->element.IHTMLElement2_iface, p);
883 static HRESULT WINAPI HTMLTextContainer_put_onscroll(IHTMLTextContainer *iface, VARIANT v)
885 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
886 FIXME("(%p)->()\n", This);
887 return E_NOTIMPL;
890 static HRESULT WINAPI HTMLTextContainer_get_onscroll(IHTMLTextContainer *iface, VARIANT *p)
892 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
893 FIXME("(%p)->(%p)\n", This, p);
894 return E_NOTIMPL;
897 static const IHTMLTextContainerVtbl HTMLTextContainerVtbl = {
898 HTMLTextContainer_QueryInterface,
899 HTMLTextContainer_AddRef,
900 HTMLTextContainer_Release,
901 HTMLTextContainer_GetTypeInfoCount,
902 HTMLTextContainer_GetTypeInfo,
903 HTMLTextContainer_GetIDsOfNames,
904 HTMLTextContainer_Invoke,
905 HTMLTextContainer_createControlRange,
906 HTMLTextContainer_get_scrollHeight,
907 HTMLTextContainer_get_scrollWidth,
908 HTMLTextContainer_put_scrollTop,
909 HTMLTextContainer_get_scrollTop,
910 HTMLTextContainer_put_scrollLeft,
911 HTMLTextContainer_get_scrollLeft,
912 HTMLTextContainer_put_onscroll,
913 HTMLTextContainer_get_onscroll
916 static inline HTMLBodyElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
918 return CONTAINING_RECORD(iface, HTMLBodyElement, element.node);
921 static HRESULT HTMLBodyElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
923 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
925 *ppv = NULL;
927 if(IsEqualGUID(&IID_IUnknown, riid)) {
928 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
929 *ppv = &This->IHTMLBodyElement_iface;
930 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
931 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
932 *ppv = &This->IHTMLBodyElement_iface;
933 }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
934 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
935 *ppv = &This->IHTMLBodyElement_iface;
936 }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
937 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", This, ppv);
938 *ppv = &This->IHTMLTextContainer_iface;
941 if(*ppv) {
942 IUnknown_AddRef((IUnknown*)*ppv);
943 return S_OK;
946 return HTMLElement_QI(&This->element.node, riid, ppv);
949 static void HTMLBodyElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
951 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
953 if(This->nsbody)
954 note_cc_edge((nsISupports*)This->nsbody, "This->nsbody", cb);
957 static void HTMLBodyElement_unlink(HTMLDOMNode *iface)
959 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
961 if(This->nsbody) {
962 nsIDOMHTMLBodyElement *nsbody = This->nsbody;
963 This->nsbody = NULL;
964 nsIDOMHTMLBodyElement_Release(nsbody);
968 static EventTarget *HTMLBodyElement_get_event_prop_target(HTMLDOMNode *iface, int event_id)
970 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
972 switch(event_id) {
973 case EVENTID_BLUR:
974 case EVENTID_ERROR:
975 case EVENTID_FOCUS:
976 case EVENTID_LOAD:
977 case EVENTID_SCROLL:
978 return This->element.node.doc && This->element.node.doc->window
979 ? &This->element.node.doc->window->event_target
980 : &This->element.node.event_target;
981 default:
982 return &This->element.node.event_target;
986 static BOOL HTMLBodyElement_is_text_edit(HTMLDOMNode *iface)
988 return TRUE;
991 static BOOL HTMLBodyElement_is_settable(HTMLDOMNode *iface, DISPID dispid)
993 switch(dispid) {
994 case DISPID_IHTMLELEMENT_OUTERTEXT:
995 return FALSE;
996 default:
997 return TRUE;
1001 static const cpc_entry_t HTMLBodyElement_cpc[] = {
1002 {&DIID_HTMLTextContainerEvents},
1003 {&IID_IPropertyNotifySink},
1004 HTMLELEMENT_CPC,
1005 {NULL}
1008 static const NodeImplVtbl HTMLBodyElementImplVtbl = {
1009 &CLSID_HTMLBody,
1010 HTMLBodyElement_QI,
1011 HTMLElement_destructor,
1012 HTMLBodyElement_cpc,
1013 HTMLElement_clone,
1014 HTMLElement_handle_event,
1015 HTMLElement_get_attr_col,
1016 HTMLBodyElement_get_event_prop_target,
1017 NULL,
1018 NULL,
1019 NULL,
1020 NULL,
1021 NULL,
1022 NULL,
1023 NULL,
1024 HTMLBodyElement_traverse,
1025 HTMLBodyElement_unlink,
1026 HTMLBodyElement_is_text_edit,
1027 HTMLBodyElement_is_settable
1030 static const tid_t HTMLBodyElement_iface_tids[] = {
1031 IHTMLBodyElement_tid,
1032 IHTMLBodyElement2_tid,
1033 HTMLELEMENT_TIDS,
1034 IHTMLTextContainer_tid,
1038 static dispex_static_data_t HTMLBodyElement_dispex = {
1039 NULL,
1040 DispHTMLBody_tid,
1041 HTMLBodyElement_iface_tids,
1042 HTMLElement_init_dispex_info
1045 HRESULT HTMLBodyElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
1047 HTMLBodyElement *ret;
1048 nsresult nsres;
1050 ret = heap_alloc_zero(sizeof(HTMLBodyElement));
1051 if(!ret)
1052 return E_OUTOFMEMORY;
1054 ret->IHTMLBodyElement_iface.lpVtbl = &HTMLBodyElementVtbl;
1055 ret->IHTMLTextContainer_iface.lpVtbl = &HTMLTextContainerVtbl;
1056 ret->element.node.vtbl = &HTMLBodyElementImplVtbl;
1058 HTMLElement_Init(&ret->element, doc, nselem, &HTMLBodyElement_dispex);
1060 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLBodyElement, (void**)&ret->nsbody);
1061 assert(nsres == NS_OK);
1063 *elem = &ret->element;
1064 return S_OK;