Added CSIDL_MYVIDEO|MYPICTURES|MYMUSIC to _SHRegisterUserShellFolders.
[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 static ATOM shell_embedding_atom = 0;
33
34 static LRESULT WINAPI shell_embedding_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
35 {
36     return DefWindowProcA(hwnd, msg, wParam, lParam);
37 }
38
39 static void create_shell_embedding_hwnd(WebBrowser *This)
40 {
41     IOleInPlaceSite *inplace;
42     HWND parent = NULL;
43     HRESULT hres;
44
45     static const WCHAR wszShellEmbedding[] =
46         {'S','h','e','l','l',' ','E','m','b','e','d','d','i','n','g',0};
47
48     if(!shell_embedding_atom) {
49         static WNDCLASSEXW wndclass = {
50             sizeof(wndclass),
51             CS_DBLCLKS,
52             shell_embedding_proc,
53             0, 0 /* native uses 8 */, NULL, NULL, NULL,
54             (HBRUSH)COLOR_WINDOWFRAME, NULL,
55             wszShellEmbedding,
56             NULL
57         };
58         wndclass.hInstance = shdocvw_hinstance;
59
60         RegisterClassExW(&wndclass);
61     }
62
63     hres = IOleClientSite_QueryInterface(This->client, &IID_IOleInPlaceSite, (void**)&inplace);
64     if(SUCCEEDED(hres)) {
65         IOleInPlaceSite_GetWindow(inplace, &parent);
66         IOleInPlaceSite_Release(inplace);
67     }
68
69     This->shell_embedding_hwnd = CreateWindowExW(0, wszShellEmbedding, wszShellEmbedding,
70          WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP | WS_MAXIMIZEBOX,
71          0, 0, 0, 0, parent,
72          NULL, shdocvw_hinstance, This);
73 }
74
75 /**********************************************************************
76  * Implement the IOleObject interface for the WebBrowser control
77  */
78
79 #define OLEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleObject, iface)
80
81 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
82 {
83     WebBrowser *This = OLEOBJ_THIS(iface);
84     return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppv);
85 }
86
87 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
88 {
89     WebBrowser *This = OLEOBJ_THIS(iface);
90     return IWebBrowser_AddRef(WEBBROWSER(This));
91 }
92
93 static ULONG WINAPI OleObject_Release(IOleObject *iface)
94 {
95     WebBrowser *This = OLEOBJ_THIS(iface);
96     return IWebBrowser_Release(WEBBROWSER(This));
97 }
98
99 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
100 {
101     WebBrowser *This = OLEOBJ_THIS(iface);
102
103     TRACE("(%p)->(%p)\n", This, pClientSite);
104
105     if(This->client == pClientSite)
106         return S_OK;
107
108     if(This->doc_view_hwnd)
109         DestroyWindow(This->doc_view_hwnd);
110     if(This->shell_embedding_hwnd)
111         DestroyWindow(This->shell_embedding_hwnd);
112
113     if(This->client)
114         IOleClientSite_Release(This->client);
115
116     This->client = pClientSite;
117     if(!pClientSite)
118         return S_OK;
119     
120     IOleClientSite_AddRef(pClientSite);
121
122     create_shell_embedding_hwnd(This);
123
124     return S_OK;
125 }
126
127 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
128 {
129     WebBrowser *This = OLEOBJ_THIS(iface);
130
131     TRACE("(%p)->(%p)\n", This, ppClientSite);
132
133     if(!ppClientSite)
134         return E_INVALIDARG;
135
136     if(This->client)
137         IOleClientSite_AddRef(This->client);
138     *ppClientSite = This->client;
139
140     return S_OK;
141 }
142
143 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
144         LPCOLESTR szContainerObj)
145 {
146     WebBrowser *This = OLEOBJ_THIS(iface);
147     FIXME("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
148     return E_NOTIMPL;
149 }
150
151 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
152 {
153     WebBrowser *This = OLEOBJ_THIS(iface);
154     FIXME("(%p)->(%ld)\n", This, dwSaveOption);
155     return E_NOTIMPL;
156 }
157
158 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
159 {
160     WebBrowser *This = OLEOBJ_THIS(iface);
161     FIXME("(%p)->(%ld, %p)\n", This, dwWhichMoniker, pmk);
162     return E_NOTIMPL;
163 }
164
165 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
166         DWORD dwWhichMoniker, LPMONIKER *ppmk)
167 {
168     WebBrowser *This = OLEOBJ_THIS(iface);
169     FIXME("(%p)->(%ld, %ld, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
170     return E_NOTIMPL;
171 }
172
173 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
174         BOOL fCreation, DWORD dwReserved)
175 {
176     WebBrowser *This = OLEOBJ_THIS(iface);
177     FIXME("(%p)->(%p, %d, %ld)\n", This, pDataObject, fCreation, dwReserved);
178     return E_NOTIMPL;
179 }
180
181 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
182         LPDATAOBJECT *ppDataObject)
183 {
184     WebBrowser *This = OLEOBJ_THIS(iface);
185     FIXME("(%p)->(%ld, %p)\n", This, dwReserved, ppDataObject);
186     return E_NOTIMPL;
187 }
188
189 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
190         LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
191 {
192     WebBrowser *This = OLEOBJ_THIS(iface);
193     HRESULT hres;
194
195     TRACE("(%p)->(%ld %p %p %ld %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
196             lprcPosRect);
197
198     switch (iVerb)
199     {
200     case OLEIVERB_INPLACEACTIVATE: {
201         IOleInPlaceSite *inplace;
202
203         TRACE("OLEIVERB_INPLACEACTIVATE\n");
204
205         if(!pActiveSite)
206             return E_INVALIDARG;
207
208         hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleInPlaceSite, (void**)&inplace);
209         if(FAILED(hres)) {
210             WARN("Could not get IOleInPlaceSite\n");
211             return hres;
212         }
213
214         hres = IOleInPlaceSite_CanInPlaceActivate(inplace);
215         if(hres != S_OK) {
216             WARN("CanInPlaceActivate returned: %08lx\n", hres);
217             IOleInPlaceSite_Release(inplace);
218             return E_FAIL;
219         }
220
221         hres = IOleInPlaceSite_GetWindow(inplace, &This->iphwnd);
222         if(FAILED(hres))
223             This->iphwnd = hwndParent;
224
225         IOleInPlaceSite_OnInPlaceActivate(inplace);
226
227         IOleInPlaceSite_GetWindowContext(inplace, &This->frame, &This->uiwindow,
228                                          &This->pos_rect, &This->clip_rect,
229                                          &This->frameinfo);
230
231
232         IOleInPlaceSite_Release(inplace);
233
234         SetWindowPos(This->shell_embedding_hwnd, NULL,
235                      This->pos_rect.left, This->pos_rect.top,
236                      This->pos_rect.right-This->pos_rect.left,
237                      This->pos_rect.bottom-This->pos_rect.top,
238                      SWP_NOZORDER | SWP_SHOWWINDOW);
239
240
241         if(This->client) {
242             IOleClientSite_ShowObject(This->client);
243             IOleClientSite_GetContainer(This->client, &This->container);
244         }
245
246         if(This->frame)
247             IOleInPlaceFrame_GetWindow(This->frame, &This->frame_hwnd);
248
249         return S_OK;
250     }
251     default:
252         FIXME("stub for %ld\n", iVerb);
253         break;
254     }
255
256     return E_NOTIMPL;
257 }
258
259 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
260 {
261     WebBrowser *This = OLEOBJ_THIS(iface);
262     TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
263     return OleRegEnumVerbs(&CLSID_WebBrowser, ppEnumOleVerb);
264 }
265
266 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
267 {
268     WebBrowser *This = OLEOBJ_THIS(iface);
269     FIXME("(%p)\n", This);
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
274 {
275     WebBrowser *This = OLEOBJ_THIS(iface);
276     FIXME("(%p)\n", This);
277     return E_NOTIMPL;
278 }
279
280 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
281 {
282     WebBrowser *This = OLEOBJ_THIS(iface);
283     FIXME("(%p)->(%p)\n", This, pClsid);
284     return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
288         LPOLESTR* pszUserType)
289 {
290     WebBrowser *This = OLEOBJ_THIS(iface);
291     TRACE("(%p, %ld, %p)\n", This, dwFormOfType, pszUserType);
292     return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
293 }
294
295 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
296 {
297     WebBrowser *This = OLEOBJ_THIS(iface);
298     FIXME("(%p)->(%lx %p)\n", This, dwDrawAspect, psizel);
299     return E_NOTIMPL;
300 }
301
302 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
303 {
304     WebBrowser *This = OLEOBJ_THIS(iface);
305     FIXME("(%p)->(%lx, %p)\n", This, dwDrawAspect, psizel);
306     return E_NOTIMPL;
307 }
308
309 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
310         DWORD* pdwConnection)
311 {
312     WebBrowser *This = OLEOBJ_THIS(iface);
313     FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
314     return E_NOTIMPL;
315 }
316
317 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
318 {
319     WebBrowser *This = OLEOBJ_THIS(iface);
320     FIXME("(%p)->(%ld)\n", This, dwConnection);
321     return E_NOTIMPL;
322 }
323
324 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
325 {
326     WebBrowser *This = OLEOBJ_THIS(iface);
327     FIXME("(%p)->(%p)\n", This, ppenumAdvise);
328     return S_OK;
329 }
330
331 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
332 {
333     WebBrowser *This = OLEOBJ_THIS(iface);
334     HRESULT hres;
335
336     TRACE("(%p)->(%lx, %p)\n", This, dwAspect, pdwStatus);
337
338     hres = OleRegGetMiscStatus(&CLSID_WebBrowser, dwAspect, pdwStatus);
339
340     if (FAILED(hres))
341         *pdwStatus = 0;
342
343     return S_OK;
344 }
345
346 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
347 {
348     WebBrowser *This = OLEOBJ_THIS(iface);
349     FIXME("(%p)->(%p)\n", This, pLogpal);
350     return E_NOTIMPL;
351 }
352
353 #undef OLEOBJ_THIS
354
355 static const IOleObjectVtbl OleObjectVtbl =
356 {
357     OleObject_QueryInterface,
358     OleObject_AddRef,
359     OleObject_Release,
360     OleObject_SetClientSite,
361     OleObject_GetClientSite,
362     OleObject_SetHostNames,
363     OleObject_Close,
364     OleObject_SetMoniker,
365     OleObject_GetMoniker,
366     OleObject_InitFromData,
367     OleObject_GetClipboardData,
368     OleObject_DoVerb,
369     OleObject_EnumVerbs,
370     OleObject_Update,
371     OleObject_IsUpToDate,
372     OleObject_GetUserClassID,
373     OleObject_GetUserType,
374     OleObject_SetExtent,
375     OleObject_GetExtent,
376     OleObject_Advise,
377     OleObject_Unadvise,
378     OleObject_EnumAdvise,
379     OleObject_GetMiscStatus,
380     OleObject_SetColorScheme
381 };
382
383 /**********************************************************************
384  * Implement the IOleInPlaceObject interface
385  */
386
387 #define INPLACEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceObject, iface)
388
389 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
390         REFIID riid, LPVOID *ppobj)
391 {
392     WebBrowser *This = INPLACEOBJ_THIS(iface);
393     return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
394 }
395
396 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
397 {
398     WebBrowser *This = INPLACEOBJ_THIS(iface);
399     return IWebBrowser_AddRef(WEBBROWSER(This));
400 }
401
402 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
403 {
404     WebBrowser *This = INPLACEOBJ_THIS(iface);
405     return IWebBrowser_Release(WEBBROWSER(This));
406 }
407
408 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
409 {
410     WebBrowser *This = INPLACEOBJ_THIS(iface);
411
412     FIXME("(%p)->(%p)\n", This, phwnd);
413
414 #if 0
415     /* Create a fake window to fool MFC into believing that we actually
416      * have an implemented browser control.  Avoids the assertion.
417      */
418     HWND hwnd;
419     hwnd = CreateWindowA("BUTTON", "Web Control",
420                         WS_HSCROLL | WS_VSCROLL | WS_OVERLAPPEDWINDOW,
421                         CW_USEDEFAULT, CW_USEDEFAULT, 600,
422                         400, NULL, NULL, NULL, NULL);
423
424     *phwnd = hwnd;
425     TRACE ("Returning hwnd = %d\n", hwnd);
426 #endif
427
428     return S_OK;
429 }
430
431 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
432         BOOL fEnterMode)
433 {
434     WebBrowser *This = INPLACEOBJ_THIS(iface);
435     FIXME("(%p)->(%x)\n", This, fEnterMode);
436     return E_NOTIMPL;
437 }
438
439 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
440 {
441     WebBrowser *This = INPLACEOBJ_THIS(iface);
442     FIXME("(%p)\n", This);
443     return E_NOTIMPL;
444 }
445
446 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
447 {
448     WebBrowser *This = INPLACEOBJ_THIS(iface);
449     FIXME("(%p)\n", This);
450     return E_NOTIMPL;
451 }
452
453 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
454         LPCRECT lprcPosRect, LPCRECT lprcClipRect)
455 {
456     WebBrowser *This = INPLACEOBJ_THIS(iface);
457     FIXME("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
458     return E_NOTIMPL;
459 }
460
461 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
462 {
463     WebBrowser *This = INPLACEOBJ_THIS(iface);
464     FIXME("(%p)\n", This);
465     return E_NOTIMPL;
466 }
467
468 #undef INPLACEOBJ_THIS
469
470 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
471 {
472     OleInPlaceObject_QueryInterface,
473     OleInPlaceObject_AddRef,
474     OleInPlaceObject_Release,
475     OleInPlaceObject_GetWindow,
476     OleInPlaceObject_ContextSensitiveHelp,
477     OleInPlaceObject_InPlaceDeactivate,
478     OleInPlaceObject_UIDeactivate,
479     OleInPlaceObject_SetObjectRects,
480     OleInPlaceObject_ReactivateAndUndo
481 };
482
483 /**********************************************************************
484  * Implement the IOleControl interface
485  */
486
487 #define CONTROL_THIS(iface) DEFINE_THIS(WebBrowser, OleControl, iface)
488
489 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
490         REFIID riid, LPVOID *ppobj)
491 {
492     WebBrowser *This = CONTROL_THIS(iface);
493     return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
494 }
495
496 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
497 {
498     WebBrowser *This = CONTROL_THIS(iface);
499     return IWebBrowser_AddRef(WEBBROWSER(This));
500 }
501
502 static ULONG WINAPI OleControl_Release(IOleControl *iface)
503 {
504     WebBrowser *This = CONTROL_THIS(iface);
505     return IWebBrowser_Release(WEBBROWSER(This));
506 }
507
508 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
509 {
510     WebBrowser *This = CONTROL_THIS(iface);
511     FIXME("(%p)->(%p)\n", This, pCI);
512     return E_NOTIMPL;
513 }
514
515 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
516 {
517     WebBrowser *This = CONTROL_THIS(iface);
518     FIXME("(%p)->(%p)\n", This, pMsg);
519     return E_NOTIMPL;
520 }
521
522 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
523 {
524     WebBrowser *This = CONTROL_THIS(iface);
525     FIXME("(%p)->(%ld)\n", This, dispID);
526     return E_NOTIMPL;
527 }
528
529 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
530 {
531     WebBrowser *This = CONTROL_THIS(iface);
532     FIXME("(%p)->(%x)\n", This, bFreeze);
533     return E_NOTIMPL;
534 }
535
536 #undef CONTROL_THIS
537
538 static const IOleControlVtbl OleControlVtbl =
539 {
540     OleControl_QueryInterface,
541     OleControl_AddRef,
542     OleControl_Release,
543     OleControl_GetControlInfo,
544     OleControl_OnMnemonic,
545     OleControl_OnAmbientPropertyChange,
546     OleControl_FreezeEvents
547 };
548
549 void WebBrowser_OleObject_Init(WebBrowser *This)
550 {
551     This->lpOleObjectVtbl        = &OleObjectVtbl;
552     This->lpOleInPlaceObjectVtbl = &OleInPlaceObjectVtbl;
553     This->lpOleControlVtbl       = &OleControlVtbl;
554
555     This->client = NULL;
556     This->container = NULL;
557     This->iphwnd = NULL;
558     This->frame_hwnd = NULL;
559     This->frame = NULL;
560     This->uiwindow = NULL;
561     This->shell_embedding_hwnd = NULL;
562
563     memset(&This->pos_rect, 0, sizeof(RECT));
564     memset(&This->clip_rect, 0, sizeof(RECT));
565     memset(&This->frameinfo, 0, sizeof(OLEINPLACEFRAMEINFO));
566 }
567
568 void WebBrowser_OleObject_Destroy(WebBrowser *This)
569 {
570     if(This->client)
571         IOleObject_SetClientSite(OLEOBJ(This), NULL);
572     if(This->container)
573         IOleContainer_Release(This->container);
574     if(This->frame)
575         IOleInPlaceFrame_Release(This->frame);
576     if(This->uiwindow)
577         IOleInPlaceUIWindow_Release(This->uiwindow);
578 }