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