dwmapi: Add a stub for DwmGetTransportAttributes.
[wine] / dlls / mshtml / htmldoc3.c
1 /*
2  * Copyright 2005 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 #include "htmlevent.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
38 #define HTMLDOC3_THIS(iface) DEFINE_THIS(HTMLDocument, HTMLDocument3, iface)
39
40 static HRESULT WINAPI HTMLDocument3_QueryInterface(IHTMLDocument3 *iface,
41                                                   REFIID riid, void **ppv)
42 {
43     HTMLDocument *This = HTMLDOC3_THIS(iface);
44     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
45 }
46
47 static ULONG WINAPI HTMLDocument3_AddRef(IHTMLDocument3 *iface)
48 {
49     HTMLDocument *This = HTMLDOC3_THIS(iface);
50     return IHTMLDocument2_AddRef(HTMLDOC(This));
51 }
52
53 static ULONG WINAPI HTMLDocument3_Release(IHTMLDocument3 *iface)
54 {
55     HTMLDocument *This = HTMLDOC3_THIS(iface);
56     return IHTMLDocument2_Release(HTMLDOC(This));
57 }
58
59 static HRESULT WINAPI HTMLDocument3_GetTypeInfoCount(IHTMLDocument3 *iface, UINT *pctinfo)
60 {
61     HTMLDocument *This = HTMLDOC3_THIS(iface);
62     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
63 }
64
65 static HRESULT WINAPI HTMLDocument3_GetTypeInfo(IHTMLDocument3 *iface, UINT iTInfo,
66                                                 LCID lcid, ITypeInfo **ppTInfo)
67 {
68     HTMLDocument *This = HTMLDOC3_THIS(iface);
69     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
70 }
71
72 static HRESULT WINAPI HTMLDocument3_GetIDsOfNames(IHTMLDocument3 *iface, REFIID riid,
73                                                 LPOLESTR *rgszNames, UINT cNames,
74                                                 LCID lcid, DISPID *rgDispId)
75 {
76     HTMLDocument *This = HTMLDOC3_THIS(iface);
77     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
78 }
79
80 static HRESULT WINAPI HTMLDocument3_Invoke(IHTMLDocument3 *iface, DISPID dispIdMember,
81                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
82                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
83 {
84     HTMLDocument *This = HTMLDOC3_THIS(iface);
85     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
86             pVarResult, pExcepInfo, puArgErr);
87 }
88
89 static HRESULT WINAPI HTMLDocument3_releaseCapture(IHTMLDocument3 *iface)
90 {
91     HTMLDocument *This = HTMLDOC3_THIS(iface);
92     FIXME("(%p)\n", This);
93     return E_NOTIMPL;
94 }
95
96 static HRESULT WINAPI HTMLDocument3_recalc(IHTMLDocument3 *iface, VARIANT_BOOL fForce)
97 {
98     HTMLDocument *This = HTMLDOC3_THIS(iface);
99     FIXME("(%p)->(%x)\n", This, fForce);
100     return E_NOTIMPL;
101 }
102
103 static HRESULT WINAPI HTMLDocument3_createTextNode(IHTMLDocument3 *iface, BSTR text,
104                                                    IHTMLDOMNode **newTextNode)
105 {
106     HTMLDocument *This = HTMLDOC3_THIS(iface);
107     nsIDOMText *nstext;
108     HTMLDOMNode *node;
109     nsAString text_str;
110     nsresult nsres;
111
112     TRACE("(%p)->(%s %p)\n", This, debugstr_w(text), newTextNode);
113
114     if(!This->nsdoc) {
115         WARN("NULL nsdoc\n");
116         return E_UNEXPECTED;
117     }
118
119     nsAString_Init(&text_str, text);
120     nsres = nsIDOMHTMLDocument_CreateTextNode(This->nsdoc, &text_str, &nstext);
121     nsAString_Finish(&text_str);
122     if(NS_FAILED(nsres)) {
123         ERR("CreateTextNode failed: %08x\n", nsres);
124         return E_FAIL;
125     }
126
127     node = HTMLDOMTextNode_Create(This->doc_node, (nsIDOMNode*)nstext);
128     nsIDOMElement_Release(nstext);
129
130     *newTextNode = HTMLDOMNODE(node);
131     IHTMLDOMNode_AddRef(HTMLDOMNODE(node));
132     return S_OK;
133 }
134
135 static HRESULT WINAPI HTMLDocument3_get_documentElement(IHTMLDocument3 *iface, IHTMLElement **p)
136 {
137     HTMLDocument *This = HTMLDOC3_THIS(iface);
138     nsIDOMElement *nselem = NULL;
139     HTMLDOMNode *node;
140     nsresult nsres;
141
142     TRACE("(%p)->(%p)\n", This, p);
143
144     if(!This->nsdoc) {
145         WARN("NULL nsdoc\n");
146         return E_UNEXPECTED;
147     }
148
149     nsres = nsIDOMHTMLDocument_GetDocumentElement(This->nsdoc, &nselem);
150     if(NS_FAILED(nsres)) {
151         ERR("GetDocumentElement failed: %08x\n", nsres);
152         return E_FAIL;
153     }
154
155     if(nselem) {
156         node = get_node(This->doc_node, (nsIDOMNode *)nselem, TRUE);
157         nsIDOMElement_Release(nselem);
158         IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)p);
159     }else {
160         *p = NULL;
161     }
162
163     return S_OK;
164 }
165
166 static HRESULT WINAPI HTMLDocument3_uniqueID(IHTMLDocument3 *iface, BSTR *p)
167 {
168     HTMLDocument *This = HTMLDOC3_THIS(iface);
169     FIXME("(%p)->(%p)\n", This, p);
170     return E_NOTIMPL;
171 }
172
173 static HRESULT WINAPI HTMLDocument3_attachEvent(IHTMLDocument3 *iface, BSTR event,
174                                                 IDispatch* pDisp, VARIANT_BOOL *pfResult)
175 {
176     HTMLDocument *This = HTMLDOC3_THIS(iface);
177
178     TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
179
180     return attach_event(&This->doc_node->node.event_target, This, event, pDisp, pfResult);
181 }
182
183 static HRESULT WINAPI HTMLDocument3_detachEvent(IHTMLDocument3 *iface, BSTR event,
184                                                 IDispatch *pDisp)
185 {
186     HTMLDocument *This = HTMLDOC3_THIS(iface);
187     FIXME("(%p)->(%s %p)\n", This, debugstr_w(event), pDisp);
188     return E_NOTIMPL;
189 }
190
191 static HRESULT WINAPI HTMLDocument3_put_onrowsdelete(IHTMLDocument3 *iface, VARIANT v)
192 {
193     HTMLDocument *This = HTMLDOC3_THIS(iface);
194     FIXME("(%p)->()\n", This);
195     return E_NOTIMPL;
196 }
197
198 static HRESULT WINAPI HTMLDocument3_get_onrowsdelete(IHTMLDocument3 *iface, VARIANT *p)
199 {
200     HTMLDocument *This = HTMLDOC3_THIS(iface);
201     FIXME("(%p)->(%p)\n", This, p);
202     return E_NOTIMPL;
203 }
204
205 static HRESULT WINAPI HTMLDocument3_put_onrowsinserted(IHTMLDocument3 *iface, VARIANT v)
206 {
207     HTMLDocument *This = HTMLDOC3_THIS(iface);
208     FIXME("(%p)->()\n", This);
209     return E_NOTIMPL;
210 }
211
212 static HRESULT WINAPI HTMLDocument3_get_onrowsinserted(IHTMLDocument3 *iface, VARIANT *p)
213 {
214     HTMLDocument *This = HTMLDOC3_THIS(iface);
215     FIXME("(%p)->(%p)\n", This, p);
216     return E_NOTIMPL;
217 }
218
219 static HRESULT WINAPI HTMLDocument3_put_oncellchange(IHTMLDocument3 *iface, VARIANT v)
220 {
221     HTMLDocument *This = HTMLDOC3_THIS(iface);
222     FIXME("(%p)->()\n", This);
223     return E_NOTIMPL;
224 }
225
226 static HRESULT WINAPI HTMLDocument3_get_oncellchange(IHTMLDocument3 *iface, VARIANT *p)
227 {
228     HTMLDocument *This = HTMLDOC3_THIS(iface);
229     FIXME("(%p)->(%p)\n", This, p);
230     return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI HTMLDocument3_put_ondatasetchanged(IHTMLDocument3 *iface, VARIANT v)
234 {
235     HTMLDocument *This = HTMLDOC3_THIS(iface);
236     FIXME("(%p)->()\n", This);
237     return E_NOTIMPL;
238 }
239
240 static HRESULT WINAPI HTMLDocument3_get_ondatasetchanged(IHTMLDocument3 *iface, VARIANT *p)
241 {
242     HTMLDocument *This = HTMLDOC3_THIS(iface);
243     FIXME("(%p)->(%p)\n", This, p);
244     return E_NOTIMPL;
245 }
246
247 static HRESULT WINAPI HTMLDocument3_put_ondataavailable(IHTMLDocument3 *iface, VARIANT v)
248 {
249     HTMLDocument *This = HTMLDOC3_THIS(iface);
250     FIXME("(%p)->()\n", This);
251     return E_NOTIMPL;
252 }
253
254 static HRESULT WINAPI HTMLDocument3_get_ondataavailable(IHTMLDocument3 *iface, VARIANT *p)
255 {
256     HTMLDocument *This = HTMLDOC3_THIS(iface);
257     FIXME("(%p)->(%p)\n", This, p);
258     return E_NOTIMPL;
259 }
260
261 static HRESULT WINAPI HTMLDocument3_put_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT v)
262 {
263     HTMLDocument *This = HTMLDOC3_THIS(iface);
264     FIXME("(%p)->()\n", This);
265     return E_NOTIMPL;
266 }
267
268 static HRESULT WINAPI HTMLDocument3_get_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT *p)
269 {
270     HTMLDocument *This = HTMLDOC3_THIS(iface);
271     FIXME("(%p)->(%p)\n", This, p);
272     return E_NOTIMPL;
273 }
274
275 static HRESULT WINAPI HTMLDocument3_put_onpropertychange(IHTMLDocument3 *iface, VARIANT v)
276 {
277     HTMLDocument *This = HTMLDOC3_THIS(iface);
278     FIXME("(%p)->()\n", This);
279     return E_NOTIMPL;
280 }
281
282 static HRESULT WINAPI HTMLDocument3_get_onpropertychange(IHTMLDocument3 *iface, VARIANT *p)
283 {
284     HTMLDocument *This = HTMLDOC3_THIS(iface);
285     FIXME("(%p)->(%p)\n", This, p);
286     return E_NOTIMPL;
287 }
288
289 static HRESULT WINAPI HTMLDocument3_put_dir(IHTMLDocument3 *iface, BSTR v)
290 {
291     HTMLDocument *This = HTMLDOC3_THIS(iface);
292     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
293     return E_NOTIMPL;
294 }
295
296 static HRESULT WINAPI HTMLDocument3_get_dir(IHTMLDocument3 *iface, BSTR *p)
297 {
298     HTMLDocument *This = HTMLDOC3_THIS(iface);
299     FIXME("(%p)->(%p)\n", This, p);
300     return E_NOTIMPL;
301 }
302
303 static HRESULT WINAPI HTMLDocument3_put_oncontextmenu(IHTMLDocument3 *iface, VARIANT v)
304 {
305     HTMLDocument *This = HTMLDOC3_THIS(iface);
306     FIXME("(%p)->()\n", This);
307     return E_NOTIMPL;
308 }
309
310 static HRESULT WINAPI HTMLDocument3_get_oncontextmenu(IHTMLDocument3 *iface, VARIANT *p)
311 {
312     HTMLDocument *This = HTMLDOC3_THIS(iface);
313     FIXME("(%p)->(%p)\n", This, p);
314     return E_NOTIMPL;
315 }
316
317 static HRESULT WINAPI HTMLDocument3_put_onstop(IHTMLDocument3 *iface, VARIANT v)
318 {
319     HTMLDocument *This = HTMLDOC3_THIS(iface);
320     FIXME("(%p)->()\n", This);
321     return E_NOTIMPL;
322 }
323
324 static HRESULT WINAPI HTMLDocument3_get_onstop(IHTMLDocument3 *iface, VARIANT *p)
325 {
326     HTMLDocument *This = HTMLDOC3_THIS(iface);
327     FIXME("(%p)->(%p)\n", This, p);
328     return E_NOTIMPL;
329 }
330
331 static HRESULT WINAPI HTMLDocument3_createDocumentFragment(IHTMLDocument3 *iface,
332                                                            IHTMLDocument2 **ppNewDoc)
333 {
334     HTMLDocument *This = HTMLDOC3_THIS(iface);
335     FIXME("(%p)->(%p)\n", This, ppNewDoc);
336     return E_NOTIMPL;
337 }
338
339 static HRESULT WINAPI HTMLDocument3_get_parentDocument(IHTMLDocument3 *iface,
340                                                        IHTMLDocument2 **p)
341 {
342     HTMLDocument *This = HTMLDOC3_THIS(iface);
343     FIXME("(%p)->(%p)\n", This, p);
344     return E_NOTIMPL;
345 }
346
347 static HRESULT WINAPI HTMLDocument3_put_enableDownload(IHTMLDocument3 *iface,
348                                                        VARIANT_BOOL v)
349 {
350     HTMLDocument *This = HTMLDOC3_THIS(iface);
351     FIXME("(%p)->(%x)\n", This, v);
352     return E_NOTIMPL;
353 }
354
355 static HRESULT WINAPI HTMLDocument3_get_enableDownload(IHTMLDocument3 *iface,
356                                                        VARIANT_BOOL *p)
357 {
358     HTMLDocument *This = HTMLDOC3_THIS(iface);
359     FIXME("(%p)->(%p)\n", This, p);
360     return E_NOTIMPL;
361 }
362
363 static HRESULT WINAPI HTMLDocument3_put_baseUrl(IHTMLDocument3 *iface, BSTR v)
364 {
365     HTMLDocument *This = HTMLDOC3_THIS(iface);
366     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
367     return E_NOTIMPL;
368 }
369
370 static HRESULT WINAPI HTMLDocument3_get_baseUrl(IHTMLDocument3 *iface, BSTR *p)
371 {
372     HTMLDocument *This = HTMLDOC3_THIS(iface);
373     FIXME("(%p)->(%p)\n", This, p);
374     return E_NOTIMPL;
375 }
376
377 static HRESULT WINAPI HTMLDocument3_get_childNodes(IHTMLDocument3 *iface, IDispatch **p)
378 {
379     HTMLDocument *This = HTMLDOC3_THIS(iface);
380     FIXME("(%p)->(%p)\n", This, p);
381     return E_NOTIMPL;
382 }
383
384 static HRESULT WINAPI HTMLDocument3_put_inheritStyleSheets(IHTMLDocument3 *iface,
385                                                            VARIANT_BOOL v)
386 {
387     HTMLDocument *This = HTMLDOC3_THIS(iface);
388     FIXME("(%p)->()\n", This);
389     return E_NOTIMPL;
390 }
391
392 static HRESULT WINAPI HTMLDocument3_get_inheritStyleSheets(IHTMLDocument3 *iface,
393                                                            VARIANT_BOOL *p)
394 {
395     HTMLDocument *This = HTMLDOC3_THIS(iface);
396     FIXME("(%p)->(%p)\n", This, p);
397     return E_NOTIMPL;
398 }
399
400 static HRESULT WINAPI HTMLDocument3_put_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT v)
401 {
402     HTMLDocument *This = HTMLDOC3_THIS(iface);
403     FIXME("(%p)->()\n", This);
404     return E_NOTIMPL;
405 }
406
407 static HRESULT WINAPI HTMLDocument3_get_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT *p)
408 {
409     HTMLDocument *This = HTMLDOC3_THIS(iface);
410     FIXME("(%p)->(%p)\n", This, p);
411     return E_NOTIMPL;
412 }
413
414 static HRESULT WINAPI HTMLDocument3_getElementsByName(IHTMLDocument3 *iface, BSTR v,
415                                                       IHTMLElementCollection **ppelColl)
416 {
417     HTMLDocument *This = HTMLDOC3_THIS(iface);
418     FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), ppelColl);
419     return E_NOTIMPL;
420 }
421
422
423 static HRESULT WINAPI HTMLDocument3_getElementById(IHTMLDocument3 *iface, BSTR v,
424                                                    IHTMLElement **pel)
425 {
426     HTMLDocument *This = HTMLDOC3_THIS(iface);
427     nsIDOMElement *nselem;
428     HTMLDOMNode *node;
429     nsAString id_str;
430     nsresult nsres;
431
432     TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
433
434     if(!This->nsdoc) {
435         WARN("NULL nsdoc\n");
436         return E_UNEXPECTED;
437     }
438
439     nsAString_Init(&id_str, v);
440     nsres = nsIDOMHTMLDocument_GetElementById(This->nsdoc, &id_str, &nselem);
441     nsAString_Finish(&id_str);
442     if(FAILED(nsres)) {
443         ERR("GetElementById failed: %08x\n", nsres);
444         return E_FAIL;
445     }
446
447     if(nselem) {
448         node = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE);
449         nsIDOMElement_Release(nselem);
450
451         IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)pel);
452     }else {
453         *pel = NULL;
454     }
455
456     return S_OK;
457 }
458
459
460 static HRESULT WINAPI HTMLDocument3_getElementsByTagName(IHTMLDocument3 *iface, BSTR v,
461                                                          IHTMLElementCollection **pelColl)
462 {
463     HTMLDocument *This = HTMLDOC3_THIS(iface);
464     nsIDOMNodeList *nslist;
465     nsAString id_str, ns_str;
466     nsresult nsres;
467     static const WCHAR str[] = {'*',0};
468
469     TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pelColl);
470
471     if(!This->nsdoc) {
472         WARN("NULL nsdoc\n");
473         return E_UNEXPECTED;
474     }
475
476     nsAString_Init(&id_str, v);
477     nsAString_Init(&ns_str, str);
478     nsres = nsIDOMHTMLDocument_GetElementsByTagNameNS(This->nsdoc, &ns_str, &id_str, &nslist);
479     nsAString_Finish(&id_str);
480     nsAString_Finish(&ns_str);
481     if(FAILED(nsres)) {
482         ERR("GetElementByName failed: %08x\n", nsres);
483         return E_FAIL;
484     }
485
486     *pelColl = (IHTMLElementCollection*)create_collection_from_nodelist(This->doc_node, (IUnknown*)HTMLDOC3(This), nslist);
487     nsIDOMNodeList_Release(nslist);
488
489     return S_OK;
490 }
491
492 #undef HTMLDOC3_THIS
493
494 static const IHTMLDocument3Vtbl HTMLDocument3Vtbl = {
495     HTMLDocument3_QueryInterface,
496     HTMLDocument3_AddRef,
497     HTMLDocument3_Release,
498     HTMLDocument3_GetTypeInfoCount,
499     HTMLDocument3_GetTypeInfo,
500     HTMLDocument3_GetIDsOfNames,
501     HTMLDocument3_Invoke,
502     HTMLDocument3_releaseCapture,
503     HTMLDocument3_recalc,
504     HTMLDocument3_createTextNode,
505     HTMLDocument3_get_documentElement,
506     HTMLDocument3_uniqueID,
507     HTMLDocument3_attachEvent,
508     HTMLDocument3_detachEvent,
509     HTMLDocument3_put_onrowsdelete,
510     HTMLDocument3_get_onrowsdelete,
511     HTMLDocument3_put_onrowsinserted,
512     HTMLDocument3_get_onrowsinserted,
513     HTMLDocument3_put_oncellchange,
514     HTMLDocument3_get_oncellchange,
515     HTMLDocument3_put_ondatasetchanged,
516     HTMLDocument3_get_ondatasetchanged,
517     HTMLDocument3_put_ondataavailable,
518     HTMLDocument3_get_ondataavailable,
519     HTMLDocument3_put_ondatasetcomplete,
520     HTMLDocument3_get_ondatasetcomplete,
521     HTMLDocument3_put_onpropertychange,
522     HTMLDocument3_get_onpropertychange,
523     HTMLDocument3_put_dir,
524     HTMLDocument3_get_dir,
525     HTMLDocument3_put_oncontextmenu,
526     HTMLDocument3_get_oncontextmenu,
527     HTMLDocument3_put_onstop,
528     HTMLDocument3_get_onstop,
529     HTMLDocument3_createDocumentFragment,
530     HTMLDocument3_get_parentDocument,
531     HTMLDocument3_put_enableDownload,
532     HTMLDocument3_get_enableDownload,
533     HTMLDocument3_put_baseUrl,
534     HTMLDocument3_get_baseUrl,
535     HTMLDocument3_get_childNodes,
536     HTMLDocument3_put_inheritStyleSheets,
537     HTMLDocument3_get_inheritStyleSheets,
538     HTMLDocument3_put_onbeforeeditfocus,
539     HTMLDocument3_get_onbeforeeditfocus,
540     HTMLDocument3_getElementsByName,
541     HTMLDocument3_getElementById,
542     HTMLDocument3_getElementsByTagName
543 };
544
545 #define HTMLDOC4_THIS(iface) DEFINE_THIS(HTMLDocument, HTMLDocument4, iface)
546
547 static HRESULT WINAPI HTMLDocument4_QueryInterface(IHTMLDocument4 *iface,
548                                                    REFIID riid, void **ppv)
549 {
550     HTMLDocument *This = HTMLDOC4_THIS(iface);
551     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
552 }
553
554 static ULONG WINAPI HTMLDocument4_AddRef(IHTMLDocument4 *iface)
555 {
556     HTMLDocument *This = HTMLDOC4_THIS(iface);
557     return IHTMLDocument2_AddRef(HTMLDOC(This));
558 }
559
560 static ULONG WINAPI HTMLDocument4_Release(IHTMLDocument4 *iface)
561 {
562     HTMLDocument *This = HTMLDOC4_THIS(iface);
563     return IHTMLDocument2_Release(HTMLDOC(This));
564 }
565
566 static HRESULT WINAPI HTMLDocument4_GetTypeInfoCount(IHTMLDocument4 *iface, UINT *pctinfo)
567 {
568     HTMLDocument *This = HTMLDOC4_THIS(iface);
569     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
570 }
571
572 static HRESULT WINAPI HTMLDocument4_GetTypeInfo(IHTMLDocument4 *iface, UINT iTInfo,
573                                                 LCID lcid, ITypeInfo **ppTInfo)
574 {
575     HTMLDocument *This = HTMLDOC4_THIS(iface);
576     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
577 }
578
579 static HRESULT WINAPI HTMLDocument4_GetIDsOfNames(IHTMLDocument4 *iface, REFIID riid,
580                                                 LPOLESTR *rgszNames, UINT cNames,
581                                                 LCID lcid, DISPID *rgDispId)
582 {
583     HTMLDocument *This = HTMLDOC4_THIS(iface);
584     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
585 }
586
587 static HRESULT WINAPI HTMLDocument4_Invoke(IHTMLDocument4 *iface, DISPID dispIdMember,
588                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
589                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
590 {
591     HTMLDocument *This = HTMLDOC4_THIS(iface);
592     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
593             pVarResult, pExcepInfo, puArgErr);
594 }
595
596 static HRESULT WINAPI HTMLDocument4_focus(IHTMLDocument4 *iface)
597 {
598     HTMLDocument *This = HTMLDOC4_THIS(iface);
599     nsIDOMNSHTMLElement *nselem;
600     nsIDOMHTMLElement *nsbody;
601     nsresult nsres;
602
603     TRACE("(%p)->()\n", This);
604
605     nsres = nsIDOMHTMLDocument_GetBody(This->nsdoc, &nsbody);
606     if(NS_FAILED(nsres) || !nsbody) {
607         ERR("GetBody failed: %08x\n", nsres);
608         return E_FAIL;
609     }
610
611     nsres = nsIDOMHTMLElement_QueryInterface(nsbody, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
612     nsIDOMHTMLElement_Release(nsbody);
613     if(NS_FAILED(nsres)) {
614         ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
615         return E_FAIL;
616     }
617
618     nsres = nsIDOMNSHTMLElement_focus(nselem);
619     nsIDOMNSHTMLElement_Release(nselem);
620     if(NS_FAILED(nsres)) {
621         ERR("Focus failed: %08x\n", nsres);
622         return E_FAIL;
623     }
624
625     return S_OK;
626 }
627
628 static HRESULT WINAPI HTMLDocument4_hasFocus(IHTMLDocument4 *iface, VARIANT_BOOL *pfFocus)
629 {
630     HTMLDocument *This = HTMLDOC4_THIS(iface);
631     FIXME("(%p)->(%p)\n", This, pfFocus);
632     return E_NOTIMPL;
633 }
634
635 static HRESULT WINAPI HTMLDocument4_put_onselectionchange(IHTMLDocument4 *iface, VARIANT v)
636 {
637     HTMLDocument *This = HTMLDOC4_THIS(iface);
638     FIXME("(%p)->(v)\n", This);
639     return E_NOTIMPL;
640 }
641
642 static HRESULT WINAPI HTMLDocument4_get_onselectionchange(IHTMLDocument4 *iface, VARIANT *p)
643 {
644     HTMLDocument *This = HTMLDOC4_THIS(iface);
645     FIXME("(%p)->(%p)\n", This, p);
646     return E_NOTIMPL;
647 }
648
649 static HRESULT WINAPI HTMLDocument4_get_namespace(IHTMLDocument4 *iface, IDispatch **p)
650 {
651     HTMLDocument *This = HTMLDOC4_THIS(iface);
652     FIXME("(%p)->(%p)\n", This, p);
653     return E_NOTIMPL;
654 }
655
656 static HRESULT WINAPI HTMLDocument4_createDocumentFromUrl(IHTMLDocument4 *iface, BSTR bstrUrl,
657         BSTR bstrOptions, IHTMLDocument2 **newDoc)
658 {
659     HTMLDocument *This = HTMLDOC4_THIS(iface);
660     FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(bstrUrl), debugstr_w(bstrOptions), newDoc);
661     return E_NOTIMPL;
662 }
663
664 static HRESULT WINAPI HTMLDocument4_put_media(IHTMLDocument4 *iface, BSTR v)
665 {
666     HTMLDocument *This = HTMLDOC4_THIS(iface);
667     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
668     return E_NOTIMPL;
669 }
670
671 static HRESULT WINAPI HTMLDocument4_get_media(IHTMLDocument4 *iface, BSTR *p)
672 {
673     HTMLDocument *This = HTMLDOC4_THIS(iface);
674     FIXME("(%p)->(%p)\n", This, p);
675     return E_NOTIMPL;
676 }
677
678 static HRESULT WINAPI HTMLDocument4_createEventObject(IHTMLDocument4 *iface,
679         VARIANT *pvarEventObject, IHTMLEventObj **ppEventObj)
680 {
681     HTMLDocument *This = HTMLDOC4_THIS(iface);
682     FIXME("(%p)->(%p %p)\n", This, pvarEventObject, ppEventObj);
683     return E_NOTIMPL;
684 }
685
686 static HRESULT WINAPI HTMLDocument4_fireEvent(IHTMLDocument4 *iface, BSTR bstrEventName,
687         VARIANT *pvarEventObject, VARIANT_BOOL *pfCanceled)
688 {
689     HTMLDocument *This = HTMLDOC4_THIS(iface);
690     FIXME("(%p)->(%s %p %p)\n", This, debugstr_w(bstrEventName), pvarEventObject, pfCanceled);
691     return E_NOTIMPL;
692 }
693
694 static HRESULT WINAPI HTMLDocument4_createRenderStyle(IHTMLDocument4 *iface, BSTR v,
695         IHTMLRenderStyle **ppIHTMLRenderStyle)
696 {
697     HTMLDocument *This = HTMLDOC4_THIS(iface);
698     FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), ppIHTMLRenderStyle);
699     return E_NOTIMPL;
700 }
701
702 static HRESULT WINAPI HTMLDocument4_put_oncontrolselect(IHTMLDocument4 *iface, VARIANT v)
703 {
704     HTMLDocument *This = HTMLDOC4_THIS(iface);
705     FIXME("(%p)->(v)\n", This);
706     return E_NOTIMPL;
707 }
708
709 static HRESULT WINAPI HTMLDocument4_get_oncontrolselect(IHTMLDocument4 *iface, VARIANT *p)
710 {
711     HTMLDocument *This = HTMLDOC4_THIS(iface);
712     FIXME("(%p)->(%p)\n", This, p);
713     return E_NOTIMPL;
714 }
715
716 static HRESULT WINAPI HTMLDocument4_get_URLEncoded(IHTMLDocument4 *iface, BSTR *p)
717 {
718     HTMLDocument *This = HTMLDOC4_THIS(iface);
719     FIXME("(%p)->(%p)\n", This, p);
720     return E_NOTIMPL;
721 }
722
723 #undef HTMLDOC4_THIS
724
725 static const IHTMLDocument4Vtbl HTMLDocument4Vtbl = {
726     HTMLDocument4_QueryInterface,
727     HTMLDocument4_AddRef,
728     HTMLDocument4_Release,
729     HTMLDocument4_GetTypeInfoCount,
730     HTMLDocument4_GetTypeInfo,
731     HTMLDocument4_GetIDsOfNames,
732     HTMLDocument4_Invoke,
733     HTMLDocument4_focus,
734     HTMLDocument4_hasFocus,
735     HTMLDocument4_put_onselectionchange,
736     HTMLDocument4_get_onselectionchange,
737     HTMLDocument4_get_namespace,
738     HTMLDocument4_createDocumentFromUrl,
739     HTMLDocument4_put_media,
740     HTMLDocument4_get_media,
741     HTMLDocument4_createEventObject,
742     HTMLDocument4_fireEvent,
743     HTMLDocument4_createRenderStyle,
744     HTMLDocument4_put_oncontrolselect,
745     HTMLDocument4_get_oncontrolselect,
746     HTMLDocument4_get_URLEncoded
747 };
748
749 void HTMLDocument_HTMLDocument3_Init(HTMLDocument *This)
750 {
751     This->lpHTMLDocument3Vtbl = &HTMLDocument3Vtbl;
752     This->lpHTMLDocument4Vtbl = &HTMLDocument4Vtbl;
753 }