mshtml: Added DOCUMENT_NODE type support.
[wine] / dlls / mshtml / htmlwindow.c
1 /*
2  * Copyright 2006 Jacek Caban for CodeWeavers
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 <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "wine/debug.h"
29 #include "wine/unicode.h"
30
31 #include "mshtml_private.h"
32 #include "resource.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35
36 static struct list window_list = LIST_INIT(window_list);
37
38 #define HTMLWINDOW2_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow2, iface)
39
40 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
41 {
42     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
43
44     *ppv = NULL;
45
46     if(IsEqualGUID(&IID_IUnknown, riid)) {
47         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
48         *ppv = HTMLWINDOW2(This);
49     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
50         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
51         *ppv = HTMLWINDOW2(This);
52     }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
53         TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
54         *ppv = DISPATCHEX(This);
55     }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
56         TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
57         *ppv = HTMLWINDOW2(This);
58     }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
59         TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
60         *ppv = HTMLWINDOW2(This);
61     }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
62         TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
63         *ppv = HTMLWINDOW3(This);
64     }
65
66     if(*ppv) {
67         IUnknown_AddRef((IUnknown*)*ppv);
68         return S_OK;
69     }
70
71     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
72     return E_NOINTERFACE;
73 }
74
75 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
76 {
77     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
78     LONG ref = InterlockedIncrement(&This->ref);
79
80     TRACE("(%p) ref=%d\n", This, ref);
81
82     return ref;
83 }
84
85 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
86 {
87     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
88     LONG ref = InterlockedDecrement(&This->ref);
89
90     TRACE("(%p) ref=%d\n", This, ref);
91
92     if(!ref) {
93         list_remove(&This->entry);
94         heap_free(This);
95     }
96
97     return ref;
98 }
99
100 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
101 {
102     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
103
104     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
105 }
106
107 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
108                                               LCID lcid, ITypeInfo **ppTInfo)
109 {
110     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
111
112     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
113 }
114
115 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
116                                                 LPOLESTR *rgszNames, UINT cNames,
117                                                 LCID lcid, DISPID *rgDispId)
118 {
119     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
120
121     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
122 }
123
124 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
125                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
126                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
127 {
128     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
129
130     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
131             pVarResult, pExcepInfo, puArgErr);
132 }
133
134 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
135 {
136     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
137     FIXME("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
138     return E_NOTIMPL;
139 }
140
141 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, long *p)
142 {
143     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
144     FIXME("(%p)->(%p)\n", This, p);
145     return E_NOTIMPL;
146 }
147
148 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
149 {
150     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
151     FIXME("(%p)->(%p)\n", This, p);
152     return E_NOTIMPL;
153 }
154
155 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
156 {
157     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
158     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
159     return E_NOTIMPL;
160 }
161
162 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
163 {
164     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
165     FIXME("(%p)->(%p)\n", This, p);
166     return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
170 {
171     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
172     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
177 {
178     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
179     FIXME("(%p)->(%p)\n", This, p);
180     return E_NOTIMPL;
181 }
182
183 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
184         long msec, VARIANT *language, long *timerID)
185 {
186     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
187     VARIANT expr_var;
188
189     TRACE("(%p)->(%s %ld %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
190
191     V_VT(&expr_var) = VT_BSTR;
192     V_BSTR(&expr_var) = expression;
193
194     return IHTMLWindow3_setTimeout(HTMLWINDOW3(This), &expr_var, msec, language, timerID);
195 }
196
197 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, long timerID)
198 {
199     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
200     FIXME("(%p)->(%ld)\n", This, timerID);
201     return E_NOTIMPL;
202 }
203
204 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
205 {
206     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
207     WCHAR wszTitle[100];
208
209     TRACE("(%p)->(%s)\n", This, debugstr_w(message));
210
211     if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
212                     sizeof(wszTitle)/sizeof(WCHAR))) {
213         WARN("Could not load message box title: %d\n", GetLastError());
214         return S_OK;
215     }
216
217     MessageBoxW(This->doc->hwnd, message, wszTitle, MB_ICONWARNING);
218     return S_OK;
219 }
220
221 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
222         VARIANT_BOOL *confirmed)
223 {
224     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
225     FIXME("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
226     return E_NOTIMPL;
227 }
228
229 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
230         BSTR dststr, VARIANT *textdata)
231 {
232     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
233     FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
234     return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
238 {
239     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
240     FIXME("(%p)->(%p)\n", This, p);
241     return E_NOTIMPL;
242 }
243
244 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
245 {
246     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
247     FIXME("(%p)->(%p)\n", This, p);
248     return E_NOTIMPL;
249 }
250
251 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
252 {
253     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
254     FIXME("(%p)->(%p)\n", This, p);
255     return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
259 {
260     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
261     FIXME("(%p)->()\n", This);
262     return E_NOTIMPL;
263 }
264
265 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
266 {
267     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
268     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
269     return E_NOTIMPL;
270 }
271
272 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
273 {
274     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
275     FIXME("(%p)->(%p)\n", This, p);
276     return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
280 {
281     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
282
283     TRACE("(%p)->(%p)\n", This, p);
284
285     *p = OmNavigator_Create();
286     return S_OK;
287 }
288
289 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
290 {
291     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
292     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
293     return E_NOTIMPL;
294 }
295
296 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
297 {
298     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
299     FIXME("(%p)->(%p)\n", This, p);
300     return E_NOTIMPL;
301 }
302
303 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
304 {
305     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
306     FIXME("(%p)->(%p)\n", This, p);
307     return E_NOTIMPL;
308 }
309
310 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
311          BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
312 {
313     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
314     FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
315           debugstr_w(features), replace, pomWindowResult);
316     return E_NOTIMPL;
317 }
318
319 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
320 {
321     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
322     FIXME("(%p)->(%p)\n", This, p);
323     return E_NOTIMPL;
324 }
325
326 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
327 {
328     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
329     FIXME("(%p)->(%p)\n", This, p);
330     return E_NOTIMPL;
331 }
332
333 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
334 {
335     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
336     FIXME("(%p)->(%p)\n", This, p);
337     return E_NOTIMPL;
338 }
339
340 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
341 {
342     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
343     FIXME("(%p)->(%s)\n", This, debugstr_w(url));
344     return E_NOTIMPL;
345 }
346
347 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
348 {
349     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
350     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
351     return E_NOTIMPL;
352 }
353
354 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
355 {
356     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
357     FIXME("(%p)->(%p)\n", This, p);
358     return E_NOTIMPL;
359 }
360
361 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
362 {
363     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
364     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
365     return E_NOTIMPL;
366 }
367
368 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
369 {
370     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
371     FIXME("(%p)->(%p)\n", This, p);
372     return E_NOTIMPL;
373 }
374
375 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
376 {
377     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
378     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
379     return E_NOTIMPL;
380 }
381
382 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
383 {
384     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
385     FIXME("(%p)->(%p)\n", This, p);
386     return E_NOTIMPL;
387 }
388
389 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
390 {
391     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
392     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
393     return E_NOTIMPL;
394 }
395
396 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
397 {
398     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
399     FIXME("(%p)->(%p)\n", This, p);
400     return E_NOTIMPL;
401 }
402
403 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
404 {
405     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
406     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
407     return E_NOTIMPL;
408 }
409
410 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
411 {
412     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
413     FIXME("(%p)->(%p)\n", This, p);
414     return E_NOTIMPL;
415 }
416
417 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
418 {
419     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
420     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
421     return E_NOTIMPL;
422 }
423
424 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
425 {
426     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
427     FIXME("(%p)->(%p)\n", This, p);
428     return E_NOTIMPL;
429 }
430
431 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
432 {
433     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
434     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
435     return E_NOTIMPL;
436 }
437
438 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
439 {
440     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
441     FIXME("(%p)->(%p)\n", This, p);
442     return E_NOTIMPL;
443 }
444
445 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
446 {
447     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
448     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
449     return E_NOTIMPL;
450 }
451
452 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
453 {
454     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
455     FIXME("(%p)->(%p)\n", This, p);
456     return E_NOTIMPL;
457 }
458
459 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
460 {
461     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
462     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
463     return E_NOTIMPL;
464 }
465
466 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
467 {
468     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
469     FIXME("(%p)->(%p)\n", This, p);
470     return E_NOTIMPL;
471 }
472
473 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
474 {
475     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
476
477     TRACE("(%p)->(%p)\n", This, p);
478
479     if(This->doc) {
480         /* FIXME: We should return a wrapper object here */
481         *p = HTMLDOC(This->doc);
482         IHTMLDocument2_AddRef(*p);
483     }else {
484         *p = NULL;
485     }
486
487     return S_OK;
488 }
489
490 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
491 {
492     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
493     FIXME("(%p)->(%p)\n", This, p);
494     return E_NOTIMPL;
495 }
496
497 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
498 {
499     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
500     FIXME("(%p)->(%p)\n", This, p);
501     return E_NOTIMPL;
502 }
503
504 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
505         VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
506 {
507     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
508     FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
509     return E_NOTIMPL;
510 }
511
512 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
513         BSTR features)
514 {
515     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
516     FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
517     return E_NOTIMPL;
518 }
519
520 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
521 {
522     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
523     FIXME("(%p)->(%p)\n", This, p);
524     return E_NOTIMPL;
525 }
526
527 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
528 {
529     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
530
531     TRACE("(%p)->(%p)\n", This, p);
532
533     if(!This->doc->option_factory)
534         This->doc->option_factory = HTMLOptionElementFactory_Create(This->doc);
535
536     *p = HTMLOPTFACTORY(This->doc->option_factory);
537     IHTMLOptionElementFactory_AddRef(*p);
538
539     return S_OK;
540 }
541
542 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
543 {
544     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
545     FIXME("(%p)->()\n", This);
546     return E_NOTIMPL;
547 }
548
549 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
550 {
551     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
552     FIXME("(%p)->(%p)\n", This, p);
553     return E_NOTIMPL;
554 }
555
556 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
557 {
558     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
559     FIXME("(%p)->()\n", This);
560     return E_NOTIMPL;
561 }
562
563 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, long x, long y)
564 {
565     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
566     FIXME("(%p)->(%ld %ld)\n", This, x, y);
567     return E_NOTIMPL;
568 }
569
570 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
571 {
572     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
573     FIXME("(%p)->(%p)\n", This, p);
574     return E_NOTIMPL;
575 }
576
577 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
578         long msec, VARIANT *language, long *timerID)
579 {
580     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
581     FIXME("(%p)->(%s %ld %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
582     return E_NOTIMPL;
583 }
584
585 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, long timerID)
586 {
587     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
588     FIXME("(%p)->(%ld)\n", This, timerID);
589     return E_NOTIMPL;
590 }
591
592 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
593 {
594     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
595     FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
596     return E_NOTIMPL;
597 }
598
599 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
600 {
601     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
602     FIXME("(%p)->(%p)\n", This, p);
603     return E_NOTIMPL;
604 }
605
606 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
607         VARIANT *pvarRet)
608 {
609     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
610     FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
611     return E_NOTIMPL;
612 }
613
614 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
615 {
616     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
617     FIXME("(%p)->(%p)\n", This, String);
618     return E_NOTIMPL;
619 }
620
621 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, long x, long y)
622 {
623     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
624     FIXME("(%p)->(%ld %ld)\n", This, x, y);
625     return E_NOTIMPL;
626 }
627
628 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, long x, long y)
629 {
630     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
631     FIXME("(%p)->(%ld %ld)\n", This, x, y);
632     return E_NOTIMPL;
633 }
634
635 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, long x, long y)
636 {
637     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
638     FIXME("(%p)->(%ld %ld)\n", This, x, y);
639     return E_NOTIMPL;
640 }
641
642 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, long x, long y)
643 {
644     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
645     FIXME("(%p)->(%ld %ld)\n", This, x, y);
646     return E_NOTIMPL;
647 }
648
649 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, long x, long y)
650 {
651     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
652     FIXME("(%p)->(%ld %ld)\n", This, x, y);
653     return E_NOTIMPL;
654 }
655
656 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, long x, long y)
657 {
658     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
659     FIXME("(%p)->(%ld %ld)\n", This, x, y);
660     return E_NOTIMPL;
661 }
662
663 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
664 {
665     HTMLWindow *This = HTMLWINDOW2_THIS(iface);
666
667     TRACE("(%p)->(%p)\n", This, p);
668
669     *p = NULL;
670
671     if(!This->doc->hostui)
672         return S_OK;
673
674     return IDocHostUIHandler_GetExternal(This->doc->hostui, p);
675 }
676
677 #undef HTMLWINDOW2_THIS
678
679 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
680     HTMLWindow2_QueryInterface,
681     HTMLWindow2_AddRef,
682     HTMLWindow2_Release,
683     HTMLWindow2_GetTypeInfoCount,
684     HTMLWindow2_GetTypeInfo,
685     HTMLWindow2_GetIDsOfNames,
686     HTMLWindow2_Invoke,
687     HTMLWindow2_item,
688     HTMLWindow2_get_length,
689     HTMLWindow2_get_frames,
690     HTMLWindow2_put_defaultStatus,
691     HTMLWindow2_get_defaultStatus,
692     HTMLWindow2_put_status,
693     HTMLWindow2_get_status,
694     HTMLWindow2_setTimeout,
695     HTMLWindow2_clearTimeout,
696     HTMLWindow2_alert,
697     HTMLWindow2_confirm,
698     HTMLWindow2_prompt,
699     HTMLWindow2_get_Image,
700     HTMLWindow2_get_location,
701     HTMLWindow2_get_history,
702     HTMLWindow2_close,
703     HTMLWindow2_put_opener,
704     HTMLWindow2_get_opener,
705     HTMLWindow2_get_navigator,
706     HTMLWindow2_put_name,
707     HTMLWindow2_get_name,
708     HTMLWindow2_get_parent,
709     HTMLWindow2_open,
710     HTMLWindow2_get_self,
711     HTMLWindow2_get_top,
712     HTMLWindow2_get_window,
713     HTMLWindow2_navigate,
714     HTMLWindow2_put_onfocus,
715     HTMLWindow2_get_onfocus,
716     HTMLWindow2_put_onblur,
717     HTMLWindow2_get_onblur,
718     HTMLWindow2_put_onload,
719     HTMLWindow2_get_onload,
720     HTMLWindow2_put_onbeforeunload,
721     HTMLWindow2_get_onbeforeunload,
722     HTMLWindow2_put_onunload,
723     HTMLWindow2_get_onunload,
724     HTMLWindow2_put_onhelp,
725     HTMLWindow2_get_onhelp,
726     HTMLWindow2_put_onerror,
727     HTMLWindow2_get_onerror,
728     HTMLWindow2_put_onresize,
729     HTMLWindow2_get_onresize,
730     HTMLWindow2_put_onscroll,
731     HTMLWindow2_get_onscroll,
732     HTMLWindow2_get_document,
733     HTMLWindow2_get_event,
734     HTMLWindow2_get__newEnum,
735     HTMLWindow2_showModalDialog,
736     HTMLWindow2_showHelp,
737     HTMLWindow2_get_screen,
738     HTMLWindow2_get_Option,
739     HTMLWindow2_focus,
740     HTMLWindow2_get_closed,
741     HTMLWindow2_blur,
742     HTMLWindow2_scroll,
743     HTMLWindow2_get_clientInformation,
744     HTMLWindow2_setInterval,
745     HTMLWindow2_clearInterval,
746     HTMLWindow2_put_offscreenBuffering,
747     HTMLWindow2_get_offscreenBuffering,
748     HTMLWindow2_execScript,
749     HTMLWindow2_toString,
750     HTMLWindow2_scrollBy,
751     HTMLWindow2_scrollTo,
752     HTMLWindow2_moveTo,
753     HTMLWindow2_moveBy,
754     HTMLWindow2_resizeTo,
755     HTMLWindow2_resizeBy,
756     HTMLWindow2_get_external
757 };
758
759 #define HTMLWINDOW3_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow3, iface)
760
761 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
762 {
763     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
764
765     return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
766 }
767
768 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
769 {
770     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
771
772     return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
773 }
774
775 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
776 {
777     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
778
779     return IHTMLWindow2_Release(HTMLWINDOW2(This));
780 }
781
782 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
783 {
784     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
785
786     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
787 }
788
789 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
790                                               LCID lcid, ITypeInfo **ppTInfo)
791 {
792     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
793
794     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
795 }
796
797 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
798                                                 LPOLESTR *rgszNames, UINT cNames,
799                                                 LCID lcid, DISPID *rgDispId)
800 {
801     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
802
803     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
804 }
805
806 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
807                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
808                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
809 {
810     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
811
812     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
813             pVarResult, pExcepInfo, puArgErr);
814 }
815
816 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, long *p)
817 {
818     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
819     FIXME("(%p)->(%p)\n", This, p);
820     return E_NOTIMPL;
821 }
822
823 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, long *p)
824 {
825     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
826     FIXME("(%p)->(%p)\n", This, p);
827     return E_NOTIMPL;
828 }
829
830 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
831 {
832     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
833     FIXME("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
834     return E_NOTIMPL;
835 }
836
837 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
838 {
839     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
840     FIXME("(%p)->()\n", This);
841     return E_NOTIMPL;
842 }
843
844 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, long msec,
845         VARIANT *language, long *timerID)
846 {
847     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
848
849     TRACE("(%p)->(%p(%d) %ld %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
850
851     switch(V_VT(expression)) {
852     case VT_DISPATCH:
853         *timerID = set_task_timer(This->doc, msec, V_DISPATCH(expression));
854         break;
855
856     default:
857         FIXME("unimplemented vt=%d\n", V_VT(expression));
858     }
859
860     return S_OK;
861 }
862
863 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, long msec,
864         VARIANT *language, long *timerID)
865 {
866     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
867     FIXME("(%p)->(%p %ld %p %p)\n", This, expression, msec, language, timerID);
868     return E_NOTIMPL;
869 }
870
871 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
872 {
873     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
874     FIXME("(%p)\n", This);
875     return E_NOTIMPL;
876 }
877
878 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
879 {
880     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
881     FIXME("(%p)->()\n", This);
882     return E_NOTIMPL;
883 }
884
885 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
886 {
887     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
888     FIXME("(%p)->(%p)\n", This, p);
889     return E_NOTIMPL;
890 }
891
892 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
893 {
894     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
895     FIXME("(%p)->()\n", This);
896     return E_NOTIMPL;
897 }
898
899 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
900 {
901     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
902     FIXME("(%p)->(%p)\n", This, p);
903     return E_NOTIMPL;
904 }
905
906 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
907 {
908     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
909     FIXME("(%p)->(%p)\n", This, p);
910     return E_NOTIMPL;
911 }
912
913 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
914         VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
915 {
916     HTMLWindow *This = HTMLWINDOW3_THIS(iface);
917     FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
918     return E_NOTIMPL;
919 }
920
921 #undef HTMLWINDOW3_THIS
922
923 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
924     HTMLWindow3_QueryInterface,
925     HTMLWindow3_AddRef,
926     HTMLWindow3_Release,
927     HTMLWindow3_GetTypeInfoCount,
928     HTMLWindow3_GetTypeInfo,
929     HTMLWindow3_GetIDsOfNames,
930     HTMLWindow3_Invoke,
931     HTMLWindow3_get_screenLeft,
932     HTMLWindow3_get_screenTop,
933     HTMLWindow3_attachEvent,
934     HTMLWindow3_detachEvent,
935     HTMLWindow3_setTimeout,
936     HTMLWindow3_setInterval,
937     HTMLWindow3_print,
938     HTMLWindow3_put_onbeforeprint,
939     HTMLWindow3_get_onbeforeprint,
940     HTMLWindow3_put_onafterprint,
941     HTMLWindow3_get_onafterprint,
942     HTMLWindow3_get_clipboardData,
943     HTMLWindow3_showModelessDialog
944 };
945
946 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLWindow, IDispatchEx, iface)
947
948 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
949 {
950     HTMLWindow *This = DISPEX_THIS(iface);
951
952     return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
953 }
954
955 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
956 {
957     HTMLWindow *This = DISPEX_THIS(iface);
958
959     return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
960 }
961
962 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
963 {
964     HTMLWindow *This = DISPEX_THIS(iface);
965
966     return IHTMLWindow2_Release(HTMLWINDOW2(This));
967 }
968
969 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
970 {
971     HTMLWindow *This = DISPEX_THIS(iface);
972
973     TRACE("(%p)->(%p)\n", This, pctinfo);
974
975     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
976 }
977
978 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
979                                                LCID lcid, ITypeInfo **ppTInfo)
980 {
981     HTMLWindow *This = DISPEX_THIS(iface);
982
983     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
984
985     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
986 }
987
988 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
989                                                  LPOLESTR *rgszNames, UINT cNames,
990                                                  LCID lcid, DISPID *rgDispId)
991 {
992     HTMLWindow *This = DISPEX_THIS(iface);
993
994     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
995           lcid, rgDispId);
996
997     /* FIXME: Use script dispatch */
998
999     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
1000 }
1001
1002 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1003                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1004                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1005 {
1006     HTMLWindow *This = DISPEX_THIS(iface);
1007
1008     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1009           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1010
1011     /* FIXME: Use script dispatch */
1012
1013     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1014                               pVarResult, pExcepInfo, puArgErr);
1015 }
1016
1017 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1018 {
1019     HTMLWindow *This = DISPEX_THIS(iface);
1020
1021     TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1022
1023     return IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1024 }
1025
1026 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1027         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1028 {
1029     HTMLWindow *This = DISPEX_THIS(iface);
1030
1031     TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1032
1033     return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1034 }
1035
1036 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1037 {
1038     HTMLWindow *This = DISPEX_THIS(iface);
1039
1040     TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
1041
1042     return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
1043 }
1044
1045 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1046 {
1047     HTMLWindow *This = DISPEX_THIS(iface);
1048
1049     TRACE("(%p)->(%x)\n", This, id);
1050
1051     return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
1052 }
1053
1054 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1055 {
1056     HTMLWindow *This = DISPEX_THIS(iface);
1057
1058     TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
1059
1060     return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
1061 }
1062
1063 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1064 {
1065     HTMLWindow *This = DISPEX_THIS(iface);
1066
1067     TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
1068
1069     return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
1070 }
1071
1072 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1073 {
1074     HTMLWindow *This = DISPEX_THIS(iface);
1075
1076     TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
1077
1078     return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
1079 }
1080
1081 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1082 {
1083     HTMLWindow *This = DISPEX_THIS(iface);
1084
1085     TRACE("(%p)->(%p)\n", This, ppunk);
1086
1087     return IDispatchEx_GetNameSpaceParent(DISPATCHEX(&This->dispex), ppunk);
1088 }
1089
1090 #undef DISPEX_THIS
1091
1092 static const IDispatchExVtbl WindowDispExVtbl = {
1093     WindowDispEx_QueryInterface,
1094     WindowDispEx_AddRef,
1095     WindowDispEx_Release,
1096     WindowDispEx_GetTypeInfoCount,
1097     WindowDispEx_GetTypeInfo,
1098     WindowDispEx_GetIDsOfNames,
1099     WindowDispEx_Invoke,
1100     WindowDispEx_GetDispID,
1101     WindowDispEx_InvokeEx,
1102     WindowDispEx_DeleteMemberByName,
1103     WindowDispEx_DeleteMemberByDispID,
1104     WindowDispEx_GetMemberProperties,
1105     WindowDispEx_GetMemberName,
1106     WindowDispEx_GetNextDispID,
1107     WindowDispEx_GetNameSpaceParent
1108 };
1109
1110 static const tid_t HTMLWindow_iface_tids[] = {
1111     IHTMLWindow2_tid,
1112     IHTMLWindow3_tid,
1113     0
1114 };
1115 static dispex_static_data_t HTMLWindow_dispex = {
1116     NULL,
1117     DispHTMLWindow2_tid,
1118     NULL,
1119     HTMLWindow_iface_tids
1120 };
1121
1122 static const char wineConfig_func[] =
1123 "window.__defineGetter__(\"external\",function() {\n"
1124 "    return window.__wineWindow__.external;\n"
1125 "});\n"
1126 "window.__wineWindow__ = wineWindow;\n";
1127
1128 static void astr_to_nswstr(const char *str, nsAString *nsstr)
1129 {
1130     LPWSTR wstr;
1131     int len;
1132
1133     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
1134     wstr = heap_alloc(len*sizeof(WCHAR));
1135     MultiByteToWideChar(CP_ACP, 0, str, -1, wstr, len);
1136
1137     nsAString_Init(nsstr, wstr);
1138
1139     heap_free(wstr);
1140 }
1141
1142 static nsresult call_js_func(nsIScriptContainer *script_container, nsISupports *target,
1143                              const char *name, const char *body,
1144                              PRUint32 argc, const char **arg_names, nsIArray *argv)
1145 {
1146     nsACString name_str;
1147     nsAString body_str;
1148     JSObject func_obj, jsglobal;
1149     nsIVariant *jsret;
1150     nsresult nsres;
1151
1152     nsres = nsIScriptContainer_GetGlobalObject(script_container, &jsglobal);
1153     if(NS_FAILED(nsres))
1154         ERR("GetGlobalObject: %08x\n", nsres);
1155
1156     nsACString_Init(&name_str, name);
1157     astr_to_nswstr(body, &body_str);
1158
1159     nsres =  nsIScriptContainer_CompileFunction(script_container, jsglobal, &name_str, argc, arg_names,
1160                                                 &body_str, NULL, 1, FALSE, &func_obj);
1161
1162     nsACString_Finish(&name_str);
1163     nsAString_Finish(&body_str);
1164
1165     if(NS_FAILED(nsres)) {
1166         ERR("CompileFunction failed: %08x\n", nsres);
1167         return nsres;
1168     }
1169
1170     nsres = nsIScriptContainer_CallFunction(script_container, target, jsglobal, func_obj, argv, &jsret);
1171
1172     nsIScriptContainer_DropScriptObject(script_container, func_obj);
1173     nsIScriptContainer_DropScriptObject(script_container, jsglobal);
1174     if(NS_FAILED(nsres)) {
1175         ERR("CallFunction failed: %08x\n", nsres);
1176         return nsres;
1177     }
1178
1179     nsIVariant_Release(jsret);
1180     return NS_OK;
1181 }
1182
1183 void setup_nswindow(HTMLWindow *This)
1184 {
1185     nsIScriptContainer *script_container;
1186     nsIDOMWindow *nswindow;
1187     nsIDOMDocument *domdoc;
1188     nsIWritableVariant *nsvar;
1189     nsIMutableArray *argv;
1190     nsresult nsres;
1191
1192     static const char *args[] = {"wineWindow"};
1193
1194     TRACE("(%p)\n", This);
1195
1196     nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &domdoc);
1197     nsres = nsIDOMDocument_QueryInterface(domdoc, &IID_nsIScriptContainer, (void**)&script_container);
1198     nsIDOMDocument_Release(domdoc);
1199     if(NS_FAILED(nsres)) {
1200         TRACE("Could not get nsIDOMScriptContainer: %08x\n", nsres);
1201         return;
1202     }
1203
1204     nsIWebBrowser_GetContentDOMWindow(This->doc->nscontainer->webbrowser, &nswindow);
1205
1206     nsvar = create_nsvariant();
1207     nsres = nsIWritableVariant_SetAsInterface(nsvar, &IID_IDispatch, HTMLWINDOW2(This));
1208     if(NS_FAILED(nsres))
1209         ERR("SetAsInterface failed: %08x\n", nsres);
1210
1211     argv = create_nsarray();
1212     nsres = nsIMutableArray_AppendElement(argv, (nsISupports*)nsvar, FALSE);
1213     nsIWritableVariant_Release(nsvar);
1214     if(NS_FAILED(nsres))
1215         ERR("AppendElement failed: %08x\n", nsres);
1216
1217     call_js_func(script_container, (nsISupports*)nswindow/*HTMLWINDOW2(This)*/, "wineConfig",
1218                  wineConfig_func, 1, args, (nsIArray*)argv);
1219
1220     nsIMutableArray_Release(argv);
1221     nsIScriptContainer_Release(script_container);
1222 }
1223
1224 HTMLWindow *HTMLWindow_Create(HTMLDocument *doc)
1225 {
1226     HTMLWindow *ret = heap_alloc(sizeof(HTMLWindow));
1227
1228     ret->lpHTMLWindow2Vtbl = &HTMLWindow2Vtbl;
1229     ret->lpHTMLWindow3Vtbl = &HTMLWindow3Vtbl;
1230     ret->lpIDispatchExVtbl = &WindowDispExVtbl;
1231     ret->ref = 1;
1232     ret->doc = doc;
1233
1234     init_dispex(&ret->dispex, (IUnknown*)HTMLWINDOW2(ret), &HTMLWindow_dispex);
1235
1236     if(doc->nscontainer) {
1237         nsresult nsres;
1238
1239         nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &ret->nswindow);
1240         if(NS_FAILED(nsres))
1241             ERR("GetContentDOMWindow failed: %08x\n", nsres);
1242     }
1243
1244     list_add_head(&window_list, &ret->entry);
1245
1246     return ret;
1247 }
1248
1249 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
1250 {
1251     HTMLWindow *iter;
1252
1253     LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
1254         if(iter->nswindow == nswindow)
1255             return iter;
1256     }
1257
1258     return NULL;
1259 }