mshtml: Move GetContentDOMWindow call from HTMLWindow_Create.
[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         UNLOCK_MODULE();
219     }
220
221     return ref;
222 }
223
224 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
225 {
226     HTMLDocument *This = HTMLDOC_THIS(iface);
227
228     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
229 }
230
231 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
232                                                 LCID lcid, ITypeInfo **ppTInfo)
233 {
234     HTMLDocument *This = HTMLDOC_THIS(iface);
235
236     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
237 }
238
239 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
240                                                 LPOLESTR *rgszNames, UINT cNames,
241                                                 LCID lcid, DISPID *rgDispId)
242 {
243     HTMLDocument *This = HTMLDOC_THIS(iface);
244
245     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
246 }
247
248 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
249                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
250                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
251 {
252     HTMLDocument *This = HTMLDOC_THIS(iface);
253
254     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
255             pVarResult, pExcepInfo, puArgErr);
256 }
257
258 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
259 {
260     HTMLDocument *This = HTMLDOC_THIS(iface);
261
262     TRACE("(%p)->(%p)\n", This, p);
263
264     *p = (IDispatch*)HTMLWINDOW2(This->window);
265     IDispatch_AddRef(*p);
266     return S_OK;
267 }
268
269 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
270 {
271     HTMLDocument *This = HTMLDOC_THIS(iface);
272     nsIDOMElement *nselem = NULL;
273     nsresult nsres;
274
275     TRACE("(%p)->(%p)\n", This, p);
276
277     if(!This->nsdoc) {
278         WARN("NULL nsdoc\n");
279         return E_UNEXPECTED;
280     }
281
282     nsres = nsIDOMHTMLDocument_GetDocumentElement(This->nsdoc, &nselem);
283     if(NS_FAILED(nsres)) {
284         ERR("GetDocumentElement failed: %08x\n", nsres);
285         return E_FAIL;
286     }
287
288     if(nselem) {
289         *p = create_all_collection(get_node(This, (nsIDOMNode*)nselem, TRUE), TRUE);
290         nsIDOMElement_Release(nselem);
291     }else {
292         *p = NULL;
293     }
294
295     return S_OK;
296 }
297
298 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
299 {
300     HTMLDocument *This = HTMLDOC_THIS(iface);
301     nsIDOMHTMLElement *nsbody = NULL;
302     HTMLDOMNode *node;
303     nsresult nsres;
304
305     TRACE("(%p)->(%p)\n", This, p);
306
307     if(!This->nsdoc) {
308         WARN("NULL nsdoc\n");
309         return E_UNEXPECTED;
310     }
311
312     nsres = nsIDOMHTMLDocument_GetBody(This->nsdoc, &nsbody);
313     if(NS_FAILED(nsres)) {
314         TRACE("Could not get body: %08x\n", nsres);
315         return E_UNEXPECTED;
316     }
317
318     if(nsbody) {
319         node = get_node(This, (nsIDOMNode*)nsbody, TRUE);
320         nsIDOMHTMLElement_Release(nsbody);
321
322         IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)p);
323     }else {
324         *p = NULL;
325     }
326
327     TRACE("*p = %p\n", *p);
328     return S_OK;
329 }
330
331 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
332 {
333     HTMLDocument *This = HTMLDOC_THIS(iface);
334     FIXME("(%p)->(%p)\n", This, p);
335     return E_NOTIMPL;
336 }
337
338 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
339 {
340     HTMLDocument *This = HTMLDOC_THIS(iface);
341     FIXME("(%p)->(%p)\n", This, p);
342     return E_NOTIMPL;
343 }
344
345 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
346 {
347     HTMLDocument *This = HTMLDOC_THIS(iface);
348     FIXME("(%p)->(%p)\n", This, p);
349     return E_NOTIMPL;
350 }
351
352 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
353 {
354     HTMLDocument *This = HTMLDOC_THIS(iface);
355     FIXME("(%p)->(%p)\n", This, p);
356     return E_NOTIMPL;
357 }
358
359 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
360 {
361     HTMLDocument *This = HTMLDOC_THIS(iface);
362     FIXME("(%p)->(%p)\n", This, p);
363     return E_NOTIMPL;
364 }
365
366 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
367 {
368     HTMLDocument *This = HTMLDOC_THIS(iface);
369     FIXME("(%p)->(%p)\n", This, p);
370     return E_NOTIMPL;
371 }
372
373 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
374 {
375     HTMLDocument *This = HTMLDOC_THIS(iface);
376     nsAString nsstr;
377     nsresult nsres;
378
379     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
380
381     if(!This->nsdoc) {
382         WARN("NULL nsdoc\n");
383         return E_UNEXPECTED;
384     }
385
386     nsAString_Init(&nsstr, v);
387     nsres = nsIDOMHTMLDocument_SetTitle(This->nsdoc, &nsstr);
388     nsAString_Finish(&nsstr);
389     if(NS_FAILED(nsres))
390         ERR("SetTitle failed: %08x\n", nsres);
391
392     return S_OK;
393 }
394
395 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
396 {
397     HTMLDocument *This = HTMLDOC_THIS(iface);
398     const PRUnichar *ret;
399     nsAString nsstr;
400     nsresult nsres;
401
402     TRACE("(%p)->(%p)\n", This, p);
403
404     if(!This->nsdoc) {
405         WARN("NULL nsdoc\n");
406         return E_UNEXPECTED;
407     }
408
409
410     nsAString_Init(&nsstr, NULL);
411     nsres = nsIDOMHTMLDocument_GetTitle(This->nsdoc, &nsstr);
412     if (NS_SUCCEEDED(nsres)) {
413         nsAString_GetData(&nsstr, &ret);
414         *p = SysAllocString(ret);
415     }
416     nsAString_Finish(&nsstr);
417
418     if(NS_FAILED(nsres)) {
419         ERR("GetTitle failed: %08x\n", nsres);
420         return E_FAIL;
421     }
422
423     return S_OK;
424 }
425
426 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
427 {
428     HTMLDocument *This = HTMLDOC_THIS(iface);
429     FIXME("(%p)->(%p)\n", This, p);
430     return E_NOTIMPL;
431 }
432
433 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
434 {
435     HTMLDocument *This = HTMLDOC_THIS(iface);
436     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
437     return E_NOTIMPL;
438 }
439
440 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
441 {
442     HTMLDocument *This = HTMLDOC_THIS(iface);
443     FIXME("(%p)->(%p)\n", This, p);
444     return E_NOTIMPL;
445 }
446
447 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
448 {
449     HTMLDocument *This = HTMLDOC_THIS(iface);
450     nsISelection *nsselection = NULL;
451
452     TRACE("(%p)->(%p)\n", This, p);
453
454     if(This->nscontainer) {
455         nsIDOMWindow *dom_window = NULL;
456
457         nsIWebBrowser_GetContentDOMWindow(This->nscontainer->webbrowser, &dom_window);
458         if(dom_window) {
459             nsIDOMWindow_GetSelection(dom_window, &nsselection);
460             nsIDOMWindow_Release(dom_window);
461         }
462     }
463
464     *p = HTMLSelectionObject_Create(This, nsselection);
465     return S_OK;
466 }
467
468 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
469 {
470     HTMLDocument *This = HTMLDOC_THIS(iface);
471
472     static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
473     static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
474     static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
475     static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
476     static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
477
478     static const LPCWSTR readystate_str[] = {
479         wszUninitialized,
480         wszLoading,
481         wszLoaded,
482         wszInteractive,
483         wszComplete
484     };
485
486     TRACE("(%p)->(%p)\n", iface, p);
487
488     if(!p)
489         return E_POINTER;
490
491     *p = SysAllocString(readystate_str[This->readystate]);
492     return S_OK;
493 }
494
495 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
496 {
497     HTMLDocument *This = HTMLDOC_THIS(iface);
498     FIXME("(%p)->(%p)\n", This, p);
499     return E_NOTIMPL;
500 }
501
502 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
503 {
504     HTMLDocument *This = HTMLDOC_THIS(iface);
505     FIXME("(%p)->(%p)\n", This, p);
506     return E_NOTIMPL;
507 }
508
509 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
510 {
511     HTMLDocument *This = HTMLDOC_THIS(iface);
512     FIXME("(%p)->(%p)\n", This, p);
513     return E_NOTIMPL;
514 }
515
516 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
517 {
518     HTMLDocument *This = HTMLDOC_THIS(iface);
519     FIXME("(%p)\n", This);
520     return E_NOTIMPL;
521 }
522
523 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
524 {
525     HTMLDocument *This = HTMLDOC_THIS(iface);
526     FIXME("(%p)->(%p)\n", This, p);
527     return E_NOTIMPL;
528 }
529
530 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
531 {
532     HTMLDocument *This = HTMLDOC_THIS(iface);
533     FIXME("(%p)\n", This);
534     return E_NOTIMPL;
535 }
536
537 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
538 {
539     HTMLDocument *This = HTMLDOC_THIS(iface);
540     FIXME("(%p)->(%p)\n", This, p);
541     return E_NOTIMPL;
542 }
543
544 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
545 {
546     HTMLDocument *This = HTMLDOC_THIS(iface);
547     FIXME("(%p)\n", This);
548     return E_NOTIMPL;
549 }
550
551 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
552 {
553     HTMLDocument *This = HTMLDOC_THIS(iface);
554     FIXME("(%p)->(%p)\n", This, p);
555     return E_NOTIMPL;
556 }
557
558 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
559 {
560     HTMLDocument *This = HTMLDOC_THIS(iface);
561     FIXME("(%p)->()\n", This);
562     return E_NOTIMPL;
563 }
564
565 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
566 {
567     HTMLDocument *This = HTMLDOC_THIS(iface);
568     FIXME("(%p)->(%p)\n", This, p);
569     return E_NOTIMPL;
570 }
571
572 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
573 {
574     HTMLDocument *This = HTMLDOC_THIS(iface);
575     FIXME("(%p)\n", This);
576     return E_NOTIMPL;
577 }
578
579 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
580 {
581     HTMLDocument *This = HTMLDOC_THIS(iface);
582     FIXME("(%p)->(%p)\n", This, p);
583     return E_NOTIMPL;
584 }
585
586 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
587 {
588     HTMLDocument *This = HTMLDOC_THIS(iface);
589     FIXME("(%p)->(%p)\n", This, p);
590     return E_NOTIMPL;
591 }
592
593 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
594 {
595     HTMLDocument *This = HTMLDOC_THIS(iface);
596
597     TRACE("(%p)->(%p)\n", This, p);
598
599     if(This->location)
600         IHTMLLocation_AddRef(HTMLLOCATION(This->location));
601     else
602         This->location = HTMLLocation_Create(This);
603
604     *p = HTMLLOCATION(This->location);
605     return S_OK;
606 }
607
608 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
609 {
610     HTMLDocument *This = HTMLDOC_THIS(iface);
611     FIXME("(%p)->(%p)\n", This, p);
612     return E_NOTIMPL;
613 }
614
615 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
616 {
617     HTMLDocument *This = HTMLDOC_THIS(iface);
618     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
619     return E_NOTIMPL;
620 }
621
622 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
623 {
624     HTMLDocument *This = HTMLDOC_THIS(iface);
625
626     static const WCHAR about_blank_url[] =
627         {'a','b','o','u','t',':','b','l','a','n','k',0};
628
629     TRACE("(%p)->(%p)\n", iface, p);
630
631     *p = SysAllocString(This->url ? This->url : about_blank_url);
632     return S_OK;
633 }
634
635 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
636 {
637     HTMLDocument *This = HTMLDOC_THIS(iface);
638     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
639     return E_NOTIMPL;
640 }
641
642 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
643 {
644     HTMLDocument *This = HTMLDOC_THIS(iface);
645     FIXME("(%p)->(%p)\n", This, p);
646     return E_NOTIMPL;
647 }
648
649 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
650 {
651     HTMLDocument *This = HTMLDOC_THIS(iface);
652     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
653     return E_NOTIMPL;
654 }
655
656 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
657 {
658     HTMLDocument *This = HTMLDOC_THIS(iface);
659     FIXME("(%p)->(%p)\n", This, p);
660     return E_NOTIMPL;
661 }
662
663 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
664 {
665     HTMLDocument *This = HTMLDOC_THIS(iface);
666     FIXME("(%p)->(%x)\n", This, v);
667     return E_NOTIMPL;
668 }
669
670 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
671 {
672     HTMLDocument *This = HTMLDOC_THIS(iface);
673     FIXME("(%p)->(%p)\n", This, p);
674     return E_NOTIMPL;
675 }
676
677 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
678 {
679     HTMLDocument *This = HTMLDOC_THIS(iface);
680     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
681     return E_NOTIMPL;
682 }
683
684 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
685 {
686     HTMLDocument *This = HTMLDOC_THIS(iface);
687     FIXME("(%p)->(%p)\n", This, p);
688     return E_NOTIMPL;
689 }
690
691 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
692 {
693     HTMLDocument *This = HTMLDOC_THIS(iface);
694     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
695     return E_NOTIMPL;
696 }
697
698 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
699 {
700     HTMLDocument *This = HTMLDOC_THIS(iface);
701     FIXME("(%p)->(%p)\n", This, p);
702     return E_NOTIMPL;
703 }
704
705 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
706 {
707     HTMLDocument *This = HTMLDOC_THIS(iface);
708     FIXME("(%p)->(%p)\n", This, p);
709     return E_NOTIMPL;
710 }
711
712 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
713 {
714     HTMLDocument *This = HTMLDOC_THIS(iface);
715     FIXME("(%p)->(%p)\n", This, p);
716     return E_NOTIMPL;
717 }
718
719 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
720 {
721     HTMLDocument *This = HTMLDOC_THIS(iface);
722     FIXME("(%p)->(%p)\n", This, p);
723     return E_NOTIMPL;
724 }
725
726 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
727 {
728     HTMLDocument *This = HTMLDOC_THIS(iface);
729     FIXME("(%p)->(%p)\n", This, p);
730     return E_NOTIMPL;
731 }
732
733 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
734 {
735     HTMLDocument *This = HTMLDOC_THIS(iface);
736     FIXME("(%p)->(%p)\n", This, p);
737     return E_NOTIMPL;
738 }
739
740 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
741 {
742     HTMLDocument *This = HTMLDOC_THIS(iface);
743     FIXME("(%p)->(%p)\n", This, p);
744     return E_NOTIMPL;
745 }
746
747 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
748 {
749     HTMLDocument *This = HTMLDOC_THIS(iface);
750     FIXME("(%p)->(%p)\n", This, p);
751     return E_NOTIMPL;
752 }
753
754 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
755 {
756     HTMLDocument *This = HTMLDOC_THIS(iface);
757     FIXME("(%p)->(%p)\n", This, p);
758     return E_NOTIMPL;
759 }
760
761 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
762 {
763     HTMLDocument *This = HTMLDOC_THIS(iface);
764     nsAString nsstr;
765     VARIANT *var;
766     int i;
767     nsresult nsres;
768     HRESULT hres;
769
770     TRACE("(%p)->(%p)\n", iface, psarray);
771
772     if(!This->nsdoc) {
773         WARN("NULL nsdoc\n");
774         return E_UNEXPECTED;
775     }
776
777     if(psarray->cDims != 1) {
778         FIXME("cDims=%d\n", psarray->cDims);
779         return E_INVALIDARG;
780     }
781
782     hres = SafeArrayAccessData(psarray, (void**)&var);
783     if(FAILED(hres)) {
784         WARN("SafeArrayAccessData failed: %08x\n", hres);
785         return hres;
786     }
787
788     nsAString_Init(&nsstr, NULL);
789
790     for(i=0; i < psarray->rgsabound[0].cElements; i++) {
791         if(V_VT(var+i) == VT_BSTR) {
792             nsAString_SetData(&nsstr, V_BSTR(var+i));
793             nsres = nsIDOMHTMLDocument_Write(This->nsdoc, &nsstr);
794             if(NS_FAILED(nsres))
795                 ERR("Write failed: %08x\n", nsres);
796         }else {
797             FIXME("vt=%d\n", V_VT(var+i));
798         }
799     }
800
801     nsAString_Finish(&nsstr);
802     SafeArrayUnaccessData(psarray);
803
804     return S_OK;
805 }
806
807 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
808 {
809     HTMLDocument *This = HTMLDOC_THIS(iface);
810     FIXME("(%p)->(%p)\n", This, psarray);
811     return E_NOTIMPL;
812 }
813
814 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
815                         VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
816 {
817     HTMLDocument *This = HTMLDOC_THIS(iface);
818     FIXME("(%p)->(%s %p)\n", This, debugstr_w(url), pomWindowResult);
819     return E_NOTIMPL;
820 }
821
822 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
823 {
824     HTMLDocument *This = HTMLDOC_THIS(iface);
825     FIXME("(%p)\n", This);
826     return E_NOTIMPL;
827 }
828
829 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
830 {
831     HTMLDocument *This = HTMLDOC_THIS(iface);
832     FIXME("(%p)\n", This);
833     return E_NOTIMPL;
834 }
835
836 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
837                                                         VARIANT_BOOL *pfRet)
838 {
839     HTMLDocument *This = HTMLDOC_THIS(iface);
840     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
841     return E_NOTIMPL;
842 }
843
844 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
845                                                         VARIANT_BOOL *pfRet)
846 {
847     HTMLDocument *This = HTMLDOC_THIS(iface);
848     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
849     return E_NOTIMPL;
850 }
851
852 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
853                                                         VARIANT_BOOL *pfRet)
854 {
855     HTMLDocument *This = HTMLDOC_THIS(iface);
856     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
857     return E_NOTIMPL;
858 }
859
860 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
861                                                         VARIANT_BOOL *pfRet)
862 {
863     HTMLDocument *This = HTMLDOC_THIS(iface);
864     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
865     return E_NOTIMPL;
866 }
867
868 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
869                                                         BSTR *pfRet)
870 {
871     HTMLDocument *This = HTMLDOC_THIS(iface);
872     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
873     return E_NOTIMPL;
874 }
875
876 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
877                                                         VARIANT *pfRet)
878 {
879     HTMLDocument *This = HTMLDOC_THIS(iface);
880     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
881     return E_NOTIMPL;
882 }
883
884 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
885                                 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
886 {
887     HTMLDocument *This = HTMLDOC_THIS(iface);
888     FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
889     return E_NOTIMPL;
890 }
891
892 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
893                                                         VARIANT_BOOL *pfRet)
894 {
895     HTMLDocument *This = HTMLDOC_THIS(iface);
896     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
897     return E_NOTIMPL;
898 }
899
900 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
901                                                  IHTMLElement **newElem)
902 {
903     HTMLDocument *This = HTMLDOC_THIS(iface);
904     nsIDOMElement *nselem;
905     HTMLElement *elem;
906     nsAString tag_str;
907     nsresult nsres;
908
909     TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
910
911     if(!This->nsdoc) {
912         WARN("NULL nsdoc\n");
913         return E_UNEXPECTED;
914     }
915
916     nsAString_Init(&tag_str, eTag);
917     nsres = nsIDOMDocument_CreateElement(This->nsdoc, &tag_str, &nselem);
918     nsAString_Finish(&tag_str);
919     if(NS_FAILED(nsres)) {
920         ERR("CreateElement failed: %08x\n", nsres);
921         return E_FAIL;
922     }
923
924     elem = HTMLElement_Create(This, (nsIDOMNode*)nselem, TRUE);
925     nsIDOMElement_Release(nselem);
926
927     *newElem = HTMLELEM(elem);
928     IHTMLElement_AddRef(HTMLELEM(elem));
929     return S_OK;
930 }
931
932 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
933 {
934     HTMLDocument *This = HTMLDOC_THIS(iface);
935     FIXME("(%p)\n", This);
936     return E_NOTIMPL;
937 }
938
939 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
940 {
941     HTMLDocument *This = HTMLDOC_THIS(iface);
942     FIXME("(%p)->(%p)\n", This, p);
943     return E_NOTIMPL;
944 }
945
946 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
947 {
948     HTMLDocument *This = HTMLDOC_THIS(iface);
949     FIXME("(%p)\n", This);
950     return E_NOTIMPL;
951 }
952
953 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
954 {
955     HTMLDocument *This = HTMLDOC_THIS(iface);
956     FIXME("(%p)->(%p)\n", This, p);
957     return E_NOTIMPL;
958 }
959
960 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
961 {
962     HTMLDocument *This = HTMLDOC_THIS(iface);
963     FIXME("(%p)\n", This);
964     return E_NOTIMPL;
965 }
966
967 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
968 {
969     HTMLDocument *This = HTMLDOC_THIS(iface);
970     FIXME("(%p)->(%p)\n", This, p);
971     return E_NOTIMPL;
972 }
973
974 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
975 {
976     HTMLDocument *This = HTMLDOC_THIS(iface);
977     FIXME("(%p)\n", This);
978     return E_NOTIMPL;
979 }
980
981 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
982 {
983     HTMLDocument *This = HTMLDOC_THIS(iface);
984     FIXME("(%p)->(%p)\n", This, p);
985     return E_NOTIMPL;
986 }
987
988 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
989 {
990     HTMLDocument *This = HTMLDOC_THIS(iface);
991     FIXME("(%p)\n", This);
992     return E_NOTIMPL;
993 }
994
995 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
996 {
997     HTMLDocument *This = HTMLDOC_THIS(iface);
998     FIXME("(%p)->(%p)\n", This, p);
999     return E_NOTIMPL;
1000 }
1001
1002 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1003 {
1004     HTMLDocument *This = HTMLDOC_THIS(iface);
1005     FIXME("(%p)\n", This);
1006     return E_NOTIMPL;
1007 }
1008
1009 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1010 {
1011     HTMLDocument *This = HTMLDOC_THIS(iface);
1012     FIXME("(%p)->(%p)\n", This, p);
1013     return E_NOTIMPL;
1014 }
1015
1016 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1017 {
1018     HTMLDocument *This = HTMLDOC_THIS(iface);
1019     FIXME("(%p)\n", This);
1020     return E_NOTIMPL;
1021 }
1022
1023 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1024 {
1025     HTMLDocument *This = HTMLDOC_THIS(iface);
1026     FIXME("(%p)->(%p)\n", This, p);
1027     return E_NOTIMPL;
1028 }
1029
1030 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1031 {
1032     HTMLDocument *This = HTMLDOC_THIS(iface);
1033     FIXME("(%p)\n", This);
1034     return E_NOTIMPL;
1035 }
1036
1037 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1038 {
1039     HTMLDocument *This = HTMLDOC_THIS(iface);
1040     FIXME("(%p)->(%p)\n", This, p);
1041     return E_NOTIMPL;
1042 }
1043
1044 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1045 {
1046     HTMLDocument *This = HTMLDOC_THIS(iface);
1047     FIXME("(%p)\n", This);
1048     return E_NOTIMPL;
1049 }
1050
1051 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1052 {
1053     HTMLDocument *This = HTMLDOC_THIS(iface);
1054     FIXME("(%p)->(%p)\n", This, p);
1055     return E_NOTIMPL;
1056 }
1057
1058 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1059 {
1060     HTMLDocument *This = HTMLDOC_THIS(iface);
1061     FIXME("(%p)\n", This);
1062     return E_NOTIMPL;
1063 }
1064
1065 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1066 {
1067     HTMLDocument *This = HTMLDOC_THIS(iface);
1068     FIXME("(%p)->(%p)\n", This, p);
1069     return E_NOTIMPL;
1070 }
1071
1072 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1073 {
1074     HTMLDocument *This = HTMLDOC_THIS(iface);
1075
1076     TRACE("(%p)\n", This);
1077
1078     return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1079 }
1080
1081 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1082 {
1083     HTMLDocument *This = HTMLDOC_THIS(iface);
1084
1085     TRACE("(%p)->(%p)\n", This, p);
1086
1087     return get_doc_event(This, EVENTID_MOUSEOVER, p);
1088 }
1089
1090 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1091 {
1092     HTMLDocument *This = HTMLDOC_THIS(iface);
1093     FIXME("(%p)\n", This);
1094     return E_NOTIMPL;
1095 }
1096
1097 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1098 {
1099     HTMLDocument *This = HTMLDOC_THIS(iface);
1100     FIXME("(%p)->(%p)\n", This, p);
1101     return E_NOTIMPL;
1102 }
1103
1104 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1105 {
1106     HTMLDocument *This = HTMLDOC_THIS(iface);
1107     FIXME("(%p)\n", This);
1108     return E_NOTIMPL;
1109 }
1110
1111 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1112 {
1113     HTMLDocument *This = HTMLDOC_THIS(iface);
1114     FIXME("(%p)->(%p)\n", This, p);
1115     return E_NOTIMPL;
1116 }
1117
1118 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1119 {
1120     HTMLDocument *This = HTMLDOC_THIS(iface);
1121     FIXME("(%p)\n", This);
1122     return E_NOTIMPL;
1123 }
1124
1125 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1126 {
1127     HTMLDocument *This = HTMLDOC_THIS(iface);
1128     FIXME("(%p)->(%p)\n", This, p);
1129     return E_NOTIMPL;
1130 }
1131
1132 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1133 {
1134     HTMLDocument *This = HTMLDOC_THIS(iface);
1135     FIXME("(%p)\n", This);
1136     return E_NOTIMPL;
1137 }
1138
1139 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1140 {
1141     HTMLDocument *This = HTMLDOC_THIS(iface);
1142     FIXME("(%p)->(%p)\n", This, p);
1143     return E_NOTIMPL;
1144 }
1145
1146 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1147 {
1148     HTMLDocument *This = HTMLDOC_THIS(iface);
1149     FIXME("(%p)\n", This);
1150     return E_NOTIMPL;
1151 }
1152
1153 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1154 {
1155     HTMLDocument *This = HTMLDOC_THIS(iface);
1156     FIXME("(%p)->(%p)\n", This, p);
1157     return E_NOTIMPL;
1158 }
1159
1160 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1161 {
1162     HTMLDocument *This = HTMLDOC_THIS(iface);
1163     FIXME("(%p)\n", This);
1164     return E_NOTIMPL;
1165 }
1166
1167 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1168 {
1169     HTMLDocument *This = HTMLDOC_THIS(iface);
1170     FIXME("(%p)->(%p)\n", This, p);
1171     return E_NOTIMPL;
1172 }
1173
1174 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, long x, long y,
1175                                                         IHTMLElement **elementHit)
1176 {
1177     HTMLDocument *This = HTMLDOC_THIS(iface);
1178     FIXME("(%p)->(%ld %ld %p)\n", This, x, y, elementHit);
1179     return E_NOTIMPL;
1180 }
1181
1182 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1183 {
1184     HTMLDocument *This = HTMLDOC_THIS(iface);
1185
1186     TRACE("(%p)->(%p)\n", This, p);
1187
1188     *p = HTMLWINDOW2(This->window);
1189     IHTMLWindow2_AddRef(*p);
1190     return S_OK;
1191 }
1192
1193 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1194                                                    IHTMLStyleSheetsCollection **p)
1195 {
1196     HTMLDocument *This = HTMLDOC_THIS(iface);
1197     nsIDOMStyleSheetList *nsstylelist;
1198     nsIDOMDocumentStyle *nsdocstyle;
1199     nsresult nsres;
1200
1201     TRACE("(%p)->(%p)\n", This, p);
1202
1203     *p = NULL;
1204
1205     if(!This->nsdoc) {
1206         WARN("NULL nsdoc\n");
1207         return E_UNEXPECTED;
1208     }
1209
1210     nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMDocumentStyle, (void**)&nsdocstyle);
1211     nsres = nsIDOMDocumentStyle_GetStyleSheets(nsdocstyle, &nsstylelist);
1212     nsIDOMDocumentStyle_Release(nsdocstyle);
1213     if(NS_FAILED(nsres)) {
1214         ERR("GetStyleSheets failed: %08x\n", nsres);
1215         return E_FAIL;
1216     }
1217
1218     *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1219     nsIDOMDocumentStyle_Release(nsstylelist);
1220
1221     return S_OK;
1222 }
1223
1224 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1225 {
1226     HTMLDocument *This = HTMLDOC_THIS(iface);
1227     FIXME("(%p)\n", This);
1228     return E_NOTIMPL;
1229 }
1230
1231 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1232 {
1233     HTMLDocument *This = HTMLDOC_THIS(iface);
1234     FIXME("(%p)->(%p)\n", This, p);
1235     return E_NOTIMPL;
1236 }
1237
1238 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1239 {
1240     HTMLDocument *This = HTMLDOC_THIS(iface);
1241     FIXME("(%p)\n", This);
1242     return E_NOTIMPL;
1243 }
1244
1245 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1246 {
1247     HTMLDocument *This = HTMLDOC_THIS(iface);
1248     FIXME("(%p)->(%p)\n", This, p);
1249     return E_NOTIMPL;
1250 }
1251
1252 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1253 {
1254     HTMLDocument *This = HTMLDOC_THIS(iface);
1255     FIXME("(%p)->(%p)\n", This, String);
1256     return E_NOTIMPL;
1257 }
1258
1259 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1260                                             long lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1261 {
1262     HTMLDocument *This = HTMLDOC_THIS(iface);
1263
1264     FIXME("(%p)->(%s %ld %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1265
1266     *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1267     return S_OK;
1268 }
1269
1270 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1271     HTMLDocument_QueryInterface,
1272     HTMLDocument_AddRef,
1273     HTMLDocument_Release,
1274     HTMLDocument_GetTypeInfoCount,
1275     HTMLDocument_GetTypeInfo,
1276     HTMLDocument_GetIDsOfNames,
1277     HTMLDocument_Invoke,
1278     HTMLDocument_get_Script,
1279     HTMLDocument_get_all,
1280     HTMLDocument_get_body,
1281     HTMLDocument_get_activeElement,
1282     HTMLDocument_get_images,
1283     HTMLDocument_get_applets,
1284     HTMLDocument_get_links,
1285     HTMLDocument_get_forms,
1286     HTMLDocument_get_anchors,
1287     HTMLDocument_put_title,
1288     HTMLDocument_get_title,
1289     HTMLDocument_get_scripts,
1290     HTMLDocument_put_designMode,
1291     HTMLDocument_get_designMode,
1292     HTMLDocument_get_selection,
1293     HTMLDocument_get_readyState,
1294     HTMLDocument_get_frames,
1295     HTMLDocument_get_embeds,
1296     HTMLDocument_get_plugins,
1297     HTMLDocument_put_alinkColor,
1298     HTMLDocument_get_alinkColor,
1299     HTMLDocument_put_bgColor,
1300     HTMLDocument_get_bgColor,
1301     HTMLDocument_put_fgColor,
1302     HTMLDocument_get_fgColor,
1303     HTMLDocument_put_linkColor,
1304     HTMLDocument_get_linkColor,
1305     HTMLDocument_put_vlinkColor,
1306     HTMLDocument_get_vlinkColor,
1307     HTMLDocument_get_referrer,
1308     HTMLDocument_get_location,
1309     HTMLDocument_get_lastModified,
1310     HTMLDocument_put_URL,
1311     HTMLDocument_get_URL,
1312     HTMLDocument_put_domain,
1313     HTMLDocument_get_domain,
1314     HTMLDocument_put_cookie,
1315     HTMLDocument_get_cookie,
1316     HTMLDocument_put_expando,
1317     HTMLDocument_get_expando,
1318     HTMLDocument_put_charset,
1319     HTMLDocument_get_charset,
1320     HTMLDocument_put_defaultCharset,
1321     HTMLDocument_get_defaultCharset,
1322     HTMLDocument_get_mimeType,
1323     HTMLDocument_get_fileSize,
1324     HTMLDocument_get_fileCreatedDate,
1325     HTMLDocument_get_fileModifiedDate,
1326     HTMLDocument_get_fileUpdatedDate,
1327     HTMLDocument_get_security,
1328     HTMLDocument_get_protocol,
1329     HTMLDocument_get_nameProp,
1330     HTMLDocument_write,
1331     HTMLDocument_writeln,
1332     HTMLDocument_open,
1333     HTMLDocument_close,
1334     HTMLDocument_clear,
1335     HTMLDocument_queryCommandSupported,
1336     HTMLDocument_queryCommandEnabled,
1337     HTMLDocument_queryCommandState,
1338     HTMLDocument_queryCommandIndeterm,
1339     HTMLDocument_queryCommandText,
1340     HTMLDocument_queryCommandValue,
1341     HTMLDocument_execCommand,
1342     HTMLDocument_execCommandShowHelp,
1343     HTMLDocument_createElement,
1344     HTMLDocument_put_onhelp,
1345     HTMLDocument_get_onhelp,
1346     HTMLDocument_put_onclick,
1347     HTMLDocument_get_onclick,
1348     HTMLDocument_put_ondblclick,
1349     HTMLDocument_get_ondblclick,
1350     HTMLDocument_put_onkeyup,
1351     HTMLDocument_get_onkeyup,
1352     HTMLDocument_put_onkeydown,
1353     HTMLDocument_get_onkeydown,
1354     HTMLDocument_put_onkeypress,
1355     HTMLDocument_get_onkeypress,
1356     HTMLDocument_put_onmouseup,
1357     HTMLDocument_get_onmouseup,
1358     HTMLDocument_put_onmousedown,
1359     HTMLDocument_get_onmousedown,
1360     HTMLDocument_put_onmousemove,
1361     HTMLDocument_get_onmousemove,
1362     HTMLDocument_put_onmouseout,
1363     HTMLDocument_get_onmouseout,
1364     HTMLDocument_put_onmouseover,
1365     HTMLDocument_get_onmouseover,
1366     HTMLDocument_put_onreadystatechange,
1367     HTMLDocument_get_onreadystatechange,
1368     HTMLDocument_put_onafterupdate,
1369     HTMLDocument_get_onafterupdate,
1370     HTMLDocument_put_onrowexit,
1371     HTMLDocument_get_onrowexit,
1372     HTMLDocument_put_onrowenter,
1373     HTMLDocument_get_onrowenter,
1374     HTMLDocument_put_ondragstart,
1375     HTMLDocument_get_ondragstart,
1376     HTMLDocument_put_onselectstart,
1377     HTMLDocument_get_onselectstart,
1378     HTMLDocument_elementFromPoint,
1379     HTMLDocument_get_parentWindow,
1380     HTMLDocument_get_styleSheets,
1381     HTMLDocument_put_onbeforeupdate,
1382     HTMLDocument_get_onbeforeupdate,
1383     HTMLDocument_put_onerrorupdate,
1384     HTMLDocument_get_onerrorupdate,
1385     HTMLDocument_toString,
1386     HTMLDocument_createStyleSheet
1387 };
1388
1389 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLDocument, IDispatchEx, iface)
1390
1391 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1392 {
1393     HTMLDocument *This = DISPEX_THIS(iface);
1394
1395     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
1396 }
1397
1398 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1399 {
1400     HTMLDocument *This = DISPEX_THIS(iface);
1401
1402     return IHTMLDocument2_AddRef(HTMLDOC(This));
1403 }
1404
1405 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1406 {
1407     HTMLDocument *This = DISPEX_THIS(iface);
1408
1409     return IHTMLDocument2_Release(HTMLDOC(This));
1410 }
1411
1412 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1413 {
1414     HTMLDocument *This = DISPEX_THIS(iface);
1415
1416     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1417 }
1418
1419 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1420                                                LCID lcid, ITypeInfo **ppTInfo)
1421 {
1422     HTMLDocument *This = DISPEX_THIS(iface);
1423
1424     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1425 }
1426
1427 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1428                                                  LPOLESTR *rgszNames, UINT cNames,
1429                                                  LCID lcid, DISPID *rgDispId)
1430 {
1431     HTMLDocument *This = DISPEX_THIS(iface);
1432
1433     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
1434 }
1435
1436 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1437                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1438                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1439 {
1440     HTMLDocument *This = DISPEX_THIS(iface);
1441
1442     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1443           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1444
1445     switch(dispIdMember) {
1446     case DISPID_READYSTATE:
1447         TRACE("DISPID_READYSTATE\n");
1448
1449         if(!(wFlags & DISPATCH_PROPERTYGET))
1450             return E_INVALIDARG;
1451
1452         V_VT(pVarResult) = VT_I4;
1453         V_I4(pVarResult) = This->readystate;
1454         return S_OK;
1455     }
1456
1457     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1458                               pVarResult, pExcepInfo, puArgErr);
1459 }
1460
1461 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1462 {
1463     HTMLDocument *This = DISPEX_THIS(iface);
1464
1465     return IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1466 }
1467
1468 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1469         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1470 {
1471     HTMLDocument *This = DISPEX_THIS(iface);
1472
1473     return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1474 }
1475
1476 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1477 {
1478     HTMLDocument *This = DISPEX_THIS(iface);
1479
1480     return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
1481 }
1482
1483 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1484 {
1485     HTMLDocument *This = DISPEX_THIS(iface);
1486
1487     return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
1488 }
1489
1490 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1491 {
1492     HTMLDocument *This = DISPEX_THIS(iface);
1493
1494     return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
1495 }
1496
1497 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1498 {
1499     HTMLDocument *This = DISPEX_THIS(iface);
1500
1501     return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
1502 }
1503
1504 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1505 {
1506     HTMLDocument *This = DISPEX_THIS(iface);
1507
1508     return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
1509 }
1510
1511 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1512 {
1513     HTMLDocument *This = DISPEX_THIS(iface);
1514
1515     return IDispatchEx_GetNameSpaceParent(DISPATCHEX(&This->dispex), ppunk);
1516 }
1517
1518 #undef DISPEX_THIS
1519
1520 static const IDispatchExVtbl DocDispatchExVtbl = {
1521     DocDispatchEx_QueryInterface,
1522     DocDispatchEx_AddRef,
1523     DocDispatchEx_Release,
1524     DocDispatchEx_GetTypeInfoCount,
1525     DocDispatchEx_GetTypeInfo,
1526     DocDispatchEx_GetIDsOfNames,
1527     DocDispatchEx_Invoke,
1528     DocDispatchEx_GetDispID,
1529     DocDispatchEx_InvokeEx,
1530     DocDispatchEx_DeleteMemberByName,
1531     DocDispatchEx_DeleteMemberByDispID,
1532     DocDispatchEx_GetMemberProperties,
1533     DocDispatchEx_GetMemberName,
1534     DocDispatchEx_GetNextDispID,
1535     DocDispatchEx_GetNameSpaceParent
1536 };
1537
1538 static const tid_t HTMLDocument_iface_tids[] = {
1539     IHTMLDocument2_tid,
1540     IHTMLDocument3_tid,
1541     IHTMLDocument4_tid,
1542     IHTMLDocument5_tid,
1543     0
1544 };
1545 static dispex_static_data_t HTMLDocument_dispex = {
1546     NULL,
1547     DispHTMLDocument_tid,
1548     NULL,
1549     HTMLDocument_iface_tids
1550 };
1551
1552 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
1553 {
1554     nsIDOMWindow *nswindow;
1555     HTMLDocument *ret;
1556     HRESULT hres;
1557
1558     TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
1559
1560     ret = heap_alloc_zero(sizeof(HTMLDocument));
1561     ret->lpHTMLDocument2Vtbl = &HTMLDocumentVtbl;
1562     ret->lpIDispatchExVtbl = &DocDispatchExVtbl;
1563     ret->ref = 0;
1564     ret->readystate = READYSTATE_UNINITIALIZED;
1565     ret->scriptmode = SCRIPTMODE_GECKO;
1566
1567     list_init(&ret->bindings);
1568     list_init(&ret->script_hosts);
1569     list_init(&ret->selection_list);
1570     list_init(&ret->range_list);
1571
1572     hres = IHTMLDocument_QueryInterface(HTMLDOC(ret), riid, ppvObject);
1573     if(FAILED(hres)) {
1574         heap_free(ret);
1575         return hres;
1576     }
1577
1578     LOCK_MODULE();
1579
1580     HTMLDocument_HTMLDocument3_Init(ret);
1581     HTMLDocument_HTMLDocument5_Init(ret);
1582     HTMLDocument_Persist_Init(ret);
1583     HTMLDocument_OleCmd_Init(ret);
1584     HTMLDocument_OleObj_Init(ret);
1585     HTMLDocument_View_Init(ret);
1586     HTMLDocument_Window_Init(ret);
1587     HTMLDocument_Service_Init(ret);
1588     HTMLDocument_Hlink_Init(ret);
1589
1590     ConnectionPointContainer_Init(&ret->cp_container, (IUnknown*)HTMLDOC(ret));
1591     ConnectionPoint_Init(&ret->cp_propnotif, &ret->cp_container, &IID_IPropertyNotifySink);
1592     ConnectionPoint_Init(&ret->cp_htmldocevents, &ret->cp_container, &DIID_HTMLDocumentEvents);
1593     ConnectionPoint_Init(&ret->cp_htmldocevents2, &ret->cp_container, &DIID_HTMLDocumentEvents2);
1594
1595     init_dispex(&ret->dispex, (IUnknown*)HTMLDOC(ret), &HTMLDocument_dispex);
1596
1597     ret->nscontainer = NSContainer_Create(ret, NULL);
1598     update_nsdocument(ret);
1599
1600     if(ret->nscontainer)
1601         nsIWebBrowser_GetContentDOMWindow(ret->nscontainer->webbrowser, &nswindow);
1602
1603     HTMLWindow_Create(ret, nswindow, &ret->window);
1604     if(nswindow)
1605         nsIDOMWindow_Release(nswindow);
1606
1607     get_thread_hwnd();
1608
1609     return hres;
1610 }