include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / mshtml / view.c
blobfe7448ec0cf52ab232a855460d15fb69ac913964
1 /*
2 * Copyright 2005-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>
20 #include <stdio.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "commctrl.h"
28 #include "ole2.h"
29 #include "resource.h"
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
34 #include "htmlevent.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define TIMER_ID 0x1000
40 static ATOM serverwnd_class = 0;
42 typedef struct {
43 HTMLDocumentObj *doc;
44 WNDPROC proc;
45 } tooltip_data;
47 static void paint_document(HTMLDocumentObj *This)
49 PAINTSTRUCT ps;
50 RECT rect;
51 HDC hdc;
53 if(This->window && This->window->base.inner_window && !This->window->base.inner_window->first_paint_time)
54 This->window->base.inner_window->first_paint_time = get_time_stamp();
56 GetClientRect(This->hwnd, &rect);
58 hdc = BeginPaint(This->hwnd, &ps);
60 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER)))
61 DrawEdge(hdc, &rect, EDGE_SUNKEN, BF_RECT|BF_ADJUST);
63 EndPaint(This->hwnd, &ps);
66 static void activate_gecko(GeckoBrowser *This)
68 TRACE("(%p) %p\n", This, This->window);
70 SetParent(This->hwnd, This->doc->hwnd);
71 ShowWindow(This->hwnd, SW_SHOW);
73 nsIBaseWindow_SetVisibility(This->window, TRUE);
74 nsIBaseWindow_SetEnabled(This->window, TRUE);
77 void update_doc(HTMLDocumentObj *This, DWORD flags)
79 if(!This->update && This->hwnd)
80 SetTimer(This->hwnd, TIMER_ID, 100, NULL);
82 This->update |= flags;
85 void update_title(HTMLDocumentObj *This)
87 IOleCommandTarget *olecmd;
88 HRESULT hres;
90 if(!(This->update & UPDATE_TITLE))
91 return;
93 This->update &= ~UPDATE_TITLE;
95 if(!This->client)
96 return;
98 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&olecmd);
99 if(SUCCEEDED(hres)) {
100 VARIANT title;
102 V_VT(&title) = VT_BSTR;
103 V_BSTR(&title) = SysAllocString(L"");
104 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER,
105 &title, NULL);
106 SysFreeString(V_BSTR(&title));
108 IOleCommandTarget_Release(olecmd);
112 static LRESULT on_timer(HTMLDocumentObj *This)
114 TRACE("(%p) %lx\n", This, This->update);
116 KillTimer(This->hwnd, TIMER_ID);
118 if(!This->update)
119 return 0;
120 IUnknown_AddRef(This->outer_unk);
122 if(This->update & UPDATE_UI) {
123 if(This->hostui)
124 IDocHostUIHandler_UpdateUI(This->hostui);
126 if(This->client) {
127 IOleCommandTarget *cmdtrg;
128 HRESULT hres;
130 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
131 (void**)&cmdtrg);
132 if(SUCCEEDED(hres)) {
133 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_UPDATECOMMANDS,
134 OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
135 IOleCommandTarget_Release(cmdtrg);
140 update_title(This);
141 This->update = 0;
143 IUnknown_Release(This->outer_unk);
144 return 0;
147 void notif_focus(HTMLDocumentObj *This)
149 IOleControlSite *site;
150 HRESULT hres;
152 if(!This->client)
153 return;
155 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleControlSite, (void**)&site);
156 if(FAILED(hres))
157 return;
159 IOleControlSite_OnFocus(site, This->focus);
160 IOleControlSite_Release(site);
163 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
165 HTMLDocumentObj *This;
167 if(msg == WM_CREATE) {
168 This = *(HTMLDocumentObj**)lParam;
169 SetPropW(hwnd, L"THIS", This);
170 }else {
171 This = GetPropW(hwnd, L"THIS");
174 switch(msg) {
175 case WM_CREATE:
176 This->hwnd = hwnd;
177 break;
178 case WM_PAINT:
179 paint_document(This);
180 break;
181 case WM_SIZE:
182 TRACE("(%p)->(WM_SIZE)\n", This);
183 if(This->nscontainer) {
184 INT ew=0, eh=0;
186 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER))) {
187 ew = GetSystemMetrics(SM_CXEDGE);
188 eh = GetSystemMetrics(SM_CYEDGE);
191 SetWindowPos(This->nscontainer->hwnd, NULL, ew, eh,
192 LOWORD(lParam) - 2*ew, HIWORD(lParam) - 2*eh,
193 SWP_NOZORDER | SWP_NOACTIVATE);
195 break;
196 case WM_TIMER:
197 return on_timer(This);
198 case WM_SETFOCUS:
199 TRACE("(%p) WM_SETFOCUS\n", This);
200 nsIWebBrowserFocus_Activate(This->nscontainer->focus);
201 break;
202 case WM_MOUSEACTIVATE:
203 return MA_ACTIVATE;
206 return DefWindowProcW(hwnd, msg, wParam, lParam);
209 static void register_serverwnd_class(void)
211 static WNDCLASSEXW wndclass = {
212 sizeof(WNDCLASSEXW),
213 CS_DBLCLKS,
214 serverwnd_proc,
215 0, 0, NULL, NULL, NULL, NULL, NULL,
216 L"Internet Explorer_Server",
217 NULL,
219 wndclass.hInstance = hInst;
220 serverwnd_class = RegisterClassExW(&wndclass);
223 static HRESULT activate_window(HTMLDocumentObj *This)
225 IOleInPlaceFrame *pIPFrame;
226 IOleCommandTarget *cmdtrg;
227 IOleInPlaceSiteEx *ipsiteex;
228 RECT posrect, cliprect;
229 OLEINPLACEFRAMEINFO frameinfo;
230 HWND parent_hwnd;
231 HRESULT hres;
233 if(!serverwnd_class)
234 register_serverwnd_class();
236 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
237 if(hres != S_OK) {
238 WARN("CanInPlaceActivate returned: %08lx\n", hres);
239 return FAILED(hres) ? hres : E_FAIL;
242 frameinfo.cb = sizeof(OLEINPLACEFRAMEINFO);
243 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &This->ip_window,
244 &posrect, &cliprect, &frameinfo);
245 if(FAILED(hres)) {
246 WARN("GetWindowContext failed: %08lx\n", hres);
247 return hres;
250 TRACE("got window context: %p %p %s %s {%d %x %p %p %d}\n",
251 pIPFrame, This->ip_window, wine_dbgstr_rect(&posrect), wine_dbgstr_rect(&cliprect),
252 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
254 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
255 if(FAILED(hres)) {
256 WARN("GetWindow failed: %08lx\n", hres);
257 return hres;
260 TRACE("got parent window %p\n", parent_hwnd);
262 if(This->hwnd) {
263 if(GetParent(This->hwnd) != parent_hwnd)
264 SetParent(This->hwnd, parent_hwnd);
265 SetWindowPos(This->hwnd, HWND_TOP,
266 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
267 SWP_NOACTIVATE | SWP_SHOWWINDOW);
268 }else {
269 CreateWindowExW(0, L"Internet Explorer_Server", NULL,
270 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
271 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
272 parent_hwnd, NULL, hInst, This);
274 TRACE("Created window %p\n", This->hwnd);
276 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
277 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
278 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
279 SetTimer(This->hwnd, TIMER_ID, 100, NULL);
282 if(This->nscontainer)
283 activate_gecko(This->nscontainer);
285 This->in_place_active = TRUE;
286 hres = IOleInPlaceSite_QueryInterface(This->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex);
287 if(SUCCEEDED(hres)) {
288 BOOL redraw = FALSE;
290 hres = IOleInPlaceSiteEx_OnInPlaceActivateEx(ipsiteex, &redraw, 0);
291 IOleInPlaceSiteEx_Release(ipsiteex);
292 if(redraw)
293 FIXME("unsupported redraw\n");
294 }else{
295 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
297 if(FAILED(hres)) {
298 WARN("OnInPlaceActivate failed: %08lx\n", hres);
299 This->in_place_active = FALSE;
300 return hres;
303 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
304 if(SUCCEEDED(hres)) {
305 VARIANT var;
307 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
309 V_VT(&var) = VT_I4;
310 V_I4(&var) = 0;
311 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
312 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
313 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS,
314 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
316 IOleCommandTarget_Release(cmdtrg);
319 if(This->frame)
320 IOleInPlaceFrame_Release(This->frame);
321 This->frame = pIPFrame;
323 if(!This->request_uiactivate) {
324 hres = IOleInPlaceSite_QueryInterface(This->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex);
325 if(SUCCEEDED(hres)) {
326 IOleInPlaceSiteEx_RequestUIActivate(ipsiteex);
327 IOleInPlaceSiteEx_Release(ipsiteex);
331 This->window_active = TRUE;
333 return S_OK;
336 static LRESULT WINAPI tooltips_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
338 tooltip_data *data = GetPropW(hwnd, L"tooltip_data");
340 TRACE("%d %p\n", msg, data);
342 if(msg == TTM_WINDOWFROMPOINT) {
343 RECT rect;
344 POINT *pt = (POINT*)lParam;
346 TRACE("TTM_WINDOWFROMPOINT (%ld,%ld)\n", pt->x, pt->y);
348 GetWindowRect(data->doc->hwnd, &rect);
350 if(rect.left <= pt->x && pt->x <= rect.right
351 && rect.top <= pt->y && pt->y <= rect.bottom)
352 return (LPARAM)data->doc->hwnd;
355 return CallWindowProcW(data->proc, hwnd, msg, wParam, lParam);
358 static void create_tooltips_window(HTMLDocumentObj *This)
360 tooltip_data *data = malloc(sizeof(*data));
362 This->tooltips_hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, TTS_NOPREFIX | WS_POPUP,
363 CW_USEDEFAULT, CW_USEDEFAULT, 10, 10, This->hwnd, NULL, hInst, NULL);
365 data->doc = This;
366 data->proc = (WNDPROC)GetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC);
368 SetPropW(This->tooltips_hwnd, L"tooltip_data", data);
370 SetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC, (LONG_PTR)tooltips_proc);
372 SetWindowPos(This->tooltips_hwnd, HWND_TOPMOST,0, 0, 0, 0,
373 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
377 void show_tooltip(HTMLDocumentObj *This, DWORD x, DWORD y, LPCWSTR text)
379 TTTOOLINFOW toolinfo = {
380 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
381 {x>2 ? x-2 : 0, y>0 ? y-2 : 0, x+2, y+2}, /* FIXME */
382 NULL, (LPWSTR)text, 0};
383 MSG msg = {This->hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x,y), 0, {x,y}};
385 TRACE("(%p)->(%ld %ld %s)\n", This, x, y, debugstr_w(text));
387 if(!This->tooltips_hwnd)
388 create_tooltips_window(This);
390 SendMessageW(This->tooltips_hwnd, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo);
391 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, TRUE, 0);
392 SendMessageW(This->tooltips_hwnd, TTM_RELAYEVENT, 0, (LPARAM)&msg);
395 void hide_tooltip(HTMLDocumentObj *This)
397 TTTOOLINFOW toolinfo = {
398 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
399 {0,0,0,0}, NULL, NULL, 0};
401 TRACE("(%p)\n", This);
403 SendMessageW(This->tooltips_hwnd, TTM_DELTOOLW, 0, (LPARAM)&toolinfo);
404 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, FALSE, 0);
407 HRESULT call_set_active_object(IOleInPlaceUIWindow *window, IOleInPlaceActiveObject *act_obj)
409 static WCHAR html_documentW[30];
411 if(act_obj && !html_documentW[0])
412 LoadStringW(hInst, IDS_HTMLDOCUMENT, html_documentW, ARRAY_SIZE(html_documentW));
414 return IOleInPlaceUIWindow_SetActiveObject(window, act_obj, act_obj ? html_documentW : NULL);
417 static unsigned get_window_list_num(HTMLInnerWindow *window)
419 HTMLOuterWindow *child;
420 unsigned ret = 1;
422 LIST_FOR_EACH_ENTRY(child, &window->children, HTMLOuterWindow, sibling_entry)
423 ret += get_window_list_num(child->base.inner_window);
424 return ret;
427 static HTMLInnerWindow **get_window_list(HTMLInnerWindow *window, HTMLInnerWindow **output)
429 HTMLOuterWindow *child;
431 *output++ = window;
432 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
434 LIST_FOR_EACH_ENTRY(child, &window->children, HTMLOuterWindow, sibling_entry)
435 output = get_window_list(child->base.inner_window, output);
436 return output;
439 static void send_unload_events(HTMLDocumentObj *doc)
441 HTMLInnerWindow **windows, *window;
442 DOMEvent *event;
443 unsigned i, num;
444 HRESULT hres;
446 if(!doc->window || !doc->doc_node->content_ready)
447 return;
448 window = doc->window->base.inner_window;
450 /* Grab list of all windows ahead, and keep refs,
451 since it can be detached from under our feet. */
452 num = get_window_list_num(window);
453 if(!(windows = malloc(num * sizeof(*windows))))
454 return;
455 get_window_list(window, windows);
457 for(i = 0; i < num; i++) {
458 window = windows[i];
460 if(window->doc && !window->doc->unload_sent) {
461 window->doc->unload_sent = TRUE;
463 /* Native sends pagehide events prior to unload on the same window
464 before it moves on to the next window, so they're interleaved. */
465 if(window->doc->document_mode >= COMPAT_MODE_IE11) {
466 hres = create_document_event(window->doc, EVENTID_PAGEHIDE, &event);
467 if(SUCCEEDED(hres)) {
468 dispatch_event(&window->event_target, event);
469 IDOMEvent_Release(&event->IDOMEvent_iface);
473 hres = create_document_event(window->doc, EVENTID_UNLOAD, &event);
474 if(SUCCEEDED(hres)) {
475 dispatch_event(&window->event_target, event);
476 IDOMEvent_Release(&event->IDOMEvent_iface);
480 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
483 free(windows);
486 /**********************************************************
487 * IOleDocumentView implementation
490 static inline HTMLDocumentObj *impl_from_IOleDocumentView(IOleDocumentView *iface)
492 return CONTAINING_RECORD(iface, HTMLDocumentObj, IOleDocumentView_iface);
495 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
497 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
498 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObject);
501 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
503 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
504 return IUnknown_AddRef(This->outer_unk);
507 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
509 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
510 return IUnknown_Release(This->outer_unk);
513 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
515 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
516 TRACE("(%p)->(%p)\n", This, pIPSite);
518 if(pIPSite)
519 IOleInPlaceSite_AddRef(pIPSite);
521 if(This->ipsite)
522 IOleInPlaceSite_Release(This->ipsite);
524 This->ipsite = pIPSite;
525 This->request_uiactivate = TRUE;
526 return S_OK;
529 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
531 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
532 TRACE("(%p)->(%p)\n", This, ppIPSite);
534 if(!ppIPSite)
535 return E_INVALIDARG;
537 if(This->ipsite)
538 IOleInPlaceSite_AddRef(This->ipsite);
540 *ppIPSite = This->ipsite;
541 return S_OK;
544 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
546 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
547 TRACE("(%p)->(%p)\n", This, ppunk);
549 if(!ppunk)
550 return E_INVALIDARG;
552 *ppunk = (IUnknown*)&This->IHTMLDocument2_iface;
553 IUnknown_AddRef(*ppunk);
554 return S_OK;
557 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
559 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
560 RECT rect;
562 TRACE("(%p)->(%p)\n", This, prcView);
564 if(!prcView)
565 return E_INVALIDARG;
567 if(This->hwnd) {
568 GetClientRect(This->hwnd, &rect);
569 if(!EqualRect(prcView, &rect)) {
570 InvalidateRect(This->hwnd, NULL, TRUE);
571 SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right - prcView->left,
572 prcView->bottom - prcView->top, SWP_NOZORDER | SWP_NOACTIVATE);
576 return S_OK;
579 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
581 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
583 TRACE("(%p)->(%p)\n", This, prcView);
585 if(!prcView)
586 return E_INVALIDARG;
588 GetClientRect(This->hwnd, prcView);
589 MapWindowPoints(This->hwnd, GetParent(This->hwnd), (POINT*)prcView, 2);
590 return S_OK;
593 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
594 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
596 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
597 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
598 return E_NOTIMPL;
601 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
603 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
604 HRESULT hres;
606 TRACE("(%p)->(%x)\n", This, fShow);
608 if(fShow) {
609 if(!This->ui_active) {
610 hres = activate_window(This);
611 if(FAILED(hres))
612 return hres;
614 update_doc(This, UPDATE_UI);
615 ShowWindow(This->hwnd, SW_SHOW);
616 }else {
617 ShowWindow(This->hwnd, SW_HIDE);
619 if(This->in_place_active)
620 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->IOleInPlaceObjectWindowless_iface);
622 unlink_ref(&This->ip_window);
625 return S_OK;
628 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
630 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
631 HRESULT hres;
633 TRACE("(%p)->(%x)\n", This, fUIActivate);
635 if(!This->ipsite) {
636 IOleClientSite *cs = This->client;
637 IOleInPlaceSite *ips;
639 if(!cs) {
640 WARN("this->ipsite = NULL\n");
641 return E_UNEXPECTED;
644 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteWindowless, (void**)&ips);
645 if(SUCCEEDED(hres))
646 This->ipsite = ips;
647 else {
648 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteEx, (void**)&ips);
649 if(SUCCEEDED(hres))
650 This->ipsite = ips;
651 else {
652 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSite, (void**)&ips);
653 if(SUCCEEDED(hres))
654 This->ipsite = ips;
655 else {
656 WARN("this->ipsite = NULL\n");
657 return E_NOINTERFACE;
662 IOleInPlaceSite_AddRef(This->ipsite);
663 This->request_uiactivate = FALSE;
664 HTMLDocument_LockContainer(This, TRUE);
667 if(fUIActivate) {
668 RECT rcBorderWidths;
670 if(This->ui_active)
671 return S_OK;
673 if(!This->window_active) {
674 hres = activate_window(This);
675 if(FAILED(hres))
676 return hres;
679 This->focus = TRUE;
680 if(This->nscontainer)
681 nsIWebBrowserFocus_Activate(This->nscontainer->focus);
682 notif_focus(This);
684 update_doc(This, UPDATE_UI);
686 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
687 if(SUCCEEDED(hres)) {
688 call_set_active_object((IOleInPlaceUIWindow*)This->frame, &This->IOleInPlaceActiveObject_iface);
689 }else {
690 FIXME("OnUIActivate failed: %08lx\n", hres);
691 IOleInPlaceFrame_Release(This->frame);
692 This->frame = NULL;
693 This->ui_active = FALSE;
694 return hres;
697 if(This->hostui) {
698 hres = IDocHostUIHandler_ShowUI(This->hostui,
699 This->nscontainer->usermode == EDITMODE ? DOCHOSTUITYPE_AUTHOR : DOCHOSTUITYPE_BROWSE,
700 &This->IOleInPlaceActiveObject_iface, &This->IOleCommandTarget_iface,
701 This->frame, This->ip_window);
702 if(FAILED(hres))
703 IDocHostUIHandler_HideUI(This->hostui);
706 if(This->ip_window)
707 call_set_active_object(This->ip_window, &This->IOleInPlaceActiveObject_iface);
709 SetRectEmpty(&rcBorderWidths);
710 IOleInPlaceFrame_SetBorderSpace(This->frame, &rcBorderWidths);
712 This->ui_active = TRUE;
713 }else {
714 This->focus = FALSE;
715 nsIWebBrowserFocus_Deactivate(This->nscontainer->focus);
716 if(This->ui_active) {
717 This->ui_active = FALSE;
718 if(This->ip_window)
719 call_set_active_object(This->ip_window, NULL);
720 if(This->frame)
721 call_set_active_object((IOleInPlaceUIWindow*)This->frame, NULL);
722 if(This->hostui)
723 IDocHostUIHandler_HideUI(This->hostui);
724 if(This->ipsite)
725 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
728 return S_OK;
731 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
733 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
734 FIXME("(%p)\n", This);
735 return E_NOTIMPL;
738 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
740 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
741 TRACE("(%p)->(%lx)\n", This, dwReserved);
743 if(dwReserved)
744 WARN("dwReserved = %ld\n", dwReserved);
746 send_unload_events(This);
747 IOleDocumentView_Show(iface, FALSE);
748 return S_OK;
751 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, IStream *pstm)
753 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
754 FIXME("(%p)->(%p)\n", This, pstm);
755 return E_NOTIMPL;
758 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, IStream *pstm)
760 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
761 FIXME("(%p)->(%p)\n", This, pstm);
762 return E_NOTIMPL;
765 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
766 IOleDocumentView **ppViewNew)
768 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
769 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
770 return E_NOTIMPL;
773 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
774 OleDocumentView_QueryInterface,
775 OleDocumentView_AddRef,
776 OleDocumentView_Release,
777 OleDocumentView_SetInPlaceSite,
778 OleDocumentView_GetInPlaceSite,
779 OleDocumentView_GetDocument,
780 OleDocumentView_SetRect,
781 OleDocumentView_GetRect,
782 OleDocumentView_SetRectComplex,
783 OleDocumentView_Show,
784 OleDocumentView_UIActivate,
785 OleDocumentView_Open,
786 OleDocumentView_CloseView,
787 OleDocumentView_SaveViewState,
788 OleDocumentView_ApplyViewState,
789 OleDocumentView_Clone
792 /**********************************************************
793 * IViewObject implementation
796 static inline HTMLDocumentObj *impl_from_IViewObjectEx(IViewObjectEx *iface)
798 return CONTAINING_RECORD(iface, HTMLDocumentObj, IViewObjectEx_iface);
801 static HRESULT WINAPI ViewObject_QueryInterface(IViewObjectEx *iface, REFIID riid, void **ppv)
803 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
804 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
807 static ULONG WINAPI ViewObject_AddRef(IViewObjectEx *iface)
809 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
810 return IUnknown_AddRef(This->outer_unk);
813 static ULONG WINAPI ViewObject_Release(IViewObjectEx *iface)
815 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
816 return IUnknown_Release(This->outer_unk);
819 static HRESULT WINAPI ViewObject_Draw(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
820 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
821 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
823 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
824 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %Id)\n", This, dwDrawAspect, lindex, pvAspect,
825 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
826 return E_NOTIMPL;
829 static HRESULT WINAPI ViewObject_GetColorSet(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
830 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
832 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
833 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
834 return E_NOTIMPL;
837 static HRESULT WINAPI ViewObject_Freeze(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex,
838 void *pvAspect, DWORD *pdwFreeze)
840 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
841 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
842 return E_NOTIMPL;
845 static HRESULT WINAPI ViewObject_Unfreeze(IViewObjectEx *iface, DWORD dwFreeze)
847 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
848 FIXME("(%p)->(%ld)\n", This, dwFreeze);
849 return E_NOTIMPL;
852 static HRESULT WINAPI ViewObject_SetAdvise(IViewObjectEx *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
854 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
856 TRACE("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
858 if(aspects != DVASPECT_CONTENT || advf != ADVF_PRIMEFIRST)
859 FIXME("unsupported arguments\n");
861 if(This->view_sink)
862 IAdviseSink_Release(This->view_sink);
863 if(pAdvSink)
864 IAdviseSink_AddRef(pAdvSink);
866 This->view_sink = pAdvSink;
867 return S_OK;
870 static HRESULT WINAPI ViewObject_GetAdvise(IViewObjectEx *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
872 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
873 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
874 return E_NOTIMPL;
877 static HRESULT WINAPI ViewObject_GetExtent(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex,
878 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
880 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
881 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
882 return E_NOTIMPL;
885 static HRESULT WINAPI ViewObject_GetRect(IViewObjectEx *iface, DWORD dwAspect, LPRECTL pRect)
887 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
888 FIXME("(%p)->(%ld %p)\n", This, dwAspect, pRect);
889 return E_NOTIMPL;
892 static HRESULT WINAPI ViewObject_GetViewStatus(IViewObjectEx *iface, DWORD *pdwStatus)
894 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
895 FIXME("(%p)->(%p)\n", This, pdwStatus);
896 return E_NOTIMPL;
899 static HRESULT WINAPI ViewObject_QueryHitPoint(IViewObjectEx* iface, DWORD dwAspect,
900 LPCRECT pRectBounds, POINT ptlLoc, LONG lCloseHint, DWORD *pHitResult)
902 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
903 FIXME("(%p)->(%ld %p (%ld %ld) %ld %p)\n", This, dwAspect, pRectBounds, ptlLoc.x,
904 ptlLoc.y, lCloseHint, pHitResult);
905 return E_NOTIMPL;
908 static HRESULT WINAPI ViewObject_QueryHitRect(IViewObjectEx *iface, DWORD dwAspect,
909 LPCRECT pRectBounds, LPCRECT pRectLoc, LONG lCloseHint, DWORD *pHitResult)
911 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
912 FIXME("(%p)->(%ld %p %p %ld %p)\n", This, dwAspect, pRectBounds, pRectLoc, lCloseHint, pHitResult);
913 return E_NOTIMPL;
916 static HRESULT WINAPI ViewObject_GetNaturalExtent(IViewObjectEx *iface, DWORD dwAspect, LONG lindex,
917 DVTARGETDEVICE *ptd, HDC hicTargetDev, DVEXTENTINFO *pExtentInfo, LPSIZEL pSizel)
919 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
920 FIXME("(%p)->(%ld %ld %p %p %p %p\n", This, dwAspect,lindex, ptd,
921 hicTargetDev, pExtentInfo, pSizel);
922 return E_NOTIMPL;
925 static const IViewObjectExVtbl ViewObjectVtbl = {
926 ViewObject_QueryInterface,
927 ViewObject_AddRef,
928 ViewObject_Release,
929 ViewObject_Draw,
930 ViewObject_GetColorSet,
931 ViewObject_Freeze,
932 ViewObject_Unfreeze,
933 ViewObject_SetAdvise,
934 ViewObject_GetAdvise,
935 ViewObject_GetExtent,
936 ViewObject_GetRect,
937 ViewObject_GetViewStatus,
938 ViewObject_QueryHitPoint,
939 ViewObject_QueryHitRect,
940 ViewObject_GetNaturalExtent
943 static inline HTMLDocumentObj *impl_from_IWindowForBindingUI(IWindowForBindingUI *iface)
945 return CONTAINING_RECORD(iface, HTMLDocumentObj, IWindowForBindingUI_iface);
948 static HRESULT WINAPI WindowForBindingUI_QueryInterface(IWindowForBindingUI *iface, REFIID riid, void **ppv)
950 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
952 if(IsEqualGUID(&IID_IUnknown, riid)) {
953 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
954 *ppv = &This->IWindowForBindingUI_iface;
955 }else if(IsEqualGUID(&IID_IWindowForBindingUI, riid)) {
956 TRACE("(%p)->(IID_IWindowForBindingUI %p)\n", This, ppv);
957 *ppv = &This->IWindowForBindingUI_iface;
958 }else {
959 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
960 *ppv = NULL;
961 return E_NOINTERFACE;
964 IUnknown_AddRef((IUnknown*)*ppv);
965 return S_OK;
968 static ULONG WINAPI WindowForBindingUI_AddRef(IWindowForBindingUI *iface)
970 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
971 return IUnknown_AddRef(This->outer_unk);
974 static ULONG WINAPI WindowForBindingUI_Release(IWindowForBindingUI *iface)
976 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
977 return IUnknown_Release(This->outer_unk);
980 static HRESULT WINAPI WindowForBindingUI_GetWindow(IWindowForBindingUI *iface, REFGUID rguidReason, HWND *phwnd)
982 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
984 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(rguidReason), phwnd);
986 *phwnd = This->hwnd;
987 return S_OK;
990 static const IWindowForBindingUIVtbl WindowForBindingUIVtbl = {
991 WindowForBindingUI_QueryInterface,
992 WindowForBindingUI_AddRef,
993 WindowForBindingUI_Release,
994 WindowForBindingUI_GetWindow
997 void HTMLDocument_View_Init(HTMLDocumentObj *doc)
999 doc->IOleDocumentView_iface.lpVtbl = &OleDocumentViewVtbl;
1000 doc->IViewObjectEx_iface.lpVtbl = &ViewObjectVtbl;
1001 doc->IWindowForBindingUI_iface.lpVtbl = &WindowForBindingUIVtbl;