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