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
34 #include "wine/debug.h"
36 #include "mshtml_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
40 static const WCHAR wszInternetExplorer_Server[] =
41 {'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','_','S','e','r','v','e','r',0};
43 static const WCHAR wszTooltipData[] = {'t','o','o','l','t','i','p','_','d','a','t','a',0};
45 static ATOM serverwnd_class = 0;
52 static void paint_document(HTMLDocument *This)
58 GetClientRect(This->hwnd, &rect);
60 hdc = BeginPaint(This->hwnd, &ps);
62 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER)))
63 DrawEdge(hdc, &rect, EDGE_SUNKEN, BF_RECT|BF_ADJUST);
65 if(!This->nscontainer) {
66 WCHAR wszHTMLDisabled[100];
69 LoadStringW(hInst, IDS_HTMLDISABLED, wszHTMLDisabled, sizeof(wszHTMLDisabled)/sizeof(WCHAR));
71 font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
73 SelectObject(hdc, font);
74 SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW));
76 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
77 DrawTextW(hdc, wszHTMLDisabled,-1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
82 EndPaint(This->hwnd, &ps);
85 static void activate_gecko(HTMLDocument *This)
87 TRACE("(%p) %p\n", This, This->nscontainer->window);
89 SetParent(This->nscontainer->hwnd, This->hwnd);
90 ShowWindow(This->nscontainer->hwnd, SW_SHOW);
92 nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
93 nsIBaseWindow_SetEnabled(This->nscontainer->window, TRUE);
94 nsIWebBrowserFocus_Activate(This->nscontainer->focus);
97 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
101 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
103 if(msg == WM_CREATE) {
104 This = *(HTMLDocument**)lParam;
105 SetPropW(hwnd, wszTHIS, This);
107 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
113 if(This->nscontainer)
114 activate_gecko(This);
117 paint_document(This);
120 TRACE("(%p)->(WM_SIZE)\n", This);
121 if(This->nscontainer) {
124 if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER))) {
125 ew = GetSystemMetrics(SM_CXEDGE);
126 eh = GetSystemMetrics(SM_CYEDGE);
129 SetWindowPos(This->nscontainer->hwnd, NULL, ew, eh,
130 LOWORD(lParam) - 2*ew, HIWORD(lParam) - 2*eh,
131 SWP_NOZORDER | SWP_NOACTIVATE);
135 return DefWindowProcW(hwnd, msg, wParam, lParam);
138 static void register_serverwnd_class(void)
140 static WNDCLASSEXW wndclass = {
144 0, 0, NULL, NULL, NULL, NULL, NULL,
145 wszInternetExplorer_Server,
148 wndclass.hInstance = hInst;
149 serverwnd_class = RegisterClassExW(&wndclass);
152 static HRESULT activate_window(HTMLDocument *This)
154 IOleInPlaceUIWindow *pIPWnd;
155 IOleInPlaceFrame *pIPFrame;
156 IOleCommandTarget *cmdtrg;
157 RECT posrect, cliprect;
158 OLEINPLACEFRAMEINFO frameinfo;
163 register_serverwnd_class();
165 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
167 WARN("CanInPlaceActivate returned: %08x\n", hres);
168 return FAILED(hres) ? hres : E_FAIL;
171 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd, &posrect, &cliprect, &frameinfo);
173 WARN("GetWindowContext failed: %08x\n", hres);
178 IOleInPlaceUIWindow_Release(pIPWnd);
179 TRACE("got window context: %p %p {%d %d %d %d} {%d %d %d %d} {%d %x %p %p %d}\n",
180 pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
181 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
182 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
184 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
186 WARN("GetWindow failed: %08x\n", hres);
190 TRACE("got parent window %p\n", parent_hwnd);
193 if(GetParent(This->hwnd) != parent_hwnd)
194 SetParent(This->hwnd, parent_hwnd);
195 SetWindowPos(This->hwnd, HWND_TOP,
196 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
197 SWP_NOACTIVATE | SWP_SHOWWINDOW);
199 CreateWindowExW(0, wszInternetExplorer_Server, NULL,
200 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
201 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
202 parent_hwnd, NULL, hInst, This);
204 TRACE("Created window %p\n", This->hwnd);
206 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
207 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
208 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
209 SetFocus(This->hwnd);
212 * Windows implementation calls:
213 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
214 * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
218 This->in_place_active = TRUE;
219 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
221 WARN("OnInPlaceActivate failed: %08x\n", hres);
222 This->in_place_active = FALSE;
226 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
227 if(SUCCEEDED(hres)) {
230 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
234 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
235 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
236 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS,
237 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
239 IOleCommandTarget_Release(cmdtrg);
243 IOleInPlaceFrame_Release(This->frame);
244 This->frame = pIPFrame;
246 This->window_active = TRUE;
251 static LRESULT tooltips_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
253 tooltip_data *data = GetPropW(hwnd, wszTooltipData);
255 TRACE("%d %p\n", msg, data);
257 if(msg == TTM_WINDOWFROMPOINT) {
259 POINT *pt = (POINT*)lParam;
261 TRACE("TTM_WINDOWFROMPOINT (%d,%d)\n", pt->x, pt->y);
263 GetWindowRect(data->doc->hwnd, &rect);
265 if(rect.left <= pt->x && pt->x <= rect.right
266 && rect.top <= pt->y && pt->y <= rect.bottom)
267 return (LPARAM)data->doc->hwnd;
270 return CallWindowProcW(data->proc, hwnd, msg, wParam, lParam);
273 static void create_tooltips_window(HTMLDocument *This)
275 tooltip_data *data = mshtml_alloc(sizeof(*data));
277 This->tooltips_hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, TTS_NOPREFIX | WS_POPUP,
278 CW_USEDEFAULT, CW_USEDEFAULT, 10, 10, This->hwnd, NULL, hInst, NULL);
281 data->proc = (WNDPROC)GetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC);
283 SetPropW(This->tooltips_hwnd, wszTooltipData, data);
285 SetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC, (LONG_PTR)tooltips_proc);
287 SetWindowPos(This->tooltips_hwnd, HWND_TOPMOST,0, 0, 0, 0,
288 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
292 void show_tooltip(HTMLDocument *This, DWORD x, DWORD y, LPCWSTR text)
294 TTTOOLINFOW toolinfo = {
295 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
296 {x>2 ? x-2 : 0, y>0 ? y-2 : 0, x+2, y+2}, /* FIXME */
297 NULL, (LPWSTR)text, 0};
298 MSG msg = {This->hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x,y), 0, {x,y}};
300 TRACE("(%p)->(%d %d %s)\n", This, x, y, debugstr_w(text));
302 if(!This->tooltips_hwnd)
303 create_tooltips_window(This);
305 SendMessageW(This->tooltips_hwnd, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo);
306 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, TRUE, 0);
307 SendMessageW(This->tooltips_hwnd, TTM_RELAYEVENT, 0, (LPARAM)&msg);
310 void hide_tooltip(HTMLDocument *This)
312 TTTOOLINFOW toolinfo = {
313 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
314 {0,0,0,0}, NULL, NULL, 0};
316 TRACE("(%p)\n", This);
318 SendMessageW(This->tooltips_hwnd, TTM_DELTOOLW, 0, (LPARAM)&toolinfo);
319 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, FALSE, 0);
322 /**********************************************************
323 * IOleDocumentView implementation
326 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
328 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
330 HTMLDocument *This = DOCVIEW_THIS(iface);
331 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
334 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
336 HTMLDocument *This = DOCVIEW_THIS(iface);
337 return IHTMLDocument2_AddRef(HTMLDOC(This));
340 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
342 HTMLDocument *This = DOCVIEW_THIS(iface);
343 return IHTMLDocument2_Release(HTMLDOC(This));
346 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
348 HTMLDocument *This = DOCVIEW_THIS(iface);
349 TRACE("(%p)->(%p)\n", This, pIPSite);
352 IOleInPlaceSite_AddRef(pIPSite);
355 IOleInPlaceSite_Release(This->ipsite);
357 This->ipsite = pIPSite;
361 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
363 HTMLDocument *This = DOCVIEW_THIS(iface);
364 TRACE("(%p)->(%p)\n", This, ppIPSite);
370 IOleInPlaceSite_AddRef(This->ipsite);
372 *ppIPSite = This->ipsite;
376 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
378 HTMLDocument *This = DOCVIEW_THIS(iface);
379 TRACE("(%p)->(%p)\n", This, ppunk);
384 IHTMLDocument2_AddRef(HTMLDOC(This));
385 *ppunk = (IUnknown*)HTMLDOC(This);
389 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
391 HTMLDocument *This = DOCVIEW_THIS(iface);
394 TRACE("(%p)->(%p)\n", This, prcView);
400 GetClientRect(This->hwnd, &rect);
401 if(memcmp(prcView, &rect, sizeof(RECT))) {
402 InvalidateRect(This->hwnd,NULL,TRUE);
403 SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
404 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
411 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
413 HTMLDocument *This = DOCVIEW_THIS(iface);
415 TRACE("(%p)->(%p)\n", This, prcView);
420 GetClientRect(This->hwnd, prcView);
424 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
425 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
427 HTMLDocument *This = DOCVIEW_THIS(iface);
428 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
432 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
434 HTMLDocument *This = DOCVIEW_THIS(iface);
437 TRACE("(%p)->(%x)\n", This, fShow);
440 if(!This->ui_active) {
441 hres = activate_window(This);
445 ShowWindow(This->hwnd, SW_SHOW);
447 ShowWindow(This->hwnd, SW_HIDE);
453 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
455 HTMLDocument *This = DOCVIEW_THIS(iface);
458 TRACE("(%p)->(%x)\n", This, fUIActivate);
461 FIXME("This->ipsite = NULL\n");
469 if(!This->window_active) {
470 hres = activate_window(This);
475 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
476 if(SUCCEEDED(hres)) {
477 OLECHAR wszHTMLDocument[30];
478 LoadStringW(hInst, IDS_HTMLDOCUMENT, wszHTMLDocument,
479 sizeof(wszHTMLDocument)/sizeof(WCHAR));
480 IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTMLDocument);
482 FIXME("OnUIActivate failed: %08x\n", hres);
483 IOleInPlaceFrame_Release(This->frame);
485 This->ui_active = FALSE;
489 hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
492 IDocHostUIHandler_HideUI(This->hostui);
494 This->ui_active = TRUE;
496 This->window_active = FALSE;
497 if(This->ui_active) {
498 This->ui_active = FALSE;
500 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
502 IDocHostUIHandler_HideUI(This->hostui);
504 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
510 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
512 HTMLDocument *This = DOCVIEW_THIS(iface);
513 FIXME("(%p)\n", This);
517 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
519 HTMLDocument *This = DOCVIEW_THIS(iface);
520 TRACE("(%p)->(%x)\n", This, dwReserved);
523 WARN("dwReserved = %d\n", dwReserved);
526 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
527 * QueryInterface(IID_IOleControlSite) and KillTimer
530 IOleDocumentView_Show(iface, FALSE);
535 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
537 HTMLDocument *This = DOCVIEW_THIS(iface);
538 FIXME("(%p)->(%p)\n", This, pstm);
542 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
544 HTMLDocument *This = DOCVIEW_THIS(iface);
545 FIXME("(%p)->(%p)\n", This, pstm);
549 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
550 IOleDocumentView **ppViewNew)
552 HTMLDocument *This = DOCVIEW_THIS(iface);
553 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
559 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
560 OleDocumentView_QueryInterface,
561 OleDocumentView_AddRef,
562 OleDocumentView_Release,
563 OleDocumentView_SetInPlaceSite,
564 OleDocumentView_GetInPlaceSite,
565 OleDocumentView_GetDocument,
566 OleDocumentView_SetRect,
567 OleDocumentView_GetRect,
568 OleDocumentView_SetRectComplex,
569 OleDocumentView_Show,
570 OleDocumentView_UIActivate,
571 OleDocumentView_Open,
572 OleDocumentView_CloseView,
573 OleDocumentView_SaveViewState,
574 OleDocumentView_ApplyViewState,
575 OleDocumentView_Clone
578 /**********************************************************
579 * IViewObject implementation
582 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
584 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
586 HTMLDocument *This = VIEWOBJ_THIS(iface);
587 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
590 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
592 HTMLDocument *This = VIEWOBJ_THIS(iface);
593 return IHTMLDocument2_AddRef(HTMLDOC(This));
596 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
598 HTMLDocument *This = VIEWOBJ_THIS(iface);
599 return IHTMLDocument2_Release(HTMLDOC(This));
602 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
603 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
604 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
606 HTMLDocument *This = VIEWOBJ_THIS(iface);
607 FIXME("(%p)->(%d %d %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
608 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
612 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
613 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
615 HTMLDocument *This = VIEWOBJ_THIS(iface);
616 FIXME("(%p)->(%d %d %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
620 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
621 void *pvAspect, DWORD *pdwFreeze)
623 HTMLDocument *This = VIEWOBJ_THIS(iface);
624 FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
628 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
630 HTMLDocument *This = VIEWOBJ_THIS(iface);
631 FIXME("(%p)->(%d)\n", This, dwFreeze);
635 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
637 HTMLDocument *This = VIEWOBJ_THIS(iface);
638 FIXME("(%p)->(%d %d %p)\n", This, aspects, advf, pAdvSink);
642 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
644 HTMLDocument *This = VIEWOBJ_THIS(iface);
645 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
649 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
650 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
652 HTMLDocument *This = VIEWOBJ_THIS(iface);
653 FIXME("(%p)->(%d %d %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
659 static const IViewObject2Vtbl ViewObjectVtbl = {
660 ViewObject_QueryInterface,
664 ViewObject_GetColorSet,
667 ViewObject_SetAdvise,
668 ViewObject_GetAdvise,
672 void HTMLDocument_View_Init(HTMLDocument *This)
674 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
675 This->lpViewObject2Vtbl = &ViewObjectVtbl;
680 This->tooltips_hwnd = NULL;
682 This->in_place_active = FALSE;
683 This->ui_active = FALSE;
684 This->window_active = FALSE;