secur32/tests: Use importlib for functions available since Windows XP.
[wine.git] / dlls / mshtml / view.c
blob15f39f47717dff090f5d0c14eed3120731708842
1 /*
2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "commctrl.h"
30 #include "ole2.h"
31 #include "resource.h"
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 #define TIMER_ID 0x1000
41 static const WCHAR wszInternetExplorer_Server[] =
42 {'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','_','S','e','r','v','e','r',0};
44 static const WCHAR wszTooltipData[] = {'t','o','o','l','t','i','p','_','d','a','t','a',0};
46 static ATOM serverwnd_class = 0;
48 typedef struct {
49 HTMLDocumentObj *doc;
50 WNDPROC proc;
51 } tooltip_data;
53 static void paint_document(HTMLDocumentObj *This)
55 PAINTSTRUCT ps;
56 RECT rect;
57 HDC hdc;
59 GetClientRect(This->hwnd, &rect);
61 hdc = BeginPaint(This->hwnd, &ps);
63 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER)))
64 DrawEdge(hdc, &rect, EDGE_SUNKEN, BF_RECT|BF_ADJUST);
66 EndPaint(This->hwnd, &ps);
69 static void activate_gecko(NSContainer *This)
71 TRACE("(%p) %p\n", This, This->window);
73 SetParent(This->hwnd, This->doc->hwnd);
74 ShowWindow(This->hwnd, SW_SHOW);
76 nsIBaseWindow_SetVisibility(This->window, TRUE);
77 nsIBaseWindow_SetEnabled(This->window, TRUE);
80 void update_doc(HTMLDocument *This, DWORD flags)
82 if(!This->doc_obj->update && This->doc_obj->hwnd)
83 SetTimer(This->doc_obj->hwnd, TIMER_ID, 100, NULL);
85 This->doc_obj->update |= flags;
88 void update_title(HTMLDocumentObj *This)
90 IOleCommandTarget *olecmd;
91 HRESULT hres;
93 if(!(This->update & UPDATE_TITLE))
94 return;
96 This->update &= ~UPDATE_TITLE;
98 if(!This->client)
99 return;
101 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&olecmd);
102 if(SUCCEEDED(hres)) {
103 VARIANT title;
104 WCHAR empty[] = {0};
106 V_VT(&title) = VT_BSTR;
107 V_BSTR(&title) = SysAllocString(empty);
108 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETTITLE, OLECMDEXECOPT_DONTPROMPTUSER,
109 &title, NULL);
110 SysFreeString(V_BSTR(&title));
112 IOleCommandTarget_Release(olecmd);
116 static LRESULT on_timer(HTMLDocumentObj *This)
118 TRACE("(%p) %x\n", This, This->update);
120 KillTimer(This->hwnd, TIMER_ID);
122 if(!This->update)
123 return 0;
125 if(This->update & UPDATE_UI) {
126 if(This->hostui)
127 IDocHostUIHandler_UpdateUI(This->hostui);
129 if(This->client) {
130 IOleCommandTarget *cmdtrg;
131 HRESULT hres;
133 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget,
134 (void**)&cmdtrg);
135 if(SUCCEEDED(hres)) {
136 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_UPDATECOMMANDS,
137 OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
138 IOleCommandTarget_Release(cmdtrg);
143 update_title(This);
144 This->update = 0;
145 return 0;
148 void notif_focus(HTMLDocumentObj *This)
150 IOleControlSite *site;
151 HRESULT hres;
153 if(!This->client)
154 return;
156 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleControlSite, (void**)&site);
157 if(FAILED(hres))
158 return;
160 IOleControlSite_OnFocus(site, This->focus);
161 IOleControlSite_Release(site);
164 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
166 HTMLDocumentObj *This;
168 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
170 if(msg == WM_CREATE) {
171 This = *(HTMLDocumentObj**)lParam;
172 SetPropW(hwnd, wszTHIS, This);
173 }else {
174 This = GetPropW(hwnd, wszTHIS);
177 switch(msg) {
178 case WM_CREATE:
179 This->hwnd = hwnd;
180 break;
181 case WM_PAINT:
182 paint_document(This);
183 break;
184 case WM_SIZE:
185 TRACE("(%p)->(WM_SIZE)\n", This);
186 if(This->nscontainer) {
187 INT ew=0, eh=0;
189 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER))) {
190 ew = GetSystemMetrics(SM_CXEDGE);
191 eh = GetSystemMetrics(SM_CYEDGE);
194 SetWindowPos(This->nscontainer->hwnd, NULL, ew, eh,
195 LOWORD(lParam) - 2*ew, HIWORD(lParam) - 2*eh,
196 SWP_NOZORDER | SWP_NOACTIVATE);
198 break;
199 case WM_TIMER:
200 return on_timer(This);
201 case WM_SETFOCUS:
202 TRACE("(%p) WM_SETFOCUS\n", This);
203 nsIWebBrowserFocus_Activate(This->nscontainer->focus);
204 break;
205 case WM_MOUSEACTIVATE:
206 return MA_ACTIVATE;
209 return DefWindowProcW(hwnd, msg, wParam, lParam);
212 static void register_serverwnd_class(void)
214 static WNDCLASSEXW wndclass = {
215 sizeof(WNDCLASSEXW),
216 CS_DBLCLKS,
217 serverwnd_proc,
218 0, 0, NULL, NULL, NULL, NULL, NULL,
219 wszInternetExplorer_Server,
220 NULL,
222 wndclass.hInstance = hInst;
223 serverwnd_class = RegisterClassExW(&wndclass);
226 static HRESULT activate_window(HTMLDocumentObj *This)
228 IOleInPlaceFrame *pIPFrame;
229 IOleCommandTarget *cmdtrg;
230 IOleInPlaceSiteEx *ipsiteex;
231 RECT posrect, cliprect;
232 OLEINPLACEFRAMEINFO frameinfo;
233 HWND parent_hwnd;
234 HRESULT hres;
236 if(!serverwnd_class)
237 register_serverwnd_class();
239 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
240 if(hres != S_OK) {
241 WARN("CanInPlaceActivate returned: %08x\n", hres);
242 return FAILED(hres) ? hres : E_FAIL;
245 frameinfo.cb = sizeof(OLEINPLACEFRAMEINFO);
246 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &This->ip_window,
247 &posrect, &cliprect, &frameinfo);
248 if(FAILED(hres)) {
249 WARN("GetWindowContext failed: %08x\n", hres);
250 return hres;
253 TRACE("got window context: %p %p %s %s {%d %x %p %p %d}\n",
254 pIPFrame, This->ip_window, wine_dbgstr_rect(&posrect), wine_dbgstr_rect(&cliprect),
255 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
257 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
258 if(FAILED(hres)) {
259 WARN("GetWindow failed: %08x\n", hres);
260 return hres;
263 TRACE("got parent window %p\n", parent_hwnd);
265 if(This->hwnd) {
266 if(GetParent(This->hwnd) != parent_hwnd)
267 SetParent(This->hwnd, parent_hwnd);
268 SetWindowPos(This->hwnd, HWND_TOP,
269 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
270 SWP_NOACTIVATE | SWP_SHOWWINDOW);
271 }else {
272 CreateWindowExW(0, wszInternetExplorer_Server, NULL,
273 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
274 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
275 parent_hwnd, NULL, hInst, This);
277 TRACE("Created window %p\n", This->hwnd);
279 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
280 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
281 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
283 /* NOTE:
284 * Windows implementation calls:
285 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
287 SetTimer(This->hwnd, TIMER_ID, 100, NULL);
290 if(This->nscontainer)
291 activate_gecko(This->nscontainer);
293 This->in_place_active = TRUE;
294 hres = IOleInPlaceSite_QueryInterface(This->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex);
295 if(SUCCEEDED(hres)) {
296 BOOL redraw = FALSE;
298 hres = IOleInPlaceSiteEx_OnInPlaceActivateEx(ipsiteex, &redraw, 0);
299 IOleInPlaceSiteEx_Release(ipsiteex);
300 if(redraw)
301 FIXME("unsupported redraw\n");
302 }else{
303 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
305 if(FAILED(hres)) {
306 WARN("OnInPlaceActivate failed: %08x\n", hres);
307 This->in_place_active = FALSE;
308 return hres;
311 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
312 if(SUCCEEDED(hres)) {
313 VARIANT var;
315 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
317 V_VT(&var) = VT_I4;
318 V_I4(&var) = 0;
319 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
320 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
321 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS,
322 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
324 IOleCommandTarget_Release(cmdtrg);
327 if(This->frame)
328 IOleInPlaceFrame_Release(This->frame);
329 This->frame = pIPFrame;
331 if(!This->request_uiactivate) {
332 hres = IOleInPlaceSite_QueryInterface(This->ipsite, &IID_IOleInPlaceSiteEx, (void**)&ipsiteex);
333 if(SUCCEEDED(hres)) {
334 IOleInPlaceSiteEx_RequestUIActivate(ipsiteex);
335 IOleInPlaceSiteEx_Release(ipsiteex);
339 This->window_active = TRUE;
341 return S_OK;
344 static LRESULT WINAPI tooltips_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
346 tooltip_data *data = GetPropW(hwnd, wszTooltipData);
348 TRACE("%d %p\n", msg, data);
350 if(msg == TTM_WINDOWFROMPOINT) {
351 RECT rect;
352 POINT *pt = (POINT*)lParam;
354 TRACE("TTM_WINDOWFROMPOINT (%d,%d)\n", pt->x, pt->y);
356 GetWindowRect(data->doc->hwnd, &rect);
358 if(rect.left <= pt->x && pt->x <= rect.right
359 && rect.top <= pt->y && pt->y <= rect.bottom)
360 return (LPARAM)data->doc->hwnd;
363 return CallWindowProcW(data->proc, hwnd, msg, wParam, lParam);
366 static void create_tooltips_window(HTMLDocumentObj *This)
368 tooltip_data *data = heap_alloc(sizeof(*data));
370 This->tooltips_hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, TTS_NOPREFIX | WS_POPUP,
371 CW_USEDEFAULT, CW_USEDEFAULT, 10, 10, This->hwnd, NULL, hInst, NULL);
373 data->doc = This;
374 data->proc = (WNDPROC)GetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC);
376 SetPropW(This->tooltips_hwnd, wszTooltipData, data);
378 SetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC, (LONG_PTR)tooltips_proc);
380 SetWindowPos(This->tooltips_hwnd, HWND_TOPMOST,0, 0, 0, 0,
381 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
385 void show_tooltip(HTMLDocumentObj *This, DWORD x, DWORD y, LPCWSTR text)
387 TTTOOLINFOW toolinfo = {
388 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
389 {x>2 ? x-2 : 0, y>0 ? y-2 : 0, x+2, y+2}, /* FIXME */
390 NULL, (LPWSTR)text, 0};
391 MSG msg = {This->hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x,y), 0, {x,y}};
393 TRACE("(%p)->(%d %d %s)\n", This, x, y, debugstr_w(text));
395 if(!This->tooltips_hwnd)
396 create_tooltips_window(This);
398 SendMessageW(This->tooltips_hwnd, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo);
399 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, TRUE, 0);
400 SendMessageW(This->tooltips_hwnd, TTM_RELAYEVENT, 0, (LPARAM)&msg);
403 void hide_tooltip(HTMLDocumentObj *This)
405 TTTOOLINFOW toolinfo = {
406 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
407 {0,0,0,0}, NULL, NULL, 0};
409 TRACE("(%p)\n", This);
411 SendMessageW(This->tooltips_hwnd, TTM_DELTOOLW, 0, (LPARAM)&toolinfo);
412 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, FALSE, 0);
415 HRESULT call_set_active_object(IOleInPlaceUIWindow *window, IOleInPlaceActiveObject *act_obj)
417 static WCHAR html_documentW[30];
419 if(act_obj && !html_documentW[0]) {
420 LoadStringW(hInst, IDS_HTMLDOCUMENT, html_documentW,
421 sizeof(html_documentW)/sizeof(WCHAR));
424 return IOleInPlaceUIWindow_SetActiveObject(window, act_obj, act_obj ? html_documentW : NULL);
427 /**********************************************************
428 * IOleDocumentView implementation
431 static inline HTMLDocument *impl_from_IOleDocumentView(IOleDocumentView *iface)
433 return CONTAINING_RECORD(iface, HTMLDocument, IOleDocumentView_iface);
436 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
438 HTMLDocument *This = impl_from_IOleDocumentView(iface);
439 return htmldoc_query_interface(This, riid, ppvObject);
442 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
444 HTMLDocument *This = impl_from_IOleDocumentView(iface);
445 return htmldoc_addref(This);
448 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
450 HTMLDocument *This = impl_from_IOleDocumentView(iface);
451 return htmldoc_release(This);
454 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
456 HTMLDocument *This = impl_from_IOleDocumentView(iface);
457 TRACE("(%p)->(%p)\n", This, pIPSite);
459 if(pIPSite)
460 IOleInPlaceSite_AddRef(pIPSite);
462 if(This->doc_obj->ipsite)
463 IOleInPlaceSite_Release(This->doc_obj->ipsite);
465 This->doc_obj->ipsite = pIPSite;
466 This->doc_obj->request_uiactivate = TRUE;
467 return S_OK;
470 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
472 HTMLDocument *This = impl_from_IOleDocumentView(iface);
473 TRACE("(%p)->(%p)\n", This, ppIPSite);
475 if(!ppIPSite)
476 return E_INVALIDARG;
478 if(This->doc_obj->ipsite)
479 IOleInPlaceSite_AddRef(This->doc_obj->ipsite);
481 *ppIPSite = This->doc_obj->ipsite;
482 return S_OK;
485 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
487 HTMLDocument *This = impl_from_IOleDocumentView(iface);
488 TRACE("(%p)->(%p)\n", This, ppunk);
490 if(!ppunk)
491 return E_INVALIDARG;
493 htmldoc_addref(This);
494 *ppunk = (IUnknown*)&This->IHTMLDocument2_iface;
495 return S_OK;
498 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
500 HTMLDocument *This = impl_from_IOleDocumentView(iface);
501 RECT rect;
503 TRACE("(%p)->(%p)\n", This, prcView);
505 if(!prcView)
506 return E_INVALIDARG;
508 if(This->doc_obj->hwnd) {
509 GetClientRect(This->doc_obj->hwnd, &rect);
510 if(!EqualRect(prcView, &rect)) {
511 InvalidateRect(This->doc_obj->hwnd, NULL, TRUE);
512 SetWindowPos(This->doc_obj->hwnd, NULL, prcView->left, prcView->top, prcView->right,
513 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
517 return S_OK;
520 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
522 HTMLDocument *This = impl_from_IOleDocumentView(iface);
524 TRACE("(%p)->(%p)\n", This, prcView);
526 if(!prcView)
527 return E_INVALIDARG;
529 GetClientRect(This->doc_obj->hwnd, prcView);
530 return S_OK;
533 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
534 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
536 HTMLDocument *This = impl_from_IOleDocumentView(iface);
537 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
538 return E_NOTIMPL;
541 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
543 HTMLDocument *This = impl_from_IOleDocumentView(iface);
544 HRESULT hres;
546 TRACE("(%p)->(%x)\n", This, fShow);
548 if(fShow) {
549 if(!This->doc_obj->ui_active) {
550 hres = activate_window(This->doc_obj);
551 if(FAILED(hres))
552 return hres;
554 update_doc(This, UPDATE_UI);
555 ShowWindow(This->doc_obj->hwnd, SW_SHOW);
556 }else {
557 ShowWindow(This->doc_obj->hwnd, SW_HIDE);
559 if(This->doc_obj->in_place_active)
560 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->IOleInPlaceObjectWindowless_iface);
562 if(This->doc_obj->ip_window) {
563 IOleInPlaceUIWindow_Release(This->doc_obj->ip_window);
564 This->doc_obj->ip_window = NULL;
568 return S_OK;
571 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
573 HTMLDocument *This = impl_from_IOleDocumentView(iface);
574 HRESULT hres;
576 TRACE("(%p)->(%x)\n", This, fUIActivate);
578 if(!This->doc_obj->ipsite) {
579 IOleClientSite *cs = This->doc_obj->client;
580 IOleInPlaceSite *ips;
582 if(!cs) {
583 WARN("this->ipsite = NULL\n");
584 return E_UNEXPECTED;
587 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteWindowless, (void**)&ips);
588 if(SUCCEEDED(hres))
589 This->doc_obj->ipsite = ips;
590 else {
591 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSiteEx, (void**)&ips);
592 if(SUCCEEDED(hres))
593 This->doc_obj->ipsite = ips;
594 else {
595 hres = IOleClientSite_QueryInterface(cs, &IID_IOleInPlaceSite, (void**)&ips);
596 if(SUCCEEDED(hres))
597 This->doc_obj->ipsite = ips;
598 else {
599 WARN("this->ipsite = NULL\n");
600 return E_NOINTERFACE;
605 IOleInPlaceSite_AddRef(This->doc_obj->ipsite);
606 This->doc_obj->request_uiactivate = FALSE;
607 HTMLDocument_LockContainer(This->doc_obj, TRUE);
610 if(fUIActivate) {
611 RECT rcBorderWidths;
613 if(This->doc_obj->ui_active)
614 return S_OK;
616 if(!This->doc_obj->window_active) {
617 hres = activate_window(This->doc_obj);
618 if(FAILED(hres))
619 return hres;
622 This->doc_obj->focus = TRUE;
623 if(This->doc_obj->nscontainer)
624 nsIWebBrowserFocus_Activate(This->doc_obj->nscontainer->focus);
625 notif_focus(This->doc_obj);
627 update_doc(This, UPDATE_UI);
629 hres = IOleInPlaceSite_OnUIActivate(This->doc_obj->ipsite);
630 if(SUCCEEDED(hres)) {
631 call_set_active_object((IOleInPlaceUIWindow*)This->doc_obj->frame,
632 &This->IOleInPlaceActiveObject_iface);
633 }else {
634 FIXME("OnUIActivate failed: %08x\n", hres);
635 IOleInPlaceFrame_Release(This->doc_obj->frame);
636 This->doc_obj->frame = NULL;
637 This->doc_obj->ui_active = FALSE;
638 return hres;
641 if(This->doc_obj->hostui) {
642 hres = IDocHostUIHandler_ShowUI(This->doc_obj->hostui,
643 This->doc_obj->usermode == EDITMODE ? DOCHOSTUITYPE_AUTHOR : DOCHOSTUITYPE_BROWSE,
644 &This->IOleInPlaceActiveObject_iface, &This->IOleCommandTarget_iface,
645 This->doc_obj->frame, This->doc_obj->ip_window);
646 if(FAILED(hres))
647 IDocHostUIHandler_HideUI(This->doc_obj->hostui);
650 if(This->doc_obj->ip_window)
651 call_set_active_object(This->doc_obj->ip_window, &This->IOleInPlaceActiveObject_iface);
653 SetRectEmpty(&rcBorderWidths);
654 IOleInPlaceFrame_SetBorderSpace(This->doc_obj->frame, &rcBorderWidths);
656 This->doc_obj->ui_active = TRUE;
657 }else {
658 This->doc_obj->focus = FALSE;
659 nsIWebBrowserFocus_Deactivate(This->doc_obj->nscontainer->focus);
660 if(This->doc_obj->ui_active) {
661 This->doc_obj->ui_active = FALSE;
662 if(This->doc_obj->ip_window)
663 call_set_active_object(This->doc_obj->ip_window, NULL);
664 if(This->doc_obj->frame)
665 call_set_active_object((IOleInPlaceUIWindow*)This->doc_obj->frame, NULL);
666 if(This->doc_obj->hostui)
667 IDocHostUIHandler_HideUI(This->doc_obj->hostui);
668 if(This->doc_obj->ipsite)
669 IOleInPlaceSite_OnUIDeactivate(This->doc_obj->ipsite, FALSE);
672 return S_OK;
675 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
677 HTMLDocument *This = impl_from_IOleDocumentView(iface);
678 FIXME("(%p)\n", This);
679 return E_NOTIMPL;
682 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
684 HTMLDocument *This = impl_from_IOleDocumentView(iface);
685 TRACE("(%p)->(%x)\n", This, dwReserved);
687 if(dwReserved)
688 WARN("dwReserved = %d\n", dwReserved);
690 /* NOTE:
691 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
692 * QueryInterface(IID_IOleControlSite) and KillTimer
695 IOleDocumentView_Show(iface, FALSE);
697 return S_OK;
700 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, IStream *pstm)
702 HTMLDocument *This = impl_from_IOleDocumentView(iface);
703 FIXME("(%p)->(%p)\n", This, pstm);
704 return E_NOTIMPL;
707 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, IStream *pstm)
709 HTMLDocument *This = impl_from_IOleDocumentView(iface);
710 FIXME("(%p)->(%p)\n", This, pstm);
711 return E_NOTIMPL;
714 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
715 IOleDocumentView **ppViewNew)
717 HTMLDocument *This = impl_from_IOleDocumentView(iface);
718 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
719 return E_NOTIMPL;
722 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
723 OleDocumentView_QueryInterface,
724 OleDocumentView_AddRef,
725 OleDocumentView_Release,
726 OleDocumentView_SetInPlaceSite,
727 OleDocumentView_GetInPlaceSite,
728 OleDocumentView_GetDocument,
729 OleDocumentView_SetRect,
730 OleDocumentView_GetRect,
731 OleDocumentView_SetRectComplex,
732 OleDocumentView_Show,
733 OleDocumentView_UIActivate,
734 OleDocumentView_Open,
735 OleDocumentView_CloseView,
736 OleDocumentView_SaveViewState,
737 OleDocumentView_ApplyViewState,
738 OleDocumentView_Clone
741 /**********************************************************
742 * IViewObject implementation
745 static inline HTMLDocument *impl_from_IViewObjectEx(IViewObjectEx *iface)
747 return CONTAINING_RECORD(iface, HTMLDocument, IViewObjectEx_iface);
750 static HRESULT WINAPI ViewObject_QueryInterface(IViewObjectEx *iface, REFIID riid, void **ppv)
752 HTMLDocument *This = impl_from_IViewObjectEx(iface);
753 return htmldoc_query_interface(This, riid, ppv);
756 static ULONG WINAPI ViewObject_AddRef(IViewObjectEx *iface)
758 HTMLDocument *This = impl_from_IViewObjectEx(iface);
759 return htmldoc_addref(This);
762 static ULONG WINAPI ViewObject_Release(IViewObjectEx *iface)
764 HTMLDocument *This = impl_from_IViewObjectEx(iface);
765 return htmldoc_release(This);
768 static HRESULT WINAPI ViewObject_Draw(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
769 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
770 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
772 HTMLDocument *This = impl_from_IViewObjectEx(iface);
773 FIXME("(%p)->(%d %d %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
774 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
775 return E_NOTIMPL;
778 static HRESULT WINAPI ViewObject_GetColorSet(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
779 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
781 HTMLDocument *This = impl_from_IViewObjectEx(iface);
782 FIXME("(%p)->(%d %d %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
783 return E_NOTIMPL;
786 static HRESULT WINAPI ViewObject_Freeze(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex,
787 void *pvAspect, DWORD *pdwFreeze)
789 HTMLDocument *This = impl_from_IViewObjectEx(iface);
790 FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
791 return E_NOTIMPL;
794 static HRESULT WINAPI ViewObject_Unfreeze(IViewObjectEx *iface, DWORD dwFreeze)
796 HTMLDocument *This = impl_from_IViewObjectEx(iface);
797 FIXME("(%p)->(%d)\n", This, dwFreeze);
798 return E_NOTIMPL;
801 static HRESULT WINAPI ViewObject_SetAdvise(IViewObjectEx *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
803 HTMLDocument *This = impl_from_IViewObjectEx(iface);
805 TRACE("(%p)->(%d %d %p)\n", This, aspects, advf, pAdvSink);
807 if(aspects != DVASPECT_CONTENT || advf != ADVF_PRIMEFIRST)
808 FIXME("unsupported arguments\n");
810 if(This->doc_obj->view_sink)
811 IAdviseSink_Release(This->doc_obj->view_sink);
812 if(pAdvSink)
813 IAdviseSink_AddRef(pAdvSink);
815 This->doc_obj->view_sink = pAdvSink;
816 return S_OK;
819 static HRESULT WINAPI ViewObject_GetAdvise(IViewObjectEx *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
821 HTMLDocument *This = impl_from_IViewObjectEx(iface);
822 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
823 return E_NOTIMPL;
826 static HRESULT WINAPI ViewObject_GetExtent(IViewObjectEx *iface, DWORD dwDrawAspect, LONG lindex,
827 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
829 HTMLDocument *This = impl_from_IViewObjectEx(iface);
830 FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
831 return E_NOTIMPL;
834 static HRESULT WINAPI ViewObject_GetRect(IViewObjectEx *iface, DWORD dwAspect, LPRECTL pRect)
836 HTMLDocument *This = impl_from_IViewObjectEx(iface);
837 FIXME("(%p)->(%d %p)\n", This, dwAspect, pRect);
838 return E_NOTIMPL;
841 static HRESULT WINAPI ViewObject_GetViewStatus(IViewObjectEx *iface, DWORD *pdwStatus)
843 HTMLDocument *This = impl_from_IViewObjectEx(iface);
844 FIXME("(%p)->(%p)\n", This, pdwStatus);
845 return E_NOTIMPL;
848 static HRESULT WINAPI ViewObject_QueryHitPoint(IViewObjectEx* iface, DWORD dwAspect,
849 LPCRECT pRectBounds, POINT ptlLoc, LONG lCloseHint, DWORD *pHitResult)
851 HTMLDocument *This = impl_from_IViewObjectEx(iface);
852 FIXME("(%p)->(%d %p (%d %d) %d %p)\n", This, dwAspect, pRectBounds, ptlLoc.x,
853 ptlLoc.y, lCloseHint, pHitResult);
854 return E_NOTIMPL;
857 static HRESULT WINAPI ViewObject_QueryHitRect(IViewObjectEx *iface, DWORD dwAspect,
858 LPCRECT pRectBounds, LPCRECT pRectLoc, LONG lCloseHint, DWORD *pHitResult)
860 HTMLDocument *This = impl_from_IViewObjectEx(iface);
861 FIXME("(%p)->(%d %p %p %d %p)\n", This, dwAspect, pRectBounds, pRectLoc, lCloseHint, pHitResult);
862 return E_NOTIMPL;
865 static HRESULT WINAPI ViewObject_GetNaturalExtent(IViewObjectEx *iface, DWORD dwAspect, LONG lindex,
866 DVTARGETDEVICE *ptd, HDC hicTargetDev, DVEXTENTINFO *pExtentInfo, LPSIZEL pSizel)
868 HTMLDocument *This = impl_from_IViewObjectEx(iface);
869 FIXME("(%p)->(%d %d %p %p %p %p\n", This, dwAspect,lindex, ptd,
870 hicTargetDev, pExtentInfo, pSizel);
871 return E_NOTIMPL;
874 static const IViewObjectExVtbl ViewObjectVtbl = {
875 ViewObject_QueryInterface,
876 ViewObject_AddRef,
877 ViewObject_Release,
878 ViewObject_Draw,
879 ViewObject_GetColorSet,
880 ViewObject_Freeze,
881 ViewObject_Unfreeze,
882 ViewObject_SetAdvise,
883 ViewObject_GetAdvise,
884 ViewObject_GetExtent,
885 ViewObject_GetRect,
886 ViewObject_GetViewStatus,
887 ViewObject_QueryHitPoint,
888 ViewObject_QueryHitRect,
889 ViewObject_GetNaturalExtent
892 void HTMLDocument_View_Init(HTMLDocument *This)
894 This->IOleDocumentView_iface.lpVtbl = &OleDocumentViewVtbl;
895 This->IViewObjectEx_iface.lpVtbl = &ViewObjectVtbl;
898 static inline HTMLDocumentObj *impl_from_IWindowForBindingUI(IWindowForBindingUI *iface)
900 return CONTAINING_RECORD(iface, HTMLDocumentObj, IWindowForBindingUI_iface);
903 static HRESULT WINAPI WindowForBindingUI_QueryInterface(IWindowForBindingUI *iface, REFIID riid, void **ppv)
905 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
907 if(IsEqualGUID(&IID_IUnknown, riid)) {
908 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
909 *ppv = &This->IWindowForBindingUI_iface;
910 }else if(IsEqualGUID(&IID_IWindowForBindingUI, riid)) {
911 TRACE("(%p)->(IID_IWindowForBindingUI %p)\n", This, ppv);
912 *ppv = &This->IWindowForBindingUI_iface;
913 }else {
914 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
915 *ppv = NULL;
916 return E_NOINTERFACE;
919 IUnknown_AddRef((IUnknown*)*ppv);
920 return S_OK;
923 static ULONG WINAPI WindowForBindingUI_AddRef(IWindowForBindingUI *iface)
925 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
926 return htmldoc_addref(&This->basedoc);
929 static ULONG WINAPI WindowForBindingUI_Release(IWindowForBindingUI *iface)
931 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
932 return htmldoc_release(&This->basedoc);
935 static HRESULT WINAPI WindowForBindingUI_GetWindow(IWindowForBindingUI *iface, REFGUID rguidReason, HWND *phwnd)
937 HTMLDocumentObj *This = impl_from_IWindowForBindingUI(iface);
939 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(rguidReason), phwnd);
941 *phwnd = This->hwnd;
942 return S_OK;
945 static const IWindowForBindingUIVtbl WindowForBindingUIVtbl = {
946 WindowForBindingUI_QueryInterface,
947 WindowForBindingUI_AddRef,
948 WindowForBindingUI_Release,
949 WindowForBindingUI_GetWindow
952 void init_binding_ui(HTMLDocumentObj *doc)
954 doc->IWindowForBindingUI_iface.lpVtbl = &WindowForBindingUIVtbl;