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) ((IHTMLBodyElement*) &(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 FIXME("(%p)->(%p)\n", This
, pctinfo
);
117 static HRESULT WINAPI
HTMLBodyElement_GetTypeInfo(IHTMLBodyElement
*iface
, UINT iTInfo
,
118 LCID lcid
, ITypeInfo
**ppTInfo
)
120 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
121 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
125 static HRESULT WINAPI
HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement
*iface
, REFIID riid
,
126 LPOLESTR
*rgszNames
, UINT cNames
,
127 LCID lcid
, DISPID
*rgDispId
)
129 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
130 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
135 static HRESULT WINAPI
HTMLBodyElement_Invoke(IHTMLBodyElement
*iface
, DISPID dispIdMember
,
136 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
137 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
139 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
140 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
141 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
145 static HRESULT WINAPI
HTMLBodyElement_put_background(IHTMLBodyElement
*iface
, BSTR v
)
147 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
148 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
152 static HRESULT WINAPI
HTMLBodyElement_get_background(IHTMLBodyElement
*iface
, BSTR
*p
)
154 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
155 nsAString background_str
;
158 TRACE("(%p)->(%p)\n", This
, p
);
160 nsAString_Init(&background_str
, NULL
);
162 nsres
= nsIDOMHTMLBodyElement_GetBackground(This
->nsbody
, &background_str
);
163 if(NS_SUCCEEDED(nsres
)) {
164 const PRUnichar
*background
;
165 nsAString_GetData(&background_str
, &background
);
166 *p
= *background
? SysAllocString(background
) : NULL
;
168 ERR("GetBackground failed: %08x\n", nsres
);
172 nsAString_Finish(&background_str
);
174 TRACE("*p = %s\n", debugstr_w(*p
));
178 static HRESULT WINAPI
HTMLBodyElement_put_bgProperties(IHTMLBodyElement
*iface
, BSTR v
)
180 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
181 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
185 static HRESULT WINAPI
HTMLBodyElement_get_bgProperties(IHTMLBodyElement
*iface
, BSTR
*p
)
187 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
188 FIXME("(%p)->(%p)\n", This
, p
);
192 static HRESULT WINAPI
HTMLBodyElement_put_leftMargin(IHTMLBodyElement
*iface
, VARIANT v
)
194 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
195 FIXME("(%p)->()\n", This
);
199 static HRESULT WINAPI
HTMLBodyElement_get_leftMargin(IHTMLBodyElement
*iface
, VARIANT
*p
)
201 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
202 FIXME("(%p)->(%p)\n", This
, p
);
206 static HRESULT WINAPI
HTMLBodyElement_put_topMargin(IHTMLBodyElement
*iface
, VARIANT v
)
208 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
209 FIXME("(%p)->()\n", This
);
213 static HRESULT WINAPI
HTMLBodyElement_get_topMargin(IHTMLBodyElement
*iface
, VARIANT
*p
)
215 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
216 FIXME("(%p)->(%p)\n", This
, p
);
220 static HRESULT WINAPI
HTMLBodyElement_put_rightMargin(IHTMLBodyElement
*iface
, VARIANT v
)
222 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
223 FIXME("(%p)->()\n", This
);
227 static HRESULT WINAPI
HTMLBodyElement_get_rightMargin(IHTMLBodyElement
*iface
, VARIANT
*p
)
229 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
230 FIXME("(%p)->(%p)\n", This
, p
);
234 static HRESULT WINAPI
HTMLBodyElement_put_bottomMargin(IHTMLBodyElement
*iface
, VARIANT v
)
236 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
237 FIXME("(%p)->()\n", This
);
241 static HRESULT WINAPI
HTMLBodyElement_get_bottomMargin(IHTMLBodyElement
*iface
, VARIANT
*p
)
243 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
244 FIXME("(%p)->(%p)\n", This
, p
);
248 static HRESULT WINAPI
HTMLBodyElement_put_noWrap(IHTMLBodyElement
*iface
, VARIANT_BOOL v
)
250 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
251 FIXME("(%p)->(%x)\n", This
, v
);
255 static HRESULT WINAPI
HTMLBodyElement_get_noWrap(IHTMLBodyElement
*iface
, VARIANT_BOOL
*p
)
257 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
258 FIXME("(%p)->(%p)\n", This
, p
);
262 static HRESULT WINAPI
HTMLBodyElement_put_bgColor(IHTMLBodyElement
*iface
, VARIANT v
)
264 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
265 FIXME("(%p)->()\n", This
);
269 static HRESULT WINAPI
HTMLBodyElement_get_bgColor(IHTMLBodyElement
*iface
, VARIANT
*p
)
271 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
272 FIXME("(%p)->(%p)\n", This
, p
);
276 static HRESULT WINAPI
HTMLBodyElement_put_text(IHTMLBodyElement
*iface
, VARIANT v
)
278 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
279 FIXME("(%p)->()\n", This
);
283 static HRESULT WINAPI
HTMLBodyElement_get_text(IHTMLBodyElement
*iface
, VARIANT
*p
)
285 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
286 FIXME("(%p)->(%p)\n", This
, p
);
290 static HRESULT WINAPI
HTMLBodyElement_put_link(IHTMLBodyElement
*iface
, VARIANT v
)
292 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
296 TRACE("(%p)->(v%d)\n", This
, V_VT(&v
));
298 if(!variant_to_nscolor(&v
, &link_str
))
301 nsres
= nsIDOMHTMLBodyElement_SetLink(This
->nsbody
, &link_str
);
302 nsAString_Finish(&link_str
);
304 ERR("SetLink failed: %08x\n", nsres
);
309 static HRESULT WINAPI
HTMLBodyElement_get_link(IHTMLBodyElement
*iface
, VARIANT
*p
)
311 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
315 TRACE("(%p)->(%p)\n", This
, p
);
317 nsAString_Init(&link_str
, NULL
);
318 nsres
= nsIDOMHTMLBodyElement_GetLink(This
->nsbody
, &link_str
);
320 ERR("GetLink failed: %08x\n", nsres
);
322 nscolor_to_variant(&link_str
, p
);
323 nsAString_Finish(&link_str
);
328 static HRESULT WINAPI
HTMLBodyElement_put_vLink(IHTMLBodyElement
*iface
, VARIANT v
)
330 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
334 TRACE("(%p)->(v%d)\n", This
, V_VT(&v
));
336 if(!variant_to_nscolor(&v
, &vlink_str
))
339 nsres
= nsIDOMHTMLBodyElement_SetVLink(This
->nsbody
, &vlink_str
);
340 nsAString_Finish(&vlink_str
);
342 ERR("SetLink failed: %08x\n", nsres
);
347 static HRESULT WINAPI
HTMLBodyElement_get_vLink(IHTMLBodyElement
*iface
, VARIANT
*p
)
349 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
353 TRACE("(%p)->(%p)\n", This
, p
);
355 nsAString_Init(&vlink_str
, NULL
);
356 nsres
= nsIDOMHTMLBodyElement_GetVLink(This
->nsbody
, &vlink_str
);
358 ERR("GetLink failed: %08x\n", nsres
);
360 nscolor_to_variant(&vlink_str
, p
);
361 nsAString_Finish(&vlink_str
);
366 static HRESULT WINAPI
HTMLBodyElement_put_aLink(IHTMLBodyElement
*iface
, VARIANT v
)
368 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
372 TRACE("(%p)->(v%d)\n", This
, V_VT(&v
));
374 if(!variant_to_nscolor(&v
, &alink_str
))
377 nsres
= nsIDOMHTMLBodyElement_SetALink(This
->nsbody
, &alink_str
);
378 nsAString_Finish(&alink_str
);
380 ERR("SetALink failed: %08x\n", nsres
);
385 static HRESULT WINAPI
HTMLBodyElement_get_aLink(IHTMLBodyElement
*iface
, VARIANT
*p
)
387 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
391 TRACE("(%p)->(%p)\n", This
, p
);
393 nsAString_Init(&alink_str
, NULL
);
394 nsres
= nsIDOMHTMLBodyElement_GetALink(This
->nsbody
, &alink_str
);
396 ERR("GetALink failed: %08x\n", nsres
);
398 nscolor_to_variant(&alink_str
, p
);
399 nsAString_Finish(&alink_str
);
404 static HRESULT WINAPI
HTMLBodyElement_put_onload(IHTMLBodyElement
*iface
, VARIANT v
)
406 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
407 FIXME("(%p)->()\n", This
);
411 static HRESULT WINAPI
HTMLBodyElement_get_onload(IHTMLBodyElement
*iface
, VARIANT
*p
)
413 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
414 FIXME("(%p)->(%p)\n", This
, p
);
418 static HRESULT WINAPI
HTMLBodyElement_put_onunload(IHTMLBodyElement
*iface
, VARIANT v
)
420 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
421 FIXME("(%p)->()\n", This
);
425 static HRESULT WINAPI
HTMLBodyElement_get_onunload(IHTMLBodyElement
*iface
, VARIANT
*p
)
427 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
428 FIXME("(%p)->(%p)\n", This
, p
);
432 static HRESULT WINAPI
HTMLBodyElement_put_scroll(IHTMLBodyElement
*iface
, BSTR v
)
434 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
435 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
439 static HRESULT WINAPI
HTMLBodyElement_get_scroll(IHTMLBodyElement
*iface
, BSTR
*p
)
441 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
442 FIXME("(%p)->(%p)\n", This
, p
);
446 static HRESULT WINAPI
HTMLBodyElement_put_onselect(IHTMLBodyElement
*iface
, VARIANT v
)
448 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
449 FIXME("(%p)->()\n", This
);
453 static HRESULT WINAPI
HTMLBodyElement_get_onselect(IHTMLBodyElement
*iface
, VARIANT
*p
)
455 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
456 FIXME("(%p)->(%p)\n", This
, p
);
460 static HRESULT WINAPI
HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement
*iface
, VARIANT v
)
462 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
463 FIXME("(%p)->()\n", This
);
467 static HRESULT WINAPI
HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement
*iface
, VARIANT
*p
)
469 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
470 FIXME("(%p)->(%p)\n", This
, p
);
474 static HRESULT WINAPI
HTMLBodyElement_createTextRange(IHTMLBodyElement
*iface
, IHTMLTxtRange
**range
)
476 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
477 nsIDOMRange
*nsrange
= NULL
;
479 TRACE("(%p)->(%p)\n", This
, range
);
481 if(This
->textcont
.element
.node
.doc
->nscontainer
) {
482 nsIDOMDocument
*nsdoc
;
483 nsIDOMDocumentRange
*nsdocrange
;
486 nsIWebNavigation_GetDocument(This
->textcont
.element
.node
.doc
->nscontainer
->navigation
, &nsdoc
);
487 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMDocumentRange
, (void**)&nsdocrange
);
488 nsIDOMDocument_Release(nsdoc
);
490 nsres
= nsIDOMDocumentRange_CreateRange(nsdocrange
, &nsrange
);
491 if(NS_SUCCEEDED(nsres
)) {
492 nsres
= nsIDOMRange_SelectNodeContents(nsrange
, This
->textcont
.element
.node
.nsnode
);
494 ERR("SelectNodeContents failed: %08x\n", nsres
);
496 ERR("CreateRange failed: %08x\n", nsres
);
499 nsIDOMDocumentRange_Release(nsdocrange
);
502 *range
= HTMLTxtRange_Create(This
->textcont
.element
.node
.doc
, nsrange
);
508 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl
= {
509 HTMLBodyElement_QueryInterface
,
510 HTMLBodyElement_AddRef
,
511 HTMLBodyElement_Release
,
512 HTMLBodyElement_GetTypeInfoCount
,
513 HTMLBodyElement_GetTypeInfo
,
514 HTMLBodyElement_GetIDsOfNames
,
515 HTMLBodyElement_Invoke
,
516 HTMLBodyElement_put_background
,
517 HTMLBodyElement_get_background
,
518 HTMLBodyElement_put_bgProperties
,
519 HTMLBodyElement_get_bgProperties
,
520 HTMLBodyElement_put_leftMargin
,
521 HTMLBodyElement_get_leftMargin
,
522 HTMLBodyElement_put_topMargin
,
523 HTMLBodyElement_get_topMargin
,
524 HTMLBodyElement_put_rightMargin
,
525 HTMLBodyElement_get_rightMargin
,
526 HTMLBodyElement_put_bottomMargin
,
527 HTMLBodyElement_get_bottomMargin
,
528 HTMLBodyElement_put_noWrap
,
529 HTMLBodyElement_get_noWrap
,
530 HTMLBodyElement_put_bgColor
,
531 HTMLBodyElement_get_bgColor
,
532 HTMLBodyElement_put_text
,
533 HTMLBodyElement_get_text
,
534 HTMLBodyElement_put_link
,
535 HTMLBodyElement_get_link
,
536 HTMLBodyElement_put_vLink
,
537 HTMLBodyElement_get_vLink
,
538 HTMLBodyElement_put_aLink
,
539 HTMLBodyElement_get_aLink
,
540 HTMLBodyElement_put_onload
,
541 HTMLBodyElement_get_onload
,
542 HTMLBodyElement_put_onunload
,
543 HTMLBodyElement_get_onunload
,
544 HTMLBodyElement_put_scroll
,
545 HTMLBodyElement_get_scroll
,
546 HTMLBodyElement_put_onselect
,
547 HTMLBodyElement_get_onselect
,
548 HTMLBodyElement_put_onbeforeunload
,
549 HTMLBodyElement_get_onbeforeunload
,
550 HTMLBodyElement_createTextRange
553 #define HTMLBODY_NODE_THIS(iface) DEFINE_THIS2(HTMLBodyElement, textcont.element.node, iface)
555 static HRESULT
HTMLBodyElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
557 HTMLBodyElement
*This
= HTMLBODY_NODE_THIS(iface
);
561 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
562 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
563 *ppv
= HTMLBODY(This
);
564 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
565 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
566 *ppv
= HTMLBODY(This
);
567 }else if(IsEqualGUID(&IID_IHTMLBodyElement
, riid
)) {
568 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This
, ppv
);
569 *ppv
= HTMLBODY(This
);
570 }else if(IsEqualGUID(&IID_IHTMLTextContainer
, riid
)) {
571 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", &This
->textcont
, ppv
);
572 *ppv
= HTMLTEXTCONT(&This
->textcont
);
576 IUnknown_AddRef((IUnknown
*)*ppv
);
580 return HTMLElement_QI(&This
->textcont
.element
.node
, riid
, ppv
);
583 static void HTMLBodyElement_destructor(HTMLDOMNode
*iface
)
585 HTMLBodyElement
*This
= HTMLBODY_NODE_THIS(iface
);
587 nsIDOMHTMLBodyElement_Release(This
->nsbody
);
589 HTMLElement_destructor(&This
->textcont
.element
.node
);
592 #undef HTMLBODY_NODE_THIS
594 static const NodeImplVtbl HTMLBodyElementImplVtbl
= {
596 HTMLBodyElement_destructor
599 HTMLElement
*HTMLBodyElement_Create(nsIDOMHTMLElement
*nselem
)
601 HTMLBodyElement
*ret
= heap_alloc_zero(sizeof(HTMLBodyElement
));
604 TRACE("(%p)->(%p)\n", ret
, nselem
);
606 HTMLTextContainer_Init(&ret
->textcont
);
608 ret
->lpHTMLBodyElementVtbl
= &HTMLBodyElementVtbl
;
609 ret
->textcont
.element
.node
.vtbl
= &HTMLBodyElementImplVtbl
;
611 ConnectionPoint_Init(&ret
->cp_propnotif
, &ret
->textcont
.element
.cp_container
, &IID_IPropertyNotifySink
);
613 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLBodyElement
,
614 (void**)&ret
->nsbody
);
616 ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres
);
618 return &ret
->textcont
.element
;