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