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
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 static const WCHAR wszInternetExplorer_Server[] =
39 {'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','_','S','e','r','v','e','r',0};
40 static const WCHAR wszHTML_Document[] =
41 {'H','T','M','L',' ','D','o','c','u','m','e','n','t',0};
43 static ATOM serverwnd_class = 0;
45 static void paint_disabled(HWND hwnd) {
52 font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
53 brush = CreateSolidBrush(RGB(255,255,255));
54 GetClientRect(hwnd, &rect);
56 hdc = BeginPaint(hwnd, &ps);
57 SelectObject(hdc, font);
58 SelectObject(hdc, brush);
59 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
60 DrawTextA(hdc, "HTML rendering is currently disabled.",-1, &rect,
61 DT_CENTER | DT_SINGLELINE | DT_VCENTER);
68 static void activate_gecko(HTMLDocument *This)
70 TRACE("(%p) %p\n", This, This->nscontainer->window);
72 SetParent(This->nscontainer->hwnd, This->hwnd);
73 ShowWindow(This->nscontainer->hwnd, SW_SHOW);
75 nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
76 nsIBaseWindow_SetEnabled(This->nscontainer->window, TRUE);
77 nsIWebBrowserFocus_Activate(This->nscontainer->focus);
80 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
84 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
86 if(msg == WM_CREATE) {
87 This = *(HTMLDocument**)lParam;
88 SetPropW(hwnd, wszTHIS, This);
90 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
100 if(!This->nscontainer)
101 paint_disabled(hwnd);
104 TRACE("(%p)->(WM_SIZE)\n", This);
105 if(This->nscontainer)
106 SetWindowPos(This->nscontainer->hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
107 SWP_NOZORDER | SWP_NOACTIVATE);
110 return DefWindowProcW(hwnd, msg, wParam, lParam);
113 static void register_serverwnd_class(void)
115 static WNDCLASSEXW wndclass = {
119 0, 0, NULL, NULL, NULL, NULL, NULL,
120 wszInternetExplorer_Server,
123 wndclass.hInstance = hInst;
124 serverwnd_class = RegisterClassExW(&wndclass);
127 static HRESULT activate_window(HTMLDocument *This)
129 IOleInPlaceUIWindow *pIPWnd;
130 IOleInPlaceFrame *pIPFrame;
131 IOleCommandTarget *cmdtrg;
132 RECT posrect, cliprect;
133 OLEINPLACEFRAMEINFO frameinfo;
138 register_serverwnd_class();
140 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
142 WARN("CanInPlaceActivate returned: %08lx\n", hres);
143 return FAILED(hres) ? hres : E_FAIL;
146 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd, &posrect, &cliprect, &frameinfo);
148 WARN("GetWindowContext failed: %08lx\n", hres);
152 IOleInPlaceUIWindow_Release(pIPWnd);
153 TRACE("got window context: %p %p {%ld %ld %ld %ld} {%ld %ld %ld %ld} {%d %x %p %p %d}\n",
154 pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
155 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
156 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
158 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
160 WARN("GetWindow failed: %08lx\n", hres);
164 TRACE("got parent window %p\n", parent_hwnd);
167 if(GetParent(This->hwnd) != parent_hwnd)
168 SetParent(This->hwnd, parent_hwnd);
169 SetWindowPos(This->hwnd, HWND_TOP,
170 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
171 SWP_NOACTIVATE | SWP_SHOWWINDOW);
173 CreateWindowExW(0, wszInternetExplorer_Server, NULL,
174 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
175 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
176 parent_hwnd, NULL, hInst, This);
178 TRACE("Created window %p\n", This->hwnd);
180 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
181 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
182 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
183 SetFocus(This->hwnd);
186 * Windows implementation calls:
187 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
188 * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
192 This->in_place_active = TRUE;
193 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
195 WARN("OnInPlaceActivate failed: %08lx\n", hres);
196 This->in_place_active = FALSE;
200 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
201 if(SUCCEEDED(hres)) {
204 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
208 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX, 0, &var, NULL);
209 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 0, &var, NULL);
211 IOleCommandTarget_Release(cmdtrg);
215 IOleInPlaceFrame_Release(This->frame);
216 This->frame = pIPFrame;
218 This->window_active = TRUE;
223 /**********************************************************
224 * IOleDocumentView implementation
227 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
229 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
231 HTMLDocument *This = DOCVIEW_THIS(iface);
232 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
235 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
237 HTMLDocument *This = DOCVIEW_THIS(iface);
238 return IHTMLDocument2_AddRef(HTMLDOC(This));
241 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
243 HTMLDocument *This = DOCVIEW_THIS(iface);
244 return IHTMLDocument2_Release(HTMLDOC(This));
247 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
249 HTMLDocument *This = DOCVIEW_THIS(iface);
250 TRACE("(%p)->(%p)\n", This, pIPSite);
253 IOleInPlaceSite_AddRef(pIPSite);
256 IOleInPlaceSite_Release(This->ipsite);
258 This->ipsite = pIPSite;
262 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
264 HTMLDocument *This = DOCVIEW_THIS(iface);
265 TRACE("(%p)->(%p)\n", This, ppIPSite);
271 IOleInPlaceSite_AddRef(This->ipsite);
273 *ppIPSite = This->ipsite;
277 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
279 HTMLDocument *This = DOCVIEW_THIS(iface);
280 TRACE("(%p)->(%p)\n", This, ppunk);
285 IHTMLDocument2_AddRef(HTMLDOC(This));
286 *ppunk = (IUnknown*)HTMLDOC(This);
290 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
292 HTMLDocument *This = DOCVIEW_THIS(iface);
295 TRACE("(%p)->(%p)\n", This, prcView);
301 GetClientRect(This->hwnd, &rect);
302 if(memcmp(prcView, &rect, sizeof(RECT))) {
303 InvalidateRect(This->hwnd,NULL,TRUE);
304 SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
305 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
312 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
314 HTMLDocument *This = DOCVIEW_THIS(iface);
316 TRACE("(%p)->(%p)\n", This, prcView);
321 GetClientRect(This->hwnd, prcView);
325 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
326 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
328 HTMLDocument *This = DOCVIEW_THIS(iface);
329 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
333 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
335 HTMLDocument *This = DOCVIEW_THIS(iface);
338 TRACE("(%p)->(%x)\n", This, fShow);
341 if(!This->ui_active) {
342 hres = activate_window(This);
346 ShowWindow(This->hwnd, SW_SHOW);
348 ShowWindow(This->hwnd, SW_HIDE);
354 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
356 HTMLDocument *This = DOCVIEW_THIS(iface);
359 TRACE("(%p)->(%x)\n", This, fUIActivate);
362 FIXME("This->ipsite = NULL\n");
370 if(!This->window_active) {
371 hres = activate_window(This);
376 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
377 if(SUCCEEDED(hres)) {
378 IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTML_Document);
380 FIXME("OnUIActivate failed: %08lx\n", hres);
381 IOleInPlaceFrame_Release(This->frame);
383 This->ui_active = FALSE;
387 hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
390 IDocHostUIHandler_HideUI(This->hostui);
392 This->ui_active = TRUE;
394 This->window_active = FALSE;
395 if(This->ui_active) {
396 This->ui_active = FALSE;
398 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
400 IDocHostUIHandler_HideUI(This->hostui);
402 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
408 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
410 HTMLDocument *This = DOCVIEW_THIS(iface);
411 FIXME("(%p)\n", This);
415 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
417 HTMLDocument *This = DOCVIEW_THIS(iface);
418 TRACE("(%p)->(%lx)\n", This, dwReserved);
421 WARN("dwReserved = %ld\n", dwReserved);
424 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
425 * QueryInterface(IID_IOleControlSite) and KillTimer
428 IOleDocumentView_Show(iface, FALSE);
433 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
435 HTMLDocument *This = DOCVIEW_THIS(iface);
436 FIXME("(%p)->(%p)\n", This, pstm);
440 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
442 HTMLDocument *This = DOCVIEW_THIS(iface);
443 FIXME("(%p)->(%p)\n", This, pstm);
447 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
448 IOleDocumentView **ppViewNew)
450 HTMLDocument *This = DOCVIEW_THIS(iface);
451 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
457 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
458 OleDocumentView_QueryInterface,
459 OleDocumentView_AddRef,
460 OleDocumentView_Release,
461 OleDocumentView_SetInPlaceSite,
462 OleDocumentView_GetInPlaceSite,
463 OleDocumentView_GetDocument,
464 OleDocumentView_SetRect,
465 OleDocumentView_GetRect,
466 OleDocumentView_SetRectComplex,
467 OleDocumentView_Show,
468 OleDocumentView_UIActivate,
469 OleDocumentView_Open,
470 OleDocumentView_CloseView,
471 OleDocumentView_SaveViewState,
472 OleDocumentView_ApplyViewState,
473 OleDocumentView_Clone
476 /**********************************************************
477 * IViewObject implementation
480 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
482 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
484 HTMLDocument *This = VIEWOBJ_THIS(iface);
485 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
488 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
490 HTMLDocument *This = VIEWOBJ_THIS(iface);
491 return IHTMLDocument2_AddRef(HTMLDOC(This));
494 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
496 HTMLDocument *This = VIEWOBJ_THIS(iface);
497 return IHTMLDocument2_Release(HTMLDOC(This));
500 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
501 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
502 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
504 HTMLDocument *This = VIEWOBJ_THIS(iface);
505 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
506 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
510 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
511 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
513 HTMLDocument *This = VIEWOBJ_THIS(iface);
514 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
518 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
519 void *pvAspect, DWORD *pdwFreeze)
521 HTMLDocument *This = VIEWOBJ_THIS(iface);
522 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
526 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
528 HTMLDocument *This = VIEWOBJ_THIS(iface);
529 FIXME("(%p)->(%ld)\n", This, dwFreeze);
533 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
535 HTMLDocument *This = VIEWOBJ_THIS(iface);
536 FIXME("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
540 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
542 HTMLDocument *This = VIEWOBJ_THIS(iface);
543 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
547 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
548 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
550 HTMLDocument *This = VIEWOBJ_THIS(iface);
551 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
557 static const IViewObject2Vtbl ViewObjectVtbl = {
558 ViewObject_QueryInterface,
562 ViewObject_GetColorSet,
565 ViewObject_SetAdvise,
566 ViewObject_GetAdvise,
570 void HTMLDocument_View_Init(HTMLDocument *This)
572 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
573 This->lpViewObject2Vtbl = &ViewObjectVtbl;
579 This->in_place_active = FALSE;
580 This->ui_active = FALSE;
581 This->window_active = FALSE;