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