crypt32: Add I_CertUpdateStore stub.
[wine] / dlls / mshtml / view.c
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     HTMLDocument *doc;
50     WNDPROC proc;
51 } tooltip_data;
52
53 static void paint_document(HTMLDocument *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->update && This->hwnd)
100         SetTimer(This->hwnd, TIMER_ID, 100, NULL);
101
102     This->update |= flags;
103 }
104
105 void update_title(HTMLDocument *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(HTMLDocument *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(HTMLDocument *This)
166 {
167     IOleControlSite *site;
168     HRESULT hres;
169
170     hres = IOleClientSite_QueryInterface(This->client, &IID_IOleControlSite, (void**)&site);
171     if(FAILED(hres))
172         return;
173
174     IOleControlSite_OnFocus(site, This->focus);
175     IOleControlSite_Release(site);
176 }
177
178 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
179 {
180     HTMLDocument *This;
181
182     static const WCHAR wszTHIS[] = {'T','H','I','S',0};
183
184     if(msg == WM_CREATE) {
185         This = *(HTMLDocument**)lParam;
186         SetPropW(hwnd, wszTHIS, This);
187     }else {
188         This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
189     }
190
191     switch(msg) {
192     case WM_CREATE:
193         This->hwnd = hwnd;
194         break;
195     case WM_PAINT:
196         paint_document(This);
197         break;
198     case WM_SIZE:
199         TRACE("(%p)->(WM_SIZE)\n", This);
200         if(This->nscontainer) {
201             INT ew=0, eh=0;
202
203             if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER))) {
204                 ew = GetSystemMetrics(SM_CXEDGE);
205                 eh = GetSystemMetrics(SM_CYEDGE);
206             }
207
208             SetWindowPos(This->nscontainer->hwnd, NULL, ew, eh,
209                          LOWORD(lParam) - 2*ew, HIWORD(lParam) - 2*eh,
210                          SWP_NOZORDER | SWP_NOACTIVATE);
211         }
212         break;
213     case WM_TIMER:
214         return on_timer(This);
215     case WM_MOUSEACTIVATE:
216         return MA_ACTIVATE;
217     }
218         
219     return DefWindowProcW(hwnd, msg, wParam, lParam);
220 }
221
222 static void register_serverwnd_class(void)
223 {
224     static WNDCLASSEXW wndclass = {
225         sizeof(WNDCLASSEXW),
226         CS_DBLCLKS,
227         serverwnd_proc,
228         0, 0, NULL, NULL, NULL, NULL, NULL,
229         wszInternetExplorer_Server,
230         NULL,
231     };
232     wndclass.hInstance = hInst;
233     serverwnd_class = RegisterClassExW(&wndclass);
234 }
235
236 static HRESULT activate_window(HTMLDocument *This)
237 {
238     IOleInPlaceFrame *pIPFrame;
239     IOleCommandTarget *cmdtrg;
240     IOleInPlaceSiteEx *ipsiteex;
241     RECT posrect, cliprect;
242     OLEINPLACEFRAMEINFO frameinfo;
243     HWND parent_hwnd;
244     HRESULT hres;
245
246     if(!serverwnd_class)
247         register_serverwnd_class();
248
249     hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
250     if(hres != S_OK) {
251         WARN("CanInPlaceActivate returned: %08x\n", hres);
252         return FAILED(hres) ? hres : E_FAIL;
253     }
254
255     hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &This->ip_window,
256             &posrect, &cliprect, &frameinfo);
257     if(FAILED(hres)) {
258         WARN("GetWindowContext failed: %08x\n", hres);
259         return hres;
260     }
261
262     TRACE("got window context: %p %p {%d %d %d %d} {%d %d %d %d} {%d %x %p %p %d}\n",
263             pIPFrame, This->ip_window, posrect.left, posrect.top, posrect.right, posrect.bottom,
264             cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
265             frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
266
267     hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
268     if(FAILED(hres)) {
269         WARN("GetWindow failed: %08x\n", hres);
270         return hres;
271     }
272
273     TRACE("got parent window %p\n", parent_hwnd);
274
275     if(This->hwnd) {
276         if(GetParent(This->hwnd) != parent_hwnd)
277             SetParent(This->hwnd, parent_hwnd);
278         SetWindowPos(This->hwnd, HWND_TOP,
279                 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
280                 SWP_NOACTIVATE | SWP_SHOWWINDOW);
281     }else {
282         CreateWindowExW(0, wszInternetExplorer_Server, NULL,
283                 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
284                 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
285                 parent_hwnd, NULL, hInst, This);
286
287         TRACE("Created window %p\n", This->hwnd);
288
289         SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
290                 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
291         RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
292
293         /* NOTE:
294          * Windows implementation calls:
295          * RegisterWindowMessage("MSWHEEL_ROLLMSG");
296          */
297         SetTimer(This->hwnd, TIMER_ID, 100, NULL);
298     }
299
300     if(This->nscontainer)
301         activate_gecko(This->nscontainer);
302
303     This->in_place_active = TRUE;
304     hres = IOleInPlaceSite_QueryInterface(This->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex);
305     if(SUCCEEDED(hres)) {
306         BOOL redraw = FALSE;
307
308         hres = IOleInPlaceSiteEx_OnInPlaceActivateEx(ipsiteex, &redraw, 0);
309         IOleInPlaceSiteEx_Release(ipsiteex);
310         if(redraw)
311             FIXME("unsupported redraw\n");
312     }else{
313         hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
314     }
315     if(FAILED(hres)) {
316         WARN("OnInPlaceActivate failed: %08x\n", hres);
317         This->in_place_active = FALSE;
318         return hres;
319     }
320
321     hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
322     if(SUCCEEDED(hres)) {
323         VARIANT var;
324
325         IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
326
327         V_VT(&var) = VT_I4;
328         V_I4(&var) = 0;
329         IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
330                 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
331         IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 
332                 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
333
334         IOleCommandTarget_Release(cmdtrg);
335     }
336
337     if(This->frame)
338         IOleInPlaceFrame_Release(This->frame);
339     This->frame = pIPFrame;
340
341     This->window_active = TRUE;
342
343     return S_OK;
344 }
345
346 static LRESULT WINAPI tooltips_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
347 {
348     tooltip_data *data = GetPropW(hwnd, wszTooltipData);
349
350     TRACE("%d %p\n", msg, data);
351
352     if(msg == TTM_WINDOWFROMPOINT) {
353         RECT rect;
354         POINT *pt = (POINT*)lParam;
355
356         TRACE("TTM_WINDOWFROMPOINT (%d,%d)\n", pt->x, pt->y);
357
358         GetWindowRect(data->doc->hwnd, &rect);
359
360         if(rect.left <= pt->x && pt->x <= rect.right
361            && rect.top <= pt->y && pt->y <= rect.bottom)
362             return (LPARAM)data->doc->hwnd;
363     }
364
365     return CallWindowProcW(data->proc, hwnd, msg, wParam, lParam);
366 }
367
368 static void create_tooltips_window(HTMLDocument *This)
369 {
370     tooltip_data *data = mshtml_alloc(sizeof(*data));
371
372     This->tooltips_hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, TTS_NOPREFIX | WS_POPUP,
373             CW_USEDEFAULT, CW_USEDEFAULT, 10, 10, This->hwnd, NULL, hInst, NULL);
374
375     data->doc = This;
376     data->proc = (WNDPROC)GetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC);
377
378     SetPropW(This->tooltips_hwnd, wszTooltipData, data);
379
380     SetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC, (LONG_PTR)tooltips_proc);
381
382     SetWindowPos(This->tooltips_hwnd, HWND_TOPMOST,0, 0, 0, 0,
383                  SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
384
385 }
386
387 void show_tooltip(HTMLDocument *This, DWORD x, DWORD y, LPCWSTR text)
388 {
389     TTTOOLINFOW toolinfo = {
390         sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
391         {x>2 ? x-2 : 0, y>0 ? y-2 : 0, x+2, y+2}, /* FIXME */
392         NULL, (LPWSTR)text, 0};
393     MSG msg = {This->hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x,y), 0, {x,y}};
394
395     TRACE("(%p)->(%d %d %s)\n", This, x, y, debugstr_w(text));
396
397     if(!This->tooltips_hwnd)
398         create_tooltips_window(This);
399
400     SendMessageW(This->tooltips_hwnd, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo);
401     SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, TRUE, 0);
402     SendMessageW(This->tooltips_hwnd, TTM_RELAYEVENT, 0, (LPARAM)&msg);
403 }
404
405 void hide_tooltip(HTMLDocument *This)
406 {
407     TTTOOLINFOW toolinfo = {
408         sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
409         {0,0,0,0}, NULL, NULL, 0};
410
411     TRACE("(%p)\n", This);
412
413     SendMessageW(This->tooltips_hwnd, TTM_DELTOOLW, 0, (LPARAM)&toolinfo);
414     SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, FALSE, 0);
415 }
416
417 /**********************************************************
418  * IOleDocumentView implementation
419  */
420
421 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
422
423 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
424 {
425     HTMLDocument *This = DOCVIEW_THIS(iface);
426     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
427 }
428
429 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
430 {
431     HTMLDocument *This = DOCVIEW_THIS(iface);
432     return IHTMLDocument2_AddRef(HTMLDOC(This));
433 }
434
435 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
436 {
437     HTMLDocument *This = DOCVIEW_THIS(iface);
438     return IHTMLDocument2_Release(HTMLDOC(This));
439 }
440
441 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
442 {
443     HTMLDocument *This = DOCVIEW_THIS(iface);
444     TRACE("(%p)->(%p)\n", This, pIPSite);
445
446     if(pIPSite)
447         IOleInPlaceSite_AddRef(pIPSite);
448
449     if(This->ipsite)
450         IOleInPlaceSite_Release(This->ipsite);
451
452     This->ipsite = pIPSite;
453     return S_OK;
454 }
455
456 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
457 {
458     HTMLDocument *This = DOCVIEW_THIS(iface);
459     TRACE("(%p)->(%p)\n", This, ppIPSite);
460
461     if(!ppIPSite)
462         return E_INVALIDARG;
463
464     if(This->ipsite)
465         IOleInPlaceSite_AddRef(This->ipsite);
466
467     *ppIPSite = This->ipsite;
468     return S_OK;
469 }
470
471 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
472 {
473     HTMLDocument *This = DOCVIEW_THIS(iface);
474     TRACE("(%p)->(%p)\n", This, ppunk);
475
476     if(!ppunk)
477         return E_INVALIDARG;
478
479     IHTMLDocument2_AddRef(HTMLDOC(This));
480     *ppunk = (IUnknown*)HTMLDOC(This);
481     return S_OK;
482 }
483
484 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
485 {
486     HTMLDocument *This = DOCVIEW_THIS(iface);
487     RECT rect;
488
489     TRACE("(%p)->(%p)\n", This, prcView);
490
491     if(!prcView)
492         return E_INVALIDARG;
493
494     if(This->hwnd) {
495         GetClientRect(This->hwnd, &rect);
496         if(memcmp(prcView, &rect, sizeof(RECT))) {
497             InvalidateRect(This->hwnd,NULL,TRUE);
498             SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
499                     prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
500         }
501     }
502     
503     return S_OK;
504 }
505
506 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
507 {
508     HTMLDocument *This = DOCVIEW_THIS(iface);
509
510     TRACE("(%p)->(%p)\n", This, prcView);
511
512     if(!prcView)
513         return E_INVALIDARG;
514
515     GetClientRect(This->hwnd, prcView);
516     return S_OK;
517 }
518
519 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
520                         LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
521 {
522     HTMLDocument *This = DOCVIEW_THIS(iface);
523     FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
524     return E_NOTIMPL;
525 }
526
527 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
528 {
529     HTMLDocument *This = DOCVIEW_THIS(iface);
530     HRESULT hres;
531
532     TRACE("(%p)->(%x)\n", This, fShow);
533
534     if(fShow) {
535         if(!This->ui_active) {
536             hres = activate_window(This);
537             if(FAILED(hres))
538                 return hres;
539         }
540         update_doc(This, UPDATE_UI);
541         ShowWindow(This->hwnd, SW_SHOW);
542     }else {
543         ShowWindow(This->hwnd, SW_HIDE);
544         if(This->ip_window) {
545             IOleInPlaceUIWindow_Release(This->ip_window);
546             This->ip_window = NULL;
547         }
548     }
549
550     return S_OK;
551 }
552
553 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
554 {
555     HTMLDocument *This = DOCVIEW_THIS(iface);
556     HRESULT hres;
557
558     TRACE("(%p)->(%x)\n", This, fUIActivate);
559
560     if(!This->ipsite) {
561         FIXME("This->ipsite = NULL\n");
562         return E_FAIL;
563     }
564
565     if(fUIActivate) {
566         OLECHAR wszHTMLDocument[30];
567         RECT rcBorderWidths;
568
569         if(This->ui_active)
570             return S_OK;
571
572         if(!This->window_active) {
573             hres = activate_window(This);
574             if(FAILED(hres))
575                 return hres;
576         }
577
578         This->focus = TRUE;
579         if(This->nscontainer)
580             nsIWebBrowserFocus_Activate(This->nscontainer->focus);
581         notif_focus(This);
582
583         update_doc(This, UPDATE_UI);
584
585         LoadStringW(hInst, IDS_HTMLDOCUMENT, wszHTMLDocument,
586                     sizeof(wszHTMLDocument)/sizeof(WCHAR));
587
588         hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
589         if(SUCCEEDED(hres)) {
590             IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTMLDocument);
591         }else {
592             FIXME("OnUIActivate failed: %08x\n", hres);
593             IOleInPlaceFrame_Release(This->frame);
594             This->frame = NULL;
595             This->ui_active = FALSE;
596             return hres;
597         }
598
599         hres = IDocHostUIHandler_ShowUI(This->hostui,
600                 This->usermode == EDITMODE ? DOCHOSTUITYPE_AUTHOR : DOCHOSTUITYPE_BROWSE,
601                 ACTOBJ(This), CMDTARGET(This), This->frame, This->ip_window);
602         if(FAILED(hres))
603             IDocHostUIHandler_HideUI(This->hostui);
604
605         if(This->ip_window)
606             IOleInPlaceUIWindow_SetActiveObject(This->ip_window, ACTOBJ(This), wszHTMLDocument);
607
608         memset(&rcBorderWidths, 0, sizeof(rcBorderWidths));
609         IOleInPlaceFrame_SetBorderSpace(This->frame, &rcBorderWidths);
610
611         This->ui_active = TRUE;
612     }else {
613         if(This->ui_active) {
614             This->ui_active = FALSE;
615             if(This->ip_window)
616                 IOleInPlaceUIWindow_SetActiveObject(This->ip_window, NULL, NULL);
617             if(This->frame)
618                 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
619             if(This->hostui)
620                 IDocHostUIHandler_HideUI(This->hostui);
621             if(This->ipsite)
622                 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
623         }
624     }
625     return S_OK;
626 }
627
628 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
629 {
630     HTMLDocument *This = DOCVIEW_THIS(iface);
631     FIXME("(%p)\n", This);
632     return E_NOTIMPL;
633 }
634
635 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
636 {
637     HTMLDocument *This = DOCVIEW_THIS(iface);
638     TRACE("(%p)->(%x)\n", This, dwReserved);
639
640     if(dwReserved)
641         WARN("dwReserved = %d\n", dwReserved);
642
643     /* NOTE:
644      * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
645      * QueryInterface(IID_IOleControlSite) and KillTimer
646      */
647
648     IOleDocumentView_Show(iface, FALSE);
649
650     return S_OK;
651 }
652
653 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
654 {
655     HTMLDocument *This = DOCVIEW_THIS(iface);
656     FIXME("(%p)->(%p)\n", This, pstm);
657     return E_NOTIMPL;
658 }
659
660 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
661 {
662     HTMLDocument *This = DOCVIEW_THIS(iface);
663     FIXME("(%p)->(%p)\n", This, pstm);
664     return E_NOTIMPL;
665 }
666
667 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
668                                         IOleDocumentView **ppViewNew)
669 {
670     HTMLDocument *This = DOCVIEW_THIS(iface);
671     FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
672     return E_NOTIMPL;
673 }
674
675 #undef DOCVIEW_THIS
676
677 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
678     OleDocumentView_QueryInterface,
679     OleDocumentView_AddRef,
680     OleDocumentView_Release,
681     OleDocumentView_SetInPlaceSite,
682     OleDocumentView_GetInPlaceSite,
683     OleDocumentView_GetDocument,
684     OleDocumentView_SetRect,
685     OleDocumentView_GetRect,
686     OleDocumentView_SetRectComplex,
687     OleDocumentView_Show,
688     OleDocumentView_UIActivate,
689     OleDocumentView_Open,
690     OleDocumentView_CloseView,
691     OleDocumentView_SaveViewState,
692     OleDocumentView_ApplyViewState,
693     OleDocumentView_Clone
694 };
695
696 /**********************************************************
697  * IViewObject implementation
698  */
699
700 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
701
702 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
703 {
704     HTMLDocument *This = VIEWOBJ_THIS(iface);
705     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
706 }
707
708 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
709 {
710     HTMLDocument *This = VIEWOBJ_THIS(iface);
711     return IHTMLDocument2_AddRef(HTMLDOC(This));
712 }
713
714 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
715 {
716     HTMLDocument *This = VIEWOBJ_THIS(iface);
717     return IHTMLDocument2_Release(HTMLDOC(This));
718 }
719
720 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
721         DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
722         LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
723 {
724     HTMLDocument *This = VIEWOBJ_THIS(iface);
725     FIXME("(%p)->(%d %d %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
726             ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
727     return E_NOTIMPL;
728 }
729
730 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
731         DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
732 {
733     HTMLDocument *This = VIEWOBJ_THIS(iface);
734     FIXME("(%p)->(%d %d %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
735     return E_NOTIMPL;
736 }
737
738 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
739         void *pvAspect, DWORD *pdwFreeze)
740 {
741     HTMLDocument *This = VIEWOBJ_THIS(iface);
742     FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
743     return E_NOTIMPL;
744 }
745
746 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
747 {
748     HTMLDocument *This = VIEWOBJ_THIS(iface);
749     FIXME("(%p)->(%d)\n", This, dwFreeze);
750     return E_NOTIMPL;
751 }
752
753 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
754 {
755     HTMLDocument *This = VIEWOBJ_THIS(iface);
756     FIXME("(%p)->(%d %d %p)\n", This, aspects, advf, pAdvSink);
757     return E_NOTIMPL;
758 }
759
760 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
761 {
762     HTMLDocument *This = VIEWOBJ_THIS(iface);
763     FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
764     return E_NOTIMPL;
765 }
766
767 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
768                                 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
769 {
770     HTMLDocument *This = VIEWOBJ_THIS(iface);
771     FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
772     return E_NOTIMPL;
773 }
774
775 #undef VIEWOBJ_THIS
776
777 static const IViewObject2Vtbl ViewObjectVtbl = {
778     ViewObject_QueryInterface,
779     ViewObject_AddRef,
780     ViewObject_Release,
781     ViewObject_Draw,
782     ViewObject_GetColorSet,
783     ViewObject_Freeze,
784     ViewObject_Unfreeze,
785     ViewObject_SetAdvise,
786     ViewObject_GetAdvise,
787     ViewObject_GetExtent
788 };
789
790 void HTMLDocument_View_Init(HTMLDocument *This)
791 {
792     This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
793     This->lpViewObject2Vtbl = &ViewObjectVtbl;
794
795     This->ipsite = NULL;
796     This->frame = NULL;
797     This->ip_window = NULL;
798     This->hwnd = NULL;
799     This->tooltips_hwnd = NULL;
800
801     This->in_place_active = FALSE;
802     This->ui_active = FALSE;
803     This->window_active = FALSE;
804     This->focus = FALSE;
805
806     This->update = 0;
807 }