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 LRESULT WINAPI hidden_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
55 FIXME("(%p %d %x %lx)\n", hwnd, msg, wParam, lParam);
57 return DefWindowProcW(hwnd, msg, wParam, lParam);
60 static void create_hidden_window(HTMLDocument *This)
62 static ATOM hidden_wnd_class = 0;
63 static const WCHAR wszInternetExplorer_Hidden[] = {'I','n','t','e','r','n','e','t',
64 ' ','E','x','p','l','o','r','e','r','_','H','i','d','d','e','n',0};
66 if(!hidden_wnd_class) {
67 WNDCLASSEXW wndclass = {
68 sizeof(WNDCLASSEXW), 0,
70 0, 0, hInst, NULL, NULL, NULL, NULL,
71 wszInternetExplorer_Hidden,
75 hidden_wnd_class = RegisterClassExW(&wndclass);
78 This->hidden_hwnd = CreateWindowExW(0, wszInternetExplorer_Hidden, NULL, WS_POPUP,
79 0, 0, 0, 0, NULL, NULL, hInst, This);
82 static void paint_disabled(HWND hwnd) {
88 WCHAR wszHTMLDisabled[100];
90 LoadStringW(hInst, IDS_HTMLDISABLED, wszHTMLDisabled, sizeof(wszHTMLDisabled)/sizeof(WCHAR));
92 font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
93 brush = CreateSolidBrush(RGB(255,255,255));
94 GetClientRect(hwnd, &rect);
96 hdc = BeginPaint(hwnd, &ps);
97 SelectObject(hdc, font);
98 SelectObject(hdc, brush);
99 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
100 DrawTextW(hdc, wszHTMLDisabled,-1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
107 static void activate_gecko(HTMLDocument *This)
109 TRACE("(%p) %p\n", This, This->nscontainer->window);
111 SetParent(This->nscontainer->hwnd, This->hwnd);
112 ShowWindow(This->nscontainer->hwnd, SW_SHOW);
114 nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
115 nsIBaseWindow_SetEnabled(This->nscontainer->window, TRUE);
116 nsIWebBrowserFocus_Activate(This->nscontainer->focus);
119 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
123 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
125 if(msg == WM_CREATE) {
126 This = *(HTMLDocument**)lParam;
127 SetPropW(hwnd, wszTHIS, This);
129 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
135 if(This->nscontainer)
136 activate_gecko(This);
139 if(!This->nscontainer)
140 paint_disabled(hwnd);
143 TRACE("(%p)->(WM_SIZE)\n", This);
144 if(This->nscontainer)
145 SetWindowPos(This->nscontainer->hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
146 SWP_NOZORDER | SWP_NOACTIVATE);
149 return DefWindowProcW(hwnd, msg, wParam, lParam);
152 static void register_serverwnd_class(void)
154 static WNDCLASSEXW wndclass = {
158 0, 0, NULL, NULL, NULL, NULL, NULL,
159 wszInternetExplorer_Server,
162 wndclass.hInstance = hInst;
163 serverwnd_class = RegisterClassExW(&wndclass);
166 static HRESULT activate_window(HTMLDocument *This)
168 IOleInPlaceUIWindow *pIPWnd;
169 IOleInPlaceFrame *pIPFrame;
170 IOleCommandTarget *cmdtrg;
171 RECT posrect, cliprect;
172 OLEINPLACEFRAMEINFO frameinfo;
177 register_serverwnd_class();
179 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
181 WARN("CanInPlaceActivate returned: %08lx\n", hres);
182 return FAILED(hres) ? hres : E_FAIL;
185 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd, &posrect, &cliprect, &frameinfo);
187 WARN("GetWindowContext failed: %08lx\n", hres);
192 IOleInPlaceUIWindow_Release(pIPWnd);
193 TRACE("got window context: %p %p {%ld %ld %ld %ld} {%ld %ld %ld %ld} {%d %x %p %p %d}\n",
194 pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
195 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
196 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
198 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
200 WARN("GetWindow failed: %08lx\n", hres);
204 TRACE("got parent window %p\n", parent_hwnd);
207 if(GetParent(This->hwnd) != parent_hwnd)
208 SetParent(This->hwnd, parent_hwnd);
209 SetWindowPos(This->hwnd, HWND_TOP,
210 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
211 SWP_NOACTIVATE | SWP_SHOWWINDOW);
213 CreateWindowExW(0, wszInternetExplorer_Server, NULL,
214 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
215 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
216 parent_hwnd, NULL, hInst, This);
218 TRACE("Created window %p\n", This->hwnd);
220 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
221 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
222 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
223 SetFocus(This->hwnd);
226 * Windows implementation calls:
227 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
228 * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
232 This->in_place_active = TRUE;
233 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
235 WARN("OnInPlaceActivate failed: %08lx\n", hres);
236 This->in_place_active = FALSE;
240 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
241 if(SUCCEEDED(hres)) {
244 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
248 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
249 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
250 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS,
251 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
253 IOleCommandTarget_Release(cmdtrg);
257 IOleInPlaceFrame_Release(This->frame);
258 This->frame = pIPFrame;
260 This->window_active = TRUE;
265 static LRESULT tooltips_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
267 tooltip_data *data = GetPropW(hwnd, wszTooltipData);
269 TRACE("%d %p\n", msg, data);
271 if(msg == TTM_WINDOWFROMPOINT) {
273 POINT *pt = (POINT*)lParam;
275 TRACE("TTM_WINDOWFROMPOINT (%ld,%ld)\n", pt->x, pt->y);
277 GetWindowRect(data->doc->hwnd, &rect);
279 if(rect.left <= pt->x && pt->x <= rect.right
280 && rect.top <= pt->y && pt->y <= rect.bottom)
281 return (LPARAM)data->doc->hwnd;
284 return CallWindowProcW(data->proc, hwnd, msg, wParam, lParam);
287 static void create_tooltips_window(HTMLDocument *This)
289 tooltip_data *data = mshtml_alloc(sizeof(*data));
291 This->tooltips_hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, TTS_NOPREFIX | WS_POPUP,
292 CW_USEDEFAULT, CW_USEDEFAULT, 10, 10, This->hwnd, NULL, hInst, NULL);
295 data->proc = (WNDPROC)GetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC);
297 SetPropW(This->tooltips_hwnd, wszTooltipData, data);
299 SetWindowLongPtrW(This->tooltips_hwnd, GWLP_WNDPROC, (LONG_PTR)tooltips_proc);
301 SetWindowPos(This->tooltips_hwnd, HWND_TOPMOST,0, 0, 0, 0,
302 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
306 void show_tooltip(HTMLDocument *This, DWORD x, DWORD y, LPCWSTR text)
308 TTTOOLINFOW toolinfo = {
309 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
310 {x>2 ? x-2 : 0, y>0 ? y-2 : 0, x+2, y+2}, /* FIXME */
311 NULL, (LPWSTR)text, 0};
312 MSG msg = {This->hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x,y), 0, {x,y}};
314 TRACE("(%p)->(%ld %ld %s)\n", This, x, y, debugstr_w(text));
316 if(!This->tooltips_hwnd)
317 create_tooltips_window(This);
319 SendMessageW(This->tooltips_hwnd, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo);
320 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, TRUE, 0);
321 SendMessageW(This->tooltips_hwnd, TTM_RELAYEVENT, 0, (LPARAM)&msg);
324 void hide_tooltip(HTMLDocument *This)
326 TTTOOLINFOW toolinfo = {
327 sizeof(TTTOOLINFOW), 0, This->hwnd, 0xdeadbeef,
328 {0,0,0,0}, NULL, NULL, 0};
330 TRACE("(%p)\n", This);
332 SendMessageW(This->tooltips_hwnd, TTM_DELTOOLW, 0, (LPARAM)&toolinfo);
333 SendMessageW(This->tooltips_hwnd, TTM_ACTIVATE, FALSE, 0);
336 /**********************************************************
337 * IOleDocumentView implementation
340 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
342 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
344 HTMLDocument *This = DOCVIEW_THIS(iface);
345 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
348 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
350 HTMLDocument *This = DOCVIEW_THIS(iface);
351 return IHTMLDocument2_AddRef(HTMLDOC(This));
354 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
356 HTMLDocument *This = DOCVIEW_THIS(iface);
357 return IHTMLDocument2_Release(HTMLDOC(This));
360 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
362 HTMLDocument *This = DOCVIEW_THIS(iface);
363 TRACE("(%p)->(%p)\n", This, pIPSite);
366 IOleInPlaceSite_AddRef(pIPSite);
369 IOleInPlaceSite_Release(This->ipsite);
371 This->ipsite = pIPSite;
375 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
377 HTMLDocument *This = DOCVIEW_THIS(iface);
378 TRACE("(%p)->(%p)\n", This, ppIPSite);
384 IOleInPlaceSite_AddRef(This->ipsite);
386 *ppIPSite = This->ipsite;
390 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
392 HTMLDocument *This = DOCVIEW_THIS(iface);
393 TRACE("(%p)->(%p)\n", This, ppunk);
398 IHTMLDocument2_AddRef(HTMLDOC(This));
399 *ppunk = (IUnknown*)HTMLDOC(This);
403 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
405 HTMLDocument *This = DOCVIEW_THIS(iface);
408 TRACE("(%p)->(%p)\n", This, prcView);
414 GetClientRect(This->hwnd, &rect);
415 if(memcmp(prcView, &rect, sizeof(RECT))) {
416 InvalidateRect(This->hwnd,NULL,TRUE);
417 SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
418 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
425 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
427 HTMLDocument *This = DOCVIEW_THIS(iface);
429 TRACE("(%p)->(%p)\n", This, prcView);
434 GetClientRect(This->hwnd, prcView);
438 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
439 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
441 HTMLDocument *This = DOCVIEW_THIS(iface);
442 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
446 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
448 HTMLDocument *This = DOCVIEW_THIS(iface);
451 TRACE("(%p)->(%x)\n", This, fShow);
454 if(!This->ui_active) {
455 hres = activate_window(This);
459 ShowWindow(This->hwnd, SW_SHOW);
461 ShowWindow(This->hwnd, SW_HIDE);
467 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
469 HTMLDocument *This = DOCVIEW_THIS(iface);
472 TRACE("(%p)->(%x)\n", This, fUIActivate);
475 FIXME("This->ipsite = NULL\n");
483 if(!This->window_active) {
484 hres = activate_window(This);
489 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
490 if(SUCCEEDED(hres)) {
491 OLECHAR wszHTMLDocument[30];
492 LoadStringW(hInst, IDS_HTMLDOCUMENT, wszHTMLDocument,
493 sizeof(wszHTMLDocument)/sizeof(WCHAR));
494 IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTMLDocument);
496 FIXME("OnUIActivate failed: %08lx\n", hres);
497 IOleInPlaceFrame_Release(This->frame);
499 This->ui_active = FALSE;
503 hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
506 IDocHostUIHandler_HideUI(This->hostui);
508 This->ui_active = TRUE;
510 This->window_active = FALSE;
511 if(This->ui_active) {
512 This->ui_active = FALSE;
514 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
516 IDocHostUIHandler_HideUI(This->hostui);
518 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
524 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
526 HTMLDocument *This = DOCVIEW_THIS(iface);
527 FIXME("(%p)\n", This);
531 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
533 HTMLDocument *This = DOCVIEW_THIS(iface);
534 TRACE("(%p)->(%lx)\n", This, dwReserved);
537 WARN("dwReserved = %ld\n", dwReserved);
540 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
541 * QueryInterface(IID_IOleControlSite) and KillTimer
544 IOleDocumentView_Show(iface, FALSE);
549 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
551 HTMLDocument *This = DOCVIEW_THIS(iface);
552 FIXME("(%p)->(%p)\n", This, pstm);
556 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
558 HTMLDocument *This = DOCVIEW_THIS(iface);
559 FIXME("(%p)->(%p)\n", This, pstm);
563 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
564 IOleDocumentView **ppViewNew)
566 HTMLDocument *This = DOCVIEW_THIS(iface);
567 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
573 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
574 OleDocumentView_QueryInterface,
575 OleDocumentView_AddRef,
576 OleDocumentView_Release,
577 OleDocumentView_SetInPlaceSite,
578 OleDocumentView_GetInPlaceSite,
579 OleDocumentView_GetDocument,
580 OleDocumentView_SetRect,
581 OleDocumentView_GetRect,
582 OleDocumentView_SetRectComplex,
583 OleDocumentView_Show,
584 OleDocumentView_UIActivate,
585 OleDocumentView_Open,
586 OleDocumentView_CloseView,
587 OleDocumentView_SaveViewState,
588 OleDocumentView_ApplyViewState,
589 OleDocumentView_Clone
592 /**********************************************************
593 * IViewObject implementation
596 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
598 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
600 HTMLDocument *This = VIEWOBJ_THIS(iface);
601 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
604 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
606 HTMLDocument *This = VIEWOBJ_THIS(iface);
607 return IHTMLDocument2_AddRef(HTMLDOC(This));
610 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
612 HTMLDocument *This = VIEWOBJ_THIS(iface);
613 return IHTMLDocument2_Release(HTMLDOC(This));
616 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
617 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
618 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
620 HTMLDocument *This = VIEWOBJ_THIS(iface);
621 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
622 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
626 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
627 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
629 HTMLDocument *This = VIEWOBJ_THIS(iface);
630 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
634 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
635 void *pvAspect, DWORD *pdwFreeze)
637 HTMLDocument *This = VIEWOBJ_THIS(iface);
638 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
642 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
644 HTMLDocument *This = VIEWOBJ_THIS(iface);
645 FIXME("(%p)->(%ld)\n", This, dwFreeze);
649 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
651 HTMLDocument *This = VIEWOBJ_THIS(iface);
652 FIXME("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
656 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
658 HTMLDocument *This = VIEWOBJ_THIS(iface);
659 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
663 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
664 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
666 HTMLDocument *This = VIEWOBJ_THIS(iface);
667 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
673 static const IViewObject2Vtbl ViewObjectVtbl = {
674 ViewObject_QueryInterface,
678 ViewObject_GetColorSet,
681 ViewObject_SetAdvise,
682 ViewObject_GetAdvise,
686 void HTMLDocument_View_Init(HTMLDocument *This)
688 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
689 This->lpViewObject2Vtbl = &ViewObjectVtbl;
694 This->tooltips_hwnd = NULL;
696 This->in_place_active = FALSE;
697 This->ui_active = FALSE;
698 This->window_active = FALSE;
700 create_hidden_window(This);