Added stub implementation of IOleInPlaceObjectWindowless.
[wine.git] / dlls / mshtml / view.c
blob7385b27d318e645bce714e15139a9638365607cc
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"
31 #include "docobj.h"
33 #include "mshtml.h"
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 static const WCHAR wszInternetExplorer_Server[] =
42 {'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','_','S','e','r','v','e','r',0};
43 static const WCHAR wszHTML_Document[] =
44 {'H','T','M','L',' ','D','o','c','u','m','e','n','t',0};
46 static ATOM serverwnd_class = 0;
48 static void paint_disabled(HWND hwnd) {
49 HDC hdc;
50 PAINTSTRUCT ps;
51 HBRUSH brush;
52 RECT rect;
53 HFONT font;
55 font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
56 brush = CreateSolidBrush(RGB(255,255,255));
57 GetClientRect(hwnd, &rect);
59 hdc = BeginPaint(hwnd, &ps);
60 SelectObject(hdc, font);
61 SelectObject(hdc, brush);
62 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
63 DrawTextA(hdc, "HTML rendering is currently disabled.",-1, &rect,
64 DT_CENTER | DT_SINGLELINE | DT_VCENTER);
65 EndPaint(hwnd, &ps);
67 DeleteObject(font);
68 DeleteObject(brush);
71 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
73 if(msg == WM_PAINT)
74 paint_disabled(hwnd);
76 return DefWindowProcW(hwnd, msg, wParam, lParam);
79 static void register_serverwnd_class(void)
81 static WNDCLASSEXW wndclass = {
82 sizeof(WNDCLASSEXW),
83 CS_DBLCLKS,
84 serverwnd_proc,
85 0, 0, NULL, NULL, NULL, NULL, NULL,
86 wszInternetExplorer_Server,
87 NULL,
89 wndclass.hInstance = hInst;
90 serverwnd_class = RegisterClassExW(&wndclass);
94 /**********************************************************
95 * IOleDocumentView implementation
98 #define DOCVIEW_THIS \
99 HTMLDocument* const This=(HTMLDocument*)((char*)(iface)-offsetof(HTMLDocument,lpOleDocumentViewVtbl));
101 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
103 DOCVIEW_THIS
104 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
107 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
109 DOCVIEW_THIS
110 return IHTMLDocument2_AddRef(HTMLDOC(This));
113 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
115 DOCVIEW_THIS
116 return IHTMLDocument2_Release(HTMLDOC(This));
119 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
121 DOCVIEW_THIS
122 TRACE("(%p)->(%p)\n", This, pIPSite);
124 if(!pIPSite)
125 return E_INVALIDARG;
127 if(pIPSite)
128 IOleInPlaceSite_AddRef(pIPSite);
130 if(This->ipsite)
131 IOleInPlaceSite_Release(This->ipsite);
133 This->ipsite = pIPSite;
134 return S_OK;
137 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
139 DOCVIEW_THIS
140 TRACE("(%p)->(%p)\n", This, ppIPSite);
142 if(!ppIPSite)
143 return E_INVALIDARG;
145 if(This->ipsite)
146 IOleInPlaceSite_AddRef(This->ipsite);
148 *ppIPSite = This->ipsite;
149 return S_OK;
152 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
154 DOCVIEW_THIS
155 TRACE("(%p)->(%p)\n", This, ppunk);
157 if(!ppunk)
158 return E_INVALIDARG;
160 IHTMLDocument2_AddRef(HTMLDOC(This));
161 *ppunk = (IUnknown*)HTMLDOC(This);
162 return S_OK;
165 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
167 DOCVIEW_THIS
168 RECT rect;
170 TRACE("(%p)->(%p)\n", This, prcView);
172 if(!prcView)
173 return E_INVALIDARG;
175 if(This->hwnd) {
176 GetClientRect(This->hwnd, &rect);
177 if(memcmp(prcView, &rect, sizeof(RECT))) {
178 InvalidateRect(This->hwnd,NULL,TRUE);
179 SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
180 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
184 return S_OK;
187 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
189 DOCVIEW_THIS
191 TRACE("(%p)->(%p)\n", This, prcView);
193 if(!prcView)
194 return E_INVALIDARG;
196 GetClientRect(This->hwnd, prcView);
197 return S_OK;
200 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
201 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
203 DOCVIEW_THIS
204 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
205 return E_NOTIMPL;
208 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
210 DOCVIEW_THIS
211 TRACE("(%p)->(%x)\n", This, fShow);
213 if(This->hwnd)
214 ShowWindow(This->hwnd, fShow);
216 return S_OK;
219 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
221 DOCVIEW_THIS
222 HRESULT hres;
223 IOleInPlaceUIWindow *pIPWnd;
224 IOleInPlaceFrame *pIPFrame;
225 RECT posrect, cliprect;
226 OLEINPLACEFRAMEINFO frameinfo;
227 HWND parent_hwnd, hwnd;
229 TRACE("(%p)->(%x)\n", This, fUIActivate);
231 if(!This->ipsite) {
232 FIXME("This->ipsite = NULL\n");
233 return E_FAIL;
236 if(fUIActivate) {
237 if(This->hwnd)
238 return S_OK;
239 if(!serverwnd_class)
240 register_serverwnd_class();
242 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
243 if(hres != S_OK) {
244 WARN("CanInPlaceActivate returned: %08lx\n", hres);
245 return FAILED(hres) ? hres : E_FAIL;
248 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd, &posrect, &cliprect, &frameinfo);
249 if(FAILED(hres)) {
250 WARN("GetWindowContext failed: %08lx\n", hres);
251 return hres;
253 if(pIPWnd)
254 IOleInPlaceUIWindow_Release(pIPWnd);
255 TRACE("got window context: %p %p {%ld %ld %ld %ld} {%ld %ld %ld %ld} {%d %x %p %p %d}\n",
256 pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
257 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
258 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
260 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
261 if(FAILED(hres)) {
262 WARN("GetWindow failed: %08lx\n", hres);
263 return hres;
266 hwnd = CreateWindowExW(0, wszInternetExplorer_Server, NULL,
267 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
268 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
269 parent_hwnd, NULL, hInst, This);
271 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
272 if(FAILED(hres)) {
273 WARN("OnInPlaceActivate failed: %08lx\n", hres);
274 return hres;
277 SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
278 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
279 RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
280 SetFocus(hwnd);
282 /* NOTE:
283 * Windows implementation calls:
284 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
285 * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
288 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
289 if(SUCCEEDED(hres)) {
290 IOleInPlaceFrame_SetActiveObject(pIPFrame, ACTOBJ(This), wszHTML_Document);
291 }else {
292 FIXME("OnUIActivate failed: %08lx\n", hres);
293 DestroyWindow(hwnd);
294 return hres;
296 if(This->frame)
297 IOleInPlaceFrame_Release(This->frame);
298 This->frame = pIPFrame;
299 This->hwnd = hwnd;
300 }else {
301 static const WCHAR wszEmpty[] = {0};
303 if(This->frame)
304 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, wszEmpty);
305 if(This->ipsite)
306 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
308 return S_OK;
311 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
313 DOCVIEW_THIS
314 FIXME("(%p)\n", This);
315 return E_NOTIMPL;
318 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
320 DOCVIEW_THIS
321 TRACE("(%p)->(%lx)\n", This, dwReserved);
323 if(dwReserved)
324 WARN("dwReserved = %ld\n", dwReserved);
326 /* NOTE:
327 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
328 * QueryInterface(IID_IOleControlSite) and KillTimer
331 IOleDocumentView_Show(iface, FALSE);
333 return S_OK;
336 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
338 DOCVIEW_THIS
339 FIXME("(%p)->(%p)\n", This, pstm);
340 return E_NOTIMPL;
343 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
345 DOCVIEW_THIS
346 FIXME("(%p)->(%p)\n", This, pstm);
347 return E_NOTIMPL;
350 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
351 IOleDocumentView **ppViewNew)
353 DOCVIEW_THIS
354 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
355 return E_NOTIMPL;
358 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
359 OleDocumentView_QueryInterface,
360 OleDocumentView_AddRef,
361 OleDocumentView_Release,
362 OleDocumentView_SetInPlaceSite,
363 OleDocumentView_GetInPlaceSite,
364 OleDocumentView_GetDocument,
365 OleDocumentView_SetRect,
366 OleDocumentView_GetRect,
367 OleDocumentView_SetRectComplex,
368 OleDocumentView_Show,
369 OleDocumentView_UIActivate,
370 OleDocumentView_Open,
371 OleDocumentView_CloseView,
372 OleDocumentView_SaveViewState,
373 OleDocumentView_ApplyViewState,
374 OleDocumentView_Clone
377 /**********************************************************
378 * IViewObject implementation
381 #define VIEWOBJ_THIS \
382 HTMLDocument* const This=(HTMLDocument*)((char*)(iface)-offsetof(HTMLDocument,lpViewObject2Vtbl));
384 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
386 VIEWOBJ_THIS
387 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
390 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
392 VIEWOBJ_THIS
393 return IHTMLDocument2_AddRef(HTMLDOC(This));
396 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
398 VIEWOBJ_THIS
399 return IHTMLDocument2_Release(HTMLDOC(This));
402 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
403 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
404 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
406 VIEWOBJ_THIS
407 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
408 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
409 return E_NOTIMPL;
412 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
413 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
415 VIEWOBJ_THIS
416 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
417 return E_NOTIMPL;
420 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
421 void *pvAspect, DWORD *pdwFreeze)
423 VIEWOBJ_THIS
424 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
425 return E_NOTIMPL;
428 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
430 VIEWOBJ_THIS
431 FIXME("(%p)->(%ld)\n", This, dwFreeze);
432 return E_NOTIMPL;
435 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
437 VIEWOBJ_THIS
438 FIXME("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
439 return E_NOTIMPL;
442 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
444 VIEWOBJ_THIS
445 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
446 return E_NOTIMPL;
449 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
450 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
452 VIEWOBJ_THIS
453 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
454 return E_NOTIMPL;
457 static const IViewObject2Vtbl ViewObjectVtbl = {
458 ViewObject_QueryInterface,
459 ViewObject_AddRef,
460 ViewObject_Release,
461 ViewObject_Draw,
462 ViewObject_GetColorSet,
463 ViewObject_Freeze,
464 ViewObject_Unfreeze,
465 ViewObject_SetAdvise,
466 ViewObject_GetAdvise,
467 ViewObject_GetExtent
470 void HTMLDocument_View_Init(HTMLDocument *This)
472 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
473 This->lpViewObject2Vtbl = &ViewObjectVtbl;
475 This->ipsite = NULL;
476 This->frame = NULL;
477 This->hwnd = NULL;