appwiz.cpl: Add imagelist for listview.
[wine/multimedia.git] / dlls / mshtml / htmlbody.c
blob8e1f70c7e47d32414885cab9eab46abc26416039
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>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 typedef struct {
36 HTMLTextContainer textcont;
38 const IHTMLBodyElementVtbl *lpHTMLBodyElementVtbl;
40 ConnectionPoint cp_propnotif;
42 nsIDOMHTMLBodyElement *nsbody;
43 } HTMLBodyElement;
45 #define HTMLBODY(x) ((IHTMLBodyElement*) &(x)->lpHTMLBodyElementVtbl)
47 static BOOL variant_to_nscolor(const VARIANT *v, nsAString *nsstr)
49 switch(V_VT(v)) {
50 case VT_BSTR:
51 nsAString_Init(nsstr, V_BSTR(v));
52 return TRUE;
54 case VT_I4: {
55 PRUnichar buf[10];
56 static const WCHAR formatW[] = {'#','%','x',0};
58 wsprintfW(buf, formatW, V_I4(v));
59 nsAString_Init(nsstr, buf);
60 return TRUE;
63 default:
64 FIXME("invalid vt=%d\n", V_VT(v));
67 return FALSE;
71 static void nscolor_to_variant(const nsAString *nsstr, VARIANT *p)
73 const PRUnichar *color;
75 nsAString_GetData(nsstr, &color);
77 if(*color == '#') {
78 V_VT(p) = VT_I4;
79 V_I4(p) = strtolW(color+1, NULL, 16);
80 }else {
81 V_VT(p) = VT_BSTR;
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);
114 return E_NOTIMPL;
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);
122 return E_NOTIMPL;
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,
131 lcid, rgDispId);
132 return E_NOTIMPL;
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);
142 return E_NOTIMPL;
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));
149 return E_NOTIMPL;
152 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
154 HTMLBodyElement *This = HTMLBODY_THIS(iface);
155 nsAString background_str;
156 nsresult nsres;
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;
167 }else {
168 ERR("GetBackground failed: %08x\n", nsres);
169 *p = NULL;
172 nsAString_Finish(&background_str);
174 TRACE("*p = %s\n", debugstr_w(*p));
175 return S_OK;
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));
182 return E_NOTIMPL;
185 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
187 HTMLBodyElement *This = HTMLBODY_THIS(iface);
188 FIXME("(%p)->(%p)\n", This, p);
189 return E_NOTIMPL;
192 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
194 HTMLBodyElement *This = HTMLBODY_THIS(iface);
195 FIXME("(%p)->()\n", This);
196 return E_NOTIMPL;
199 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
201 HTMLBodyElement *This = HTMLBODY_THIS(iface);
202 FIXME("(%p)->(%p)\n", This, p);
203 return E_NOTIMPL;
206 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
208 HTMLBodyElement *This = HTMLBODY_THIS(iface);
209 FIXME("(%p)->()\n", This);
210 return E_NOTIMPL;
213 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
215 HTMLBodyElement *This = HTMLBODY_THIS(iface);
216 FIXME("(%p)->(%p)\n", This, p);
217 return E_NOTIMPL;
220 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
222 HTMLBodyElement *This = HTMLBODY_THIS(iface);
223 FIXME("(%p)->()\n", This);
224 return E_NOTIMPL;
227 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
229 HTMLBodyElement *This = HTMLBODY_THIS(iface);
230 FIXME("(%p)->(%p)\n", This, p);
231 return E_NOTIMPL;
234 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
236 HTMLBodyElement *This = HTMLBODY_THIS(iface);
237 FIXME("(%p)->()\n", This);
238 return E_NOTIMPL;
241 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
243 HTMLBodyElement *This = HTMLBODY_THIS(iface);
244 FIXME("(%p)->(%p)\n", This, p);
245 return E_NOTIMPL;
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);
252 return E_NOTIMPL;
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);
259 return E_NOTIMPL;
262 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
264 HTMLBodyElement *This = HTMLBODY_THIS(iface);
265 FIXME("(%p)->()\n", This);
266 return E_NOTIMPL;
269 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
271 HTMLBodyElement *This = HTMLBODY_THIS(iface);
272 FIXME("(%p)->(%p)\n", This, p);
273 return E_NOTIMPL;
276 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
278 HTMLBodyElement *This = HTMLBODY_THIS(iface);
279 FIXME("(%p)->()\n", This);
280 return E_NOTIMPL;
283 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
285 HTMLBodyElement *This = HTMLBODY_THIS(iface);
286 FIXME("(%p)->(%p)\n", This, p);
287 return E_NOTIMPL;
290 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
292 HTMLBodyElement *This = HTMLBODY_THIS(iface);
293 nsAString link_str;
294 nsresult nsres;
296 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
298 if(!variant_to_nscolor(&v, &link_str))
299 return S_OK;
301 nsres = nsIDOMHTMLBodyElement_SetLink(This->nsbody, &link_str);
302 nsAString_Finish(&link_str);
303 if(NS_FAILED(nsres))
304 ERR("SetLink failed: %08x\n", nsres);
306 return S_OK;
309 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
311 HTMLBodyElement *This = HTMLBODY_THIS(iface);
312 nsAString link_str;
313 nsresult nsres;
315 TRACE("(%p)->(%p)\n", This, p);
317 nsAString_Init(&link_str, NULL);
318 nsres = nsIDOMHTMLBodyElement_GetLink(This->nsbody, &link_str);
319 if(NS_FAILED(nsres))
320 ERR("GetLink failed: %08x\n", nsres);
322 nscolor_to_variant(&link_str, p);
323 nsAString_Finish(&link_str);
325 return S_OK;
328 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
330 HTMLBodyElement *This = HTMLBODY_THIS(iface);
331 nsAString vlink_str;
332 nsresult nsres;
334 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
336 if(!variant_to_nscolor(&v, &vlink_str))
337 return S_OK;
339 nsres = nsIDOMHTMLBodyElement_SetVLink(This->nsbody, &vlink_str);
340 nsAString_Finish(&vlink_str);
341 if(NS_FAILED(nsres))
342 ERR("SetLink failed: %08x\n", nsres);
344 return S_OK;
347 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
349 HTMLBodyElement *This = HTMLBODY_THIS(iface);
350 nsAString vlink_str;
351 nsresult nsres;
353 TRACE("(%p)->(%p)\n", This, p);
355 nsAString_Init(&vlink_str, NULL);
356 nsres = nsIDOMHTMLBodyElement_GetVLink(This->nsbody, &vlink_str);
357 if(NS_FAILED(nsres))
358 ERR("GetLink failed: %08x\n", nsres);
360 nscolor_to_variant(&vlink_str, p);
361 nsAString_Finish(&vlink_str);
363 return S_OK;
366 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
368 HTMLBodyElement *This = HTMLBODY_THIS(iface);
369 nsAString alink_str;
370 nsresult nsres;
372 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
374 if(!variant_to_nscolor(&v, &alink_str))
375 return S_OK;
377 nsres = nsIDOMHTMLBodyElement_SetALink(This->nsbody, &alink_str);
378 nsAString_Finish(&alink_str);
379 if(NS_FAILED(nsres))
380 ERR("SetALink failed: %08x\n", nsres);
382 return S_OK;
385 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
387 HTMLBodyElement *This = HTMLBODY_THIS(iface);
388 nsAString alink_str;
389 nsresult nsres;
391 TRACE("(%p)->(%p)\n", This, p);
393 nsAString_Init(&alink_str, NULL);
394 nsres = nsIDOMHTMLBodyElement_GetALink(This->nsbody, &alink_str);
395 if(NS_FAILED(nsres))
396 ERR("GetALink failed: %08x\n", nsres);
398 nscolor_to_variant(&alink_str, p);
399 nsAString_Finish(&alink_str);
401 return S_OK;
404 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
406 HTMLBodyElement *This = HTMLBODY_THIS(iface);
407 FIXME("(%p)->()\n", This);
408 return E_NOTIMPL;
411 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
413 HTMLBodyElement *This = HTMLBODY_THIS(iface);
414 FIXME("(%p)->(%p)\n", This, p);
415 return E_NOTIMPL;
418 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
420 HTMLBodyElement *This = HTMLBODY_THIS(iface);
421 FIXME("(%p)->()\n", This);
422 return E_NOTIMPL;
425 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
427 HTMLBodyElement *This = HTMLBODY_THIS(iface);
428 FIXME("(%p)->(%p)\n", This, p);
429 return E_NOTIMPL;
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));
436 return E_NOTIMPL;
439 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
441 HTMLBodyElement *This = HTMLBODY_THIS(iface);
442 FIXME("(%p)->(%p)\n", This, p);
443 return E_NOTIMPL;
446 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
448 HTMLBodyElement *This = HTMLBODY_THIS(iface);
449 FIXME("(%p)->()\n", This);
450 return E_NOTIMPL;
453 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
455 HTMLBodyElement *This = HTMLBODY_THIS(iface);
456 FIXME("(%p)->(%p)\n", This, p);
457 return E_NOTIMPL;
460 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
462 HTMLBodyElement *This = HTMLBODY_THIS(iface);
463 FIXME("(%p)->()\n", This);
464 return E_NOTIMPL;
467 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
469 HTMLBodyElement *This = HTMLBODY_THIS(iface);
470 FIXME("(%p)->(%p)\n", This, p);
471 return E_NOTIMPL;
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;
484 nsresult nsres;
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);
493 if(NS_FAILED(nsres))
494 ERR("SelectNodeContents failed: %08x\n", nsres);
495 }else {
496 ERR("CreateRange failed: %08x\n", nsres);
499 nsIDOMDocumentRange_Release(nsdocrange);
502 *range = HTMLTxtRange_Create(This->textcont.element.node.doc, nsrange);
503 return S_OK;
506 #undef HTMLBODY_THIS
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);
559 *ppv = NULL;
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);
575 if(*ppv) {
576 IUnknown_AddRef((IUnknown*)*ppv);
577 return S_OK;
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 = {
595 HTMLBodyElement_QI,
596 HTMLBodyElement_destructor
599 HTMLElement *HTMLBodyElement_Create(nsIDOMHTMLElement *nselem)
601 HTMLBodyElement *ret = heap_alloc_zero(sizeof(HTMLBodyElement));
602 nsresult nsres;
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);
615 if(NS_FAILED(nsres))
616 ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres);
618 return &ret->textcont.element;