Fixed a few prototypes in the USER driver.
[wine] / dlls / mshtml / view.c
1 /*
2  * Copyright 2005 Jacek Caban
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wingdi.h"
30 #include "ole2.h"
31 #include "docobj.h"
32
33 #include "mshtml.h"
34 #include "mshtmhst.h"
35
36 #include "wine/debug.h"
37
38 #include "mshtml_private.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41
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};
46
47 static ATOM serverwnd_class = 0;
48
49 static void paint_disabled(HWND hwnd) {
50     HDC hdc;
51     PAINTSTRUCT ps;
52     HBRUSH brush;
53     RECT rect;
54     HFONT font;
55
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);
59
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);
66     EndPaint(hwnd, &ps);
67
68     DeleteObject(font);
69     DeleteObject(brush);
70 }
71
72 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
73 {
74     if(msg == WM_PAINT)
75         paint_disabled(hwnd);
76         
77     return DefWindowProcW(hwnd, msg, wParam, lParam);
78 }
79
80 static void register_serverwnd_class(void)
81 {
82     static WNDCLASSEXW wndclass = {
83         sizeof(WNDCLASSEXW),
84         CS_DBLCLKS,
85         serverwnd_proc,
86         0, 0, NULL, NULL, NULL, NULL, NULL,
87         wszInternetExplorer_Server,
88         NULL,
89     };
90     wndclass.hInstance = hInst;
91     serverwnd_class = RegisterClassExW(&wndclass);
92 }
93
94
95 /**********************************************************
96  * IOleDocumentView implementation
97  */
98
99 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
100
101 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
102 {
103     HTMLDocument *This = DOCVIEW_THIS(iface);
104     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
105 }
106
107 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
108 {
109     HTMLDocument *This = DOCVIEW_THIS(iface);
110     return IHTMLDocument2_AddRef(HTMLDOC(This));
111 }
112
113 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
114 {
115     HTMLDocument *This = DOCVIEW_THIS(iface);
116     return IHTMLDocument2_Release(HTMLDOC(This));
117 }
118
119 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
120 {
121     HTMLDocument *This = DOCVIEW_THIS(iface);
122     TRACE("(%p)->(%p)\n", This, pIPSite);
123
124     if(pIPSite)
125         IOleInPlaceSite_AddRef(pIPSite);
126
127     if(This->ipsite)
128         IOleInPlaceSite_Release(This->ipsite);
129
130     This->ipsite = pIPSite;
131     return S_OK;
132 }
133
134 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
135 {
136     HTMLDocument *This = DOCVIEW_THIS(iface);
137     TRACE("(%p)->(%p)\n", This, ppIPSite);
138
139     if(!ppIPSite)
140         return E_INVALIDARG;
141
142     if(This->ipsite)
143         IOleInPlaceSite_AddRef(This->ipsite);
144
145     *ppIPSite = This->ipsite;
146     return S_OK;
147 }
148
149 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
150 {
151     HTMLDocument *This = DOCVIEW_THIS(iface);
152     TRACE("(%p)->(%p)\n", This, ppunk);
153
154     if(!ppunk)
155         return E_INVALIDARG;
156
157     IHTMLDocument2_AddRef(HTMLDOC(This));
158     *ppunk = (IUnknown*)HTMLDOC(This);
159     return S_OK;
160 }
161
162 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
163 {
164     HTMLDocument *This = DOCVIEW_THIS(iface);
165     RECT rect;
166
167     TRACE("(%p)->(%p)\n", This, prcView);
168
169     if(!prcView)
170         return E_INVALIDARG;
171
172     if(This->hwnd) {
173         GetClientRect(This->hwnd, &rect);
174         if(memcmp(prcView, &rect, sizeof(RECT))) {
175             InvalidateRect(This->hwnd,NULL,TRUE);
176             SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
177                     prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
178         }
179     }
180     
181     return S_OK;
182 }
183
184 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
185 {
186     HTMLDocument *This = DOCVIEW_THIS(iface);
187
188     TRACE("(%p)->(%p)\n", This, prcView);
189
190     if(!prcView)
191         return E_INVALIDARG;
192
193     GetClientRect(This->hwnd, prcView);
194     return S_OK;
195 }
196
197 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
198                         LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
199 {
200     HTMLDocument *This = DOCVIEW_THIS(iface);
201     FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
202     return E_NOTIMPL;
203 }
204
205 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
206 {
207     HTMLDocument *This = DOCVIEW_THIS(iface);
208     TRACE("(%p)->(%x)\n", This, fShow);
209
210     if(This->hwnd)
211         ShowWindow(This->hwnd, fShow);
212
213     return S_OK;
214 }
215
216 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
217 {
218     HTMLDocument *This = DOCVIEW_THIS(iface);
219     HRESULT hres;
220     IOleInPlaceUIWindow *pIPWnd;
221     IOleInPlaceFrame *pIPFrame;
222     RECT posrect, cliprect;
223     OLEINPLACEFRAMEINFO frameinfo;
224     HWND parent_hwnd;
225
226     TRACE("(%p)->(%x)\n", This, fUIActivate);
227
228     if(!This->ipsite) {
229         FIXME("This->ipsite = NULL\n");
230         return E_FAIL;
231     }
232
233     if(fUIActivate) {
234         if(This->ui_active)
235             return S_OK;
236         if(!serverwnd_class)
237             register_serverwnd_class();
238
239         hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
240         if(hres != S_OK) {
241             WARN("CanInPlaceActivate returned: %08lx\n", hres);
242             return FAILED(hres) ? hres : E_FAIL;
243         }
244
245         hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd, &posrect, &cliprect, &frameinfo);
246         if(FAILED(hres)) {
247             WARN("GetWindowContext failed: %08lx\n", hres);
248             return hres;
249         }
250         if(pIPWnd)
251             IOleInPlaceUIWindow_Release(pIPWnd);
252         TRACE("got window context: %p %p {%ld %ld %ld %ld} {%ld %ld %ld %ld} {%d %x %p %p %d}\n",
253                 pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
254                 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
255                 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
256
257         hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
258         if(FAILED(hres)) {
259             WARN("GetWindow failed: %08lx\n", hres);
260             return hres;
261         }
262
263         TRACE("got parent window %p\n", parent_hwnd);
264
265         if(This->hwnd) {
266             if(GetParent(This->hwnd) != parent_hwnd)
267                 SetParent(This->hwnd, parent_hwnd);
268             SetWindowPos(This->hwnd, HWND_TOP,
269                     posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
270                     SWP_NOACTIVATE | SWP_SHOWWINDOW);
271         }else {
272             This->hwnd = CreateWindowExW(0, wszInternetExplorer_Server, NULL,
273                     WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
274                     posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
275                     parent_hwnd, NULL, hInst, This);
276             SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
277                     SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
278             RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
279             SetFocus(This->hwnd);
280         }
281
282         This->in_place_active = TRUE;
283         hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
284         if(FAILED(hres)) {
285             WARN("OnInPlaceActivate failed: %08lx\n", hres);
286             This->in_place_active = FALSE;
287             return hres;
288         }
289
290         /* NOTE:
291          * Windows implementation calls:
292          * RegisterWindowMessage("MSWHEEL_ROLLMSG");
293          * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
294          */
295
296         This->ui_active = TRUE;
297         hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
298         if(SUCCEEDED(hres)) {
299             IOleInPlaceFrame_SetActiveObject(pIPFrame, ACTOBJ(This), wszHTML_Document);
300         }else {
301             FIXME("OnUIActivate failed: %08lx\n", hres);
302             This->ui_active = FALSE;
303             return hres;
304         }
305         if(This->frame)
306             IOleInPlaceFrame_Release(This->frame);
307         This->frame = pIPFrame;
308
309         hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
310                 pIPFrame, NULL);
311         if(FAILED(hres))
312             IDocHostUIHandler_HideUI(This->hostui);
313     }else {
314         This->ui_active = FALSE;
315         if(This->frame)
316             IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
317         if(This->hostui)
318             IDocHostUIHandler_HideUI(This->hostui);
319         if(This->ipsite)
320             IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
321     }
322     return S_OK;
323 }
324
325 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
326 {
327     HTMLDocument *This = DOCVIEW_THIS(iface);
328     FIXME("(%p)\n", This);
329     return E_NOTIMPL;
330 }
331
332 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
333 {
334     HTMLDocument *This = DOCVIEW_THIS(iface);
335     TRACE("(%p)->(%lx)\n", This, dwReserved);
336
337     if(dwReserved)
338         WARN("dwReserved = %ld\n", dwReserved);
339
340     /* NOTE:
341      * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
342      * QueryInterface(IID_IOleControlSite) and KillTimer
343      */
344
345     IOleDocumentView_Show(iface, FALSE);
346
347     return S_OK;
348 }
349
350 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
351 {
352     HTMLDocument *This = DOCVIEW_THIS(iface);
353     FIXME("(%p)->(%p)\n", This, pstm);
354     return E_NOTIMPL;
355 }
356
357 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
358 {
359     HTMLDocument *This = DOCVIEW_THIS(iface);
360     FIXME("(%p)->(%p)\n", This, pstm);
361     return E_NOTIMPL;
362 }
363
364 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
365                                         IOleDocumentView **ppViewNew)
366 {
367     HTMLDocument *This = DOCVIEW_THIS(iface);
368     FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
369     return E_NOTIMPL;
370 }
371
372 #undef DOCVIEW_THIS
373
374 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
375     OleDocumentView_QueryInterface,
376     OleDocumentView_AddRef,
377     OleDocumentView_Release,
378     OleDocumentView_SetInPlaceSite,
379     OleDocumentView_GetInPlaceSite,
380     OleDocumentView_GetDocument,
381     OleDocumentView_SetRect,
382     OleDocumentView_GetRect,
383     OleDocumentView_SetRectComplex,
384     OleDocumentView_Show,
385     OleDocumentView_UIActivate,
386     OleDocumentView_Open,
387     OleDocumentView_CloseView,
388     OleDocumentView_SaveViewState,
389     OleDocumentView_ApplyViewState,
390     OleDocumentView_Clone
391 };
392
393 /**********************************************************
394  * IViewObject implementation
395  */
396
397 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
398
399 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
400 {
401     HTMLDocument *This = VIEWOBJ_THIS(iface);
402     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
403 }
404
405 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
406 {
407     HTMLDocument *This = VIEWOBJ_THIS(iface);
408     return IHTMLDocument2_AddRef(HTMLDOC(This));
409 }
410
411 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
412 {
413     HTMLDocument *This = VIEWOBJ_THIS(iface);
414     return IHTMLDocument2_Release(HTMLDOC(This));
415 }
416
417 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
418         DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
419         LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
420 {
421     HTMLDocument *This = VIEWOBJ_THIS(iface);
422     FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
423             ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
424     return E_NOTIMPL;
425 }
426
427 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
428         DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
429 {
430     HTMLDocument *This = VIEWOBJ_THIS(iface);
431     FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
432     return E_NOTIMPL;
433 }
434
435 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
436         void *pvAspect, DWORD *pdwFreeze)
437 {
438     HTMLDocument *This = VIEWOBJ_THIS(iface);
439     FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
440     return E_NOTIMPL;
441 }
442
443 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
444 {
445     HTMLDocument *This = VIEWOBJ_THIS(iface);
446     FIXME("(%p)->(%ld)\n", This, dwFreeze);
447     return E_NOTIMPL;
448 }
449
450 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
451 {
452     HTMLDocument *This = VIEWOBJ_THIS(iface);
453     FIXME("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
454     return E_NOTIMPL;
455 }
456
457 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
458 {
459     HTMLDocument *This = VIEWOBJ_THIS(iface);
460     FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
461     return E_NOTIMPL;
462 }
463
464 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
465                                 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
466 {
467     HTMLDocument *This = VIEWOBJ_THIS(iface);
468     FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
469     return E_NOTIMPL;
470 }
471
472 #undef VIEWOBJ_THIS
473
474 static const IViewObject2Vtbl ViewObjectVtbl = {
475     ViewObject_QueryInterface,
476     ViewObject_AddRef,
477     ViewObject_Release,
478     ViewObject_Draw,
479     ViewObject_GetColorSet,
480     ViewObject_Freeze,
481     ViewObject_Unfreeze,
482     ViewObject_SetAdvise,
483     ViewObject_GetAdvise,
484     ViewObject_GetExtent
485 };
486
487 void HTMLDocument_View_Init(HTMLDocument *This)
488 {
489     This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
490     This->lpViewObject2Vtbl = &ViewObjectVtbl;
491
492     This->ipsite = NULL;
493     This->frame = NULL;
494     This->hwnd = NULL;
495
496     This->in_place_active = FALSE;
497     This->ui_active = FALSE;
498 }