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