mshtml: Implement IHTMLCurrentStyle_get_borderBottomColor.
[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
182         if(This->client)
183             IOleObject_SetClientSite(OLEOBJ(This), NULL);
184         if(This->in_place_active)
185             IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This));
186         if(This->ipsite)
187             IOleDocumentView_SetInPlaceSite(DOCVIEW(This), NULL);
188         if(This->undomgr)
189             IOleUndoManager_Release(This->undomgr);
190
191         set_document_bscallback(This, NULL);
192         set_current_mon(This, NULL);
193
194         if(This->tooltips_hwnd)
195             DestroyWindow(This->tooltips_hwnd);
196         if(This->hwnd)
197             DestroyWindow(This->hwnd);
198
199         if(This->option_factory) {
200             This->option_factory->doc = NULL;
201             IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
202         }
203
204         if(This->location)
205             This->location->doc = NULL;
206
207         if(This->window)
208             IHTMLWindow2_Release(HTMLWINDOW2(This->window));
209
210         if(This->event_target)
211             release_event_target(This->event_target);
212
213         heap_free(This->mime);
214         detach_selection(This);
215         detach_ranges(This);
216         release_nodes(This);
217         release_dispex(&This->dispex);
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 document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
904 {
905     nsAString nsstr;
906     VARIANT *var;
907     ULONG i, argc;
908     nsresult nsres;
909     HRESULT hres;
910
911     if(!This->nsdoc) {
912         WARN("NULL nsdoc\n");
913         return E_UNEXPECTED;
914     }
915
916     if(psarray->cDims != 1) {
917         FIXME("cDims=%d\n", psarray->cDims);
918         return E_INVALIDARG;
919     }
920
921     hres = SafeArrayAccessData(psarray, (void**)&var);
922     if(FAILED(hres)) {
923         WARN("SafeArrayAccessData failed: %08x\n", hres);
924         return hres;
925     }
926
927     nsAString_Init(&nsstr, NULL);
928
929     argc = psarray->rgsabound[0].cElements;
930     for(i=0; i < argc; i++) {
931         if(V_VT(var+i) == VT_BSTR) {
932             nsAString_SetData(&nsstr, V_BSTR(var+i));
933             if(!ln || i != argc-1)
934                 nsres = nsIDOMHTMLDocument_Write(This->nsdoc, &nsstr);
935             else
936                 nsres = nsIDOMHTMLDocument_Writeln(This->nsdoc, &nsstr);
937             if(NS_FAILED(nsres))
938                 ERR("Write failed: %08x\n", nsres);
939         }else {
940             FIXME("vt=%d\n", V_VT(var+i));
941         }
942     }
943
944     nsAString_Finish(&nsstr);
945     SafeArrayUnaccessData(psarray);
946
947     return S_OK;
948 }
949
950 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
951 {
952     HTMLDocument *This = HTMLDOC_THIS(iface);
953
954     TRACE("(%p)->(%p)\n", iface, psarray);
955
956     return document_write(This, psarray, FALSE);
957 }
958
959 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
960 {
961     HTMLDocument *This = HTMLDOC_THIS(iface);
962
963     TRACE("(%p)->(%p)\n", This, psarray);
964
965     return document_write(This, psarray, TRUE);
966 }
967
968 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
969                         VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
970 {
971     HTMLDocument *This = HTMLDOC_THIS(iface);
972     nsresult nsres;
973
974     static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
975
976     TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
977           debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
978
979     if(!This->nsdoc) {
980         ERR("!nsdoc\n");
981         return E_NOTIMPL;
982     }
983
984     if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
985        || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
986         FIXME("unsupported args\n");
987
988     nsres = nsIDOMHTMLDocument_Open(This->nsdoc);
989     if(NS_FAILED(nsres)) {
990         ERR("Open failed: %08x\n", nsres);
991         return E_FAIL;
992     }
993
994     *pomWindowResult = (IDispatch*)HTMLWINDOW2(This->window);
995     IHTMLWindow2_AddRef(HTMLWINDOW2(This->window));
996     return S_OK;
997 }
998
999 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
1000 {
1001     HTMLDocument *This = HTMLDOC_THIS(iface);
1002     nsresult nsres;
1003
1004     TRACE("(%p)\n", This);
1005
1006     if(!This->nsdoc) {
1007         ERR("!nsdoc\n");
1008         return E_NOTIMPL;
1009     }
1010
1011     nsres = nsIDOMHTMLDocument_Close(This->nsdoc);
1012     if(NS_FAILED(nsres)) {
1013         ERR("Close failed: %08x\n", nsres);
1014         return E_FAIL;
1015     }
1016
1017     return S_OK;
1018 }
1019
1020 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
1021 {
1022     HTMLDocument *This = HTMLDOC_THIS(iface);
1023     FIXME("(%p)\n", This);
1024     return E_NOTIMPL;
1025 }
1026
1027 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
1028                                                         VARIANT_BOOL *pfRet)
1029 {
1030     HTMLDocument *This = HTMLDOC_THIS(iface);
1031     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1032     return E_NOTIMPL;
1033 }
1034
1035 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
1036                                                         VARIANT_BOOL *pfRet)
1037 {
1038     HTMLDocument *This = HTMLDOC_THIS(iface);
1039     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1040     return E_NOTIMPL;
1041 }
1042
1043 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
1044                                                         VARIANT_BOOL *pfRet)
1045 {
1046     HTMLDocument *This = HTMLDOC_THIS(iface);
1047     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1048     return E_NOTIMPL;
1049 }
1050
1051 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
1052                                                         VARIANT_BOOL *pfRet)
1053 {
1054     HTMLDocument *This = HTMLDOC_THIS(iface);
1055     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1056     return E_NOTIMPL;
1057 }
1058
1059 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
1060                                                         BSTR *pfRet)
1061 {
1062     HTMLDocument *This = HTMLDOC_THIS(iface);
1063     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1064     return E_NOTIMPL;
1065 }
1066
1067 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
1068                                                         VARIANT *pfRet)
1069 {
1070     HTMLDocument *This = HTMLDOC_THIS(iface);
1071     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1072     return E_NOTIMPL;
1073 }
1074
1075 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
1076                                 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1077 {
1078     HTMLDocument *This = HTMLDOC_THIS(iface);
1079     FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
1080     return E_NOTIMPL;
1081 }
1082
1083 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
1084                                                         VARIANT_BOOL *pfRet)
1085 {
1086     HTMLDocument *This = HTMLDOC_THIS(iface);
1087     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1088     return E_NOTIMPL;
1089 }
1090
1091 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1092                                                  IHTMLElement **newElem)
1093 {
1094     HTMLDocument *This = HTMLDOC_THIS(iface);
1095     nsIDOMElement *nselem;
1096     HTMLElement *elem;
1097     nsAString tag_str;
1098     nsresult nsres;
1099
1100     TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1101
1102     if(!This->nsdoc) {
1103         WARN("NULL nsdoc\n");
1104         return E_UNEXPECTED;
1105     }
1106
1107     nsAString_Init(&tag_str, eTag);
1108     nsres = nsIDOMDocument_CreateElement(This->nsdoc, &tag_str, &nselem);
1109     nsAString_Finish(&tag_str);
1110     if(NS_FAILED(nsres)) {
1111         ERR("CreateElement failed: %08x\n", nsres);
1112         return E_FAIL;
1113     }
1114
1115     elem = HTMLElement_Create(This, (nsIDOMNode*)nselem, TRUE);
1116     nsIDOMElement_Release(nselem);
1117
1118     *newElem = HTMLELEM(elem);
1119     IHTMLElement_AddRef(HTMLELEM(elem));
1120     return S_OK;
1121 }
1122
1123 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1124 {
1125     HTMLDocument *This = HTMLDOC_THIS(iface);
1126     FIXME("(%p)\n", This);
1127     return E_NOTIMPL;
1128 }
1129
1130 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1131 {
1132     HTMLDocument *This = HTMLDOC_THIS(iface);
1133     FIXME("(%p)->(%p)\n", This, p);
1134     return E_NOTIMPL;
1135 }
1136
1137 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1138 {
1139     HTMLDocument *This = HTMLDOC_THIS(iface);
1140
1141     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1142
1143     return set_doc_event(This, EVENTID_CLICK, &v);
1144 }
1145
1146 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1147 {
1148     HTMLDocument *This = HTMLDOC_THIS(iface);
1149
1150     TRACE("(%p)->(%p)\n", This, p);
1151
1152     return get_doc_event(This, EVENTID_CLICK, p);
1153 }
1154
1155 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1156 {
1157     HTMLDocument *This = HTMLDOC_THIS(iface);
1158     FIXME("(%p)\n", This);
1159     return E_NOTIMPL;
1160 }
1161
1162 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1163 {
1164     HTMLDocument *This = HTMLDOC_THIS(iface);
1165     FIXME("(%p)->(%p)\n", This, p);
1166     return E_NOTIMPL;
1167 }
1168
1169 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1170 {
1171     HTMLDocument *This = HTMLDOC_THIS(iface);
1172
1173     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1174
1175     return set_doc_event(This, EVENTID_KEYUP, &v);
1176 }
1177
1178 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1179 {
1180     HTMLDocument *This = HTMLDOC_THIS(iface);
1181
1182     TRACE("(%p)->(%p)\n", This, p);
1183
1184     return get_doc_event(This, EVENTID_KEYUP, p);
1185 }
1186
1187 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1188 {
1189     HTMLDocument *This = HTMLDOC_THIS(iface);
1190
1191     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1192
1193     return set_doc_event(This, EVENTID_KEYDOWN, &v);
1194 }
1195
1196 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1197 {
1198     HTMLDocument *This = HTMLDOC_THIS(iface);
1199
1200     TRACE("(%p)->(%p)\n", This, p);
1201
1202     return get_doc_event(This, EVENTID_KEYDOWN, p);
1203 }
1204
1205 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1206 {
1207     HTMLDocument *This = HTMLDOC_THIS(iface);
1208     FIXME("(%p)\n", This);
1209     return E_NOTIMPL;
1210 }
1211
1212 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1213 {
1214     HTMLDocument *This = HTMLDOC_THIS(iface);
1215     FIXME("(%p)->(%p)\n", This, p);
1216     return E_NOTIMPL;
1217 }
1218
1219 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1220 {
1221     HTMLDocument *This = HTMLDOC_THIS(iface);
1222     FIXME("(%p)\n", This);
1223     return E_NOTIMPL;
1224 }
1225
1226 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1227 {
1228     HTMLDocument *This = HTMLDOC_THIS(iface);
1229     FIXME("(%p)->(%p)\n", This, p);
1230     return E_NOTIMPL;
1231 }
1232
1233 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1234 {
1235     HTMLDocument *This = HTMLDOC_THIS(iface);
1236     FIXME("(%p)\n", This);
1237     return E_NOTIMPL;
1238 }
1239
1240 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1241 {
1242     HTMLDocument *This = HTMLDOC_THIS(iface);
1243     FIXME("(%p)->(%p)\n", This, p);
1244     return E_NOTIMPL;
1245 }
1246
1247 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1248 {
1249     HTMLDocument *This = HTMLDOC_THIS(iface);
1250     FIXME("(%p)\n", This);
1251     return E_NOTIMPL;
1252 }
1253
1254 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1255 {
1256     HTMLDocument *This = HTMLDOC_THIS(iface);
1257     FIXME("(%p)->(%p)\n", This, p);
1258     return E_NOTIMPL;
1259 }
1260
1261 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1262 {
1263     HTMLDocument *This = HTMLDOC_THIS(iface);
1264     FIXME("(%p)\n", This);
1265     return E_NOTIMPL;
1266 }
1267
1268 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1269 {
1270     HTMLDocument *This = HTMLDOC_THIS(iface);
1271     FIXME("(%p)->(%p)\n", This, p);
1272     return E_NOTIMPL;
1273 }
1274
1275 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1276 {
1277     HTMLDocument *This = HTMLDOC_THIS(iface);
1278
1279     TRACE("(%p)\n", This);
1280
1281     return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1282 }
1283
1284 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1285 {
1286     HTMLDocument *This = HTMLDOC_THIS(iface);
1287
1288     TRACE("(%p)->(%p)\n", This, p);
1289
1290     return get_doc_event(This, EVENTID_MOUSEOVER, p);
1291 }
1292
1293 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1294 {
1295     HTMLDocument *This = HTMLDOC_THIS(iface);
1296     FIXME("(%p)\n", This);
1297     return E_NOTIMPL;
1298 }
1299
1300 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1301 {
1302     HTMLDocument *This = HTMLDOC_THIS(iface);
1303     FIXME("(%p)->(%p)\n", This, p);
1304     return E_NOTIMPL;
1305 }
1306
1307 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1308 {
1309     HTMLDocument *This = HTMLDOC_THIS(iface);
1310     FIXME("(%p)\n", This);
1311     return E_NOTIMPL;
1312 }
1313
1314 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1315 {
1316     HTMLDocument *This = HTMLDOC_THIS(iface);
1317     FIXME("(%p)->(%p)\n", This, p);
1318     return E_NOTIMPL;
1319 }
1320
1321 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1322 {
1323     HTMLDocument *This = HTMLDOC_THIS(iface);
1324     FIXME("(%p)\n", This);
1325     return E_NOTIMPL;
1326 }
1327
1328 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1329 {
1330     HTMLDocument *This = HTMLDOC_THIS(iface);
1331     FIXME("(%p)->(%p)\n", This, p);
1332     return E_NOTIMPL;
1333 }
1334
1335 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1336 {
1337     HTMLDocument *This = HTMLDOC_THIS(iface);
1338     FIXME("(%p)\n", This);
1339     return E_NOTIMPL;
1340 }
1341
1342 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1343 {
1344     HTMLDocument *This = HTMLDOC_THIS(iface);
1345     FIXME("(%p)->(%p)\n", This, p);
1346     return E_NOTIMPL;
1347 }
1348
1349 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1350 {
1351     HTMLDocument *This = HTMLDOC_THIS(iface);
1352
1353     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1354
1355     return set_doc_event(This, EVENTID_DRAGSTART, &v);
1356 }
1357
1358 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1359 {
1360     HTMLDocument *This = HTMLDOC_THIS(iface);
1361
1362     TRACE("(%p)->(%p)\n", This, p);
1363
1364     return get_doc_event(This, EVENTID_DRAGSTART, p);
1365 }
1366
1367 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1368 {
1369     HTMLDocument *This = HTMLDOC_THIS(iface);
1370
1371     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1372
1373     return set_doc_event(This, EVENTID_SELECTSTART, &v);
1374 }
1375
1376 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1377 {
1378     HTMLDocument *This = HTMLDOC_THIS(iface);
1379
1380     TRACE("(%p)->(%p)\n", This, p);
1381
1382     return get_doc_event(This, EVENTID_SELECTSTART, p);
1383 }
1384
1385 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1386                                                         IHTMLElement **elementHit)
1387 {
1388     HTMLDocument *This = HTMLDOC_THIS(iface);
1389     FIXME("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1390     return E_NOTIMPL;
1391 }
1392
1393 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1394 {
1395     HTMLDocument *This = HTMLDOC_THIS(iface);
1396
1397     TRACE("(%p)->(%p)\n", This, p);
1398
1399     *p = HTMLWINDOW2(This->window);
1400     IHTMLWindow2_AddRef(*p);
1401     return S_OK;
1402 }
1403
1404 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1405                                                    IHTMLStyleSheetsCollection **p)
1406 {
1407     HTMLDocument *This = HTMLDOC_THIS(iface);
1408     nsIDOMStyleSheetList *nsstylelist;
1409     nsIDOMDocumentStyle *nsdocstyle;
1410     nsresult nsres;
1411
1412     TRACE("(%p)->(%p)\n", This, p);
1413
1414     *p = NULL;
1415
1416     if(!This->nsdoc) {
1417         WARN("NULL nsdoc\n");
1418         return E_UNEXPECTED;
1419     }
1420
1421     nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMDocumentStyle, (void**)&nsdocstyle);
1422     nsres = nsIDOMDocumentStyle_GetStyleSheets(nsdocstyle, &nsstylelist);
1423     nsIDOMDocumentStyle_Release(nsdocstyle);
1424     if(NS_FAILED(nsres)) {
1425         ERR("GetStyleSheets failed: %08x\n", nsres);
1426         return E_FAIL;
1427     }
1428
1429     *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1430     nsIDOMDocumentStyle_Release(nsstylelist);
1431
1432     return S_OK;
1433 }
1434
1435 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1436 {
1437     HTMLDocument *This = HTMLDOC_THIS(iface);
1438     FIXME("(%p)\n", This);
1439     return E_NOTIMPL;
1440 }
1441
1442 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1443 {
1444     HTMLDocument *This = HTMLDOC_THIS(iface);
1445     FIXME("(%p)->(%p)\n", This, p);
1446     return E_NOTIMPL;
1447 }
1448
1449 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1450 {
1451     HTMLDocument *This = HTMLDOC_THIS(iface);
1452     FIXME("(%p)\n", This);
1453     return E_NOTIMPL;
1454 }
1455
1456 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1457 {
1458     HTMLDocument *This = HTMLDOC_THIS(iface);
1459     FIXME("(%p)->(%p)\n", This, p);
1460     return E_NOTIMPL;
1461 }
1462
1463 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1464 {
1465     HTMLDocument *This = HTMLDOC_THIS(iface);
1466     FIXME("(%p)->(%p)\n", This, String);
1467     return E_NOTIMPL;
1468 }
1469
1470 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1471                                             LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1472 {
1473     HTMLDocument *This = HTMLDOC_THIS(iface);
1474
1475     FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1476
1477     *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1478     return S_OK;
1479 }
1480
1481 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1482     HTMLDocument_QueryInterface,
1483     HTMLDocument_AddRef,
1484     HTMLDocument_Release,
1485     HTMLDocument_GetTypeInfoCount,
1486     HTMLDocument_GetTypeInfo,
1487     HTMLDocument_GetIDsOfNames,
1488     HTMLDocument_Invoke,
1489     HTMLDocument_get_Script,
1490     HTMLDocument_get_all,
1491     HTMLDocument_get_body,
1492     HTMLDocument_get_activeElement,
1493     HTMLDocument_get_images,
1494     HTMLDocument_get_applets,
1495     HTMLDocument_get_links,
1496     HTMLDocument_get_forms,
1497     HTMLDocument_get_anchors,
1498     HTMLDocument_put_title,
1499     HTMLDocument_get_title,
1500     HTMLDocument_get_scripts,
1501     HTMLDocument_put_designMode,
1502     HTMLDocument_get_designMode,
1503     HTMLDocument_get_selection,
1504     HTMLDocument_get_readyState,
1505     HTMLDocument_get_frames,
1506     HTMLDocument_get_embeds,
1507     HTMLDocument_get_plugins,
1508     HTMLDocument_put_alinkColor,
1509     HTMLDocument_get_alinkColor,
1510     HTMLDocument_put_bgColor,
1511     HTMLDocument_get_bgColor,
1512     HTMLDocument_put_fgColor,
1513     HTMLDocument_get_fgColor,
1514     HTMLDocument_put_linkColor,
1515     HTMLDocument_get_linkColor,
1516     HTMLDocument_put_vlinkColor,
1517     HTMLDocument_get_vlinkColor,
1518     HTMLDocument_get_referrer,
1519     HTMLDocument_get_location,
1520     HTMLDocument_get_lastModified,
1521     HTMLDocument_put_URL,
1522     HTMLDocument_get_URL,
1523     HTMLDocument_put_domain,
1524     HTMLDocument_get_domain,
1525     HTMLDocument_put_cookie,
1526     HTMLDocument_get_cookie,
1527     HTMLDocument_put_expando,
1528     HTMLDocument_get_expando,
1529     HTMLDocument_put_charset,
1530     HTMLDocument_get_charset,
1531     HTMLDocument_put_defaultCharset,
1532     HTMLDocument_get_defaultCharset,
1533     HTMLDocument_get_mimeType,
1534     HTMLDocument_get_fileSize,
1535     HTMLDocument_get_fileCreatedDate,
1536     HTMLDocument_get_fileModifiedDate,
1537     HTMLDocument_get_fileUpdatedDate,
1538     HTMLDocument_get_security,
1539     HTMLDocument_get_protocol,
1540     HTMLDocument_get_nameProp,
1541     HTMLDocument_write,
1542     HTMLDocument_writeln,
1543     HTMLDocument_open,
1544     HTMLDocument_close,
1545     HTMLDocument_clear,
1546     HTMLDocument_queryCommandSupported,
1547     HTMLDocument_queryCommandEnabled,
1548     HTMLDocument_queryCommandState,
1549     HTMLDocument_queryCommandIndeterm,
1550     HTMLDocument_queryCommandText,
1551     HTMLDocument_queryCommandValue,
1552     HTMLDocument_execCommand,
1553     HTMLDocument_execCommandShowHelp,
1554     HTMLDocument_createElement,
1555     HTMLDocument_put_onhelp,
1556     HTMLDocument_get_onhelp,
1557     HTMLDocument_put_onclick,
1558     HTMLDocument_get_onclick,
1559     HTMLDocument_put_ondblclick,
1560     HTMLDocument_get_ondblclick,
1561     HTMLDocument_put_onkeyup,
1562     HTMLDocument_get_onkeyup,
1563     HTMLDocument_put_onkeydown,
1564     HTMLDocument_get_onkeydown,
1565     HTMLDocument_put_onkeypress,
1566     HTMLDocument_get_onkeypress,
1567     HTMLDocument_put_onmouseup,
1568     HTMLDocument_get_onmouseup,
1569     HTMLDocument_put_onmousedown,
1570     HTMLDocument_get_onmousedown,
1571     HTMLDocument_put_onmousemove,
1572     HTMLDocument_get_onmousemove,
1573     HTMLDocument_put_onmouseout,
1574     HTMLDocument_get_onmouseout,
1575     HTMLDocument_put_onmouseover,
1576     HTMLDocument_get_onmouseover,
1577     HTMLDocument_put_onreadystatechange,
1578     HTMLDocument_get_onreadystatechange,
1579     HTMLDocument_put_onafterupdate,
1580     HTMLDocument_get_onafterupdate,
1581     HTMLDocument_put_onrowexit,
1582     HTMLDocument_get_onrowexit,
1583     HTMLDocument_put_onrowenter,
1584     HTMLDocument_get_onrowenter,
1585     HTMLDocument_put_ondragstart,
1586     HTMLDocument_get_ondragstart,
1587     HTMLDocument_put_onselectstart,
1588     HTMLDocument_get_onselectstart,
1589     HTMLDocument_elementFromPoint,
1590     HTMLDocument_get_parentWindow,
1591     HTMLDocument_get_styleSheets,
1592     HTMLDocument_put_onbeforeupdate,
1593     HTMLDocument_get_onbeforeupdate,
1594     HTMLDocument_put_onerrorupdate,
1595     HTMLDocument_get_onerrorupdate,
1596     HTMLDocument_toString,
1597     HTMLDocument_createStyleSheet
1598 };
1599
1600 #define SUPPINFO_THIS(iface) DEFINE_THIS(HTMLDocument, SupportErrorInfo, iface)
1601
1602 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1603 {
1604     HTMLDocument *This = SUPPINFO_THIS(iface);
1605     return IHTMLDocument_QueryInterface(HTMLDOC(This), riid, ppv);
1606 }
1607
1608 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1609 {
1610     HTMLDocument *This = SUPPINFO_THIS(iface);
1611     return IHTMLDocument_AddRef(HTMLDOC(This));
1612 }
1613
1614 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1615 {
1616     HTMLDocument *This = SUPPINFO_THIS(iface);
1617     return IHTMLDocument_Release(HTMLDOC(This));
1618 }
1619
1620 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1621 {
1622     FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1623     return S_FALSE;
1624 }
1625
1626 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1627     SupportErrorInfo_QueryInterface,
1628     SupportErrorInfo_AddRef,
1629     SupportErrorInfo_Release,
1630     SupportErrorInfo_InterfaceSupportsErrorInfo
1631 };
1632
1633 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLDocument, IDispatchEx, iface)
1634
1635 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1636 {
1637     HTMLDocument *This = DISPEX_THIS(iface);
1638
1639     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
1640 }
1641
1642 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1643 {
1644     HTMLDocument *This = DISPEX_THIS(iface);
1645
1646     return IHTMLDocument2_AddRef(HTMLDOC(This));
1647 }
1648
1649 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1650 {
1651     HTMLDocument *This = DISPEX_THIS(iface);
1652
1653     return IHTMLDocument2_Release(HTMLDOC(This));
1654 }
1655
1656 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1657 {
1658     HTMLDocument *This = DISPEX_THIS(iface);
1659
1660     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1661 }
1662
1663 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1664                                                LCID lcid, ITypeInfo **ppTInfo)
1665 {
1666     HTMLDocument *This = DISPEX_THIS(iface);
1667
1668     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1669 }
1670
1671 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1672                                                  LPOLESTR *rgszNames, UINT cNames,
1673                                                  LCID lcid, DISPID *rgDispId)
1674 {
1675     HTMLDocument *This = DISPEX_THIS(iface);
1676
1677     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
1678 }
1679
1680 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1681                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1682                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1683 {
1684     HTMLDocument *This = DISPEX_THIS(iface);
1685
1686     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1687           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1688
1689     switch(dispIdMember) {
1690     case DISPID_READYSTATE:
1691         TRACE("DISPID_READYSTATE\n");
1692
1693         if(!(wFlags & DISPATCH_PROPERTYGET))
1694             return E_INVALIDARG;
1695
1696         V_VT(pVarResult) = VT_I4;
1697         V_I4(pVarResult) = This->readystate;
1698         return S_OK;
1699     }
1700
1701     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1702                               pVarResult, pExcepInfo, puArgErr);
1703 }
1704
1705 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1706 {
1707     HTMLDocument *This = DISPEX_THIS(iface);
1708
1709     return IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1710 }
1711
1712 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1713         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1714 {
1715     HTMLDocument *This = DISPEX_THIS(iface);
1716
1717     return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1718 }
1719
1720 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1721 {
1722     HTMLDocument *This = DISPEX_THIS(iface);
1723
1724     return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
1725 }
1726
1727 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1728 {
1729     HTMLDocument *This = DISPEX_THIS(iface);
1730
1731     return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
1732 }
1733
1734 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1735 {
1736     HTMLDocument *This = DISPEX_THIS(iface);
1737
1738     return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
1739 }
1740
1741 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1742 {
1743     HTMLDocument *This = DISPEX_THIS(iface);
1744
1745     return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
1746 }
1747
1748 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1749 {
1750     HTMLDocument *This = DISPEX_THIS(iface);
1751
1752     return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
1753 }
1754
1755 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1756 {
1757     HTMLDocument *This = DISPEX_THIS(iface);
1758
1759     return IDispatchEx_GetNameSpaceParent(DISPATCHEX(&This->dispex), ppunk);
1760 }
1761
1762 #undef DISPEX_THIS
1763
1764 static const IDispatchExVtbl DocDispatchExVtbl = {
1765     DocDispatchEx_QueryInterface,
1766     DocDispatchEx_AddRef,
1767     DocDispatchEx_Release,
1768     DocDispatchEx_GetTypeInfoCount,
1769     DocDispatchEx_GetTypeInfo,
1770     DocDispatchEx_GetIDsOfNames,
1771     DocDispatchEx_Invoke,
1772     DocDispatchEx_GetDispID,
1773     DocDispatchEx_InvokeEx,
1774     DocDispatchEx_DeleteMemberByName,
1775     DocDispatchEx_DeleteMemberByDispID,
1776     DocDispatchEx_GetMemberProperties,
1777     DocDispatchEx_GetMemberName,
1778     DocDispatchEx_GetNextDispID,
1779     DocDispatchEx_GetNameSpaceParent
1780 };
1781
1782 static const tid_t HTMLDocument_iface_tids[] = {
1783     IHTMLDocument2_tid,
1784     IHTMLDocument3_tid,
1785     IHTMLDocument4_tid,
1786     IHTMLDocument5_tid,
1787     0
1788 };
1789 static dispex_static_data_t HTMLDocument_dispex = {
1790     NULL,
1791     DispHTMLDocument_tid,
1792     NULL,
1793     HTMLDocument_iface_tids
1794 };
1795
1796 static HRESULT alloc_doc(HTMLDocument **ret)
1797 {
1798     HTMLDocument *doc;
1799
1800     doc = heap_alloc_zero(sizeof(HTMLDocument));
1801     doc->lpHTMLDocument2Vtbl = &HTMLDocumentVtbl;
1802     doc->lpIDispatchExVtbl = &DocDispatchExVtbl;
1803     doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl;
1804     doc->ref = 1;
1805     doc->readystate = READYSTATE_UNINITIALIZED;
1806
1807     list_init(&doc->bindings);
1808     list_init(&doc->selection_list);
1809     list_init(&doc->range_list);
1810
1811     HTMLDocument_HTMLDocument3_Init(doc);
1812     HTMLDocument_HTMLDocument5_Init(doc);
1813     HTMLDocument_Persist_Init(doc);
1814     HTMLDocument_OleCmd_Init(doc);
1815     HTMLDocument_OleObj_Init(doc);
1816     HTMLDocument_View_Init(doc);
1817     HTMLDocument_Window_Init(doc);
1818     HTMLDocument_Service_Init(doc);
1819     HTMLDocument_Hlink_Init(doc);
1820
1821     ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)HTMLDOC(doc));
1822     ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink);
1823     ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents);
1824     ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2);
1825
1826     init_dispex(&doc->dispex, (IUnknown*)HTMLDOC(doc), &HTMLDocument_dispex);
1827
1828     *ret = doc;
1829     return S_OK;
1830 }
1831
1832 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocument **ret)
1833 {
1834     HTMLDocument *doc;
1835     HRESULT hres;
1836
1837     hres = alloc_doc(&doc);
1838     if(FAILED(hres))
1839         return hres;
1840
1841     nsIDOMHTMLDocument_AddRef(nsdoc);
1842     doc->nsdoc = nsdoc;
1843
1844     hres = HTMLWindow_Create(doc, NULL, &doc->window);
1845     if(FAILED(hres)) {
1846         IHTMLDocument_Release(HTMLDOC(doc));
1847         return hres;
1848     }
1849
1850     *ret = doc;
1851     return S_OK;
1852 }
1853
1854 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
1855 {
1856     HTMLDocument *doc;
1857     nsIDOMWindow *nswindow = NULL;
1858     HRESULT hres;
1859
1860     TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
1861
1862     hres = alloc_doc(&doc);
1863     if(FAILED(hres))
1864         return hres;
1865
1866     hres = IHTMLDocument_QueryInterface(HTMLDOC(doc), riid, ppvObject);
1867     IHTMLDocument_Release(HTMLDOC(doc));
1868     if(FAILED(hres))
1869         return hres;
1870
1871     doc->nscontainer = NSContainer_Create(doc, NULL);
1872     update_nsdocument(doc);
1873
1874     if(doc->nscontainer) {
1875         nsresult nsres;
1876
1877         nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
1878         if(NS_FAILED(nsres))
1879             ERR("GetContentDOMWindow failed: %08x\n", nsres);
1880     }
1881
1882     hres = HTMLWindow_Create(doc, nswindow, &doc->window);
1883     if(nswindow)
1884         nsIDOMWindow_Release(nswindow);
1885     if(FAILED(hres)) {
1886         IHTMLDocument_Release(HTMLDOC(doc));
1887         return hres;
1888     }
1889
1890     get_thread_hwnd();
1891
1892     return S_OK;
1893 }