documentation: Suggest installing OpenLDAP development libraries to packagers.
[wine/dcerpc.git] / dlls / mshtml / view.c
blobdda2f4bc7ad64f8700959473a30bfcf89f3e9fbc
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 "resource.h"
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 static const WCHAR wszInternetExplorer_Server[] =
40 {'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','_','S','e','r','v','e','r',0};
42 static ATOM serverwnd_class = 0;
44 static void paint_disabled(HWND hwnd) {
45 HDC hdc;
46 PAINTSTRUCT ps;
47 HBRUSH brush;
48 RECT rect;
49 HFONT font;
50 WCHAR wszHTMLDisabled[100];
52 LoadStringW(hInst, IDS_HTMLDISABLED, wszHTMLDisabled, sizeof(wszHTMLDisabled)/sizeof(WCHAR));
54 font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
55 brush = CreateSolidBrush(RGB(255,255,255));
56 GetClientRect(hwnd, &rect);
58 hdc = BeginPaint(hwnd, &ps);
59 SelectObject(hdc, font);
60 SelectObject(hdc, brush);
61 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
62 DrawTextW(hdc, wszHTMLDisabled,-1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
63 EndPaint(hwnd, &ps);
65 DeleteObject(font);
66 DeleteObject(brush);
69 static void activate_gecko(HTMLDocument *This)
71 TRACE("(%p) %p\n", This, This->nscontainer->window);
73 SetParent(This->nscontainer->hwnd, This->hwnd);
74 ShowWindow(This->nscontainer->hwnd, SW_SHOW);
76 nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
77 nsIBaseWindow_SetEnabled(This->nscontainer->window, TRUE);
78 nsIWebBrowserFocus_Activate(This->nscontainer->focus);
81 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
83 HTMLDocument *This;
85 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
87 if(msg == WM_CREATE) {
88 This = *(HTMLDocument**)lParam;
89 SetPropW(hwnd, wszTHIS, This);
90 }else {
91 This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
94 switch(msg) {
95 case WM_CREATE:
96 This->hwnd = hwnd;
97 if(This->nscontainer)
98 activate_gecko(This);
99 break;
100 case WM_PAINT:
101 if(!This->nscontainer)
102 paint_disabled(hwnd);
103 break;
104 case WM_SIZE:
105 TRACE("(%p)->(WM_SIZE)\n", This);
106 if(This->nscontainer)
107 SetWindowPos(This->nscontainer->hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
108 SWP_NOZORDER | SWP_NOACTIVATE);
111 return DefWindowProcW(hwnd, msg, wParam, lParam);
114 static void register_serverwnd_class(void)
116 static WNDCLASSEXW wndclass = {
117 sizeof(WNDCLASSEXW),
118 CS_DBLCLKS,
119 serverwnd_proc,
120 0, 0, NULL, NULL, NULL, NULL, NULL,
121 wszInternetExplorer_Server,
122 NULL,
124 wndclass.hInstance = hInst;
125 serverwnd_class = RegisterClassExW(&wndclass);
128 static HRESULT activate_window(HTMLDocument *This)
130 IOleInPlaceUIWindow *pIPWnd;
131 IOleInPlaceFrame *pIPFrame;
132 IOleCommandTarget *cmdtrg;
133 RECT posrect, cliprect;
134 OLEINPLACEFRAMEINFO frameinfo;
135 HWND parent_hwnd;
136 HRESULT hres;
138 if(!serverwnd_class)
139 register_serverwnd_class();
141 hres = IOleInPlaceSite_CanInPlaceActivate(This->ipsite);
142 if(hres != S_OK) {
143 WARN("CanInPlaceActivate returned: %08lx\n", hres);
144 return FAILED(hres) ? hres : E_FAIL;
147 hres = IOleInPlaceSite_GetWindowContext(This->ipsite, &pIPFrame, &pIPWnd, &posrect, &cliprect, &frameinfo);
148 if(FAILED(hres)) {
149 WARN("GetWindowContext failed: %08lx\n", hres);
150 return hres;
152 if(pIPWnd)
153 IOleInPlaceUIWindow_Release(pIPWnd);
154 TRACE("got window context: %p %p {%ld %ld %ld %ld} {%ld %ld %ld %ld} {%d %x %p %p %d}\n",
155 pIPFrame, pIPWnd, posrect.left, posrect.top, posrect.right, posrect.bottom,
156 cliprect.left, cliprect.top, cliprect.right, cliprect.bottom,
157 frameinfo.cb, frameinfo.fMDIApp, frameinfo.hwndFrame, frameinfo.haccel, frameinfo.cAccelEntries);
159 hres = IOleInPlaceSite_GetWindow(This->ipsite, &parent_hwnd);
160 if(FAILED(hres)) {
161 WARN("GetWindow failed: %08lx\n", hres);
162 return hres;
165 TRACE("got parent window %p\n", parent_hwnd);
167 if(This->hwnd) {
168 if(GetParent(This->hwnd) != parent_hwnd)
169 SetParent(This->hwnd, parent_hwnd);
170 SetWindowPos(This->hwnd, HWND_TOP,
171 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
172 SWP_NOACTIVATE | SWP_SHOWWINDOW);
173 }else {
174 CreateWindowExW(0, wszInternetExplorer_Server, NULL,
175 WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
176 posrect.left, posrect.top, posrect.right-posrect.left, posrect.bottom-posrect.top,
177 parent_hwnd, NULL, hInst, This);
179 TRACE("Created window %p\n", This->hwnd);
181 SetWindowPos(This->hwnd, NULL, 0, 0, 0, 0,
182 SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_SHOWWINDOW);
183 RedrawWindow(This->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_ALLCHILDREN);
184 SetFocus(This->hwnd);
186 /* NOTE:
187 * Windows implementation calls:
188 * RegisterWindowMessage("MSWHEEL_ROLLMSG");
189 * SetTimer(This->hwnd, TIMER_ID, 100, NULL);
193 This->in_place_active = TRUE;
194 hres = IOleInPlaceSite_OnInPlaceActivate(This->ipsite);
195 if(FAILED(hres)) {
196 WARN("OnInPlaceActivate failed: %08lx\n", hres);
197 This->in_place_active = FALSE;
198 return hres;
201 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
202 if(SUCCEEDED(hres)) {
203 VARIANT var;
205 IOleInPlaceFrame_SetStatusText(pIPFrame, NULL);
207 V_VT(&var) = VT_I4;
208 V_I4(&var) = 0;
209 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX, 0, &var, NULL);
210 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 0, &var, NULL);
212 IOleCommandTarget_Release(cmdtrg);
215 if(This->frame)
216 IOleInPlaceFrame_Release(This->frame);
217 This->frame = pIPFrame;
219 This->window_active = TRUE;
221 return S_OK;
224 /**********************************************************
225 * IOleDocumentView implementation
228 #define DOCVIEW_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocumentView, iface)
230 static HRESULT WINAPI OleDocumentView_QueryInterface(IOleDocumentView *iface, REFIID riid, void **ppvObject)
232 HTMLDocument *This = DOCVIEW_THIS(iface);
233 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
236 static ULONG WINAPI OleDocumentView_AddRef(IOleDocumentView *iface)
238 HTMLDocument *This = DOCVIEW_THIS(iface);
239 return IHTMLDocument2_AddRef(HTMLDOC(This));
242 static ULONG WINAPI OleDocumentView_Release(IOleDocumentView *iface)
244 HTMLDocument *This = DOCVIEW_THIS(iface);
245 return IHTMLDocument2_Release(HTMLDOC(This));
248 static HRESULT WINAPI OleDocumentView_SetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite *pIPSite)
250 HTMLDocument *This = DOCVIEW_THIS(iface);
251 TRACE("(%p)->(%p)\n", This, pIPSite);
253 if(pIPSite)
254 IOleInPlaceSite_AddRef(pIPSite);
256 if(This->ipsite)
257 IOleInPlaceSite_Release(This->ipsite);
259 This->ipsite = pIPSite;
260 return S_OK;
263 static HRESULT WINAPI OleDocumentView_GetInPlaceSite(IOleDocumentView *iface, IOleInPlaceSite **ppIPSite)
265 HTMLDocument *This = DOCVIEW_THIS(iface);
266 TRACE("(%p)->(%p)\n", This, ppIPSite);
268 if(!ppIPSite)
269 return E_INVALIDARG;
271 if(This->ipsite)
272 IOleInPlaceSite_AddRef(This->ipsite);
274 *ppIPSite = This->ipsite;
275 return S_OK;
278 static HRESULT WINAPI OleDocumentView_GetDocument(IOleDocumentView *iface, IUnknown **ppunk)
280 HTMLDocument *This = DOCVIEW_THIS(iface);
281 TRACE("(%p)->(%p)\n", This, ppunk);
283 if(!ppunk)
284 return E_INVALIDARG;
286 IHTMLDocument2_AddRef(HTMLDOC(This));
287 *ppunk = (IUnknown*)HTMLDOC(This);
288 return S_OK;
291 static HRESULT WINAPI OleDocumentView_SetRect(IOleDocumentView *iface, LPRECT prcView)
293 HTMLDocument *This = DOCVIEW_THIS(iface);
294 RECT rect;
296 TRACE("(%p)->(%p)\n", This, prcView);
298 if(!prcView)
299 return E_INVALIDARG;
301 if(This->hwnd) {
302 GetClientRect(This->hwnd, &rect);
303 if(memcmp(prcView, &rect, sizeof(RECT))) {
304 InvalidateRect(This->hwnd,NULL,TRUE);
305 SetWindowPos(This->hwnd, NULL, prcView->left, prcView->top, prcView->right,
306 prcView->bottom, SWP_NOZORDER | SWP_NOACTIVATE);
310 return S_OK;
313 static HRESULT WINAPI OleDocumentView_GetRect(IOleDocumentView *iface, LPRECT prcView)
315 HTMLDocument *This = DOCVIEW_THIS(iface);
317 TRACE("(%p)->(%p)\n", This, prcView);
319 if(!prcView)
320 return E_INVALIDARG;
322 GetClientRect(This->hwnd, prcView);
323 return S_OK;
326 static HRESULT WINAPI OleDocumentView_SetRectComplex(IOleDocumentView *iface, LPRECT prcView,
327 LPRECT prcHScroll, LPRECT prcVScroll, LPRECT prcSizeBox)
329 HTMLDocument *This = DOCVIEW_THIS(iface);
330 FIXME("(%p)->(%p %p %p %p)\n", This, prcView, prcHScroll, prcVScroll, prcSizeBox);
331 return E_NOTIMPL;
334 static HRESULT WINAPI OleDocumentView_Show(IOleDocumentView *iface, BOOL fShow)
336 HTMLDocument *This = DOCVIEW_THIS(iface);
337 HRESULT hres;
339 TRACE("(%p)->(%x)\n", This, fShow);
341 if(fShow) {
342 if(!This->ui_active) {
343 hres = activate_window(This);
344 if(FAILED(hres))
345 return hres;
347 ShowWindow(This->hwnd, SW_SHOW);
348 }else {
349 ShowWindow(This->hwnd, SW_HIDE);
352 return S_OK;
355 static HRESULT WINAPI OleDocumentView_UIActivate(IOleDocumentView *iface, BOOL fUIActivate)
357 HTMLDocument *This = DOCVIEW_THIS(iface);
358 HRESULT hres;
360 TRACE("(%p)->(%x)\n", This, fUIActivate);
362 if(!This->ipsite) {
363 FIXME("This->ipsite = NULL\n");
364 return E_FAIL;
367 if(fUIActivate) {
368 if(This->ui_active)
369 return S_OK;
371 if(!This->window_active) {
372 hres = activate_window(This);
373 if(FAILED(hres))
374 return hres;
377 hres = IOleInPlaceSite_OnUIActivate(This->ipsite);
378 if(SUCCEEDED(hres)) {
379 OLECHAR wszHTMLDocument[30];
380 LoadStringW(hInst, IDS_HTMLDOCUMENT, wszHTMLDocument,
381 sizeof(wszHTMLDocument)/sizeof(WCHAR));
382 IOleInPlaceFrame_SetActiveObject(This->frame, ACTOBJ(This), wszHTMLDocument);
383 }else {
384 FIXME("OnUIActivate failed: %08lx\n", hres);
385 IOleInPlaceFrame_Release(This->frame);
386 This->frame = NULL;
387 This->ui_active = FALSE;
388 return hres;
391 hres = IDocHostUIHandler_ShowUI(This->hostui, 0, ACTOBJ(This), CMDTARGET(This),
392 This->frame, NULL);
393 if(FAILED(hres))
394 IDocHostUIHandler_HideUI(This->hostui);
396 This->ui_active = TRUE;
397 }else {
398 This->window_active = FALSE;
399 if(This->ui_active) {
400 This->ui_active = FALSE;
401 if(This->frame)
402 IOleInPlaceFrame_SetActiveObject(This->frame, NULL, NULL);
403 if(This->hostui)
404 IDocHostUIHandler_HideUI(This->hostui);
405 if(This->ipsite)
406 IOleInPlaceSite_OnUIDeactivate(This->ipsite, FALSE);
409 return S_OK;
412 static HRESULT WINAPI OleDocumentView_Open(IOleDocumentView *iface)
414 HTMLDocument *This = DOCVIEW_THIS(iface);
415 FIXME("(%p)\n", This);
416 return E_NOTIMPL;
419 static HRESULT WINAPI OleDocumentView_CloseView(IOleDocumentView *iface, DWORD dwReserved)
421 HTMLDocument *This = DOCVIEW_THIS(iface);
422 TRACE("(%p)->(%lx)\n", This, dwReserved);
424 if(dwReserved)
425 WARN("dwReserved = %ld\n", dwReserved);
427 /* NOTE:
428 * Windows implementation calls QueryInterface(IID_IOleCommandTarget),
429 * QueryInterface(IID_IOleControlSite) and KillTimer
432 IOleDocumentView_Show(iface, FALSE);
434 return S_OK;
437 static HRESULT WINAPI OleDocumentView_SaveViewState(IOleDocumentView *iface, LPSTREAM pstm)
439 HTMLDocument *This = DOCVIEW_THIS(iface);
440 FIXME("(%p)->(%p)\n", This, pstm);
441 return E_NOTIMPL;
444 static HRESULT WINAPI OleDocumentView_ApplyViewState(IOleDocumentView *iface, LPSTREAM pstm)
446 HTMLDocument *This = DOCVIEW_THIS(iface);
447 FIXME("(%p)->(%p)\n", This, pstm);
448 return E_NOTIMPL;
451 static HRESULT WINAPI OleDocumentView_Clone(IOleDocumentView *iface, IOleInPlaceSite *pIPSiteNew,
452 IOleDocumentView **ppViewNew)
454 HTMLDocument *This = DOCVIEW_THIS(iface);
455 FIXME("(%p)->(%p %p)\n", This, pIPSiteNew, ppViewNew);
456 return E_NOTIMPL;
459 #undef DOCVIEW_THIS
461 static const IOleDocumentViewVtbl OleDocumentViewVtbl = {
462 OleDocumentView_QueryInterface,
463 OleDocumentView_AddRef,
464 OleDocumentView_Release,
465 OleDocumentView_SetInPlaceSite,
466 OleDocumentView_GetInPlaceSite,
467 OleDocumentView_GetDocument,
468 OleDocumentView_SetRect,
469 OleDocumentView_GetRect,
470 OleDocumentView_SetRectComplex,
471 OleDocumentView_Show,
472 OleDocumentView_UIActivate,
473 OleDocumentView_Open,
474 OleDocumentView_CloseView,
475 OleDocumentView_SaveViewState,
476 OleDocumentView_ApplyViewState,
477 OleDocumentView_Clone
480 /**********************************************************
481 * IViewObject implementation
484 #define VIEWOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, ViewObject2, iface)
486 static HRESULT WINAPI ViewObject_QueryInterface(IViewObject2 *iface, REFIID riid, void **ppvObject)
488 HTMLDocument *This = VIEWOBJ_THIS(iface);
489 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
492 static ULONG WINAPI ViewObject_AddRef(IViewObject2 *iface)
494 HTMLDocument *This = VIEWOBJ_THIS(iface);
495 return IHTMLDocument2_AddRef(HTMLDOC(This));
498 static ULONG WINAPI ViewObject_Release(IViewObject2 *iface)
500 HTMLDocument *This = VIEWOBJ_THIS(iface);
501 return IHTMLDocument2_Release(HTMLDOC(This));
504 static HRESULT WINAPI ViewObject_Draw(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
505 DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
506 LPCRECTL lprcWBounds, BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue), ULONG_PTR dwContinue)
508 HTMLDocument *This = VIEWOBJ_THIS(iface);
509 FIXME("(%p)->(%ld %ld %p %p %p %p %p %p %p %ld)\n", This, dwDrawAspect, lindex, pvAspect,
510 ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
511 return E_NOTIMPL;
514 static HRESULT WINAPI ViewObject_GetColorSet(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex, void *pvAspect,
515 DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet)
517 HTMLDocument *This = VIEWOBJ_THIS(iface);
518 FIXME("(%p)->(%ld %ld %p %p %p %p)\n", This, dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet);
519 return E_NOTIMPL;
522 static HRESULT WINAPI ViewObject_Freeze(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
523 void *pvAspect, DWORD *pdwFreeze)
525 HTMLDocument *This = VIEWOBJ_THIS(iface);
526 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, pvAspect, pdwFreeze);
527 return E_NOTIMPL;
530 static HRESULT WINAPI ViewObject_Unfreeze(IViewObject2 *iface, DWORD dwFreeze)
532 HTMLDocument *This = VIEWOBJ_THIS(iface);
533 FIXME("(%p)->(%ld)\n", This, dwFreeze);
534 return E_NOTIMPL;
537 static HRESULT WINAPI ViewObject_SetAdvise(IViewObject2 *iface, DWORD aspects, DWORD advf, IAdviseSink *pAdvSink)
539 HTMLDocument *This = VIEWOBJ_THIS(iface);
540 FIXME("(%p)->(%ld %ld %p)\n", This, aspects, advf, pAdvSink);
541 return E_NOTIMPL;
544 static HRESULT WINAPI ViewObject_GetAdvise(IViewObject2 *iface, DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink)
546 HTMLDocument *This = VIEWOBJ_THIS(iface);
547 FIXME("(%p)->(%p %p %p)\n", This, pAspects, pAdvf, ppAdvSink);
548 return E_NOTIMPL;
551 static HRESULT WINAPI ViewObject_GetExtent(IViewObject2 *iface, DWORD dwDrawAspect, LONG lindex,
552 DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
554 HTMLDocument *This = VIEWOBJ_THIS(iface);
555 FIXME("(%p)->(%ld %ld %p %p)\n", This, dwDrawAspect, lindex, ptd, lpsizel);
556 return E_NOTIMPL;
559 #undef VIEWOBJ_THIS
561 static const IViewObject2Vtbl ViewObjectVtbl = {
562 ViewObject_QueryInterface,
563 ViewObject_AddRef,
564 ViewObject_Release,
565 ViewObject_Draw,
566 ViewObject_GetColorSet,
567 ViewObject_Freeze,
568 ViewObject_Unfreeze,
569 ViewObject_SetAdvise,
570 ViewObject_GetAdvise,
571 ViewObject_GetExtent
574 void HTMLDocument_View_Init(HTMLDocument *This)
576 This->lpOleDocumentViewVtbl = &OleDocumentViewVtbl;
577 This->lpViewObject2Vtbl = &ViewObjectVtbl;
579 This->ipsite = NULL;
580 This->frame = NULL;
581 This->hwnd = NULL;
583 This->in_place_active = FALSE;
584 This->ui_active = FALSE;
585 This->window_active = FALSE;