mshtml: Fix classList toggle() when return value pointer is NULL.
[wine.git] / dlls / mshtml / view.c
blob3f31e609e39f5b919cf6f22caa95bfacde69a044
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->performance_timing->first_paint_time)
54 This->window->base.inner_window->performance_timing->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 if(This->ip_window) {
623 IOleInPlaceUIWindow_Release(This->ip_window);
624 This->ip_window = NULL;
628 return S_OK;
631 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
633 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
634 HRESULT hres;
636 TRACE("(%p)->(%x)\n", This, fUIActivate);
638 if(!This->ipsite) {
639 IOleClientSite *cs = This->client;
640 IOleInPlaceSite *ips;
642 if(!cs) {
643 WARN("this->ipsite = NULL\n");
644 return E_UNEXPECTED;
647 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteWindowless, (void**)&ips);
648 if(SUCCEEDED(hres))
649 This->ipsite = ips;
650 else {
651 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteEx, (void**)&ips);
652 if(SUCCEEDED(hres))
653 This->ipsite = ips;
654 else {
655 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSite, (void**)&ips);
656 if(SUCCEEDED(hres))
657 This->ipsite = ips;
658 else {
659 WARN("this->ipsite = NULL\n");
660 return E_NOINTERFACE;
665 IOleInPlaceSite_AddRef(This->ipsite);
666 This->request_uiactivate = FALSE;
667 HTMLDocument_LockContainer(This, TRUE);
670 if(fUIActivate) {
671 RECT rcBorderWidths;
673 if(This->ui_active)
674 return S_OK;
676 if(!This->window_active) {
677 hres = activate_window(This);
678 if(FAILED(hres))
679 return hres;
682 This->focus = TRUE;
683 if(This->nscontainer)
684 nsIWebBrowserFocus_Activate(This->nscontainer->focus);
685 notif_focus(This);
687 update_doc(This, UPDATE_UI);
689 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
690 if(SUCCEEDED(hres)) {
691 call_set_active_object((IOleInPlaceUIWindow*)This->frame, &This->IOleInPlaceActiveObject_iface);
692 }else {
693 FIXME("OnUIActivate failed: %08lx\n", hres);
694 IOleInPlaceFrame_Release(This->frame);
695 This->frame = NULL;
696 This->ui_active = FALSE;
697 return hres;
700 if(This->hostui) {
701 hres = IDocHostUIHandler_ShowUI(This->hostui,
702 This->nscontainer->usermode == EDITMODE ? DOCHOSTUITYPE_AUTHOR : DOCHOSTUITYPE_BROWSE,
703 &This->IOleInPlaceActiveObject_iface, &This->IOleCommandTarget_iface,
704 This->frame, This->ip_window);
705 if(FAILED(hres))
706 IDocHostUIHandler_HideUI(This->hostui);
709 if(This->ip_window)
710 call_set_active_object(This->ip_window, &This->IOleInPlaceActiveObject_iface);
712 SetRectEmpty(&rcBorderWidths);
713 IOleInPlaceFrame_SetBorderSpace(This->frame, &rcBorderWidths);
715 This->ui_active = TRUE;
716 }else {
717 This->focus = FALSE;
718 nsIWebBrowserFocus_Deactivate(This->nscontainer->focus);
719 if(This->ui_active) {
720 This->ui_active = FALSE;
721 if(This->ip_window)
722 call_set_active_object(This->ip_window, NULL);
723 if(This->frame)
724 call_set_active_object((IOleInPlaceUIWindow*)This->frame, NULL);
725 if(This->hostui)
726 IDocHostUIHandler_HideUI(This->hostui);
727 if(This->ipsite)
728 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
731 return S_OK;
734 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
736 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
737 FIXME("(%p)\n", This);
738 return E_NOTIMPL;
741 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
743 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
744 TRACE("(%p)->(%lx)\n", This, dwReserved);
746 if(dwReserved)
747 WARN("dwReserved = %ld\n", dwReserved);
749 send_unload_events(This);
750 IOleDocumentView_Show(iface, FALSE);
751 return S_OK;
754 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, IStream *pstm)
756 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
757 FIXME("(%p)->(%p)\n", This, pstm);
758 return E_NOTIMPL;
761 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, IStream *pstm)
763 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
764 FIXME("(%p)->(%p)\n", This, pstm);
765 return E_NOTIMPL;
768 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
769 IOleDocumentView **ppViewNew)
771 HTMLDocumentObj *This = impl_from_IOleDocumentView(iface);
772 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
773 return E_NOTIMPL;
776 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
777 OleDocumentView_QueryInterface,
778 OleDocumentView_AddRef,
779 OleDocumentView_Release,
780 OleDocumentView_SetInPlaceSite,
781 OleDocumentView_GetInPlaceSite,
782 OleDocumentView_GetDocument,
783 OleDocumentView_SetRect,
784 OleDocumentView_GetRect,
785 OleDocumentView_SetRectComplex,
786 OleDocumentView_Show,
787 OleDocumentView_UIActivate,
788 OleDocumentView_Open,
789 OleDocumentView_CloseView,
790 OleDocumentView_SaveViewState,
791 OleDocumentView_ApplyViewState,
792 OleDocumentView_Clone
795 /**********************************************************
796 * IViewObject implementation
799 static inline HTMLDocumentObj *impl_from_IViewObjectEx(IViewObjectEx *iface)
801 return CONTAINING_RECORD(iface, HTMLDocumentObj, IViewObjectEx_iface);
804 static HRESULT WINAPI ViewObject_QueryInterface(IViewObjectEx *iface, REFIID riid, void **ppv)
806 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
807 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
810 static ULONG WINAPI ViewObject_AddRef(IViewObjectEx *iface)
812 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
813 return IUnknown_AddRef(This->outer_unk);
816 static ULONG WINAPI ViewObject_Release(IViewObjectEx *iface)
818 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
819 return IUnknown_Release(This->outer_unk);
822 static HRESULT WINAPI ViewObject_Draw(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
823 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
824 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
826 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
827 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %Id)\n", This, dwDrawAspect, lindex, pvAspect,
828 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
829 return E_NOTIMPL;
832 static HRESULT WINAPI ViewObject_GetColorSet(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
833 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
835 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
836 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
837 return E_NOTIMPL;
840 static HRESULT WINAPI ViewObject_Freeze(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex,
841 void *pvAspect, DWORD *pdwFreeze)
843 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
844 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
845 return E_NOTIMPL;
848 static HRESULT WINAPI ViewObject_Unfreeze(IViewObjectEx *iface, DWORD dwFreeze)
850 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
851 FIXME("(%p)->(%ld)\n", This, dwFreeze);
852 return E_NOTIMPL;
855 static HRESULT WINAPI ViewObject_SetAdvise(IViewObjectEx *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
857 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
859 TRACE("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
861 if(aspects != DVASPECT_CONTENT || advf != ADVF_PRIMEFIRST)
862 FIXME("unsupported arguments\n");
864 if(This->view_sink)
865 IAdviseSink_Release(This->view_sink);
866 if(pAdvSink)
867 IAdviseSink_AddRef(pAdvSink);
869 This->view_sink = pAdvSink;
870 return S_OK;
873 static HRESULT WINAPI ViewObject_GetAdvise(IViewObjectEx *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
875 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
876 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
877 return E_NOTIMPL;
880 static HRESULT WINAPI ViewObject_GetExtent(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex,
881 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
883 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
884 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
885 return E_NOTIMPL;
888 static HRESULT WINAPI ViewObject_GetRect(IViewObjectEx *iface, DWORD dwAspect, LPRECTL pRect)
890 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
891 FIXME("(%p)->(%ld %p)\n", This, dwAspect, pRect);
892 return E_NOTIMPL;
895 static HRESULT WINAPI ViewObject_GetViewStatus(IViewObjectEx *iface, DWORD *pdwStatus)
897 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
898 FIXME("(%p)->(%p)\n", This, pdwStatus);
899 return E_NOTIMPL;
902 static HRESULT WINAPI ViewObject_QueryHitPoint(IViewObjectEx* iface, DWORD dwAspect,
903 LPCRECT pRectBounds, POINT ptlLoc, LONG lCloseHint, DWORD *pHitResult)
905 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
906 FIXME("(%p)->(%ld %p (%ld %ld) %ld %p)\n", This, dwAspect, pRectBounds, ptlLoc.x,
907 ptlLoc.y, lCloseHint, pHitResult);
908 return E_NOTIMPL;
911 static HRESULT WINAPI ViewObject_QueryHitRect(IViewObjectEx *iface, DWORD dwAspect,
912 LPCRECT pRectBounds, LPCRECT pRectLoc, LONG lCloseHint, DWORD *pHitResult)
914 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
915 FIXME("(%p)->(%ld %p %p %ld %p)\n", This, dwAspect, pRectBounds, pRectLoc, lCloseHint, pHitResult);
916 return E_NOTIMPL;
919 static HRESULT WINAPI ViewObject_GetNaturalExtent(IViewObjectEx *iface, DWORD dwAspect, LONG lindex,
920 DVTARGETDEVICE *ptd, HDC hicTargetDev, DVEXTENTINFO *pExtentInfo, LPSIZEL pSizel)
922 HTMLDocumentObj *This = impl_from_IViewObjectEx(iface);
923 FIXME("(%p)->(%ld %ld %p %p %p %p\n", This, dwAspect,lindex, ptd,
924 hicTargetDev, pExtentInfo, pSizel);
925 return E_NOTIMPL;
928 static const IViewObjectExVtbl ViewObjectVtbl = {
929 ViewObject_QueryInterface,
930 ViewObject_AddRef,
931 ViewObject_Release,
932 ViewObject_Draw,
933 ViewObject_GetColorSet,
934 ViewObject_Freeze,
935 ViewObject_Unfreeze,
936 ViewObject_SetAdvise,
937 ViewObject_GetAdvise,
938 ViewObject_GetExtent,
939 ViewObject_GetRect,
940 ViewObject_GetViewStatus,
941 ViewObject_QueryHitPoint,
942 ViewObject_QueryHitRect,
943 ViewObject_GetNaturalExtent
946 static inline HTMLDocumentObj *impl_from_IWindowForBindingUI(IWindowForBindingUI *iface)
948 return CONTAINING_RECORD(iface, HTMLDocumentObj, IWindowForBindingUI_iface);
951 static HRESULT WINAPI WindowForBindingUI_QueryInterface(IWindowForBindingUI *iface, REFIID riid, void **ppv)
953 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
955 if(IsEqualGUID(&IID_IUnknown, riid)) {
956 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
957 *ppv = &This->IWindowForBindingUI_iface;
958 }else if(IsEqualGUID(&IID_IWindowForBindingUI, riid)) {
959 TRACE("(%p)->(IID_IWindowForBindingUI %p)\n", This, ppv);
960 *ppv = &This->IWindowForBindingUI_iface;
961 }else {
962 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
963 *ppv = NULL;
964 return E_NOINTERFACE;
967 IUnknown_AddRef((IUnknown*)*ppv);
968 return S_OK;
971 static ULONG WINAPI WindowForBindingUI_AddRef(IWindowForBindingUI *iface)
973 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
974 return IUnknown_AddRef(This->outer_unk);
977 static ULONG WINAPI WindowForBindingUI_Release(IWindowForBindingUI *iface)
979 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
980 return IUnknown_Release(This->outer_unk);
983 static HRESULT WINAPI WindowForBindingUI_GetWindow(IWindowForBindingUI *iface, REFGUID rguidReason, HWND *phwnd)
985 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
987 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(rguidReason), phwnd);
989 *phwnd = This->hwnd;
990 return S_OK;
993 static const IWindowForBindingUIVtbl WindowForBindingUIVtbl = {
994 WindowForBindingUI_QueryInterface,
995 WindowForBindingUI_AddRef,
996 WindowForBindingUI_Release,
997 WindowForBindingUI_GetWindow
1000 void HTMLDocument_View_Init(HTMLDocumentObj *doc)
1002 doc->IOleDocumentView_iface.lpVtbl = &OleDocumentViewVtbl;
1003 doc->IViewObjectEx_iface.lpVtbl = &ViewObjectVtbl;
1004 doc->IWindowForBindingUI_iface.lpVtbl = &WindowForBindingUIVtbl;