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);
79 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
83 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
85 if(msg == WM_CREATE) {
86 This = *(HTMLDocument**)lParam;
87 SetPropW(hwnd, wszTHIS, This);
89 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
99 if(!This->nscontainer)
100 paint_disabled(hwnd);
103 TRACE("(%p)->(WM_SIZE)\n", This);
104 if(This->nscontainer)
105 SetWindowPos(This->nscontainer->hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
106 SWP_NOZORDER | SWP_NOACTIVATE);
109 return DefWindowProcW(hwnd, msg, wParam, lParam);
112 static void register_serverwnd_class(void)
114 static WNDCLASSEXW wndclass = {
118 0, 0, NULL, NULL, NULL, NULL, NULL,
119 wszInternetExplorer_Server,
122 wndclass.hInstance = hInst;
123 serverwnd_class = RegisterClassExW(&wndclass);
126 static HRESULT activate_window(HTMLDocument *This)
128 IOleInPlaceUIWindow *pIPWnd;
129 IOleInPlaceFrame *pIPFrame;
130 IOleCommandTarget *cmdtrg;
131 RECT posrect, cliprect;
132 OLEINPLACEFRAMEINFO frameinfo;
137 register_serverwnd_class();
139 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
141 WARN("CanInPlaceActivate returned: %08lx\n", hres);
142 return FAILED(hres) ? hres : E_FAIL;
145 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd, &posrect, &cliprect, &frameinfo);
147 WARN("GetWindowContext failed: %08lx\n", hres);
151 IOleInPlaceUIWindow_Release(pIPWnd);
152 TRACE("got window context: %p %p {%ld %ld %ld %ld} {%ld %ld %ld %ld} {%d %x %p %p %d}\n",
153 pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
154 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
155 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
157 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
159 WARN("GetWindow failed: %08lx\n", hres);
163 TRACE("got parent window %p\n", parent_hwnd);
166 if(GetParent(This->hwnd) != parent_hwnd)
167 SetParent(This->hwnd, parent_hwnd);
168 SetWindowPos(This->hwnd, HWND_TOP,
169 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
170 SWP_NOACTIVATE | SWP_SHOWWINDOW);
172 CreateWindowExW(0, wszInternetExplorer_Server, NULL,
173 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
174 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
175 parent_hwnd, NULL, hInst, This);
177 TRACE("Created window %p\n", This->hwnd);
179 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
180 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
181 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
182 SetFocus(This->hwnd);
185 * Windows implementation calls:
186 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
187 * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
191 This->in_place_active = TRUE;
192 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
194 WARN("OnInPlaceActivate failed: %08lx\n", hres);
195 This->in_place_active = FALSE;
199 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
200 if(SUCCEEDED(hres)) {
203 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
207 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX, 0, &var, NULL);
208 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 0, &var, NULL);
210 IOleCommandTarget_Release(cmdtrg);
214 IOleInPlaceFrame_Release(This->frame);
215 This->frame = pIPFrame;
217 This->window_active = TRUE;
222 /**********************************************************
223 * IOleDocumentView implementation
226 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
228 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
230 HTMLDocument *This = DOCVIEW_THIS(iface);
231 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
234 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
236 HTMLDocument *This = DOCVIEW_THIS(iface);
237 return IHTMLDocument2_AddRef(HTMLDOC(This));
240 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
242 HTMLDocument *This = DOCVIEW_THIS(iface);
243 return IHTMLDocument2_Release(HTMLDOC(This));
246 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
248 HTMLDocument *This = DOCVIEW_THIS(iface);
249 TRACE("(%p)->(%p)\n", This, pIPSite);
252 IOleInPlaceSite_AddRef(pIPSite);
255 IOleInPlaceSite_Release(This->ipsite);
257 This->ipsite = pIPSite;
261 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
263 HTMLDocument *This = DOCVIEW_THIS(iface);
264 TRACE("(%p)->(%p)\n", This, ppIPSite);
270 IOleInPlaceSite_AddRef(This->ipsite);
272 *ppIPSite = This->ipsite;
276 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
278 HTMLDocument *This = DOCVIEW_THIS(iface);
279 TRACE("(%p)->(%p)\n", This, ppunk);
284 IHTMLDocument2_AddRef(HTMLDOC(This));
285 *ppunk = (IUnknown*)HTMLDOC(This);
289 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
291 HTMLDocument *This = DOCVIEW_THIS(iface);
294 TRACE("(%p)->(%p)\n", This, prcView);
300 GetClientRect(This->hwnd, &rect);
301 if(memcmp(prcView, &rect, sizeof(RECT))) {
302 InvalidateRect(This->hwnd,NULL,TRUE);
303 SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
304 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
311 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
313 HTMLDocument *This = DOCVIEW_THIS(iface);
315 TRACE("(%p)->(%p)\n", This, prcView);
320 GetClientRect(This->hwnd, prcView);
324 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
325 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
327 HTMLDocument *This = DOCVIEW_THIS(iface);
328 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
332 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
334 HTMLDocument *This = DOCVIEW_THIS(iface);
337 TRACE("(%p)->(%x)\n", This, fShow);
340 if(!This->ui_active) {
341 hres = activate_window(This);
345 ShowWindow(This->hwnd, SW_SHOW);
347 ShowWindow(This->hwnd, SW_HIDE);
353 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
355 HTMLDocument *This = DOCVIEW_THIS(iface);
358 TRACE("(%p)->(%x)\n", This, fUIActivate);
361 FIXME("This->ipsite = NULL\n");
369 if(!This->window_active) {
370 hres = activate_window(This);
375 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
376 if(SUCCEEDED(hres)) {
377 IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTML_Document);
379 FIXME("OnUIActivate failed: %08lx\n", hres);
380 IOleInPlaceFrame_Release(This->frame);
382 This->ui_active = FALSE;
386 hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
389 IDocHostUIHandler_HideUI(This->hostui);
391 This->ui_active = TRUE;
393 This->window_active = FALSE;
394 if(This->ui_active) {
395 This->ui_active = FALSE;
397 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
399 IDocHostUIHandler_HideUI(This->hostui);
401 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
407 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
409 HTMLDocument *This = DOCVIEW_THIS(iface);
410 FIXME("(%p)\n", This);
414 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
416 HTMLDocument *This = DOCVIEW_THIS(iface);
417 TRACE("(%p)->(%lx)\n", This, dwReserved);
420 WARN("dwReserved = %ld\n", dwReserved);
423 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
424 * QueryInterface(IID_IOleControlSite) and KillTimer
427 IOleDocumentView_Show(iface, FALSE);
432 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
434 HTMLDocument *This = DOCVIEW_THIS(iface);
435 FIXME("(%p)->(%p)\n", This, pstm);
439 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
441 HTMLDocument *This = DOCVIEW_THIS(iface);
442 FIXME("(%p)->(%p)\n", This, pstm);
446 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
447 IOleDocumentView **ppViewNew)
449 HTMLDocument *This = DOCVIEW_THIS(iface);
450 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
456 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
457 OleDocumentView_QueryInterface,
458 OleDocumentView_AddRef,
459 OleDocumentView_Release,
460 OleDocumentView_SetInPlaceSite,
461 OleDocumentView_GetInPlaceSite,
462 OleDocumentView_GetDocument,
463 OleDocumentView_SetRect,
464 OleDocumentView_GetRect,
465 OleDocumentView_SetRectComplex,
466 OleDocumentView_Show,
467 OleDocumentView_UIActivate,
468 OleDocumentView_Open,
469 OleDocumentView_CloseView,
470 OleDocumentView_SaveViewState,
471 OleDocumentView_ApplyViewState,
472 OleDocumentView_Clone
475 /**********************************************************
476 * IViewObject implementation
479 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
481 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
483 HTMLDocument *This = VIEWOBJ_THIS(iface);
484 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
487 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
489 HTMLDocument *This = VIEWOBJ_THIS(iface);
490 return IHTMLDocument2_AddRef(HTMLDOC(This));
493 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
495 HTMLDocument *This = VIEWOBJ_THIS(iface);
496 return IHTMLDocument2_Release(HTMLDOC(This));
499 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
500 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
501 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
503 HTMLDocument *This = VIEWOBJ_THIS(iface);
504 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
505 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
509 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
510 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
512 HTMLDocument *This = VIEWOBJ_THIS(iface);
513 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
517 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
518 void *pvAspect, DWORD *pdwFreeze)
520 HTMLDocument *This = VIEWOBJ_THIS(iface);
521 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
525 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
527 HTMLDocument *This = VIEWOBJ_THIS(iface);
528 FIXME("(%p)->(%ld)\n", This, dwFreeze);
532 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
534 HTMLDocument *This = VIEWOBJ_THIS(iface);
535 FIXME("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
539 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
541 HTMLDocument *This = VIEWOBJ_THIS(iface);
542 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
546 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
547 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
549 HTMLDocument *This = VIEWOBJ_THIS(iface);
550 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
556 static const IViewObject2Vtbl ViewObjectVtbl = {
557 ViewObject_QueryInterface,
561 ViewObject_GetColorSet,
564 ViewObject_SetAdvise,
565 ViewObject_GetAdvise,
569 void HTMLDocument_View_Init(HTMLDocument *This)
571 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
572 This->lpViewObject2Vtbl = &ViewObjectVtbl;
578 This->in_place_active = FALSE;
579 This->ui_active = FALSE;
580 This->window_active = FALSE;