Sync with trunk head
[reactos.git] / dll / win32 / mshtml / htmlbody.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 <stdarg.h>
20 #include <stdio.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28
29 #include "wine/debug.h"
30
31 #include "mshtml_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34
35 typedef struct {
36 HTMLTextContainer textcont;
37
38 const IHTMLBodyElementVtbl *lpHTMLBodyElementVtbl;
39
40 ConnectionPoint cp_propnotif;
41
42 nsIDOMHTMLBodyElement *nsbody;
43 } HTMLBodyElement;
44
45 #define HTMLBODY(x) (&(x)->lpHTMLBodyElementVtbl)
46
47 static const WCHAR aquaW[] = {'a','q','u','a',0};
48 static const WCHAR blackW[] = {'b','l','a','c','k',0};
49 static const WCHAR blueW[] = {'b','l','u','e',0};
50 static const WCHAR fuchsiaW[] = {'f','u','s','h','s','i','a',0};
51 static const WCHAR grayW[] = {'g','r','a','y',0};
52 static const WCHAR greenW[] = {'g','r','e','e','n',0};
53 static const WCHAR limeW[] = {'l','i','m','e',0};
54 static const WCHAR maroonW[] = {'m','a','r','o','o','n',0};
55 static const WCHAR navyW[] = {'n','a','v','y',0};
56 static const WCHAR oliveW[] = {'o','l','i','v','e',0};
57 static const WCHAR purpleW[] = {'p','u','r','p','l','e',0};
58 static const WCHAR redW[] = {'r','e','d',0};
59 static const WCHAR silverW[] = {'s','i','l','v','e','r',0};
60 static const WCHAR tealW[] = {'t','e','a','l',0};
61 static const WCHAR whiteW[] = {'w','h','i','t','e',0};
62 static const WCHAR yellowW[] = {'y','e','l','l','o','w',0};
63
64 static const struct {
65 LPCWSTR keyword;
66 DWORD rgb;
67 } keyword_table[] = {
68 {aquaW, 0x00ffff},
69 {blackW, 0x000000},
70 {blueW, 0x0000ff},
71 {fuchsiaW, 0xff00ff},
72 {grayW, 0x808080},
73 {greenW, 0x008000},
74 {limeW, 0x00ff00},
75 {maroonW, 0x800000},
76 {navyW, 0x000080},
77 {oliveW, 0x808000},
78 {purpleW, 0x800080},
79 {redW, 0xff0000},
80 {silverW, 0xc0c0c0},
81 {tealW, 0x008080},
82 {whiteW, 0xffffff},
83 {yellowW, 0xffff00}
84 };
85
86 static int comp_value(const WCHAR *ptr, int dpc)
87 {
88 int ret = 0;
89 WCHAR ch;
90
91 if(dpc > 2)
92 dpc = 2;
93
94 while(dpc--) {
95 if(!*ptr)
96 ret *= 16;
97 else if(isdigitW(ch = *ptr++))
98 ret = ret*16 + (ch-'0');
99 else if('a' <= ch && ch <= 'f')
100 ret = ret*16 + (ch-'a') + 10;
101 else if('A' <= ch && ch <= 'F')
102 ret = ret*16 + (ch-'A') + 10;
103 else
104 ret *= 16;
105 }
106
107 return ret;
108 }
109
110 /* Based on Gecko NS_LooseHexToRGB */
111 static int loose_hex_to_rgb(const WCHAR *hex)
112 {
113 int len, dpc;
114
115 len = strlenW(hex);
116 if(*hex == '#') {
117 hex++;
118 len--;
119 }
120 if(len <= 3)
121 return 0;
122
123 dpc = min(len/3 + (len%3 ? 1 : 0), 4);
124 return (comp_value(hex, dpc) << 16)
125 | (comp_value(hex+dpc, dpc) << 8)
126 | comp_value(hex+2*dpc, dpc);
127 }
128
129 static HRESULT nscolor_to_str(LPCWSTR color, BSTR *ret)
130 {
131 int i, rgb = -1;
132
133 static const WCHAR formatW[] = {'#','%','0','2','x','%','0','2','x','%','0','2','x',0};
134
135 if(!color || !*color) {
136 *ret = NULL;
137 return S_OK;
138 }
139
140 if(*color != '#') {
141 for(i=0; i < sizeof(keyword_table)/sizeof(keyword_table[0]); i++) {
142 if(!strcmpiW(color, keyword_table[i].keyword))
143 rgb = keyword_table[i].rgb;
144 }
145 }
146 if(rgb == -1)
147 rgb = loose_hex_to_rgb(color);
148
149 *ret = SysAllocStringLen(NULL, 7);
150 if(!*ret)
151 return E_OUTOFMEMORY;
152
153 sprintfW(*ret, formatW, rgb>>16, (rgb>>8)&0xff, rgb&0xff);
154
155 TRACE("%s -> %s\n", debugstr_w(color), debugstr_w(*ret));
156 return S_OK;
157 }
158
159 static BOOL variant_to_nscolor(const VARIANT *v, nsAString *nsstr)
160 {
161 switch(V_VT(v)) {
162 case VT_BSTR:
163 nsAString_Init(nsstr, V_BSTR(v));
164 return TRUE;
165
166 case VT_I4: {
167 PRUnichar buf[10];
168 static const WCHAR formatW[] = {'#','%','x',0};
169
170 wsprintfW(buf, formatW, V_I4(v));
171 nsAString_Init(nsstr, buf);
172 return TRUE;
173 }
174
175 default:
176 FIXME("invalid vt=%d\n", V_VT(v));
177 }
178
179 return FALSE;
180
181 }
182
183 static void nscolor_to_variant(const nsAString *nsstr, VARIANT *p)
184 {
185 const PRUnichar *color;
186
187 nsAString_GetData(nsstr, &color);
188
189 if(*color == '#') {
190 V_VT(p) = VT_I4;
191 V_I4(p) = strtolW(color+1, NULL, 16);
192 }else {
193 V_VT(p) = VT_BSTR;
194 V_BSTR(p) = SysAllocString(color);
195 }
196 }
197
198 #define HTMLBODY_THIS(iface) DEFINE_THIS(HTMLBodyElement, HTMLBodyElement, iface)
199
200 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
201 REFIID riid, void **ppv)
202 {
203 HTMLBodyElement *This = HTMLBODY_THIS(iface);
204
205 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->textcont.element.node), riid, ppv);
206 }
207
208 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
209 {
210 HTMLBodyElement *This = HTMLBODY_THIS(iface);
211
212 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->textcont.element.node));
213 }
214
215 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
216 {
217 HTMLBodyElement *This = HTMLBODY_THIS(iface);
218
219 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->textcont.element.node));
220 }
221
222 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
223 {
224 HTMLBodyElement *This = HTMLBODY_THIS(iface);
225 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->textcont.element.node.dispex), pctinfo);
226 }
227
228 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
229 LCID lcid, ITypeInfo **ppTInfo)
230 {
231 HTMLBodyElement *This = HTMLBODY_THIS(iface);
232 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->textcont.element.node.dispex), iTInfo, lcid, ppTInfo);
233 }
234
235 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
236 LPOLESTR *rgszNames, UINT cNames,
237 LCID lcid, DISPID *rgDispId)
238 {
239 HTMLBodyElement *This = HTMLBODY_THIS(iface);
240 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->textcont.element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
241 }
242
243 static HRESULT WINAPI HTMLBodyElement_Invoke(IHTMLBodyElement *iface, DISPID dispIdMember,
244 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
245 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
246 {
247 HTMLBodyElement *This = HTMLBODY_THIS(iface);
248 return IDispatchEx_Invoke(DISPATCHEX(&This->textcont.element.node.dispex), dispIdMember, riid, lcid,
249 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
250 }
251
252 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
253 {
254 HTMLBodyElement *This = HTMLBODY_THIS(iface);
255 nsAString nsstr;
256 nsresult nsres;
257
258 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
259
260 nsAString_InitDepend(&nsstr, v);
261 nsres = nsIDOMHTMLBodyElement_SetBackground(This->nsbody, &nsstr);
262 nsAString_Finish(&nsstr);
263 if(NS_FAILED(nsres))
264 return E_FAIL;
265
266 return S_OK;
267 }
268
269 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
270 {
271 HTMLBodyElement *This = HTMLBODY_THIS(iface);
272 nsAString background_str;
273 nsresult nsres;
274
275 TRACE("(%p)->(%p)\n", This, p);
276
277 nsAString_Init(&background_str, NULL);
278
279 nsres = nsIDOMHTMLBodyElement_GetBackground(This->nsbody, &background_str);
280 if(NS_SUCCEEDED(nsres)) {
281 const PRUnichar *background;
282 nsAString_GetData(&background_str, &background);
283 *p = *background ? SysAllocString(background) : NULL;
284 }else {
285 ERR("GetBackground failed: %08x\n", nsres);
286 *p = NULL;
287 }
288
289 nsAString_Finish(&background_str);
290
291 TRACE("*p = %s\n", debugstr_w(*p));
292 return S_OK;
293 }
294
295 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
296 {
297 HTMLBodyElement *This = HTMLBODY_THIS(iface);
298 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
299 return E_NOTIMPL;
300 }
301
302 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
303 {
304 HTMLBodyElement *This = HTMLBODY_THIS(iface);
305 FIXME("(%p)->(%p)\n", This, p);
306 return E_NOTIMPL;
307 }
308
309 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
310 {
311 HTMLBodyElement *This = HTMLBODY_THIS(iface);
312 FIXME("(%p)->()\n", This);
313 return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
317 {
318 HTMLBodyElement *This = HTMLBODY_THIS(iface);
319 FIXME("(%p)->(%p)\n", This, p);
320 return E_NOTIMPL;
321 }
322
323 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
324 {
325 HTMLBodyElement *This = HTMLBODY_THIS(iface);
326 FIXME("(%p)->()\n", This);
327 return E_NOTIMPL;
328 }
329
330 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
331 {
332 HTMLBodyElement *This = HTMLBODY_THIS(iface);
333 FIXME("(%p)->(%p)\n", This, p);
334 return E_NOTIMPL;
335 }
336
337 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
338 {
339 HTMLBodyElement *This = HTMLBODY_THIS(iface);
340 FIXME("(%p)->()\n", This);
341 return E_NOTIMPL;
342 }
343
344 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
345 {
346 HTMLBodyElement *This = HTMLBODY_THIS(iface);
347 FIXME("(%p)->(%p)\n", This, p);
348 return E_NOTIMPL;
349 }
350
351 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
352 {
353 HTMLBodyElement *This = HTMLBODY_THIS(iface);
354 FIXME("(%p)->()\n", This);
355 return E_NOTIMPL;
356 }
357
358 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
359 {
360 HTMLBodyElement *This = HTMLBODY_THIS(iface);
361 FIXME("(%p)->(%p)\n", This, p);
362 return E_NOTIMPL;
363 }
364
365 static HRESULT WINAPI HTMLBodyElement_put_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
366 {
367 HTMLBodyElement *This = HTMLBODY_THIS(iface);
368 FIXME("(%p)->(%x)\n", This, v);
369 return E_NOTIMPL;
370 }
371
372 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *p)
373 {
374 HTMLBodyElement *This = HTMLBODY_THIS(iface);
375 FIXME("(%p)->(%p)\n", This, p);
376 return E_NOTIMPL;
377 }
378
379 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
380 {
381 HTMLBodyElement *This = HTMLBODY_THIS(iface);
382 nsAString strColor;
383 nsresult nsres;
384
385 TRACE("(%p)->()\n", This);
386
387 if(!variant_to_nscolor(&v, &strColor))
388 return S_OK;
389
390 nsres = nsIDOMHTMLBodyElement_SetBgColor(This->nsbody, &strColor);
391 nsAString_Finish(&strColor);
392 if(NS_FAILED(nsres))
393 ERR("SetBgColor failed: %08x\n", nsres);
394
395 return S_OK;
396 }
397
398 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
399 {
400 HTMLBodyElement *This = HTMLBODY_THIS(iface);
401 nsAString strColor;
402 nsresult nsres;
403 HRESULT hres;
404
405 TRACE("(%p)->(%p)\n", This, p);
406
407 nsAString_Init(&strColor, NULL);
408 nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &strColor);
409 if(NS_SUCCEEDED(nsres)) {
410 const PRUnichar *color;
411
412 nsAString_GetData(&strColor, &color);
413 V_VT(p) = VT_BSTR;
414 hres = nscolor_to_str(color, &V_BSTR(p));
415 }else {
416 ERR("SetBgColor failed: %08x\n", nsres);
417 hres = E_FAIL;
418 }
419
420 nsAString_Finish(&strColor);
421 return hres;
422 }
423
424 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
425 {
426 HTMLBodyElement *This = HTMLBODY_THIS(iface);
427 nsAString text;
428 nsresult nsres;
429
430 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
431
432 if(!variant_to_nscolor(&v, &text))
433 return S_OK;
434
435 nsres = nsIDOMHTMLBodyElement_SetText(This->nsbody, &text);
436 nsAString_Finish(&text);
437
438 return S_OK;
439 }
440
441 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
442 {
443 HTMLBodyElement *This = HTMLBODY_THIS(iface);
444 nsAString text;
445 nsresult nsres;
446 HRESULT hres;
447
448 TRACE("(%p)->(%p)\n", This, p);
449
450 nsAString_Init(&text, NULL);
451 nsres = nsIDOMHTMLBodyElement_GetText(This->nsbody, &text);
452 if(NS_SUCCEEDED(nsres)) {
453 const PRUnichar *color;
454
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;
461 }
462
463 nsAString_Finish(&text);
464
465 return S_OK;
466 }
467
468 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
469 {
470 HTMLBodyElement *This = HTMLBODY_THIS(iface);
471 nsAString link_str;
472 nsresult nsres;
473
474 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
475
476 if(!variant_to_nscolor(&v, &link_str))
477 return S_OK;
478
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);
483
484 return S_OK;
485 }
486
487 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
488 {
489 HTMLBodyElement *This = HTMLBODY_THIS(iface);
490 nsAString link_str;
491 nsresult nsres;
492
493 TRACE("(%p)->(%p)\n", This, p);
494
495 nsAString_Init(&link_str, NULL);
496 nsres = nsIDOMHTMLBodyElement_GetLink(This->nsbody, &link_str);
497 if(NS_FAILED(nsres))
498 ERR("GetLink failed: %08x\n", nsres);
499
500 nscolor_to_variant(&link_str, p);
501 nsAString_Finish(&link_str);
502
503 return S_OK;
504 }
505
506 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
507 {
508 HTMLBodyElement *This = HTMLBODY_THIS(iface);
509 nsAString vlink_str;
510 nsresult nsres;
511
512 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
513
514 if(!variant_to_nscolor(&v, &vlink_str))
515 return S_OK;
516
517 nsres = nsIDOMHTMLBodyElement_SetVLink(This->nsbody, &vlink_str);
518 nsAString_Finish(&vlink_str);
519 if(NS_FAILED(nsres))
520 ERR("SetLink failed: %08x\n", nsres);
521
522 return S_OK;
523 }
524
525 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
526 {
527 HTMLBodyElement *This = HTMLBODY_THIS(iface);
528 nsAString vlink_str;
529 nsresult nsres;
530
531 TRACE("(%p)->(%p)\n", This, p);
532
533 nsAString_Init(&vlink_str, NULL);
534 nsres = nsIDOMHTMLBodyElement_GetVLink(This->nsbody, &vlink_str);
535 if(NS_FAILED(nsres))
536 ERR("GetLink failed: %08x\n", nsres);
537
538 nscolor_to_variant(&vlink_str, p);
539 nsAString_Finish(&vlink_str);
540
541 return S_OK;
542 }
543
544 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
545 {
546 HTMLBodyElement *This = HTMLBODY_THIS(iface);
547 nsAString alink_str;
548 nsresult nsres;
549
550 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
551
552 if(!variant_to_nscolor(&v, &alink_str))
553 return S_OK;
554
555 nsres = nsIDOMHTMLBodyElement_SetALink(This->nsbody, &alink_str);
556 nsAString_Finish(&alink_str);
557 if(NS_FAILED(nsres))
558 ERR("SetALink failed: %08x\n", nsres);
559
560 return S_OK;
561 }
562
563 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
564 {
565 HTMLBodyElement *This = HTMLBODY_THIS(iface);
566 nsAString alink_str;
567 nsresult nsres;
568
569 TRACE("(%p)->(%p)\n", This, p);
570
571 nsAString_Init(&alink_str, NULL);
572 nsres = nsIDOMHTMLBodyElement_GetALink(This->nsbody, &alink_str);
573 if(NS_FAILED(nsres))
574 ERR("GetALink failed: %08x\n", nsres);
575
576 nscolor_to_variant(&alink_str, p);
577 nsAString_Finish(&alink_str);
578
579 return S_OK;
580 }
581
582 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
583 {
584 HTMLBodyElement *This = HTMLBODY_THIS(iface);
585 FIXME("(%p)->()\n", This);
586 return E_NOTIMPL;
587 }
588
589 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
590 {
591 HTMLBodyElement *This = HTMLBODY_THIS(iface);
592 FIXME("(%p)->(%p)\n", This, p);
593 return E_NOTIMPL;
594 }
595
596 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
597 {
598 HTMLBodyElement *This = HTMLBODY_THIS(iface);
599 FIXME("(%p)->()\n", This);
600 return E_NOTIMPL;
601 }
602
603 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
604 {
605 HTMLBodyElement *This = HTMLBODY_THIS(iface);
606 FIXME("(%p)->(%p)\n", This, p);
607 return E_NOTIMPL;
608 }
609
610 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
611 {
612 HTMLBodyElement *This = HTMLBODY_THIS(iface);
613 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
614 return E_NOTIMPL;
615 }
616
617 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
618 {
619 HTMLBodyElement *This = HTMLBODY_THIS(iface);
620 FIXME("(%p)->(%p)\n", This, p);
621 return E_NOTIMPL;
622 }
623
624 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
625 {
626 HTMLBodyElement *This = HTMLBODY_THIS(iface);
627 FIXME("(%p)->()\n", This);
628 return E_NOTIMPL;
629 }
630
631 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
632 {
633 HTMLBodyElement *This = HTMLBODY_THIS(iface);
634 FIXME("(%p)->(%p)\n", This, p);
635 return E_NOTIMPL;
636 }
637
638 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
639 {
640 HTMLBodyElement *This = HTMLBODY_THIS(iface);
641 FIXME("(%p)->()\n", This);
642 return E_NOTIMPL;
643 }
644
645 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
646 {
647 HTMLBodyElement *This = HTMLBODY_THIS(iface);
648 FIXME("(%p)->(%p)\n", This, p);
649 return E_NOTIMPL;
650 }
651
652 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
653 {
654 HTMLBodyElement *This = HTMLBODY_THIS(iface);
655 nsIDOMDocumentRange *nsdocrange;
656 nsIDOMRange *nsrange = NULL;
657 nsresult nsres;
658 HRESULT hres;
659
660 TRACE("(%p)->(%p)\n", This, range);
661
662 if(!This->textcont.element.node.doc->nsdoc) {
663 WARN("No nsdoc\n");
664 return E_UNEXPECTED;
665 }
666
667 nsres = nsIDOMDocument_QueryInterface(This->textcont.element.node.doc->nsdoc, &IID_nsIDOMDocumentRange,
668 (void**)&nsdocrange);
669 if(NS_FAILED(nsres)) {
670 ERR("Could not get nsIDOMDocumentRabge iface: %08x\n", nsres);
671 return E_FAIL;
672 }
673
674 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &nsrange);
675 if(NS_SUCCEEDED(nsres)) {
676 nsres = nsIDOMRange_SelectNodeContents(nsrange, This->textcont.element.node.nsnode);
677 if(NS_FAILED(nsres))
678 ERR("SelectNodeContents failed: %08x\n", nsres);
679 }else {
680 ERR("CreateRange failed: %08x\n", nsres);
681 }
682
683 nsIDOMDocumentRange_Release(nsdocrange);
684
685 hres = HTMLTxtRange_Create(This->textcont.element.node.doc->basedoc.doc_node, nsrange, range);
686
687 nsIDOMRange_Release(nsrange);
688 return hres;
689 }
690
691 #undef HTMLBODY_THIS
692
693 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
694 HTMLBodyElement_QueryInterface,
695 HTMLBodyElement_AddRef,
696 HTMLBodyElement_Release,
697 HTMLBodyElement_GetTypeInfoCount,
698 HTMLBodyElement_GetTypeInfo,
699 HTMLBodyElement_GetIDsOfNames,
700 HTMLBodyElement_Invoke,
701 HTMLBodyElement_put_background,
702 HTMLBodyElement_get_background,
703 HTMLBodyElement_put_bgProperties,
704 HTMLBodyElement_get_bgProperties,
705 HTMLBodyElement_put_leftMargin,
706 HTMLBodyElement_get_leftMargin,
707 HTMLBodyElement_put_topMargin,
708 HTMLBodyElement_get_topMargin,
709 HTMLBodyElement_put_rightMargin,
710 HTMLBodyElement_get_rightMargin,
711 HTMLBodyElement_put_bottomMargin,
712 HTMLBodyElement_get_bottomMargin,
713 HTMLBodyElement_put_noWrap,
714 HTMLBodyElement_get_noWrap,
715 HTMLBodyElement_put_bgColor,
716 HTMLBodyElement_get_bgColor,
717 HTMLBodyElement_put_text,
718 HTMLBodyElement_get_text,
719 HTMLBodyElement_put_link,
720 HTMLBodyElement_get_link,
721 HTMLBodyElement_put_vLink,
722 HTMLBodyElement_get_vLink,
723 HTMLBodyElement_put_aLink,
724 HTMLBodyElement_get_aLink,
725 HTMLBodyElement_put_onload,
726 HTMLBodyElement_get_onload,
727 HTMLBodyElement_put_onunload,
728 HTMLBodyElement_get_onunload,
729 HTMLBodyElement_put_scroll,
730 HTMLBodyElement_get_scroll,
731 HTMLBodyElement_put_onselect,
732 HTMLBodyElement_get_onselect,
733 HTMLBodyElement_put_onbeforeunload,
734 HTMLBodyElement_get_onbeforeunload,
735 HTMLBodyElement_createTextRange
736 };
737
738 #define HTMLBODY_NODE_THIS(iface) DEFINE_THIS2(HTMLBodyElement, textcont.element.node, iface)
739
740 static HRESULT HTMLBodyElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
741 {
742 HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface);
743
744 *ppv = NULL;
745
746 if(IsEqualGUID(&IID_IUnknown, riid)) {
747 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
748 *ppv = HTMLBODY(This);
749 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
750 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
751 *ppv = HTMLBODY(This);
752 }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
753 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
754 *ppv = HTMLBODY(This);
755 }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
756 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", &This->textcont, ppv);
757 *ppv = HTMLTEXTCONT(&This->textcont);
758 }
759
760 if(*ppv) {
761 IUnknown_AddRef((IUnknown*)*ppv);
762 return S_OK;
763 }
764
765 return HTMLElement_QI(&This->textcont.element.node, riid, ppv);
766 }
767
768 static void HTMLBodyElement_destructor(HTMLDOMNode *iface)
769 {
770 HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface);
771
772 nsIDOMHTMLBodyElement_Release(This->nsbody);
773
774 HTMLElement_destructor(&This->textcont.element.node);
775 }
776
777 static event_target_t **HTMLBodyElement_get_event_target(HTMLDOMNode *iface)
778 {
779 HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface);
780
781 return This->textcont.element.node.doc
782 ? &This->textcont.element.node.doc->body_event_target
783 : &This->textcont.element.node.event_target;
784 }
785
786 #undef HTMLBODY_NODE_THIS
787
788 static const NodeImplVtbl HTMLBodyElementImplVtbl = {
789 HTMLBodyElement_QI,
790 HTMLBodyElement_destructor,
791 HTMLBodyElement_get_event_target
792 };
793
794 static const tid_t HTMLBodyElement_iface_tids[] = {
795 IHTMLBodyElement_tid,
796 IHTMLBodyElement2_tid,
797 HTMLELEMENT_TIDS,
798 IHTMLTextContainer_tid,
799 IHTMLUniqueName_tid,
800 0
801 };
802
803 static dispex_static_data_t HTMLBodyElement_dispex = {
804 NULL,
805 DispHTMLBody_tid,
806 NULL,
807 HTMLBodyElement_iface_tids
808 };
809
810 HTMLElement *HTMLBodyElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
811 {
812 HTMLBodyElement *ret = heap_alloc_zero(sizeof(HTMLBodyElement));
813 nsresult nsres;
814
815 TRACE("(%p)->(%p)\n", ret, nselem);
816
817 ret->lpHTMLBodyElementVtbl = &HTMLBodyElementVtbl;
818 ret->textcont.element.node.vtbl = &HTMLBodyElementImplVtbl;
819
820 HTMLTextContainer_Init(&ret->textcont, doc, nselem, &HTMLBodyElement_dispex);
821
822 ConnectionPoint_Init(&ret->cp_propnotif, &ret->textcont.element.cp_container, &IID_IPropertyNotifySink, NULL);
823
824 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLBodyElement,
825 (void**)&ret->nsbody);
826 if(NS_FAILED(nsres))
827 ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres);
828
829 return &ret->textcont.element;
830 }