mshtml: Store HTMLDOMNode struct instead of pointer in HTMLElement object.
[wine/multimedia.git] / dlls / mshtml / htmlbody.c
blob966b693fb2327eb8fe6e971f4d73f614291df0a3
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 const IHTMLBodyElementVtbl *lpHTMLBodyElementVtbl;
41 HTMLTextContainer text_container;
43 ConnectionPointContainer cp_container;
44 ConnectionPoint cp_propnotif;
45 ConnectionPoint cp_txtcontevents;
47 HTMLElement *element;
48 nsIDOMHTMLBodyElement *nsbody;
49 } HTMLBodyElement;
51 #define HTMLBODY(x) ((IHTMLBodyElement*) &(x)->lpHTMLBodyElementVtbl)
53 #define HTMLBODY_THIS(iface) DEFINE_THIS(HTMLBodyElement, HTMLBodyElement, iface)
55 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
56 REFIID riid, void **ppv)
58 HTMLBodyElement *This = HTMLBODY_THIS(iface);
59 HRESULT hres;
61 *ppv = NULL;
63 if(IsEqualGUID(&IID_IUnknown, riid)) {
64 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
65 *ppv = HTMLBODY(This);
66 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
67 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
68 *ppv = HTMLBODY(This);
69 }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
70 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
71 *ppv = HTMLBODY(This);
72 }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
73 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", This, ppv);
74 *ppv = HTMLTEXTCONT(&This->text_container);
75 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
76 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
77 *ppv = CONPTCONT(&This->cp_container);
80 if(*ppv) {
81 IUnknown_AddRef((IUnknown*)*ppv);
82 return S_OK;
85 hres = HTMLElement_QI(This->element, riid, ppv);
86 if(FAILED(hres))
87 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
89 return hres;
92 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
94 HTMLBodyElement *This = HTMLBODY_THIS(iface);
96 TRACE("(%p)\n", This);
98 return IHTMLDocument2_AddRef(HTMLDOC(This->element->node.doc));
101 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
103 HTMLBodyElement *This = HTMLBODY_THIS(iface);
105 TRACE("(%p)\n", This);
107 return IHTMLDocument2_Release(HTMLDOC(This->element->node.doc));
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, NULL);
166 *p = SysAllocString(background);
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 FIXME("(%p)->()\n", This);
294 return E_NOTIMPL;
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->element->node.doc->nscontainer) {
410 nsIDOMDocument *nsdoc;
411 nsIDOMDocumentRange *nsdocrange;
412 nsresult nsres;
414 nsIWebNavigation_GetDocument(This->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->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->element->node.doc, nsrange);
431 return S_OK;
434 static void HTMLBodyElement_destructor(IUnknown *iface)
436 HTMLBodyElement *This = HTMLBODY_THIS(iface);
438 ConnectionPointContainer_Destroy(&This->cp_container);
439 nsIDOMHTMLBodyElement_Release(This->nsbody);
440 mshtml_free(This);
443 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
444 HTMLBodyElement_QueryInterface,
445 HTMLBodyElement_AddRef,
446 HTMLBodyElement_Release,
447 HTMLBodyElement_GetTypeInfoCount,
448 HTMLBodyElement_GetTypeInfo,
449 HTMLBodyElement_GetIDsOfNames,
450 HTMLBodyElement_Invoke,
451 HTMLBodyElement_put_background,
452 HTMLBodyElement_get_background,
453 HTMLBodyElement_put_bgProperties,
454 HTMLBodyElement_get_bgProperties,
455 HTMLBodyElement_put_leftMargin,
456 HTMLBodyElement_get_leftMargin,
457 HTMLBodyElement_put_topMargin,
458 HTMLBodyElement_get_topMargin,
459 HTMLBodyElement_put_rightMargin,
460 HTMLBodyElement_get_rightMargin,
461 HTMLBodyElement_put_bottomMargin,
462 HTMLBodyElement_get_bottomMargin,
463 HTMLBodyElement_put_noWrap,
464 HTMLBodyElement_get_noWrap,
465 HTMLBodyElement_put_bgColor,
466 HTMLBodyElement_get_bgColor,
467 HTMLBodyElement_put_text,
468 HTMLBodyElement_get_text,
469 HTMLBodyElement_put_link,
470 HTMLBodyElement_get_link,
471 HTMLBodyElement_put_vLink,
472 HTMLBodyElement_get_vLink,
473 HTMLBodyElement_put_aLink,
474 HTMLBodyElement_get_aLink,
475 HTMLBodyElement_put_onload,
476 HTMLBodyElement_get_onload,
477 HTMLBodyElement_put_onunload,
478 HTMLBodyElement_get_onunload,
479 HTMLBodyElement_put_scroll,
480 HTMLBodyElement_get_scroll,
481 HTMLBodyElement_put_onselect,
482 HTMLBodyElement_get_onselect,
483 HTMLBodyElement_put_onbeforeunload,
484 HTMLBodyElement_get_onbeforeunload,
485 HTMLBodyElement_createTextRange
488 void HTMLBodyElement_Create(HTMLElement *element)
490 HTMLBodyElement *ret = mshtml_alloc(sizeof(HTMLBodyElement));
491 nsresult nsres;
493 ret->lpHTMLBodyElementVtbl = &HTMLBodyElementVtbl;
494 ret->element = element;
496 HTMLTextContainer_Init(&ret->text_container, element);
498 ConnectionPoint_Init(&ret->cp_propnotif, CONPTCONT(&ret->cp_container),
499 &IID_IPropertyNotifySink, NULL);
500 ConnectionPoint_Init(&ret->cp_txtcontevents, CONPTCONT(&ret->cp_container),
501 &DIID_HTMLTextContainerEvents, &ret->cp_propnotif);
502 ConnectionPointContainer_Init(&ret->cp_container, &ret->cp_propnotif, (IUnknown*)HTMLBODY(ret));
504 nsres = nsIDOMHTMLElement_QueryInterface(element->nselem, &IID_nsIDOMHTMLBodyElement,
505 (void**)&ret->nsbody);
506 if(NS_FAILED(nsres))
507 ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres);
509 element->impl = (IUnknown*)HTMLBODY(ret);
510 element->destructor = HTMLBodyElement_destructor;