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