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