mshtml: IHTMLDocument2 iface handling clean up.
[wine] / dlls / mshtml / htmldoc5.c
1 /*
2  * Copyright 2007 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 "ole2.h"
30
31 #include "wine/debug.h"
32
33 #include "mshtml_private.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36
37 #define HTMLDOC5_THIS(iface) DEFINE_THIS(HTMLDocument, HTMLDocument5, iface)
38
39 static HRESULT WINAPI HTMLDocument5_QueryInterface(IHTMLDocument5 *iface,
40         REFIID riid, void **ppv)
41 {
42     HTMLDocument *This = HTMLDOC5_THIS(iface);
43     return htmldoc_query_interface(This, riid, ppv);
44 }
45
46 static ULONG WINAPI HTMLDocument5_AddRef(IHTMLDocument5 *iface)
47 {
48     HTMLDocument *This = HTMLDOC5_THIS(iface);
49     return htmldoc_addref(This);
50 }
51
52 static ULONG WINAPI HTMLDocument5_Release(IHTMLDocument5 *iface)
53 {
54     HTMLDocument *This = HTMLDOC5_THIS(iface);
55     return htmldoc_release(This);
56 }
57
58 static HRESULT WINAPI HTMLDocument5_GetTypeInfoCount(IHTMLDocument5 *iface, UINT *pctinfo)
59 {
60     HTMLDocument *This = HTMLDOC5_THIS(iface);
61     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
62 }
63
64 static HRESULT WINAPI HTMLDocument5_GetTypeInfo(IHTMLDocument5 *iface, UINT iTInfo,
65         LCID lcid, ITypeInfo **ppTInfo)
66 {
67     HTMLDocument *This = HTMLDOC5_THIS(iface);
68     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
69 }
70
71 static HRESULT WINAPI HTMLDocument5_GetIDsOfNames(IHTMLDocument5 *iface, REFIID riid,
72         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
73 {
74     HTMLDocument *This = HTMLDOC5_THIS(iface);
75     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
76 }
77
78 static HRESULT WINAPI HTMLDocument5_Invoke(IHTMLDocument5 *iface, DISPID dispIdMember,
79                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
80                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
81 {
82     HTMLDocument *This = HTMLDOC5_THIS(iface);
83     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
84             pVarResult, pExcepInfo, puArgErr);
85 }
86
87 static HRESULT WINAPI HTMLDocument5_put_onmousewheel(IHTMLDocument5 *iface, VARIANT v)
88 {
89     HTMLDocument *This = HTMLDOC5_THIS(iface);
90     FIXME("(%p)->(v)\n", This);
91     return E_NOTIMPL;
92 }
93
94 static HRESULT WINAPI HTMLDocument5_get_onmousewheel(IHTMLDocument5 *iface, VARIANT *p)
95 {
96     HTMLDocument *This = HTMLDOC5_THIS(iface);
97     FIXME("(%p)->(%p)\n", This, p);
98     return E_NOTIMPL;
99 }
100
101 static HRESULT WINAPI HTMLDocument5_get_doctype(IHTMLDocument5 *iface, IHTMLDOMNode **p)
102 {
103     HTMLDocument *This = HTMLDOC5_THIS(iface);
104     FIXME("(%p)->(%p)\n", This, p);
105     return E_NOTIMPL;
106 }
107
108 static HRESULT WINAPI HTMLDocument5_get_implementation(IHTMLDocument5 *iface, IHTMLDOMImplementation **p)
109 {
110     HTMLDocument *This = HTMLDOC5_THIS(iface);
111     FIXME("(%p)->(%p)\n", This, p);
112     return E_NOTIMPL;
113 }
114
115 static HRESULT WINAPI HTMLDocument5_createAttribute(IHTMLDocument5 *iface, BSTR bstrattrName,
116         IHTMLDOMAttribute **ppattribute)
117 {
118     HTMLDocument *This = HTMLDOC5_THIS(iface);
119     FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrattrName), ppattribute);
120     return E_NOTIMPL;
121 }
122
123 static HRESULT WINAPI HTMLDocument5_createComment(IHTMLDocument5 *iface, BSTR bstrdata,
124         IHTMLDOMNode **ppRetNode)
125 {
126     HTMLDocument *This = HTMLDOC5_THIS(iface);
127     nsIDOMComment *nscomment;
128     HTMLElement *elem;
129     nsAString str;
130     nsresult nsres;
131     HRESULT hres;
132
133     TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrdata), ppRetNode);
134
135     if(!This->doc_node->nsdoc) {
136         WARN("NULL nsdoc\n");
137         return E_UNEXPECTED;
138     }
139
140     nsAString_InitDepend(&str, bstrdata);
141     nsres = nsIDOMHTMLDocument_CreateComment(This->doc_node->nsdoc, &str, &nscomment);
142     nsAString_Finish(&str);
143     if(NS_FAILED(nsres)) {
144         ERR("CreateTextNode failed: %08x\n", nsres);
145         return E_FAIL;
146     }
147
148     hres = HTMLCommentElement_Create(This->doc_node, (nsIDOMNode*)nscomment, &elem);
149     nsIDOMElement_Release(nscomment);
150     if(FAILED(hres))
151         return hres;
152
153     *ppRetNode = HTMLDOMNODE(&elem->node);
154     IHTMLDOMNode_AddRef(HTMLDOMNODE(&elem->node));
155     return S_OK;
156 }
157
158 static HRESULT WINAPI HTMLDocument5_put_onfocusin(IHTMLDocument5 *iface, VARIANT v)
159 {
160     HTMLDocument *This = HTMLDOC5_THIS(iface);
161     FIXME("(%p)->(v)\n", This);
162     return E_NOTIMPL;
163 }
164
165 static HRESULT WINAPI HTMLDocument5_get_onfocusin(IHTMLDocument5 *iface, VARIANT *p)
166 {
167     HTMLDocument *This = HTMLDOC5_THIS(iface);
168     FIXME("(%p)->(%p)\n", This, p);
169     return E_NOTIMPL;
170 }
171
172 static HRESULT WINAPI HTMLDocument5_put_onfocusout(IHTMLDocument5 *iface, VARIANT v)
173 {
174     HTMLDocument *This = HTMLDOC5_THIS(iface);
175     FIXME("(%p)->(v)\n", This);
176     return E_NOTIMPL;
177 }
178
179 static HRESULT WINAPI HTMLDocument5_get_onfocusout(IHTMLDocument5 *iface, VARIANT *p)
180 {
181     HTMLDocument *This = HTMLDOC5_THIS(iface);
182     FIXME("(%p)->(%p)\n", This, p);
183     return E_NOTIMPL;
184 }
185
186 static HRESULT WINAPI HTMLDocument5_put_onactivate(IHTMLDocument5 *iface, VARIANT v)
187 {
188     HTMLDocument *This = HTMLDOC5_THIS(iface);
189     FIXME("(%p)->(v)\n", This);
190     return E_NOTIMPL;
191 }
192
193 static HRESULT WINAPI HTMLDocument5_get_onactivate(IHTMLDocument5 *iface, VARIANT *p)
194 {
195     HTMLDocument *This = HTMLDOC5_THIS(iface);
196     FIXME("(%p)->(%p)\n", This, p);
197     return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI HTMLDocument5_put_ondeactivate(IHTMLDocument5 *iface, VARIANT v)
201 {
202     HTMLDocument *This = HTMLDOC5_THIS(iface);
203     FIXME("(%p)->(v)\n", This);
204     return E_NOTIMPL;
205 }
206
207 static HRESULT WINAPI HTMLDocument5_get_ondeactivate(IHTMLDocument5 *iface, VARIANT *p)
208 {
209     HTMLDocument *This = HTMLDOC5_THIS(iface);
210     FIXME("(%p)->(%p)\n", This, p);
211     return E_NOTIMPL;
212 }
213
214 static HRESULT WINAPI HTMLDocument5_put_onbeforeactivate(IHTMLDocument5 *iface, VARIANT v)
215 {
216     HTMLDocument *This = HTMLDOC5_THIS(iface);
217     FIXME("(%p)->(v)\n", This);
218     return E_NOTIMPL;
219 }
220
221 static HRESULT WINAPI HTMLDocument5_get_onbeforeactivate(IHTMLDocument5 *iface, VARIANT *p)
222 {
223     HTMLDocument *This = HTMLDOC5_THIS(iface);
224     FIXME("(%p)->(%p)\n", This, p);
225     return E_NOTIMPL;
226 }
227
228 static HRESULT WINAPI HTMLDocument5_put_onbeforedeactivate(IHTMLDocument5 *iface, VARIANT v)
229 {
230     HTMLDocument *This = HTMLDOC5_THIS(iface);
231     FIXME("(%p)->(v)\n", This);
232     return E_NOTIMPL;
233 }
234
235 static HRESULT WINAPI HTMLDocument5_get_onbeforedeactivate(IHTMLDocument5 *iface, VARIANT *p)
236 {
237     HTMLDocument *This = HTMLDOC5_THIS(iface);
238     FIXME("(%p)->(%p)\n", This, p);
239     return E_NOTIMPL;
240 }
241
242 static HRESULT WINAPI HTMLDocument5_get_compatMode(IHTMLDocument5 *iface, BSTR *p)
243 {
244     HTMLDocument *This = HTMLDOC5_THIS(iface);
245     nsIDOMNSHTMLDocument *nshtmldoc;
246     nsAString mode_str;
247     const PRUnichar *mode;
248     nsresult nsres;
249
250     TRACE("(%p)->(%p)\n", This, p);
251
252     if(!This->doc_node->nsdoc) {
253         WARN("NULL nsdoc\n");
254         return E_UNEXPECTED;
255     }
256
257     nsres = nsIDOMHTMLDocument_QueryInterface(This->doc_node->nsdoc, &IID_nsIDOMNSHTMLDocument, (void**)&nshtmldoc);
258     if(NS_FAILED(nsres)) {
259         ERR("Could not get nsIDOMNSHTMLDocument: %08x\n", nsres);
260         return S_OK;
261     }
262
263     nsAString_Init(&mode_str, NULL);
264     nsIDOMNSHTMLDocument_GetCompatMode(nshtmldoc, &mode_str);
265     nsIDOMNSHTMLDocument_Release(nshtmldoc);
266
267     nsAString_GetData(&mode_str, &mode);
268     *p = SysAllocString(mode);
269     nsAString_Finish(&mode_str);
270
271     return S_OK;
272 }
273
274 #undef HTMLDOC5_THIS
275
276 static const IHTMLDocument5Vtbl HTMLDocument5Vtbl = {
277     HTMLDocument5_QueryInterface,
278     HTMLDocument5_AddRef,
279     HTMLDocument5_Release,
280     HTMLDocument5_GetTypeInfoCount,
281     HTMLDocument5_GetTypeInfo,
282     HTMLDocument5_GetIDsOfNames,
283     HTMLDocument5_Invoke,
284     HTMLDocument5_put_onmousewheel,
285     HTMLDocument5_get_onmousewheel,
286     HTMLDocument5_get_doctype,
287     HTMLDocument5_get_implementation,
288     HTMLDocument5_createAttribute,
289     HTMLDocument5_createComment,
290     HTMLDocument5_put_onfocusin,
291     HTMLDocument5_get_onfocusin,
292     HTMLDocument5_put_onfocusout,
293     HTMLDocument5_get_onfocusout,
294     HTMLDocument5_put_onactivate,
295     HTMLDocument5_get_onactivate,
296     HTMLDocument5_put_ondeactivate,
297     HTMLDocument5_get_ondeactivate,
298     HTMLDocument5_put_onbeforeactivate,
299     HTMLDocument5_get_onbeforeactivate,
300     HTMLDocument5_put_onbeforedeactivate,
301     HTMLDocument5_get_onbeforedeactivate,
302     HTMLDocument5_get_compatMode
303 };
304
305 #define HTMLDOC6_THIS(iface) DEFINE_THIS(HTMLDocument, HTMLDocument6, iface)
306
307 static HRESULT WINAPI HTMLDocument6_QueryInterface(IHTMLDocument6 *iface,
308         REFIID riid, void **ppv)
309 {
310     HTMLDocument *This = HTMLDOC6_THIS(iface);
311     return htmldoc_query_interface(This, riid, ppv);
312 }
313
314 static ULONG WINAPI HTMLDocument6_AddRef(IHTMLDocument6 *iface)
315 {
316     HTMLDocument *This = HTMLDOC6_THIS(iface);
317     return htmldoc_addref(This);
318 }
319
320 static ULONG WINAPI HTMLDocument6_Release(IHTMLDocument6 *iface)
321 {
322     HTMLDocument *This = HTMLDOC6_THIS(iface);
323     return htmldoc_release(This);
324 }
325
326 static HRESULT WINAPI HTMLDocument6_GetTypeInfoCount(IHTMLDocument6 *iface, UINT *pctinfo)
327 {
328     HTMLDocument *This = HTMLDOC6_THIS(iface);
329     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
330 }
331
332 static HRESULT WINAPI HTMLDocument6_GetTypeInfo(IHTMLDocument6 *iface, UINT iTInfo,
333         LCID lcid, ITypeInfo **ppTInfo)
334 {
335     HTMLDocument *This = HTMLDOC6_THIS(iface);
336     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
337 }
338
339 static HRESULT WINAPI HTMLDocument6_GetIDsOfNames(IHTMLDocument6 *iface, REFIID riid,
340         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
341 {
342     HTMLDocument *This = HTMLDOC6_THIS(iface);
343     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
344 }
345
346 static HRESULT WINAPI HTMLDocument6_Invoke(IHTMLDocument6 *iface, DISPID dispIdMember,
347                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
348                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
349 {
350     HTMLDocument *This = HTMLDOC6_THIS(iface);
351     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
352             pVarResult, pExcepInfo, puArgErr);
353 }
354
355 static HRESULT WINAPI HTMLDocument6_get_compatible(IHTMLDocument6 *iface,
356         IHTMLDocumentCompatibleInfoCollection **p)
357 {
358     HTMLDocument *This = HTMLDOC6_THIS(iface);
359     FIXME("(%p)->(%p)\n", This, p);
360     return E_NOTIMPL;
361 }
362
363 static HRESULT WINAPI HTMLDocument6_get_documentMode(IHTMLDocument6 *iface,
364         VARIANT *p)
365 {
366     HTMLDocument *This = HTMLDOC6_THIS(iface);
367     FIXME("(%p)->(%p)\n", This, p);
368     return E_NOTIMPL;
369 }
370
371 static HRESULT WINAPI HTMLDocument6_get_onstorage(IHTMLDocument6 *iface,
372         VARIANT *p)
373 {
374     HTMLDocument *This = HTMLDOC6_THIS(iface);
375     FIXME("(%p)->(%p)\n", This, p);
376     return E_NOTIMPL;
377 }
378
379 static HRESULT WINAPI HTMLDocument6_put_onstorage(IHTMLDocument6 *iface,
380         VARIANT p)
381 {
382     HTMLDocument *This = HTMLDOC6_THIS(iface);
383     FIXME("(%p)->(v)\n", This);
384     return E_NOTIMPL;
385 }
386
387 static HRESULT WINAPI HTMLDocument6_get_onstoragecommit(IHTMLDocument6 *iface,
388         VARIANT *p)
389 {
390     HTMLDocument *This = HTMLDOC6_THIS(iface);
391     FIXME("(%p)->(%p)\n", This, p);
392     return E_NOTIMPL;
393 }
394
395 static HRESULT WINAPI HTMLDocument6_put_onstoragecommit(IHTMLDocument6 *iface,
396         VARIANT p)
397 {
398     HTMLDocument *This = HTMLDOC6_THIS(iface);
399     FIXME("(%p)->(v)\n", This);
400     return E_NOTIMPL;
401 }
402
403 static HRESULT WINAPI HTMLDocument6_getElementById(IHTMLDocument6 *iface,
404         BSTR bstrId, IHTMLElement2 **p)
405 {
406     HTMLDocument *This = HTMLDOC6_THIS(iface);
407     FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrId), p);
408     return E_NOTIMPL;
409 }
410
411 static HRESULT WINAPI HTMLDocument6_updateSettings(IHTMLDocument6 *iface)
412 {
413     HTMLDocument *This = HTMLDOC6_THIS(iface);
414     FIXME("(%p)->()\n", This);
415     return E_NOTIMPL;
416 }
417
418 #undef HTMLDOC6_THIS
419
420 static const IHTMLDocument6Vtbl HTMLDocument6Vtbl = {
421     HTMLDocument6_QueryInterface,
422     HTMLDocument6_AddRef,
423     HTMLDocument6_Release,
424     HTMLDocument6_GetTypeInfoCount,
425     HTMLDocument6_GetTypeInfo,
426     HTMLDocument6_GetIDsOfNames,
427     HTMLDocument6_Invoke,
428     HTMLDocument6_get_compatible,
429     HTMLDocument6_get_documentMode,
430     HTMLDocument6_put_onstorage,
431     HTMLDocument6_get_onstorage,
432     HTMLDocument6_put_onstoragecommit,
433     HTMLDocument6_get_onstoragecommit,
434     HTMLDocument6_getElementById,
435     HTMLDocument6_updateSettings
436 };
437
438 void HTMLDocument_HTMLDocument5_Init(HTMLDocument *This)
439 {
440     This->lpHTMLDocument5Vtbl = &HTMLDocument5Vtbl;
441     This->lpHTMLDocument6Vtbl = &HTMLDocument6Vtbl;
442 }