mshtml: Move nodes' QueryInterface implementation to vtbl.
[wine] / dlls / mshtml / htmlbody.c
1 /*
2  * Copyright 2006 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
31
32 #include "wine/debug.h"
33
34 #include "mshtml_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
38 typedef struct {
39     HTMLTextContainer textcont;
40
41     const IHTMLBodyElementVtbl *lpHTMLBodyElementVtbl;
42
43     ConnectionPointContainer cp_container;
44     ConnectionPoint cp_propnotif;
45     ConnectionPoint cp_txtcontevents;
46
47     nsIDOMHTMLBodyElement *nsbody;
48 } HTMLBodyElement;
49
50 #define HTMLBODY(x)  ((IHTMLBodyElement*)  &(x)->lpHTMLBodyElementVtbl)
51
52 #define HTMLBODY_THIS(iface) DEFINE_THIS(HTMLBodyElement, HTMLBodyElement, iface)
53
54 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
55                                                      REFIID riid, void **ppv)
56 {
57     HTMLBodyElement *This = HTMLBODY_THIS(iface);
58
59     return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->textcont.element.node), riid, ppv);
60 }
61
62 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
63 {
64     HTMLBodyElement *This = HTMLBODY_THIS(iface);
65
66     return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->textcont.element.node));
67 }
68
69 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
70 {
71     HTMLBodyElement *This = HTMLBODY_THIS(iface);
72
73     return IHTMLDOMNode_Release(HTMLDOMNODE(&This->textcont.element.node));
74 }
75
76 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
77 {
78     HTMLBodyElement *This = HTMLBODY_THIS(iface);
79     FIXME("(%p)->(%p)\n", This, pctinfo);
80     return E_NOTIMPL;
81 }
82
83 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
84                                               LCID lcid, ITypeInfo **ppTInfo)
85 {
86     HTMLBodyElement *This = HTMLBODY_THIS(iface);
87     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
88     return E_NOTIMPL;
89 }
90
91 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
92                                                 LPOLESTR *rgszNames, UINT cNames,
93                                                 LCID lcid, DISPID *rgDispId)
94 {
95     HTMLBodyElement *This = HTMLBODY_THIS(iface);
96     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
97                                         lcid, rgDispId);
98     return E_NOTIMPL;
99 }
100
101 static HRESULT WINAPI HTMLBodyElement_Invoke(IHTMLBodyElement *iface, DISPID dispIdMember,
102                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
103                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
104 {
105     HTMLBodyElement *This = HTMLBODY_THIS(iface);
106     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
107             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
108     return E_NOTIMPL;
109 }
110
111 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
112 {
113     HTMLBodyElement *This = HTMLBODY_THIS(iface);
114     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
115     return E_NOTIMPL;
116 }
117
118 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
119 {
120     HTMLBodyElement *This = HTMLBODY_THIS(iface);
121     nsAString background_str;
122     nsresult nsres;
123
124     TRACE("(%p)->(%p)\n", This, p);
125
126     nsAString_Init(&background_str, NULL);
127
128     nsres = nsIDOMHTMLBodyElement_GetBackground(This->nsbody, &background_str);
129     if(NS_SUCCEEDED(nsres)) {
130         const PRUnichar *background;
131         nsAString_GetData(&background_str, &background, NULL);
132         *p = SysAllocString(background);
133     }else {
134         ERR("GetBackground failed: %08x\n", nsres);
135         *p = NULL;
136     }
137
138     nsAString_Finish(&background_str);
139
140     TRACE("*p = %s\n", debugstr_w(*p));
141     return S_OK;
142 }
143
144 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
145 {
146     HTMLBodyElement *This = HTMLBODY_THIS(iface);
147     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
148     return E_NOTIMPL;
149 }
150
151 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
152 {
153     HTMLBodyElement *This = HTMLBODY_THIS(iface);
154     FIXME("(%p)->(%p)\n", This, p);
155     return E_NOTIMPL;
156 }
157
158 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
159 {
160     HTMLBodyElement *This = HTMLBODY_THIS(iface);
161     FIXME("(%p)->()\n", This);
162     return E_NOTIMPL;
163 }
164
165 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
166 {
167     HTMLBodyElement *This = HTMLBODY_THIS(iface);
168     FIXME("(%p)->(%p)\n", This, p);
169     return E_NOTIMPL;
170 }
171
172 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
173 {
174     HTMLBodyElement *This = HTMLBODY_THIS(iface);
175     FIXME("(%p)->()\n", This);
176     return E_NOTIMPL;
177 }
178
179 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
180 {
181     HTMLBodyElement *This = HTMLBODY_THIS(iface);
182     FIXME("(%p)->(%p)\n", This, p);
183     return E_NOTIMPL;
184 }
185
186 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
187 {
188     HTMLBodyElement *This = HTMLBODY_THIS(iface);
189     FIXME("(%p)->()\n", This);
190     return E_NOTIMPL;
191 }
192
193 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
194 {
195     HTMLBodyElement *This = HTMLBODY_THIS(iface);
196     FIXME("(%p)->(%p)\n", This, p);
197     return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
201 {
202     HTMLBodyElement *This = HTMLBODY_THIS(iface);
203     FIXME("(%p)->()\n", This);
204     return E_NOTIMPL;
205 }
206
207 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
208 {
209     HTMLBodyElement *This = HTMLBODY_THIS(iface);
210     FIXME("(%p)->(%p)\n", This, p);
211     return E_NOTIMPL;
212 }
213
214 static HRESULT WINAPI HTMLBodyElement_put_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
215 {
216     HTMLBodyElement *This = HTMLBODY_THIS(iface);
217     FIXME("(%p)->(%x)\n", This, v);
218     return E_NOTIMPL;
219 }
220
221 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *p)
222 {
223     HTMLBodyElement *This = HTMLBODY_THIS(iface);
224     FIXME("(%p)->(%p)\n", This, p);
225     return E_NOTIMPL;
226 }
227
228 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
229 {
230     HTMLBodyElement *This = HTMLBODY_THIS(iface);
231     FIXME("(%p)->()\n", This);
232     return E_NOTIMPL;
233 }
234
235 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
236 {
237     HTMLBodyElement *This = HTMLBODY_THIS(iface);
238     FIXME("(%p)->(%p)\n", This, p);
239     return E_NOTIMPL;
240 }
241
242 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
243 {
244     HTMLBodyElement *This = HTMLBODY_THIS(iface);
245     FIXME("(%p)->()\n", This);
246     return E_NOTIMPL;
247 }
248
249 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
250 {
251     HTMLBodyElement *This = HTMLBODY_THIS(iface);
252     FIXME("(%p)->(%p)\n", This, p);
253     return E_NOTIMPL;
254 }
255
256 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
257 {
258     HTMLBodyElement *This = HTMLBODY_THIS(iface);
259     FIXME("(%p)->()\n", This);
260     return E_NOTIMPL;
261 }
262
263 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
264 {
265     HTMLBodyElement *This = HTMLBODY_THIS(iface);
266     FIXME("(%p)->(%p)\n", This, p);
267     return E_NOTIMPL;
268 }
269
270 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
271 {
272     HTMLBodyElement *This = HTMLBODY_THIS(iface);
273     FIXME("(%p)->()\n", This);
274     return E_NOTIMPL;
275 }
276
277 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
278 {
279     HTMLBodyElement *This = HTMLBODY_THIS(iface);
280     FIXME("(%p)->(%p)\n", This, p);
281     return E_NOTIMPL;
282 }
283
284 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
285 {
286     HTMLBodyElement *This = HTMLBODY_THIS(iface);
287     FIXME("(%p)->()\n", This);
288     return E_NOTIMPL;
289 }
290
291 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
292 {
293     HTMLBodyElement *This = HTMLBODY_THIS(iface);
294     FIXME("(%p)->(%p)\n", This, p);
295     return E_NOTIMPL;
296 }
297
298 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
299 {
300     HTMLBodyElement *This = HTMLBODY_THIS(iface);
301     FIXME("(%p)->()\n", This);
302     return E_NOTIMPL;
303 }
304
305 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
306 {
307     HTMLBodyElement *This = HTMLBODY_THIS(iface);
308     FIXME("(%p)->(%p)\n", This, p);
309     return E_NOTIMPL;
310 }
311
312 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
313 {
314     HTMLBodyElement *This = HTMLBODY_THIS(iface);
315     FIXME("(%p)->()\n", This);
316     return E_NOTIMPL;
317 }
318
319 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
320 {
321     HTMLBodyElement *This = HTMLBODY_THIS(iface);
322     FIXME("(%p)->(%p)\n", This, p);
323     return E_NOTIMPL;
324 }
325
326 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
327 {
328     HTMLBodyElement *This = HTMLBODY_THIS(iface);
329     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
330     return E_NOTIMPL;
331 }
332
333 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
334 {
335     HTMLBodyElement *This = HTMLBODY_THIS(iface);
336     FIXME("(%p)->(%p)\n", This, p);
337     return E_NOTIMPL;
338 }
339
340 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
341 {
342     HTMLBodyElement *This = HTMLBODY_THIS(iface);
343     FIXME("(%p)->()\n", This);
344     return E_NOTIMPL;
345 }
346
347 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
348 {
349     HTMLBodyElement *This = HTMLBODY_THIS(iface);
350     FIXME("(%p)->(%p)\n", This, p);
351     return E_NOTIMPL;
352 }
353
354 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
355 {
356     HTMLBodyElement *This = HTMLBODY_THIS(iface);
357     FIXME("(%p)->()\n", This);
358     return E_NOTIMPL;
359 }
360
361 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
362 {
363     HTMLBodyElement *This = HTMLBODY_THIS(iface);
364     FIXME("(%p)->(%p)\n", This, p);
365     return E_NOTIMPL;
366 }
367
368 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
369 {
370     HTMLBodyElement *This = HTMLBODY_THIS(iface);
371     nsIDOMRange *nsrange = NULL;
372
373     TRACE("(%p)->(%p)\n", This, range);
374
375     if(This->textcont.element.node.doc->nscontainer) {
376         nsIDOMDocument *nsdoc;
377         nsIDOMDocumentRange *nsdocrange;
378         nsresult nsres;
379
380         nsIWebNavigation_GetDocument(This->textcont.element.node.doc->nscontainer->navigation, &nsdoc);
381         nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void**)&nsdocrange);
382         nsIDOMDocument_Release(nsdoc);
383
384         nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &nsrange);
385         if(NS_SUCCEEDED(nsres)) {
386             nsres = nsIDOMRange_SelectNodeContents(nsrange, This->textcont.element.node.nsnode);
387             if(NS_FAILED(nsres))
388                 ERR("SelectNodeContents failed: %08x\n", nsres);
389         }else {
390             ERR("CreateRange failed: %08x\n", nsres);
391         }
392
393         nsIDOMDocumentRange_Release(nsdocrange);
394     }
395
396     *range = HTMLTxtRange_Create(This->textcont.element.node.doc, nsrange);
397     return S_OK;
398 }
399
400 #undef HTMLBODY_THIS
401
402 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
403     HTMLBodyElement_QueryInterface,
404     HTMLBodyElement_AddRef,
405     HTMLBodyElement_Release,
406     HTMLBodyElement_GetTypeInfoCount,
407     HTMLBodyElement_GetTypeInfo,
408     HTMLBodyElement_GetIDsOfNames,
409     HTMLBodyElement_Invoke,
410     HTMLBodyElement_put_background,
411     HTMLBodyElement_get_background,
412     HTMLBodyElement_put_bgProperties,
413     HTMLBodyElement_get_bgProperties,
414     HTMLBodyElement_put_leftMargin,
415     HTMLBodyElement_get_leftMargin,
416     HTMLBodyElement_put_topMargin,
417     HTMLBodyElement_get_topMargin,
418     HTMLBodyElement_put_rightMargin,
419     HTMLBodyElement_get_rightMargin,
420     HTMLBodyElement_put_bottomMargin,
421     HTMLBodyElement_get_bottomMargin,
422     HTMLBodyElement_put_noWrap,
423     HTMLBodyElement_get_noWrap,
424     HTMLBodyElement_put_bgColor,
425     HTMLBodyElement_get_bgColor,
426     HTMLBodyElement_put_text,
427     HTMLBodyElement_get_text,
428     HTMLBodyElement_put_link,
429     HTMLBodyElement_get_link,
430     HTMLBodyElement_put_vLink,
431     HTMLBodyElement_get_vLink,
432     HTMLBodyElement_put_aLink,
433     HTMLBodyElement_get_aLink,
434     HTMLBodyElement_put_onload,
435     HTMLBodyElement_get_onload,
436     HTMLBodyElement_put_onunload,
437     HTMLBodyElement_get_onunload,
438     HTMLBodyElement_put_scroll,
439     HTMLBodyElement_get_scroll,
440     HTMLBodyElement_put_onselect,
441     HTMLBodyElement_get_onselect,
442     HTMLBodyElement_put_onbeforeunload,
443     HTMLBodyElement_get_onbeforeunload,
444     HTMLBodyElement_createTextRange
445 };
446
447 #define HTMLBODY_NODE_THIS(iface) DEFINE_THIS2(HTMLBodyElement, textcont.element.node, iface)
448
449 static HRESULT HTMLBodyElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
450 {
451     HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface);
452
453     *ppv = NULL;
454
455     if(IsEqualGUID(&IID_IUnknown, riid)) {
456         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
457         *ppv = HTMLBODY(This);
458     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
459         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
460         *ppv = HTMLBODY(This);
461     }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
462         TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
463         *ppv = HTMLBODY(This);
464     }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
465         TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", &This->textcont, ppv);
466         *ppv = HTMLTEXTCONT(&This->textcont);
467     }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
468         TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
469         *ppv = CONPTCONT(&This->cp_container);
470     }
471
472     if(*ppv) {
473         IUnknown_AddRef((IUnknown*)*ppv);
474         return S_OK;
475     }
476
477     return HTMLElement_QI(&This->textcont.element.node, riid, ppv);
478 }
479
480 static void HTMLBodyElement_destructor(HTMLDOMNode *iface)
481 {
482     HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface);
483
484     ConnectionPointContainer_Destroy(&This->cp_container);
485     nsIDOMHTMLBodyElement_Release(This->nsbody);
486
487     HTMLElement_destructor(&This->textcont.element.node);
488 }
489
490 #undef HTMLBODY_NODE_THIS
491
492 static const NodeImplVtbl HTMLBodyElementImplVtbl = {
493     HTMLBodyElement_QI,
494     HTMLBodyElement_destructor
495 };
496
497 HTMLElement *HTMLBodyElement_Create(nsIDOMHTMLElement *nselem)
498 {
499     HTMLBodyElement *ret = mshtml_alloc(sizeof(HTMLBodyElement));
500     nsresult nsres;
501
502     TRACE("(%p)->(%p)\n", ret, nselem);
503
504     ret->lpHTMLBodyElementVtbl = &HTMLBodyElementVtbl;
505     ret->textcont.element.node.vtbl = &HTMLBodyElementImplVtbl;
506
507     HTMLTextContainer_Init(&ret->textcont);
508
509     ConnectionPoint_Init(&ret->cp_propnotif, CONPTCONT(&ret->cp_container),
510             &IID_IPropertyNotifySink, NULL);
511     ConnectionPoint_Init(&ret->cp_txtcontevents, CONPTCONT(&ret->cp_container),
512             &DIID_HTMLTextContainerEvents, &ret->cp_propnotif);
513     ConnectionPointContainer_Init(&ret->cp_container, &ret->cp_propnotif, (IUnknown*)HTMLBODY(ret));
514
515     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLBodyElement,
516                                              (void**)&ret->nsbody);
517     if(NS_FAILED(nsres))
518         ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres);
519
520     return &ret->textcont.element;
521 }