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