mshtml: Implement IHTMLWindow2::{get,put}_onresize.
[wine/hramrach.git] / dlls / mshtml / htmlwindow.c
blob6bc971c917fab7966c6e0429e68715967ee607cf
1 /*
2 * Copyright 2006 Jacek Caban for CodeWeavers
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.
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.
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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27 #include "mshtmdid.h"
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
32 #include "mshtml_private.h"
33 #include "htmlevent.h"
34 #include "resource.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 static struct list window_list = LIST_INIT(window_list);
40 static void window_set_docnode(HTMLWindow *window, HTMLDocumentNode *doc_node)
42 if(window->doc) {
43 abort_document_bindings(window->doc);
44 window->doc->basedoc.window = NULL;
45 htmldoc_release(&window->doc->basedoc);
47 window->doc = doc_node;
48 if(doc_node)
49 htmldoc_addref(&doc_node->basedoc);
51 if(window->doc_obj && window->doc_obj->basedoc.window == window) {
52 if(window->doc_obj->basedoc.doc_node)
53 htmldoc_release(&window->doc_obj->basedoc.doc_node->basedoc);
54 window->doc_obj->basedoc.doc_node = doc_node;
55 if(doc_node)
56 htmldoc_addref(&doc_node->basedoc);
60 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument *nsdoc)
62 nsIDOMDocumentView *nsdocview;
63 nsIDOMAbstractView *nsview;
64 nsIDOMWindow *nswindow;
65 nsresult nsres;
67 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview);
68 nsIDOMDocument_Release(nsdoc);
69 if(NS_FAILED(nsres)) {
70 ERR("Could not get nsIDOMDocumentView iface: %08x\n", nsres);
71 return NULL;
74 nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
75 nsIDOMDocumentView_Release(nsview);
76 if(NS_FAILED(nsres)) {
77 ERR("GetDefaultView failed: %08x\n", nsres);
78 return NULL;
81 nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow);
82 nsIDOMAbstractView_Release(nsview);
83 if(NS_FAILED(nsres)) {
84 ERR("Coult not get nsIDOMWindow iface: %08x\n", nsres);
85 return NULL;
88 return nswindow;
91 static void release_children(HTMLWindow *This)
93 HTMLWindow *child;
95 while(!list_empty(&This->children)) {
96 child = LIST_ENTRY(list_tail(&This->children), HTMLWindow, sibling_entry);
98 list_remove(&child->sibling_entry);
99 child->parent = NULL;
100 IHTMLWindow2_Release(HTMLWINDOW2(child));
104 static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret)
106 if(This->location) {
107 IHTMLLocation_AddRef(HTMLLOCATION(This->location));
108 }else {
109 HRESULT hres;
111 hres = HTMLLocation_Create(This, &This->location);
112 if(FAILED(hres))
113 return hres;
116 *ret = This->location;
117 return S_OK;
120 #define HTMLWINDOW2_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow2, iface)
122 static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv)
124 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
126 *ppv = NULL;
128 if(IsEqualGUID(&IID_IUnknown, riid)) {
129 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
130 *ppv = HTMLWINDOW2(This);
131 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
132 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
133 *ppv = HTMLWINDOW2(This);
134 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
135 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
136 *ppv = DISPATCHEX(This);
137 }else if(IsEqualGUID(&IID_IHTMLFramesCollection2, riid)) {
138 TRACE("(%p)->(IID_IHTMLFramesCollection2 %p)\n", This, ppv);
139 *ppv = HTMLWINDOW2(This);
140 }else if(IsEqualGUID(&IID_IHTMLWindow2, riid)) {
141 TRACE("(%p)->(IID_IHTMLWindow2 %p)\n", This, ppv);
142 *ppv = HTMLWINDOW2(This);
143 }else if(IsEqualGUID(&IID_IHTMLWindow3, riid)) {
144 TRACE("(%p)->(IID_IHTMLWindow3 %p)\n", This, ppv);
145 *ppv = HTMLWINDOW3(This);
146 }else if(IsEqualGUID(&IID_IHTMLWindow4, riid)) {
147 TRACE("(%p)->(IID_IHTMLWindow4 %p)\n", This, ppv);
148 *ppv = HTMLWINDOW4(This);
149 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
150 return *ppv ? S_OK : E_NOINTERFACE;
153 if(*ppv) {
154 IUnknown_AddRef((IUnknown*)*ppv);
155 return S_OK;
158 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
159 return E_NOINTERFACE;
162 static ULONG WINAPI HTMLWindow2_AddRef(IHTMLWindow2 *iface)
164 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
165 LONG ref = InterlockedIncrement(&This->ref);
167 TRACE("(%p) ref=%d\n", This, ref);
169 return ref;
172 static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
174 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
175 LONG ref = InterlockedDecrement(&This->ref);
177 TRACE("(%p) ref=%d\n", This, ref);
179 if(!ref) {
180 DWORD i;
182 remove_target_tasks(This->task_magic);
183 set_window_bscallback(This, NULL);
184 set_current_mon(This, NULL);
185 window_set_docnode(This, NULL);
186 release_children(This);
188 if(This->frame_element)
189 This->frame_element->content_window = NULL;
191 if(This->option_factory) {
192 This->option_factory->window = NULL;
193 IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
196 if(This->image_factory) {
197 This->image_factory->window = NULL;
198 IHTMLImageElementFactory_Release(HTMLIMGFACTORY(This->image_factory));
201 if(This->location) {
202 This->location->window = NULL;
203 IHTMLLocation_Release(HTMLLOCATION(This->location));
206 if(This->screen)
207 IHTMLScreen_Release(This->screen);
209 if(This->event_target)
210 release_event_target(This->event_target);
211 for(i=0; i < This->global_prop_cnt; i++)
212 heap_free(This->global_props[i].name);
214 This->window_ref->window = NULL;
215 windowref_release(This->window_ref);
217 heap_free(This->global_props);
218 release_script_hosts(This);
220 if(This->nswindow)
221 nsIDOMWindow_Release(This->nswindow);
223 list_remove(&This->entry);
224 release_dispex(&This->dispex);
225 heap_free(This);
228 return ref;
231 static HRESULT WINAPI HTMLWindow2_GetTypeInfoCount(IHTMLWindow2 *iface, UINT *pctinfo)
233 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
235 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
238 static HRESULT WINAPI HTMLWindow2_GetTypeInfo(IHTMLWindow2 *iface, UINT iTInfo,
239 LCID lcid, ITypeInfo **ppTInfo)
241 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
243 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
246 static HRESULT WINAPI HTMLWindow2_GetIDsOfNames(IHTMLWindow2 *iface, REFIID riid,
247 LPOLESTR *rgszNames, UINT cNames,
248 LCID lcid, DISPID *rgDispId)
250 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
252 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
255 static HRESULT WINAPI HTMLWindow2_Invoke(IHTMLWindow2 *iface, DISPID dispIdMember,
256 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
257 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
259 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
261 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
262 pVarResult, pExcepInfo, puArgErr);
265 static HRESULT get_frame_by_index(nsIDOMWindowCollection *nsFrames, PRUint32 index, HTMLWindow **ret)
267 PRUint32 length;
268 nsIDOMWindow *nsWindow;
269 nsresult nsres;
271 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
272 if(NS_FAILED(nsres)) {
273 FIXME("nsIDOMWindowCollection_GetLength failed: 0x%08x\n", nsres);
274 return E_FAIL;
277 if(index >= length)
278 return DISP_E_MEMBERNOTFOUND;
280 nsres = nsIDOMWindowCollection_Item(nsFrames, index, &nsWindow);
281 if(NS_FAILED(nsres)) {
282 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
283 return E_FAIL;
286 *ret = nswindow_to_window(nsWindow);
288 nsIDOMWindow_Release(nsWindow);
290 return S_OK;
293 static HRESULT WINAPI HTMLWindow2_item(IHTMLWindow2 *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
295 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
296 nsIDOMWindowCollection *nsFrames;
297 HTMLWindow *window;
298 HRESULT hres;
299 nsresult nsres;
301 TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
303 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nsFrames);
304 if(NS_FAILED(nsres)) {
305 FIXME("nsIDOMWindow_GetFrames failed: 0x%08x\n", nsres);
306 return E_FAIL;
309 if(V_VT(pvarIndex) == VT_I4) {
310 int index = V_I4(pvarIndex);
311 TRACE("Getting index %d\n", index);
312 if(index < 0) {
313 hres = DISP_E_MEMBERNOTFOUND;
314 goto cleanup;
316 hres = get_frame_by_index(nsFrames, index, &window);
317 if(FAILED(hres))
318 goto cleanup;
319 }else if(V_VT(pvarIndex) == VT_UINT) {
320 unsigned int index = V_UINT(pvarIndex);
321 TRACE("Getting index %u\n", index);
322 hres = get_frame_by_index(nsFrames, index, &window);
323 if(FAILED(hres))
324 goto cleanup;
325 }else if(V_VT(pvarIndex) == VT_BSTR) {
326 BSTR str = V_BSTR(pvarIndex);
327 PRUint32 length, i;
329 TRACE("Getting name %s\n", wine_dbgstr_w(str));
331 nsres = nsIDOMWindowCollection_GetLength(nsFrames, &length);
333 window = NULL;
334 for(i = 0; i < length && !window; ++i) {
335 HTMLWindow *cur_window;
336 nsIDOMWindow *nsWindow;
337 BSTR id;
339 nsres = nsIDOMWindowCollection_Item(nsFrames, i, &nsWindow);
340 if(NS_FAILED(nsres)) {
341 FIXME("nsIDOMWindowCollection_Item failed: 0x%08x\n", nsres);
342 hres = E_FAIL;
343 goto cleanup;
346 cur_window = nswindow_to_window(nsWindow);
348 nsIDOMWindow_Release(nsWindow);
350 hres = IHTMLElement_get_id(HTMLELEM(&cur_window->frame_element->element), &id);
351 if(FAILED(hres)) {
352 FIXME("IHTMLElement_get_id failed: 0x%08x\n", hres);
353 goto cleanup;
356 if(!strcmpW(id, str))
357 window = cur_window;
359 SysFreeString(id);
362 if(!window) {
363 hres = DISP_E_MEMBERNOTFOUND;
364 goto cleanup;
366 }else {
367 hres = E_INVALIDARG;
368 goto cleanup;
371 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
372 V_VT(pvarResult) = VT_DISPATCH;
373 V_DISPATCH(pvarResult) = (IDispatch*)window;
375 hres = S_OK;
377 cleanup:
378 nsIDOMWindowCollection_Release(nsFrames);
380 return hres;
383 static HRESULT WINAPI HTMLWindow2_get_length(IHTMLWindow2 *iface, LONG *p)
385 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
386 nsIDOMWindowCollection *nscollection;
387 PRUint32 length;
388 nsresult nsres;
390 TRACE("(%p)->(%p)\n", This, p);
392 nsres = nsIDOMWindow_GetFrames(This->nswindow, &nscollection);
393 if(NS_FAILED(nsres)) {
394 ERR("GetFrames failed: %08x\n", nsres);
395 return E_FAIL;
398 nsres = nsIDOMWindowCollection_GetLength(nscollection, &length);
399 nsIDOMWindowCollection_Release(nscollection);
400 if(NS_FAILED(nsres)) {
401 ERR("GetLength failed: %08x\n", nsres);
402 return E_FAIL;
405 *p = length;
406 return S_OK;
409 static HRESULT WINAPI HTMLWindow2_get_frames(IHTMLWindow2 *iface, IHTMLFramesCollection2 **p)
411 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
412 FIXME("(%p)->(%p): semi-stub\n", This, p);
414 /* FIXME: Should return a separate Window object */
415 *p = (IHTMLFramesCollection2*)HTMLWINDOW2(This);
416 HTMLWindow2_AddRef(iface);
417 return S_OK;
420 static HRESULT WINAPI HTMLWindow2_put_defaultStatus(IHTMLWindow2 *iface, BSTR v)
422 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
423 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
424 return E_NOTIMPL;
427 static HRESULT WINAPI HTMLWindow2_get_defaultStatus(IHTMLWindow2 *iface, BSTR *p)
429 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
430 FIXME("(%p)->(%p)\n", This, p);
431 return E_NOTIMPL;
434 static HRESULT WINAPI HTMLWindow2_put_status(IHTMLWindow2 *iface, BSTR v)
436 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
437 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
438 return E_NOTIMPL;
441 static HRESULT WINAPI HTMLWindow2_get_status(IHTMLWindow2 *iface, BSTR *p)
443 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
444 FIXME("(%p)->(%p)\n", This, p);
445 return E_NOTIMPL;
448 static HRESULT WINAPI HTMLWindow2_setTimeout(IHTMLWindow2 *iface, BSTR expression,
449 LONG msec, VARIANT *language, LONG *timerID)
451 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
452 VARIANT expr_var;
454 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
456 V_VT(&expr_var) = VT_BSTR;
457 V_BSTR(&expr_var) = expression;
459 return IHTMLWindow3_setTimeout(HTMLWINDOW3(This), &expr_var, msec, language, timerID);
462 static HRESULT WINAPI HTMLWindow2_clearTimeout(IHTMLWindow2 *iface, LONG timerID)
464 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
466 TRACE("(%p)->(%d)\n", This, timerID);
468 return clear_task_timer(&This->doc->basedoc, FALSE, timerID);
471 static HRESULT WINAPI HTMLWindow2_alert(IHTMLWindow2 *iface, BSTR message)
473 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
474 WCHAR wszTitle[100];
476 TRACE("(%p)->(%s)\n", This, debugstr_w(message));
478 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
479 sizeof(wszTitle)/sizeof(WCHAR))) {
480 WARN("Could not load message box title: %d\n", GetLastError());
481 return S_OK;
484 MessageBoxW(This->doc_obj->hwnd, message, wszTitle, MB_ICONWARNING);
485 return S_OK;
488 static HRESULT WINAPI HTMLWindow2_confirm(IHTMLWindow2 *iface, BSTR message,
489 VARIANT_BOOL *confirmed)
491 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
492 WCHAR wszTitle[100];
494 TRACE("(%p)->(%s %p)\n", This, debugstr_w(message), confirmed);
496 if(!confirmed) return E_INVALIDARG;
498 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
499 sizeof(wszTitle)/sizeof(WCHAR))) {
500 WARN("Could not load message box title: %d\n", GetLastError());
501 *confirmed = VARIANT_TRUE;
502 return S_OK;
505 if(MessageBoxW(This->doc_obj->hwnd, message, wszTitle,
506 MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
507 *confirmed = VARIANT_TRUE;
508 else *confirmed = VARIANT_FALSE;
510 return S_OK;
513 typedef struct
515 BSTR message;
516 BSTR dststr;
517 VARIANT *textdata;
518 }prompt_arg;
520 static INT_PTR CALLBACK prompt_dlgproc(HWND hwnd, UINT msg,
521 WPARAM wparam, LPARAM lparam)
523 switch(msg)
525 case WM_INITDIALOG:
527 prompt_arg *arg = (prompt_arg*)lparam;
528 WCHAR wszTitle[100];
530 if(!LoadStringW(get_shdoclc(), IDS_MESSAGE_BOX_TITLE, wszTitle,
531 sizeof(wszTitle)/sizeof(WCHAR))) {
532 WARN("Could not load message box title: %d\n", GetLastError());
533 EndDialog(hwnd, wparam);
534 return FALSE;
537 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
538 SetWindowTextW(hwnd, wszTitle);
539 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_PROMPT), arg->message);
540 SetWindowTextW(GetDlgItem(hwnd, ID_PROMPT_EDIT), arg->dststr);
541 return FALSE;
543 case WM_COMMAND:
544 switch(wparam)
546 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
547 EndDialog(hwnd, wparam);
548 return TRUE;
549 case MAKEWPARAM(IDOK, BN_CLICKED):
551 prompt_arg *arg =
552 (prompt_arg*)GetWindowLongPtrW(hwnd, DWLP_USER);
553 HWND hwndPrompt = GetDlgItem(hwnd, ID_PROMPT_EDIT);
554 INT len = GetWindowTextLengthW(hwndPrompt);
556 if(!arg->textdata)
558 EndDialog(hwnd, wparam);
559 return TRUE;
562 V_VT(arg->textdata) = VT_BSTR;
563 if(!len && !arg->dststr)
564 V_BSTR(arg->textdata) = NULL;
565 else
567 V_BSTR(arg->textdata) = SysAllocStringLen(NULL, len);
568 GetWindowTextW(hwndPrompt, V_BSTR(arg->textdata), len+1);
570 EndDialog(hwnd, wparam);
571 return TRUE;
574 return FALSE;
575 case WM_CLOSE:
576 EndDialog(hwnd, IDCANCEL);
577 return TRUE;
578 default:
579 return FALSE;
583 static HRESULT WINAPI HTMLWindow2_prompt(IHTMLWindow2 *iface, BSTR message,
584 BSTR dststr, VARIANT *textdata)
586 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
587 prompt_arg arg;
589 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(message), debugstr_w(dststr), textdata);
591 if(textdata) V_VT(textdata) = VT_NULL;
593 arg.message = message;
594 arg.dststr = dststr;
595 arg.textdata = textdata;
597 DialogBoxParamW(hInst, MAKEINTRESOURCEW(ID_PROMPT_DIALOG),
598 This->doc_obj->hwnd, prompt_dlgproc, (LPARAM)&arg);
599 return S_OK;
602 static HRESULT WINAPI HTMLWindow2_get_Image(IHTMLWindow2 *iface, IHTMLImageElementFactory **p)
604 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
606 TRACE("(%p)->(%p)\n", This, p);
608 if(!This->image_factory)
609 This->image_factory = HTMLImageElementFactory_Create(This);
611 *p = HTMLIMGFACTORY(This->image_factory);
612 IHTMLImageElementFactory_AddRef(*p);
614 return S_OK;
617 static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocation **p)
619 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
620 HTMLLocation *location;
621 HRESULT hres;
623 TRACE("(%p)->(%p)\n", This, p);
625 hres = get_location(This, &location);
626 if(FAILED(hres))
627 return hres;
629 *p = HTMLLOCATION(location);
630 return S_OK;
633 static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)
635 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
636 FIXME("(%p)->(%p)\n", This, p);
637 return E_NOTIMPL;
640 static HRESULT WINAPI HTMLWindow2_close(IHTMLWindow2 *iface)
642 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
643 FIXME("(%p)->()\n", This);
644 return E_NOTIMPL;
647 static HRESULT WINAPI HTMLWindow2_put_opener(IHTMLWindow2 *iface, VARIANT v)
649 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
650 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
651 return E_NOTIMPL;
654 static HRESULT WINAPI HTMLWindow2_get_opener(IHTMLWindow2 *iface, VARIANT *p)
656 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
657 FIXME("(%p)->(%p)\n", This, p);
658 return E_NOTIMPL;
661 static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigator **p)
663 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
665 TRACE("(%p)->(%p)\n", This, p);
667 *p = OmNavigator_Create();
668 return S_OK;
671 static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v)
673 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
674 nsAString name_str;
675 nsresult nsres;
677 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
679 nsAString_Init(&name_str, v);
680 nsres = nsIDOMWindow_SetName(This->nswindow, &name_str);
681 nsAString_Finish(&name_str);
682 if(NS_FAILED(nsres))
683 ERR("SetName failed: %08x\n", nsres);
685 return S_OK;
688 static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p)
690 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
691 nsAString name_str;
692 nsresult nsres;
693 HRESULT hres;
695 TRACE("(%p)->(%p)\n", This, p);
697 nsAString_Init(&name_str, NULL);
698 nsres = nsIDOMWindow_GetName(This->nswindow, &name_str);
699 if(NS_SUCCEEDED(nsres)) {
700 const PRUnichar *name;
702 nsAString_GetData(&name_str, &name);
703 if(*name) {
704 *p = SysAllocString(name);
705 hres = *p ? S_OK : E_OUTOFMEMORY;
706 }else {
707 *p = NULL;
708 hres = S_OK;
710 }else {
711 ERR("GetName failed: %08x\n", nsres);
712 hres = E_FAIL;
714 nsAString_Finish(&name_str);
716 return hres;
719 static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p)
721 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
722 TRACE("(%p)->(%p)\n", This, p);
724 if(This->parent) {
725 *p = HTMLWINDOW2(This->parent);
726 IHTMLWindow2_AddRef(*p);
727 }else
728 *p = NULL;
730 return S_OK;
733 static HRESULT WINAPI HTMLWindow2_open(IHTMLWindow2 *iface, BSTR url, BSTR name,
734 BSTR features, VARIANT_BOOL replace, IHTMLWindow2 **pomWindowResult)
736 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
737 FIXME("(%p)->(%s %s %s %x %p)\n", This, debugstr_w(url), debugstr_w(name),
738 debugstr_w(features), replace, pomWindowResult);
739 return E_NOTIMPL;
742 static HRESULT WINAPI HTMLWindow2_get_self(IHTMLWindow2 *iface, IHTMLWindow2 **p)
744 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
746 TRACE("(%p)->(%p)\n", This, p);
748 /* FIXME: We should return kind of proxy window here. */
749 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
750 *p = HTMLWINDOW2(This);
751 return S_OK;
754 static HRESULT WINAPI HTMLWindow2_get_top(IHTMLWindow2 *iface, IHTMLWindow2 **p)
756 HTMLWindow *This = HTMLWINDOW2_THIS(iface), *curr;
757 TRACE("(%p)->(%p)\n", This, p);
759 curr = This;
760 while(curr->parent)
761 curr = curr->parent;
762 *p = HTMLWINDOW2(curr);
763 IHTMLWindow2_AddRef(*p);
765 return S_OK;
768 static HRESULT WINAPI HTMLWindow2_get_window(IHTMLWindow2 *iface, IHTMLWindow2 **p)
770 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
772 TRACE("(%p)->(%p)\n", This, p);
774 /* FIXME: We should return kind of proxy window here. */
775 IHTMLWindow2_AddRef(HTMLWINDOW2(This));
776 *p = HTMLWINDOW2(This);
777 return S_OK;
780 static HRESULT WINAPI HTMLWindow2_navigate(IHTMLWindow2 *iface, BSTR url)
782 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
783 FIXME("(%p)->(%s)\n", This, debugstr_w(url));
784 return E_NOTIMPL;
787 static HRESULT WINAPI HTMLWindow2_put_onfocus(IHTMLWindow2 *iface, VARIANT v)
789 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
790 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
791 return E_NOTIMPL;
794 static HRESULT WINAPI HTMLWindow2_get_onfocus(IHTMLWindow2 *iface, VARIANT *p)
796 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
797 FIXME("(%p)->(%p)\n", This, p);
798 return E_NOTIMPL;
801 static HRESULT WINAPI HTMLWindow2_put_onblur(IHTMLWindow2 *iface, VARIANT v)
803 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
804 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
805 return E_NOTIMPL;
808 static HRESULT WINAPI HTMLWindow2_get_onblur(IHTMLWindow2 *iface, VARIANT *p)
810 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
811 FIXME("(%p)->(%p)\n", This, p);
812 return E_NOTIMPL;
815 static HRESULT WINAPI HTMLWindow2_put_onload(IHTMLWindow2 *iface, VARIANT v)
817 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
819 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
821 return set_window_event(This, EVENTID_LOAD, &v);
824 static HRESULT WINAPI HTMLWindow2_get_onload(IHTMLWindow2 *iface, VARIANT *p)
826 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
828 TRACE("(%p)->(%p)\n", This, p);
830 return get_window_event(This, EVENTID_LOAD, p);
833 static HRESULT WINAPI HTMLWindow2_put_onbeforeunload(IHTMLWindow2 *iface, VARIANT v)
835 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
837 TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
839 return set_window_event(This, EVENTID_BEFOREUNLOAD, &v);
842 static HRESULT WINAPI HTMLWindow2_get_onbeforeunload(IHTMLWindow2 *iface, VARIANT *p)
844 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
846 TRACE("(%p)->(%p)\n", This, p);
848 return get_window_event(This, EVENTID_BEFOREUNLOAD, p);
851 static HRESULT WINAPI HTMLWindow2_put_onunload(IHTMLWindow2 *iface, VARIANT v)
853 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
854 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
855 return E_NOTIMPL;
858 static HRESULT WINAPI HTMLWindow2_get_onunload(IHTMLWindow2 *iface, VARIANT *p)
860 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
861 FIXME("(%p)->(%p)\n", This, p);
862 return E_NOTIMPL;
865 static HRESULT WINAPI HTMLWindow2_put_onhelp(IHTMLWindow2 *iface, VARIANT v)
867 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
868 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
869 return E_NOTIMPL;
872 static HRESULT WINAPI HTMLWindow2_get_onhelp(IHTMLWindow2 *iface, VARIANT *p)
874 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
875 FIXME("(%p)->(%p)\n", This, p);
876 return E_NOTIMPL;
879 static HRESULT WINAPI HTMLWindow2_put_onerror(IHTMLWindow2 *iface, VARIANT v)
881 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
882 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
883 return E_NOTIMPL;
886 static HRESULT WINAPI HTMLWindow2_get_onerror(IHTMLWindow2 *iface, VARIANT *p)
888 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
889 FIXME("(%p)->(%p)\n", This, p);
890 return E_NOTIMPL;
893 static HRESULT WINAPI HTMLWindow2_put_onresize(IHTMLWindow2 *iface, VARIANT v)
895 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
897 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
899 return set_window_event(This, EVENTID_RESIZE, &v);
902 static HRESULT WINAPI HTMLWindow2_get_onresize(IHTMLWindow2 *iface, VARIANT *p)
904 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
906 TRACE("(%p)->(%p)\n", This, p);
908 return get_window_event(This, EVENTID_RESIZE, p);
911 static HRESULT WINAPI HTMLWindow2_put_onscroll(IHTMLWindow2 *iface, VARIANT v)
913 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
914 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
915 return E_NOTIMPL;
918 static HRESULT WINAPI HTMLWindow2_get_onscroll(IHTMLWindow2 *iface, VARIANT *p)
920 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
921 FIXME("(%p)->(%p)\n", This, p);
922 return E_NOTIMPL;
925 static HRESULT WINAPI HTMLWindow2_get_document(IHTMLWindow2 *iface, IHTMLDocument2 **p)
927 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
929 TRACE("(%p)->(%p)\n", This, p);
931 if(This->doc) {
932 /* FIXME: We should return a wrapper object here */
933 *p = HTMLDOC(&This->doc->basedoc);
934 IHTMLDocument2_AddRef(*p);
935 }else {
936 *p = NULL;
939 return S_OK;
942 static HRESULT WINAPI HTMLWindow2_get_event(IHTMLWindow2 *iface, IHTMLEventObj **p)
944 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
946 TRACE("(%p)->(%p)\n", This, p);
948 if(This->event)
949 IHTMLEventObj_AddRef(This->event);
950 *p = This->event;
951 return S_OK;
954 static HRESULT WINAPI HTMLWindow2_get__newEnum(IHTMLWindow2 *iface, IUnknown **p)
956 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
957 FIXME("(%p)->(%p)\n", This, p);
958 return E_NOTIMPL;
961 static HRESULT WINAPI HTMLWindow2_showModalDialog(IHTMLWindow2 *iface, BSTR dialog,
962 VARIANT *varArgIn, VARIANT *varOptions, VARIANT *varArgOut)
964 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
965 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(dialog), varArgIn, varOptions, varArgOut);
966 return E_NOTIMPL;
969 static HRESULT WINAPI HTMLWindow2_showHelp(IHTMLWindow2 *iface, BSTR helpURL, VARIANT helpArg,
970 BSTR features)
972 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
973 FIXME("(%p)->(%s v(%d) %s)\n", This, debugstr_w(helpURL), V_VT(&helpArg), debugstr_w(features));
974 return E_NOTIMPL;
977 static HRESULT WINAPI HTMLWindow2_get_screen(IHTMLWindow2 *iface, IHTMLScreen **p)
979 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
981 TRACE("(%p)->(%p)\n", This, p);
983 if(!This->screen) {
984 HRESULT hres;
986 hres = HTMLScreen_Create(&This->screen);
987 if(FAILED(hres))
988 return hres;
991 *p = This->screen;
992 IHTMLScreen_AddRef(This->screen);
993 return S_OK;
996 static HRESULT WINAPI HTMLWindow2_get_Option(IHTMLWindow2 *iface, IHTMLOptionElementFactory **p)
998 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1000 TRACE("(%p)->(%p)\n", This, p);
1002 if(!This->option_factory)
1003 This->option_factory = HTMLOptionElementFactory_Create(This);
1005 *p = HTMLOPTFACTORY(This->option_factory);
1006 IHTMLOptionElementFactory_AddRef(*p);
1008 return S_OK;
1011 static HRESULT WINAPI HTMLWindow2_focus(IHTMLWindow2 *iface)
1013 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1014 FIXME("(%p)->()\n", This);
1015 return E_NOTIMPL;
1018 static HRESULT WINAPI HTMLWindow2_get_closed(IHTMLWindow2 *iface, VARIANT_BOOL *p)
1020 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1021 FIXME("(%p)->(%p)\n", This, p);
1022 return E_NOTIMPL;
1025 static HRESULT WINAPI HTMLWindow2_blur(IHTMLWindow2 *iface)
1027 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1028 FIXME("(%p)->()\n", This);
1029 return E_NOTIMPL;
1032 static HRESULT WINAPI HTMLWindow2_scroll(IHTMLWindow2 *iface, LONG x, LONG y)
1034 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1035 FIXME("(%p)->(%d %d)\n", This, x, y);
1036 return E_NOTIMPL;
1039 static HRESULT WINAPI HTMLWindow2_get_clientInformation(IHTMLWindow2 *iface, IOmNavigator **p)
1041 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1042 FIXME("(%p)->(%p)\n", This, p);
1043 return E_NOTIMPL;
1046 static HRESULT WINAPI HTMLWindow2_setInterval(IHTMLWindow2 *iface, BSTR expression,
1047 LONG msec, VARIANT *language, LONG *timerID)
1049 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1050 VARIANT expr;
1052 TRACE("(%p)->(%s %d %p %p)\n", This, debugstr_w(expression), msec, language, timerID);
1054 V_VT(&expr) = VT_BSTR;
1055 V_BSTR(&expr) = expression;
1056 return IHTMLWindow3_setInterval(HTMLWINDOW3(This), &expr, msec, language, timerID);
1059 static HRESULT WINAPI HTMLWindow2_clearInterval(IHTMLWindow2 *iface, LONG timerID)
1061 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1063 TRACE("(%p)->(%d)\n", This, timerID);
1065 return clear_task_timer(&This->doc->basedoc, TRUE, timerID);
1068 static HRESULT WINAPI HTMLWindow2_put_offscreenBuffering(IHTMLWindow2 *iface, VARIANT v)
1070 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1071 FIXME("(%p)->(v(%d))\n", This, V_VT(&v));
1072 return E_NOTIMPL;
1075 static HRESULT WINAPI HTMLWindow2_get_offscreenBuffering(IHTMLWindow2 *iface, VARIANT *p)
1077 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1078 FIXME("(%p)->(%p)\n", This, p);
1079 return E_NOTIMPL;
1082 static HRESULT WINAPI HTMLWindow2_execScript(IHTMLWindow2 *iface, BSTR scode, BSTR language,
1083 VARIANT *pvarRet)
1085 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1086 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(scode), debugstr_w(language), pvarRet);
1087 return E_NOTIMPL;
1090 static HRESULT WINAPI HTMLWindow2_toString(IHTMLWindow2 *iface, BSTR *String)
1092 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1094 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
1096 TRACE("(%p)->(%p)\n", This, String);
1098 if(!String)
1099 return E_INVALIDARG;
1101 *String = SysAllocString(objectW);
1102 return *String ? S_OK : E_OUTOFMEMORY;
1105 static HRESULT WINAPI HTMLWindow2_scrollBy(IHTMLWindow2 *iface, LONG x, LONG y)
1107 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1108 nsresult nsres;
1110 TRACE("(%p)->(%d %d)\n", This, x, y);
1112 nsres = nsIDOMWindow_ScrollBy(This->nswindow, x, y);
1113 if(NS_FAILED(nsres))
1114 ERR("ScrollBy failed: %08x\n", nsres);
1116 return S_OK;
1119 static HRESULT WINAPI HTMLWindow2_scrollTo(IHTMLWindow2 *iface, LONG x, LONG y)
1121 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1122 nsresult nsres;
1124 TRACE("(%p)->(%d %d)\n", This, x, y);
1126 nsres = nsIDOMWindow_ScrollTo(This->nswindow, x, y);
1127 if(NS_FAILED(nsres))
1128 ERR("ScrollTo failed: %08x\n", nsres);
1130 return S_OK;
1133 static HRESULT WINAPI HTMLWindow2_moveTo(IHTMLWindow2 *iface, LONG x, LONG y)
1135 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1136 FIXME("(%p)->(%d %d)\n", This, x, y);
1137 return E_NOTIMPL;
1140 static HRESULT WINAPI HTMLWindow2_moveBy(IHTMLWindow2 *iface, LONG x, LONG y)
1142 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1143 FIXME("(%p)->(%d %d)\n", This, x, y);
1144 return E_NOTIMPL;
1147 static HRESULT WINAPI HTMLWindow2_resizeTo(IHTMLWindow2 *iface, LONG x, LONG y)
1149 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1150 FIXME("(%p)->(%d %d)\n", This, x, y);
1151 return E_NOTIMPL;
1154 static HRESULT WINAPI HTMLWindow2_resizeBy(IHTMLWindow2 *iface, LONG x, LONG y)
1156 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1157 FIXME("(%p)->(%d %d)\n", This, x, y);
1158 return E_NOTIMPL;
1161 static HRESULT WINAPI HTMLWindow2_get_external(IHTMLWindow2 *iface, IDispatch **p)
1163 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1165 TRACE("(%p)->(%p)\n", This, p);
1167 *p = NULL;
1169 if(!This->doc_obj->hostui)
1170 return S_OK;
1172 return IDocHostUIHandler_GetExternal(This->doc_obj->hostui, p);
1175 static HRESULT HTMLWindow_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1176 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1178 HTMLWindow *This = HTMLWINDOW2_THIS(iface);
1179 global_prop_t *prop;
1180 DWORD idx;
1181 HRESULT hres;
1183 idx = id - MSHTML_DISPID_CUSTOM_MIN;
1184 if(idx >= This->global_prop_cnt)
1185 return DISP_E_MEMBERNOTFOUND;
1187 prop = This->global_props+idx;
1189 switch(prop->type) {
1190 case GLOBAL_SCRIPTVAR: {
1191 IDispatchEx *dispex;
1192 IDispatch *disp;
1194 disp = get_script_disp(prop->script_host);
1195 if(!disp)
1196 return E_UNEXPECTED;
1198 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1199 if(SUCCEEDED(hres)) {
1200 TRACE("%s >>>\n", debugstr_w(prop->name));
1201 hres = IDispatchEx_InvokeEx(dispex, prop->id, lcid, flags, params, res, ei, caller);
1202 if(hres == S_OK)
1203 TRACE("%s <<<\n", debugstr_w(prop->name));
1204 else
1205 WARN("%s <<< %08x\n", debugstr_w(prop->name), hres);
1206 IDispatchEx_Release(dispex);
1207 }else {
1208 FIXME("No IDispatchEx\n");
1210 IDispatch_Release(disp);
1211 break;
1213 case GLOBAL_ELEMENTVAR: {
1214 IHTMLElement *elem;
1216 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), prop->name, &elem);
1217 if(FAILED(hres))
1218 return hres;
1220 if(!elem)
1221 return DISP_E_MEMBERNOTFOUND;
1223 V_VT(res) = VT_DISPATCH;
1224 V_DISPATCH(res) = (IDispatch*)elem;
1225 break;
1227 default:
1228 ERR("invalid type %d\n", prop->type);
1229 hres = DISP_E_MEMBERNOTFOUND;
1232 return hres;
1235 #undef HTMLWINDOW2_THIS
1237 static const IHTMLWindow2Vtbl HTMLWindow2Vtbl = {
1238 HTMLWindow2_QueryInterface,
1239 HTMLWindow2_AddRef,
1240 HTMLWindow2_Release,
1241 HTMLWindow2_GetTypeInfoCount,
1242 HTMLWindow2_GetTypeInfo,
1243 HTMLWindow2_GetIDsOfNames,
1244 HTMLWindow2_Invoke,
1245 HTMLWindow2_item,
1246 HTMLWindow2_get_length,
1247 HTMLWindow2_get_frames,
1248 HTMLWindow2_put_defaultStatus,
1249 HTMLWindow2_get_defaultStatus,
1250 HTMLWindow2_put_status,
1251 HTMLWindow2_get_status,
1252 HTMLWindow2_setTimeout,
1253 HTMLWindow2_clearTimeout,
1254 HTMLWindow2_alert,
1255 HTMLWindow2_confirm,
1256 HTMLWindow2_prompt,
1257 HTMLWindow2_get_Image,
1258 HTMLWindow2_get_location,
1259 HTMLWindow2_get_history,
1260 HTMLWindow2_close,
1261 HTMLWindow2_put_opener,
1262 HTMLWindow2_get_opener,
1263 HTMLWindow2_get_navigator,
1264 HTMLWindow2_put_name,
1265 HTMLWindow2_get_name,
1266 HTMLWindow2_get_parent,
1267 HTMLWindow2_open,
1268 HTMLWindow2_get_self,
1269 HTMLWindow2_get_top,
1270 HTMLWindow2_get_window,
1271 HTMLWindow2_navigate,
1272 HTMLWindow2_put_onfocus,
1273 HTMLWindow2_get_onfocus,
1274 HTMLWindow2_put_onblur,
1275 HTMLWindow2_get_onblur,
1276 HTMLWindow2_put_onload,
1277 HTMLWindow2_get_onload,
1278 HTMLWindow2_put_onbeforeunload,
1279 HTMLWindow2_get_onbeforeunload,
1280 HTMLWindow2_put_onunload,
1281 HTMLWindow2_get_onunload,
1282 HTMLWindow2_put_onhelp,
1283 HTMLWindow2_get_onhelp,
1284 HTMLWindow2_put_onerror,
1285 HTMLWindow2_get_onerror,
1286 HTMLWindow2_put_onresize,
1287 HTMLWindow2_get_onresize,
1288 HTMLWindow2_put_onscroll,
1289 HTMLWindow2_get_onscroll,
1290 HTMLWindow2_get_document,
1291 HTMLWindow2_get_event,
1292 HTMLWindow2_get__newEnum,
1293 HTMLWindow2_showModalDialog,
1294 HTMLWindow2_showHelp,
1295 HTMLWindow2_get_screen,
1296 HTMLWindow2_get_Option,
1297 HTMLWindow2_focus,
1298 HTMLWindow2_get_closed,
1299 HTMLWindow2_blur,
1300 HTMLWindow2_scroll,
1301 HTMLWindow2_get_clientInformation,
1302 HTMLWindow2_setInterval,
1303 HTMLWindow2_clearInterval,
1304 HTMLWindow2_put_offscreenBuffering,
1305 HTMLWindow2_get_offscreenBuffering,
1306 HTMLWindow2_execScript,
1307 HTMLWindow2_toString,
1308 HTMLWindow2_scrollBy,
1309 HTMLWindow2_scrollTo,
1310 HTMLWindow2_moveTo,
1311 HTMLWindow2_moveBy,
1312 HTMLWindow2_resizeTo,
1313 HTMLWindow2_resizeBy,
1314 HTMLWindow2_get_external
1317 #define HTMLWINDOW3_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow3, iface)
1319 static HRESULT WINAPI HTMLWindow3_QueryInterface(IHTMLWindow3 *iface, REFIID riid, void **ppv)
1321 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1323 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1326 static ULONG WINAPI HTMLWindow3_AddRef(IHTMLWindow3 *iface)
1328 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1330 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1333 static ULONG WINAPI HTMLWindow3_Release(IHTMLWindow3 *iface)
1335 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1337 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1340 static HRESULT WINAPI HTMLWindow3_GetTypeInfoCount(IHTMLWindow3 *iface, UINT *pctinfo)
1342 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1344 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1347 static HRESULT WINAPI HTMLWindow3_GetTypeInfo(IHTMLWindow3 *iface, UINT iTInfo,
1348 LCID lcid, ITypeInfo **ppTInfo)
1350 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1352 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1355 static HRESULT WINAPI HTMLWindow3_GetIDsOfNames(IHTMLWindow3 *iface, REFIID riid,
1356 LPOLESTR *rgszNames, UINT cNames,
1357 LCID lcid, DISPID *rgDispId)
1359 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1361 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1364 static HRESULT WINAPI HTMLWindow3_Invoke(IHTMLWindow3 *iface, DISPID dispIdMember,
1365 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1366 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1368 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1370 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1371 pVarResult, pExcepInfo, puArgErr);
1374 static HRESULT WINAPI HTMLWindow3_get_screenLeft(IHTMLWindow3 *iface, LONG *p)
1376 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1377 FIXME("(%p)->(%p)\n", This, p);
1378 return E_NOTIMPL;
1381 static HRESULT WINAPI HTMLWindow3_get_screenTop(IHTMLWindow3 *iface, LONG *p)
1383 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1384 FIXME("(%p)->(%p)\n", This, p);
1385 return E_NOTIMPL;
1388 static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp, VARIANT_BOOL *pfResult)
1390 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1392 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
1394 return attach_event(&This->event_target, &This->doc_obj->basedoc, event, pDisp, pfResult);
1397 static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp)
1399 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1400 FIXME("(%p)->()\n", This);
1401 return E_NOTIMPL;
1404 static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, LONG msec, VARIANT *language,
1405 BOOL interval, LONG *timer_id)
1407 IDispatch *disp = NULL;
1409 switch(V_VT(expr)) {
1410 case VT_DISPATCH:
1411 disp = V_DISPATCH(expr);
1412 IDispatch_AddRef(disp);
1413 break;
1415 case VT_BSTR:
1416 disp = script_parse_event(This, V_BSTR(expr));
1417 break;
1419 default:
1420 FIXME("unimplemented vt=%d\n", V_VT(expr));
1421 return E_NOTIMPL;
1424 if(!disp)
1425 return E_FAIL;
1427 *timer_id = set_task_timer(&This->doc->basedoc, msec, interval, disp);
1428 IDispatch_Release(disp);
1430 return S_OK;
1433 static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1434 VARIANT *language, LONG *timerID)
1436 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1438 TRACE("(%p)->(%p(%d) %d %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
1440 return window_set_timer(This, expression, msec, language, FALSE, timerID);
1443 static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, LONG msec,
1444 VARIANT *language, LONG *timerID)
1446 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1448 TRACE("(%p)->(%p %d %p %p)\n", This, expression, msec, language, timerID);
1450 return window_set_timer(This, expression, msec, language, TRUE, timerID);
1453 static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)
1455 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1456 FIXME("(%p)\n", This);
1457 return E_NOTIMPL;
1460 static HRESULT WINAPI HTMLWindow3_put_onbeforeprint(IHTMLWindow3 *iface, VARIANT v)
1462 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1463 FIXME("(%p)->()\n", This);
1464 return E_NOTIMPL;
1467 static HRESULT WINAPI HTMLWindow3_get_onbeforeprint(IHTMLWindow3 *iface, VARIANT *p)
1469 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1470 FIXME("(%p)->(%p)\n", This, p);
1471 return E_NOTIMPL;
1474 static HRESULT WINAPI HTMLWindow3_put_onafterprint(IHTMLWindow3 *iface, VARIANT v)
1476 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1477 FIXME("(%p)->()\n", This);
1478 return E_NOTIMPL;
1481 static HRESULT WINAPI HTMLWindow3_get_onafterprint(IHTMLWindow3 *iface, VARIANT *p)
1483 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1484 FIXME("(%p)->(%p)\n", This, p);
1485 return E_NOTIMPL;
1488 static HRESULT WINAPI HTMLWindow3_get_clipboardData(IHTMLWindow3 *iface, IHTMLDataTransfer **p)
1490 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1491 FIXME("(%p)->(%p)\n", This, p);
1492 return E_NOTIMPL;
1495 static HRESULT WINAPI HTMLWindow3_showModelessDialog(IHTMLWindow3 *iface, BSTR url,
1496 VARIANT *varArgIn, VARIANT *options, IHTMLWindow2 **pDialog)
1498 HTMLWindow *This = HTMLWINDOW3_THIS(iface);
1499 FIXME("(%p)->(%s %p %p %p)\n", This, debugstr_w(url), varArgIn, options, pDialog);
1500 return E_NOTIMPL;
1503 #undef HTMLWINDOW3_THIS
1505 static const IHTMLWindow3Vtbl HTMLWindow3Vtbl = {
1506 HTMLWindow3_QueryInterface,
1507 HTMLWindow3_AddRef,
1508 HTMLWindow3_Release,
1509 HTMLWindow3_GetTypeInfoCount,
1510 HTMLWindow3_GetTypeInfo,
1511 HTMLWindow3_GetIDsOfNames,
1512 HTMLWindow3_Invoke,
1513 HTMLWindow3_get_screenLeft,
1514 HTMLWindow3_get_screenTop,
1515 HTMLWindow3_attachEvent,
1516 HTMLWindow3_detachEvent,
1517 HTMLWindow3_setTimeout,
1518 HTMLWindow3_setInterval,
1519 HTMLWindow3_print,
1520 HTMLWindow3_put_onbeforeprint,
1521 HTMLWindow3_get_onbeforeprint,
1522 HTMLWindow3_put_onafterprint,
1523 HTMLWindow3_get_onafterprint,
1524 HTMLWindow3_get_clipboardData,
1525 HTMLWindow3_showModelessDialog
1528 #define HTMLWINDOW4_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow4, iface)
1530 static HRESULT WINAPI HTMLWindow4_QueryInterface(IHTMLWindow4 *iface, REFIID riid, void **ppv)
1532 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1534 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1537 static ULONG WINAPI HTMLWindow4_AddRef(IHTMLWindow4 *iface)
1539 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1541 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1544 static ULONG WINAPI HTMLWindow4_Release(IHTMLWindow4 *iface)
1546 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1548 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1551 static HRESULT WINAPI HTMLWindow4_GetTypeInfoCount(IHTMLWindow4 *iface, UINT *pctinfo)
1553 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1555 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
1558 static HRESULT WINAPI HTMLWindow4_GetTypeInfo(IHTMLWindow4 *iface, UINT iTInfo,
1559 LCID lcid, ITypeInfo **ppTInfo)
1561 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1563 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
1566 static HRESULT WINAPI HTMLWindow4_GetIDsOfNames(IHTMLWindow4 *iface, REFIID riid,
1567 LPOLESTR *rgszNames, UINT cNames,
1568 LCID lcid, DISPID *rgDispId)
1570 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1572 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
1575 static HRESULT WINAPI HTMLWindow4_Invoke(IHTMLWindow4 *iface, DISPID dispIdMember,
1576 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1577 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1579 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1581 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
1582 pVarResult, pExcepInfo, puArgErr);
1585 static HRESULT WINAPI HTMLWindow4_createPopup(IHTMLWindow4 *iface, VARIANT *varArgIn,
1586 IDispatch **ppPopup)
1588 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1589 FIXME("(%p)->(%p %p)\n", This, varArgIn, ppPopup);
1590 return E_NOTIMPL;
1593 static HRESULT WINAPI HTMLWindow4_get_frameElement(IHTMLWindow4 *iface, IHTMLFrameBase **p)
1595 HTMLWindow *This = HTMLWINDOW4_THIS(iface);
1596 TRACE("(%p)->(%p)\n", This, p);
1598 if(This->frame_element) {
1599 *p = HTMLFRAMEBASE(This->frame_element);
1600 IHTMLFrameBase_AddRef(*p);
1601 }else
1602 *p = NULL;
1604 return S_OK;
1607 #undef HTMLWINDOW4_THIS
1609 static const IHTMLWindow4Vtbl HTMLWindow4Vtbl = {
1610 HTMLWindow4_QueryInterface,
1611 HTMLWindow4_AddRef,
1612 HTMLWindow4_Release,
1613 HTMLWindow4_GetTypeInfoCount,
1614 HTMLWindow4_GetTypeInfo,
1615 HTMLWindow4_GetIDsOfNames,
1616 HTMLWindow4_Invoke,
1617 HTMLWindow4_createPopup,
1618 HTMLWindow4_get_frameElement
1621 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLWindow, IDispatchEx, iface)
1623 static HRESULT WINAPI WindowDispEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1625 HTMLWindow *This = DISPEX_THIS(iface);
1627 return IHTMLWindow2_QueryInterface(HTMLWINDOW2(This), riid, ppv);
1630 static ULONG WINAPI WindowDispEx_AddRef(IDispatchEx *iface)
1632 HTMLWindow *This = DISPEX_THIS(iface);
1634 return IHTMLWindow2_AddRef(HTMLWINDOW2(This));
1637 static ULONG WINAPI WindowDispEx_Release(IDispatchEx *iface)
1639 HTMLWindow *This = DISPEX_THIS(iface);
1641 return IHTMLWindow2_Release(HTMLWINDOW2(This));
1644 static HRESULT WINAPI WindowDispEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1646 HTMLWindow *This = DISPEX_THIS(iface);
1648 TRACE("(%p)->(%p)\n", This, pctinfo);
1650 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1653 static HRESULT WINAPI WindowDispEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1654 LCID lcid, ITypeInfo **ppTInfo)
1656 HTMLWindow *This = DISPEX_THIS(iface);
1658 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1660 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1663 static HRESULT WINAPI WindowDispEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1664 LPOLESTR *rgszNames, UINT cNames,
1665 LCID lcid, DISPID *rgDispId)
1667 HTMLWindow *This = DISPEX_THIS(iface);
1669 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1670 lcid, rgDispId);
1672 /* FIXME: Use script dispatch */
1674 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
1677 static HRESULT WINAPI WindowDispEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1678 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1679 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1681 HTMLWindow *This = DISPEX_THIS(iface);
1683 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1684 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1686 /* FIXME: Use script dispatch */
1688 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1689 pVarResult, pExcepInfo, puArgErr);
1692 static global_prop_t *alloc_global_prop(HTMLWindow *This, global_prop_type_t type, BSTR name)
1694 if(This->global_prop_cnt == This->global_prop_size) {
1695 global_prop_t *new_props;
1696 DWORD new_size;
1698 if(This->global_props) {
1699 new_size = This->global_prop_size*2;
1700 new_props = heap_realloc(This->global_props, new_size*sizeof(global_prop_t));
1701 }else {
1702 new_size = 16;
1703 new_props = heap_alloc(new_size*sizeof(global_prop_t));
1705 if(!new_props)
1706 return NULL;
1707 This->global_props = new_props;
1708 This->global_prop_size = new_size;
1711 This->global_props[This->global_prop_cnt].name = heap_strdupW(name);
1712 if(!This->global_props[This->global_prop_cnt].name)
1713 return NULL;
1715 This->global_props[This->global_prop_cnt].type = type;
1716 return This->global_props + This->global_prop_cnt++;
1719 static inline DWORD prop_to_dispid(HTMLWindow *This, global_prop_t *prop)
1721 return MSHTML_DISPID_CUSTOM_MIN + (prop-This->global_props);
1724 static HRESULT WINAPI WindowDispEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1726 HTMLWindow *This = DISPEX_THIS(iface);
1727 ScriptHost *script_host;
1728 DISPID id;
1729 DWORD i;
1730 HRESULT hres;
1732 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
1734 for(i=0; i < This->global_prop_cnt; i++) {
1735 /* FIXME: case sensitivity */
1736 if(!strcmpW(This->global_props[i].name, bstrName)) {
1737 *pid = MSHTML_DISPID_CUSTOM_MIN+i;
1738 return S_OK;
1742 if(find_global_prop(This, bstrName, grfdex, &script_host, &id)) {
1743 global_prop_t *prop;
1745 prop = alloc_global_prop(This, GLOBAL_SCRIPTVAR, bstrName);
1746 if(!prop)
1747 return E_OUTOFMEMORY;
1749 prop->script_host = script_host;
1750 prop->id = id;
1752 *pid = prop_to_dispid(This, prop);
1753 return S_OK;
1756 hres = IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1757 if(hres != DISP_E_UNKNOWNNAME)
1758 return hres;
1760 if(This->doc) {
1761 global_prop_t *prop;
1762 IHTMLElement *elem;
1764 hres = IHTMLDocument3_getElementById(HTMLDOC3(&This->doc->basedoc), bstrName, &elem);
1765 if(SUCCEEDED(hres) && elem) {
1766 IHTMLElement_Release(elem);
1768 prop = alloc_global_prop(This, GLOBAL_ELEMENTVAR, bstrName);
1769 if(!prop)
1770 return E_OUTOFMEMORY;
1772 *pid = prop_to_dispid(This, prop);
1773 return S_OK;
1777 return DISP_E_UNKNOWNNAME;
1780 static HRESULT WINAPI WindowDispEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1781 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1783 HTMLWindow *This = DISPEX_THIS(iface);
1785 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1787 if(id == DISPID_IHTMLWINDOW2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT)) {
1788 HTMLLocation *location;
1789 HRESULT hres;
1791 TRACE("forwarding to location.href\n");
1793 hres = get_location(This, &location);
1794 if(FAILED(hres))
1795 return hres;
1797 hres = IDispatchEx_InvokeEx(DISPATCHEX(&location->dispex), DISPID_VALUE, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1798 IHTMLLocation_Release(HTMLLOCATION(location));
1799 return hres;
1802 return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1805 static HRESULT WINAPI WindowDispEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1807 HTMLWindow *This = DISPEX_THIS(iface);
1809 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
1811 return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
1814 static HRESULT WINAPI WindowDispEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1816 HTMLWindow *This = DISPEX_THIS(iface);
1818 TRACE("(%p)->(%x)\n", This, id);
1820 return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
1823 static HRESULT WINAPI WindowDispEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1825 HTMLWindow *This = DISPEX_THIS(iface);
1827 TRACE("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
1829 return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
1832 static HRESULT WINAPI WindowDispEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1834 HTMLWindow *This = DISPEX_THIS(iface);
1836 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
1838 return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
1841 static HRESULT WINAPI WindowDispEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1843 HTMLWindow *This = DISPEX_THIS(iface);
1845 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
1847 return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
1850 static HRESULT WINAPI WindowDispEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1852 HTMLWindow *This = DISPEX_THIS(iface);
1854 TRACE("(%p)->(%p)\n", This, ppunk);
1856 *ppunk = NULL;
1857 return S_OK;
1860 #undef DISPEX_THIS
1862 static const IDispatchExVtbl WindowDispExVtbl = {
1863 WindowDispEx_QueryInterface,
1864 WindowDispEx_AddRef,
1865 WindowDispEx_Release,
1866 WindowDispEx_GetTypeInfoCount,
1867 WindowDispEx_GetTypeInfo,
1868 WindowDispEx_GetIDsOfNames,
1869 WindowDispEx_Invoke,
1870 WindowDispEx_GetDispID,
1871 WindowDispEx_InvokeEx,
1872 WindowDispEx_DeleteMemberByName,
1873 WindowDispEx_DeleteMemberByDispID,
1874 WindowDispEx_GetMemberProperties,
1875 WindowDispEx_GetMemberName,
1876 WindowDispEx_GetNextDispID,
1877 WindowDispEx_GetNameSpaceParent
1880 static const tid_t HTMLWindow_iface_tids[] = {
1881 IHTMLWindow2_tid,
1882 IHTMLWindow3_tid,
1883 IHTMLWindow4_tid,
1887 static const dispex_static_data_vtbl_t HTMLWindow_dispex_vtbl = {
1888 NULL,
1889 NULL,
1890 HTMLWindow_invoke
1893 static dispex_static_data_t HTMLWindow_dispex = {
1894 &HTMLWindow_dispex_vtbl,
1895 DispHTMLWindow2_tid,
1896 NULL,
1897 HTMLWindow_iface_tids
1900 HRESULT HTMLWindow_Create(HTMLDocumentObj *doc_obj, nsIDOMWindow *nswindow, HTMLWindow *parent, HTMLWindow **ret)
1902 HTMLWindow *window;
1904 window = heap_alloc_zero(sizeof(HTMLWindow));
1905 if(!window)
1906 return E_OUTOFMEMORY;
1908 window->window_ref = heap_alloc(sizeof(windowref_t));
1909 if(!window->window_ref) {
1910 heap_free(window);
1911 return E_OUTOFMEMORY;
1914 window->lpHTMLWindow2Vtbl = &HTMLWindow2Vtbl;
1915 window->lpHTMLWindow3Vtbl = &HTMLWindow3Vtbl;
1916 window->lpHTMLWindow4Vtbl = &HTMLWindow4Vtbl;
1917 window->lpIDispatchExVtbl = &WindowDispExVtbl;
1918 window->ref = 1;
1919 window->doc_obj = doc_obj;
1921 window->window_ref->window = window;
1922 window->window_ref->ref = 1;
1924 init_dispex(&window->dispex, (IUnknown*)HTMLWINDOW2(window), &HTMLWindow_dispex);
1926 if(nswindow) {
1927 nsIDOMWindow_AddRef(nswindow);
1928 window->nswindow = nswindow;
1931 window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO;
1932 window->readystate = READYSTATE_UNINITIALIZED;
1933 list_init(&window->script_hosts);
1935 window->task_magic = get_task_target_magic();
1936 update_window_doc(window);
1938 list_init(&window->children);
1939 list_add_head(&window_list, &window->entry);
1941 if(parent) {
1942 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
1944 window->parent = parent;
1945 list_add_tail(&parent->children, &window->sibling_entry);
1948 *ret = window;
1949 return S_OK;
1952 void update_window_doc(HTMLWindow *window)
1954 nsIDOMHTMLDocument *nshtmldoc;
1955 nsIDOMDocument *nsdoc;
1956 nsresult nsres;
1958 nsres = nsIDOMWindow_GetDocument(window->nswindow, &nsdoc);
1959 if(NS_FAILED(nsres) || !nsdoc) {
1960 ERR("GetDocument failed: %08x\n", nsres);
1961 return;
1964 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
1965 nsIDOMDocument_Release(nsdoc);
1966 if(NS_FAILED(nsres)) {
1967 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
1968 return;
1971 if(!window->doc || window->doc->nsdoc != nshtmldoc) {
1972 HTMLDocumentNode *doc;
1973 HRESULT hres;
1975 hres = create_doc_from_nsdoc(nshtmldoc, window->doc_obj, window, &doc);
1976 if(SUCCEEDED(hres)) {
1977 window_set_docnode(window, doc);
1978 htmldoc_release(&doc->basedoc);
1979 }else {
1980 ERR("create_doc_from_nsdoc failed: %08x\n", hres);
1984 nsIDOMHTMLDocument_Release(nshtmldoc);
1987 HTMLWindow *nswindow_to_window(const nsIDOMWindow *nswindow)
1989 HTMLWindow *iter;
1991 LIST_FOR_EACH_ENTRY(iter, &window_list, HTMLWindow, entry) {
1992 if(iter->nswindow == nswindow)
1993 return iter;
1996 return NULL;