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
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
39 HTMLTextContainer textcont
;
41 const IHTMLBodyElementVtbl
*lpHTMLBodyElementVtbl
;
43 ConnectionPoint cp_propnotif
;
45 nsIDOMHTMLBodyElement
*nsbody
;
48 #define HTMLBODY(x) ((IHTMLBodyElement*) &(x)->lpHTMLBodyElementVtbl)
50 static BOOL
variant_to_nscolor(const VARIANT
*v
, nsAString
*nsstr
)
54 nsAString_Init(nsstr
, V_BSTR(v
));
59 static const WCHAR formatW
[] = {'#','%','x',0};
61 wsprintfW(buf
, formatW
, V_I4(v
));
62 nsAString_Init(nsstr
, buf
);
67 FIXME("invalid vt=%d\n", V_VT(v
));
74 static void nscolor_to_variant(const nsAString
*nsstr
, VARIANT
*p
)
76 const PRUnichar
*color
;
78 nsAString_GetData(nsstr
, &color
);
82 V_I4(p
) = strtolW(color
+1, NULL
, 16);
85 V_BSTR(p
) = SysAllocString(color
);
89 #define HTMLBODY_THIS(iface) DEFINE_THIS(HTMLBodyElement, HTMLBodyElement, iface)
91 static HRESULT WINAPI
HTMLBodyElement_QueryInterface(IHTMLBodyElement
*iface
,
92 REFIID riid
, void **ppv
)
94 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
96 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This
->textcont
.element
.node
), riid
, ppv
);
99 static ULONG WINAPI
HTMLBodyElement_AddRef(IHTMLBodyElement
*iface
)
101 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
103 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This
->textcont
.element
.node
));
106 static ULONG WINAPI
HTMLBodyElement_Release(IHTMLBodyElement
*iface
)
108 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
110 return IHTMLDOMNode_Release(HTMLDOMNODE(&This
->textcont
.element
.node
));
113 static HRESULT WINAPI
HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement
*iface
, UINT
*pctinfo
)
115 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
116 FIXME("(%p)->(%p)\n", This
, pctinfo
);
120 static HRESULT WINAPI
HTMLBodyElement_GetTypeInfo(IHTMLBodyElement
*iface
, UINT iTInfo
,
121 LCID lcid
, ITypeInfo
**ppTInfo
)
123 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
124 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
128 static HRESULT WINAPI
HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement
*iface
, REFIID riid
,
129 LPOLESTR
*rgszNames
, UINT cNames
,
130 LCID lcid
, DISPID
*rgDispId
)
132 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
133 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
138 static HRESULT WINAPI
HTMLBodyElement_Invoke(IHTMLBodyElement
*iface
, DISPID dispIdMember
,
139 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
140 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
142 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
143 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
144 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
148 static HRESULT WINAPI
HTMLBodyElement_put_background(IHTMLBodyElement
*iface
, BSTR v
)
150 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
151 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
155 static HRESULT WINAPI
HTMLBodyElement_get_background(IHTMLBodyElement
*iface
, BSTR
*p
)
157 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
158 nsAString background_str
;
161 TRACE("(%p)->(%p)\n", This
, p
);
163 nsAString_Init(&background_str
, NULL
);
165 nsres
= nsIDOMHTMLBodyElement_GetBackground(This
->nsbody
, &background_str
);
166 if(NS_SUCCEEDED(nsres
)) {
167 const PRUnichar
*background
;
168 nsAString_GetData(&background_str
, &background
);
169 *p
= *background
? SysAllocString(background
) : NULL
;
171 ERR("GetBackground failed: %08x\n", nsres
);
175 nsAString_Finish(&background_str
);
177 TRACE("*p = %s\n", debugstr_w(*p
));
181 static HRESULT WINAPI
HTMLBodyElement_put_bgProperties(IHTMLBodyElement
*iface
, BSTR v
)
183 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
184 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
188 static HRESULT WINAPI
HTMLBodyElement_get_bgProperties(IHTMLBodyElement
*iface
, BSTR
*p
)
190 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
191 FIXME("(%p)->(%p)\n", This
, p
);
195 static HRESULT WINAPI
HTMLBodyElement_put_leftMargin(IHTMLBodyElement
*iface
, VARIANT v
)
197 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
198 FIXME("(%p)->()\n", This
);
202 static HRESULT WINAPI
HTMLBodyElement_get_leftMargin(IHTMLBodyElement
*iface
, VARIANT
*p
)
204 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
205 FIXME("(%p)->(%p)\n", This
, p
);
209 static HRESULT WINAPI
HTMLBodyElement_put_topMargin(IHTMLBodyElement
*iface
, VARIANT v
)
211 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
212 FIXME("(%p)->()\n", This
);
216 static HRESULT WINAPI
HTMLBodyElement_get_topMargin(IHTMLBodyElement
*iface
, VARIANT
*p
)
218 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
219 FIXME("(%p)->(%p)\n", This
, p
);
223 static HRESULT WINAPI
HTMLBodyElement_put_rightMargin(IHTMLBodyElement
*iface
, VARIANT v
)
225 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
226 FIXME("(%p)->()\n", This
);
230 static HRESULT WINAPI
HTMLBodyElement_get_rightMargin(IHTMLBodyElement
*iface
, VARIANT
*p
)
232 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
233 FIXME("(%p)->(%p)\n", This
, p
);
237 static HRESULT WINAPI
HTMLBodyElement_put_bottomMargin(IHTMLBodyElement
*iface
, VARIANT v
)
239 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
240 FIXME("(%p)->()\n", This
);
244 static HRESULT WINAPI
HTMLBodyElement_get_bottomMargin(IHTMLBodyElement
*iface
, VARIANT
*p
)
246 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
247 FIXME("(%p)->(%p)\n", This
, p
);
251 static HRESULT WINAPI
HTMLBodyElement_put_noWrap(IHTMLBodyElement
*iface
, VARIANT_BOOL v
)
253 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
254 FIXME("(%p)->(%x)\n", This
, v
);
258 static HRESULT WINAPI
HTMLBodyElement_get_noWrap(IHTMLBodyElement
*iface
, VARIANT_BOOL
*p
)
260 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
261 FIXME("(%p)->(%p)\n", This
, p
);
265 static HRESULT WINAPI
HTMLBodyElement_put_bgColor(IHTMLBodyElement
*iface
, VARIANT v
)
267 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
268 FIXME("(%p)->()\n", This
);
272 static HRESULT WINAPI
HTMLBodyElement_get_bgColor(IHTMLBodyElement
*iface
, VARIANT
*p
)
274 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
275 FIXME("(%p)->(%p)\n", This
, p
);
279 static HRESULT WINAPI
HTMLBodyElement_put_text(IHTMLBodyElement
*iface
, VARIANT v
)
281 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
282 FIXME("(%p)->()\n", This
);
286 static HRESULT WINAPI
HTMLBodyElement_get_text(IHTMLBodyElement
*iface
, VARIANT
*p
)
288 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
289 FIXME("(%p)->(%p)\n", This
, p
);
293 static HRESULT WINAPI
HTMLBodyElement_put_link(IHTMLBodyElement
*iface
, VARIANT v
)
295 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
299 TRACE("(%p)->(v%d)\n", This
, V_VT(&v
));
301 if(!variant_to_nscolor(&v
, &link_str
))
304 nsres
= nsIDOMHTMLBodyElement_SetLink(This
->nsbody
, &link_str
);
305 nsAString_Finish(&link_str
);
307 ERR("SetLink failed: %08x\n", nsres
);
312 static HRESULT WINAPI
HTMLBodyElement_get_link(IHTMLBodyElement
*iface
, VARIANT
*p
)
314 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
318 TRACE("(%p)->(%p)\n", This
, p
);
320 nsAString_Init(&link_str
, NULL
);
321 nsres
= nsIDOMHTMLBodyElement_GetLink(This
->nsbody
, &link_str
);
323 ERR("GetLink failed: %08x\n", nsres
);
325 nscolor_to_variant(&link_str
, p
);
326 nsAString_Finish(&link_str
);
331 static HRESULT WINAPI
HTMLBodyElement_put_vLink(IHTMLBodyElement
*iface
, VARIANT v
)
333 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
337 TRACE("(%p)->(v%d)\n", This
, V_VT(&v
));
339 if(!variant_to_nscolor(&v
, &vlink_str
))
342 nsres
= nsIDOMHTMLBodyElement_SetVLink(This
->nsbody
, &vlink_str
);
343 nsAString_Finish(&vlink_str
);
345 ERR("SetLink failed: %08x\n", nsres
);
350 static HRESULT WINAPI
HTMLBodyElement_get_vLink(IHTMLBodyElement
*iface
, VARIANT
*p
)
352 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
356 TRACE("(%p)->(%p)\n", This
, p
);
358 nsAString_Init(&vlink_str
, NULL
);
359 nsres
= nsIDOMHTMLBodyElement_GetVLink(This
->nsbody
, &vlink_str
);
361 ERR("GetLink failed: %08x\n", nsres
);
363 nscolor_to_variant(&vlink_str
, p
);
364 nsAString_Finish(&vlink_str
);
369 static HRESULT WINAPI
HTMLBodyElement_put_aLink(IHTMLBodyElement
*iface
, VARIANT v
)
371 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
375 TRACE("(%p)->(v%d)\n", This
, V_VT(&v
));
377 if(!variant_to_nscolor(&v
, &alink_str
))
380 nsres
= nsIDOMHTMLBodyElement_SetALink(This
->nsbody
, &alink_str
);
381 nsAString_Finish(&alink_str
);
383 ERR("SetALink failed: %08x\n", nsres
);
388 static HRESULT WINAPI
HTMLBodyElement_get_aLink(IHTMLBodyElement
*iface
, VARIANT
*p
)
390 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
394 TRACE("(%p)->(%p)\n", This
, p
);
396 nsAString_Init(&alink_str
, NULL
);
397 nsres
= nsIDOMHTMLBodyElement_GetALink(This
->nsbody
, &alink_str
);
399 ERR("GetALink failed: %08x\n", nsres
);
401 nscolor_to_variant(&alink_str
, p
);
402 nsAString_Finish(&alink_str
);
407 static HRESULT WINAPI
HTMLBodyElement_put_onload(IHTMLBodyElement
*iface
, VARIANT v
)
409 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
410 FIXME("(%p)->()\n", This
);
414 static HRESULT WINAPI
HTMLBodyElement_get_onload(IHTMLBodyElement
*iface
, VARIANT
*p
)
416 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
417 FIXME("(%p)->(%p)\n", This
, p
);
421 static HRESULT WINAPI
HTMLBodyElement_put_onunload(IHTMLBodyElement
*iface
, VARIANT v
)
423 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
424 FIXME("(%p)->()\n", This
);
428 static HRESULT WINAPI
HTMLBodyElement_get_onunload(IHTMLBodyElement
*iface
, VARIANT
*p
)
430 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
431 FIXME("(%p)->(%p)\n", This
, p
);
435 static HRESULT WINAPI
HTMLBodyElement_put_scroll(IHTMLBodyElement
*iface
, BSTR v
)
437 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
438 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
442 static HRESULT WINAPI
HTMLBodyElement_get_scroll(IHTMLBodyElement
*iface
, BSTR
*p
)
444 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
445 FIXME("(%p)->(%p)\n", This
, p
);
449 static HRESULT WINAPI
HTMLBodyElement_put_onselect(IHTMLBodyElement
*iface
, VARIANT v
)
451 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
452 FIXME("(%p)->()\n", This
);
456 static HRESULT WINAPI
HTMLBodyElement_get_onselect(IHTMLBodyElement
*iface
, VARIANT
*p
)
458 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
459 FIXME("(%p)->(%p)\n", This
, p
);
463 static HRESULT WINAPI
HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement
*iface
, VARIANT v
)
465 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
466 FIXME("(%p)->()\n", This
);
470 static HRESULT WINAPI
HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement
*iface
, VARIANT
*p
)
472 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
473 FIXME("(%p)->(%p)\n", This
, p
);
477 static HRESULT WINAPI
HTMLBodyElement_createTextRange(IHTMLBodyElement
*iface
, IHTMLTxtRange
**range
)
479 HTMLBodyElement
*This
= HTMLBODY_THIS(iface
);
480 nsIDOMRange
*nsrange
= NULL
;
482 TRACE("(%p)->(%p)\n", This
, range
);
484 if(This
->textcont
.element
.node
.doc
->nscontainer
) {
485 nsIDOMDocument
*nsdoc
;
486 nsIDOMDocumentRange
*nsdocrange
;
489 nsIWebNavigation_GetDocument(This
->textcont
.element
.node
.doc
->nscontainer
->navigation
, &nsdoc
);
490 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMDocumentRange
, (void**)&nsdocrange
);
491 nsIDOMDocument_Release(nsdoc
);
493 nsres
= nsIDOMDocumentRange_CreateRange(nsdocrange
, &nsrange
);
494 if(NS_SUCCEEDED(nsres
)) {
495 nsres
= nsIDOMRange_SelectNodeContents(nsrange
, This
->textcont
.element
.node
.nsnode
);
497 ERR("SelectNodeContents failed: %08x\n", nsres
);
499 ERR("CreateRange failed: %08x\n", nsres
);
502 nsIDOMDocumentRange_Release(nsdocrange
);
505 *range
= HTMLTxtRange_Create(This
->textcont
.element
.node
.doc
, nsrange
);
511 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl
= {
512 HTMLBodyElement_QueryInterface
,
513 HTMLBodyElement_AddRef
,
514 HTMLBodyElement_Release
,
515 HTMLBodyElement_GetTypeInfoCount
,
516 HTMLBodyElement_GetTypeInfo
,
517 HTMLBodyElement_GetIDsOfNames
,
518 HTMLBodyElement_Invoke
,
519 HTMLBodyElement_put_background
,
520 HTMLBodyElement_get_background
,
521 HTMLBodyElement_put_bgProperties
,
522 HTMLBodyElement_get_bgProperties
,
523 HTMLBodyElement_put_leftMargin
,
524 HTMLBodyElement_get_leftMargin
,
525 HTMLBodyElement_put_topMargin
,
526 HTMLBodyElement_get_topMargin
,
527 HTMLBodyElement_put_rightMargin
,
528 HTMLBodyElement_get_rightMargin
,
529 HTMLBodyElement_put_bottomMargin
,
530 HTMLBodyElement_get_bottomMargin
,
531 HTMLBodyElement_put_noWrap
,
532 HTMLBodyElement_get_noWrap
,
533 HTMLBodyElement_put_bgColor
,
534 HTMLBodyElement_get_bgColor
,
535 HTMLBodyElement_put_text
,
536 HTMLBodyElement_get_text
,
537 HTMLBodyElement_put_link
,
538 HTMLBodyElement_get_link
,
539 HTMLBodyElement_put_vLink
,
540 HTMLBodyElement_get_vLink
,
541 HTMLBodyElement_put_aLink
,
542 HTMLBodyElement_get_aLink
,
543 HTMLBodyElement_put_onload
,
544 HTMLBodyElement_get_onload
,
545 HTMLBodyElement_put_onunload
,
546 HTMLBodyElement_get_onunload
,
547 HTMLBodyElement_put_scroll
,
548 HTMLBodyElement_get_scroll
,
549 HTMLBodyElement_put_onselect
,
550 HTMLBodyElement_get_onselect
,
551 HTMLBodyElement_put_onbeforeunload
,
552 HTMLBodyElement_get_onbeforeunload
,
553 HTMLBodyElement_createTextRange
556 #define HTMLBODY_NODE_THIS(iface) DEFINE_THIS2(HTMLBodyElement, textcont.element.node, iface)
558 static HRESULT
HTMLBodyElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
560 HTMLBodyElement
*This
= HTMLBODY_NODE_THIS(iface
);
564 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
565 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
566 *ppv
= HTMLBODY(This
);
567 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
568 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
569 *ppv
= HTMLBODY(This
);
570 }else if(IsEqualGUID(&IID_IHTMLBodyElement
, riid
)) {
571 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This
, ppv
);
572 *ppv
= HTMLBODY(This
);
573 }else if(IsEqualGUID(&IID_IHTMLTextContainer
, riid
)) {
574 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", &This
->textcont
, ppv
);
575 *ppv
= HTMLTEXTCONT(&This
->textcont
);
579 IUnknown_AddRef((IUnknown
*)*ppv
);
583 return HTMLElement_QI(&This
->textcont
.element
.node
, riid
, ppv
);
586 static void HTMLBodyElement_destructor(HTMLDOMNode
*iface
)
588 HTMLBodyElement
*This
= HTMLBODY_NODE_THIS(iface
);
590 nsIDOMHTMLBodyElement_Release(This
->nsbody
);
592 HTMLElement_destructor(&This
->textcont
.element
.node
);
595 #undef HTMLBODY_NODE_THIS
597 static const NodeImplVtbl HTMLBodyElementImplVtbl
= {
599 HTMLBodyElement_destructor
602 HTMLElement
*HTMLBodyElement_Create(nsIDOMHTMLElement
*nselem
)
604 HTMLBodyElement
*ret
= heap_alloc(sizeof(HTMLBodyElement
));
607 TRACE("(%p)->(%p)\n", ret
, nselem
);
609 HTMLTextContainer_Init(&ret
->textcont
);
611 ret
->lpHTMLBodyElementVtbl
= &HTMLBodyElementVtbl
;
612 ret
->textcont
.element
.node
.vtbl
= &HTMLBodyElementImplVtbl
;
614 ConnectionPoint_Init(&ret
->cp_propnotif
, &ret
->textcont
.element
.cp_container
, &IID_IPropertyNotifySink
);
616 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLBodyElement
,
617 (void**)&ret
->nsbody
);
619 ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres
);
621 return &ret
->textcont
.element
;