Added IOleDocumentSite implementation.
[wine] / dlls / shdocvw / dochost.c
1 /*
2  * Copyright 2005 Jacek Caban for CodeWeavers
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 "wine/debug.h"
20 #include "shdocvw.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
23
24 static ATOM doc_view_atom = 0;
25
26 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
27 {
28     WebBrowser *This;
29
30     static const WCHAR wszTHIS[] = {'T','H','I','S',0};
31
32     if(msg == WM_CREATE) {
33         This = *(WebBrowser**)lParam;
34         ERR("create %p\n", This);
35         SetPropW(hwnd, wszTHIS, This);
36     }else {
37         This = GetPropW(hwnd, wszTHIS);
38     }
39
40     return DefWindowProcA(hwnd, msg, wParam, lParam);
41 }
42
43 void create_doc_view_hwnd(WebBrowser *This)
44 {
45     RECT rect;
46
47     static const WCHAR wszShell_DocObject_View[] =
48         {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
49
50     if(!doc_view_atom) {
51         static WNDCLASSEXW wndclass = {
52             sizeof(wndclass),
53             CS_PARENTDC,
54             doc_view_proc,
55             0, 0 /* native uses 4*/, NULL, NULL, NULL,
56             (HBRUSH)COLOR_WINDOWFRAME, NULL,
57             wszShell_DocObject_View,
58             NULL
59         };
60
61         wndclass.hInstance = shdocvw_hinstance;
62
63         doc_view_atom = RegisterClassExW(&wndclass);
64     }
65
66     GetWindowRect(This->shell_embedding_hwnd, &rect);
67     This->doc_view_hwnd = CreateWindowExW(0, wszShell_DocObject_View,
68          wszShell_DocObject_View,
69          WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP | WS_MAXIMIZEBOX,
70          rect.left, rect.top, rect.right, rect.bottom, This->shell_embedding_hwnd,
71          NULL, shdocvw_hinstance, This);
72 }
73
74 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(WebBrowser, DocHostUIHandler, iface)
75
76 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
77                                                       REFIID riid, void **ppv)
78 {
79     WebBrowser *This = DOCHOSTUI_THIS(iface);
80     return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
81 }
82
83 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
84 {
85     WebBrowser *This = DOCHOSTUI_THIS(iface);
86     return IOleClientSite_AddRef(CLIENTSITE(This));
87 }
88
89 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
90 {
91     WebBrowser *This = DOCHOSTUI_THIS(iface);
92     return IOleClientSite_Release(CLIENTSITE(This));
93 }
94
95 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
96          DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
97 {
98     WebBrowser *This = DOCHOSTUI_THIS(iface);
99     FIXME("(%p)->(%ld %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
100     return E_NOTIMPL;
101 }
102
103 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
104         DOCHOSTUIINFO *pInfo)
105 {
106     WebBrowser *This = DOCHOSTUI_THIS(iface);
107     IDocHostUIHandler *handler;
108     HRESULT hres;
109
110     TRACE("(%p)->(%p)\n", This, pInfo);
111
112     if(This->client) {
113         hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler, (void**)&handler);
114         if(SUCCEEDED(hres)) {
115             hres = IDocHostUIHandler_GetHostInfo(handler, pInfo);
116             IDocHostUIHandler_Release(handler);
117             if(SUCCEEDED(hres))
118                 return hres;
119         }
120     }
121
122     pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
123         | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
124         | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
125     return S_OK;
126 }
127
128 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
129         IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
130         IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
131 {
132     WebBrowser *This = DOCHOSTUI_THIS(iface);
133     FIXME("(%p)->(%ld %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
134           pFrame, pDoc);
135     return E_NOTIMPL;
136 }
137
138 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
139 {
140     WebBrowser *This = DOCHOSTUI_THIS(iface);
141     FIXME("(%p)\n", This);
142     return E_NOTIMPL;
143 }
144
145 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
146 {
147     WebBrowser *This = DOCHOSTUI_THIS(iface);
148     FIXME("(%p)\n", This);
149     return E_NOTIMPL;
150 }
151
152 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
153                                                       BOOL fEnable)
154 {
155     WebBrowser *This = DOCHOSTUI_THIS(iface);
156     FIXME("(%p)->(%x)\n", This, fEnable);
157     return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
161                                                            BOOL fActivate)
162 {
163     WebBrowser *This = DOCHOSTUI_THIS(iface);
164     FIXME("(%p)->(%x)\n", This, fActivate);
165     return E_NOTIMPL;
166 }
167
168 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
169                                                              BOOL fActivate)
170 {
171     WebBrowser *This = DOCHOSTUI_THIS(iface);
172     FIXME("(%p)->(%x)\n", This, fActivate);
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
177         LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
178 {
179     WebBrowser *This = DOCHOSTUI_THIS(iface);
180     FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
181     return E_NOTIMPL;
182 }
183
184 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
185         LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
186 {
187     WebBrowser *This = DOCHOSTUI_THIS(iface);
188     FIXME("(%p)->(%p %p %ld)\n", This, lpMsg, pguidCmdGroup, nCmdID);
189     return E_NOTIMPL;
190 }
191
192 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
193         LPOLESTR *pchKey, DWORD dw)
194 {
195     WebBrowser *This = DOCHOSTUI_THIS(iface);
196     FIXME("(%p)->(%p %ld)\n", This, pchKey, dw);
197     return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
201         IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
202 {
203     WebBrowser *This = DOCHOSTUI_THIS(iface);
204     FIXME("(%p)\n", This);
205     return E_NOTIMPL;
206 }
207
208 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
209         IDispatch **ppDispatch)
210 {
211     WebBrowser *This = DOCHOSTUI_THIS(iface);
212     FIXME("(%p)->(%p)\n", This, ppDispatch);
213     return E_NOTIMPL;
214 }
215
216 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
217         DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
218 {
219     WebBrowser *This = DOCHOSTUI_THIS(iface);
220     FIXME("(%p)->(%ld %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
221     return E_NOTIMPL;
222 }
223
224 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
225         IDataObject *pDO, IDataObject **ppDORet)
226 {
227     WebBrowser *This = DOCHOSTUI_THIS(iface);
228     FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
229     return E_NOTIMPL;
230 }
231
232 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
233         LPOLESTR *pchKey, DWORD dw)
234 {
235     WebBrowser *This = DOCHOSTUI_THIS(iface);
236     FIXME("(%p)->(%p %ld)\n", This, pchKey, dw);
237     return E_NOTIMPL;
238 }
239
240 #undef DOCHOSTUI_THIS
241
242 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
243     DocHostUIHandler_QueryInterface,
244     DocHostUIHandler_AddRef,
245     DocHostUIHandler_Release,
246     DocHostUIHandler_ShowContextMenu,
247     DocHostUIHandler_GetHostInfo,
248     DocHostUIHandler_ShowUI,
249     DocHostUIHandler_HideUI,
250     DocHostUIHandler_UpdateUI,
251     DocHostUIHandler_EnableModeless,
252     DocHostUIHandler_OnDocWindowActivate,
253     DocHostUIHandler_OnFrameWindowActivate,
254     DocHostUIHandler_ResizeBorder,
255     DocHostUIHandler_TranslateAccelerator,
256     DocHostUIHandler_GetOptionKeyPath,
257     DocHostUIHandler_GetDropTarget,
258     DocHostUIHandler_GetExternal,
259     DocHostUIHandler_TranslateUrl,
260     DocHostUIHandler_FilterDataObject,
261     DocHostUIHandler_GetOverrideKeyPath
262 };
263
264 void WebBrowser_DocHost_Init(WebBrowser *This)
265 {
266     This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
267
268     This->doc_view_hwnd = NULL;
269 }