Remove trailing backslash.
[wine.git] / dlls / mshtml / view.c
blob0798dfe1919e03ae9148fcfa3ba8764a8b175f1b
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wingdi.h"
30 #include "ole2.h"
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) {
46 HDC hdc;
47 PAINTSTRUCT ps;
48 HBRUSH brush;
49 RECT rect;
50 HFONT font;
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);
62 EndPaint(hwnd, &ps);
64 DeleteObject(font);
65 DeleteObject(brush);
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)
81 HTMLDocument *This;
83 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
85 if(msg == WM_CREATE) {
86 This = *(HTMLDocument**)lParam;
87 SetPropW(hwnd, wszTHIS, This);
88 }else {
89 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
92 switch(msg) {
93 case WM_CREATE:
94 This->hwnd = hwnd;
95 if(This->nscontainer)
96 activate_gecko(This);
97 break;
98 case WM_PAINT:
99 if(!This->nscontainer)
100 paint_disabled(hwnd);
101 break;
102 case WM_SIZE:
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 = {
115 sizeof(WNDCLASSEXW),
116 CS_DBLCLKS,
117 serverwnd_proc,
118 0, 0, NULL, NULL, NULL, NULL, NULL,
119 wszInternetExplorer_Server,
120 NULL,
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;
132 HWND parent_hwnd;
133 HRESULT hres;
135 if(!serverwnd_class)
136 register_serverwnd_class();
138 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
139 if(hres != S_OK) {
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);
145 if(FAILED(hres)) {
146 WARN("GetWindowContext failed: %08lx\n", hres);
147 return hres;
149 if(pIPWnd)
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);
157 if(FAILED(hres)) {
158 WARN("GetWindow failed: %08lx\n", hres);
159 return hres;
162 TRACE("got parent window %p\n", parent_hwnd);
164 if(This->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);
170 }else {
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);
183 /* NOTE:
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);
192 if(FAILED(hres)) {
193 WARN("OnInPlaceActivate failed: %08lx\n", hres);
194 This->in_place_active = FALSE;
195 return hres;
198 if(This->frame)
199 IOleInPlaceFrame_Release(This->frame);
200 This->frame = pIPFrame;
202 This->window_active = TRUE;
204 return S_OK;
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);
236 if(pIPSite)
237 IOleInPlaceSite_AddRef(pIPSite);
239 if(This->ipsite)
240 IOleInPlaceSite_Release(This->ipsite);
242 This->ipsite = pIPSite;
243 return S_OK;
246 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
248 HTMLDocument *This = DOCVIEW_THIS(iface);
249 TRACE("(%p)->(%p)\n", This, ppIPSite);
251 if(!ppIPSite)
252 return E_INVALIDARG;
254 if(This->ipsite)
255 IOleInPlaceSite_AddRef(This->ipsite);
257 *ppIPSite = This->ipsite;
258 return S_OK;
261 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
263 HTMLDocument *This = DOCVIEW_THIS(iface);
264 TRACE("(%p)->(%p)\n", This, ppunk);
266 if(!ppunk)
267 return E_INVALIDARG;
269 IHTMLDocument2_AddRef(HTMLDOC(This));
270 *ppunk = (IUnknown*)HTMLDOC(This);
271 return S_OK;
274 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
276 HTMLDocument *This = DOCVIEW_THIS(iface);
277 RECT rect;
279 TRACE("(%p)->(%p)\n", This, prcView);
281 if(!prcView)
282 return E_INVALIDARG;
284 if(This->hwnd) {
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);
293 return S_OK;
296 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
298 HTMLDocument *This = DOCVIEW_THIS(iface);
300 TRACE("(%p)->(%p)\n", This, prcView);
302 if(!prcView)
303 return E_INVALIDARG;
305 GetClientRect(This->hwnd, prcView);
306 return S_OK;
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);
314 return E_NOTIMPL;
317 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
319 HTMLDocument *This = DOCVIEW_THIS(iface);
320 HRESULT hres;
322 TRACE("(%p)->(%x)\n", This, fShow);
324 if(fShow) {
325 if(!This->ui_active) {
326 hres = activate_window(This);
327 if(FAILED(hres))
328 return hres;
330 ShowWindow(This->hwnd, SW_SHOW);
331 }else {
332 ShowWindow(This->hwnd, SW_HIDE);
335 return S_OK;
338 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
340 HTMLDocument *This = DOCVIEW_THIS(iface);
341 HRESULT hres;
343 TRACE("(%p)->(%x)\n", This, fUIActivate);
345 if(!This->ipsite) {
346 FIXME("This->ipsite = NULL\n");
347 return E_FAIL;
350 if(fUIActivate) {
351 if(This->ui_active)
352 return S_OK;
354 if(!This->window_active) {
355 hres = activate_window(This);
356 if(FAILED(hres))
357 return hres;
360 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
361 if(SUCCEEDED(hres)) {
362 IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTML_Document);
363 }else {
364 FIXME("OnUIActivate failed: %08lx\n", hres);
365 IOleInPlaceFrame_Release(This->frame);
366 This->frame = NULL;
367 This->ui_active = FALSE;
368 return hres;
371 hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
372 This->frame, NULL);
373 if(FAILED(hres))
374 IDocHostUIHandler_HideUI(This->hostui);
376 This->ui_active = TRUE;
377 }else {
378 This->window_active = FALSE;
379 if(This->ui_active) {
380 This->ui_active = FALSE;
381 if(This->frame)
382 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
383 if(This->hostui)
384 IDocHostUIHandler_HideUI(This->hostui);
385 if(This->ipsite)
386 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
389 return S_OK;
392 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
394 HTMLDocument *This = DOCVIEW_THIS(iface);
395 FIXME("(%p)\n", This);
396 return E_NOTIMPL;
399 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
401 HTMLDocument *This = DOCVIEW_THIS(iface);
402 TRACE("(%p)->(%lx)\n", This, dwReserved);
404 if(dwReserved)
405 WARN("dwReserved = %ld\n", dwReserved);
407 /* NOTE:
408 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
409 * QueryInterface(IID_IOleControlSite) and KillTimer
412 IOleDocumentView_Show(iface, FALSE);
414 return S_OK;
417 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
419 HTMLDocument *This = DOCVIEW_THIS(iface);
420 FIXME("(%p)->(%p)\n", This, pstm);
421 return E_NOTIMPL;
424 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
426 HTMLDocument *This = DOCVIEW_THIS(iface);
427 FIXME("(%p)->(%p)\n", This, pstm);
428 return E_NOTIMPL;
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);
436 return E_NOTIMPL;
439 #undef DOCVIEW_THIS
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);
491 return E_NOTIMPL;
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);
499 return E_NOTIMPL;
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);
507 return E_NOTIMPL;
510 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
512 HTMLDocument *This = VIEWOBJ_THIS(iface);
513 FIXME("(%p)->(%ld)\n", This, dwFreeze);
514 return E_NOTIMPL;
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);
521 return E_NOTIMPL;
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);
528 return E_NOTIMPL;
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);
536 return E_NOTIMPL;
539 #undef VIEWOBJ_THIS
541 static const IViewObject2Vtbl ViewObjectVtbl = {
542 ViewObject_QueryInterface,
543 ViewObject_AddRef,
544 ViewObject_Release,
545 ViewObject_Draw,
546 ViewObject_GetColorSet,
547 ViewObject_Freeze,
548 ViewObject_Unfreeze,
549 ViewObject_SetAdvise,
550 ViewObject_GetAdvise,
551 ViewObject_GetExtent
554 void HTMLDocument_View_Init(HTMLDocument *This)
556 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
557 This->lpViewObject2Vtbl = &ViewObjectVtbl;
559 This->ipsite = NULL;
560 This->frame = NULL;
561 This->hwnd = NULL;
563 This->in_place_active = FALSE;
564 This->ui_active = FALSE;
565 This->window_active = FALSE;