1 /* 2 * Copyright 2005-2006 Jacek Caban for CodeWeavers 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19 #include "config.h" 20 21 #include <stdarg.h> 22 #include <stdio.h> 23 24 #define COBJMACROS 25 26 #include "windef.h" 27 #include "winbase.h" 28 #include "winuser.h" 29 #include "commctrl.h" 30 #include "ole2.h" 31 #include "resource.h" 32 33 #include "wine/debug.h" 34 35 #include "mshtml_private.h" 36 37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml); 38 39 #define TIMER_ID 0x1000 40 41 static const WCHAR wszInternetExplorer_Server[] = 42 {'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','_','S','e','r','v','e','r',0}; 43 44 static const WCHAR wszTooltipData[] = {'t','o','o','l','t','i','p','_','d','a','t','a',0}; 45 46 static ATOM serverwnd_class = 0; 47 48 typedef struct { 49 HTMLDocumentObj *doc; 50 WNDPROC proc; 51 } tooltip_data; 52 53 static void paint_document(HTMLDocumentObj *This) 54 { 55 PAINTSTRUCT ps; 56 RECT rect; 57 HDC hdc; 58 59 GetClientRect(This->hwnd, &rect); 60 61 hdc = BeginPaint(This->hwnd, &ps); 62 63 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER))) 64 DrawEdge(hdc, &rect, EDGE_SUNKEN, BF_RECT|BF_ADJUST); 65 66 if(!This->nscontainer) { 67 WCHAR wszHTMLDisabled[100]; 68 HFONT font; 69 70 LoadStringW(hInst, IDS_HTMLDISABLED, wszHTMLDisabled, sizeof(wszHTMLDisabled)/sizeof(WCHAR)); 71 72 font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL); 73 74 SelectObject(hdc, font); 75 SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW)); 76 77 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom); 78 DrawTextW(hdc, wszHTMLDisabled,-1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER); 79 80 DeleteObject(font); 81 } 82 83 EndPaint(This->hwnd, &ps); 84 } 85 86 static void activate_gecko(NSContainer *This) 87 { 88 TRACE("(%p) %p\n", This, This->window); 89 90 SetParent(This->hwnd, This->doc->hwnd); 91 ShowWindow(This->hwnd, SW_SHOW); 92 93 nsIBaseWindow_SetVisibility(This->window, TRUE); 94 nsIBaseWindow_SetEnabled(This->window, TRUE); 95 } 96 97 void update_doc(HTMLDocument *This, DWORD flags) 98 { 99 if(!This->doc_obj->update && This->doc_obj->hwnd) 100 SetTimer(This->doc_obj->hwnd, TIMER_ID, 100, NULL); 101 102 This->doc_obj->update |= flags; 103 } 104 105 void update_title(HTMLDocumentObj *This) 106 { 107 IOleCommandTarget *olecmd; 108 HRESULT hres; 109 110 if(!(This->update & UPDATE_TITLE)) 111 return; 112 113 This->update &= ~UPDATE_TITLE; 114 115 if(!This->client) 116 return; 117 118 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&olecmd); 119 if(SUCCEEDED(hres)) { 120 VARIANT title; 121 WCHAR empty[] = {0}; 122 123 V_VT(&title) = VT_BSTR; 124 V_BSTR(&title) = SysAllocString(empty); 125 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER, 126 &title, NULL); 127 SysFreeString(V_BSTR(&title)); 128 129 IOleCommandTarget_Release(olecmd); 130 } 131 } 132 133 static LRESULT on_timer(HTMLDocumentObj *This) 134 { 135 TRACE("(%p) %x\n", This, This->update); 136 137 KillTimer(This->hwnd, TIMER_ID); 138 139 if(!This->update) 140 return 0; 141 142 if(This->update & UPDATE_UI) { 143 if(This->hostui) 144 IDocHostUIHandler_UpdateUI(This->hostui); 145 146 if(This->client) { 147 IOleCommandTarget *cmdtrg; 148 HRESULT hres; 149 150 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, 151 (void**)&cmdtrg); 152 if(SUCCEEDED(hres)) { 153 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_UPDATECOMMANDS, 154 OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL); 155 IOleCommandTarget_Release(cmdtrg); 156 } 157 } 158 } 159 160 update_title(This); 161 This->update = 0; 162 return 0; 163 } 164 165 void notif_focus(HTMLDocumentObj *This) 166 { 167 IOleControlSite *site; 168 HRESULT hres; 169 170 if(!This->client) 171 return; 172 173 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleControlSite, (void**)&site); 174 if(FAILED(hres)) 175 return; 176 177 IOleControlSite_OnFocus(site, This->focus); 178 IOleControlSite_Release(site); 179 } 180 181 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 182 { 183 HTMLDocumentObj *This; 184 185 static const WCHAR wszTHIS[] = {'T','H','I','S',0}; 186 187 if(msg == WM_CREATE) { 188 This = *(HTMLDocumentObj**)lParam; 189 SetPropW(hwnd, wszTHIS, This); 190 }else { 191 This = GetPropW(hwnd, wszTHIS); 192 } 193 194 switch(msg) { 195 case WM_CREATE: 196 This->hwnd = hwnd; 197 break; 198 case WM_PAINT: 199 paint_document(This); 200 break; 201 case WM_SIZE: 202 TRACE("(%p)->(WM_SIZE)\n", This); 203 if(This->nscontainer) { 204 INT ew=0, eh=0; 205 206 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER))) { 207 ew = GetSystemMetrics(SM_CXEDGE); 208 eh = GetSystemMetrics(SM_CYEDGE); 209 } 210 211 SetWindowPos(This->nscontainer->hwnd, NULL, ew, eh, 212 LOWORD(lParam) - 2*ew, HIWORD(lParam) - 2*eh, 213 SWP_NOZORDER | SWP_NOACTIVATE); 214 } 215 break; 216 case WM_TIMER: 217 return on_timer(This); 218 case WM_SETFOCUS: 219 TRACE("(%p) WM_SETFOCUS\n", This); 220 nsIWebBrowserFocus_Activate(This->nscontainer->focus); 221 break; 222 case WM_MOUSEACTIVATE: 223 return MA_ACTIVATE; 224 } 225 226 return DefWindowProcW(hwnd, msg, wParam, lParam); 227 } 228 229 static void register_serverwnd_class(void) 230 { 231 static WNDCLASSEXW wndclass = { 232 sizeof(WNDCLASSEXW), 233 CS_DBLCLKS, 234 serverwnd_proc, 235 0, 0, NULL, NULL, NULL, NULL, NULL, 236 wszInternetExplorer_Server, 237 NULL, 238 }; 239 wndclass.hInstance = hInst; 240 serverwnd_class = RegisterClassExW(&wndclass); 241 } 242 243 static HRESULT activate_window(HTMLDocumentObj *This) 244 { 245 IOleInPlaceFrame *pIPFrame; 246 IOleCommandTarget *cmdtrg; 247 IOleInPlaceSiteEx *ipsiteex; 248 RECT posrect, cliprect; 249 OLEINPLACEFRAMEINFO frameinfo; 250 HWND parent_hwnd; 251 HRESULT hres; 252 253 if(!serverwnd_class) 254 register_serverwnd_class(); 255 256 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite); 257 if(hres != S_OK) { 258 WARN("CanInPlaceActivate returned: %08x\n", hres); 259 return FAILED(hres) ? hres : E_FAIL; 260 } 261 262 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &This->ip_window, 263 &posrect, &cliprect, &frameinfo); 264 if(FAILED(hres)) { 265 WARN("GetWindowContext failed: %08x\n", hres); 266 return hres; 267 } 268 269 TRACE("got window context: %p %p {%d %d %d %d} {%d %d %d %d} {%d %x %p %p %d}\n", 270 pIPFrame, This->ip_window, posrect.left, posrect.top, posrect.right, posrect.bottom, 271 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom, 272 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries); 273 274 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd); 275 if(FAILED(hres)) { 276 WARN("GetWindow failed: %08x\n", hres); 277 return hres; 278 } 279 280 TRACE("got parent window %p\n", parent_hwnd); 281 282 if(This->hwnd) { 283 if(GetParent(This->hwnd) != parent_hwnd) 284 SetParent(This->hwnd, parent_hwnd); 285 SetWindowPos(This->hwnd, HWND_TOP, 286 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top, 287 SWP_NOACTIVATE | SWP_SHOWWINDOW); 288 }else { 289 CreateWindowExW(0, wszInternetExplorer_Server, NULL, 290 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 291 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top, 292 parent_hwnd, NULL, hInst, This); 293 294 TRACE("Created window %p\n", This->hwnd); 295 296 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0, 297 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW); 298 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN); 299 300 /* NOTE: 301 * Windows implementation calls: 302 * RegisterWindowMessage("MSWHEEL_ROLLMSG"); 303 */ 304 SetTimer(This->hwnd, TIMER_ID, 100, NULL); 305 } 306 307 if(This->nscontainer) 308 activate_gecko(This->nscontainer); 309 310 This->in_place_active = TRUE; 311 hres = IOleInPlaceSite_QueryInterface(This->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex); 312 if(SUCCEEDED(hres)) { 313 BOOL redraw = FALSE; 314 315 hres = IOleInPlaceSiteEx_OnInPlaceActivateEx(ipsiteex, &redraw, 0); 316 IOleInPlaceSiteEx_Release(ipsiteex); 317 if(redraw) 318 FIXME("unsupported redraw\n"); 319 }else{ 320 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite); 321 } 322 if(FAILED(hres)) { 323 WARN("OnInPlaceActivate failed: %08x\n", hres); 324 This->in_place_active = FALSE; 325 return hres; 326 } 327 328 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg); 329 if(SUCCEEDED(hres)) { 330 VARIANT var; 331 332 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL); 333 334 V_VT(&var) = VT_I4; 335 V_I4(&var) = 0; 336 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX, 337 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL); 338 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 339 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL); 340 341 IOleCommandTarget_Release(cmdtrg); 342 } 343 344 if(This->frame) 345 IOleInPlaceFrame_Release(This->frame); 346 This->frame = pIPFrame; 347 348 if(!This->request_uiactivate) { 349 hres = IOleInPlaceSite_QueryInterface(This->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex); 350 if(SUCCEEDED(hres)) { 351 IOleInPlaceSiteEx_RequestUIActivate(ipsiteex); 352 IOleInPlaceSiteEx_Release(ipsiteex); 353 } 354 } 355 356 This->window_active = TRUE; 357 358 return S_OK; 359 } 360 361 static LRESULT WINAPI tooltips_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 362 { 363 tooltip_data *data = GetPropW(hwnd, wszTooltipData); 364 365 TRACE("%d %p\n", msg, data); 366 367 if(msg == TTM_WINDOWFROMPOINT) { 368 RECT rect; 369 POINT *pt = (POINT*)lParam; 370 371 TRACE("TTM_WINDOWFROMPOINT (%d,%d)\n", pt->x, pt->y); 372 373 GetWindowRect(data->doc->hwnd, &rect); 374 375 if(rect.left <= pt->x && pt->x <= rect.right 376 && rect.top <= pt->y && pt->y <= rect.bottom) 377 return (LPARAM)data->doc->hwnd; 378 } 379 380 return CallWindowProcW(data->proc, hwnd, msg, wParam, lParam); 381 } 382 383 static void create_tooltips_window(HTMLDocumentObj *This) 384 { 385 tooltip_data *data = heap_alloc(sizeof(*data)); 386 387 This->tooltips_hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, TTS_NOPREFIX | WS_POPUP, 388 CW_USEDEFAULT, CW_USEDEFAULT, 10, 10, This->hwnd, NULL, hInst, NULL); 389 390 data->doc = This; 391 data->proc = (WNDPROC)GetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC); 392 393 SetPropW(This->tooltips_hwnd, wszTooltipData, data); 394 395 SetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC, (LONG_PTR)tooltips_proc); 396 397 SetWindowPos(This->tooltips_hwnd, HWND_TOPMOST,0, 0, 0, 0, 398 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 399 400 } 401 402 void show_tooltip(HTMLDocumentObj *This, DWORD x, DWORD y, LPCWSTR text) 403 { 404 TTTOOLINFOW toolinfo = { 405 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef, 406 {x>2 ? x-2 : 0, y>0 ? y-2 : 0, x+2, y+2}, /* FIXME */ 407 NULL, (LPWSTR)text, 0}; 408 MSG msg = {This->hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x,y), 0, {x,y}}; 409 410 TRACE("(%p)->(%d %d %s)\n", This, x, y, debugstr_w(text)); 411 412 if(!This->tooltips_hwnd) 413 create_tooltips_window(This); 414 415 SendMessageW(This->tooltips_hwnd, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo); 416 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, TRUE, 0); 417 SendMessageW(This->tooltips_hwnd, TTM_RELAYEVENT, 0, (LPARAM)&msg); 418 } 419 420 void hide_tooltip(HTMLDocumentObj *This) 421 { 422 TTTOOLINFOW toolinfo = { 423 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef, 424 {0,0,0,0}, NULL, NULL, 0}; 425 426 TRACE("(%p)\n", This); 427 428 SendMessageW(This->tooltips_hwnd, TTM_DELTOOLW, 0, (LPARAM)&toolinfo); 429 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, FALSE, 0); 430 } 431 432 HRESULT call_set_active_object(IOleInPlaceUIWindow *window, IOleInPlaceActiveObject *act_obj) 433 { 434 static WCHAR html_documentW[30]; 435 436 if(act_obj && !html_documentW[0]) { 437 LoadStringW(hInst, IDS_HTMLDOCUMENT, html_documentW, 438 sizeof(html_documentW)/sizeof(WCHAR)); 439 } 440 441 return IOleInPlaceFrame_SetActiveObject(window, act_obj, act_obj ? html_documentW : NULL); 442 } 443 444 /********************************************************** 445 * IOleDocumentView implementation 446 */ 447 448 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface) 449 450 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject) 451 { 452 HTMLDocument *This = DOCVIEW_THIS(iface); 453 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject); 454 } 455 456 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface) 457 { 458 HTMLDocument *This = DOCVIEW_THIS(iface); 459 return IHTMLDocument2_AddRef(HTMLDOC(This)); 460 } 461 462 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface) 463 { 464 HTMLDocument *This = DOCVIEW_THIS(iface); 465 return IHTMLDocument2_Release(HTMLDOC(This)); 466 } 467 468 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite) 469 { 470 HTMLDocument *This = DOCVIEW_THIS(iface); 471 TRACE("(%p)->(%p)\n", This, pIPSite); 472 473 if(pIPSite) 474 IOleInPlaceSite_AddRef(pIPSite); 475 476 if(This->doc_obj->ipsite) 477 IOleInPlaceSite_Release(This->doc_obj->ipsite); 478 479 This->doc_obj->ipsite = pIPSite; 480 This->doc_obj->request_uiactivate = TRUE; 481 return S_OK; 482 } 483 484 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite) 485 { 486 HTMLDocument *This = DOCVIEW_THIS(iface); 487 TRACE("(%p)->(%p)\n", This, ppIPSite); 488 489 if(!ppIPSite) 490 return E_INVALIDARG; 491 492 if(This->doc_obj->ipsite) 493 IOleInPlaceSite_AddRef(This->doc_obj->ipsite); 494 495 *ppIPSite = This->doc_obj->ipsite; 496 return S_OK; 497 } 498 499 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk) 500 { 501 HTMLDocument *This = DOCVIEW_THIS(iface); 502 TRACE("(%p)->(%p)\n", This, ppunk); 503 504 if(!ppunk) 505 return E_INVALIDARG; 506 507 IHTMLDocument2_AddRef(HTMLDOC(This)); 508 *ppunk = (IUnknown*)HTMLDOC(This); 509 return S_OK; 510 } 511 512 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView) 513 { 514 HTMLDocument *This = DOCVIEW_THIS(iface); 515 RECT rect; 516 517 TRACE("(%p)->(%p)\n", This, prcView); 518 519 if(!prcView) 520 return E_INVALIDARG; 521 522 if(This->doc_obj->hwnd) { 523 GetClientRect(This->doc_obj->hwnd, &rect); 524 if(memcmp(prcView, &rect, sizeof(RECT))) { 525 InvalidateRect(This->doc_obj->hwnd, NULL, TRUE); 526 SetWindowPos(This->doc_obj->hwnd, NULL, prcView->left, prcView->top, prcView->right, 527 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE); 528 } 529 } 530 531 return S_OK; 532 } 533 534 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView) 535 { 536 HTMLDocument *This = DOCVIEW_THIS(iface); 537 538 TRACE("(%p)->(%p)\n", This, prcView); 539 540 if(!prcView) 541 return E_INVALIDARG; 542 543 GetClientRect(This->doc_obj->hwnd, prcView); 544 return S_OK; 545 } 546 547 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView, 548 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox) 549 { 550 HTMLDocument *This = DOCVIEW_THIS(iface); 551 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox); 552 return E_NOTIMPL; 553 } 554 555 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow) 556 { 557 HTMLDocument *This = DOCVIEW_THIS(iface); 558 HRESULT hres; 559 560 TRACE("(%p)->(%x)\n", This, fShow); 561 562 if(fShow) { 563 if(!This->doc_obj->ui_active) { 564 hres = activate_window(This->doc_obj); 565 if(FAILED(hres)) 566 return hres; 567 } 568 update_doc(This, UPDATE_UI); 569 ShowWindow(This->doc_obj->hwnd, SW_SHOW); 570 }else { 571 ShowWindow(This->doc_obj->hwnd, SW_HIDE); 572 573 if(This->doc_obj->in_place_active) 574 IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This)); 575 576 if(This->doc_obj->ip_window) { 577 IOleInPlaceUIWindow_Release(This->doc_obj->ip_window); 578 This->doc_obj->ip_window = NULL; 579 } 580 } 581 582 return S_OK; 583 } 584 585 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate) 586 { 587 HTMLDocument *This = DOCVIEW_THIS(iface); 588 HRESULT hres; 589 590 TRACE("(%p)->(%x)\n", This, fUIActivate); 591 592 if(!This->doc_obj->ipsite) { 593 IOleClientSite *cs = This->doc_obj->client; 594 IOleInPlaceSite *ips; 595 596 if(!cs) { 597 WARN("this->ipsite = NULL\n"); 598 return E_UNEXPECTED; 599 } 600 601 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteWindowless, (void**)&ips); 602 if(SUCCEEDED(hres)) 603 This->doc_obj->ipsite = ips; 604 else { 605 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteEx, (void**)&ips); 606 if(SUCCEEDED(hres)) 607 This->doc_obj->ipsite = ips; 608 else { 609 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSite, (void**)&ips); 610 if(SUCCEEDED(hres)) 611 This->doc_obj->ipsite = ips; 612 else { 613 WARN("this->ipsite = NULL\n"); 614 return E_NOINTERFACE; 615 } 616 } 617 } 618 619 IOleClientSite_AddRef(This->doc_obj->ipsite); 620 This->doc_obj->request_uiactivate = FALSE; 621 HTMLDocument_LockContainer(This->doc_obj, TRUE); 622 } 623 624 if(fUIActivate) { 625 RECT rcBorderWidths; 626 627 if(This->doc_obj->ui_active) 628 return S_OK; 629 630 if(!This->doc_obj->window_active) { 631 hres = activate_window(This->doc_obj); 632 if(FAILED(hres)) 633 return hres; 634 } 635 636 This->doc_obj->focus = TRUE; 637 if(This->doc_obj->nscontainer) 638 nsIWebBrowserFocus_Activate(This->doc_obj->nscontainer->focus); 639 notif_focus(This->doc_obj); 640 641 update_doc(This, UPDATE_UI); 642 643 hres = IOleInPlaceSite_OnUIActivate(This->doc_obj->ipsite); 644 if(SUCCEEDED(hres)) { 645 call_set_active_object((IOleInPlaceUIWindow*)This->doc_obj->frame, ACTOBJ(This)); 646 }else { 647 FIXME("OnUIActivate failed: %08x\n", hres); 648 IOleInPlaceFrame_Release(This->doc_obj->frame); 649 This->doc_obj->frame = NULL; 650 This->doc_obj->ui_active = FALSE; 651 return hres; 652 } 653 654 if(This->doc_obj->hostui) { 655 hres = IDocHostUIHandler_ShowUI(This->doc_obj->hostui, 656 This->doc_obj->usermode == EDITMODE ? DOCHOSTUITYPE_AUTHOR : DOCHOSTUITYPE_BROWSE, 657 ACTOBJ(This), CMDTARGET(This), This->doc_obj->frame, This->doc_obj->ip_window); 658 if(FAILED(hres)) 659 IDocHostUIHandler_HideUI(This->doc_obj->hostui); 660 } 661 662 if(This->doc_obj->ip_window) 663 call_set_active_object(This->doc_obj->ip_window, ACTOBJ(This)); 664 665 memset(&rcBorderWidths, 0, sizeof(rcBorderWidths)); 666 IOleInPlaceFrame_SetBorderSpace(This->doc_obj->frame, &rcBorderWidths); 667 668 This->doc_obj->ui_active = TRUE; 669 }else { 670 This->doc_obj->focus = FALSE; 671 nsIWebBrowserFocus_Deactivate(This->doc_obj->nscontainer->focus); 672 if(This->doc_obj->ui_active) { 673 This->doc_obj->ui_active = FALSE; 674 if(This->doc_obj->ip_window) 675 call_set_active_object(This->doc_obj->ip_window, NULL); 676 if(This->doc_obj->frame) 677 call_set_active_object((IOleInPlaceUIWindow*)This->doc_obj->frame, NULL); 678 if(This->doc_obj->hostui) 679 IDocHostUIHandler_HideUI(This->doc_obj->hostui); 680 if(This->doc_obj->ipsite) 681 IOleInPlaceSite_OnUIDeactivate(This->doc_obj->ipsite, FALSE); 682 } 683 } 684 return S_OK; 685 } 686 687 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface) 688 { 689 HTMLDocument *This = DOCVIEW_THIS(iface); 690 FIXME("(%p)\n", This); 691 return E_NOTIMPL; 692 } 693 694 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved) 695 { 696 HTMLDocument *This = DOCVIEW_THIS(iface); 697 TRACE("(%p)->(%x)\n", This, dwReserved); 698 699 if(dwReserved) 700 WARN("dwReserved = %d\n", dwReserved); 701 702 /* NOTE: 703 * Windows implementation calls QueryInterface(IID_IOleCommandTarget), 704 * QueryInterface(IID_IOleControlSite) and KillTimer 705 */ 706 707 IOleDocumentView_Show(iface, FALSE); 708 709 return S_OK; 710 } 711 712 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm) 713 { 714 HTMLDocument *This = DOCVIEW_THIS(iface); 715 FIXME("(%p)->(%p)\n", This, pstm); 716 return E_NOTIMPL; 717 } 718 719 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm) 720 { 721 HTMLDocument *This = DOCVIEW_THIS(iface); 722 FIXME("(%p)->(%p)\n", This, pstm); 723 return E_NOTIMPL; 724 } 725 726 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew, 727 IOleDocumentView **ppViewNew) 728 { 729 HTMLDocument *This = DOCVIEW_THIS(iface); 730 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew); 731 return E_NOTIMPL; 732 } 733 734 #undef DOCVIEW_THIS 735 736 static const IOleDocumentViewVtbl OleDocumentViewVtbl = { 737 OleDocumentView_QueryInterface, 738 OleDocumentView_AddRef, 739 OleDocumentView_Release, 740 OleDocumentView_SetInPlaceSite, 741 OleDocumentView_GetInPlaceSite, 742 OleDocumentView_GetDocument, 743 OleDocumentView_SetRect, 744 OleDocumentView_GetRect, 745 OleDocumentView_SetRectComplex, 746 OleDocumentView_Show, 747 OleDocumentView_UIActivate, 748 OleDocumentView_Open, 749 OleDocumentView_CloseView, 750 OleDocumentView_SaveViewState, 751 OleDocumentView_ApplyViewState, 752 OleDocumentView_Clone 753 }; 754 755 /********************************************************** 756 * IViewObject implementation 757 */ 758 759 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObjectEx, iface) 760 761 static HRESULT WINAPI ViewObject_QueryInterface(IViewObjectEx *iface, REFIID riid, void **ppvObject) 762 { 763 HTMLDocument *This = VIEWOBJ_THIS(iface); 764 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject); 765 } 766 767 static ULONG WINAPI ViewObject_AddRef(IViewObjectEx *iface) 768 { 769 HTMLDocument *This = VIEWOBJ_THIS(iface); 770 return IHTMLDocument2_AddRef(HTMLDOC(This)); 771 } 772 773 static ULONG WINAPI ViewObject_Release(IViewObjectEx *iface) 774 { 775 HTMLDocument *This = VIEWOBJ_THIS(iface); 776 return IHTMLDocument2_Release(HTMLDOC(This)); 777 } 778 779 static HRESULT WINAPI ViewObject_Draw(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect, 780 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, 781 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue) 782 { 783 HTMLDocument *This = VIEWOBJ_THIS(iface); 784 FIXME("(%p)->(%d %d %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect, 785 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue); 786 return E_NOTIMPL; 787 } 788 789 static HRESULT WINAPI ViewObject_GetColorSet(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect, 790 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet) 791 { 792 HTMLDocument *This = VIEWOBJ_THIS(iface); 793 FIXME("(%p)->(%d %d %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet); 794 return E_NOTIMPL; 795 } 796 797 static HRESULT WINAPI ViewObject_Freeze(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, 798 void *pvAspect, DWORD *pdwFreeze) 799 { 800 HTMLDocument *This = VIEWOBJ_THIS(iface); 801 FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze); 802 return E_NOTIMPL; 803 } 804 805 static HRESULT WINAPI ViewObject_Unfreeze(IViewObjectEx *iface, DWORD dwFreeze) 806 { 807 HTMLDocument *This = VIEWOBJ_THIS(iface); 808 FIXME("(%p)->(%d)\n", This, dwFreeze); 809 return E_NOTIMPL; 810 } 811 812 static HRESULT WINAPI ViewObject_SetAdvise(IViewObjectEx *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink) 813 { 814 HTMLDocument *This = VIEWOBJ_THIS(iface); 815 816 TRACE("(%p)->(%d %d %p)\n", This, aspects, advf, pAdvSink); 817 818 if(aspects != DVASPECT_CONTENT || advf != ADVF_PRIMEFIRST) 819 FIXME("unsupported arguments\n"); 820 821 if(This->doc_obj->view_sink) 822 IAdviseSink_Release(This->doc_obj->view_sink); 823 if(pAdvSink) 824 IAdviseSink_AddRef(pAdvSink); 825 826 This->doc_obj->view_sink = pAdvSink; 827 return S_OK; 828 } 829 830 static HRESULT WINAPI ViewObject_GetAdvise(IViewObjectEx *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink) 831 { 832 HTMLDocument *This = VIEWOBJ_THIS(iface); 833 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink); 834 return E_NOTIMPL; 835 } 836 837 static HRESULT WINAPI ViewObject_GetExtent(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, 838 DVTARGETDEVICE* ptd, LPSIZEL lpsizel) 839 { 840 HTMLDocument *This = VIEWOBJ_THIS(iface); 841 FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel); 842 return E_NOTIMPL; 843 } 844 845 static HRESULT WINAPI ViewObject_GetRect(IViewObjectEx *iface, DWORD dwAspect, LPRECTL pRect) 846 { 847 HTMLDocument *This = VIEWOBJ_THIS(iface); 848 FIXME("(%p)->(%d %p)\n", This, dwAspect, pRect); 849 return E_NOTIMPL; 850 } 851 852 static HRESULT WINAPI ViewObject_GetViewStatus(IViewObjectEx *iface, DWORD *pdwStatus) 853 { 854 HTMLDocument *This = VIEWOBJ_THIS(iface); 855 FIXME("(%p)->(%p)\n", This, pdwStatus); 856 return E_NOTIMPL; 857 } 858 859 static HRESULT WINAPI ViewObject_QueryHitPoint(IViewObjectEx* iface, DWORD dwAspect, 860 LPCRECT pRectBounds, POINT ptlLoc, LONG lCloseHint, DWORD *pHitResult) 861 { 862 HTMLDocument *This = VIEWOBJ_THIS(iface); 863 FIXME("(%p)->(%d %p (%d %d) %d %p)\n", This, dwAspect, pRectBounds, ptlLoc.x, 864 ptlLoc.y, lCloseHint, pHitResult); 865 return E_NOTIMPL; 866 } 867 868 static HRESULT WINAPI ViewObject_QueryHitRect(IViewObjectEx *iface, DWORD dwAspect, 869 LPCRECT pRectBounds, LPCRECT pRectLoc, LONG lCloseHint, DWORD *pHitResult) 870 { 871 HTMLDocument *This = VIEWOBJ_THIS(iface); 872 FIXME("(%p)->(%d %p %p %d %p)\n", This, dwAspect, pRectBounds, pRectLoc, lCloseHint, pHitResult); 873 return E_NOTIMPL; 874 } 875 876 static HRESULT WINAPI ViewObject_GetNaturalExtent(IViewObjectEx *iface, DWORD dwAspect, LONG lindex, 877 DVTARGETDEVICE *ptd, HDC hicTargetDev, DVEXTENTINFO *pExtentInfo, LPSIZEL pSizel) 878 { 879 HTMLDocument *This = VIEWOBJ_THIS(iface); 880 FIXME("(%p)->(%d %d %p %p %p %p\n", This, dwAspect,lindex, ptd, 881 hicTargetDev, pExtentInfo, pSizel); 882 return E_NOTIMPL; 883 } 884 885 #undef VIEWOBJ_THIS 886 887 static const IViewObjectExVtbl ViewObjectVtbl = { 888 ViewObject_QueryInterface, 889 ViewObject_AddRef, 890 ViewObject_Release, 891 ViewObject_Draw, 892 ViewObject_GetColorSet, 893 ViewObject_Freeze, 894 ViewObject_Unfreeze, 895 ViewObject_SetAdvise, 896 ViewObject_GetAdvise, 897 ViewObject_GetExtent, 898 ViewObject_GetRect, 899 ViewObject_GetViewStatus, 900 ViewObject_QueryHitPoint, 901 ViewObject_QueryHitRect, 902 ViewObject_GetNaturalExtent 903 }; 904 905 void HTMLDocument_View_Init(HTMLDocument *This) 906 { 907 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl; 908 This->lpViewObjectExVtbl = &ViewObjectVtbl; 909 } 910