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