mciqtz: Improve MCIQTZ_mciSet traces.
[wine] / dlls / mshtml / oleobj.c
1 /*
2  * Copyright 2005 Jacek Caban
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "shlguid.h"
31 #include "mshtmdid.h"
32 #include "idispids.h"
33
34 #include "wine/debug.h"
35
36 #include "mshtml_private.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39
40 /**********************************************************
41  * IOleObject implementation
42  */
43
44 #define OLEOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, OleObject, iface)
45
46 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppvObject)
47 {
48     HTMLDocument *This = OLEOBJ_THIS(iface);
49     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
50 }
51
52 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
53 {
54     HTMLDocument *This = OLEOBJ_THIS(iface);
55     return IHTMLDocument2_AddRef(HTMLDOC(This));
56 }
57
58 static ULONG WINAPI OleObject_Release(IOleObject *iface)
59 {
60     HTMLDocument *This = OLEOBJ_THIS(iface);
61     return IHTMLDocument2_Release(HTMLDOC(This));
62 }
63
64 static void update_hostinfo(HTMLDocumentObj *This, DOCHOSTUIINFO *hostinfo)
65 {
66     nsIScrollable *scrollable;
67     nsresult nsres;
68
69     if(!This->nscontainer)
70         return;
71
72     nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
73     if(NS_SUCCEEDED(nsres)) {
74         nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable, ScrollOrientation_Y,
75                 (hostinfo->dwFlags & DOCHOSTUIFLAG_SCROLL_NO) ? Scrollbar_Never : Scrollbar_Always);
76         if(NS_FAILED(nsres))
77             ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
78
79         nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable, ScrollOrientation_X,
80                 hostinfo->dwFlags & DOCHOSTUIFLAG_SCROLL_NO ? Scrollbar_Never : Scrollbar_Auto);
81         if(NS_FAILED(nsres))
82             ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
83
84         nsIScrollable_Release(scrollable);
85     }else {
86         ERR("Could not get nsIScrollable: %08x\n", nsres);
87     }
88 }
89
90 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, IOleClientSite *pClientSite)
91 {
92     HTMLDocument *This = OLEOBJ_THIS(iface);
93     IDocHostUIHandler *pDocHostUIHandler = NULL;
94     IOleCommandTarget *cmdtrg = NULL;
95     VARIANT silent;
96     HRESULT hres;
97
98     TRACE("(%p)->(%p)\n", This, pClientSite);
99
100     if(pClientSite == This->doc_obj->client)
101         return S_OK;
102
103     if(This->doc_obj->client) {
104         IOleClientSite_Release(This->doc_obj->client);
105         This->doc_obj->client = NULL;
106         This->doc_obj->usermode = UNKNOWN_USERMODE;
107     }
108
109     if(This->doc_obj->hostui) {
110         IDocHostUIHandler_Release(This->doc_obj->hostui);
111         This->doc_obj->hostui = NULL;
112     }
113
114     memset(&This->doc_obj->hostinfo, 0, sizeof(DOCHOSTUIINFO));
115
116     if(!pClientSite)
117         return S_OK;
118
119     hres = IOleObject_QueryInterface(pClientSite, &IID_IDocHostUIHandler, (void**)&pDocHostUIHandler);
120     if(SUCCEEDED(hres)) {
121         DOCHOSTUIINFO hostinfo;
122         LPOLESTR key_path = NULL, override_key_path = NULL;
123         IDocHostUIHandler2 *pDocHostUIHandler2;
124
125         memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
126         hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
127         hres = IDocHostUIHandler_GetHostInfo(pDocHostUIHandler, &hostinfo);
128         if(SUCCEEDED(hres)) {
129             TRACE("hostinfo = {%u %08x %08x %s %s}\n",
130                     hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
131                     debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
132             update_hostinfo(This->doc_obj, &hostinfo);
133             This->doc_obj->hostinfo = hostinfo;
134         }
135
136         if(!This->doc_obj->has_key_path) {
137             hres = IDocHostUIHandler_GetOptionKeyPath(pDocHostUIHandler, &key_path, 0);
138             if(hres == S_OK && key_path) {
139                 if(key_path[0]) {
140                     /* FIXME: use key_path */
141                     TRACE("key_path = %s\n", debugstr_w(key_path));
142                 }
143                 CoTaskMemFree(key_path);
144             }
145
146             hres = IDocHostUIHandler_QueryInterface(pDocHostUIHandler, &IID_IDocHostUIHandler2,
147                     (void**)&pDocHostUIHandler2);
148             if(SUCCEEDED(hres)) {
149                 hres = IDocHostUIHandler2_GetOverrideKeyPath(pDocHostUIHandler2, &override_key_path, 0);
150                 if(hres == S_OK && override_key_path && override_key_path[0]) {
151                     if(override_key_path[0]) {
152                         /*FIXME: use override_key_path */
153                         TRACE("override_key_path = %s\n", debugstr_w(override_key_path));
154                     }
155                     CoTaskMemFree(override_key_path);
156                 }
157                 IDocHostUIHandler2_Release(pDocHostUIHandler2);
158             }
159
160             This->doc_obj->has_key_path = TRUE;
161         }
162     }
163
164     /* Native calls here GetWindow. What is it for?
165      * We don't have anything to do with it here (yet). */
166     if(pClientSite) {
167         IOleWindow *pOleWindow = NULL;
168         HWND hwnd;
169
170         hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleWindow, (void**)&pOleWindow);
171         if(SUCCEEDED(hres)) {
172             IOleWindow_GetWindow(pOleWindow, &hwnd);
173             IOleWindow_Release(pOleWindow);
174         }
175     }
176
177     hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleCommandTarget, (void**)&cmdtrg);
178     if(SUCCEEDED(hres)) {
179         VARIANT var;
180         OLECMD cmd = {OLECMDID_SETPROGRESSTEXT, 0};
181
182         IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &cmd, NULL);
183
184         V_VT(&var) = VT_I4;
185         V_I4(&var) = 0;
186         IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
187                 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
188         IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 
189                 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
190
191         IOleCommandTarget_Release(cmdtrg);
192     }
193
194     IOleClientSite_AddRef(pClientSite);
195     This->doc_obj->client = pClientSite;
196     This->doc_obj->hostui = pDocHostUIHandler;
197
198     if(This->doc_obj->usermode == UNKNOWN_USERMODE)
199         IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERMODE);
200
201     IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_OFFLINEIFNOTCONNECTED); 
202
203     hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
204     if(SUCCEEDED(hres)) {
205         if(V_VT(&silent) != VT_BOOL)
206             WARN("V_VT(silent) = %d\n", V_VT(&silent));
207         else if(V_BOOL(&silent))
208             FIXME("silent == true\n");
209     }
210
211     IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERAGENT);
212     IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_PALETTE);
213
214     return S_OK;
215 }
216
217 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, IOleClientSite **ppClientSite)
218 {
219     HTMLDocument *This = OLEOBJ_THIS(iface);
220
221     TRACE("(%p)->(%p)\n", This, ppClientSite);
222
223     if(!ppClientSite)
224         return E_INVALIDARG;
225
226     if(This->doc_obj->client)
227         IOleClientSite_AddRef(This->doc_obj->client);
228     *ppClientSite = This->doc_obj->client;
229
230     return S_OK;
231 }
232
233 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
234 {
235     HTMLDocument *This = OLEOBJ_THIS(iface);
236     FIXME("(%p)->(%s %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
237     return E_NOTIMPL;
238 }
239
240 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
241 {
242     HTMLDocument *This = OLEOBJ_THIS(iface);
243
244     TRACE("(%p)->(%08x)\n", This, dwSaveOption);
245
246     if(dwSaveOption == OLECLOSE_PROMPTSAVE)
247         FIXME("OLECLOSE_PROMPTSAVE not implemented\n");
248
249     if(This->doc_obj->in_place_active)
250         IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This));
251
252     HTMLDocument_LockContainer(This->doc_obj, FALSE);
253
254     if(This->advise_holder)
255         IOleAdviseHolder_SendOnClose(This->advise_holder);
256     
257     return S_OK;
258 }
259
260 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker *pmk)
261 {
262     HTMLDocument *This = OLEOBJ_THIS(iface);
263     FIXME("(%p %d %p)->()\n", This, dwWhichMoniker, pmk);
264     return E_NOTIMPL;
265 }
266
267 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
268 {
269     HTMLDocument *This = OLEOBJ_THIS(iface);
270     FIXME("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
271     return E_NOTIMPL;
272 }
273
274 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, IDataObject *pDataObject, BOOL fCreation,
275                                         DWORD dwReserved)
276 {
277     HTMLDocument *This = OLEOBJ_THIS(iface);
278     FIXME("(%p)->(%p %x %d)\n", This, pDataObject, fCreation, dwReserved);
279     return E_NOTIMPL;
280 }
281
282 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved, IDataObject **ppDataObject)
283 {
284     HTMLDocument *This = OLEOBJ_THIS(iface);
285     FIXME("(%p)->(%d %p)\n", This, dwReserved, ppDataObject);
286     return E_NOTIMPL;
287 }
288
289 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite,
290                                         LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
291 {
292     HTMLDocument *This = OLEOBJ_THIS(iface);
293     IOleDocumentSite *pDocSite;
294     HRESULT hres;
295
296     TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
297
298     if(iVerb != OLEIVERB_SHOW && iVerb != OLEIVERB_UIACTIVATE && iVerb != OLEIVERB_INPLACEACTIVATE) { 
299         FIXME("iVerb = %d not supported\n", iVerb);
300         return E_NOTIMPL;
301     }
302
303     if(!pActiveSite)
304         pActiveSite = This->doc_obj->client;
305
306     hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleDocumentSite, (void**)&pDocSite);
307     if(SUCCEEDED(hres)) {
308         HTMLDocument_LockContainer(This->doc_obj, TRUE);
309
310         /* FIXME: Create new IOleDocumentView. See CreateView for more info. */
311         hres = IOleDocumentSite_ActivateMe(pDocSite, DOCVIEW(This));
312         IOleDocumentSite_Release(pDocSite);
313     }else {
314         hres = IOleDocumentView_UIActivate(DOCVIEW(This), TRUE);
315         if(SUCCEEDED(hres)) {
316             if(lprcPosRect) {
317                 RECT rect; /* We need to pass rect as not const pointer */
318                 rect = *lprcPosRect;
319                 IOleDocumentView_SetRect(DOCVIEW(This), &rect);
320             }
321             IOleDocumentView_Show(DOCVIEW(This), TRUE);
322         }
323     }
324
325     return hres;
326 }
327
328 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
329 {
330     HTMLDocument *This = OLEOBJ_THIS(iface);
331     FIXME("(%p)->(%p)\n", This, ppEnumOleVerb);
332     return E_NOTIMPL;
333 }
334
335 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
336 {
337     HTMLDocument *This = OLEOBJ_THIS(iface);
338     FIXME("(%p)\n", This);
339     return E_NOTIMPL;
340 }
341
342 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
343 {
344     HTMLDocument *This = OLEOBJ_THIS(iface);
345     FIXME("(%p)\n", This);
346     return E_NOTIMPL;
347 }
348
349 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
350 {
351     HTMLDocument *This = OLEOBJ_THIS(iface);
352
353     TRACE("(%p)->(%p)\n", This, pClsid);
354
355     if(!pClsid)
356         return E_INVALIDARG;
357
358     *pClsid = CLSID_HTMLDocument;
359     return S_OK;
360 }
361
362 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType, LPOLESTR *pszUserType)
363 {
364     HTMLDocument *This = OLEOBJ_THIS(iface);
365     FIXME("(%p)->(%d %p)\n", This, dwFormOfType, pszUserType);
366     return E_NOTIMPL;
367 }
368
369 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
370 {
371     HTMLDocument *This = OLEOBJ_THIS(iface);
372     FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
373     return E_NOTIMPL;
374 }
375
376 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
377 {
378     HTMLDocument *This = OLEOBJ_THIS(iface);
379     FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
380     return E_NOTIMPL;
381 }
382
383 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink, DWORD *pdwConnection)
384 {
385     HTMLDocument *This = OLEOBJ_THIS(iface);
386     TRACE("(%p)->(%p %p)\n", This, pAdvSink, pdwConnection);
387
388     if(!pdwConnection)
389         return E_INVALIDARG;
390
391     if(!pAdvSink) {
392         *pdwConnection = 0;
393         return E_INVALIDARG;
394     }
395
396     if(!This->advise_holder) {
397         CreateOleAdviseHolder(&This->advise_holder);
398         if(!This->advise_holder)
399             return E_OUTOFMEMORY;
400     }
401
402     return IOleAdviseHolder_Advise(This->advise_holder, pAdvSink, pdwConnection);
403 }
404
405 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
406 {
407     HTMLDocument *This = OLEOBJ_THIS(iface);
408     TRACE("(%p)->(%d)\n", This, dwConnection);
409
410     if(!This->advise_holder)
411         return OLE_E_NOCONNECTION;
412
413     return IOleAdviseHolder_Unadvise(This->advise_holder, dwConnection);
414 }
415
416 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
417 {
418     HTMLDocument *This = OLEOBJ_THIS(iface);
419
420     if(!This->advise_holder) {
421         *ppenumAdvise = NULL;
422         return S_OK;
423     }
424
425     return IOleAdviseHolder_EnumAdvise(This->advise_holder, ppenumAdvise);
426 }
427
428 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
429 {
430     HTMLDocument *This = OLEOBJ_THIS(iface);
431     FIXME("(%p)->(%d %p)\n", This, dwAspect, pdwStatus);
432     return E_NOTIMPL;
433 }
434
435 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *pLogpal)
436 {
437     HTMLDocument *This = OLEOBJ_THIS(iface);
438     FIXME("(%p)->(%p)\n", This, pLogpal);
439     return E_NOTIMPL;
440 }
441
442 #undef OLEPBJ_THIS
443
444 static const IOleObjectVtbl OleObjectVtbl = {
445     OleObject_QueryInterface,
446     OleObject_AddRef,
447     OleObject_Release,
448     OleObject_SetClientSite,
449     OleObject_GetClientSite,
450     OleObject_SetHostNames,
451     OleObject_Close,
452     OleObject_SetMoniker,
453     OleObject_GetMoniker,
454     OleObject_InitFromData,
455     OleObject_GetClipboardData,
456     OleObject_DoVerb,
457     OleObject_EnumVerbs,
458     OleObject_Update,
459     OleObject_IsUpToDate,
460     OleObject_GetUserClassID,
461     OleObject_GetUserType,
462     OleObject_SetExtent,
463     OleObject_GetExtent,
464     OleObject_Advise,
465     OleObject_Unadvise,
466     OleObject_EnumAdvise,
467     OleObject_GetMiscStatus,
468     OleObject_SetColorScheme
469 };
470
471 /**********************************************************
472  * IOleDocument implementation
473  */
474
475 #define OLEDOC_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocument, iface)
476
477 static HRESULT WINAPI OleDocument_QueryInterface(IOleDocument *iface, REFIID riid, void **ppvObject)
478 {
479     HTMLDocument *This = OLEDOC_THIS(iface);
480     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
481 }
482
483 static ULONG WINAPI OleDocument_AddRef(IOleDocument *iface)
484 {
485     HTMLDocument *This = OLEDOC_THIS(iface);
486     return IHTMLDocument2_AddRef(HTMLDOC(This));
487 }
488
489 static ULONG WINAPI OleDocument_Release(IOleDocument *iface)
490 {
491     HTMLDocument *This = OLEDOC_THIS(iface);
492     return IHTMLDocument2_Release(HTMLDOC(This));
493 }
494
495 static HRESULT WINAPI OleDocument_CreateView(IOleDocument *iface, IOleInPlaceSite *pIPSite, IStream *pstm,
496                                    DWORD dwReserved, IOleDocumentView **ppView)
497 {
498     HTMLDocument *This = OLEDOC_THIS(iface);
499     HRESULT hres;
500
501     TRACE("(%p)->(%p %p %d %p)\n", This, pIPSite, pstm, dwReserved, ppView);
502
503     if(!ppView)
504         return E_INVALIDARG;
505
506     /* FIXME:
507      * Windows implementation creates new IOleDocumentView when function is called for the
508      * first time and returns E_FAIL when it is called for the second time, but it doesn't matter
509      * if the application uses returned interfaces, passed to ActivateMe or returned by
510      * QueryInterface, so there is no reason to create new interface. This needs more testing.
511      */
512
513     if(pIPSite) {
514         hres = IOleDocumentView_SetInPlaceSite(DOCVIEW(This), pIPSite);
515         if(FAILED(hres))
516             return hres;
517     }
518
519     if(pstm)
520         FIXME("pstm is not supported\n");
521
522     IOleDocumentView_AddRef(DOCVIEW(This));
523     *ppView = DOCVIEW(This);
524     return S_OK;
525 }
526
527 static HRESULT WINAPI OleDocument_GetDocMiscStatus(IOleDocument *iface, DWORD *pdwStatus)
528 {
529     HTMLDocument *This = OLEDOC_THIS(iface);
530     FIXME("(%p)->(%p)\n", This, pdwStatus);
531     return E_NOTIMPL;
532 }
533
534 static HRESULT WINAPI OleDocument_EnumViews(IOleDocument *iface, IEnumOleDocumentViews **ppEnum,
535                                    IOleDocumentView **ppView)
536 {
537     HTMLDocument *This = OLEDOC_THIS(iface);
538     FIXME("(%p)->(%p %p)\n", This, ppEnum, ppView);
539     return E_NOTIMPL;
540 }
541
542 #undef OLEDOC_THIS
543
544 static const IOleDocumentVtbl OleDocumentVtbl = {
545     OleDocument_QueryInterface,
546     OleDocument_AddRef,
547     OleDocument_Release,
548     OleDocument_CreateView,
549     OleDocument_GetDocMiscStatus,
550     OleDocument_EnumViews
551 };
552
553 /**********************************************************
554  * IOleControl implementation
555  */
556
557 #define CONTROL_THIS(iface) DEFINE_THIS(HTMLDocument, OleControl, iface)
558
559 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface, REFIID riid, void **ppv)
560 {
561     HTMLDocument *This = CONTROL_THIS(iface);
562     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
563 }
564
565 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
566 {
567     HTMLDocument *This = CONTROL_THIS(iface);
568     return IHTMLDocument2_AddRef(HTMLDOC(This));
569 }
570
571 static ULONG WINAPI OleControl_Release(IOleControl *iface)
572 {
573     HTMLDocument *This = CONTROL_THIS(iface);
574     return IHTMLDocument_Release(HTMLDOC(This));
575 }
576
577 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, CONTROLINFO *pCI)
578 {
579     HTMLDocument *This = CONTROL_THIS(iface);
580     FIXME("(%p)->(%p)\n", This, pCI);
581     return E_NOTIMPL;
582 }
583
584 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, MSG *pMsg)
585 {
586     HTMLDocument *This = CONTROL_THIS(iface);
587     FIXME("(%p)->(%p)\n", This, pMsg);
588     return E_NOTIMPL;
589 }
590
591 HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
592 {
593     IDispatch *disp = NULL;
594     DISPPARAMS dispparams = {NULL, 0};
595     UINT err;
596     HRESULT hres;
597
598     hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
599     if(FAILED(hres)) {
600         TRACE("Could not get IDispatch\n");
601         return hres;
602     }
603
604     VariantInit(res);
605
606     hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
607             DISPATCH_PROPERTYGET, &dispparams, res, NULL, &err);
608
609     IDispatch_Release(disp);
610
611     return hres;
612 }
613
614 static HRESULT on_change_dlcontrol(HTMLDocument *This)
615 {
616     VARIANT res;
617     HRESULT hres;
618     
619     hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_DLCONTROL, &res);
620     if(SUCCEEDED(hres))
621         FIXME("unsupported dlcontrol %08x\n", V_I4(&res));
622
623     return S_OK;
624 }
625
626 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
627 {
628     HTMLDocument *This = CONTROL_THIS(iface);
629     IOleClientSite *client;
630     VARIANT res;
631     HRESULT hres;
632
633     client = This->doc_obj->client;
634     if(!client) {
635         TRACE("client = NULL\n");
636         return S_OK;
637     }
638
639     switch(dispID) {
640     case DISPID_AMBIENT_USERMODE:
641         TRACE("(%p)->(DISPID_AMBIENT_USERMODE)\n", This);
642         hres = get_client_disp_property(client, DISPID_AMBIENT_USERMODE, &res);
643         if(FAILED(hres))
644             return S_OK;
645
646         if(V_VT(&res) == VT_BOOL) {
647             if(V_BOOL(&res)) {
648                 This->doc_obj->usermode = BROWSEMODE;
649             }else {
650                 FIXME("edit mode is not supported\n");
651                 This->doc_obj->usermode = EDITMODE;
652             }
653         }else {
654             FIXME("V_VT(res)=%d\n", V_VT(&res));
655         }
656         return S_OK;
657     case DISPID_AMBIENT_DLCONTROL:
658         TRACE("(%p)->(DISPID_AMBIENT_DLCONTROL)\n", This);
659         return on_change_dlcontrol(This);
660     case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
661         TRACE("(%p)->(DISPID_AMBIENT_OFFLINEIFNOTCONNECTED)\n", This);
662         on_change_dlcontrol(This);
663         hres = get_client_disp_property(client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &res);
664         if(FAILED(hres))
665             return S_OK;
666
667         if(V_VT(&res) == VT_BOOL) {
668             if(V_BOOL(&res)) {
669                 FIXME("offline connection is not supported\n");
670                 hres = E_FAIL;
671             }
672         }else {
673             FIXME("V_VT(res)=%d\n", V_VT(&res));
674         }
675         return S_OK;
676     case DISPID_AMBIENT_SILENT:
677         TRACE("(%p)->(DISPID_AMBIENT_SILENT)\n", This);
678         on_change_dlcontrol(This);
679         hres = get_client_disp_property(client, DISPID_AMBIENT_SILENT, &res);
680         if(FAILED(hres))
681             return S_OK;
682
683         if(V_VT(&res) == VT_BOOL) {
684             if(V_BOOL(&res)) {
685                 FIXME("silent mode is not supported\n");
686                 hres = E_FAIL;
687             }
688         }else {
689             FIXME("V_VT(res)=%d\n", V_VT(&res));
690         }
691         return S_OK;
692     case DISPID_AMBIENT_USERAGENT:
693         TRACE("(%p)->(DISPID_AMBIENT_USERAGENT)\n", This);
694         hres = get_client_disp_property(client, DISPID_AMBIENT_USERAGENT, &res);
695         if(FAILED(hres))
696             return S_OK;
697
698         FIXME("not supported AMBIENT_USERAGENT\n");
699         hres = E_FAIL;
700         return S_OK;
701     case DISPID_AMBIENT_PALETTE:
702         TRACE("(%p)->(DISPID_AMBIENT_PALETTE)\n", This);
703         hres = get_client_disp_property(client, DISPID_AMBIENT_PALETTE, &res);
704         if(FAILED(hres))
705             return S_OK;
706
707         FIXME("not supported AMBIENT_PALETTE\n");
708         hres = E_FAIL;
709         return S_OK;
710     }
711
712     FIXME("(%p) unsupported dispID=%d\n", This, dispID);
713     return E_FAIL;
714 }
715
716 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
717 {
718     HTMLDocument *This = CONTROL_THIS(iface);
719     FIXME("(%p)->(%x)\n", This, bFreeze);
720     return E_NOTIMPL;
721 }
722
723 #undef CONTROL_THIS
724
725 static const IOleControlVtbl OleControlVtbl = {
726     OleControl_QueryInterface,
727     OleControl_AddRef,
728     OleControl_Release,
729     OleControl_GetControlInfo,
730     OleControl_OnMnemonic,
731     OleControl_OnAmbientPropertyChange,
732     OleControl_FreezeEvents
733 };
734
735 /**********************************************************
736  * IObjectWithSite implementation
737  */
738
739 #define OBJSITE_THIS(iface) DEFINE_THIS(HTMLDocument, ObjectWithSite, iface)
740
741 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppvObject)
742 {
743     HTMLDocument *This = OBJSITE_THIS(iface);
744     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
745 }
746
747 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
748 {
749     HTMLDocument *This = OBJSITE_THIS(iface);
750     return IHTMLDocument2_AddRef(HTMLDOC(This));
751 }
752
753 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
754 {
755     HTMLDocument *This = OBJSITE_THIS(iface);
756     return IHTMLDocument2_Release(HTMLDOC(This));
757 }
758
759 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
760 {
761     HTMLDocument *This = OBJSITE_THIS(iface);
762     FIXME("(%p)->(%p)\n", This, pUnkSite);
763     return E_NOTIMPL;
764 }
765
766 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite* iface, REFIID riid, PVOID *ppvSite)
767 {
768     HTMLDocument *This = OBJSITE_THIS(iface);
769     FIXME("(%p)->(%p)\n", This, ppvSite);
770     return E_NOTIMPL;
771 }
772
773 #undef OBJSITE_THIS
774
775 static const IObjectWithSiteVtbl ObjectWithSiteVtbl = {
776     ObjectWithSite_QueryInterface,
777     ObjectWithSite_AddRef,
778     ObjectWithSite_Release,
779     ObjectWithSite_SetSite,
780     ObjectWithSite_GetSite
781 };
782
783 void HTMLDocument_LockContainer(HTMLDocumentObj *This, BOOL fLock)
784 {
785     IOleContainer *container;
786     HRESULT hres;
787
788     if(!This->client || This->container_locked == fLock)
789         return;
790
791     hres = IOleClientSite_GetContainer(This->client, &container);
792     if(SUCCEEDED(hres)) {
793         IOleContainer_LockContainer(container, fLock);
794         This->container_locked = fLock;
795         IOleContainer_Release(container);
796     }
797 }
798
799 void HTMLDocument_OleObj_Init(HTMLDocument *This)
800 {
801     This->lpOleObjectVtbl = &OleObjectVtbl;
802     This->lpOleDocumentVtbl = &OleDocumentVtbl;
803     This->lpOleControlVtbl = &OleControlVtbl;
804     This->lpObjectWithSiteVtbl = &ObjectWithSiteVtbl;
805 }