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
36 #include "wine/debug.h"
38 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 static const WCHAR wszInternetExplorer_Server[] =
43 {'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 wszHTML_Document[] =
45 {'H','T','M','L',' ','D','o','c','u','m','e','n','t',0};
47 static ATOM serverwnd_class = 0;
49 static void paint_disabled(HWND hwnd) {
56 font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
57 brush = CreateSolidBrush(RGB(255,255,255));
58 GetClientRect(hwnd, &rect);
60 hdc = BeginPaint(hwnd, &ps);
61 SelectObject(hdc, font);
62 SelectObject(hdc, brush);
63 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
64 DrawTextA(hdc, "HTML rendering is currently disabled.",-1, &rect,
65 DT_CENTER | DT_SINGLELINE | DT_VCENTER);
72 static void activate_gecko(HTMLDocument *This)
74 TRACE("(%p) %p\n", This, This->nscontainer->window);
76 SetParent(This->nscontainer->hwnd, This->hwnd);
77 ShowWindow(This->nscontainer->hwnd, SW_SHOW);
79 nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
80 nsIBaseWindow_SetEnabled(This->nscontainer->window, TRUE);
83 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
87 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
89 if(msg == WM_CREATE) {
90 This = *(HTMLDocument**)lParam;
91 SetPropW(hwnd, wszTHIS, This);
93 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
100 activate_gecko(This);
103 if(!This->nscontainer)
104 paint_disabled(hwnd);
107 TRACE("(%p)->(WM_SIZE)\n", This);
108 if(This->nscontainer)
109 SetWindowPos(This->nscontainer->hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
110 SWP_NOZORDER | SWP_NOACTIVATE);
113 return DefWindowProcW(hwnd, msg, wParam, lParam);
116 static void register_serverwnd_class(void)
118 static WNDCLASSEXW wndclass = {
122 0, 0, NULL, NULL, NULL, NULL, NULL,
123 wszInternetExplorer_Server,
126 wndclass.hInstance = hInst;
127 serverwnd_class = RegisterClassExW(&wndclass);
130 /**********************************************************
131 * IOleDocumentView implementation
134 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
136 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
138 HTMLDocument *This = DOCVIEW_THIS(iface);
139 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
142 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
144 HTMLDocument *This = DOCVIEW_THIS(iface);
145 return IHTMLDocument2_AddRef(HTMLDOC(This));
148 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
150 HTMLDocument *This = DOCVIEW_THIS(iface);
151 return IHTMLDocument2_Release(HTMLDOC(This));
154 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
156 HTMLDocument *This = DOCVIEW_THIS(iface);
157 TRACE("(%p)->(%p)\n", This, pIPSite);
160 IOleInPlaceSite_AddRef(pIPSite);
163 IOleInPlaceSite_Release(This->ipsite);
165 This->ipsite = pIPSite;
169 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
171 HTMLDocument *This = DOCVIEW_THIS(iface);
172 TRACE("(%p)->(%p)\n", This, ppIPSite);
178 IOleInPlaceSite_AddRef(This->ipsite);
180 *ppIPSite = This->ipsite;
184 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
186 HTMLDocument *This = DOCVIEW_THIS(iface);
187 TRACE("(%p)->(%p)\n", This, ppunk);
192 IHTMLDocument2_AddRef(HTMLDOC(This));
193 *ppunk = (IUnknown*)HTMLDOC(This);
197 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
199 HTMLDocument *This = DOCVIEW_THIS(iface);
202 TRACE("(%p)->(%p)\n", This, prcView);
208 GetClientRect(This->hwnd, &rect);
209 if(memcmp(prcView, &rect, sizeof(RECT))) {
210 InvalidateRect(This->hwnd,NULL,TRUE);
211 SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
212 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
219 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
221 HTMLDocument *This = DOCVIEW_THIS(iface);
223 TRACE("(%p)->(%p)\n", This, prcView);
228 GetClientRect(This->hwnd, prcView);
232 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
233 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
235 HTMLDocument *This = DOCVIEW_THIS(iface);
236 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
240 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
242 HTMLDocument *This = DOCVIEW_THIS(iface);
243 TRACE("(%p)->(%x)\n", This, fShow);
246 ShowWindow(This->hwnd, fShow);
251 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
253 HTMLDocument *This = DOCVIEW_THIS(iface);
255 IOleInPlaceUIWindow *pIPWnd;
256 IOleInPlaceFrame *pIPFrame;
257 RECT posrect, cliprect;
258 OLEINPLACEFRAMEINFO frameinfo;
261 TRACE("(%p)->(%x)\n", This, fUIActivate);
264 FIXME("This->ipsite = NULL\n");
272 register_serverwnd_class();
274 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
276 WARN("CanInPlaceActivate returned: %08lx\n", hres);
277 return FAILED(hres) ? hres : E_FAIL;
280 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd, &posrect, &cliprect, &frameinfo);
282 WARN("GetWindowContext failed: %08lx\n", hres);
286 IOleInPlaceUIWindow_Release(pIPWnd);
287 TRACE("got window context: %p %p {%ld %ld %ld %ld} {%ld %ld %ld %ld} {%d %x %p %p %d}\n",
288 pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
289 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
290 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
292 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
294 WARN("GetWindow failed: %08lx\n", hres);
298 TRACE("got parent window %p\n", parent_hwnd);
301 if(GetParent(This->hwnd) != parent_hwnd)
302 SetParent(This->hwnd, parent_hwnd);
303 SetWindowPos(This->hwnd, HWND_TOP,
304 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
305 SWP_NOACTIVATE | SWP_SHOWWINDOW);
307 CreateWindowExW(0, wszInternetExplorer_Server, NULL,
308 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
309 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
310 parent_hwnd, NULL, hInst, This);
312 TRACE("Created window %p\n", This->hwnd);
314 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
315 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
316 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
317 SetFocus(This->hwnd);
320 This->in_place_active = TRUE;
321 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
323 WARN("OnInPlaceActivate failed: %08lx\n", hres);
324 This->in_place_active = FALSE;
329 * Windows implementation calls:
330 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
331 * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
334 This->ui_active = TRUE;
335 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
336 if(SUCCEEDED(hres)) {
337 IOleInPlaceFrame_SetActiveObject(pIPFrame, ACTOBJ(This), wszHTML_Document);
339 FIXME("OnUIActivate failed: %08lx\n", hres);
340 This->ui_active = FALSE;
344 IOleInPlaceFrame_Release(This->frame);
345 This->frame = pIPFrame;
347 hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
350 IDocHostUIHandler_HideUI(This->hostui);
352 This->ui_active = FALSE;
354 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
356 IDocHostUIHandler_HideUI(This->hostui);
358 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
363 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
365 HTMLDocument *This = DOCVIEW_THIS(iface);
366 FIXME("(%p)\n", This);
370 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
372 HTMLDocument *This = DOCVIEW_THIS(iface);
373 TRACE("(%p)->(%lx)\n", This, dwReserved);
376 WARN("dwReserved = %ld\n", dwReserved);
379 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
380 * QueryInterface(IID_IOleControlSite) and KillTimer
383 IOleDocumentView_Show(iface, FALSE);
388 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
390 HTMLDocument *This = DOCVIEW_THIS(iface);
391 FIXME("(%p)->(%p)\n", This, pstm);
395 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
397 HTMLDocument *This = DOCVIEW_THIS(iface);
398 FIXME("(%p)->(%p)\n", This, pstm);
402 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
403 IOleDocumentView **ppViewNew)
405 HTMLDocument *This = DOCVIEW_THIS(iface);
406 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
412 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
413 OleDocumentView_QueryInterface,
414 OleDocumentView_AddRef,
415 OleDocumentView_Release,
416 OleDocumentView_SetInPlaceSite,
417 OleDocumentView_GetInPlaceSite,
418 OleDocumentView_GetDocument,
419 OleDocumentView_SetRect,
420 OleDocumentView_GetRect,
421 OleDocumentView_SetRectComplex,
422 OleDocumentView_Show,
423 OleDocumentView_UIActivate,
424 OleDocumentView_Open,
425 OleDocumentView_CloseView,
426 OleDocumentView_SaveViewState,
427 OleDocumentView_ApplyViewState,
428 OleDocumentView_Clone
431 /**********************************************************
432 * IViewObject implementation
435 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
437 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
439 HTMLDocument *This = VIEWOBJ_THIS(iface);
440 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
443 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
445 HTMLDocument *This = VIEWOBJ_THIS(iface);
446 return IHTMLDocument2_AddRef(HTMLDOC(This));
449 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
451 HTMLDocument *This = VIEWOBJ_THIS(iface);
452 return IHTMLDocument2_Release(HTMLDOC(This));
455 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
456 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
457 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
459 HTMLDocument *This = VIEWOBJ_THIS(iface);
460 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
461 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
465 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
466 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
468 HTMLDocument *This = VIEWOBJ_THIS(iface);
469 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
473 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
474 void *pvAspect, DWORD *pdwFreeze)
476 HTMLDocument *This = VIEWOBJ_THIS(iface);
477 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
481 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
483 HTMLDocument *This = VIEWOBJ_THIS(iface);
484 FIXME("(%p)->(%ld)\n", This, dwFreeze);
488 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
490 HTMLDocument *This = VIEWOBJ_THIS(iface);
491 FIXME("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
495 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
497 HTMLDocument *This = VIEWOBJ_THIS(iface);
498 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
502 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
503 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
505 HTMLDocument *This = VIEWOBJ_THIS(iface);
506 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
512 static const IViewObject2Vtbl ViewObjectVtbl = {
513 ViewObject_QueryInterface,
517 ViewObject_GetColorSet,
520 ViewObject_SetAdvise,
521 ViewObject_GetAdvise,
525 void HTMLDocument_View_Init(HTMLDocument *This)
527 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
528 This->lpViewObject2Vtbl = &ViewObjectVtbl;
534 This->in_place_active = FALSE;
535 This->ui_active = FALSE;