mshtml: Pass HTMLDOMNode pointer to its destructor.
[wine.git] / dlls / mshtml / htmlbody.c
blob30643478b424438a941425779ff03dee137de908
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 ConnectionPointContainer cp_container;
44 ConnectionPoint cp_propnotif;
45 ConnectionPoint cp_txtcontevents;
47 nsIDOMHTMLBodyElement *nsbody;
48 } HTMLBodyElement;
50 #define HTMLBODY(x) ((IHTMLBodyElement*) &(x)->lpHTMLBodyElementVtbl)
52 #define HTMLBODY_THIS(iface) DEFINE_THIS(HTMLBodyElement, HTMLBodyElement, iface)
54 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
55 REFIID riid, void **ppv)
57 HTMLBodyElement *This = HTMLBODY_THIS(iface);
58 HRESULT hres;
60 *ppv = NULL;
62 if(IsEqualGUID(&IID_IUnknown, riid)) {
63 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
64 *ppv = HTMLBODY(This);
65 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
66 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
67 *ppv = HTMLBODY(This);
68 }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
69 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
70 *ppv = HTMLBODY(This);
71 }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
72 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", &This->textcont, ppv);
73 *ppv = HTMLTEXTCONT(&This->textcont);
74 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
75 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
76 *ppv = CONPTCONT(&This->cp_container);
79 if(*ppv) {
80 IUnknown_AddRef((IUnknown*)*ppv);
81 return S_OK;
84 hres = HTMLElement_QI(&This->textcont.element, riid, ppv);
85 if(FAILED(hres))
86 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
88 return hres;
91 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
93 HTMLBodyElement *This = HTMLBODY_THIS(iface);
95 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->textcont.element.node));
98 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
100 HTMLBodyElement *This = HTMLBODY_THIS(iface);
102 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->textcont.element.node));
105 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
107 HTMLBodyElement *This = HTMLBODY_THIS(iface);
108 FIXME("(%p)->(%p)\n", This, pctinfo);
109 return E_NOTIMPL;
112 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
113 LCID lcid, ITypeInfo **ppTInfo)
115 HTMLBodyElement *This = HTMLBODY_THIS(iface);
116 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
117 return E_NOTIMPL;
120 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
121 LPOLESTR *rgszNames, UINT cNames,
122 LCID lcid, DISPID *rgDispId)
124 HTMLBodyElement *This = HTMLBODY_THIS(iface);
125 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
126 lcid, rgDispId);
127 return E_NOTIMPL;
130 static HRESULT WINAPI HTMLBodyElement_Invoke(IHTMLBodyElement *iface, DISPID dispIdMember,
131 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
132 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
134 HTMLBodyElement *This = HTMLBODY_THIS(iface);
135 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
136 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
137 return E_NOTIMPL;
140 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
142 HTMLBodyElement *This = HTMLBODY_THIS(iface);
143 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
144 return E_NOTIMPL;
147 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
149 HTMLBodyElement *This = HTMLBODY_THIS(iface);
150 nsAString background_str;
151 nsresult nsres;
153 TRACE("(%p)->(%p)\n", This, p);
155 nsAString_Init(&background_str, NULL);
157 nsres = nsIDOMHTMLBodyElement_GetBackground(This->nsbody, &background_str);
158 if(NS_SUCCEEDED(nsres)) {
159 const PRUnichar *background;
160 nsAString_GetData(&background_str, &background, NULL);
161 *p = SysAllocString(background);
162 }else {
163 ERR("GetBackground failed: %08x\n", nsres);
164 *p = NULL;
167 nsAString_Finish(&background_str);
169 TRACE("*p = %s\n", debugstr_w(*p));
170 return S_OK;
173 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
175 HTMLBodyElement *This = HTMLBODY_THIS(iface);
176 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
177 return E_NOTIMPL;
180 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
182 HTMLBodyElement *This = HTMLBODY_THIS(iface);
183 FIXME("(%p)->(%p)\n", This, p);
184 return E_NOTIMPL;
187 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
189 HTMLBodyElement *This = HTMLBODY_THIS(iface);
190 FIXME("(%p)->()\n", This);
191 return E_NOTIMPL;
194 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
196 HTMLBodyElement *This = HTMLBODY_THIS(iface);
197 FIXME("(%p)->(%p)\n", This, p);
198 return E_NOTIMPL;
201 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
203 HTMLBodyElement *This = HTMLBODY_THIS(iface);
204 FIXME("(%p)->()\n", This);
205 return E_NOTIMPL;
208 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
210 HTMLBodyElement *This = HTMLBODY_THIS(iface);
211 FIXME("(%p)->(%p)\n", This, p);
212 return E_NOTIMPL;
215 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
217 HTMLBodyElement *This = HTMLBODY_THIS(iface);
218 FIXME("(%p)->()\n", This);
219 return E_NOTIMPL;
222 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
224 HTMLBodyElement *This = HTMLBODY_THIS(iface);
225 FIXME("(%p)->(%p)\n", This, p);
226 return E_NOTIMPL;
229 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
231 HTMLBodyElement *This = HTMLBODY_THIS(iface);
232 FIXME("(%p)->()\n", This);
233 return E_NOTIMPL;
236 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
238 HTMLBodyElement *This = HTMLBODY_THIS(iface);
239 FIXME("(%p)->(%p)\n", This, p);
240 return E_NOTIMPL;
243 static HRESULT WINAPI HTMLBodyElement_put_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
245 HTMLBodyElement *This = HTMLBODY_THIS(iface);
246 FIXME("(%p)->(%x)\n", This, v);
247 return E_NOTIMPL;
250 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *p)
252 HTMLBodyElement *This = HTMLBODY_THIS(iface);
253 FIXME("(%p)->(%p)\n", This, p);
254 return E_NOTIMPL;
257 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
259 HTMLBodyElement *This = HTMLBODY_THIS(iface);
260 FIXME("(%p)->()\n", This);
261 return E_NOTIMPL;
264 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
266 HTMLBodyElement *This = HTMLBODY_THIS(iface);
267 FIXME("(%p)->(%p)\n", This, p);
268 return E_NOTIMPL;
271 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
273 HTMLBodyElement *This = HTMLBODY_THIS(iface);
274 FIXME("(%p)->()\n", This);
275 return E_NOTIMPL;
278 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
280 HTMLBodyElement *This = HTMLBODY_THIS(iface);
281 FIXME("(%p)->(%p)\n", This, p);
282 return E_NOTIMPL;
285 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
287 HTMLBodyElement *This = HTMLBODY_THIS(iface);
288 FIXME("(%p)->()\n", This);
289 return E_NOTIMPL;
292 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
294 HTMLBodyElement *This = HTMLBODY_THIS(iface);
295 FIXME("(%p)->(%p)\n", This, p);
296 return E_NOTIMPL;
299 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
301 HTMLBodyElement *This = HTMLBODY_THIS(iface);
302 FIXME("(%p)->()\n", This);
303 return E_NOTIMPL;
306 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
308 HTMLBodyElement *This = HTMLBODY_THIS(iface);
309 FIXME("(%p)->(%p)\n", This, p);
310 return E_NOTIMPL;
313 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
315 HTMLBodyElement *This = HTMLBODY_THIS(iface);
316 FIXME("(%p)->()\n", This);
317 return E_NOTIMPL;
320 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
322 HTMLBodyElement *This = HTMLBODY_THIS(iface);
323 FIXME("(%p)->(%p)\n", This, p);
324 return E_NOTIMPL;
327 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
329 HTMLBodyElement *This = HTMLBODY_THIS(iface);
330 FIXME("(%p)->()\n", This);
331 return E_NOTIMPL;
334 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
336 HTMLBodyElement *This = HTMLBODY_THIS(iface);
337 FIXME("(%p)->(%p)\n", This, p);
338 return E_NOTIMPL;
341 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
343 HTMLBodyElement *This = HTMLBODY_THIS(iface);
344 FIXME("(%p)->()\n", This);
345 return E_NOTIMPL;
348 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
350 HTMLBodyElement *This = HTMLBODY_THIS(iface);
351 FIXME("(%p)->(%p)\n", This, p);
352 return E_NOTIMPL;
355 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
357 HTMLBodyElement *This = HTMLBODY_THIS(iface);
358 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
359 return E_NOTIMPL;
362 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
364 HTMLBodyElement *This = HTMLBODY_THIS(iface);
365 FIXME("(%p)->(%p)\n", This, p);
366 return E_NOTIMPL;
369 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
371 HTMLBodyElement *This = HTMLBODY_THIS(iface);
372 FIXME("(%p)->()\n", This);
373 return E_NOTIMPL;
376 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
378 HTMLBodyElement *This = HTMLBODY_THIS(iface);
379 FIXME("(%p)->(%p)\n", This, p);
380 return E_NOTIMPL;
383 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
385 HTMLBodyElement *This = HTMLBODY_THIS(iface);
386 FIXME("(%p)->()\n", This);
387 return E_NOTIMPL;
390 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
392 HTMLBodyElement *This = HTMLBODY_THIS(iface);
393 FIXME("(%p)->(%p)\n", This, p);
394 return E_NOTIMPL;
397 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
399 HTMLBodyElement *This = HTMLBODY_THIS(iface);
400 nsIDOMRange *nsrange = NULL;
402 TRACE("(%p)->(%p)\n", This, range);
404 if(This->textcont.element.node.doc->nscontainer) {
405 nsIDOMDocument *nsdoc;
406 nsIDOMDocumentRange *nsdocrange;
407 nsresult nsres;
409 nsIWebNavigation_GetDocument(This->textcont.element.node.doc->nscontainer->navigation, &nsdoc);
410 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void**)&nsdocrange);
411 nsIDOMDocument_Release(nsdoc);
413 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &nsrange);
414 if(NS_SUCCEEDED(nsres)) {
415 nsres = nsIDOMRange_SelectNodeContents(nsrange, This->textcont.element.node.nsnode);
416 if(NS_FAILED(nsres))
417 ERR("SelectNodeContents failed: %08x\n", nsres);
418 }else {
419 ERR("CreateRange failed: %08x\n", nsres);
422 nsIDOMDocumentRange_Release(nsdocrange);
425 *range = HTMLTxtRange_Create(This->textcont.element.node.doc, nsrange);
426 return S_OK;
429 static void HTMLBodyElement_destructor(IUnknown *iface)
431 HTMLBodyElement *This = HTMLBODY_THIS(iface);
433 ConnectionPointContainer_Destroy(&This->cp_container);
434 nsIDOMHTMLBodyElement_Release(This->nsbody);
435 mshtml_free(This);
438 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
439 HTMLBodyElement_QueryInterface,
440 HTMLBodyElement_AddRef,
441 HTMLBodyElement_Release,
442 HTMLBodyElement_GetTypeInfoCount,
443 HTMLBodyElement_GetTypeInfo,
444 HTMLBodyElement_GetIDsOfNames,
445 HTMLBodyElement_Invoke,
446 HTMLBodyElement_put_background,
447 HTMLBodyElement_get_background,
448 HTMLBodyElement_put_bgProperties,
449 HTMLBodyElement_get_bgProperties,
450 HTMLBodyElement_put_leftMargin,
451 HTMLBodyElement_get_leftMargin,
452 HTMLBodyElement_put_topMargin,
453 HTMLBodyElement_get_topMargin,
454 HTMLBodyElement_put_rightMargin,
455 HTMLBodyElement_get_rightMargin,
456 HTMLBodyElement_put_bottomMargin,
457 HTMLBodyElement_get_bottomMargin,
458 HTMLBodyElement_put_noWrap,
459 HTMLBodyElement_get_noWrap,
460 HTMLBodyElement_put_bgColor,
461 HTMLBodyElement_get_bgColor,
462 HTMLBodyElement_put_text,
463 HTMLBodyElement_get_text,
464 HTMLBodyElement_put_link,
465 HTMLBodyElement_get_link,
466 HTMLBodyElement_put_vLink,
467 HTMLBodyElement_get_vLink,
468 HTMLBodyElement_put_aLink,
469 HTMLBodyElement_get_aLink,
470 HTMLBodyElement_put_onload,
471 HTMLBodyElement_get_onload,
472 HTMLBodyElement_put_onunload,
473 HTMLBodyElement_get_onunload,
474 HTMLBodyElement_put_scroll,
475 HTMLBodyElement_get_scroll,
476 HTMLBodyElement_put_onselect,
477 HTMLBodyElement_get_onselect,
478 HTMLBodyElement_put_onbeforeunload,
479 HTMLBodyElement_get_onbeforeunload,
480 HTMLBodyElement_createTextRange
483 HTMLElement *HTMLBodyElement_Create(nsIDOMHTMLElement *nselem)
485 HTMLBodyElement *ret = mshtml_alloc(sizeof(HTMLBodyElement));
486 nsresult nsres;
488 TRACE("(%p)->(%p)\n", ret, nselem);
490 ret->lpHTMLBodyElementVtbl = &HTMLBodyElementVtbl;
492 HTMLTextContainer_Init(&ret->textcont);
494 ConnectionPoint_Init(&ret->cp_propnotif, CONPTCONT(&ret->cp_container),
495 &IID_IPropertyNotifySink, NULL);
496 ConnectionPoint_Init(&ret->cp_txtcontevents, CONPTCONT(&ret->cp_container),
497 &DIID_HTMLTextContainerEvents, &ret->cp_propnotif);
498 ConnectionPointContainer_Init(&ret->cp_container, &ret->cp_propnotif, (IUnknown*)HTMLBODY(ret));
500 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLBodyElement,
501 (void**)&ret->nsbody);
502 if(NS_FAILED(nsres))
503 ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres);
505 ret->textcont.element.impl = (IUnknown*)HTMLBODY(ret);
506 ret->textcont.element.destructor = HTMLBodyElement_destructor;
508 return &ret->textcont.element;