mshtml: COM cleanup for the IOleInPlaceObjectWindowless iface.
[wine/wine-gecko.git] / dlls / mshtml / view.c
blob1878e154c6e5bddf10267ea3f4eb50cbd1a804b3
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 "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "commctrl.h"
30 #include "ole2.h"
31 #include "resource.h"
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 #define TIMER_ID 0x1000
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};
44 static const WCHAR wszTooltipData[] = {'t','o','o','l','t','i','p','_','d','a','t','a',0};
46 static ATOM serverwnd_class = 0;
48 typedef struct {
49 HTMLDocumentObj *doc;
50 WNDPROC proc;
51 } tooltip_data;
53 static void paint_document(HTMLDocumentObj *This)
55 PAINTSTRUCT ps;
56 RECT rect;
57 HDC hdc;
59 GetClientRect(This->hwnd, &rect);
61 hdc = BeginPaint(This->hwnd, &ps);
63 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER)))
64 DrawEdge(hdc, &rect, EDGE_SUNKEN, BF_RECT|BF_ADJUST);
66 if(!This->nscontainer) {
67 WCHAR wszHTMLDisabled[100];
68 HFONT font;
70 LoadStringW(hInst, IDS_HTMLDISABLED, wszHTMLDisabled, sizeof(wszHTMLDisabled)/sizeof(WCHAR));
72 font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
74 SelectObject(hdc, font);
75 SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW));
77 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
78 DrawTextW(hdc, wszHTMLDisabled,-1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
80 DeleteObject(font);
83 EndPaint(This->hwnd, &ps);
86 static void activate_gecko(NSContainer *This)
88 TRACE("(%p) %p\n", This, This->window);
90 SetParent(This->hwnd, This->doc->hwnd);
91 ShowWindow(This->hwnd, SW_SHOW);
93 nsIBaseWindow_SetVisibility(This->window, TRUE);
94 nsIBaseWindow_SetEnabled(This->window, TRUE);
97 void update_doc(HTMLDocument *This, DWORD flags)
99 if(!This->doc_obj->update && This->doc_obj->hwnd)
100 SetTimer(This->doc_obj->hwnd, TIMER_ID, 100, NULL);
102 This->doc_obj->update |= flags;
105 void update_title(HTMLDocumentObj *This)
107 IOleCommandTarget *olecmd;
108 HRESULT hres;
110 if(!(This->update & UPDATE_TITLE))
111 return;
113 This->update &= ~UPDATE_TITLE;
115 if(!This->client)
116 return;
118 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&olecmd);
119 if(SUCCEEDED(hres)) {
120 VARIANT title;
121 WCHAR empty[] = {0};
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));
129 IOleCommandTarget_Release(olecmd);
133 static LRESULT on_timer(HTMLDocumentObj *This)
135 TRACE("(%p) %x\n", This, This->update);
137 KillTimer(This->hwnd, TIMER_ID);
139 if(!This->update)
140 return 0;
142 if(This->update & UPDATE_UI) {
143 if(This->hostui)
144 IDocHostUIHandler_UpdateUI(This->hostui);
146 if(This->client) {
147 IOleCommandTarget *cmdtrg;
148 HRESULT hres;
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);
160 update_title(This);
161 This->update = 0;
162 return 0;
165 void notif_focus(HTMLDocumentObj *This)
167 IOleControlSite *site;
168 HRESULT hres;
170 if(!This->client)
171 return;
173 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleControlSite, (void**)&site);
174 if(FAILED(hres))
175 return;
177 IOleControlSite_OnFocus(site, This->focus);
178 IOleControlSite_Release(site);
181 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
183 HTMLDocumentObj *This;
185 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
187 if(msg == WM_CREATE) {
188 This = *(HTMLDocumentObj**)lParam;
189 SetPropW(hwnd, wszTHIS, This);
190 }else {
191 This = GetPropW(hwnd, wszTHIS);
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;
206 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER))) {
207 ew = GetSystemMetrics(SM_CXEDGE);
208 eh = GetSystemMetrics(SM_CYEDGE);
211 SetWindowPos(This->nscontainer->hwnd, NULL, ew, eh,
212 LOWORD(lParam) - 2*ew, HIWORD(lParam) - 2*eh,
213 SWP_NOZORDER | SWP_NOACTIVATE);
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;
226 return DefWindowProcW(hwnd, msg, wParam, lParam);
229 static void register_serverwnd_class(void)
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,
239 wndclass.hInstance = hInst;
240 serverwnd_class = RegisterClassExW(&wndclass);
243 static HRESULT activate_window(HTMLDocumentObj *This)
245 IOleInPlaceFrame *pIPFrame;
246 IOleCommandTarget *cmdtrg;
247 IOleInPlaceSiteEx *ipsiteex;
248 RECT posrect, cliprect;
249 OLEINPLACEFRAMEINFO frameinfo;
250 HWND parent_hwnd;
251 HRESULT hres;
253 if(!serverwnd_class)
254 register_serverwnd_class();
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;
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;
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);
274 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
275 if(FAILED(hres)) {
276 WARN("GetWindow failed: %08x\n", hres);
277 return hres;
280 TRACE("got parent window %p\n", parent_hwnd);
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);
294 TRACE("Created window %p\n", This->hwnd);
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);
300 /* NOTE:
301 * Windows implementation calls:
302 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
304 SetTimer(This->hwnd, TIMER_ID, 100, NULL);
307 if(This->nscontainer)
308 activate_gecko(This->nscontainer);
310 This->in_place_active = TRUE;
311 hres = IOleInPlaceSite_QueryInterface(This->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex);
312 if(SUCCEEDED(hres)) {
313 BOOL redraw = FALSE;
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);
322 if(FAILED(hres)) {
323 WARN("OnInPlaceActivate failed: %08x\n", hres);
324 This->in_place_active = FALSE;
325 return hres;
328 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
329 if(SUCCEEDED(hres)) {
330 VARIANT var;
332 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
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);
341 IOleCommandTarget_Release(cmdtrg);
344 if(This->frame)
345 IOleInPlaceFrame_Release(This->frame);
346 This->frame = pIPFrame;
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);
356 This->window_active = TRUE;
358 return S_OK;
361 static LRESULT WINAPI tooltips_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
363 tooltip_data *data = GetPropW(hwnd, wszTooltipData);
365 TRACE("%d %p\n", msg, data);
367 if(msg == TTM_WINDOWFROMPOINT) {
368 RECT rect;
369 POINT *pt = (POINT*)lParam;
371 TRACE("TTM_WINDOWFROMPOINT (%d,%d)\n", pt->x, pt->y);
373 GetWindowRect(data->doc->hwnd, &rect);
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;
380 return CallWindowProcW(data->proc, hwnd, msg, wParam, lParam);
383 static void create_tooltips_window(HTMLDocumentObj *This)
385 tooltip_data *data = heap_alloc(sizeof(*data));
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);
390 data->doc = This;
391 data->proc = (WNDPROC)GetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC);
393 SetPropW(This->tooltips_hwnd, wszTooltipData, data);
395 SetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC, (LONG_PTR)tooltips_proc);
397 SetWindowPos(This->tooltips_hwnd, HWND_TOPMOST,0, 0, 0, 0,
398 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
402 void show_tooltip(HTMLDocumentObj *This, DWORD x, DWORD y, LPCWSTR text)
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}};
410 TRACE("(%p)->(%d %d %s)\n", This, x, y, debugstr_w(text));
412 if(!This->tooltips_hwnd)
413 create_tooltips_window(This);
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);
420 void hide_tooltip(HTMLDocumentObj *This)
422 TTTOOLINFOW toolinfo = {
423 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
424 {0,0,0,0}, NULL, NULL, 0};
426 TRACE("(%p)\n", This);
428 SendMessageW(This->tooltips_hwnd, TTM_DELTOOLW, 0, (LPARAM)&toolinfo);
429 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, FALSE, 0);
432 HRESULT call_set_active_object(IOleInPlaceUIWindow *window, IOleInPlaceActiveObject *act_obj)
434 static WCHAR html_documentW[30];
436 if(act_obj && !html_documentW[0]) {
437 LoadStringW(hInst, IDS_HTMLDOCUMENT, html_documentW,
438 sizeof(html_documentW)/sizeof(WCHAR));
441 return IOleInPlaceFrame_SetActiveObject(window, act_obj, act_obj ? html_documentW : NULL);
444 /**********************************************************
445 * IOleDocumentView implementation
448 static inline HTMLDocument *impl_from_IOleDocumentView(IOleDocumentView *iface)
450 return CONTAINING_RECORD(iface, HTMLDocument, IOleDocumentView_iface);
453 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
455 HTMLDocument *This = impl_from_IOleDocumentView(iface);
456 return htmldoc_query_interface(This, riid, ppvObject);
459 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
461 HTMLDocument *This = impl_from_IOleDocumentView(iface);
462 return htmldoc_addref(This);
465 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
467 HTMLDocument *This = impl_from_IOleDocumentView(iface);
468 return htmldoc_release(This);
471 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
473 HTMLDocument *This = impl_from_IOleDocumentView(iface);
474 TRACE("(%p)->(%p)\n", This, pIPSite);
476 if(pIPSite)
477 IOleInPlaceSite_AddRef(pIPSite);
479 if(This->doc_obj->ipsite)
480 IOleInPlaceSite_Release(This->doc_obj->ipsite);
482 This->doc_obj->ipsite = pIPSite;
483 This->doc_obj->request_uiactivate = TRUE;
484 return S_OK;
487 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
489 HTMLDocument *This = impl_from_IOleDocumentView(iface);
490 TRACE("(%p)->(%p)\n", This, ppIPSite);
492 if(!ppIPSite)
493 return E_INVALIDARG;
495 if(This->doc_obj->ipsite)
496 IOleInPlaceSite_AddRef(This->doc_obj->ipsite);
498 *ppIPSite = This->doc_obj->ipsite;
499 return S_OK;
502 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
504 HTMLDocument *This = impl_from_IOleDocumentView(iface);
505 TRACE("(%p)->(%p)\n", This, ppunk);
507 if(!ppunk)
508 return E_INVALIDARG;
510 htmldoc_addref(This);
511 *ppunk = (IUnknown*)&This->IHTMLDocument2_iface;
512 return S_OK;
515 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
517 HTMLDocument *This = impl_from_IOleDocumentView(iface);
518 RECT rect;
520 TRACE("(%p)->(%p)\n", This, prcView);
522 if(!prcView)
523 return E_INVALIDARG;
525 if(This->doc_obj->hwnd) {
526 GetClientRect(This->doc_obj->hwnd, &rect);
527 if(memcmp(prcView, &rect, sizeof(RECT))) {
528 InvalidateRect(This->doc_obj->hwnd, NULL, TRUE);
529 SetWindowPos(This->doc_obj->hwnd, NULL, prcView->left, prcView->top, prcView->right,
530 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
534 return S_OK;
537 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
539 HTMLDocument *This = impl_from_IOleDocumentView(iface);
541 TRACE("(%p)->(%p)\n", This, prcView);
543 if(!prcView)
544 return E_INVALIDARG;
546 GetClientRect(This->doc_obj->hwnd, prcView);
547 return S_OK;
550 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
551 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
553 HTMLDocument *This = impl_from_IOleDocumentView(iface);
554 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
555 return E_NOTIMPL;
558 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
560 HTMLDocument *This = impl_from_IOleDocumentView(iface);
561 HRESULT hres;
563 TRACE("(%p)->(%x)\n", This, fShow);
565 if(fShow) {
566 if(!This->doc_obj->ui_active) {
567 hres = activate_window(This->doc_obj);
568 if(FAILED(hres))
569 return hres;
571 update_doc(This, UPDATE_UI);
572 ShowWindow(This->doc_obj->hwnd, SW_SHOW);
573 }else {
574 ShowWindow(This->doc_obj->hwnd, SW_HIDE);
576 if(This->doc_obj->in_place_active)
577 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->IOleInPlaceObjectWindowless_iface);
579 if(This->doc_obj->ip_window) {
580 IOleInPlaceUIWindow_Release(This->doc_obj->ip_window);
581 This->doc_obj->ip_window = NULL;
585 return S_OK;
588 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
590 HTMLDocument *This = impl_from_IOleDocumentView(iface);
591 HRESULT hres;
593 TRACE("(%p)->(%x)\n", This, fUIActivate);
595 if(!This->doc_obj->ipsite) {
596 IOleClientSite *cs = This->doc_obj->client;
597 IOleInPlaceSite *ips;
599 if(!cs) {
600 WARN("this->ipsite = NULL\n");
601 return E_UNEXPECTED;
604 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteWindowless, (void**)&ips);
605 if(SUCCEEDED(hres))
606 This->doc_obj->ipsite = ips;
607 else {
608 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteEx, (void**)&ips);
609 if(SUCCEEDED(hres))
610 This->doc_obj->ipsite = ips;
611 else {
612 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSite, (void**)&ips);
613 if(SUCCEEDED(hres))
614 This->doc_obj->ipsite = ips;
615 else {
616 WARN("this->ipsite = NULL\n");
617 return E_NOINTERFACE;
622 IOleClientSite_AddRef(This->doc_obj->ipsite);
623 This->doc_obj->request_uiactivate = FALSE;
624 HTMLDocument_LockContainer(This->doc_obj, TRUE);
627 if(fUIActivate) {
628 RECT rcBorderWidths;
630 if(This->doc_obj->ui_active)
631 return S_OK;
633 if(!This->doc_obj->window_active) {
634 hres = activate_window(This->doc_obj);
635 if(FAILED(hres))
636 return hres;
639 This->doc_obj->focus = TRUE;
640 if(This->doc_obj->nscontainer)
641 nsIWebBrowserFocus_Activate(This->doc_obj->nscontainer->focus);
642 notif_focus(This->doc_obj);
644 update_doc(This, UPDATE_UI);
646 hres = IOleInPlaceSite_OnUIActivate(This->doc_obj->ipsite);
647 if(SUCCEEDED(hres)) {
648 call_set_active_object((IOleInPlaceUIWindow*)This->doc_obj->frame,
649 &This->IOleInPlaceActiveObject_iface);
650 }else {
651 FIXME("OnUIActivate failed: %08x\n", hres);
652 IOleInPlaceFrame_Release(This->doc_obj->frame);
653 This->doc_obj->frame = NULL;
654 This->doc_obj->ui_active = FALSE;
655 return hres;
658 if(This->doc_obj->hostui) {
659 hres = IDocHostUIHandler_ShowUI(This->doc_obj->hostui,
660 This->doc_obj->usermode == EDITMODE ? DOCHOSTUITYPE_AUTHOR : DOCHOSTUITYPE_BROWSE,
661 &This->IOleInPlaceActiveObject_iface, CMDTARGET(This), This->doc_obj->frame,
662 This->doc_obj->ip_window);
663 if(FAILED(hres))
664 IDocHostUIHandler_HideUI(This->doc_obj->hostui);
667 if(This->doc_obj->ip_window)
668 call_set_active_object(This->doc_obj->ip_window, &This->IOleInPlaceActiveObject_iface);
670 memset(&rcBorderWidths, 0, sizeof(rcBorderWidths));
671 IOleInPlaceFrame_SetBorderSpace(This->doc_obj->frame, &rcBorderWidths);
673 This->doc_obj->ui_active = TRUE;
674 }else {
675 This->doc_obj->focus = FALSE;
676 nsIWebBrowserFocus_Deactivate(This->doc_obj->nscontainer->focus);
677 if(This->doc_obj->ui_active) {
678 This->doc_obj->ui_active = FALSE;
679 if(This->doc_obj->ip_window)
680 call_set_active_object(This->doc_obj->ip_window, NULL);
681 if(This->doc_obj->frame)
682 call_set_active_object((IOleInPlaceUIWindow*)This->doc_obj->frame, NULL);
683 if(This->doc_obj->hostui)
684 IDocHostUIHandler_HideUI(This->doc_obj->hostui);
685 if(This->doc_obj->ipsite)
686 IOleInPlaceSite_OnUIDeactivate(This->doc_obj->ipsite, FALSE);
689 return S_OK;
692 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
694 HTMLDocument *This = impl_from_IOleDocumentView(iface);
695 FIXME("(%p)\n", This);
696 return E_NOTIMPL;
699 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
701 HTMLDocument *This = impl_from_IOleDocumentView(iface);
702 TRACE("(%p)->(%x)\n", This, dwReserved);
704 if(dwReserved)
705 WARN("dwReserved = %d\n", dwReserved);
707 /* NOTE:
708 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
709 * QueryInterface(IID_IOleControlSite) and KillTimer
712 IOleDocumentView_Show(iface, FALSE);
714 return S_OK;
717 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
719 HTMLDocument *This = impl_from_IOleDocumentView(iface);
720 FIXME("(%p)->(%p)\n", This, pstm);
721 return E_NOTIMPL;
724 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
726 HTMLDocument *This = impl_from_IOleDocumentView(iface);
727 FIXME("(%p)->(%p)\n", This, pstm);
728 return E_NOTIMPL;
731 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
732 IOleDocumentView **ppViewNew)
734 HTMLDocument *This = impl_from_IOleDocumentView(iface);
735 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
736 return E_NOTIMPL;
739 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
740 OleDocumentView_QueryInterface,
741 OleDocumentView_AddRef,
742 OleDocumentView_Release,
743 OleDocumentView_SetInPlaceSite,
744 OleDocumentView_GetInPlaceSite,
745 OleDocumentView_GetDocument,
746 OleDocumentView_SetRect,
747 OleDocumentView_GetRect,
748 OleDocumentView_SetRectComplex,
749 OleDocumentView_Show,
750 OleDocumentView_UIActivate,
751 OleDocumentView_Open,
752 OleDocumentView_CloseView,
753 OleDocumentView_SaveViewState,
754 OleDocumentView_ApplyViewState,
755 OleDocumentView_Clone
758 /**********************************************************
759 * IViewObject implementation
762 static inline HTMLDocument *impl_from_IViewObjectEx(IViewObjectEx *iface)
764 return CONTAINING_RECORD(iface, HTMLDocument, IViewObjectEx_iface);
767 static HRESULT WINAPI ViewObject_QueryInterface(IViewObjectEx *iface, REFIID riid, void **ppv)
769 HTMLDocument *This = impl_from_IViewObjectEx(iface);
770 return htmldoc_query_interface(This, riid, ppv);
773 static ULONG WINAPI ViewObject_AddRef(IViewObjectEx *iface)
775 HTMLDocument *This = impl_from_IViewObjectEx(iface);
776 return htmldoc_addref(This);
779 static ULONG WINAPI ViewObject_Release(IViewObjectEx *iface)
781 HTMLDocument *This = impl_from_IViewObjectEx(iface);
782 return htmldoc_release(This);
785 static HRESULT WINAPI ViewObject_Draw(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
786 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
787 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
789 HTMLDocument *This = impl_from_IViewObjectEx(iface);
790 FIXME("(%p)->(%d %d %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
791 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
792 return E_NOTIMPL;
795 static HRESULT WINAPI ViewObject_GetColorSet(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
796 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
798 HTMLDocument *This = impl_from_IViewObjectEx(iface);
799 FIXME("(%p)->(%d %d %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
800 return E_NOTIMPL;
803 static HRESULT WINAPI ViewObject_Freeze(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex,
804 void *pvAspect, DWORD *pdwFreeze)
806 HTMLDocument *This = impl_from_IViewObjectEx(iface);
807 FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
808 return E_NOTIMPL;
811 static HRESULT WINAPI ViewObject_Unfreeze(IViewObjectEx *iface, DWORD dwFreeze)
813 HTMLDocument *This = impl_from_IViewObjectEx(iface);
814 FIXME("(%p)->(%d)\n", This, dwFreeze);
815 return E_NOTIMPL;
818 static HRESULT WINAPI ViewObject_SetAdvise(IViewObjectEx *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
820 HTMLDocument *This = impl_from_IViewObjectEx(iface);
822 TRACE("(%p)->(%d %d %p)\n", This, aspects, advf, pAdvSink);
824 if(aspects != DVASPECT_CONTENT || advf != ADVF_PRIMEFIRST)
825 FIXME("unsupported arguments\n");
827 if(This->doc_obj->view_sink)
828 IAdviseSink_Release(This->doc_obj->view_sink);
829 if(pAdvSink)
830 IAdviseSink_AddRef(pAdvSink);
832 This->doc_obj->view_sink = pAdvSink;
833 return S_OK;
836 static HRESULT WINAPI ViewObject_GetAdvise(IViewObjectEx *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
838 HTMLDocument *This = impl_from_IViewObjectEx(iface);
839 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
840 return E_NOTIMPL;
843 static HRESULT WINAPI ViewObject_GetExtent(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex,
844 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
846 HTMLDocument *This = impl_from_IViewObjectEx(iface);
847 FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
848 return E_NOTIMPL;
851 static HRESULT WINAPI ViewObject_GetRect(IViewObjectEx *iface, DWORD dwAspect, LPRECTL pRect)
853 HTMLDocument *This = impl_from_IViewObjectEx(iface);
854 FIXME("(%p)->(%d %p)\n", This, dwAspect, pRect);
855 return E_NOTIMPL;
858 static HRESULT WINAPI ViewObject_GetViewStatus(IViewObjectEx *iface, DWORD *pdwStatus)
860 HTMLDocument *This = impl_from_IViewObjectEx(iface);
861 FIXME("(%p)->(%p)\n", This, pdwStatus);
862 return E_NOTIMPL;
865 static HRESULT WINAPI ViewObject_QueryHitPoint(IViewObjectEx* iface, DWORD dwAspect,
866 LPCRECT pRectBounds, POINT ptlLoc, LONG lCloseHint, DWORD *pHitResult)
868 HTMLDocument *This = impl_from_IViewObjectEx(iface);
869 FIXME("(%p)->(%d %p (%d %d) %d %p)\n", This, dwAspect, pRectBounds, ptlLoc.x,
870 ptlLoc.y, lCloseHint, pHitResult);
871 return E_NOTIMPL;
874 static HRESULT WINAPI ViewObject_QueryHitRect(IViewObjectEx *iface, DWORD dwAspect,
875 LPCRECT pRectBounds, LPCRECT pRectLoc, LONG lCloseHint, DWORD *pHitResult)
877 HTMLDocument *This = impl_from_IViewObjectEx(iface);
878 FIXME("(%p)->(%d %p %p %d %p)\n", This, dwAspect, pRectBounds, pRectLoc, lCloseHint, pHitResult);
879 return E_NOTIMPL;
882 static HRESULT WINAPI ViewObject_GetNaturalExtent(IViewObjectEx *iface, DWORD dwAspect, LONG lindex,
883 DVTARGETDEVICE *ptd, HDC hicTargetDev, DVEXTENTINFO *pExtentInfo, LPSIZEL pSizel)
885 HTMLDocument *This = impl_from_IViewObjectEx(iface);
886 FIXME("(%p)->(%d %d %p %p %p %p\n", This, dwAspect,lindex, ptd,
887 hicTargetDev, pExtentInfo, pSizel);
888 return E_NOTIMPL;
891 static const IViewObjectExVtbl ViewObjectVtbl = {
892 ViewObject_QueryInterface,
893 ViewObject_AddRef,
894 ViewObject_Release,
895 ViewObject_Draw,
896 ViewObject_GetColorSet,
897 ViewObject_Freeze,
898 ViewObject_Unfreeze,
899 ViewObject_SetAdvise,
900 ViewObject_GetAdvise,
901 ViewObject_GetExtent,
902 ViewObject_GetRect,
903 ViewObject_GetViewStatus,
904 ViewObject_QueryHitPoint,
905 ViewObject_QueryHitRect,
906 ViewObject_GetNaturalExtent
909 void HTMLDocument_View_Init(HTMLDocument *This)
911 This->IOleDocumentView_iface.lpVtbl = &OleDocumentViewVtbl;
912 This->IViewObjectEx_iface.lpVtbl = &ViewObjectVtbl;