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