mciwave: MCI Capability returns number of wave devices.
[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->doc_node->nsdoc) {
115         WARN("NULL nsdoc\n");
116         return E_UNEXPECTED;
117     }
118
119     nsAString_Init(&text_str, text);
120     nsres = nsIDOMHTMLDocument_CreateTextNode(This->doc_node->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->window->readystate == READYSTATE_UNINITIALIZED) {
145         *p = NULL;
146         return S_OK;
147     }
148
149     if(!This->doc_node->nsdoc) {
150         WARN("NULL nsdoc\n");
151         return E_UNEXPECTED;
152     }
153
154     nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
155     if(NS_FAILED(nsres)) {
156         ERR("GetDocumentElement failed: %08x\n", nsres);
157         return E_FAIL;
158     }
159
160     if(nselem) {
161         node = get_node(This->doc_node, (nsIDOMNode *)nselem, TRUE);
162         nsIDOMElement_Release(nselem);
163         IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)p);
164     }else {
165         *p = NULL;
166     }
167
168     return S_OK;
169 }
170
171 static HRESULT WINAPI HTMLDocument3_uniqueID(IHTMLDocument3 *iface, BSTR *p)
172 {
173     HTMLDocument *This = HTMLDOC3_THIS(iface);
174     FIXME("(%p)->(%p)\n", This, p);
175     return E_NOTIMPL;
176 }
177
178 static HRESULT WINAPI HTMLDocument3_attachEvent(IHTMLDocument3 *iface, BSTR event,
179                                                 IDispatch* pDisp, VARIANT_BOOL *pfResult)
180 {
181     HTMLDocument *This = HTMLDOC3_THIS(iface);
182
183     TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
184
185     return attach_event(&This->doc_node->node.event_target, This, event, pDisp, pfResult);
186 }
187
188 static HRESULT WINAPI HTMLDocument3_detachEvent(IHTMLDocument3 *iface, BSTR event,
189                                                 IDispatch *pDisp)
190 {
191     HTMLDocument *This = HTMLDOC3_THIS(iface);
192     FIXME("(%p)->(%s %p)\n", This, debugstr_w(event), pDisp);
193     return E_NOTIMPL;
194 }
195
196 static HRESULT WINAPI HTMLDocument3_put_onrowsdelete(IHTMLDocument3 *iface, VARIANT v)
197 {
198     HTMLDocument *This = HTMLDOC3_THIS(iface);
199     FIXME("(%p)->()\n", This);
200     return E_NOTIMPL;
201 }
202
203 static HRESULT WINAPI HTMLDocument3_get_onrowsdelete(IHTMLDocument3 *iface, VARIANT *p)
204 {
205     HTMLDocument *This = HTMLDOC3_THIS(iface);
206     FIXME("(%p)->(%p)\n", This, p);
207     return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI HTMLDocument3_put_onrowsinserted(IHTMLDocument3 *iface, VARIANT v)
211 {
212     HTMLDocument *This = HTMLDOC3_THIS(iface);
213     FIXME("(%p)->()\n", This);
214     return E_NOTIMPL;
215 }
216
217 static HRESULT WINAPI HTMLDocument3_get_onrowsinserted(IHTMLDocument3 *iface, VARIANT *p)
218 {
219     HTMLDocument *This = HTMLDOC3_THIS(iface);
220     FIXME("(%p)->(%p)\n", This, p);
221     return E_NOTIMPL;
222 }
223
224 static HRESULT WINAPI HTMLDocument3_put_oncellchange(IHTMLDocument3 *iface, VARIANT v)
225 {
226     HTMLDocument *This = HTMLDOC3_THIS(iface);
227     FIXME("(%p)->()\n", This);
228     return E_NOTIMPL;
229 }
230
231 static HRESULT WINAPI HTMLDocument3_get_oncellchange(IHTMLDocument3 *iface, VARIANT *p)
232 {
233     HTMLDocument *This = HTMLDOC3_THIS(iface);
234     FIXME("(%p)->(%p)\n", This, p);
235     return E_NOTIMPL;
236 }
237
238 static HRESULT WINAPI HTMLDocument3_put_ondatasetchanged(IHTMLDocument3 *iface, VARIANT v)
239 {
240     HTMLDocument *This = HTMLDOC3_THIS(iface);
241     FIXME("(%p)->()\n", This);
242     return E_NOTIMPL;
243 }
244
245 static HRESULT WINAPI HTMLDocument3_get_ondatasetchanged(IHTMLDocument3 *iface, VARIANT *p)
246 {
247     HTMLDocument *This = HTMLDOC3_THIS(iface);
248     FIXME("(%p)->(%p)\n", This, p);
249     return E_NOTIMPL;
250 }
251
252 static HRESULT WINAPI HTMLDocument3_put_ondataavailable(IHTMLDocument3 *iface, VARIANT v)
253 {
254     HTMLDocument *This = HTMLDOC3_THIS(iface);
255     FIXME("(%p)->()\n", This);
256     return E_NOTIMPL;
257 }
258
259 static HRESULT WINAPI HTMLDocument3_get_ondataavailable(IHTMLDocument3 *iface, VARIANT *p)
260 {
261     HTMLDocument *This = HTMLDOC3_THIS(iface);
262     FIXME("(%p)->(%p)\n", This, p);
263     return E_NOTIMPL;
264 }
265
266 static HRESULT WINAPI HTMLDocument3_put_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT v)
267 {
268     HTMLDocument *This = HTMLDOC3_THIS(iface);
269     FIXME("(%p)->()\n", This);
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI HTMLDocument3_get_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT *p)
274 {
275     HTMLDocument *This = HTMLDOC3_THIS(iface);
276     FIXME("(%p)->(%p)\n", This, p);
277     return E_NOTIMPL;
278 }
279
280 static HRESULT WINAPI HTMLDocument3_put_onpropertychange(IHTMLDocument3 *iface, VARIANT v)
281 {
282     HTMLDocument *This = HTMLDOC3_THIS(iface);
283     FIXME("(%p)->()\n", This);
284     return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI HTMLDocument3_get_onpropertychange(IHTMLDocument3 *iface, VARIANT *p)
288 {
289     HTMLDocument *This = HTMLDOC3_THIS(iface);
290     FIXME("(%p)->(%p)\n", This, p);
291     return E_NOTIMPL;
292 }
293
294 static HRESULT WINAPI HTMLDocument3_put_dir(IHTMLDocument3 *iface, BSTR v)
295 {
296     HTMLDocument *This = HTMLDOC3_THIS(iface);
297     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
298     return E_NOTIMPL;
299 }
300
301 static HRESULT WINAPI HTMLDocument3_get_dir(IHTMLDocument3 *iface, BSTR *p)
302 {
303     HTMLDocument *This = HTMLDOC3_THIS(iface);
304     FIXME("(%p)->(%p)\n", This, p);
305     return E_NOTIMPL;
306 }
307
308 static HRESULT WINAPI HTMLDocument3_put_oncontextmenu(IHTMLDocument3 *iface, VARIANT v)
309 {
310     HTMLDocument *This = HTMLDOC3_THIS(iface);
311     FIXME("(%p)->()\n", This);
312     return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI HTMLDocument3_get_oncontextmenu(IHTMLDocument3 *iface, VARIANT *p)
316 {
317     HTMLDocument *This = HTMLDOC3_THIS(iface);
318     FIXME("(%p)->(%p)\n", This, p);
319     return E_NOTIMPL;
320 }
321
322 static HRESULT WINAPI HTMLDocument3_put_onstop(IHTMLDocument3 *iface, VARIANT v)
323 {
324     HTMLDocument *This = HTMLDOC3_THIS(iface);
325     FIXME("(%p)->()\n", This);
326     return E_NOTIMPL;
327 }
328
329 static HRESULT WINAPI HTMLDocument3_get_onstop(IHTMLDocument3 *iface, VARIANT *p)
330 {
331     HTMLDocument *This = HTMLDOC3_THIS(iface);
332     FIXME("(%p)->(%p)\n", This, p);
333     return E_NOTIMPL;
334 }
335
336 static HRESULT WINAPI HTMLDocument3_createDocumentFragment(IHTMLDocument3 *iface,
337                                                            IHTMLDocument2 **ppNewDoc)
338 {
339     HTMLDocument *This = HTMLDOC3_THIS(iface);
340     FIXME("(%p)->(%p)\n", This, ppNewDoc);
341     return E_NOTIMPL;
342 }
343
344 static HRESULT WINAPI HTMLDocument3_get_parentDocument(IHTMLDocument3 *iface,
345                                                        IHTMLDocument2 **p)
346 {
347     HTMLDocument *This = HTMLDOC3_THIS(iface);
348     FIXME("(%p)->(%p)\n", This, p);
349     return E_NOTIMPL;
350 }
351
352 static HRESULT WINAPI HTMLDocument3_put_enableDownload(IHTMLDocument3 *iface,
353                                                        VARIANT_BOOL v)
354 {
355     HTMLDocument *This = HTMLDOC3_THIS(iface);
356     FIXME("(%p)->(%x)\n", This, v);
357     return E_NOTIMPL;
358 }
359
360 static HRESULT WINAPI HTMLDocument3_get_enableDownload(IHTMLDocument3 *iface,
361                                                        VARIANT_BOOL *p)
362 {
363     HTMLDocument *This = HTMLDOC3_THIS(iface);
364     FIXME("(%p)->(%p)\n", This, p);
365     return E_NOTIMPL;
366 }
367
368 static HRESULT WINAPI HTMLDocument3_put_baseUrl(IHTMLDocument3 *iface, BSTR v)
369 {
370     HTMLDocument *This = HTMLDOC3_THIS(iface);
371     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
372     return E_NOTIMPL;
373 }
374
375 static HRESULT WINAPI HTMLDocument3_get_baseUrl(IHTMLDocument3 *iface, BSTR *p)
376 {
377     HTMLDocument *This = HTMLDOC3_THIS(iface);
378     FIXME("(%p)->(%p)\n", This, p);
379     return E_NOTIMPL;
380 }
381
382 static HRESULT WINAPI HTMLDocument3_get_childNodes(IHTMLDocument3 *iface, IDispatch **p)
383 {
384     HTMLDocument *This = HTMLDOC3_THIS(iface);
385     FIXME("(%p)->(%p)\n", This, p);
386     return E_NOTIMPL;
387 }
388
389 static HRESULT WINAPI HTMLDocument3_put_inheritStyleSheets(IHTMLDocument3 *iface,
390                                                            VARIANT_BOOL v)
391 {
392     HTMLDocument *This = HTMLDOC3_THIS(iface);
393     FIXME("(%p)->()\n", This);
394     return E_NOTIMPL;
395 }
396
397 static HRESULT WINAPI HTMLDocument3_get_inheritStyleSheets(IHTMLDocument3 *iface,
398                                                            VARIANT_BOOL *p)
399 {
400     HTMLDocument *This = HTMLDOC3_THIS(iface);
401     FIXME("(%p)->(%p)\n", This, p);
402     return E_NOTIMPL;
403 }
404
405 static HRESULT WINAPI HTMLDocument3_put_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT v)
406 {
407     HTMLDocument *This = HTMLDOC3_THIS(iface);
408     FIXME("(%p)->()\n", This);
409     return E_NOTIMPL;
410 }
411
412 static HRESULT WINAPI HTMLDocument3_get_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT *p)
413 {
414     HTMLDocument *This = HTMLDOC3_THIS(iface);
415     FIXME("(%p)->(%p)\n", This, p);
416     return E_NOTIMPL;
417 }
418
419 static HRESULT WINAPI HTMLDocument3_getElementsByName(IHTMLDocument3 *iface, BSTR v,
420                                                       IHTMLElementCollection **ppelColl)
421 {
422     HTMLDocument *This = HTMLDOC3_THIS(iface);
423     FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), ppelColl);
424     return E_NOTIMPL;
425 }
426
427
428 static HRESULT WINAPI HTMLDocument3_getElementById(IHTMLDocument3 *iface, BSTR v,
429                                                    IHTMLElement **pel)
430 {
431     HTMLDocument *This = HTMLDOC3_THIS(iface);
432     nsIDOMElement *nselem;
433     HTMLDOMNode *node;
434     nsIDOMNode *nsnode, *nsnode_by_id, *nsnode_by_name;
435     nsIDOMNodeList *nsnode_list;
436     nsAString id_str;
437     nsresult nsres;
438
439     TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
440
441     if(!This->doc_node->nsdoc) {
442         WARN("NULL nsdoc\n");
443         return E_UNEXPECTED;
444     }
445
446     nsAString_Init(&id_str, v);
447     /* get element by id attribute */
448     nsres = nsIDOMHTMLDocument_GetElementById(This->doc_node->nsdoc, &id_str, &nselem);
449     if(FAILED(nsres)) {
450         ERR("GetElementById failed: %08x\n", nsres);
451         nsAString_Finish(&id_str);
452         return E_FAIL;
453     }
454     nsnode_by_id = (nsIDOMNode*)nselem;
455
456     /* get first element by name attribute */
457     nsres = nsIDOMHTMLDocument_GetElementsByName(This->doc_node->nsdoc, &id_str, &nsnode_list);
458     if(FAILED(nsres)) {
459         ERR("getElementsByName failed: %08x\n", nsres);
460         nsAString_Finish(&id_str);
461         if(nsnode_by_id)
462             nsIDOMNode_Release(nsnode_by_id);
463         return E_FAIL;
464     }
465     nsIDOMNodeList_Item(nsnode_list, 0, &nsnode_by_name);
466     nsIDOMNodeList_Release(nsnode_list);
467
468     nsAString_Finish(&id_str);
469
470     if(nsnode_by_name && nsnode_by_id) {
471         nsIDOM3Node *node3;
472         PRUint16 pos;
473
474         nsres = nsIDOMNode_QueryInterface(nsnode_by_name, &IID_nsIDOM3Node, (void**)&node3);
475         if(NS_FAILED(nsres)) {
476             FIXME("failed to get nsIDOM3Node interface: 0x%08x\n", nsres);
477             nsIDOMNode_Release(nsnode_by_name);
478             nsIDOMNode_Release(nsnode_by_id);
479             return E_FAIL;
480         }
481
482         nsres = nsIDOM3Node_CompareDocumentPosition(node3, nsnode_by_id, &pos);
483         nsIDOM3Node_Release(node3);
484         if(NS_FAILED(nsres)) {
485             FIXME("nsIDOM3Node_CompareDocumentPosition failed: 0x%08x\n", nsres);
486             nsIDOMNode_Release(nsnode_by_name);
487             nsIDOMNode_Release(nsnode_by_id);
488             return E_FAIL;
489         }
490
491         TRACE("CompareDocumentPosition gave: 0x%x\n", pos);
492         if(pos & PRECEDING || pos & CONTAINS) {
493             nsnode = nsnode_by_id;
494             nsIDOMNode_Release(nsnode_by_name);
495         }else {
496             nsnode = nsnode_by_name;
497             nsIDOMNode_Release(nsnode_by_id);
498         }
499     }else
500         nsnode = nsnode_by_name ? nsnode_by_name : nsnode_by_id;
501
502     if(nsnode) {
503         node = get_node(This->doc_node, nsnode, TRUE);
504         nsIDOMNode_Release(nsnode);
505
506         IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)pel);
507     }else {
508         *pel = NULL;
509     }
510
511     return S_OK;
512 }
513
514
515 static HRESULT WINAPI HTMLDocument3_getElementsByTagName(IHTMLDocument3 *iface, BSTR v,
516                                                          IHTMLElementCollection **pelColl)
517 {
518     HTMLDocument *This = HTMLDOC3_THIS(iface);
519     nsIDOMNodeList *nslist;
520     nsAString id_str, ns_str;
521     nsresult nsres;
522     static const WCHAR str[] = {'*',0};
523
524     TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pelColl);
525
526     if(!This->doc_node->nsdoc) {
527         WARN("NULL nsdoc\n");
528         return E_UNEXPECTED;
529     }
530
531     nsAString_Init(&id_str, v);
532     nsAString_Init(&ns_str, str);
533     nsres = nsIDOMHTMLDocument_GetElementsByTagNameNS(This->doc_node->nsdoc, &ns_str, &id_str, &nslist);
534     nsAString_Finish(&id_str);
535     nsAString_Finish(&ns_str);
536     if(FAILED(nsres)) {
537         ERR("GetElementByName failed: %08x\n", nsres);
538         return E_FAIL;
539     }
540
541     *pelColl = (IHTMLElementCollection*)create_collection_from_nodelist(This->doc_node, (IUnknown*)HTMLDOC3(This), nslist);
542     nsIDOMNodeList_Release(nslist);
543
544     return S_OK;
545 }
546
547 #undef HTMLDOC3_THIS
548
549 static const IHTMLDocument3Vtbl HTMLDocument3Vtbl = {
550     HTMLDocument3_QueryInterface,
551     HTMLDocument3_AddRef,
552     HTMLDocument3_Release,
553     HTMLDocument3_GetTypeInfoCount,
554     HTMLDocument3_GetTypeInfo,
555     HTMLDocument3_GetIDsOfNames,
556     HTMLDocument3_Invoke,
557     HTMLDocument3_releaseCapture,
558     HTMLDocument3_recalc,
559     HTMLDocument3_createTextNode,
560     HTMLDocument3_get_documentElement,
561     HTMLDocument3_uniqueID,
562     HTMLDocument3_attachEvent,
563     HTMLDocument3_detachEvent,
564     HTMLDocument3_put_onrowsdelete,
565     HTMLDocument3_get_onrowsdelete,
566     HTMLDocument3_put_onrowsinserted,
567     HTMLDocument3_get_onrowsinserted,
568     HTMLDocument3_put_oncellchange,
569     HTMLDocument3_get_oncellchange,
570     HTMLDocument3_put_ondatasetchanged,
571     HTMLDocument3_get_ondatasetchanged,
572     HTMLDocument3_put_ondataavailable,
573     HTMLDocument3_get_ondataavailable,
574     HTMLDocument3_put_ondatasetcomplete,
575     HTMLDocument3_get_ondatasetcomplete,
576     HTMLDocument3_put_onpropertychange,
577     HTMLDocument3_get_onpropertychange,
578     HTMLDocument3_put_dir,
579     HTMLDocument3_get_dir,
580     HTMLDocument3_put_oncontextmenu,
581     HTMLDocument3_get_oncontextmenu,
582     HTMLDocument3_put_onstop,
583     HTMLDocument3_get_onstop,
584     HTMLDocument3_createDocumentFragment,
585     HTMLDocument3_get_parentDocument,
586     HTMLDocument3_put_enableDownload,
587     HTMLDocument3_get_enableDownload,
588     HTMLDocument3_put_baseUrl,
589     HTMLDocument3_get_baseUrl,
590     HTMLDocument3_get_childNodes,
591     HTMLDocument3_put_inheritStyleSheets,
592     HTMLDocument3_get_inheritStyleSheets,
593     HTMLDocument3_put_onbeforeeditfocus,
594     HTMLDocument3_get_onbeforeeditfocus,
595     HTMLDocument3_getElementsByName,
596     HTMLDocument3_getElementById,
597     HTMLDocument3_getElementsByTagName
598 };
599
600 #define HTMLDOC4_THIS(iface) DEFINE_THIS(HTMLDocument, HTMLDocument4, iface)
601
602 static HRESULT WINAPI HTMLDocument4_QueryInterface(IHTMLDocument4 *iface,
603                                                    REFIID riid, void **ppv)
604 {
605     HTMLDocument *This = HTMLDOC4_THIS(iface);
606     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
607 }
608
609 static ULONG WINAPI HTMLDocument4_AddRef(IHTMLDocument4 *iface)
610 {
611     HTMLDocument *This = HTMLDOC4_THIS(iface);
612     return IHTMLDocument2_AddRef(HTMLDOC(This));
613 }
614
615 static ULONG WINAPI HTMLDocument4_Release(IHTMLDocument4 *iface)
616 {
617     HTMLDocument *This = HTMLDOC4_THIS(iface);
618     return IHTMLDocument2_Release(HTMLDOC(This));
619 }
620
621 static HRESULT WINAPI HTMLDocument4_GetTypeInfoCount(IHTMLDocument4 *iface, UINT *pctinfo)
622 {
623     HTMLDocument *This = HTMLDOC4_THIS(iface);
624     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
625 }
626
627 static HRESULT WINAPI HTMLDocument4_GetTypeInfo(IHTMLDocument4 *iface, UINT iTInfo,
628                                                 LCID lcid, ITypeInfo **ppTInfo)
629 {
630     HTMLDocument *This = HTMLDOC4_THIS(iface);
631     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
632 }
633
634 static HRESULT WINAPI HTMLDocument4_GetIDsOfNames(IHTMLDocument4 *iface, REFIID riid,
635                                                 LPOLESTR *rgszNames, UINT cNames,
636                                                 LCID lcid, DISPID *rgDispId)
637 {
638     HTMLDocument *This = HTMLDOC4_THIS(iface);
639     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
640 }
641
642 static HRESULT WINAPI HTMLDocument4_Invoke(IHTMLDocument4 *iface, DISPID dispIdMember,
643                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
644                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
645 {
646     HTMLDocument *This = HTMLDOC4_THIS(iface);
647     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
648             pVarResult, pExcepInfo, puArgErr);
649 }
650
651 static HRESULT WINAPI HTMLDocument4_focus(IHTMLDocument4 *iface)
652 {
653     HTMLDocument *This = HTMLDOC4_THIS(iface);
654     nsIDOMNSHTMLElement *nselem;
655     nsIDOMHTMLElement *nsbody;
656     nsresult nsres;
657
658     TRACE("(%p)->()\n", This);
659
660     nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
661     if(NS_FAILED(nsres) || !nsbody) {
662         ERR("GetBody failed: %08x\n", nsres);
663         return E_FAIL;
664     }
665
666     nsres = nsIDOMHTMLElement_QueryInterface(nsbody, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
667     nsIDOMHTMLElement_Release(nsbody);
668     if(NS_FAILED(nsres)) {
669         ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
670         return E_FAIL;
671     }
672
673     nsres = nsIDOMNSHTMLElement_focus(nselem);
674     nsIDOMNSHTMLElement_Release(nselem);
675     if(NS_FAILED(nsres)) {
676         ERR("Focus failed: %08x\n", nsres);
677         return E_FAIL;
678     }
679
680     return S_OK;
681 }
682
683 static HRESULT WINAPI HTMLDocument4_hasFocus(IHTMLDocument4 *iface, VARIANT_BOOL *pfFocus)
684 {
685     HTMLDocument *This = HTMLDOC4_THIS(iface);
686     FIXME("(%p)->(%p)\n", This, pfFocus);
687     return E_NOTIMPL;
688 }
689
690 static HRESULT WINAPI HTMLDocument4_put_onselectionchange(IHTMLDocument4 *iface, VARIANT v)
691 {
692     HTMLDocument *This = HTMLDOC4_THIS(iface);
693     FIXME("(%p)->(v)\n", This);
694     return E_NOTIMPL;
695 }
696
697 static HRESULT WINAPI HTMLDocument4_get_onselectionchange(IHTMLDocument4 *iface, VARIANT *p)
698 {
699     HTMLDocument *This = HTMLDOC4_THIS(iface);
700     FIXME("(%p)->(%p)\n", This, p);
701     return E_NOTIMPL;
702 }
703
704 static HRESULT WINAPI HTMLDocument4_get_namespace(IHTMLDocument4 *iface, IDispatch **p)
705 {
706     HTMLDocument *This = HTMLDOC4_THIS(iface);
707     FIXME("(%p)->(%p)\n", This, p);
708     return E_NOTIMPL;
709 }
710
711 static HRESULT WINAPI HTMLDocument4_createDocumentFromUrl(IHTMLDocument4 *iface, BSTR bstrUrl,
712         BSTR bstrOptions, IHTMLDocument2 **newDoc)
713 {
714     HTMLDocument *This = HTMLDOC4_THIS(iface);
715     FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(bstrUrl), debugstr_w(bstrOptions), newDoc);
716     return E_NOTIMPL;
717 }
718
719 static HRESULT WINAPI HTMLDocument4_put_media(IHTMLDocument4 *iface, BSTR v)
720 {
721     HTMLDocument *This = HTMLDOC4_THIS(iface);
722     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
723     return E_NOTIMPL;
724 }
725
726 static HRESULT WINAPI HTMLDocument4_get_media(IHTMLDocument4 *iface, BSTR *p)
727 {
728     HTMLDocument *This = HTMLDOC4_THIS(iface);
729     FIXME("(%p)->(%p)\n", This, p);
730     return E_NOTIMPL;
731 }
732
733 static HRESULT WINAPI HTMLDocument4_createEventObject(IHTMLDocument4 *iface,
734         VARIANT *pvarEventObject, IHTMLEventObj **ppEventObj)
735 {
736     HTMLDocument *This = HTMLDOC4_THIS(iface);
737     FIXME("(%p)->(%p %p)\n", This, pvarEventObject, ppEventObj);
738     return E_NOTIMPL;
739 }
740
741 static HRESULT WINAPI HTMLDocument4_fireEvent(IHTMLDocument4 *iface, BSTR bstrEventName,
742         VARIANT *pvarEventObject, VARIANT_BOOL *pfCanceled)
743 {
744     HTMLDocument *This = HTMLDOC4_THIS(iface);
745     FIXME("(%p)->(%s %p %p)\n", This, debugstr_w(bstrEventName), pvarEventObject, pfCanceled);
746     return E_NOTIMPL;
747 }
748
749 static HRESULT WINAPI HTMLDocument4_createRenderStyle(IHTMLDocument4 *iface, BSTR v,
750         IHTMLRenderStyle **ppIHTMLRenderStyle)
751 {
752     HTMLDocument *This = HTMLDOC4_THIS(iface);
753     FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), ppIHTMLRenderStyle);
754     return E_NOTIMPL;
755 }
756
757 static HRESULT WINAPI HTMLDocument4_put_oncontrolselect(IHTMLDocument4 *iface, VARIANT v)
758 {
759     HTMLDocument *This = HTMLDOC4_THIS(iface);
760     FIXME("(%p)->(v)\n", This);
761     return E_NOTIMPL;
762 }
763
764 static HRESULT WINAPI HTMLDocument4_get_oncontrolselect(IHTMLDocument4 *iface, VARIANT *p)
765 {
766     HTMLDocument *This = HTMLDOC4_THIS(iface);
767     FIXME("(%p)->(%p)\n", This, p);
768     return E_NOTIMPL;
769 }
770
771 static HRESULT WINAPI HTMLDocument4_get_URLEncoded(IHTMLDocument4 *iface, BSTR *p)
772 {
773     HTMLDocument *This = HTMLDOC4_THIS(iface);
774     FIXME("(%p)->(%p)\n", This, p);
775     return E_NOTIMPL;
776 }
777
778 #undef HTMLDOC4_THIS
779
780 static const IHTMLDocument4Vtbl HTMLDocument4Vtbl = {
781     HTMLDocument4_QueryInterface,
782     HTMLDocument4_AddRef,
783     HTMLDocument4_Release,
784     HTMLDocument4_GetTypeInfoCount,
785     HTMLDocument4_GetTypeInfo,
786     HTMLDocument4_GetIDsOfNames,
787     HTMLDocument4_Invoke,
788     HTMLDocument4_focus,
789     HTMLDocument4_hasFocus,
790     HTMLDocument4_put_onselectionchange,
791     HTMLDocument4_get_onselectionchange,
792     HTMLDocument4_get_namespace,
793     HTMLDocument4_createDocumentFromUrl,
794     HTMLDocument4_put_media,
795     HTMLDocument4_get_media,
796     HTMLDocument4_createEventObject,
797     HTMLDocument4_fireEvent,
798     HTMLDocument4_createRenderStyle,
799     HTMLDocument4_put_oncontrolselect,
800     HTMLDocument4_get_oncontrolselect,
801     HTMLDocument4_get_URLEncoded
802 };
803
804 void HTMLDocument_HTMLDocument3_Init(HTMLDocument *This)
805 {
806     This->lpHTMLDocument3Vtbl = &HTMLDocument3Vtbl;
807     This->lpHTMLDocument4Vtbl = &HTMLDocument4Vtbl;
808 }