2 * Copyright 2005 Jacek Caban
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 static const WCHAR wszInternetExplorer_Server[] =
40 {'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','_','S','e','r','v','e','r',0};
42 static ATOM serverwnd_class = 0;
44 static void paint_disabled(HWND hwnd) {
50 WCHAR wszHTMLDisabled[100];
52 LoadStringW(hInst, IDS_HTMLDISABLED, wszHTMLDisabled, sizeof(wszHTMLDisabled)/sizeof(WCHAR));
54 font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
55 brush = CreateSolidBrush(RGB(255,255,255));
56 GetClientRect(hwnd, &rect);
58 hdc = BeginPaint(hwnd, &ps);
59 SelectObject(hdc, font);
60 SelectObject(hdc, brush);
61 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
62 DrawTextW(hdc, wszHTMLDisabled,-1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
69 static void activate_gecko(HTMLDocument *This)
71 TRACE("(%p) %p\n", This, This->nscontainer->window);
73 SetParent(This->nscontainer->hwnd, This->hwnd);
74 ShowWindow(This->nscontainer->hwnd, SW_SHOW);
76 nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
77 nsIBaseWindow_SetEnabled(This->nscontainer->window, TRUE);
78 nsIWebBrowserFocus_Activate(This->nscontainer->focus);
81 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
85 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
87 if(msg == WM_CREATE) {
88 This = *(HTMLDocument**)lParam;
89 SetPropW(hwnd, wszTHIS, This);
91 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
101 if(!This->nscontainer)
102 paint_disabled(hwnd);
105 TRACE("(%p)->(WM_SIZE)\n", This);
106 if(This->nscontainer)
107 SetWindowPos(This->nscontainer->hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
108 SWP_NOZORDER | SWP_NOACTIVATE);
111 return DefWindowProcW(hwnd, msg, wParam, lParam);
114 static void register_serverwnd_class(void)
116 static WNDCLASSEXW wndclass = {
120 0, 0, NULL, NULL, NULL, NULL, NULL,
121 wszInternetExplorer_Server,
124 wndclass.hInstance = hInst;
125 serverwnd_class = RegisterClassExW(&wndclass);
128 static HRESULT activate_window(HTMLDocument *This)
130 IOleInPlaceUIWindow *pIPWnd;
131 IOleInPlaceFrame *pIPFrame;
132 IOleCommandTarget *cmdtrg;
133 RECT posrect, cliprect;
134 OLEINPLACEFRAMEINFO frameinfo;
139 register_serverwnd_class();
141 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
143 WARN("CanInPlaceActivate returned: %08lx\n", hres);
144 return FAILED(hres) ? hres : E_FAIL;
147 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd, &posrect, &cliprect, &frameinfo);
149 WARN("GetWindowContext failed: %08lx\n", hres);
153 IOleInPlaceUIWindow_Release(pIPWnd);
154 TRACE("got window context: %p %p {%ld %ld %ld %ld} {%ld %ld %ld %ld} {%d %x %p %p %d}\n",
155 pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
156 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
157 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
159 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
161 WARN("GetWindow failed: %08lx\n", hres);
165 TRACE("got parent window %p\n", parent_hwnd);
168 if(GetParent(This->hwnd) != parent_hwnd)
169 SetParent(This->hwnd, parent_hwnd);
170 SetWindowPos(This->hwnd, HWND_TOP,
171 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
172 SWP_NOACTIVATE | SWP_SHOWWINDOW);
174 CreateWindowExW(0, wszInternetExplorer_Server, NULL,
175 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
176 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
177 parent_hwnd, NULL, hInst, This);
179 TRACE("Created window %p\n", This->hwnd);
181 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
182 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
183 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
184 SetFocus(This->hwnd);
187 * Windows implementation calls:
188 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
189 * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
193 This->in_place_active = TRUE;
194 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
196 WARN("OnInPlaceActivate failed: %08lx\n", hres);
197 This->in_place_active = FALSE;
201 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
202 if(SUCCEEDED(hres)) {
205 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
209 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX, 0, &var, NULL);
210 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 0, &var, NULL);
212 IOleCommandTarget_Release(cmdtrg);
216 IOleInPlaceFrame_Release(This->frame);
217 This->frame = pIPFrame;
219 This->window_active = TRUE;
224 /**********************************************************
225 * IOleDocumentView implementation
228 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
230 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
232 HTMLDocument *This = DOCVIEW_THIS(iface);
233 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
236 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
238 HTMLDocument *This = DOCVIEW_THIS(iface);
239 return IHTMLDocument2_AddRef(HTMLDOC(This));
242 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
244 HTMLDocument *This = DOCVIEW_THIS(iface);
245 return IHTMLDocument2_Release(HTMLDOC(This));
248 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
250 HTMLDocument *This = DOCVIEW_THIS(iface);
251 TRACE("(%p)->(%p)\n", This, pIPSite);
254 IOleInPlaceSite_AddRef(pIPSite);
257 IOleInPlaceSite_Release(This->ipsite);
259 This->ipsite = pIPSite;
263 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
265 HTMLDocument *This = DOCVIEW_THIS(iface);
266 TRACE("(%p)->(%p)\n", This, ppIPSite);
272 IOleInPlaceSite_AddRef(This->ipsite);
274 *ppIPSite = This->ipsite;
278 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
280 HTMLDocument *This = DOCVIEW_THIS(iface);
281 TRACE("(%p)->(%p)\n", This, ppunk);
286 IHTMLDocument2_AddRef(HTMLDOC(This));
287 *ppunk = (IUnknown*)HTMLDOC(This);
291 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
293 HTMLDocument *This = DOCVIEW_THIS(iface);
296 TRACE("(%p)->(%p)\n", This, prcView);
302 GetClientRect(This->hwnd, &rect);
303 if(memcmp(prcView, &rect, sizeof(RECT))) {
304 InvalidateRect(This->hwnd,NULL,TRUE);
305 SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
306 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
313 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
315 HTMLDocument *This = DOCVIEW_THIS(iface);
317 TRACE("(%p)->(%p)\n", This, prcView);
322 GetClientRect(This->hwnd, prcView);
326 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
327 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
329 HTMLDocument *This = DOCVIEW_THIS(iface);
330 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
334 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
336 HTMLDocument *This = DOCVIEW_THIS(iface);
339 TRACE("(%p)->(%x)\n", This, fShow);
342 if(!This->ui_active) {
343 hres = activate_window(This);
347 ShowWindow(This->hwnd, SW_SHOW);
349 ShowWindow(This->hwnd, SW_HIDE);
355 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
357 HTMLDocument *This = DOCVIEW_THIS(iface);
360 TRACE("(%p)->(%x)\n", This, fUIActivate);
363 FIXME("This->ipsite = NULL\n");
371 if(!This->window_active) {
372 hres = activate_window(This);
377 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
378 if(SUCCEEDED(hres)) {
379 OLECHAR wszHTMLDocument[30];
380 LoadStringW(hInst, IDS_HTMLDOCUMENT, wszHTMLDocument,
381 sizeof(wszHTMLDocument)/sizeof(WCHAR));
382 IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTMLDocument);
384 FIXME("OnUIActivate failed: %08lx\n", hres);
385 IOleInPlaceFrame_Release(This->frame);
387 This->ui_active = FALSE;
391 hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
394 IDocHostUIHandler_HideUI(This->hostui);
396 This->ui_active = TRUE;
398 This->window_active = FALSE;
399 if(This->ui_active) {
400 This->ui_active = FALSE;
402 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
404 IDocHostUIHandler_HideUI(This->hostui);
406 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
412 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
414 HTMLDocument *This = DOCVIEW_THIS(iface);
415 FIXME("(%p)\n", This);
419 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
421 HTMLDocument *This = DOCVIEW_THIS(iface);
422 TRACE("(%p)->(%lx)\n", This, dwReserved);
425 WARN("dwReserved = %ld\n", dwReserved);
428 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
429 * QueryInterface(IID_IOleControlSite) and KillTimer
432 IOleDocumentView_Show(iface, FALSE);
437 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
439 HTMLDocument *This = DOCVIEW_THIS(iface);
440 FIXME("(%p)->(%p)\n", This, pstm);
444 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
446 HTMLDocument *This = DOCVIEW_THIS(iface);
447 FIXME("(%p)->(%p)\n", This, pstm);
451 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
452 IOleDocumentView **ppViewNew)
454 HTMLDocument *This = DOCVIEW_THIS(iface);
455 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
461 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
462 OleDocumentView_QueryInterface,
463 OleDocumentView_AddRef,
464 OleDocumentView_Release,
465 OleDocumentView_SetInPlaceSite,
466 OleDocumentView_GetInPlaceSite,
467 OleDocumentView_GetDocument,
468 OleDocumentView_SetRect,
469 OleDocumentView_GetRect,
470 OleDocumentView_SetRectComplex,
471 OleDocumentView_Show,
472 OleDocumentView_UIActivate,
473 OleDocumentView_Open,
474 OleDocumentView_CloseView,
475 OleDocumentView_SaveViewState,
476 OleDocumentView_ApplyViewState,
477 OleDocumentView_Clone
480 /**********************************************************
481 * IViewObject implementation
484 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
486 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
488 HTMLDocument *This = VIEWOBJ_THIS(iface);
489 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
492 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
494 HTMLDocument *This = VIEWOBJ_THIS(iface);
495 return IHTMLDocument2_AddRef(HTMLDOC(This));
498 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
500 HTMLDocument *This = VIEWOBJ_THIS(iface);
501 return IHTMLDocument2_Release(HTMLDOC(This));
504 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
505 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
506 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
508 HTMLDocument *This = VIEWOBJ_THIS(iface);
509 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
510 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
514 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
515 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
517 HTMLDocument *This = VIEWOBJ_THIS(iface);
518 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
522 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
523 void *pvAspect, DWORD *pdwFreeze)
525 HTMLDocument *This = VIEWOBJ_THIS(iface);
526 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
530 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
532 HTMLDocument *This = VIEWOBJ_THIS(iface);
533 FIXME("(%p)->(%ld)\n", This, dwFreeze);
537 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
539 HTMLDocument *This = VIEWOBJ_THIS(iface);
540 FIXME("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
544 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
546 HTMLDocument *This = VIEWOBJ_THIS(iface);
547 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
551 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
552 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
554 HTMLDocument *This = VIEWOBJ_THIS(iface);
555 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
561 static const IViewObject2Vtbl ViewObjectVtbl = {
562 ViewObject_QueryInterface,
566 ViewObject_GetColorSet,
569 ViewObject_SetAdvise,
570 ViewObject_GetAdvise,
574 void HTMLDocument_View_Init(HTMLDocument *This)
576 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
577 This->lpViewObject2Vtbl = &ViewObjectVtbl;
583 This->in_place_active = FALSE;
584 This->ui_active = FALSE;
585 This->window_active = FALSE;