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