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 RECT posrect
, cliprect
;
131 OLEINPLACEFRAMEINFO frameinfo
;
136 register_serverwnd_class();
138 hres
= IOleInPlaceSite_CanInPlaceActivate(This
->ipsite
);
140 WARN("CanInPlaceActivate returned: %08lx\n", hres
);
141 return FAILED(hres
) ? hres
: E_FAIL
;
144 hres
= IOleInPlaceSite_GetWindowContext(This
->ipsite
, &pIPFrame
, &pIPWnd
, &posrect
, &cliprect
, &frameinfo
);
146 WARN("GetWindowContext failed: %08lx\n", hres
);
150 IOleInPlaceUIWindow_Release(pIPWnd
);
151 TRACE("got window context: %p %p {%ld %ld %ld %ld} {%ld %ld %ld %ld} {%d %x %p %p %d}\n",
152 pIPFrame
, pIPWnd
, posrect
.left
, posrect
.top
, posrect
.right
, posrect
.bottom
,
153 cliprect
.left
, cliprect
.top
, cliprect
.right
, cliprect
.bottom
,
154 frameinfo
.cb
, frameinfo
.fMDIApp
, frameinfo
.hwndFrame
, frameinfo
.haccel
, frameinfo
.cAccelEntries
);
156 hres
= IOleInPlaceSite_GetWindow(This
->ipsite
, &parent_hwnd
);
158 WARN("GetWindow failed: %08lx\n", hres
);
162 TRACE("got parent window %p\n", parent_hwnd
);
165 if(GetParent(This
->hwnd
) != parent_hwnd
)
166 SetParent(This
->hwnd
, parent_hwnd
);
167 SetWindowPos(This
->hwnd
, HWND_TOP
,
168 posrect
.left
, posrect
.top
, posrect
.right
-posrect
.left
, posrect
.bottom
-posrect
.top
,
169 SWP_NOACTIVATE
| SWP_SHOWWINDOW
);
171 CreateWindowExW(0, wszInternetExplorer_Server
, NULL
,
172 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
173 posrect
.left
, posrect
.top
, posrect
.right
-posrect
.left
, posrect
.bottom
-posrect
.top
,
174 parent_hwnd
, NULL
, hInst
, This
);
176 TRACE("Created window %p\n", This
->hwnd
);
178 SetWindowPos(This
->hwnd
, NULL
, 0, 0, 0, 0,
179 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
| SWP_NOACTIVATE
| SWP_SHOWWINDOW
);
180 RedrawWindow(This
->hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_NOERASE
| RDW_ALLCHILDREN
);
181 SetFocus(This
->hwnd
);
184 * Windows implementation calls:
185 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
186 * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
190 This
->in_place_active
= TRUE
;
191 hres
= IOleInPlaceSite_OnInPlaceActivate(This
->ipsite
);
193 WARN("OnInPlaceActivate failed: %08lx\n", hres
);
194 This
->in_place_active
= FALSE
;
199 IOleInPlaceFrame_Release(This
->frame
);
200 This
->frame
= pIPFrame
;
202 This
->window_active
= TRUE
;
207 /**********************************************************
208 * IOleDocumentView implementation
211 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
213 static HRESULT WINAPI
OleDocumentView_QueryInterface(IOleDocumentView
*iface
, REFIID riid
, void **ppvObject
)
215 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
216 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
219 static ULONG WINAPI
OleDocumentView_AddRef(IOleDocumentView
*iface
)
221 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
222 return IHTMLDocument2_AddRef(HTMLDOC(This
));
225 static ULONG WINAPI
OleDocumentView_Release(IOleDocumentView
*iface
)
227 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
228 return IHTMLDocument2_Release(HTMLDOC(This
));
231 static HRESULT WINAPI
OleDocumentView_SetInPlaceSite(IOleDocumentView
*iface
, IOleInPlaceSite
*pIPSite
)
233 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
234 TRACE("(%p)->(%p)\n", This
, pIPSite
);
237 IOleInPlaceSite_AddRef(pIPSite
);
240 IOleInPlaceSite_Release(This
->ipsite
);
242 This
->ipsite
= pIPSite
;
246 static HRESULT WINAPI
OleDocumentView_GetInPlaceSite(IOleDocumentView
*iface
, IOleInPlaceSite
**ppIPSite
)
248 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
249 TRACE("(%p)->(%p)\n", This
, ppIPSite
);
255 IOleInPlaceSite_AddRef(This
->ipsite
);
257 *ppIPSite
= This
->ipsite
;
261 static HRESULT WINAPI
OleDocumentView_GetDocument(IOleDocumentView
*iface
, IUnknown
**ppunk
)
263 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
264 TRACE("(%p)->(%p)\n", This
, ppunk
);
269 IHTMLDocument2_AddRef(HTMLDOC(This
));
270 *ppunk
= (IUnknown
*)HTMLDOC(This
);
274 static HRESULT WINAPI
OleDocumentView_SetRect(IOleDocumentView
*iface
, LPRECT prcView
)
276 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
279 TRACE("(%p)->(%p)\n", This
, prcView
);
285 GetClientRect(This
->hwnd
, &rect
);
286 if(memcmp(prcView
, &rect
, sizeof(RECT
))) {
287 InvalidateRect(This
->hwnd
,NULL
,TRUE
);
288 SetWindowPos(This
->hwnd
, NULL
, prcView
->left
, prcView
->top
, prcView
->right
,
289 prcView
->bottom
, SWP_NOZORDER
| SWP_NOACTIVATE
);
296 static HRESULT WINAPI
OleDocumentView_GetRect(IOleDocumentView
*iface
, LPRECT prcView
)
298 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
300 TRACE("(%p)->(%p)\n", This
, prcView
);
305 GetClientRect(This
->hwnd
, prcView
);
309 static HRESULT WINAPI
OleDocumentView_SetRectComplex(IOleDocumentView
*iface
, LPRECT prcView
,
310 LPRECT prcHScroll
, LPRECT prcVScroll
, LPRECT prcSizeBox
)
312 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
313 FIXME("(%p)->(%p %p %p %p)\n", This
, prcView
, prcHScroll
, prcVScroll
, prcSizeBox
);
317 static HRESULT WINAPI
OleDocumentView_Show(IOleDocumentView
*iface
, BOOL fShow
)
319 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
322 TRACE("(%p)->(%x)\n", This
, fShow
);
325 if(!This
->ui_active
) {
326 hres
= activate_window(This
);
330 ShowWindow(This
->hwnd
, SW_SHOW
);
332 ShowWindow(This
->hwnd
, SW_HIDE
);
338 static HRESULT WINAPI
OleDocumentView_UIActivate(IOleDocumentView
*iface
, BOOL fUIActivate
)
340 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
343 TRACE("(%p)->(%x)\n", This
, fUIActivate
);
346 FIXME("This->ipsite = NULL\n");
354 if(!This
->window_active
) {
355 hres
= activate_window(This
);
360 hres
= IOleInPlaceSite_OnUIActivate(This
->ipsite
);
361 if(SUCCEEDED(hres
)) {
362 IOleInPlaceFrame_SetActiveObject(This
->frame
, ACTOBJ(This
), wszHTML_Document
);
364 FIXME("OnUIActivate failed: %08lx\n", hres
);
365 IOleInPlaceFrame_Release(This
->frame
);
367 This
->ui_active
= FALSE
;
371 hres
= IDocHostUIHandler_ShowUI(This
->hostui
, 0, ACTOBJ(This
), CMDTARGET(This
),
374 IDocHostUIHandler_HideUI(This
->hostui
);
376 This
->ui_active
= TRUE
;
378 This
->window_active
= FALSE
;
379 if(This
->ui_active
) {
380 This
->ui_active
= FALSE
;
382 IOleInPlaceFrame_SetActiveObject(This
->frame
, NULL
, NULL
);
384 IDocHostUIHandler_HideUI(This
->hostui
);
386 IOleInPlaceSite_OnUIDeactivate(This
->ipsite
, FALSE
);
392 static HRESULT WINAPI
OleDocumentView_Open(IOleDocumentView
*iface
)
394 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
395 FIXME("(%p)\n", This
);
399 static HRESULT WINAPI
OleDocumentView_CloseView(IOleDocumentView
*iface
, DWORD dwReserved
)
401 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
402 TRACE("(%p)->(%lx)\n", This
, dwReserved
);
405 WARN("dwReserved = %ld\n", dwReserved
);
408 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
409 * QueryInterface(IID_IOleControlSite) and KillTimer
412 IOleDocumentView_Show(iface
, FALSE
);
417 static HRESULT WINAPI
OleDocumentView_SaveViewState(IOleDocumentView
*iface
, LPSTREAM pstm
)
419 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
420 FIXME("(%p)->(%p)\n", This
, pstm
);
424 static HRESULT WINAPI
OleDocumentView_ApplyViewState(IOleDocumentView
*iface
, LPSTREAM pstm
)
426 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
427 FIXME("(%p)->(%p)\n", This
, pstm
);
431 static HRESULT WINAPI
OleDocumentView_Clone(IOleDocumentView
*iface
, IOleInPlaceSite
*pIPSiteNew
,
432 IOleDocumentView
**ppViewNew
)
434 HTMLDocument
*This
= DOCVIEW_THIS(iface
);
435 FIXME("(%p)->(%p %p)\n", This
, pIPSiteNew
, ppViewNew
);
441 static const IOleDocumentViewVtbl OleDocumentViewVtbl
= {
442 OleDocumentView_QueryInterface
,
443 OleDocumentView_AddRef
,
444 OleDocumentView_Release
,
445 OleDocumentView_SetInPlaceSite
,
446 OleDocumentView_GetInPlaceSite
,
447 OleDocumentView_GetDocument
,
448 OleDocumentView_SetRect
,
449 OleDocumentView_GetRect
,
450 OleDocumentView_SetRectComplex
,
451 OleDocumentView_Show
,
452 OleDocumentView_UIActivate
,
453 OleDocumentView_Open
,
454 OleDocumentView_CloseView
,
455 OleDocumentView_SaveViewState
,
456 OleDocumentView_ApplyViewState
,
457 OleDocumentView_Clone
460 /**********************************************************
461 * IViewObject implementation
464 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
466 static HRESULT WINAPI
ViewObject_QueryInterface(IViewObject2
*iface
, REFIID riid
, void **ppvObject
)
468 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
469 return IHTMLDocument2_QueryInterface(HTMLDOC(This
), riid
, ppvObject
);
472 static ULONG WINAPI
ViewObject_AddRef(IViewObject2
*iface
)
474 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
475 return IHTMLDocument2_AddRef(HTMLDOC(This
));
478 static ULONG WINAPI
ViewObject_Release(IViewObject2
*iface
)
480 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
481 return IHTMLDocument2_Release(HTMLDOC(This
));
484 static HRESULT WINAPI
ViewObject_Draw(IViewObject2
*iface
, DWORD dwDrawAspect
, LONG lindex
, void *pvAspect
,
485 DVTARGETDEVICE
*ptd
, HDC hdcTargetDev
, HDC hdcDraw
, LPCRECTL lprcBounds
,
486 LPCRECTL lprcWBounds
, BOOL (CALLBACK
*pfnContinue
)(ULONG_PTR dwContinue
), ULONG_PTR dwContinue
)
488 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
489 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This
, dwDrawAspect
, lindex
, pvAspect
,
490 ptd
, hdcTargetDev
, hdcDraw
, lprcBounds
, lprcWBounds
, pfnContinue
, dwContinue
);
494 static HRESULT WINAPI
ViewObject_GetColorSet(IViewObject2
*iface
, DWORD dwDrawAspect
, LONG lindex
, void *pvAspect
,
495 DVTARGETDEVICE
*ptd
, HDC hicTargetDev
, LOGPALETTE
**ppColorSet
)
497 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
498 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This
, dwDrawAspect
, lindex
, pvAspect
, ptd
, hicTargetDev
, ppColorSet
);
502 static HRESULT WINAPI
ViewObject_Freeze(IViewObject2
*iface
, DWORD dwDrawAspect
, LONG lindex
,
503 void *pvAspect
, DWORD
*pdwFreeze
)
505 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
506 FIXME("(%p)->(%ld %ld %p %p)\n", This
, dwDrawAspect
, lindex
, pvAspect
, pdwFreeze
);
510 static HRESULT WINAPI
ViewObject_Unfreeze(IViewObject2
*iface
, DWORD dwFreeze
)
512 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
513 FIXME("(%p)->(%ld)\n", This
, dwFreeze
);
517 static HRESULT WINAPI
ViewObject_SetAdvise(IViewObject2
*iface
, DWORD aspects
, DWORD advf
, IAdviseSink
*pAdvSink
)
519 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
520 FIXME("(%p)->(%ld %ld %p)\n", This
, aspects
, advf
, pAdvSink
);
524 static HRESULT WINAPI
ViewObject_GetAdvise(IViewObject2
*iface
, DWORD
*pAspects
, DWORD
*pAdvf
, IAdviseSink
**ppAdvSink
)
526 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
527 FIXME("(%p)->(%p %p %p)\n", This
, pAspects
, pAdvf
, ppAdvSink
);
531 static HRESULT WINAPI
ViewObject_GetExtent(IViewObject2
*iface
, DWORD dwDrawAspect
, LONG lindex
,
532 DVTARGETDEVICE
* ptd
, LPSIZEL lpsizel
)
534 HTMLDocument
*This
= VIEWOBJ_THIS(iface
);
535 FIXME("(%p)->(%ld %ld %p %p)\n", This
, dwDrawAspect
, lindex
, ptd
, lpsizel
);
541 static const IViewObject2Vtbl ViewObjectVtbl
= {
542 ViewObject_QueryInterface
,
546 ViewObject_GetColorSet
,
549 ViewObject_SetAdvise
,
550 ViewObject_GetAdvise
,
554 void HTMLDocument_View_Init(HTMLDocument
*This
)
556 This
->lpOleDocumentViewVtbl
= &OleDocumentViewVtbl
;
557 This
->lpViewObject2Vtbl
= &ViewObjectVtbl
;
563 This
->in_place_active
= FALSE
;
564 This
->ui_active
= FALSE
;
565 This
->window_active
= FALSE
;