cryptui: Fix UI display.
[wine] / dlls / mshtml / htmldoc.c
1 /*
2  * Copyright 2005 Jacek Caban
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 #include "perhist.h"
31
32 #include "wine/debug.h"
33
34 #include "mshtml_private.h"
35 #include "htmlevent.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38
39 #define HTMLDOC_THIS(iface) DEFINE_THIS(HTMLDocument, HTMLDocument2, iface)
40
41 static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppvObject)
42 {
43     HTMLDocument *This = HTMLDOC_THIS(iface);
44
45     *ppvObject = NULL;
46     if(IsEqualGUID(&IID_IUnknown, riid)) {
47         TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppvObject);
48         *ppvObject = HTMLDOC(This);
49     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
50         TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppvObject);
51         *ppvObject = DISPATCHEX(This);
52     }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
53         TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppvObject);
54         *ppvObject = DISPATCHEX(This);
55     }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
56         TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppvObject);
57         *ppvObject = HTMLDOC(This);
58     }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
59         TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppvObject);
60         *ppvObject = HTMLDOC(This);
61     }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
62         TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppvObject);
63         *ppvObject = HTMLDOC3(This);
64     }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
65         TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppvObject);
66         *ppvObject = HTMLDOC4(This);
67     }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
68         TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppvObject);
69         *ppvObject = HTMLDOC5(This);
70     }else if(IsEqualGUID(&IID_IPersist, riid)) {
71         TRACE("(%p)->(IID_IPersist, %p)\n", This, ppvObject);
72         *ppvObject = PERSIST(This);
73     }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
74         TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppvObject);
75         *ppvObject = PERSISTMON(This);
76     }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
77         TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppvObject);
78         *ppvObject = PERSISTFILE(This);
79     }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
80         TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppvObject);
81         *ppvObject = MONPROP(This);
82     }else if(IsEqualGUID(&IID_IOleObject, riid)) {
83         TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppvObject);
84         *ppvObject = OLEOBJ(This);
85     }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
86         TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppvObject);
87         *ppvObject = OLEDOC(This);
88     }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
89         TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppvObject);
90         *ppvObject = DOCVIEW(This);
91     }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
92         TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppvObject);
93         *ppvObject = ACTOBJ(This);
94     }else if(IsEqualGUID(&IID_IViewObject, riid)) {
95         TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppvObject);
96         *ppvObject = VIEWOBJ(This);
97     }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
98         TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppvObject);
99         *ppvObject = VIEWOBJ2(This);
100     }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
101         TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppvObject);
102         *ppvObject = OLEWIN(This);
103     }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
104         TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppvObject);
105         *ppvObject = INPLACEOBJ(This);
106     }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
107         TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppvObject);
108         *ppvObject = INPLACEWIN(This);
109     }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
110         TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppvObject);
111         *ppvObject = SERVPROV(This);
112     }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
113         TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppvObject);
114         *ppvObject = CMDTARGET(This);
115     }else if(IsEqualGUID(&IID_IOleControl, riid)) {
116         TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppvObject);
117         *ppvObject = CONTROL(This);
118     }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
119         TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppvObject);
120         *ppvObject = HLNKTARGET(This);
121     }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
122         TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppvObject);
123         *ppvObject = CONPTCONT(&This->cp_container);
124     }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
125         TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppvObject);
126         *ppvObject = PERSTRINIT(This);
127     }else if(IsEqualGUID(&IID_ICustomDoc, riid)) {
128         TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppvObject);
129         *ppvObject = CUSTOMDOC(This);
130     }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
131         TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppvObject);
132         *ppvObject = HTMLDOC(This);
133     }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
134         TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppvObject);
135         *ppvObject = SUPPERRINFO(This);
136     }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
137         TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppvObject);
138         *ppvObject = PERSISTHIST(This);
139     }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
140         FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppvObject);
141         return E_NOINTERFACE;
142     }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
143         TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppvObject);
144         return E_NOINTERFACE;
145     }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
146         TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppvObject);
147         return E_NOINTERFACE;
148     }else if(IsEqualGUID(&IID_IMarshal, riid)) {
149         TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppvObject);
150         return E_NOINTERFACE;
151     }else if(dispex_query_interface(&This->dispex, riid, ppvObject)) {
152         return *ppvObject ? S_OK : E_NOINTERFACE;
153     }
154
155     if(*ppvObject) {
156         IHTMLDocument2_AddRef(iface);
157         return S_OK;
158     }
159
160     FIXME("(%p)->(%s %p) interface not supported\n", This, debugstr_guid(riid), ppvObject);
161     return E_NOINTERFACE;
162 }
163
164 static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
165 {
166     HTMLDocument *This = HTMLDOC_THIS(iface);
167     ULONG ref = InterlockedIncrement(&This->ref);
168     TRACE("(%p) ref = %u\n", This, ref);
169     return ref;
170 }
171
172 static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
173 {
174     HTMLDocument *This = HTMLDOC_THIS(iface);
175     ULONG ref = InterlockedDecrement(&This->ref);
176
177     TRACE("(%p) ref = %u\n", This, ref);
178
179     if(!ref) {
180         remove_doc_tasks(This);
181         release_script_hosts(This);
182
183         if(This->client)
184             IOleObject_SetClientSite(OLEOBJ(This), NULL);
185         if(This->in_place_active)
186             IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This));
187         if(This->ipsite)
188             IOleDocumentView_SetInPlaceSite(DOCVIEW(This), NULL);
189         if(This->undomgr)
190             IOleUndoManager_Release(This->undomgr);
191
192         set_document_bscallback(This, NULL);
193         set_current_mon(This, NULL);
194
195         if(This->tooltips_hwnd)
196             DestroyWindow(This->tooltips_hwnd);
197         if(This->hwnd)
198             DestroyWindow(This->hwnd);
199
200         if(This->option_factory) {
201             This->option_factory->doc = NULL;
202             IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
203         }
204
205         if(This->location)
206             This->location->doc = NULL;
207
208         if(This->window)
209             IHTMLWindow2_Release(HTMLWINDOW2(This->window));
210
211         if(This->event_target)
212             release_event_target(This->event_target);
213
214         heap_free(This->mime);
215         detach_selection(This);
216         detach_ranges(This);
217         release_nodes(This);
218
219         ConnectionPointContainer_Destroy(&This->cp_container);
220
221         if(This->nsdoc) {
222             remove_mutation_observer(This->nscontainer, This->nsdoc);
223             nsIDOMHTMLDocument_Release(This->nsdoc);
224         }
225         if(This->nscontainer)
226             NSContainer_Release(This->nscontainer);
227
228         heap_free(This);
229     }
230
231     return ref;
232 }
233
234 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
235 {
236     HTMLDocument *This = HTMLDOC_THIS(iface);
237
238     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
239 }
240
241 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
242                                                 LCID lcid, ITypeInfo **ppTInfo)
243 {
244     HTMLDocument *This = HTMLDOC_THIS(iface);
245
246     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
247 }
248
249 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
250                                                 LPOLESTR *rgszNames, UINT cNames,
251                                                 LCID lcid, DISPID *rgDispId)
252 {
253     HTMLDocument *This = HTMLDOC_THIS(iface);
254
255     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
256 }
257
258 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
259                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
260                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
261 {
262     HTMLDocument *This = HTMLDOC_THIS(iface);
263
264     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
265             pVarResult, pExcepInfo, puArgErr);
266 }
267
268 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
269 {
270     HTMLDocument *This = HTMLDOC_THIS(iface);
271
272     TRACE("(%p)->(%p)\n", This, p);
273
274     *p = (IDispatch*)HTMLWINDOW2(This->window);
275     IDispatch_AddRef(*p);
276     return S_OK;
277 }
278
279 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
280 {
281     HTMLDocument *This = HTMLDOC_THIS(iface);
282     nsIDOMElement *nselem = NULL;
283     nsresult nsres;
284
285     TRACE("(%p)->(%p)\n", This, p);
286
287     if(!This->nsdoc) {
288         WARN("NULL nsdoc\n");
289         return E_UNEXPECTED;
290     }
291
292     nsres = nsIDOMHTMLDocument_GetDocumentElement(This->nsdoc, &nselem);
293     if(NS_FAILED(nsres)) {
294         ERR("GetDocumentElement failed: %08x\n", nsres);
295         return E_FAIL;
296     }
297
298     if(nselem) {
299         *p = create_all_collection(get_node(This, (nsIDOMNode*)nselem, TRUE), TRUE);
300         nsIDOMElement_Release(nselem);
301     }else {
302         *p = NULL;
303     }
304
305     return S_OK;
306 }
307
308 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
309 {
310     HTMLDocument *This = HTMLDOC_THIS(iface);
311     nsIDOMHTMLElement *nsbody = NULL;
312     HTMLDOMNode *node;
313     nsresult nsres;
314
315     TRACE("(%p)->(%p)\n", This, p);
316
317     if(!This->nsdoc) {
318         WARN("NULL nsdoc\n");
319         return E_UNEXPECTED;
320     }
321
322     nsres = nsIDOMHTMLDocument_GetBody(This->nsdoc, &nsbody);
323     if(NS_FAILED(nsres)) {
324         TRACE("Could not get body: %08x\n", nsres);
325         return E_UNEXPECTED;
326     }
327
328     if(nsbody) {
329         node = get_node(This, (nsIDOMNode*)nsbody, TRUE);
330         nsIDOMHTMLElement_Release(nsbody);
331
332         IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)p);
333     }else {
334         *p = NULL;
335     }
336
337     TRACE("*p = %p\n", *p);
338     return S_OK;
339 }
340
341 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
342 {
343     HTMLDocument *This = HTMLDOC_THIS(iface);
344     FIXME("(%p)->(%p)\n", This, p);
345     return E_NOTIMPL;
346 }
347
348 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
349 {
350     HTMLDocument *This = HTMLDOC_THIS(iface);
351     nsIDOMHTMLCollection *nscoll = NULL;
352     nsresult nsres;
353
354     TRACE("(%p)->(%p)\n", This, p);
355
356     if(!p)
357         return E_INVALIDARG;
358
359     *p = NULL;
360
361     if(!This->nsdoc) {
362         WARN("NULL nsdoc\n");
363         return E_UNEXPECTED;
364     }
365
366     nsres = nsIDOMHTMLDocument_GetImages(This->nsdoc, &nscoll);
367     if(NS_FAILED(nsres)) {
368         ERR("GetImages failed: %08x\n", nsres);
369         return E_FAIL;
370     }
371
372     if(nscoll) {
373         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
374         nsIDOMElement_Release(nscoll);
375     }
376
377     return S_OK;
378 }
379
380 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
381 {
382     HTMLDocument *This = HTMLDOC_THIS(iface);
383     nsIDOMHTMLCollection *nscoll = NULL;
384     nsresult nsres;
385
386     TRACE("(%p)->(%p)\n", This, p);
387
388     if(!p)
389         return E_INVALIDARG;
390
391     *p = NULL;
392
393     if(!This->nsdoc) {
394         WARN("NULL nsdoc\n");
395         return E_UNEXPECTED;
396     }
397
398     nsres = nsIDOMHTMLDocument_GetApplets(This->nsdoc, &nscoll);
399     if(NS_FAILED(nsres)) {
400         ERR("GetApplets failed: %08x\n", nsres);
401         return E_FAIL;
402     }
403
404     if(nscoll) {
405         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
406         nsIDOMElement_Release(nscoll);
407     }
408
409     return S_OK;
410 }
411
412 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
413 {
414     HTMLDocument *This = HTMLDOC_THIS(iface);
415     nsIDOMHTMLCollection *nscoll = NULL;
416     nsresult nsres;
417
418     TRACE("(%p)->(%p)\n", This, p);
419
420     if(!p)
421         return E_INVALIDARG;
422
423     *p = NULL;
424
425     if(!This->nsdoc) {
426         WARN("NULL nsdoc\n");
427         return E_UNEXPECTED;
428     }
429
430     nsres = nsIDOMHTMLDocument_GetLinks(This->nsdoc, &nscoll);
431     if(NS_FAILED(nsres)) {
432         ERR("GetLinks failed: %08x\n", nsres);
433         return E_FAIL;
434     }
435
436     if(nscoll) {
437         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
438         nsIDOMElement_Release(nscoll);
439     }
440
441     return S_OK;
442 }
443
444 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
445 {
446     HTMLDocument *This = HTMLDOC_THIS(iface);
447     nsIDOMHTMLCollection *nscoll = NULL;
448     nsresult nsres;
449
450     TRACE("(%p)->(%p)\n", This, p);
451
452     if(!p)
453         return E_INVALIDARG;
454
455     *p = NULL;
456
457     if(!This->nsdoc) {
458         WARN("NULL nsdoc\n");
459         return E_UNEXPECTED;
460     }
461
462     nsres = nsIDOMHTMLDocument_GetForms(This->nsdoc, &nscoll);
463     if(NS_FAILED(nsres)) {
464         ERR("GetForms failed: %08x\n", nsres);
465         return E_FAIL;
466     }
467
468     if(nscoll) {
469         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
470         nsIDOMElement_Release(nscoll);
471     }
472
473     return S_OK;
474 }
475
476 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
477 {
478     HTMLDocument *This = HTMLDOC_THIS(iface);
479     nsIDOMHTMLCollection *nscoll = NULL;
480     nsresult nsres;
481
482     TRACE("(%p)->(%p)\n", This, p);
483
484     if(!p)
485         return E_INVALIDARG;
486
487     *p = NULL;
488
489     if(!This->nsdoc) {
490         WARN("NULL nsdoc\n");
491         return E_UNEXPECTED;
492     }
493
494     nsres = nsIDOMHTMLDocument_GetAnchors(This->nsdoc, &nscoll);
495     if(NS_FAILED(nsres)) {
496         ERR("GetAnchors failed: %08x\n", nsres);
497         return E_FAIL;
498     }
499
500     if(nscoll) {
501         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
502         nsIDOMElement_Release(nscoll);
503     }
504
505     return S_OK;
506 }
507
508 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
509 {
510     HTMLDocument *This = HTMLDOC_THIS(iface);
511     nsAString nsstr;
512     nsresult nsres;
513
514     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
515
516     if(!This->nsdoc) {
517         WARN("NULL nsdoc\n");
518         return E_UNEXPECTED;
519     }
520
521     nsAString_Init(&nsstr, v);
522     nsres = nsIDOMHTMLDocument_SetTitle(This->nsdoc, &nsstr);
523     nsAString_Finish(&nsstr);
524     if(NS_FAILED(nsres))
525         ERR("SetTitle failed: %08x\n", nsres);
526
527     return S_OK;
528 }
529
530 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
531 {
532     HTMLDocument *This = HTMLDOC_THIS(iface);
533     const PRUnichar *ret;
534     nsAString nsstr;
535     nsresult nsres;
536
537     TRACE("(%p)->(%p)\n", This, p);
538
539     if(!This->nsdoc) {
540         WARN("NULL nsdoc\n");
541         return E_UNEXPECTED;
542     }
543
544
545     nsAString_Init(&nsstr, NULL);
546     nsres = nsIDOMHTMLDocument_GetTitle(This->nsdoc, &nsstr);
547     if (NS_SUCCEEDED(nsres)) {
548         nsAString_GetData(&nsstr, &ret);
549         *p = SysAllocString(ret);
550     }
551     nsAString_Finish(&nsstr);
552
553     if(NS_FAILED(nsres)) {
554         ERR("GetTitle failed: %08x\n", nsres);
555         return E_FAIL;
556     }
557
558     return S_OK;
559 }
560
561 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
562 {
563     HTMLDocument *This = HTMLDOC_THIS(iface);
564     FIXME("(%p)->(%p)\n", This, p);
565     return E_NOTIMPL;
566 }
567
568 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
569 {
570     HTMLDocument *This = HTMLDOC_THIS(iface);
571     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
572     return E_NOTIMPL;
573 }
574
575 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
576 {
577     HTMLDocument *This = HTMLDOC_THIS(iface);
578     static WCHAR szOff[] = {'O','f','f',0};
579     FIXME("(%p)->(%p) always returning Off\n", This, p);
580
581     if(!p)
582         return E_INVALIDARG;
583
584     *p = SysAllocString(szOff);
585
586     return S_OK;
587 }
588
589 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
590 {
591     HTMLDocument *This = HTMLDOC_THIS(iface);
592     nsISelection *nsselection = NULL;
593
594     TRACE("(%p)->(%p)\n", This, p);
595
596     if(This->nscontainer) {
597         nsIDOMWindow *dom_window = NULL;
598
599         nsIWebBrowser_GetContentDOMWindow(This->nscontainer->webbrowser, &dom_window);
600         if(dom_window) {
601             nsIDOMWindow_GetSelection(dom_window, &nsselection);
602             nsIDOMWindow_Release(dom_window);
603         }
604     }
605
606     *p = HTMLSelectionObject_Create(This, nsselection);
607     return S_OK;
608 }
609
610 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
611 {
612     HTMLDocument *This = HTMLDOC_THIS(iface);
613
614     static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
615     static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
616     static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
617     static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
618     static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
619
620     static const LPCWSTR readystate_str[] = {
621         wszUninitialized,
622         wszLoading,
623         wszLoaded,
624         wszInteractive,
625         wszComplete
626     };
627
628     TRACE("(%p)->(%p)\n", iface, p);
629
630     if(!p)
631         return E_POINTER;
632
633     *p = SysAllocString(readystate_str[This->readystate]);
634     return S_OK;
635 }
636
637 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
638 {
639     HTMLDocument *This = HTMLDOC_THIS(iface);
640     FIXME("(%p)->(%p)\n", This, p);
641     return E_NOTIMPL;
642 }
643
644 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
645 {
646     HTMLDocument *This = HTMLDOC_THIS(iface);
647     FIXME("(%p)->(%p)\n", This, p);
648     return E_NOTIMPL;
649 }
650
651 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
652 {
653     HTMLDocument *This = HTMLDOC_THIS(iface);
654     FIXME("(%p)->(%p)\n", This, p);
655     return E_NOTIMPL;
656 }
657
658 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
659 {
660     HTMLDocument *This = HTMLDOC_THIS(iface);
661     FIXME("(%p)\n", This);
662     return E_NOTIMPL;
663 }
664
665 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
666 {
667     HTMLDocument *This = HTMLDOC_THIS(iface);
668     FIXME("(%p)->(%p)\n", This, p);
669     return E_NOTIMPL;
670 }
671
672 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
673 {
674     HTMLDocument *This = HTMLDOC_THIS(iface);
675     FIXME("(%p)\n", This);
676     return E_NOTIMPL;
677 }
678
679 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
680 {
681     HTMLDocument *This = HTMLDOC_THIS(iface);
682     FIXME("(%p)->(%p)\n", This, p);
683     return E_NOTIMPL;
684 }
685
686 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
687 {
688     HTMLDocument *This = HTMLDOC_THIS(iface);
689     FIXME("(%p)\n", This);
690     return E_NOTIMPL;
691 }
692
693 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
694 {
695     HTMLDocument *This = HTMLDOC_THIS(iface);
696     FIXME("(%p)->(%p)\n", This, p);
697     return E_NOTIMPL;
698 }
699
700 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
701 {
702     HTMLDocument *This = HTMLDOC_THIS(iface);
703     FIXME("(%p)->()\n", This);
704     return E_NOTIMPL;
705 }
706
707 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
708 {
709     HTMLDocument *This = HTMLDOC_THIS(iface);
710     FIXME("(%p)->(%p)\n", This, p);
711     return E_NOTIMPL;
712 }
713
714 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
715 {
716     HTMLDocument *This = HTMLDOC_THIS(iface);
717     FIXME("(%p)\n", This);
718     return E_NOTIMPL;
719 }
720
721 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
722 {
723     HTMLDocument *This = HTMLDOC_THIS(iface);
724     FIXME("(%p)->(%p)\n", This, p);
725     return E_NOTIMPL;
726 }
727
728 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
729 {
730     HTMLDocument *This = HTMLDOC_THIS(iface);
731     FIXME("(%p)->(%p)\n", This, p);
732     return E_NOTIMPL;
733 }
734
735 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
736 {
737     HTMLDocument *This = HTMLDOC_THIS(iface);
738
739     TRACE("(%p)->(%p)\n", This, p);
740
741     if(This->location)
742         IHTMLLocation_AddRef(HTMLLOCATION(This->location));
743     else
744         This->location = HTMLLocation_Create(This);
745
746     *p = HTMLLOCATION(This->location);
747     return S_OK;
748 }
749
750 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
751 {
752     HTMLDocument *This = HTMLDOC_THIS(iface);
753     FIXME("(%p)->(%p)\n", This, p);
754     return E_NOTIMPL;
755 }
756
757 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
758 {
759     HTMLDocument *This = HTMLDOC_THIS(iface);
760     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
761     return E_NOTIMPL;
762 }
763
764 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
765 {
766     HTMLDocument *This = HTMLDOC_THIS(iface);
767
768     static const WCHAR about_blank_url[] =
769         {'a','b','o','u','t',':','b','l','a','n','k',0};
770
771     TRACE("(%p)->(%p)\n", iface, p);
772
773     *p = SysAllocString(This->url ? This->url : about_blank_url);
774     return S_OK;
775 }
776
777 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
778 {
779     HTMLDocument *This = HTMLDOC_THIS(iface);
780     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
781     return E_NOTIMPL;
782 }
783
784 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
785 {
786     HTMLDocument *This = HTMLDOC_THIS(iface);
787     FIXME("(%p)->(%p)\n", This, p);
788     return E_NOTIMPL;
789 }
790
791 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
792 {
793     HTMLDocument *This = HTMLDOC_THIS(iface);
794     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
795     return E_NOTIMPL;
796 }
797
798 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
799 {
800     HTMLDocument *This = HTMLDOC_THIS(iface);
801     FIXME("(%p)->(%p)\n", This, p);
802     return E_NOTIMPL;
803 }
804
805 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
806 {
807     HTMLDocument *This = HTMLDOC_THIS(iface);
808     FIXME("(%p)->(%x)\n", This, v);
809     return E_NOTIMPL;
810 }
811
812 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
813 {
814     HTMLDocument *This = HTMLDOC_THIS(iface);
815     FIXME("(%p)->(%p)\n", This, p);
816     return E_NOTIMPL;
817 }
818
819 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
820 {
821     HTMLDocument *This = HTMLDOC_THIS(iface);
822     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
823     return E_NOTIMPL;
824 }
825
826 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
827 {
828     HTMLDocument *This = HTMLDOC_THIS(iface);
829     FIXME("(%p)->(%p)\n", This, p);
830     return E_NOTIMPL;
831 }
832
833 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
834 {
835     HTMLDocument *This = HTMLDOC_THIS(iface);
836     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
837     return E_NOTIMPL;
838 }
839
840 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
841 {
842     HTMLDocument *This = HTMLDOC_THIS(iface);
843     FIXME("(%p)->(%p)\n", This, p);
844     return E_NOTIMPL;
845 }
846
847 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
848 {
849     HTMLDocument *This = HTMLDOC_THIS(iface);
850     FIXME("(%p)->(%p)\n", This, p);
851     return E_NOTIMPL;
852 }
853
854 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
855 {
856     HTMLDocument *This = HTMLDOC_THIS(iface);
857     FIXME("(%p)->(%p)\n", This, p);
858     return E_NOTIMPL;
859 }
860
861 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
862 {
863     HTMLDocument *This = HTMLDOC_THIS(iface);
864     FIXME("(%p)->(%p)\n", This, p);
865     return E_NOTIMPL;
866 }
867
868 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
869 {
870     HTMLDocument *This = HTMLDOC_THIS(iface);
871     FIXME("(%p)->(%p)\n", This, p);
872     return E_NOTIMPL;
873 }
874
875 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
876 {
877     HTMLDocument *This = HTMLDOC_THIS(iface);
878     FIXME("(%p)->(%p)\n", This, p);
879     return E_NOTIMPL;
880 }
881
882 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
883 {
884     HTMLDocument *This = HTMLDOC_THIS(iface);
885     FIXME("(%p)->(%p)\n", This, p);
886     return E_NOTIMPL;
887 }
888
889 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
890 {
891     HTMLDocument *This = HTMLDOC_THIS(iface);
892     FIXME("(%p)->(%p)\n", This, p);
893     return E_NOTIMPL;
894 }
895
896 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
897 {
898     HTMLDocument *This = HTMLDOC_THIS(iface);
899     FIXME("(%p)->(%p)\n", This, p);
900     return E_NOTIMPL;
901 }
902
903 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
904 {
905     HTMLDocument *This = HTMLDOC_THIS(iface);
906     nsAString nsstr;
907     VARIANT *var;
908     ULONG i;
909     nsresult nsres;
910     HRESULT hres;
911
912     TRACE("(%p)->(%p)\n", iface, psarray);
913
914     if(!This->nsdoc) {
915         WARN("NULL nsdoc\n");
916         return E_UNEXPECTED;
917     }
918
919     if(psarray->cDims != 1) {
920         FIXME("cDims=%d\n", psarray->cDims);
921         return E_INVALIDARG;
922     }
923
924     hres = SafeArrayAccessData(psarray, (void**)&var);
925     if(FAILED(hres)) {
926         WARN("SafeArrayAccessData failed: %08x\n", hres);
927         return hres;
928     }
929
930     nsAString_Init(&nsstr, NULL);
931
932     for(i=0; i < psarray->rgsabound[0].cElements; i++) {
933         if(V_VT(var+i) == VT_BSTR) {
934             nsAString_SetData(&nsstr, V_BSTR(var+i));
935             nsres = nsIDOMHTMLDocument_Write(This->nsdoc, &nsstr);
936             if(NS_FAILED(nsres))
937                 ERR("Write failed: %08x\n", nsres);
938         }else {
939             FIXME("vt=%d\n", V_VT(var+i));
940         }
941     }
942
943     nsAString_Finish(&nsstr);
944     SafeArrayUnaccessData(psarray);
945
946     return S_OK;
947 }
948
949 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
950 {
951     HTMLDocument *This = HTMLDOC_THIS(iface);
952     FIXME("(%p)->(%p)\n", This, psarray);
953     return E_NOTIMPL;
954 }
955
956 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
957                         VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
958 {
959     HTMLDocument *This = HTMLDOC_THIS(iface);
960     nsresult nsres;
961
962     static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
963
964     TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
965           debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
966
967     if(!This->nsdoc) {
968         ERR("!nsdoc\n");
969         return E_NOTIMPL;
970     }
971
972     if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
973        || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
974         FIXME("unsupported args\n");
975
976     nsres = nsIDOMHTMLDocument_Open(This->nsdoc);
977     if(NS_FAILED(nsres)) {
978         ERR("Open failed: %08x\n", nsres);
979         return E_FAIL;
980     }
981
982     *pomWindowResult = (IDispatch*)HTMLWINDOW2(This->window);
983     IHTMLWindow2_AddRef(HTMLWINDOW2(This->window));
984     return S_OK;
985 }
986
987 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
988 {
989     HTMLDocument *This = HTMLDOC_THIS(iface);
990     nsresult nsres;
991
992     TRACE("(%p)\n", This);
993
994     if(!This->nsdoc) {
995         ERR("!nsdoc\n");
996         return E_NOTIMPL;
997     }
998
999     nsres = nsIDOMHTMLDocument_Close(This->nsdoc);
1000     if(NS_FAILED(nsres)) {
1001         ERR("Close failed: %08x\n", nsres);
1002         return E_FAIL;
1003     }
1004
1005     return S_OK;
1006 }
1007
1008 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
1009 {
1010     HTMLDocument *This = HTMLDOC_THIS(iface);
1011     FIXME("(%p)\n", This);
1012     return E_NOTIMPL;
1013 }
1014
1015 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
1016                                                         VARIANT_BOOL *pfRet)
1017 {
1018     HTMLDocument *This = HTMLDOC_THIS(iface);
1019     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1020     return E_NOTIMPL;
1021 }
1022
1023 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
1024                                                         VARIANT_BOOL *pfRet)
1025 {
1026     HTMLDocument *This = HTMLDOC_THIS(iface);
1027     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1028     return E_NOTIMPL;
1029 }
1030
1031 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
1032                                                         VARIANT_BOOL *pfRet)
1033 {
1034     HTMLDocument *This = HTMLDOC_THIS(iface);
1035     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1036     return E_NOTIMPL;
1037 }
1038
1039 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
1040                                                         VARIANT_BOOL *pfRet)
1041 {
1042     HTMLDocument *This = HTMLDOC_THIS(iface);
1043     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1044     return E_NOTIMPL;
1045 }
1046
1047 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
1048                                                         BSTR *pfRet)
1049 {
1050     HTMLDocument *This = HTMLDOC_THIS(iface);
1051     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1052     return E_NOTIMPL;
1053 }
1054
1055 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
1056                                                         VARIANT *pfRet)
1057 {
1058     HTMLDocument *This = HTMLDOC_THIS(iface);
1059     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1060     return E_NOTIMPL;
1061 }
1062
1063 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
1064                                 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1065 {
1066     HTMLDocument *This = HTMLDOC_THIS(iface);
1067     FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
1068     return E_NOTIMPL;
1069 }
1070
1071 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
1072                                                         VARIANT_BOOL *pfRet)
1073 {
1074     HTMLDocument *This = HTMLDOC_THIS(iface);
1075     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1076     return E_NOTIMPL;
1077 }
1078
1079 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1080                                                  IHTMLElement **newElem)
1081 {
1082     HTMLDocument *This = HTMLDOC_THIS(iface);
1083     nsIDOMElement *nselem;
1084     HTMLElement *elem;
1085     nsAString tag_str;
1086     nsresult nsres;
1087
1088     TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1089
1090     if(!This->nsdoc) {
1091         WARN("NULL nsdoc\n");
1092         return E_UNEXPECTED;
1093     }
1094
1095     nsAString_Init(&tag_str, eTag);
1096     nsres = nsIDOMDocument_CreateElement(This->nsdoc, &tag_str, &nselem);
1097     nsAString_Finish(&tag_str);
1098     if(NS_FAILED(nsres)) {
1099         ERR("CreateElement failed: %08x\n", nsres);
1100         return E_FAIL;
1101     }
1102
1103     elem = HTMLElement_Create(This, (nsIDOMNode*)nselem, TRUE);
1104     nsIDOMElement_Release(nselem);
1105
1106     *newElem = HTMLELEM(elem);
1107     IHTMLElement_AddRef(HTMLELEM(elem));
1108     return S_OK;
1109 }
1110
1111 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1112 {
1113     HTMLDocument *This = HTMLDOC_THIS(iface);
1114     FIXME("(%p)\n", This);
1115     return E_NOTIMPL;
1116 }
1117
1118 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1119 {
1120     HTMLDocument *This = HTMLDOC_THIS(iface);
1121     FIXME("(%p)->(%p)\n", This, p);
1122     return E_NOTIMPL;
1123 }
1124
1125 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1126 {
1127     HTMLDocument *This = HTMLDOC_THIS(iface);
1128     FIXME("(%p)\n", This);
1129     return E_NOTIMPL;
1130 }
1131
1132 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1133 {
1134     HTMLDocument *This = HTMLDOC_THIS(iface);
1135     FIXME("(%p)->(%p)\n", This, p);
1136     return E_NOTIMPL;
1137 }
1138
1139 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1140 {
1141     HTMLDocument *This = HTMLDOC_THIS(iface);
1142     FIXME("(%p)\n", This);
1143     return E_NOTIMPL;
1144 }
1145
1146 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1147 {
1148     HTMLDocument *This = HTMLDOC_THIS(iface);
1149     FIXME("(%p)->(%p)\n", This, p);
1150     return E_NOTIMPL;
1151 }
1152
1153 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1154 {
1155     HTMLDocument *This = HTMLDOC_THIS(iface);
1156
1157     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1158
1159     return set_doc_event(This, EVENTID_KEYUP, &v);
1160 }
1161
1162 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1163 {
1164     HTMLDocument *This = HTMLDOC_THIS(iface);
1165
1166     TRACE("(%p)->(%p)\n", This, p);
1167
1168     return get_doc_event(This, EVENTID_KEYUP, p);
1169 }
1170
1171 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1172 {
1173     HTMLDocument *This = HTMLDOC_THIS(iface);
1174
1175     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1176
1177     return set_doc_event(This, EVENTID_KEYDOWN, &v);
1178 }
1179
1180 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1181 {
1182     HTMLDocument *This = HTMLDOC_THIS(iface);
1183
1184     TRACE("(%p)->(%p)\n", This, p);
1185
1186     return get_doc_event(This, EVENTID_KEYDOWN, p);
1187 }
1188
1189 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1190 {
1191     HTMLDocument *This = HTMLDOC_THIS(iface);
1192     FIXME("(%p)\n", This);
1193     return E_NOTIMPL;
1194 }
1195
1196 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1197 {
1198     HTMLDocument *This = HTMLDOC_THIS(iface);
1199     FIXME("(%p)->(%p)\n", This, p);
1200     return E_NOTIMPL;
1201 }
1202
1203 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1204 {
1205     HTMLDocument *This = HTMLDOC_THIS(iface);
1206     FIXME("(%p)\n", This);
1207     return E_NOTIMPL;
1208 }
1209
1210 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1211 {
1212     HTMLDocument *This = HTMLDOC_THIS(iface);
1213     FIXME("(%p)->(%p)\n", This, p);
1214     return E_NOTIMPL;
1215 }
1216
1217 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1218 {
1219     HTMLDocument *This = HTMLDOC_THIS(iface);
1220     FIXME("(%p)\n", This);
1221     return E_NOTIMPL;
1222 }
1223
1224 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1225 {
1226     HTMLDocument *This = HTMLDOC_THIS(iface);
1227     FIXME("(%p)->(%p)\n", This, p);
1228     return E_NOTIMPL;
1229 }
1230
1231 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1232 {
1233     HTMLDocument *This = HTMLDOC_THIS(iface);
1234     FIXME("(%p)\n", This);
1235     return E_NOTIMPL;
1236 }
1237
1238 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1239 {
1240     HTMLDocument *This = HTMLDOC_THIS(iface);
1241     FIXME("(%p)->(%p)\n", This, p);
1242     return E_NOTIMPL;
1243 }
1244
1245 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1246 {
1247     HTMLDocument *This = HTMLDOC_THIS(iface);
1248     FIXME("(%p)\n", This);
1249     return E_NOTIMPL;
1250 }
1251
1252 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1253 {
1254     HTMLDocument *This = HTMLDOC_THIS(iface);
1255     FIXME("(%p)->(%p)\n", This, p);
1256     return E_NOTIMPL;
1257 }
1258
1259 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1260 {
1261     HTMLDocument *This = HTMLDOC_THIS(iface);
1262
1263     TRACE("(%p)\n", This);
1264
1265     return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1266 }
1267
1268 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1269 {
1270     HTMLDocument *This = HTMLDOC_THIS(iface);
1271
1272     TRACE("(%p)->(%p)\n", This, p);
1273
1274     return get_doc_event(This, EVENTID_MOUSEOVER, p);
1275 }
1276
1277 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1278 {
1279     HTMLDocument *This = HTMLDOC_THIS(iface);
1280     FIXME("(%p)\n", This);
1281     return E_NOTIMPL;
1282 }
1283
1284 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1285 {
1286     HTMLDocument *This = HTMLDOC_THIS(iface);
1287     FIXME("(%p)->(%p)\n", This, p);
1288     return E_NOTIMPL;
1289 }
1290
1291 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1292 {
1293     HTMLDocument *This = HTMLDOC_THIS(iface);
1294     FIXME("(%p)\n", This);
1295     return E_NOTIMPL;
1296 }
1297
1298 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1299 {
1300     HTMLDocument *This = HTMLDOC_THIS(iface);
1301     FIXME("(%p)->(%p)\n", This, p);
1302     return E_NOTIMPL;
1303 }
1304
1305 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1306 {
1307     HTMLDocument *This = HTMLDOC_THIS(iface);
1308     FIXME("(%p)\n", This);
1309     return E_NOTIMPL;
1310 }
1311
1312 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1313 {
1314     HTMLDocument *This = HTMLDOC_THIS(iface);
1315     FIXME("(%p)->(%p)\n", This, p);
1316     return E_NOTIMPL;
1317 }
1318
1319 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1320 {
1321     HTMLDocument *This = HTMLDOC_THIS(iface);
1322     FIXME("(%p)\n", This);
1323     return E_NOTIMPL;
1324 }
1325
1326 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1327 {
1328     HTMLDocument *This = HTMLDOC_THIS(iface);
1329     FIXME("(%p)->(%p)\n", This, p);
1330     return E_NOTIMPL;
1331 }
1332
1333 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1334 {
1335     HTMLDocument *This = HTMLDOC_THIS(iface);
1336
1337     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1338
1339     return set_doc_event(This, EVENTID_DRAGSTART, &v);
1340 }
1341
1342 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1343 {
1344     HTMLDocument *This = HTMLDOC_THIS(iface);
1345
1346     TRACE("(%p)->(%p)\n", This, p);
1347
1348     return get_doc_event(This, EVENTID_DRAGSTART, p);
1349 }
1350
1351 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1352 {
1353     HTMLDocument *This = HTMLDOC_THIS(iface);
1354
1355     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1356
1357     return set_doc_event(This, EVENTID_SELECTSTART, &v);
1358 }
1359
1360 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1361 {
1362     HTMLDocument *This = HTMLDOC_THIS(iface);
1363
1364     TRACE("(%p)->(%p)\n", This, p);
1365
1366     return get_doc_event(This, EVENTID_SELECTSTART, p);
1367 }
1368
1369 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1370                                                         IHTMLElement **elementHit)
1371 {
1372     HTMLDocument *This = HTMLDOC_THIS(iface);
1373     FIXME("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1374     return E_NOTIMPL;
1375 }
1376
1377 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1378 {
1379     HTMLDocument *This = HTMLDOC_THIS(iface);
1380
1381     TRACE("(%p)->(%p)\n", This, p);
1382
1383     *p = HTMLWINDOW2(This->window);
1384     IHTMLWindow2_AddRef(*p);
1385     return S_OK;
1386 }
1387
1388 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1389                                                    IHTMLStyleSheetsCollection **p)
1390 {
1391     HTMLDocument *This = HTMLDOC_THIS(iface);
1392     nsIDOMStyleSheetList *nsstylelist;
1393     nsIDOMDocumentStyle *nsdocstyle;
1394     nsresult nsres;
1395
1396     TRACE("(%p)->(%p)\n", This, p);
1397
1398     *p = NULL;
1399
1400     if(!This->nsdoc) {
1401         WARN("NULL nsdoc\n");
1402         return E_UNEXPECTED;
1403     }
1404
1405     nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMDocumentStyle, (void**)&nsdocstyle);
1406     nsres = nsIDOMDocumentStyle_GetStyleSheets(nsdocstyle, &nsstylelist);
1407     nsIDOMDocumentStyle_Release(nsdocstyle);
1408     if(NS_FAILED(nsres)) {
1409         ERR("GetStyleSheets failed: %08x\n", nsres);
1410         return E_FAIL;
1411     }
1412
1413     *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1414     nsIDOMDocumentStyle_Release(nsstylelist);
1415
1416     return S_OK;
1417 }
1418
1419 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1420 {
1421     HTMLDocument *This = HTMLDOC_THIS(iface);
1422     FIXME("(%p)\n", This);
1423     return E_NOTIMPL;
1424 }
1425
1426 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1427 {
1428     HTMLDocument *This = HTMLDOC_THIS(iface);
1429     FIXME("(%p)->(%p)\n", This, p);
1430     return E_NOTIMPL;
1431 }
1432
1433 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1434 {
1435     HTMLDocument *This = HTMLDOC_THIS(iface);
1436     FIXME("(%p)\n", This);
1437     return E_NOTIMPL;
1438 }
1439
1440 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1441 {
1442     HTMLDocument *This = HTMLDOC_THIS(iface);
1443     FIXME("(%p)->(%p)\n", This, p);
1444     return E_NOTIMPL;
1445 }
1446
1447 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1448 {
1449     HTMLDocument *This = HTMLDOC_THIS(iface);
1450     FIXME("(%p)->(%p)\n", This, String);
1451     return E_NOTIMPL;
1452 }
1453
1454 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1455                                             LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1456 {
1457     HTMLDocument *This = HTMLDOC_THIS(iface);
1458
1459     FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1460
1461     *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1462     return S_OK;
1463 }
1464
1465 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1466     HTMLDocument_QueryInterface,
1467     HTMLDocument_AddRef,
1468     HTMLDocument_Release,
1469     HTMLDocument_GetTypeInfoCount,
1470     HTMLDocument_GetTypeInfo,
1471     HTMLDocument_GetIDsOfNames,
1472     HTMLDocument_Invoke,
1473     HTMLDocument_get_Script,
1474     HTMLDocument_get_all,
1475     HTMLDocument_get_body,
1476     HTMLDocument_get_activeElement,
1477     HTMLDocument_get_images,
1478     HTMLDocument_get_applets,
1479     HTMLDocument_get_links,
1480     HTMLDocument_get_forms,
1481     HTMLDocument_get_anchors,
1482     HTMLDocument_put_title,
1483     HTMLDocument_get_title,
1484     HTMLDocument_get_scripts,
1485     HTMLDocument_put_designMode,
1486     HTMLDocument_get_designMode,
1487     HTMLDocument_get_selection,
1488     HTMLDocument_get_readyState,
1489     HTMLDocument_get_frames,
1490     HTMLDocument_get_embeds,
1491     HTMLDocument_get_plugins,
1492     HTMLDocument_put_alinkColor,
1493     HTMLDocument_get_alinkColor,
1494     HTMLDocument_put_bgColor,
1495     HTMLDocument_get_bgColor,
1496     HTMLDocument_put_fgColor,
1497     HTMLDocument_get_fgColor,
1498     HTMLDocument_put_linkColor,
1499     HTMLDocument_get_linkColor,
1500     HTMLDocument_put_vlinkColor,
1501     HTMLDocument_get_vlinkColor,
1502     HTMLDocument_get_referrer,
1503     HTMLDocument_get_location,
1504     HTMLDocument_get_lastModified,
1505     HTMLDocument_put_URL,
1506     HTMLDocument_get_URL,
1507     HTMLDocument_put_domain,
1508     HTMLDocument_get_domain,
1509     HTMLDocument_put_cookie,
1510     HTMLDocument_get_cookie,
1511     HTMLDocument_put_expando,
1512     HTMLDocument_get_expando,
1513     HTMLDocument_put_charset,
1514     HTMLDocument_get_charset,
1515     HTMLDocument_put_defaultCharset,
1516     HTMLDocument_get_defaultCharset,
1517     HTMLDocument_get_mimeType,
1518     HTMLDocument_get_fileSize,
1519     HTMLDocument_get_fileCreatedDate,
1520     HTMLDocument_get_fileModifiedDate,
1521     HTMLDocument_get_fileUpdatedDate,
1522     HTMLDocument_get_security,
1523     HTMLDocument_get_protocol,
1524     HTMLDocument_get_nameProp,
1525     HTMLDocument_write,
1526     HTMLDocument_writeln,
1527     HTMLDocument_open,
1528     HTMLDocument_close,
1529     HTMLDocument_clear,
1530     HTMLDocument_queryCommandSupported,
1531     HTMLDocument_queryCommandEnabled,
1532     HTMLDocument_queryCommandState,
1533     HTMLDocument_queryCommandIndeterm,
1534     HTMLDocument_queryCommandText,
1535     HTMLDocument_queryCommandValue,
1536     HTMLDocument_execCommand,
1537     HTMLDocument_execCommandShowHelp,
1538     HTMLDocument_createElement,
1539     HTMLDocument_put_onhelp,
1540     HTMLDocument_get_onhelp,
1541     HTMLDocument_put_onclick,
1542     HTMLDocument_get_onclick,
1543     HTMLDocument_put_ondblclick,
1544     HTMLDocument_get_ondblclick,
1545     HTMLDocument_put_onkeyup,
1546     HTMLDocument_get_onkeyup,
1547     HTMLDocument_put_onkeydown,
1548     HTMLDocument_get_onkeydown,
1549     HTMLDocument_put_onkeypress,
1550     HTMLDocument_get_onkeypress,
1551     HTMLDocument_put_onmouseup,
1552     HTMLDocument_get_onmouseup,
1553     HTMLDocument_put_onmousedown,
1554     HTMLDocument_get_onmousedown,
1555     HTMLDocument_put_onmousemove,
1556     HTMLDocument_get_onmousemove,
1557     HTMLDocument_put_onmouseout,
1558     HTMLDocument_get_onmouseout,
1559     HTMLDocument_put_onmouseover,
1560     HTMLDocument_get_onmouseover,
1561     HTMLDocument_put_onreadystatechange,
1562     HTMLDocument_get_onreadystatechange,
1563     HTMLDocument_put_onafterupdate,
1564     HTMLDocument_get_onafterupdate,
1565     HTMLDocument_put_onrowexit,
1566     HTMLDocument_get_onrowexit,
1567     HTMLDocument_put_onrowenter,
1568     HTMLDocument_get_onrowenter,
1569     HTMLDocument_put_ondragstart,
1570     HTMLDocument_get_ondragstart,
1571     HTMLDocument_put_onselectstart,
1572     HTMLDocument_get_onselectstart,
1573     HTMLDocument_elementFromPoint,
1574     HTMLDocument_get_parentWindow,
1575     HTMLDocument_get_styleSheets,
1576     HTMLDocument_put_onbeforeupdate,
1577     HTMLDocument_get_onbeforeupdate,
1578     HTMLDocument_put_onerrorupdate,
1579     HTMLDocument_get_onerrorupdate,
1580     HTMLDocument_toString,
1581     HTMLDocument_createStyleSheet
1582 };
1583
1584 #define SUPPINFO_THIS(iface) DEFINE_THIS(HTMLDocument, SupportErrorInfo, iface)
1585
1586 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1587 {
1588     HTMLDocument *This = SUPPINFO_THIS(iface);
1589     return IHTMLDocument_QueryInterface(HTMLDOC(This), riid, ppv);
1590 }
1591
1592 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1593 {
1594     HTMLDocument *This = SUPPINFO_THIS(iface);
1595     return IHTMLDocument_AddRef(HTMLDOC(This));
1596 }
1597
1598 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1599 {
1600     HTMLDocument *This = SUPPINFO_THIS(iface);
1601     return IHTMLDocument_Release(HTMLDOC(This));
1602 }
1603
1604 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1605 {
1606     FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1607     return S_FALSE;
1608 }
1609
1610 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1611     SupportErrorInfo_QueryInterface,
1612     SupportErrorInfo_AddRef,
1613     SupportErrorInfo_Release,
1614     SupportErrorInfo_InterfaceSupportsErrorInfo
1615 };
1616
1617 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLDocument, IDispatchEx, iface)
1618
1619 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1620 {
1621     HTMLDocument *This = DISPEX_THIS(iface);
1622
1623     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
1624 }
1625
1626 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1627 {
1628     HTMLDocument *This = DISPEX_THIS(iface);
1629
1630     return IHTMLDocument2_AddRef(HTMLDOC(This));
1631 }
1632
1633 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1634 {
1635     HTMLDocument *This = DISPEX_THIS(iface);
1636
1637     return IHTMLDocument2_Release(HTMLDOC(This));
1638 }
1639
1640 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1641 {
1642     HTMLDocument *This = DISPEX_THIS(iface);
1643
1644     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1645 }
1646
1647 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1648                                                LCID lcid, ITypeInfo **ppTInfo)
1649 {
1650     HTMLDocument *This = DISPEX_THIS(iface);
1651
1652     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1653 }
1654
1655 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1656                                                  LPOLESTR *rgszNames, UINT cNames,
1657                                                  LCID lcid, DISPID *rgDispId)
1658 {
1659     HTMLDocument *This = DISPEX_THIS(iface);
1660
1661     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
1662 }
1663
1664 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1665                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1666                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1667 {
1668     HTMLDocument *This = DISPEX_THIS(iface);
1669
1670     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1671           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1672
1673     switch(dispIdMember) {
1674     case DISPID_READYSTATE:
1675         TRACE("DISPID_READYSTATE\n");
1676
1677         if(!(wFlags & DISPATCH_PROPERTYGET))
1678             return E_INVALIDARG;
1679
1680         V_VT(pVarResult) = VT_I4;
1681         V_I4(pVarResult) = This->readystate;
1682         return S_OK;
1683     }
1684
1685     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1686                               pVarResult, pExcepInfo, puArgErr);
1687 }
1688
1689 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1690 {
1691     HTMLDocument *This = DISPEX_THIS(iface);
1692
1693     return IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1694 }
1695
1696 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1697         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1698 {
1699     HTMLDocument *This = DISPEX_THIS(iface);
1700
1701     return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1702 }
1703
1704 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1705 {
1706     HTMLDocument *This = DISPEX_THIS(iface);
1707
1708     return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
1709 }
1710
1711 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1712 {
1713     HTMLDocument *This = DISPEX_THIS(iface);
1714
1715     return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
1716 }
1717
1718 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1719 {
1720     HTMLDocument *This = DISPEX_THIS(iface);
1721
1722     return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
1723 }
1724
1725 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1726 {
1727     HTMLDocument *This = DISPEX_THIS(iface);
1728
1729     return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
1730 }
1731
1732 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1733 {
1734     HTMLDocument *This = DISPEX_THIS(iface);
1735
1736     return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
1737 }
1738
1739 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1740 {
1741     HTMLDocument *This = DISPEX_THIS(iface);
1742
1743     return IDispatchEx_GetNameSpaceParent(DISPATCHEX(&This->dispex), ppunk);
1744 }
1745
1746 #undef DISPEX_THIS
1747
1748 static const IDispatchExVtbl DocDispatchExVtbl = {
1749     DocDispatchEx_QueryInterface,
1750     DocDispatchEx_AddRef,
1751     DocDispatchEx_Release,
1752     DocDispatchEx_GetTypeInfoCount,
1753     DocDispatchEx_GetTypeInfo,
1754     DocDispatchEx_GetIDsOfNames,
1755     DocDispatchEx_Invoke,
1756     DocDispatchEx_GetDispID,
1757     DocDispatchEx_InvokeEx,
1758     DocDispatchEx_DeleteMemberByName,
1759     DocDispatchEx_DeleteMemberByDispID,
1760     DocDispatchEx_GetMemberProperties,
1761     DocDispatchEx_GetMemberName,
1762     DocDispatchEx_GetNextDispID,
1763     DocDispatchEx_GetNameSpaceParent
1764 };
1765
1766 static const tid_t HTMLDocument_iface_tids[] = {
1767     IHTMLDocument2_tid,
1768     IHTMLDocument3_tid,
1769     IHTMLDocument4_tid,
1770     IHTMLDocument5_tid,
1771     0
1772 };
1773 static dispex_static_data_t HTMLDocument_dispex = {
1774     NULL,
1775     DispHTMLDocument_tid,
1776     NULL,
1777     HTMLDocument_iface_tids
1778 };
1779
1780 static HRESULT alloc_doc(HTMLDocument **ret)
1781 {
1782     HTMLDocument *doc;
1783
1784     doc = heap_alloc_zero(sizeof(HTMLDocument));
1785     doc->lpHTMLDocument2Vtbl = &HTMLDocumentVtbl;
1786     doc->lpIDispatchExVtbl = &DocDispatchExVtbl;
1787     doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl;
1788     doc->ref = 1;
1789     doc->readystate = READYSTATE_UNINITIALIZED;
1790     doc->scriptmode = SCRIPTMODE_GECKO;
1791
1792     list_init(&doc->bindings);
1793     list_init(&doc->script_hosts);
1794     list_init(&doc->selection_list);
1795     list_init(&doc->range_list);
1796
1797     HTMLDocument_HTMLDocument3_Init(doc);
1798     HTMLDocument_HTMLDocument5_Init(doc);
1799     HTMLDocument_Persist_Init(doc);
1800     HTMLDocument_OleCmd_Init(doc);
1801     HTMLDocument_OleObj_Init(doc);
1802     HTMLDocument_View_Init(doc);
1803     HTMLDocument_Window_Init(doc);
1804     HTMLDocument_Service_Init(doc);
1805     HTMLDocument_Hlink_Init(doc);
1806
1807     ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)HTMLDOC(doc));
1808     ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink);
1809     ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents);
1810     ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2);
1811
1812     init_dispex(&doc->dispex, (IUnknown*)HTMLDOC(doc), &HTMLDocument_dispex);
1813
1814     *ret = doc;
1815     return S_OK;
1816 }
1817
1818 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocument **ret)
1819 {
1820     HTMLDocument *doc;
1821     HRESULT hres;
1822
1823     hres = alloc_doc(&doc);
1824     if(FAILED(hres))
1825         return hres;
1826
1827     nsIDOMHTMLDocument_AddRef(nsdoc);
1828     doc->nsdoc = nsdoc;
1829
1830     hres = HTMLWindow_Create(doc, NULL, &doc->window);
1831     if(FAILED(hres)) {
1832         IHTMLDocument_Release(HTMLDOC(doc));
1833         return hres;
1834     }
1835
1836     *ret = doc;
1837     return S_OK;
1838 }
1839
1840 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
1841 {
1842     HTMLDocument *doc;
1843     nsIDOMWindow *nswindow = NULL;
1844     HRESULT hres;
1845
1846     TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
1847
1848     hres = alloc_doc(&doc);
1849     if(FAILED(hres))
1850         return hres;
1851
1852     hres = IHTMLDocument_QueryInterface(HTMLDOC(doc), riid, ppvObject);
1853     IHTMLDocument_Release(HTMLDOC(doc));
1854     if(FAILED(hres))
1855         return hres;
1856
1857     doc->nscontainer = NSContainer_Create(doc, NULL);
1858     update_nsdocument(doc);
1859
1860     if(doc->nscontainer) {
1861         nsresult nsres;
1862
1863         nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
1864         if(NS_FAILED(nsres))
1865             ERR("GetContentDOMWindow failed: %08x\n", nsres);
1866     }
1867
1868     hres = HTMLWindow_Create(doc, nswindow, &doc->window);
1869     if(nswindow)
1870         nsIDOMWindow_Release(nswindow);
1871     if(FAILED(hres)) {
1872         IHTMLDocument_Release(HTMLDOC(doc));
1873         return hres;
1874     }
1875
1876     get_thread_hwnd();
1877
1878     return S_OK;
1879 }