rpcrt4: Try a lot harder to resuse existing connections by comparing inside the RpcQu...
[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 "wingdi.h"
30 #include "commctrl.h"
31 #include "ole2.h"
32 #include "resource.h"
33
34 #include "wine/debug.h"
35
36 #include "mshtml_private.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39
40 #define TIMER_ID 0x1000
41
42 static const WCHAR wszInternetExplorer_Server[] =
43     {'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','_','S','e','r','v','e','r',0};
44
45 static const WCHAR wszTooltipData[] = {'t','o','o','l','t','i','p','_','d','a','t','a',0};
46
47 static ATOM serverwnd_class = 0;
48
49 typedef struct {
50     HTMLDocument *doc;
51     WNDPROC proc;
52 } tooltip_data;
53
54 static void paint_document(HTMLDocument *This)
55 {
56     PAINTSTRUCT ps;
57     RECT rect;
58     HDC hdc;
59
60     GetClientRect(This->hwnd, &rect);
61
62     hdc = BeginPaint(This->hwnd, &ps);
63
64     if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER)))
65         DrawEdge(hdc, &rect, EDGE_SUNKEN, BF_RECT|BF_ADJUST);
66
67     if(!This->nscontainer) {
68         WCHAR wszHTMLDisabled[100];
69         HFONT font;
70
71         LoadStringW(hInst, IDS_HTMLDISABLED, wszHTMLDisabled, sizeof(wszHTMLDisabled)/sizeof(WCHAR));
72
73         font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
74
75         SelectObject(hdc, font);
76         SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW));
77
78         Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
79         DrawTextW(hdc, wszHTMLDisabled,-1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
80
81         DeleteObject(font);
82     }
83
84     EndPaint(This->hwnd, &ps);
85 }
86
87 static void activate_gecko(NSContainer *This)
88 {
89     TRACE("(%p) %p\n", This, This->window);
90
91     SetParent(This->hwnd, This->doc->hwnd);
92     ShowWindow(This->hwnd, SW_SHOW);
93
94     nsIBaseWindow_SetVisibility(This->window, TRUE);
95     nsIBaseWindow_SetEnabled(This->window, TRUE);
96     nsIWebBrowserFocus_Activate(This->focus);
97 }
98
99 void update_doc(HTMLDocument *This, DWORD flags)
100 {
101     if(!This->update && This->hwnd)
102         SetTimer(This->hwnd, TIMER_ID, 100, NULL);
103
104     This->update |= flags;
105 }
106
107 void update_title(HTMLDocument *This)
108 {
109     IOleCommandTarget *olecmd;
110     HRESULT hres;
111
112     if(!(This->update & UPDATE_TITLE))
113         return;
114
115     This->update &= ~UPDATE_TITLE;
116
117     if(!This->client)
118         return;
119
120     hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&olecmd);
121     if(SUCCEEDED(hres)) {
122         VARIANT title;
123         WCHAR empty[] = {0};
124
125         V_VT(&title) = VT_BSTR;
126         V_BSTR(&title) = SysAllocString(empty);
127         IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER,
128                                &title, NULL);
129         SysFreeString(V_BSTR(&title));
130
131         IOleCommandTarget_Release(olecmd);
132     }
133 }
134
135 static LRESULT on_timer(HTMLDocument *This)
136 {
137     TRACE("(%p) %x\n", This, This->update);
138
139     KillTimer(This->hwnd, TIMER_ID);
140
141     if(!This->update)
142         return 0;
143
144     if(This->update & UPDATE_UI) {
145         if(This->hostui)
146             IDocHostUIHandler_UpdateUI(This->hostui);
147
148         if(This->client) {
149             IOleCommandTarget *cmdtrg;
150             HRESULT hres;
151
152             hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
153                                                  (void**)&cmdtrg);
154             if(SUCCEEDED(hres)) {
155                 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_UPDATECOMMANDS,
156                                        OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
157                 IOleCommandTarget_Release(cmdtrg);
158             }
159         }
160     }
161
162     update_title(This);
163     This->update = 0;
164     return 0;
165 }
166
167 void notif_focus(HTMLDocument *This)
168 {
169     IOleControlSite *site;
170     HRESULT hres;
171
172     hres = IOleClientSite_QueryInterface(This->client, &IID_IOleControlSite, (void**)&site);
173     if(FAILED(hres))
174         return;
175
176     IOleControlSite_OnFocus(site, This->focus);
177     IOleControlSite_Release(site);
178 }
179
180 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
181 {
182     HTMLDocument *This;
183
184     static const WCHAR wszTHIS[] = {'T','H','I','S',0};
185
186     if(msg == WM_CREATE) {
187         This = *(HTMLDocument**)lParam;
188         SetPropW(hwnd, wszTHIS, This);
189     }else {
190         This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
191     }
192
193     switch(msg) {
194     case WM_CREATE:
195         This->hwnd = hwnd;
196         break;
197     case WM_PAINT:
198         paint_document(This);
199         break;
200     case WM_SIZE:
201         TRACE("(%p)->(WM_SIZE)\n", This);
202         if(This->nscontainer) {
203             INT ew=0, eh=0;
204
205             if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER))) {
206                 ew = GetSystemMetrics(SM_CXEDGE);
207                 eh = GetSystemMetrics(SM_CYEDGE);
208             }
209
210             SetWindowPos(This->nscontainer->hwnd, NULL, ew, eh,
211                          LOWORD(lParam) - 2*ew, HIWORD(lParam) - 2*eh,
212                          SWP_NOZORDER | SWP_NOACTIVATE);
213         }
214         break;
215     case WM_TIMER:
216         return on_timer(This);
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     IOleInPlaceUIWindow *pIPWnd;
239     IOleInPlaceFrame *pIPFrame;
240     IOleCommandTarget *cmdtrg;
241     IOleInPlaceSiteEx *ipsiteex;
242     RECT posrect, cliprect;
243     OLEINPLACEFRAMEINFO frameinfo;
244     HWND parent_hwnd;
245     HRESULT hres;
246
247     if(!serverwnd_class)
248         register_serverwnd_class();
249
250     hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
251     if(hres != S_OK) {
252         WARN("CanInPlaceActivate returned: %08x\n", hres);
253         return FAILED(hres) ? hres : E_FAIL;
254     }
255
256     hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd,
257             &posrect, &cliprect, &frameinfo);
258     if(FAILED(hres)) {
259         WARN("GetWindowContext failed: %08x\n", hres);
260         return hres;
261     }
262
263     if(pIPWnd)
264         IOleInPlaceUIWindow_Release(pIPWnd);
265     TRACE("got window context: %p %p {%d %d %d %d} {%d %d %d %d} {%d %x %p %p %d}\n",
266             pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
267             cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
268             frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
269
270     hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
271     if(FAILED(hres)) {
272         WARN("GetWindow failed: %08x\n", hres);
273         return hres;
274     }
275
276     TRACE("got parent window %p\n", parent_hwnd);
277
278     if(This->hwnd) {
279         if(GetParent(This->hwnd) != parent_hwnd)
280             SetParent(This->hwnd, parent_hwnd);
281         SetWindowPos(This->hwnd, HWND_TOP,
282                 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
283                 SWP_NOACTIVATE | SWP_SHOWWINDOW);
284     }else {
285         CreateWindowExW(0, wszInternetExplorer_Server, NULL,
286                 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
287                 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
288                 parent_hwnd, NULL, hInst, This);
289
290         TRACE("Created window %p\n", This->hwnd);
291
292         SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
293                 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
294         RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
295         SetFocus(This->hwnd);
296
297         /* NOTE:
298          * Windows implementation calls:
299          * RegisterWindowMessage("MSWHEEL_ROLLMSG");
300          */
301         SetTimer(This->hwnd, TIMER_ID, 100, NULL);
302     }
303
304     if(This->nscontainer)
305         activate_gecko(This->nscontainer);
306
307     This->in_place_active = TRUE;
308     hres = IOleInPlaceSite_QueryInterface(This->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex);
309     if(SUCCEEDED(hres)) {
310         BOOL redraw = FALSE;
311
312         hres = IOleInPlaceSiteEx_OnInPlaceActivateEx(ipsiteex, &redraw, 0);
313         IOleInPlaceSiteEx_Release(ipsiteex);
314         if(redraw)
315             FIXME("unsupported redraw\n");
316     }else{
317         hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
318     }
319     if(FAILED(hres)) {
320         WARN("OnInPlaceActivate failed: %08x\n", hres);
321         This->in_place_active = FALSE;
322         return hres;
323     }
324
325     hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
326     if(SUCCEEDED(hres)) {
327         VARIANT var;
328
329         IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
330
331         V_VT(&var) = VT_I4;
332         V_I4(&var) = 0;
333         IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
334                 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
335         IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 
336                 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
337
338         IOleCommandTarget_Release(cmdtrg);
339     }
340
341     if(This->frame)
342         IOleInPlaceFrame_Release(This->frame);
343     This->frame = pIPFrame;
344
345     This->window_active = TRUE;
346
347     return S_OK;
348 }
349
350 static LRESULT WINAPI tooltips_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
351 {
352     tooltip_data *data = GetPropW(hwnd, wszTooltipData);
353
354     TRACE("%d %p\n", msg, data);
355
356     if(msg == TTM_WINDOWFROMPOINT) {
357         RECT rect;
358         POINT *pt = (POINT*)lParam;
359
360         TRACE("TTM_WINDOWFROMPOINT (%d,%d)\n", pt->x, pt->y);
361
362         GetWindowRect(data->doc->hwnd, &rect);
363
364         if(rect.left <= pt->x && pt->x <= rect.right
365            && rect.top <= pt->y && pt->y <= rect.bottom)
366             return (LPARAM)data->doc->hwnd;
367     }
368
369     return CallWindowProcW(data->proc, hwnd, msg, wParam, lParam);
370 }
371
372 static void create_tooltips_window(HTMLDocument *This)
373 {
374     tooltip_data *data = mshtml_alloc(sizeof(*data));
375
376     This->tooltips_hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, TTS_NOPREFIX | WS_POPUP,
377             CW_USEDEFAULT, CW_USEDEFAULT, 10, 10, This->hwnd, NULL, hInst, NULL);
378
379     data->doc = This;
380     data->proc = (WNDPROC)GetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC);
381
382     SetPropW(This->tooltips_hwnd, wszTooltipData, data);
383
384     SetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC, (LONG_PTR)tooltips_proc);
385
386     SetWindowPos(This->tooltips_hwnd, HWND_TOPMOST,0, 0, 0, 0,
387                  SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
388
389 }
390
391 void show_tooltip(HTMLDocument *This, DWORD x, DWORD y, LPCWSTR text)
392 {
393     TTTOOLINFOW toolinfo = {
394         sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
395         {x>2 ? x-2 : 0, y>0 ? y-2 : 0, x+2, y+2}, /* FIXME */
396         NULL, (LPWSTR)text, 0};
397     MSG msg = {This->hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x,y), 0, {x,y}};
398
399     TRACE("(%p)->(%d %d %s)\n", This, x, y, debugstr_w(text));
400
401     if(!This->tooltips_hwnd)
402         create_tooltips_window(This);
403
404     SendMessageW(This->tooltips_hwnd, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo);
405     SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, TRUE, 0);
406     SendMessageW(This->tooltips_hwnd, TTM_RELAYEVENT, 0, (LPARAM)&msg);
407 }
408
409 void hide_tooltip(HTMLDocument *This)
410 {
411     TTTOOLINFOW toolinfo = {
412         sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
413         {0,0,0,0}, NULL, NULL, 0};
414
415     TRACE("(%p)\n", This);
416
417     SendMessageW(This->tooltips_hwnd, TTM_DELTOOLW, 0, (LPARAM)&toolinfo);
418     SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, FALSE, 0);
419 }
420
421 /**********************************************************
422  * IOleDocumentView implementation
423  */
424
425 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
426
427 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
428 {
429     HTMLDocument *This = DOCVIEW_THIS(iface);
430     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
431 }
432
433 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
434 {
435     HTMLDocument *This = DOCVIEW_THIS(iface);
436     return IHTMLDocument2_AddRef(HTMLDOC(This));
437 }
438
439 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
440 {
441     HTMLDocument *This = DOCVIEW_THIS(iface);
442     return IHTMLDocument2_Release(HTMLDOC(This));
443 }
444
445 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
446 {
447     HTMLDocument *This = DOCVIEW_THIS(iface);
448     TRACE("(%p)->(%p)\n", This, pIPSite);
449
450     if(pIPSite)
451         IOleInPlaceSite_AddRef(pIPSite);
452
453     if(This->ipsite)
454         IOleInPlaceSite_Release(This->ipsite);
455
456     This->ipsite = pIPSite;
457     return S_OK;
458 }
459
460 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
461 {
462     HTMLDocument *This = DOCVIEW_THIS(iface);
463     TRACE("(%p)->(%p)\n", This, ppIPSite);
464
465     if(!ppIPSite)
466         return E_INVALIDARG;
467
468     if(This->ipsite)
469         IOleInPlaceSite_AddRef(This->ipsite);
470
471     *ppIPSite = This->ipsite;
472     return S_OK;
473 }
474
475 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
476 {
477     HTMLDocument *This = DOCVIEW_THIS(iface);
478     TRACE("(%p)->(%p)\n", This, ppunk);
479
480     if(!ppunk)
481         return E_INVALIDARG;
482
483     IHTMLDocument2_AddRef(HTMLDOC(This));
484     *ppunk = (IUnknown*)HTMLDOC(This);
485     return S_OK;
486 }
487
488 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
489 {
490     HTMLDocument *This = DOCVIEW_THIS(iface);
491     RECT rect;
492
493     TRACE("(%p)->(%p)\n", This, prcView);
494
495     if(!prcView)
496         return E_INVALIDARG;
497
498     if(This->hwnd) {
499         GetClientRect(This->hwnd, &rect);
500         if(memcmp(prcView, &rect, sizeof(RECT))) {
501             InvalidateRect(This->hwnd,NULL,TRUE);
502             SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
503                     prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
504         }
505     }
506     
507     return S_OK;
508 }
509
510 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
511 {
512     HTMLDocument *This = DOCVIEW_THIS(iface);
513
514     TRACE("(%p)->(%p)\n", This, prcView);
515
516     if(!prcView)
517         return E_INVALIDARG;
518
519     GetClientRect(This->hwnd, prcView);
520     return S_OK;
521 }
522
523 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
524                         LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
525 {
526     HTMLDocument *This = DOCVIEW_THIS(iface);
527     FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
528     return E_NOTIMPL;
529 }
530
531 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
532 {
533     HTMLDocument *This = DOCVIEW_THIS(iface);
534     HRESULT hres;
535
536     TRACE("(%p)->(%x)\n", This, fShow);
537
538     if(fShow) {
539         if(!This->ui_active) {
540             hres = activate_window(This);
541             if(FAILED(hres))
542                 return hres;
543         }
544         update_doc(This, UPDATE_UI);
545         ShowWindow(This->hwnd, SW_SHOW);
546     }else {
547         ShowWindow(This->hwnd, SW_HIDE);
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         if(This->ui_active)
567             return S_OK;
568
569         if(!This->window_active) {
570             hres = activate_window(This);
571             if(FAILED(hres))
572                 return hres;
573         }
574
575         update_doc(This, UPDATE_UI);
576
577         hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
578         if(SUCCEEDED(hres)) {
579             OLECHAR wszHTMLDocument[30];
580             LoadStringW(hInst, IDS_HTMLDOCUMENT, wszHTMLDocument,
581                     sizeof(wszHTMLDocument)/sizeof(WCHAR));
582             IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTMLDocument);
583         }else {
584             FIXME("OnUIActivate failed: %08x\n", hres);
585             IOleInPlaceFrame_Release(This->frame);
586             This->frame = NULL;
587             This->ui_active = FALSE;
588             return hres;
589         }
590
591         hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
592                 This->frame, NULL);
593         if(FAILED(hres))
594             IDocHostUIHandler_HideUI(This->hostui);
595
596         This->ui_active = TRUE;
597     }else {
598         This->window_active = FALSE;
599         if(This->ui_active) {
600             This->ui_active = FALSE;
601             if(This->frame)
602                 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
603             if(This->hostui)
604                 IDocHostUIHandler_HideUI(This->hostui);
605             if(This->ipsite)
606                 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
607         }
608     }
609     return S_OK;
610 }
611
612 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
613 {
614     HTMLDocument *This = DOCVIEW_THIS(iface);
615     FIXME("(%p)\n", This);
616     return E_NOTIMPL;
617 }
618
619 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
620 {
621     HTMLDocument *This = DOCVIEW_THIS(iface);
622     TRACE("(%p)->(%x)\n", This, dwReserved);
623
624     if(dwReserved)
625         WARN("dwReserved = %d\n", dwReserved);
626
627     /* NOTE:
628      * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
629      * QueryInterface(IID_IOleControlSite) and KillTimer
630      */
631
632     IOleDocumentView_Show(iface, FALSE);
633
634     return S_OK;
635 }
636
637 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
638 {
639     HTMLDocument *This = DOCVIEW_THIS(iface);
640     FIXME("(%p)->(%p)\n", This, pstm);
641     return E_NOTIMPL;
642 }
643
644 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
645 {
646     HTMLDocument *This = DOCVIEW_THIS(iface);
647     FIXME("(%p)->(%p)\n", This, pstm);
648     return E_NOTIMPL;
649 }
650
651 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
652                                         IOleDocumentView **ppViewNew)
653 {
654     HTMLDocument *This = DOCVIEW_THIS(iface);
655     FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
656     return E_NOTIMPL;
657 }
658
659 #undef DOCVIEW_THIS
660
661 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
662     OleDocumentView_QueryInterface,
663     OleDocumentView_AddRef,
664     OleDocumentView_Release,
665     OleDocumentView_SetInPlaceSite,
666     OleDocumentView_GetInPlaceSite,
667     OleDocumentView_GetDocument,
668     OleDocumentView_SetRect,
669     OleDocumentView_GetRect,
670     OleDocumentView_SetRectComplex,
671     OleDocumentView_Show,
672     OleDocumentView_UIActivate,
673     OleDocumentView_Open,
674     OleDocumentView_CloseView,
675     OleDocumentView_SaveViewState,
676     OleDocumentView_ApplyViewState,
677     OleDocumentView_Clone
678 };
679
680 /**********************************************************
681  * IViewObject implementation
682  */
683
684 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
685
686 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
687 {
688     HTMLDocument *This = VIEWOBJ_THIS(iface);
689     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
690 }
691
692 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
693 {
694     HTMLDocument *This = VIEWOBJ_THIS(iface);
695     return IHTMLDocument2_AddRef(HTMLDOC(This));
696 }
697
698 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
699 {
700     HTMLDocument *This = VIEWOBJ_THIS(iface);
701     return IHTMLDocument2_Release(HTMLDOC(This));
702 }
703
704 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
705         DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
706         LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
707 {
708     HTMLDocument *This = VIEWOBJ_THIS(iface);
709     FIXME("(%p)->(%d %d %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
710             ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
711     return E_NOTIMPL;
712 }
713
714 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
715         DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
716 {
717     HTMLDocument *This = VIEWOBJ_THIS(iface);
718     FIXME("(%p)->(%d %d %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
719     return E_NOTIMPL;
720 }
721
722 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
723         void *pvAspect, DWORD *pdwFreeze)
724 {
725     HTMLDocument *This = VIEWOBJ_THIS(iface);
726     FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
727     return E_NOTIMPL;
728 }
729
730 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
731 {
732     HTMLDocument *This = VIEWOBJ_THIS(iface);
733     FIXME("(%p)->(%d)\n", This, dwFreeze);
734     return E_NOTIMPL;
735 }
736
737 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
738 {
739     HTMLDocument *This = VIEWOBJ_THIS(iface);
740     FIXME("(%p)->(%d %d %p)\n", This, aspects, advf, pAdvSink);
741     return E_NOTIMPL;
742 }
743
744 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
745 {
746     HTMLDocument *This = VIEWOBJ_THIS(iface);
747     FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
748     return E_NOTIMPL;
749 }
750
751 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
752                                 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
753 {
754     HTMLDocument *This = VIEWOBJ_THIS(iface);
755     FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
756     return E_NOTIMPL;
757 }
758
759 #undef VIEWOBJ_THIS
760
761 static const IViewObject2Vtbl ViewObjectVtbl = {
762     ViewObject_QueryInterface,
763     ViewObject_AddRef,
764     ViewObject_Release,
765     ViewObject_Draw,
766     ViewObject_GetColorSet,
767     ViewObject_Freeze,
768     ViewObject_Unfreeze,
769     ViewObject_SetAdvise,
770     ViewObject_GetAdvise,
771     ViewObject_GetExtent
772 };
773
774 void HTMLDocument_View_Init(HTMLDocument *This)
775 {
776     This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
777     This->lpViewObject2Vtbl = &ViewObjectVtbl;
778
779     This->ipsite = NULL;
780     This->frame = NULL;
781     This->hwnd = NULL;
782     This->tooltips_hwnd = NULL;
783
784     This->in_place_active = FALSE;
785     This->ui_active = FALSE;
786     This->window_active = FALSE;
787     This->focus = FALSE;
788
789     This->update = 0;
790 }