mshtml: Make the Install button the default on the Gecko installation dialog.
[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     ConnectionPointContainer cp_container;
44     ConnectionPoint cp_propnotif;
45     ConnectionPoint cp_txtcontevents;
46
47     HTMLElement *element;
48     nsIDOMHTMLBodyElement *nsbody;
49 } HTMLBodyElement;
50
51 #define HTMLBODY(x)  ((IHTMLBodyElement*)  &(x)->lpHTMLBodyElementVtbl)
52
53 #define HTMLBODY_THIS(iface) DEFINE_THIS(HTMLBodyElement, HTMLBodyElement, iface)
54
55 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
56                                                      REFIID riid, void **ppv)
57 {
58     HTMLBodyElement *This = HTMLBODY_THIS(iface);
59     HRESULT hres;
60
61     *ppv = NULL;
62
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);
78     }
79
80     if(*ppv) {
81         IUnknown_AddRef((IUnknown*)*ppv);
82         return S_OK;
83     }
84
85     hres = HTMLElement_QI(This->element, riid, ppv);
86     if(FAILED(hres))
87         WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
88
89     return hres;
90 }
91
92 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
93 {
94     HTMLBodyElement *This = HTMLBODY_THIS(iface);
95
96     TRACE("(%p)\n", This);
97
98     return IHTMLDocument2_AddRef(HTMLDOC(This->element->node->doc));
99 }
100
101 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
102 {
103     HTMLBodyElement *This = HTMLBODY_THIS(iface);
104
105     TRACE("(%p)\n", This);
106
107     return IHTMLDocument2_Release(HTMLDOC(This->element->node->doc));
108 }
109
110 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
111 {
112     HTMLBodyElement *This = HTMLBODY_THIS(iface);
113     FIXME("(%p)->(%p)\n", This, pctinfo);
114     return E_NOTIMPL;
115 }
116
117 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
118                                               LCID lcid, ITypeInfo **ppTInfo)
119 {
120     HTMLBodyElement *This = HTMLBODY_THIS(iface);
121     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
122     return E_NOTIMPL;
123 }
124
125 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
126                                                 LPOLESTR *rgszNames, UINT cNames,
127                                                 LCID lcid, DISPID *rgDispId)
128 {
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;
133 }
134
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)
138 {
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;
143 }
144
145 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
146 {
147     HTMLBodyElement *This = HTMLBODY_THIS(iface);
148     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
149     return E_NOTIMPL;
150 }
151
152 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
153 {
154     HTMLBodyElement *This = HTMLBODY_THIS(iface);
155     nsAString background_str;
156     nsresult nsres;
157
158     TRACE("(%p)->(%p)\n", This, p);
159
160     nsAString_Init(&background_str, NULL);
161
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;
170     }
171
172     nsAString_Finish(&background_str);
173
174     TRACE("*p = %s\n", debugstr_w(*p));
175     return S_OK;
176 }
177
178 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
179 {
180     HTMLBodyElement *This = HTMLBODY_THIS(iface);
181     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
182     return E_NOTIMPL;
183 }
184
185 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
186 {
187     HTMLBodyElement *This = HTMLBODY_THIS(iface);
188     FIXME("(%p)->(%p)\n", This, p);
189     return E_NOTIMPL;
190 }
191
192 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
193 {
194     HTMLBodyElement *This = HTMLBODY_THIS(iface);
195     FIXME("(%p)->()\n", This);
196     return E_NOTIMPL;
197 }
198
199 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
200 {
201     HTMLBodyElement *This = HTMLBODY_THIS(iface);
202     FIXME("(%p)->(%p)\n", This, p);
203     return E_NOTIMPL;
204 }
205
206 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
207 {
208     HTMLBodyElement *This = HTMLBODY_THIS(iface);
209     FIXME("(%p)->()\n", This);
210     return E_NOTIMPL;
211 }
212
213 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
214 {
215     HTMLBodyElement *This = HTMLBODY_THIS(iface);
216     FIXME("(%p)->(%p)\n", This, p);
217     return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
221 {
222     HTMLBodyElement *This = HTMLBODY_THIS(iface);
223     FIXME("(%p)->()\n", This);
224     return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
228 {
229     HTMLBodyElement *This = HTMLBODY_THIS(iface);
230     FIXME("(%p)->(%p)\n", This, p);
231     return E_NOTIMPL;
232 }
233
234 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
235 {
236     HTMLBodyElement *This = HTMLBODY_THIS(iface);
237     FIXME("(%p)->()\n", This);
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
242 {
243     HTMLBodyElement *This = HTMLBODY_THIS(iface);
244     FIXME("(%p)->(%p)\n", This, p);
245     return E_NOTIMPL;
246 }
247
248 static HRESULT WINAPI HTMLBodyElement_put_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
249 {
250     HTMLBodyElement *This = HTMLBODY_THIS(iface);
251     FIXME("(%p)->(%x)\n", This, v);
252     return E_NOTIMPL;
253 }
254
255 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *p)
256 {
257     HTMLBodyElement *This = HTMLBODY_THIS(iface);
258     FIXME("(%p)->(%p)\n", This, p);
259     return E_NOTIMPL;
260 }
261
262 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
263 {
264     HTMLBodyElement *This = HTMLBODY_THIS(iface);
265     FIXME("(%p)->()\n", This);
266     return E_NOTIMPL;
267 }
268
269 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
270 {
271     HTMLBodyElement *This = HTMLBODY_THIS(iface);
272     FIXME("(%p)->(%p)\n", This, p);
273     return E_NOTIMPL;
274 }
275
276 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
277 {
278     HTMLBodyElement *This = HTMLBODY_THIS(iface);
279     FIXME("(%p)->()\n", This);
280     return E_NOTIMPL;
281 }
282
283 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
284 {
285     HTMLBodyElement *This = HTMLBODY_THIS(iface);
286     FIXME("(%p)->(%p)\n", This, p);
287     return E_NOTIMPL;
288 }
289
290 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
291 {
292     HTMLBodyElement *This = HTMLBODY_THIS(iface);
293     FIXME("(%p)->()\n", This);
294     return E_NOTIMPL;
295 }
296
297 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
298 {
299     HTMLBodyElement *This = HTMLBODY_THIS(iface);
300     FIXME("(%p)->(%p)\n", This, p);
301     return E_NOTIMPL;
302 }
303
304 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
305 {
306     HTMLBodyElement *This = HTMLBODY_THIS(iface);
307     FIXME("(%p)->()\n", This);
308     return E_NOTIMPL;
309 }
310
311 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
312 {
313     HTMLBodyElement *This = HTMLBODY_THIS(iface);
314     FIXME("(%p)->(%p)\n", This, p);
315     return E_NOTIMPL;
316 }
317
318 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
319 {
320     HTMLBodyElement *This = HTMLBODY_THIS(iface);
321     FIXME("(%p)->()\n", This);
322     return E_NOTIMPL;
323 }
324
325 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
326 {
327     HTMLBodyElement *This = HTMLBODY_THIS(iface);
328     FIXME("(%p)->(%p)\n", This, p);
329     return E_NOTIMPL;
330 }
331
332 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
333 {
334     HTMLBodyElement *This = HTMLBODY_THIS(iface);
335     FIXME("(%p)->()\n", This);
336     return E_NOTIMPL;
337 }
338
339 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
340 {
341     HTMLBodyElement *This = HTMLBODY_THIS(iface);
342     FIXME("(%p)->(%p)\n", This, p);
343     return E_NOTIMPL;
344 }
345
346 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
347 {
348     HTMLBodyElement *This = HTMLBODY_THIS(iface);
349     FIXME("(%p)->()\n", This);
350     return E_NOTIMPL;
351 }
352
353 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
354 {
355     HTMLBodyElement *This = HTMLBODY_THIS(iface);
356     FIXME("(%p)->(%p)\n", This, p);
357     return E_NOTIMPL;
358 }
359
360 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
361 {
362     HTMLBodyElement *This = HTMLBODY_THIS(iface);
363     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
364     return E_NOTIMPL;
365 }
366
367 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
368 {
369     HTMLBodyElement *This = HTMLBODY_THIS(iface);
370     FIXME("(%p)->(%p)\n", This, p);
371     return E_NOTIMPL;
372 }
373
374 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
375 {
376     HTMLBodyElement *This = HTMLBODY_THIS(iface);
377     FIXME("(%p)->()\n", This);
378     return E_NOTIMPL;
379 }
380
381 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
382 {
383     HTMLBodyElement *This = HTMLBODY_THIS(iface);
384     FIXME("(%p)->(%p)\n", This, p);
385     return E_NOTIMPL;
386 }
387
388 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
389 {
390     HTMLBodyElement *This = HTMLBODY_THIS(iface);
391     FIXME("(%p)->()\n", This);
392     return E_NOTIMPL;
393 }
394
395 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
396 {
397     HTMLBodyElement *This = HTMLBODY_THIS(iface);
398     FIXME("(%p)->(%p)\n", This, p);
399     return E_NOTIMPL;
400 }
401
402 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
403 {
404     HTMLBodyElement *This = HTMLBODY_THIS(iface);
405     nsIDOMRange *nsrange = NULL;
406
407     TRACE("(%p)->(%p)\n", This, range);
408
409     if(This->element->node->doc->nscontainer) {
410         nsIDOMDocument *nsdoc;
411         nsIDOMDocumentRange *nsdocrange;
412         nsresult nsres;
413
414         nsIWebNavigation_GetDocument(This->element->node->doc->nscontainer->navigation, &nsdoc);
415         nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void**)&nsdocrange);
416         nsIDOMDocument_Release(nsdoc);
417
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);
425         }
426
427         nsIDOMDocumentRange_Release(nsdocrange);
428     }
429
430     *range = HTMLTxtRange_Create(This->element->node->doc, nsrange);
431     return S_OK;
432 }
433
434 static void HTMLBodyElement_destructor(IUnknown *iface)
435 {
436     HTMLBodyElement *This = HTMLBODY_THIS(iface);
437
438     ConnectionPointContainer_Destroy(&This->cp_container);
439     nsIDOMHTMLBodyElement_Release(This->nsbody);
440     mshtml_free(This);
441 }
442
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
486 };
487
488 void HTMLBodyElement_Create(HTMLElement *element)
489 {
490     HTMLBodyElement *ret = mshtml_alloc(sizeof(HTMLBodyElement));
491     nsresult nsres;
492
493     ret->lpHTMLBodyElementVtbl = &HTMLBodyElementVtbl;
494     ret->element = element;
495
496     HTMLTextContainer_Init(&ret->text_container, element);
497
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));
503
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);
508
509     element->impl = (IUnknown*)HTMLBODY(ret);
510     element->destructor = HTMLBodyElement_destructor;
511 }