Do filename postprocessing in GetDisplayNameOf (Hide filename
[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, 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         hwnd = CreateWindowExW(0, wszInternetExplorer_Server, NULL,
266                 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
267                 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
268                 parent_hwnd, NULL, hInst, This);
269
270         This->in_place_active = TRUE;
271         hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
272         if(FAILED(hres)) {
273             WARN("OnInPlaceActivate failed: %08lx\n", hres);
274             This->in_place_active = FALSE;
275             return hres;
276         }
277
278         SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
279                 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
280         RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
281         SetFocus(hwnd);
282
283         /* NOTE:
284          * Windows implementation calls:
285          * RegisterWindowMessage("MSWHEEL_ROLLMSG");
286          * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
287          */
288
289         This->ui_active = TRUE;
290         hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
291         if(SUCCEEDED(hres)) {
292             IOleInPlaceFrame_SetActiveObject(pIPFrame, ACTOBJ(This), wszHTML_Document);
293         }else {
294             FIXME("OnUIActivate failed: %08lx\n", hres);
295             This->ui_active = FALSE;
296             DestroyWindow(hwnd);
297             return hres;
298         }
299         if(This->frame)
300             IOleInPlaceFrame_Release(This->frame);
301         This->frame = pIPFrame;
302         This->hwnd = hwnd;
303
304         hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
305                 pIPFrame, NULL);
306         if(FAILED(hres))
307             IDocHostUIHandler_HideUI(This->hostui);
308     }else {
309         This->ui_active = FALSE;
310         if(This->frame)
311             IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
312         if(This->hostui)
313             IDocHostUIHandler_HideUI(This->hostui);
314         if(This->ipsite)
315             IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
316     }
317     return S_OK;
318 }
319
320 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
321 {
322     HTMLDocument *This = DOCVIEW_THIS(iface);
323     FIXME("(%p)\n", This);
324     return E_NOTIMPL;
325 }
326
327 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
328 {
329     HTMLDocument *This = DOCVIEW_THIS(iface);
330     TRACE("(%p)->(%lx)\n", This, dwReserved);
331
332     if(dwReserved)
333         WARN("dwReserved = %ld\n", dwReserved);
334
335     /* NOTE:
336      * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
337      * QueryInterface(IID_IOleControlSite) and KillTimer
338      */
339
340     IOleDocumentView_Show(iface, FALSE);
341
342     return S_OK;
343 }
344
345 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
346 {
347     HTMLDocument *This = DOCVIEW_THIS(iface);
348     FIXME("(%p)->(%p)\n", This, pstm);
349     return E_NOTIMPL;
350 }
351
352 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
353 {
354     HTMLDocument *This = DOCVIEW_THIS(iface);
355     FIXME("(%p)->(%p)\n", This, pstm);
356     return E_NOTIMPL;
357 }
358
359 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
360                                         IOleDocumentView **ppViewNew)
361 {
362     HTMLDocument *This = DOCVIEW_THIS(iface);
363     FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
364     return E_NOTIMPL;
365 }
366
367 #undef DOCVIEW_THIS
368
369 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
370     OleDocumentView_QueryInterface,
371     OleDocumentView_AddRef,
372     OleDocumentView_Release,
373     OleDocumentView_SetInPlaceSite,
374     OleDocumentView_GetInPlaceSite,
375     OleDocumentView_GetDocument,
376     OleDocumentView_SetRect,
377     OleDocumentView_GetRect,
378     OleDocumentView_SetRectComplex,
379     OleDocumentView_Show,
380     OleDocumentView_UIActivate,
381     OleDocumentView_Open,
382     OleDocumentView_CloseView,
383     OleDocumentView_SaveViewState,
384     OleDocumentView_ApplyViewState,
385     OleDocumentView_Clone
386 };
387
388 /**********************************************************
389  * IViewObject implementation
390  */
391
392 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
393
394 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
395 {
396     HTMLDocument *This = VIEWOBJ_THIS(iface);
397     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
398 }
399
400 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
401 {
402     HTMLDocument *This = VIEWOBJ_THIS(iface);
403     return IHTMLDocument2_AddRef(HTMLDOC(This));
404 }
405
406 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
407 {
408     HTMLDocument *This = VIEWOBJ_THIS(iface);
409     return IHTMLDocument2_Release(HTMLDOC(This));
410 }
411
412 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
413         DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
414         LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
415 {
416     HTMLDocument *This = VIEWOBJ_THIS(iface);
417     FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
418             ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
419     return E_NOTIMPL;
420 }
421
422 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
423         DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
424 {
425     HTMLDocument *This = VIEWOBJ_THIS(iface);
426     FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
427     return E_NOTIMPL;
428 }
429
430 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
431         void *pvAspect, DWORD *pdwFreeze)
432 {
433     HTMLDocument *This = VIEWOBJ_THIS(iface);
434     FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
435     return E_NOTIMPL;
436 }
437
438 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
439 {
440     HTMLDocument *This = VIEWOBJ_THIS(iface);
441     FIXME("(%p)->(%ld)\n", This, dwFreeze);
442     return E_NOTIMPL;
443 }
444
445 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
446 {
447     HTMLDocument *This = VIEWOBJ_THIS(iface);
448     FIXME("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
449     return E_NOTIMPL;
450 }
451
452 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
453 {
454     HTMLDocument *This = VIEWOBJ_THIS(iface);
455     FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
456     return E_NOTIMPL;
457 }
458
459 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
460                                 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
461 {
462     HTMLDocument *This = VIEWOBJ_THIS(iface);
463     FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
464     return E_NOTIMPL;
465 }
466
467 #undef VIEWOBJ_THIS
468
469 static const IViewObject2Vtbl ViewObjectVtbl = {
470     ViewObject_QueryInterface,
471     ViewObject_AddRef,
472     ViewObject_Release,
473     ViewObject_Draw,
474     ViewObject_GetColorSet,
475     ViewObject_Freeze,
476     ViewObject_Unfreeze,
477     ViewObject_SetAdvise,
478     ViewObject_GetAdvise,
479     ViewObject_GetExtent
480 };
481
482 void HTMLDocument_View_Init(HTMLDocument *This)
483 {
484     This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
485     This->lpViewObject2Vtbl = &ViewObjectVtbl;
486
487     This->ipsite = NULL;
488     This->frame = NULL;
489     This->hwnd = NULL;
490
491     This->in_place_active = FALSE;
492     This->ui_active = FALSE;
493 }