Improve IConnectionPoint handling.
[wine] / dlls / shdocvw / oleobject.c
1 /*
2  * Implementation of IOleObject interfaces for WebBrowser control
3  *
4  * - IOleObject
5  * - IOleInPlaceObject
6  * - IOleControl
7  *
8  * Copyright 2001 John R. Sheets (for CodeWeavers)
9  * Copyright 2005 Jacek Caban
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26 #include <string.h>
27 #include "wine/debug.h"
28 #include "shdocvw.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
31
32 /**********************************************************************
33  * Implement the IOleObject interface for the WebBrowser control
34  */
35
36 #define OLEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleObject, iface)
37
38 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
39 {
40     WebBrowser *This = OLEOBJ_THIS(iface);
41     return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppv);
42 }
43
44 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
45 {
46     WebBrowser *This = OLEOBJ_THIS(iface);
47     return IWebBrowser_AddRef(WEBBROWSER(This));
48 }
49
50 static ULONG WINAPI OleObject_Release(IOleObject *iface)
51 {
52     WebBrowser *This = OLEOBJ_THIS(iface);
53     return IWebBrowser_Release(WEBBROWSER(This));
54 }
55
56 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
57 {
58     WebBrowser *This = OLEOBJ_THIS(iface);
59
60     TRACE("(%p)->(%p)\n", This, pClientSite);
61
62     if(This->client == pClientSite)
63         return S_OK;
64
65     if(This->client)
66         IOleClientSite_Release(This->client);
67
68     if(pClientSite)
69         IOleClientSite_AddRef(pClientSite);
70
71     This->client = pClientSite;
72     return S_OK;
73 }
74
75 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
76 {
77     WebBrowser *This = OLEOBJ_THIS(iface);
78
79     TRACE("(%p)->(%p)\n", This, ppClientSite);
80
81     if(!ppClientSite)
82         return E_INVALIDARG;
83
84     if(This->client)
85         IOleClientSite_AddRef(This->client);
86     *ppClientSite = This->client;
87
88     return S_OK;
89 }
90
91 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
92         LPCOLESTR szContainerObj)
93 {
94     WebBrowser *This = OLEOBJ_THIS(iface);
95     FIXME("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
96     return E_NOTIMPL;
97 }
98
99 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
100 {
101     WebBrowser *This = OLEOBJ_THIS(iface);
102     FIXME("(%p)->(%ld)\n", This, dwSaveOption);
103     return E_NOTIMPL;
104 }
105
106 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
107 {
108     WebBrowser *This = OLEOBJ_THIS(iface);
109     FIXME("(%p)->(%ld, %p)\n", This, dwWhichMoniker, pmk);
110     return E_NOTIMPL;
111 }
112
113 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
114         DWORD dwWhichMoniker, LPMONIKER *ppmk)
115 {
116     WebBrowser *This = OLEOBJ_THIS(iface);
117     FIXME("(%p)->(%ld, %ld, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
118     return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
122         BOOL fCreation, DWORD dwReserved)
123 {
124     WebBrowser *This = OLEOBJ_THIS(iface);
125     FIXME("(%p)->(%p, %d, %ld)\n", This, pDataObject, fCreation, dwReserved);
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
130         LPDATAOBJECT *ppDataObject)
131 {
132     WebBrowser *This = OLEOBJ_THIS(iface);
133     FIXME("(%p)->(%ld, %p)\n", This, dwReserved, ppDataObject);
134     return E_NOTIMPL;
135 }
136
137 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
138         LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
139 {
140     WebBrowser *This = OLEOBJ_THIS(iface);
141     HRESULT hres;
142
143     TRACE("(%p)->(%ld %p %p %ld %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
144             lprcPosRect);
145
146     switch (iVerb)
147     {
148     case OLEIVERB_INPLACEACTIVATE: {
149         IOleInPlaceSite *inplace;
150
151         TRACE("OLEIVERB_INPLACEACTIVATE\n");
152
153         if(!pActiveSite)
154             return E_INVALIDARG;
155
156         hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleInPlaceSite, (void**)&inplace);
157         if(FAILED(hres)) {
158             WARN("Could not get IOleInPlaceSite\n");
159             return hres;
160         }
161
162         hres = IOleInPlaceSite_CanInPlaceActivate(inplace);
163         if(hres != S_OK) {
164             WARN("CanInPlaceActivate returned: %08lx\n", hres);
165             IOleInPlaceSite_Release(inplace);
166             return E_FAIL;
167         }
168
169         hres = IOleInPlaceSite_GetWindow(inplace, &This->iphwnd);
170         if(FAILED(hres))
171             This->iphwnd = hwndParent;
172
173         IOleInPlaceSite_OnInPlaceActivate(inplace);
174
175         IOleInPlaceSite_GetWindowContext(inplace, &This->frame, &This->uiwindow,
176                                          &This->pos_rect, &This->clip_rect,
177                                          &This->frameinfo);
178
179         IOleInPlaceSite_Release(inplace);
180
181         if(This->client) {
182             IOleClientSite_ShowObject(This->client);
183             IOleClientSite_GetContainer(This->client, &This->container);
184         }
185
186         if(This->frame)
187             IOleInPlaceFrame_GetWindow(This->frame, &This->frame_hwnd);
188
189         return S_OK;
190     }
191     default:
192         FIXME("stub for %ld\n", iVerb);
193         break;
194     }
195
196     return E_NOTIMPL;
197 }
198
199 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
200 {
201     WebBrowser *This = OLEOBJ_THIS(iface);
202     TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
203     return OleRegEnumVerbs(&CLSID_WebBrowser, ppEnumOleVerb);
204 }
205
206 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
207 {
208     WebBrowser *This = OLEOBJ_THIS(iface);
209     FIXME("(%p)\n", This);
210     return E_NOTIMPL;
211 }
212
213 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
214 {
215     WebBrowser *This = OLEOBJ_THIS(iface);
216     FIXME("(%p)\n", This);
217     return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
221 {
222     WebBrowser *This = OLEOBJ_THIS(iface);
223     FIXME("(%p)->(%p)\n", This, pClsid);
224     return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
228         LPOLESTR* pszUserType)
229 {
230     WebBrowser *This = OLEOBJ_THIS(iface);
231     TRACE("(%p, %ld, %p)\n", This, dwFormOfType, pszUserType);
232     return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
233 }
234
235 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
236 {
237     WebBrowser *This = OLEOBJ_THIS(iface);
238     FIXME("(%p)->(%lx %p)\n", This, dwDrawAspect, psizel);
239     return E_NOTIMPL;
240 }
241
242 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
243 {
244     WebBrowser *This = OLEOBJ_THIS(iface);
245     FIXME("(%p)->(%lx, %p)\n", This, dwDrawAspect, psizel);
246     return E_NOTIMPL;
247 }
248
249 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
250         DWORD* pdwConnection)
251 {
252     WebBrowser *This = OLEOBJ_THIS(iface);
253     FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
254     return E_NOTIMPL;
255 }
256
257 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
258 {
259     WebBrowser *This = OLEOBJ_THIS(iface);
260     FIXME("(%p)->(%ld)\n", This, dwConnection);
261     return E_NOTIMPL;
262 }
263
264 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
265 {
266     WebBrowser *This = OLEOBJ_THIS(iface);
267     FIXME("(%p)->(%p)\n", This, ppenumAdvise);
268     return S_OK;
269 }
270
271 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
272 {
273     WebBrowser *This = OLEOBJ_THIS(iface);
274     HRESULT hres;
275
276     TRACE("(%p)->(%lx, %p)\n", This, dwAspect, pdwStatus);
277
278     hres = OleRegGetMiscStatus(&CLSID_WebBrowser, dwAspect, pdwStatus);
279
280     if (FAILED(hres))
281         *pdwStatus = 0;
282
283     return S_OK;
284 }
285
286 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
287 {
288     WebBrowser *This = OLEOBJ_THIS(iface);
289     FIXME("(%p)->(%p)\n", This, pLogpal);
290     return E_NOTIMPL;
291 }
292
293 #undef OLEOBJ_THIS
294
295 static const IOleObjectVtbl OleObjectVtbl =
296 {
297     OleObject_QueryInterface,
298     OleObject_AddRef,
299     OleObject_Release,
300     OleObject_SetClientSite,
301     OleObject_GetClientSite,
302     OleObject_SetHostNames,
303     OleObject_Close,
304     OleObject_SetMoniker,
305     OleObject_GetMoniker,
306     OleObject_InitFromData,
307     OleObject_GetClipboardData,
308     OleObject_DoVerb,
309     OleObject_EnumVerbs,
310     OleObject_Update,
311     OleObject_IsUpToDate,
312     OleObject_GetUserClassID,
313     OleObject_GetUserType,
314     OleObject_SetExtent,
315     OleObject_GetExtent,
316     OleObject_Advise,
317     OleObject_Unadvise,
318     OleObject_EnumAdvise,
319     OleObject_GetMiscStatus,
320     OleObject_SetColorScheme
321 };
322
323 /**********************************************************************
324  * Implement the IOleInPlaceObject interface
325  */
326
327 #define INPLACEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceObject, iface)
328
329 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
330         REFIID riid, LPVOID *ppobj)
331 {
332     WebBrowser *This = INPLACEOBJ_THIS(iface);
333     return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
334 }
335
336 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
337 {
338     WebBrowser *This = INPLACEOBJ_THIS(iface);
339     return IWebBrowser_AddRef(WEBBROWSER(This));
340 }
341
342 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
343 {
344     WebBrowser *This = INPLACEOBJ_THIS(iface);
345     return IWebBrowser_Release(WEBBROWSER(This));
346 }
347
348 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
349 {
350     WebBrowser *This = INPLACEOBJ_THIS(iface);
351
352     FIXME("(%p)->(%p)\n", This, phwnd);
353
354 #if 0
355     /* Create a fake window to fool MFC into believing that we actually
356      * have an implemented browser control.  Avoids the assertion.
357      */
358     HWND hwnd;
359     hwnd = CreateWindowA("BUTTON", "Web Control",
360                         WS_HSCROLL | WS_VSCROLL | WS_OVERLAPPEDWINDOW,
361                         CW_USEDEFAULT, CW_USEDEFAULT, 600,
362                         400, NULL, NULL, NULL, NULL);
363
364     *phwnd = hwnd;
365     TRACE ("Returning hwnd = %d\n", hwnd);
366 #endif
367
368     return S_OK;
369 }
370
371 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
372         BOOL fEnterMode)
373 {
374     WebBrowser *This = INPLACEOBJ_THIS(iface);
375     FIXME("(%p)->(%x)\n", This, fEnterMode);
376     return E_NOTIMPL;
377 }
378
379 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
380 {
381     WebBrowser *This = INPLACEOBJ_THIS(iface);
382     FIXME("(%p)\n", This);
383     return E_NOTIMPL;
384 }
385
386 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
387 {
388     WebBrowser *This = INPLACEOBJ_THIS(iface);
389     FIXME("(%p)\n", This);
390     return E_NOTIMPL;
391 }
392
393 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
394         LPCRECT lprcPosRect, LPCRECT lprcClipRect)
395 {
396     WebBrowser *This = INPLACEOBJ_THIS(iface);
397     FIXME("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
398     return E_NOTIMPL;
399 }
400
401 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
402 {
403     WebBrowser *This = INPLACEOBJ_THIS(iface);
404     FIXME("(%p)\n", This);
405     return E_NOTIMPL;
406 }
407
408 #undef INPLACEOBJ_THIS
409
410 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
411 {
412     OleInPlaceObject_QueryInterface,
413     OleInPlaceObject_AddRef,
414     OleInPlaceObject_Release,
415     OleInPlaceObject_GetWindow,
416     OleInPlaceObject_ContextSensitiveHelp,
417     OleInPlaceObject_InPlaceDeactivate,
418     OleInPlaceObject_UIDeactivate,
419     OleInPlaceObject_SetObjectRects,
420     OleInPlaceObject_ReactivateAndUndo
421 };
422
423 /**********************************************************************
424  * Implement the IOleControl interface
425  */
426
427 #define CONTROL_THIS(iface) DEFINE_THIS(WebBrowser, OleControl, iface)
428
429 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
430         REFIID riid, LPVOID *ppobj)
431 {
432     WebBrowser *This = CONTROL_THIS(iface);
433     return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
434 }
435
436 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
437 {
438     WebBrowser *This = CONTROL_THIS(iface);
439     return IWebBrowser_AddRef(WEBBROWSER(This));
440 }
441
442 static ULONG WINAPI OleControl_Release(IOleControl *iface)
443 {
444     WebBrowser *This = CONTROL_THIS(iface);
445     return IWebBrowser_Release(WEBBROWSER(This));
446 }
447
448 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
449 {
450     WebBrowser *This = CONTROL_THIS(iface);
451     FIXME("(%p)->(%p)\n", This, pCI);
452     return E_NOTIMPL;
453 }
454
455 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
456 {
457     WebBrowser *This = CONTROL_THIS(iface);
458     FIXME("(%p)->(%p)\n", This, pMsg);
459     return E_NOTIMPL;
460 }
461
462 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
463 {
464     WebBrowser *This = CONTROL_THIS(iface);
465     FIXME("(%p)->(%ld)\n", This, dispID);
466     return E_NOTIMPL;
467 }
468
469 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
470 {
471     WebBrowser *This = CONTROL_THIS(iface);
472     FIXME("(%p)->(%x)\n", This, bFreeze);
473     return E_NOTIMPL;
474 }
475
476 #undef CONTROL_THIS
477
478 static const IOleControlVtbl OleControlVtbl =
479 {
480     OleControl_QueryInterface,
481     OleControl_AddRef,
482     OleControl_Release,
483     OleControl_GetControlInfo,
484     OleControl_OnMnemonic,
485     OleControl_OnAmbientPropertyChange,
486     OleControl_FreezeEvents
487 };
488
489 void WebBrowser_OleObject_Init(WebBrowser *This)
490 {
491     This->lpOleObjectVtbl        = &OleObjectVtbl;
492     This->lpOleInPlaceObjectVtbl = &OleInPlaceObjectVtbl;
493     This->lpOleControlVtbl       = &OleControlVtbl;
494
495     This->client = NULL;
496     This->container = NULL;
497     This->iphwnd = NULL;
498     This->frame_hwnd = NULL;
499     This->frame = NULL;
500     This->uiwindow = NULL;
501
502     memset(&This->pos_rect, 0, sizeof(RECT));
503     memset(&This->clip_rect, 0, sizeof(RECT));
504     memset(&This->frameinfo, 0, sizeof(OLEINPLACEFRAMEINFO));
505 }
506
507 void WebBrowser_OleObject_Destroy(WebBrowser *This)
508 {
509     if(This->client)
510         IOleClientSite_Release(This->client);
511     if(This->container)
512         IOleContainer_Release(This->container);
513     if(This->frame)
514         IOleInPlaceFrame_Release(This->frame);
515     if(This->uiwindow)
516         IOleInPlaceUIWindow_Release(This->uiwindow);
517 }