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