Sync with trunk r58687.
[reactos.git] / dll / win32 / 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26 //#include <string.h>
27 #include <wine/debug.h>
28 #include "shdocvw.h"
29 //#include "htiframe.h"
30 #include <idispids.h>
31 #include <mshtmdid.h>
32
33 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
34
35 /* shlwapi.dll */
36 HWND WINAPI SHSetParentHwnd(HWND hWnd, HWND hWndParent);
37
38 static ATOM shell_embedding_atom = 0;
39
40 static LRESULT resize_window(WebBrowser *This, LONG width, LONG height)
41 {
42 if(This->doc_host.hwnd)
43 SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
44 SWP_NOZORDER | SWP_NOACTIVATE);
45
46 return 0;
47 }
48
49 static LRESULT WINAPI shell_embedding_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
50 {
51 WebBrowser *This;
52
53 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
54
55 if(msg == WM_CREATE) {
56 This = *(WebBrowser**)lParam;
57 SetPropW(hwnd, wszTHIS, This);
58 }else {
59 This = GetPropW(hwnd, wszTHIS);
60 }
61
62 switch(msg) {
63 case WM_SIZE:
64 return resize_window(This, LOWORD(lParam), HIWORD(lParam));
65 case WM_DOCHOSTTASK:
66 return process_dochost_task(&This->doc_host, lParam);
67 }
68
69 return DefWindowProcW(hwnd, msg, wParam, lParam);
70 }
71
72 static void create_shell_embedding_hwnd(WebBrowser *This)
73 {
74 IOleInPlaceSite *inplace;
75 HWND parent = NULL;
76 HRESULT hres;
77
78 static const WCHAR wszShellEmbedding[] =
79 {'S','h','e','l','l',' ','E','m','b','e','d','d','i','n','g',0};
80
81 if(!shell_embedding_atom) {
82 static WNDCLASSEXW wndclass = {
83 sizeof(wndclass),
84 CS_DBLCLKS,
85 shell_embedding_proc,
86 0, 0 /* native uses 8 */, NULL, NULL, NULL,
87 (HBRUSH)(COLOR_WINDOW + 1), NULL,
88 wszShellEmbedding,
89 NULL
90 };
91 wndclass.hInstance = shdocvw_hinstance;
92
93 RegisterClassExW(&wndclass);
94 }
95
96 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleInPlaceSite, (void**)&inplace);
97 if(SUCCEEDED(hres)) {
98 IOleInPlaceSite_GetWindow(inplace, &parent);
99 IOleInPlaceSite_Release(inplace);
100 }
101
102 This->doc_host.frame_hwnd = This->shell_embedding_hwnd = CreateWindowExW(
103 WS_EX_WINDOWEDGE,
104 wszShellEmbedding, wszShellEmbedding,
105 WS_CLIPSIBLINGS | WS_CLIPCHILDREN
106 | (parent ? WS_CHILD | WS_TABSTOP : WS_POPUP | WS_MAXIMIZEBOX),
107 0, 0, 0, 0, parent,
108 NULL, shdocvw_hinstance, This);
109
110 TRACE("parent=%p hwnd=%p\n", parent, This->shell_embedding_hwnd);
111 }
112
113 static HRESULT activate_inplace(WebBrowser *This, IOleClientSite *active_site)
114 {
115 HWND parent_hwnd;
116 HRESULT hres;
117
118 if(This->inplace)
119 return S_OK;
120
121 if(!active_site)
122 return E_INVALIDARG;
123
124 hres = IOleClientSite_QueryInterface(active_site, &IID_IOleInPlaceSite,
125 (void**)&This->inplace);
126 if(FAILED(hres)) {
127 WARN("Could not get IOleInPlaceSite\n");
128 return hres;
129 }
130
131 hres = IOleInPlaceSite_CanInPlaceActivate(This->inplace);
132 if(hres != S_OK) {
133 WARN("CanInPlaceActivate returned: %08x\n", hres);
134 IOleInPlaceSite_Release(This->inplace);
135 return E_FAIL;
136 }
137
138 hres = IOleInPlaceSite_GetWindow(This->inplace, &parent_hwnd);
139 if(SUCCEEDED(hres))
140 SHSetParentHwnd(This->shell_embedding_hwnd, parent_hwnd);
141
142 IOleInPlaceSite_OnInPlaceActivate(This->inplace);
143
144 This->frameinfo.cb = sizeof(OLEINPLACEFRAMEINFO);
145 IOleInPlaceSite_GetWindowContext(This->inplace, &This->doc_host.frame, &This->uiwindow,
146 &This->pos_rect, &This->clip_rect,
147 &This->frameinfo);
148
149 SetWindowPos(This->shell_embedding_hwnd, NULL,
150 This->pos_rect.left, This->pos_rect.top,
151 This->pos_rect.right-This->pos_rect.left,
152 This->pos_rect.bottom-This->pos_rect.top,
153 SWP_NOZORDER | SWP_SHOWWINDOW);
154
155 if(This->client) {
156 IOleContainer *container;
157
158 IOleClientSite_ShowObject(This->client);
159
160 hres = IOleClientSite_GetContainer(This->client, &container);
161 if(SUCCEEDED(hres)) {
162 if(This->container)
163 IOleContainer_Release(This->container);
164 This->container = container;
165 }
166 }
167
168 if(This->doc_host.frame)
169 IOleInPlaceFrame_GetWindow(This->doc_host.frame, &This->frame_hwnd);
170
171 return S_OK;
172 }
173
174 static HRESULT activate_ui(WebBrowser *This, IOleClientSite *active_site)
175 {
176 HRESULT hres;
177
178 static const WCHAR wszitem[] = {'i','t','e','m',0};
179
180 if(This->inplace)
181 {
182 if(This->shell_embedding_hwnd)
183 ShowWindow(This->shell_embedding_hwnd, SW_SHOW);
184 return S_OK;
185 }
186
187 hres = activate_inplace(This, active_site);
188 if(FAILED(hres))
189 return hres;
190
191 IOleInPlaceSite_OnUIActivate(This->inplace);
192
193 if(This->doc_host.frame)
194 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, ACTIVEOBJ(This), wszitem);
195 if(This->uiwindow)
196 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, ACTIVEOBJ(This), wszitem);
197
198 if(This->doc_host.frame)
199 IOleInPlaceFrame_SetMenu(This->doc_host.frame, NULL, NULL, This->shell_embedding_hwnd);
200
201 SetFocus(This->shell_embedding_hwnd);
202
203 return S_OK;
204 }
205
206 static HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
207 {
208 IDispatch *disp = NULL;
209 DISPPARAMS dispparams = {NULL, 0};
210 HRESULT hres;
211
212 VariantInit(res);
213
214 if(!client)
215 return S_OK;
216
217 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
218 if(FAILED(hres)) {
219 TRACE("Could not get IDispatch\n");
220 return hres;
221 }
222
223 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
224 DISPATCH_PROPERTYGET, &dispparams, res, NULL, NULL);
225
226 IDispatch_Release(disp);
227
228 return hres;
229 }
230
231 static HRESULT on_offlineconnected_change(WebBrowser *This)
232 {
233 VARIANT offline;
234
235 get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
236
237 if(V_VT(&offline) == VT_BOOL)
238 IWebBrowser2_put_Offline(WEBBROWSER2(This), V_BOOL(&offline));
239 else if(V_VT(&offline) != VT_EMPTY)
240 WARN("wrong V_VT(silent) %d\n", V_VT(&offline));
241
242 return S_OK;
243 }
244
245 static HRESULT on_silent_change(WebBrowser *This)
246 {
247 VARIANT silent;
248
249 get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
250
251 if(V_VT(&silent) == VT_BOOL)
252 IWebBrowser2_put_Silent(WEBBROWSER2(This), V_BOOL(&silent));
253 else if(V_VT(&silent) != VT_EMPTY)
254 WARN("wrong V_VT(silent) %d\n", V_VT(&silent));
255
256 return S_OK;
257 }
258
259 static void release_client_site(WebBrowser *This)
260 {
261 release_dochost_client(&This->doc_host);
262
263 if(This->shell_embedding_hwnd) {
264 DestroyWindow(This->shell_embedding_hwnd);
265 This->shell_embedding_hwnd = NULL;
266 }
267
268 if(This->inplace) {
269 IOleInPlaceSite_Release(This->inplace);
270 This->inplace = NULL;
271 }
272
273 if(This->container) {
274 IOleContainer_Release(This->container);
275 This->container = NULL;
276 }
277
278 if(This->uiwindow) {
279 IOleInPlaceUIWindow_Release(This->uiwindow);
280 This->uiwindow = NULL;
281 }
282
283 if(This->client) {
284 IOleClientSite_Release(This->client);
285 This->client = NULL;
286 }
287 }
288
289 /**********************************************************************
290 * Implement the IOleObject interface for the WebBrowser control
291 */
292
293 #define OLEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleObject, iface)
294
295 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
296 {
297 WebBrowser *This = OLEOBJ_THIS(iface);
298 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppv);
299 }
300
301 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
302 {
303 WebBrowser *This = OLEOBJ_THIS(iface);
304 return IWebBrowser_AddRef(WEBBROWSER(This));
305 }
306
307 static ULONG WINAPI OleObject_Release(IOleObject *iface)
308 {
309 WebBrowser *This = OLEOBJ_THIS(iface);
310 return IWebBrowser_Release(WEBBROWSER(This));
311 }
312
313 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
314 {
315 WebBrowser *This = OLEOBJ_THIS(iface);
316 IDocHostUIHandler *hostui;
317 IOleContainer *container;
318 IDispatch *disp;
319 HRESULT hres;
320
321 TRACE("(%p)->(%p)\n", This, pClientSite);
322
323 if(This->client == pClientSite)
324 return S_OK;
325
326 release_client_site(This);
327
328 if(!pClientSite) {
329 if(This->doc_host.document)
330 deactivate_document(&This->doc_host);
331 return S_OK;
332 }
333
334 IOleClientSite_AddRef(pClientSite);
335 This->client = pClientSite;
336
337 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
338 (void**)&disp);
339 if(SUCCEEDED(hres))
340 This->doc_host.client_disp = disp;
341
342 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
343 (void**)&hostui);
344 if(SUCCEEDED(hres))
345 This->doc_host.hostui = hostui;
346
347 hres = IOleClientSite_GetContainer(This->client, &container);
348 if(SUCCEEDED(hres)) {
349 ITargetContainer *target_container;
350
351 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
352 (void**)&target_container);
353 if(SUCCEEDED(hres)) {
354 FIXME("Unsupported ITargetContainer\n");
355 ITargetContainer_Release(target_container);
356 }
357
358 IOleContainer_Release(container);
359 }
360
361 create_shell_embedding_hwnd(This);
362
363 on_offlineconnected_change(This);
364 on_silent_change(This);
365
366 return S_OK;
367 }
368
369 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
370 {
371 WebBrowser *This = OLEOBJ_THIS(iface);
372
373 TRACE("(%p)->(%p)\n", This, ppClientSite);
374
375 if(!ppClientSite)
376 return E_INVALIDARG;
377
378 if(This->client)
379 IOleClientSite_AddRef(This->client);
380 *ppClientSite = This->client;
381
382 return S_OK;
383 }
384
385 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
386 LPCOLESTR szContainerObj)
387 {
388 WebBrowser *This = OLEOBJ_THIS(iface);
389
390 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
391
392 /* We have nothing to do here. */
393 return S_OK;
394 }
395
396 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
397 {
398 WebBrowser *This = OLEOBJ_THIS(iface);
399 FIXME("(%p)->(%d)\n", This, dwSaveOption);
400 return E_NOTIMPL;
401 }
402
403 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
404 {
405 WebBrowser *This = OLEOBJ_THIS(iface);
406 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
407 return E_NOTIMPL;
408 }
409
410 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
411 DWORD dwWhichMoniker, LPMONIKER *ppmk)
412 {
413 WebBrowser *This = OLEOBJ_THIS(iface);
414 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
415 return E_NOTIMPL;
416 }
417
418 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
419 BOOL fCreation, DWORD dwReserved)
420 {
421 WebBrowser *This = OLEOBJ_THIS(iface);
422 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
423 return E_NOTIMPL;
424 }
425
426 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
427 LPDATAOBJECT *ppDataObject)
428 {
429 WebBrowser *This = OLEOBJ_THIS(iface);
430 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
431 return E_NOTIMPL;
432 }
433
434 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
435 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
436 {
437 WebBrowser *This = OLEOBJ_THIS(iface);
438
439 TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
440 lprcPosRect);
441
442 switch (iVerb)
443 {
444 case OLEIVERB_SHOW:
445 TRACE("OLEIVERB_SHOW\n");
446 return activate_ui(This, pActiveSite);
447 case OLEIVERB_UIACTIVATE:
448 TRACE("OLEIVERB_UIACTIVATE\n");
449 return activate_ui(This, pActiveSite);
450 case OLEIVERB_INPLACEACTIVATE:
451 TRACE("OLEIVERB_INPLACEACTIVATE\n");
452 return activate_inplace(This, pActiveSite);
453 case OLEIVERB_HIDE:
454 TRACE("OLEIVERB_HIDE\n");
455 if(This->shell_embedding_hwnd)
456 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
457 return S_OK;
458 default:
459 FIXME("stub for %d\n", iVerb);
460 break;
461 }
462
463 return E_NOTIMPL;
464 }
465
466 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
467 {
468 WebBrowser *This = OLEOBJ_THIS(iface);
469 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
470 return OleRegEnumVerbs(&CLSID_WebBrowser, ppEnumOleVerb);
471 }
472
473 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
474 {
475 WebBrowser *This = OLEOBJ_THIS(iface);
476 FIXME("(%p)\n", This);
477 return E_NOTIMPL;
478 }
479
480 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
481 {
482 WebBrowser *This = OLEOBJ_THIS(iface);
483 FIXME("(%p)\n", This);
484 return E_NOTIMPL;
485 }
486
487 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
488 {
489 WebBrowser *This = OLEOBJ_THIS(iface);
490 FIXME("(%p)->(%p)\n", This, pClsid);
491 return E_NOTIMPL;
492 }
493
494 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
495 LPOLESTR* pszUserType)
496 {
497 WebBrowser *This = OLEOBJ_THIS(iface);
498 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
499 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
500 }
501
502 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
503 {
504 WebBrowser *This = OLEOBJ_THIS(iface);
505
506 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
507
508 /* Tests show that dwDrawAspect is ignored */
509 This->extent = *psizel;
510 return S_OK;
511 }
512
513 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
514 {
515 WebBrowser *This = OLEOBJ_THIS(iface);
516
517 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
518
519 /* Tests show that dwDrawAspect is ignored */
520 *psizel = This->extent;
521 return S_OK;
522 }
523
524 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
525 DWORD* pdwConnection)
526 {
527 WebBrowser *This = OLEOBJ_THIS(iface);
528 FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
529 return E_NOTIMPL;
530 }
531
532 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
533 {
534 WebBrowser *This = OLEOBJ_THIS(iface);
535 FIXME("(%p)->(%d)\n", This, dwConnection);
536 return E_NOTIMPL;
537 }
538
539 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
540 {
541 WebBrowser *This = OLEOBJ_THIS(iface);
542 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
543 return S_OK;
544 }
545
546 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
547 {
548 WebBrowser *This = OLEOBJ_THIS(iface);
549
550 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
551
552 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
553 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
554
555 return S_OK;
556 }
557
558 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
559 {
560 WebBrowser *This = OLEOBJ_THIS(iface);
561 FIXME("(%p)->(%p)\n", This, pLogpal);
562 return E_NOTIMPL;
563 }
564
565 #undef OLEOBJ_THIS
566
567 static const IOleObjectVtbl OleObjectVtbl =
568 {
569 OleObject_QueryInterface,
570 OleObject_AddRef,
571 OleObject_Release,
572 OleObject_SetClientSite,
573 OleObject_GetClientSite,
574 OleObject_SetHostNames,
575 OleObject_Close,
576 OleObject_SetMoniker,
577 OleObject_GetMoniker,
578 OleObject_InitFromData,
579 OleObject_GetClipboardData,
580 OleObject_DoVerb,
581 OleObject_EnumVerbs,
582 OleObject_Update,
583 OleObject_IsUpToDate,
584 OleObject_GetUserClassID,
585 OleObject_GetUserType,
586 OleObject_SetExtent,
587 OleObject_GetExtent,
588 OleObject_Advise,
589 OleObject_Unadvise,
590 OleObject_EnumAdvise,
591 OleObject_GetMiscStatus,
592 OleObject_SetColorScheme
593 };
594
595 /**********************************************************************
596 * Implement the IOleInPlaceObject interface
597 */
598
599 #define INPLACEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceObject, iface)
600
601 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
602 REFIID riid, LPVOID *ppobj)
603 {
604 WebBrowser *This = INPLACEOBJ_THIS(iface);
605 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
606 }
607
608 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
609 {
610 WebBrowser *This = INPLACEOBJ_THIS(iface);
611 return IWebBrowser_AddRef(WEBBROWSER(This));
612 }
613
614 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
615 {
616 WebBrowser *This = INPLACEOBJ_THIS(iface);
617 return IWebBrowser_Release(WEBBROWSER(This));
618 }
619
620 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
621 {
622 WebBrowser *This = INPLACEOBJ_THIS(iface);
623
624 TRACE("(%p)->(%p)\n", This, phwnd);
625
626 *phwnd = This->shell_embedding_hwnd;
627 return S_OK;
628 }
629
630 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
631 BOOL fEnterMode)
632 {
633 WebBrowser *This = INPLACEOBJ_THIS(iface);
634 FIXME("(%p)->(%x)\n", This, fEnterMode);
635 return E_NOTIMPL;
636 }
637
638 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
639 {
640 WebBrowser *This = INPLACEOBJ_THIS(iface);
641 FIXME("(%p)\n", This);
642
643 if(This->inplace) {
644 IOleInPlaceSite_Release(This->inplace);
645 This->inplace = NULL;
646 }
647
648 return S_OK;
649 }
650
651 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
652 {
653 WebBrowser *This = INPLACEOBJ_THIS(iface);
654 FIXME("(%p)\n", This);
655 return E_NOTIMPL;
656 }
657
658 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
659 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
660 {
661 WebBrowser *This = INPLACEOBJ_THIS(iface);
662
663 TRACE("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
664
665 This->pos_rect = *lprcPosRect;
666
667 if(lprcClipRect)
668 This->clip_rect = *lprcClipRect;
669
670 if(This->shell_embedding_hwnd) {
671 SetWindowPos(This->shell_embedding_hwnd, NULL,
672 lprcPosRect->left, lprcPosRect->top,
673 lprcPosRect->right-lprcPosRect->left,
674 lprcPosRect->bottom-lprcPosRect->top,
675 SWP_NOZORDER | SWP_NOACTIVATE);
676 }
677
678 return S_OK;
679 }
680
681 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
682 {
683 WebBrowser *This = INPLACEOBJ_THIS(iface);
684 FIXME("(%p)\n", This);
685 return E_NOTIMPL;
686 }
687
688 #undef INPLACEOBJ_THIS
689
690 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
691 {
692 OleInPlaceObject_QueryInterface,
693 OleInPlaceObject_AddRef,
694 OleInPlaceObject_Release,
695 OleInPlaceObject_GetWindow,
696 OleInPlaceObject_ContextSensitiveHelp,
697 OleInPlaceObject_InPlaceDeactivate,
698 OleInPlaceObject_UIDeactivate,
699 OleInPlaceObject_SetObjectRects,
700 OleInPlaceObject_ReactivateAndUndo
701 };
702
703 /**********************************************************************
704 * Implement the IOleControl interface
705 */
706
707 #define CONTROL_THIS(iface) DEFINE_THIS(WebBrowser, OleControl, iface)
708
709 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
710 REFIID riid, LPVOID *ppobj)
711 {
712 WebBrowser *This = CONTROL_THIS(iface);
713 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
714 }
715
716 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
717 {
718 WebBrowser *This = CONTROL_THIS(iface);
719 return IWebBrowser_AddRef(WEBBROWSER(This));
720 }
721
722 static ULONG WINAPI OleControl_Release(IOleControl *iface)
723 {
724 WebBrowser *This = CONTROL_THIS(iface);
725 return IWebBrowser_Release(WEBBROWSER(This));
726 }
727
728 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
729 {
730 WebBrowser *This = CONTROL_THIS(iface);
731
732 TRACE("(%p)->(%p)\n", This, pCI);
733
734 /* Tests show that this function should be not implemented */
735 return E_NOTIMPL;
736 }
737
738 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
739 {
740 WebBrowser *This = CONTROL_THIS(iface);
741 FIXME("(%p)->(%p)\n", This, pMsg);
742 return E_NOTIMPL;
743 }
744
745 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
746 {
747 WebBrowser *This = CONTROL_THIS(iface);
748
749 TRACE("(%p)->(%d)\n", This, dispID);
750
751 switch(dispID) {
752 case DISPID_UNKNOWN:
753 /* Unknown means multiple properties changed, so check them all.
754 * BUT the Webbrowser OleControl object doesn't appear to do this.
755 */
756 return S_OK;
757 case DISPID_AMBIENT_DLCONTROL:
758 return S_OK;
759 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
760 return on_offlineconnected_change(This);
761 case DISPID_AMBIENT_SILENT:
762 return on_silent_change(This);
763 }
764
765 FIXME("Unknown dispID %d\n", dispID);
766 return E_NOTIMPL;
767 }
768
769 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
770 {
771 WebBrowser *This = CONTROL_THIS(iface);
772 FIXME("(%p)->(%x)\n", This, bFreeze);
773 return E_NOTIMPL;
774 }
775
776 #undef CONTROL_THIS
777
778 static const IOleControlVtbl OleControlVtbl =
779 {
780 OleControl_QueryInterface,
781 OleControl_AddRef,
782 OleControl_Release,
783 OleControl_GetControlInfo,
784 OleControl_OnMnemonic,
785 OleControl_OnAmbientPropertyChange,
786 OleControl_FreezeEvents
787 };
788
789 #define ACTIVEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceActiveObject, iface)
790
791 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
792 REFIID riid, void **ppv)
793 {
794 WebBrowser *This = ACTIVEOBJ_THIS(iface);
795 return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
796 }
797
798 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
799 {
800 WebBrowser *This = ACTIVEOBJ_THIS(iface);
801 return IWebBrowser2_AddRef(WEBBROWSER2(This));
802 }
803
804 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
805 {
806 WebBrowser *This = ACTIVEOBJ_THIS(iface);
807 return IWebBrowser2_Release(WEBBROWSER2(This));
808 }
809
810 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
811 HWND *phwnd)
812 {
813 WebBrowser *This = ACTIVEOBJ_THIS(iface);
814 return IOleInPlaceObject_GetWindow(INPLACEOBJ(This), phwnd);
815 }
816
817 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
818 BOOL fEnterMode)
819 {
820 WebBrowser *This = ACTIVEOBJ_THIS(iface);
821 return IOleInPlaceObject_ContextSensitiveHelp(INPLACEOBJ(This), fEnterMode);
822 }
823
824 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
825 LPMSG lpmsg)
826 {
827 WebBrowser *This = ACTIVEOBJ_THIS(iface);
828 FIXME("(%p)->(%p)\n", This, lpmsg);
829 return E_NOTIMPL;
830 }
831
832 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
833 BOOL fActivate)
834 {
835 WebBrowser *This = ACTIVEOBJ_THIS(iface);
836 FIXME("(%p)->(%x)\n", This, fActivate);
837 return E_NOTIMPL;
838 }
839
840 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
841 BOOL fActivate)
842 {
843 WebBrowser *This = ACTIVEOBJ_THIS(iface);
844 FIXME("(%p)->(%x)\n", This, fActivate);
845 return E_NOTIMPL;
846 }
847
848 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
849 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
850 {
851 WebBrowser *This = ACTIVEOBJ_THIS(iface);
852 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
853 return E_NOTIMPL;
854 }
855
856 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
857 BOOL fEnable)
858 {
859 WebBrowser *This = ACTIVEOBJ_THIS(iface);
860 FIXME("(%p)->(%x)\n", This, fEnable);
861 return E_NOTIMPL;
862 }
863
864 #undef ACTIVEOBJ_THIS
865
866 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
867 InPlaceActiveObject_QueryInterface,
868 InPlaceActiveObject_AddRef,
869 InPlaceActiveObject_Release,
870 InPlaceActiveObject_GetWindow,
871 InPlaceActiveObject_ContextSensitiveHelp,
872 InPlaceActiveObject_TranslateAccelerator,
873 InPlaceActiveObject_OnFrameWindowActivate,
874 InPlaceActiveObject_OnDocWindowActivate,
875 InPlaceActiveObject_ResizeBorder,
876 InPlaceActiveObject_EnableModeless
877 };
878
879 #define OLECMD_THIS(iface) DEFINE_THIS(WebBrowser, OleCommandTarget, iface)
880
881 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
882 REFIID riid, void **ppv)
883 {
884 WebBrowser *This = OLECMD_THIS(iface);
885 return IWebBrowser2_QueryInterface(WEBBROWSER(This), riid, ppv);
886 }
887
888 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
889 {
890 WebBrowser *This = OLECMD_THIS(iface);
891 return IWebBrowser2_AddRef(WEBBROWSER(This));
892 }
893
894 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
895 {
896 WebBrowser *This = OLECMD_THIS(iface);
897 return IWebBrowser2_Release(WEBBROWSER(This));
898 }
899
900 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
901 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
902 {
903 WebBrowser *This = OLECMD_THIS(iface);
904 IOleCommandTarget *cmdtrg;
905 HRESULT hres;
906
907 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
908 pCmdText);
909
910 if(!This->doc_host.document)
911 return 0x80040104;
912
913 /* NOTE: There are probably some commands that we should handle here
914 * instead of forwarding to document object. */
915
916 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
917 if(FAILED(hres))
918 return hres;
919
920 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
921 IOleCommandTarget_Release(cmdtrg);
922
923 return hres;
924 }
925
926 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
927 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
928 VARIANT *pvaOut)
929 {
930 WebBrowser *This = OLECMD_THIS(iface);
931 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
932 nCmdexecopt, pvaIn, pvaOut);
933 return E_NOTIMPL;
934 }
935
936 #undef OLECMD_THIS
937
938 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
939 WBOleCommandTarget_QueryInterface,
940 WBOleCommandTarget_AddRef,
941 WBOleCommandTarget_Release,
942 WBOleCommandTarget_QueryStatus,
943 WBOleCommandTarget_Exec
944 };
945
946 void WebBrowser_OleObject_Init(WebBrowser *This)
947 {
948 DWORD dpi_x;
949 DWORD dpi_y;
950 HDC hdc;
951
952 /* default aspect ratio is 96dpi / 96dpi */
953 hdc = GetDC(0);
954 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
955 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
956 ReleaseDC(0, hdc);
957
958 This->lpOleObjectVtbl = &OleObjectVtbl;
959 This->lpOleInPlaceObjectVtbl = &OleInPlaceObjectVtbl;
960 This->lpOleControlVtbl = &OleControlVtbl;
961 This->lpOleInPlaceActiveObjectVtbl = &OleInPlaceActiveObjectVtbl;
962 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
963
964 /* Default size is 50x20 pixels, in himetric units */
965 This->extent.cx = MulDiv( 50, 2540, dpi_x );
966 This->extent.cy = MulDiv( 20, 2540, dpi_y );
967 }
968
969 void WebBrowser_OleObject_Destroy(WebBrowser *This)
970 {
971 release_client_site(This);
972 }