mshtml: Added IHTMLBodyElement::put_link implementation.
[wine/multimedia.git] / dlls / mshtml / htmlbody.c
blob8bd60e2457be0f6a4cfce076b904fbf7368d1e00
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 "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 typedef struct {
39 HTMLTextContainer textcont;
41 const IHTMLBodyElementVtbl *lpHTMLBodyElementVtbl;
43 ConnectionPoint cp_propnotif;
45 nsIDOMHTMLBodyElement *nsbody;
46 } HTMLBodyElement;
48 #define HTMLBODY(x) ((IHTMLBodyElement*) &(x)->lpHTMLBodyElementVtbl)
50 static BOOL variant_to_nscolor(const VARIANT *v, nsAString *nsstr)
52 switch(V_VT(v)) {
53 case VT_BSTR:
54 nsAString_Init(nsstr, V_BSTR(v));
55 return TRUE;
57 case VT_I4: {
58 PRUnichar buf[10];
59 static const WCHAR formatW[] = {'#','%','x',0};
61 wsprintfW(buf, formatW, V_I4(v));
62 nsAString_Init(nsstr, buf);
63 return TRUE;
66 default:
67 FIXME("invalid vt=%d\n", V_VT(v));
70 return FALSE;
74 #define HTMLBODY_THIS(iface) DEFINE_THIS(HTMLBodyElement, HTMLBodyElement, iface)
76 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
77 REFIID riid, void **ppv)
79 HTMLBodyElement *This = HTMLBODY_THIS(iface);
81 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->textcont.element.node), riid, ppv);
84 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
86 HTMLBodyElement *This = HTMLBODY_THIS(iface);
88 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->textcont.element.node));
91 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
93 HTMLBodyElement *This = HTMLBODY_THIS(iface);
95 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->textcont.element.node));
98 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
100 HTMLBodyElement *This = HTMLBODY_THIS(iface);
101 FIXME("(%p)->(%p)\n", This, pctinfo);
102 return E_NOTIMPL;
105 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
106 LCID lcid, ITypeInfo **ppTInfo)
108 HTMLBodyElement *This = HTMLBODY_THIS(iface);
109 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
110 return E_NOTIMPL;
113 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
114 LPOLESTR *rgszNames, UINT cNames,
115 LCID lcid, DISPID *rgDispId)
117 HTMLBodyElement *This = HTMLBODY_THIS(iface);
118 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
119 lcid, rgDispId);
120 return E_NOTIMPL;
123 static HRESULT WINAPI HTMLBodyElement_Invoke(IHTMLBodyElement *iface, DISPID dispIdMember,
124 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
125 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
127 HTMLBodyElement *This = HTMLBODY_THIS(iface);
128 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
129 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
130 return E_NOTIMPL;
133 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
135 HTMLBodyElement *This = HTMLBODY_THIS(iface);
136 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
137 return E_NOTIMPL;
140 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
142 HTMLBodyElement *This = HTMLBODY_THIS(iface);
143 nsAString background_str;
144 nsresult nsres;
146 TRACE("(%p)->(%p)\n", This, p);
148 nsAString_Init(&background_str, NULL);
150 nsres = nsIDOMHTMLBodyElement_GetBackground(This->nsbody, &background_str);
151 if(NS_SUCCEEDED(nsres)) {
152 const PRUnichar *background;
153 nsAString_GetData(&background_str, &background);
154 *p = *background ? SysAllocString(background) : NULL;
155 }else {
156 ERR("GetBackground failed: %08x\n", nsres);
157 *p = NULL;
160 nsAString_Finish(&background_str);
162 TRACE("*p = %s\n", debugstr_w(*p));
163 return S_OK;
166 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
168 HTMLBodyElement *This = HTMLBODY_THIS(iface);
169 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
170 return E_NOTIMPL;
173 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
175 HTMLBodyElement *This = HTMLBODY_THIS(iface);
176 FIXME("(%p)->(%p)\n", This, p);
177 return E_NOTIMPL;
180 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
182 HTMLBodyElement *This = HTMLBODY_THIS(iface);
183 FIXME("(%p)->()\n", This);
184 return E_NOTIMPL;
187 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
189 HTMLBodyElement *This = HTMLBODY_THIS(iface);
190 FIXME("(%p)->(%p)\n", This, p);
191 return E_NOTIMPL;
194 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
196 HTMLBodyElement *This = HTMLBODY_THIS(iface);
197 FIXME("(%p)->()\n", This);
198 return E_NOTIMPL;
201 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
203 HTMLBodyElement *This = HTMLBODY_THIS(iface);
204 FIXME("(%p)->(%p)\n", This, p);
205 return E_NOTIMPL;
208 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
210 HTMLBodyElement *This = HTMLBODY_THIS(iface);
211 FIXME("(%p)->()\n", This);
212 return E_NOTIMPL;
215 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
217 HTMLBodyElement *This = HTMLBODY_THIS(iface);
218 FIXME("(%p)->(%p)\n", This, p);
219 return E_NOTIMPL;
222 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
224 HTMLBodyElement *This = HTMLBODY_THIS(iface);
225 FIXME("(%p)->()\n", This);
226 return E_NOTIMPL;
229 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
231 HTMLBodyElement *This = HTMLBODY_THIS(iface);
232 FIXME("(%p)->(%p)\n", This, p);
233 return E_NOTIMPL;
236 static HRESULT WINAPI HTMLBodyElement_put_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
238 HTMLBodyElement *This = HTMLBODY_THIS(iface);
239 FIXME("(%p)->(%x)\n", This, v);
240 return E_NOTIMPL;
243 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *p)
245 HTMLBodyElement *This = HTMLBODY_THIS(iface);
246 FIXME("(%p)->(%p)\n", This, p);
247 return E_NOTIMPL;
250 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
252 HTMLBodyElement *This = HTMLBODY_THIS(iface);
253 FIXME("(%p)->()\n", This);
254 return E_NOTIMPL;
257 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
259 HTMLBodyElement *This = HTMLBODY_THIS(iface);
260 FIXME("(%p)->(%p)\n", This, p);
261 return E_NOTIMPL;
264 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
266 HTMLBodyElement *This = HTMLBODY_THIS(iface);
267 FIXME("(%p)->()\n", This);
268 return E_NOTIMPL;
271 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
273 HTMLBodyElement *This = HTMLBODY_THIS(iface);
274 FIXME("(%p)->(%p)\n", This, p);
275 return E_NOTIMPL;
278 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
280 HTMLBodyElement *This = HTMLBODY_THIS(iface);
281 nsAString link_str;
282 nsresult nsres;
284 TRACE("(%p)->(v%d)\n", This, V_VT(&v));
286 if(!variant_to_nscolor(&v, &link_str))
287 return S_OK;
289 nsres = nsIDOMHTMLBodyElement_SetLink(This->nsbody, &link_str);
290 nsAString_Finish(&link_str);
291 if(NS_FAILED(nsres))
292 ERR("SetLink failed: %08x\n", nsres);
294 return S_OK;
297 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
299 HTMLBodyElement *This = HTMLBODY_THIS(iface);
300 FIXME("(%p)->(%p)\n", This, p);
301 return E_NOTIMPL;
304 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
306 HTMLBodyElement *This = HTMLBODY_THIS(iface);
307 FIXME("(%p)->()\n", This);
308 return E_NOTIMPL;
311 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
313 HTMLBodyElement *This = HTMLBODY_THIS(iface);
314 FIXME("(%p)->(%p)\n", This, p);
315 return E_NOTIMPL;
318 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
320 HTMLBodyElement *This = HTMLBODY_THIS(iface);
321 FIXME("(%p)->()\n", This);
322 return E_NOTIMPL;
325 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
327 HTMLBodyElement *This = HTMLBODY_THIS(iface);
328 FIXME("(%p)->(%p)\n", This, p);
329 return E_NOTIMPL;
332 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
334 HTMLBodyElement *This = HTMLBODY_THIS(iface);
335 FIXME("(%p)->()\n", This);
336 return E_NOTIMPL;
339 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
341 HTMLBodyElement *This = HTMLBODY_THIS(iface);
342 FIXME("(%p)->(%p)\n", This, p);
343 return E_NOTIMPL;
346 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
348 HTMLBodyElement *This = HTMLBODY_THIS(iface);
349 FIXME("(%p)->()\n", This);
350 return E_NOTIMPL;
353 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
355 HTMLBodyElement *This = HTMLBODY_THIS(iface);
356 FIXME("(%p)->(%p)\n", This, p);
357 return E_NOTIMPL;
360 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
362 HTMLBodyElement *This = HTMLBODY_THIS(iface);
363 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
364 return E_NOTIMPL;
367 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
369 HTMLBodyElement *This = HTMLBODY_THIS(iface);
370 FIXME("(%p)->(%p)\n", This, p);
371 return E_NOTIMPL;
374 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
376 HTMLBodyElement *This = HTMLBODY_THIS(iface);
377 FIXME("(%p)->()\n", This);
378 return E_NOTIMPL;
381 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
383 HTMLBodyElement *This = HTMLBODY_THIS(iface);
384 FIXME("(%p)->(%p)\n", This, p);
385 return E_NOTIMPL;
388 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
390 HTMLBodyElement *This = HTMLBODY_THIS(iface);
391 FIXME("(%p)->()\n", This);
392 return E_NOTIMPL;
395 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
397 HTMLBodyElement *This = HTMLBODY_THIS(iface);
398 FIXME("(%p)->(%p)\n", This, p);
399 return E_NOTIMPL;
402 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
404 HTMLBodyElement *This = HTMLBODY_THIS(iface);
405 nsIDOMRange *nsrange = NULL;
407 TRACE("(%p)->(%p)\n", This, range);
409 if(This->textcont.element.node.doc->nscontainer) {
410 nsIDOMDocument *nsdoc;
411 nsIDOMDocumentRange *nsdocrange;
412 nsresult nsres;
414 nsIWebNavigation_GetDocument(This->textcont.element.node.doc->nscontainer->navigation, &nsdoc);
415 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void**)&nsdocrange);
416 nsIDOMDocument_Release(nsdoc);
418 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &nsrange);
419 if(NS_SUCCEEDED(nsres)) {
420 nsres = nsIDOMRange_SelectNodeContents(nsrange, This->textcont.element.node.nsnode);
421 if(NS_FAILED(nsres))
422 ERR("SelectNodeContents failed: %08x\n", nsres);
423 }else {
424 ERR("CreateRange failed: %08x\n", nsres);
427 nsIDOMDocumentRange_Release(nsdocrange);
430 *range = HTMLTxtRange_Create(This->textcont.element.node.doc, nsrange);
431 return S_OK;
434 #undef HTMLBODY_THIS
436 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
437 HTMLBodyElement_QueryInterface,
438 HTMLBodyElement_AddRef,
439 HTMLBodyElement_Release,
440 HTMLBodyElement_GetTypeInfoCount,
441 HTMLBodyElement_GetTypeInfo,
442 HTMLBodyElement_GetIDsOfNames,
443 HTMLBodyElement_Invoke,
444 HTMLBodyElement_put_background,
445 HTMLBodyElement_get_background,
446 HTMLBodyElement_put_bgProperties,
447 HTMLBodyElement_get_bgProperties,
448 HTMLBodyElement_put_leftMargin,
449 HTMLBodyElement_get_leftMargin,
450 HTMLBodyElement_put_topMargin,
451 HTMLBodyElement_get_topMargin,
452 HTMLBodyElement_put_rightMargin,
453 HTMLBodyElement_get_rightMargin,
454 HTMLBodyElement_put_bottomMargin,
455 HTMLBodyElement_get_bottomMargin,
456 HTMLBodyElement_put_noWrap,
457 HTMLBodyElement_get_noWrap,
458 HTMLBodyElement_put_bgColor,
459 HTMLBodyElement_get_bgColor,
460 HTMLBodyElement_put_text,
461 HTMLBodyElement_get_text,
462 HTMLBodyElement_put_link,
463 HTMLBodyElement_get_link,
464 HTMLBodyElement_put_vLink,
465 HTMLBodyElement_get_vLink,
466 HTMLBodyElement_put_aLink,
467 HTMLBodyElement_get_aLink,
468 HTMLBodyElement_put_onload,
469 HTMLBodyElement_get_onload,
470 HTMLBodyElement_put_onunload,
471 HTMLBodyElement_get_onunload,
472 HTMLBodyElement_put_scroll,
473 HTMLBodyElement_get_scroll,
474 HTMLBodyElement_put_onselect,
475 HTMLBodyElement_get_onselect,
476 HTMLBodyElement_put_onbeforeunload,
477 HTMLBodyElement_get_onbeforeunload,
478 HTMLBodyElement_createTextRange
481 #define HTMLBODY_NODE_THIS(iface) DEFINE_THIS2(HTMLBodyElement, textcont.element.node, iface)
483 static HRESULT HTMLBodyElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
485 HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface);
487 *ppv = NULL;
489 if(IsEqualGUID(&IID_IUnknown, riid)) {
490 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
491 *ppv = HTMLBODY(This);
492 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
493 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
494 *ppv = HTMLBODY(This);
495 }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
496 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
497 *ppv = HTMLBODY(This);
498 }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
499 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", &This->textcont, ppv);
500 *ppv = HTMLTEXTCONT(&This->textcont);
503 if(*ppv) {
504 IUnknown_AddRef((IUnknown*)*ppv);
505 return S_OK;
508 return HTMLElement_QI(&This->textcont.element.node, riid, ppv);
511 static void HTMLBodyElement_destructor(HTMLDOMNode *iface)
513 HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface);
515 nsIDOMHTMLBodyElement_Release(This->nsbody);
517 HTMLElement_destructor(&This->textcont.element.node);
520 #undef HTMLBODY_NODE_THIS
522 static const NodeImplVtbl HTMLBodyElementImplVtbl = {
523 HTMLBodyElement_QI,
524 HTMLBodyElement_destructor
527 HTMLElement *HTMLBodyElement_Create(nsIDOMHTMLElement *nselem)
529 HTMLBodyElement *ret = heap_alloc(sizeof(HTMLBodyElement));
530 nsresult nsres;
532 TRACE("(%p)->(%p)\n", ret, nselem);
534 HTMLTextContainer_Init(&ret->textcont);
536 ret->lpHTMLBodyElementVtbl = &HTMLBodyElementVtbl;
537 ret->textcont.element.node.vtbl = &HTMLBodyElementImplVtbl;
539 ConnectionPoint_Init(&ret->cp_propnotif, &ret->textcont.element.cp_container, &IID_IPropertyNotifySink);
541 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLBodyElement,
542 (void**)&ret->nsbody);
543 if(NS_FAILED(nsres))
544 ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres);
546 return &ret->textcont.element;