2 * Copyright 2005 Jacek Caban
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.
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.
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
34 #include "wine/debug.h"
36 #include "mshtml_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
40 /**********************************************************
41 * IOleObject implementation
44 #define OLEOBJ_THIS(iface) DEFINE_THIS(HTMLDocument, OleObject, iface)
46 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppvObject)
48 HTMLDocument *This = OLEOBJ_THIS(iface);
49 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
52 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
54 HTMLDocument *This = OLEOBJ_THIS(iface);
55 return IHTMLDocument2_AddRef(HTMLDOC(This));
58 static ULONG WINAPI OleObject_Release(IOleObject *iface)
60 HTMLDocument *This = OLEOBJ_THIS(iface);
61 return IHTMLDocument2_Release(HTMLDOC(This));
64 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, IOleClientSite *pClientSite)
66 HTMLDocument *This = OLEOBJ_THIS(iface);
67 IDocHostUIHandler *pDocHostUIHandler = NULL;
68 IOleCommandTarget *cmdtrg = NULL;
71 TRACE("(%p)->(%p)\n", This, pClientSite);
73 if(pClientSite == This->client)
77 IOleClientSite_Release(This->client);
79 This->usermode = UNKNOWN_USERMODE;
83 IDocHostUIHandler_Release(This->hostui);
90 hres = IOleObject_QueryInterface(pClientSite, &IID_IDocHostUIHandler, (void**)&pDocHostUIHandler);
92 DOCHOSTUIINFO hostinfo;
93 LPOLESTR key_path = NULL, override_key_path = NULL;
94 IDocHostUIHandler2 *pDocHostUIHandler2;
96 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
97 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
98 hres = IDocHostUIHandler_GetHostInfo(pDocHostUIHandler, &hostinfo);
100 /* FIXME: use hostinfo */
101 TRACE("hostinfo = {%lu %08lx %08lx %s %s}\n",
102 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
103 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
105 if(!This->has_key_path) {
106 hres = IDocHostUIHandler_GetOptionKeyPath(pDocHostUIHandler, &key_path, 0);
107 if(hres == S_OK && key_path) {
109 /* FIXME: use key_path */
110 TRACE("key_path = %s\n", debugstr_w(key_path));
112 CoTaskMemFree(key_path);
115 hres = IDocHostUIHandler_QueryInterface(pDocHostUIHandler, &IID_IDocHostUIHandler2,
116 (void**)&pDocHostUIHandler2);
117 if(SUCCEEDED(hres)) {
118 hres = IDocHostUIHandler2_GetOverrideKeyPath(pDocHostUIHandler2, &override_key_path, 0);
119 if(hres == S_OK && override_key_path && override_key_path[0]) {
120 if(override_key_path[0]) {
121 /*FIXME: use override_key_path */
122 TRACE("override_key_path = %s\n", debugstr_w(override_key_path));
124 CoTaskMemFree(override_key_path);
126 IDocHostUIHandler2_Release(pDocHostUIHandler2);
129 This->has_key_path = TRUE;
133 /* Native calls here GetWindow. What is it for?
134 * We don't have anything to do with it here (yet). */
136 IOleWindow *pOleWindow = NULL;
139 hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleWindow, (void**)&pOleWindow);
140 if(SUCCEEDED(hres)) {
141 IOleWindow_GetWindow(pOleWindow, &hwnd);
142 IOleWindow_Release(pOleWindow);
146 hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleCommandTarget, (void**)&cmdtrg);
147 if(SUCCEEDED(hres)) {
149 OLECMD cmd = {OLECMDID_SETPROGRESSTEXT, 0};
151 IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &cmd, NULL);
155 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX, 0, &var, NULL);
156 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS, 0, &var, NULL);
158 IOleCommandTarget_Release(cmdtrg);
161 IOleClientSite_AddRef(pClientSite);
162 This->client = pClientSite;
163 This->hostui = pDocHostUIHandler;
165 if(This->usermode == UNKNOWN_USERMODE)
166 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERMODE);
168 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
169 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_SILENT);
170 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERAGENT);
171 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_PALETTE);
176 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, IOleClientSite **ppClientSite)
178 HTMLDocument *This = OLEOBJ_THIS(iface);
180 TRACE("(%p)->(%p)\n", This, ppClientSite);
186 IOleClientSite_AddRef(This->client);
187 *ppClientSite = This->client;
192 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
194 HTMLDocument *This = OLEOBJ_THIS(iface);
195 FIXME("(%p)->(%s %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
199 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
201 HTMLDocument *This = OLEOBJ_THIS(iface);
203 TRACE("(%p)->(%08lx)\n", This, dwSaveOption);
205 if(dwSaveOption == OLECLOSE_PROMPTSAVE)
206 FIXME("OLECLOSE_PROMPTSAVE not implemented\n");
208 if(This->in_place_active)
209 IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This));
211 HTMLDocument_LockContainer(This, FALSE);
216 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker *pmk)
218 HTMLDocument *This = OLEOBJ_THIS(iface);
219 FIXME("(%p %ld %p)->()\n", This, dwWhichMoniker, pmk);
223 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
225 HTMLDocument *This = OLEOBJ_THIS(iface);
226 FIXME("(%p)->(%ld %ld %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
230 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, IDataObject *pDataObject, BOOL fCreation,
233 HTMLDocument *This = OLEOBJ_THIS(iface);
234 FIXME("(%p)->(%p %x %ld)\n", This, pDataObject, fCreation, dwReserved);
238 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved, IDataObject **ppDataObject)
240 HTMLDocument *This = OLEOBJ_THIS(iface);
241 FIXME("(%p)->(%ld %p)\n", This, dwReserved, ppDataObject);
245 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite,
246 LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
248 HTMLDocument *This = OLEOBJ_THIS(iface);
249 IOleDocumentSite *pDocSite;
252 TRACE("(%p)->(%ld %p %p %ld %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
254 if(iVerb != OLEIVERB_SHOW && iVerb != OLEIVERB_UIACTIVATE && iVerb != OLEIVERB_INPLACEACTIVATE) {
255 FIXME("iVerb = %ld not supported\n", iVerb);
260 pActiveSite = This->client;
262 hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleDocumentSite, (void**)&pDocSite);
263 if(SUCCEEDED(hres)) {
264 HTMLDocument_LockContainer(This, TRUE);
266 /* FIXME: Create new IOleDocumentView. See CreateView for more info. */
267 hres = IOleDocumentSite_ActivateMe(pDocSite, DOCVIEW(This));
268 IOleDocumentSite_Release(pDocSite);
270 hres = IOleDocumentView_UIActivate(DOCVIEW(This), TRUE);
271 if(SUCCEEDED(hres)) {
273 RECT rect; /* We need to pass rect as not const pointer */
274 memcpy(&rect, lprcPosRect, sizeof(RECT));
275 IOleDocumentView_SetRect(DOCVIEW(This), &rect);
277 IOleDocumentView_Show(DOCVIEW(This), TRUE);
284 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
286 HTMLDocument *This = OLEOBJ_THIS(iface);
287 FIXME("(%p)->(%p)\n", This, ppEnumOleVerb);
291 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
293 HTMLDocument *This = OLEOBJ_THIS(iface);
294 FIXME("(%p)\n", This);
298 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
300 HTMLDocument *This = OLEOBJ_THIS(iface);
301 FIXME("(%p)\n", This);
305 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
307 HTMLDocument *This = OLEOBJ_THIS(iface);
309 TRACE("(%p)->(%p)\n", This, pClsid);
314 memcpy(pClsid, &CLSID_HTMLDocument, sizeof(GUID));
318 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType, LPOLESTR *pszUserType)
320 HTMLDocument *This = OLEOBJ_THIS(iface);
321 FIXME("(%p)->(%ld %p)\n", This, dwFormOfType, pszUserType);
325 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
327 HTMLDocument *This = OLEOBJ_THIS(iface);
328 FIXME("(%p)->(%ld %p)\n", This, dwDrawAspect, psizel);
332 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
334 HTMLDocument *This = OLEOBJ_THIS(iface);
335 FIXME("(%p)->(%ld %p)\n", This, dwDrawAspect, psizel);
339 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink, DWORD *pdwConnection)
341 HTMLDocument *This = OLEOBJ_THIS(iface);
342 FIXME("(%p)->(%p %p)\n", This, pAdvSink, pdwConnection);
346 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
348 HTMLDocument *This = OLEOBJ_THIS(iface);
349 FIXME("(%p)->(%ld)\n", This, dwConnection);
353 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
355 HTMLDocument *This = OLEOBJ_THIS(iface);
356 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
360 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
362 HTMLDocument *This = OLEOBJ_THIS(iface);
363 FIXME("(%p)->(%ld %p)\n", This, dwAspect, pdwStatus);
367 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *pLogpal)
369 HTMLDocument *This = OLEOBJ_THIS(iface);
370 FIXME("(%p)->(%p)\n", This, pLogpal);
376 static const IOleObjectVtbl OleObjectVtbl = {
377 OleObject_QueryInterface,
380 OleObject_SetClientSite,
381 OleObject_GetClientSite,
382 OleObject_SetHostNames,
384 OleObject_SetMoniker,
385 OleObject_GetMoniker,
386 OleObject_InitFromData,
387 OleObject_GetClipboardData,
391 OleObject_IsUpToDate,
392 OleObject_GetUserClassID,
393 OleObject_GetUserType,
398 OleObject_EnumAdvise,
399 OleObject_GetMiscStatus,
400 OleObject_SetColorScheme
403 /**********************************************************
404 * IOleDocument implementation
407 #define OLEDOC_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocument, iface)
409 static HRESULT WINAPI OleDocument_QueryInterface(IOleDocument *iface, REFIID riid, void **ppvObject)
411 HTMLDocument *This = OLEDOC_THIS(iface);
412 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
415 static ULONG WINAPI OleDocument_AddRef(IOleDocument *iface)
417 HTMLDocument *This = OLEDOC_THIS(iface);
418 return IHTMLDocument2_AddRef(HTMLDOC(This));
421 static ULONG WINAPI OleDocument_Release(IOleDocument *iface)
423 HTMLDocument *This = OLEDOC_THIS(iface);
424 return IHTMLDocument2_Release(HTMLDOC(This));
427 static HRESULT WINAPI OleDocument_CreateView(IOleDocument *iface, IOleInPlaceSite *pIPSite, IStream *pstm,
428 DWORD dwReserved, IOleDocumentView **ppView)
430 HTMLDocument *This = OLEDOC_THIS(iface);
433 TRACE("(%p)->(%p %p %ld %p)\n", This, pIPSite, pstm, dwReserved, ppView);
439 * Windows implementation creates new IOleDocumentView when function is called for the
440 * first time and returns E_FAIL when it is called for the second time, but it doesn't matter
441 * if the application uses returned interfaces, passed to ActivateMe or returned by
442 * QueryInterface, so there is no reason to create new interface. This needs more testing.
446 hres = IOleDocumentView_SetInPlaceSite(DOCVIEW(This), pIPSite);
452 FIXME("pstm is not supported\n");
454 IOleDocumentView_AddRef(DOCVIEW(This));
455 *ppView = DOCVIEW(This);
459 static HRESULT WINAPI OleDocument_GetDocMiscStatus(IOleDocument *iface, DWORD *pdwStatus)
461 HTMLDocument *This = OLEDOC_THIS(iface);
462 FIXME("(%p)->(%p)\n", This, pdwStatus);
466 static HRESULT WINAPI OleDocument_EnumViews(IOleDocument *iface, IEnumOleDocumentViews **ppEnum,
467 IOleDocumentView **ppView)
469 HTMLDocument *This = OLEDOC_THIS(iface);
470 FIXME("(%p)->(%p %p)\n", This, ppEnum, ppView);
476 static const IOleDocumentVtbl OleDocumentVtbl = {
477 OleDocument_QueryInterface,
480 OleDocument_CreateView,
481 OleDocument_GetDocMiscStatus,
482 OleDocument_EnumViews
485 /**********************************************************
486 * IOleControl implementation
489 #define CONTROL_THIS(iface) DEFINE_THIS(HTMLDocument, OleControl, iface)
491 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface, REFIID riid, void **ppv)
493 HTMLDocument *This = CONTROL_THIS(iface);
494 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
497 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
499 HTMLDocument *This = CONTROL_THIS(iface);
500 return IHTMLDocument2_AddRef(HTMLDOC(This));
503 static ULONG WINAPI OleControl_Release(IOleControl *iface)
505 HTMLDocument *This = CONTROL_THIS(iface);
506 return IHTMLDocument_Release(HTMLDOC(This));
509 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, CONTROLINFO *pCI)
511 HTMLDocument *This = CONTROL_THIS(iface);
512 FIXME("(%p)->(%p)\n", This, pCI);
516 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, MSG *pMsg)
518 HTMLDocument *This = CONTROL_THIS(iface);
519 FIXME("(%p)->(%p)\n", This, pMsg);
523 static HRESULT get_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
525 IDispatch *disp = NULL;
526 DISPPARAMS dispparams = {NULL, 0};
530 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
532 TRACE("Could not get IDispatch\n");
538 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
539 DISPATCH_PROPERTYGET, &dispparams, res, NULL, &err);
541 IDispatch_Release(disp);
546 static HRESULT on_change_dlcontrol(HTMLDocument *This)
551 hres = get_property(This->client, DISPID_AMBIENT_DLCONTROL, &res);
553 FIXME("unsupported dlcontrol %08lx\n", V_I4(&res));
558 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
560 HTMLDocument *This = CONTROL_THIS(iface);
565 TRACE("This->client = NULL\n");
570 case DISPID_AMBIENT_USERMODE:
571 TRACE("(%p)->(DISPID_AMBIENT_USERMODE)\n", This);
572 hres = get_property(This->client, DISPID_AMBIENT_USERMODE, &res);
576 if(V_VT(&res) == VT_BOOL) {
578 This->usermode = BROWSEMODE;
580 FIXME("edit mode is not supported\n");
581 This->usermode = EDITMODE;
584 FIXME("V_VT(res)=%d\n", V_VT(&res));
587 case DISPID_AMBIENT_DLCONTROL:
588 TRACE("(%p)->(DISPID_AMBIENT_DLCONTROL)\n", This);
589 return on_change_dlcontrol(This);
590 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
591 TRACE("(%p)->(DISPID_AMBIENT_OFFLINEIFNOTCONNECTED)\n", This);
592 on_change_dlcontrol(This);
593 hres = get_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &res);
597 if(V_VT(&res) == VT_BOOL) {
599 FIXME("offline connection is not supported\n");
603 FIXME("V_VT(res)=%d\n", V_VT(&res));
606 case DISPID_AMBIENT_SILENT:
607 TRACE("(%p)->(DISPID_AMBIENT_SILENT)\n", This);
608 on_change_dlcontrol(This);
609 hres = get_property(This->client, DISPID_AMBIENT_SILENT, &res);
613 if(V_VT(&res) == VT_BOOL) {
615 FIXME("silent mode is not supported\n");
619 FIXME("V_VT(res)=%d\n", V_VT(&res));
622 case DISPID_AMBIENT_USERAGENT:
623 TRACE("(%p)->(DISPID_AMBIENT_USERAGENT)\n", This);
624 hres = get_property(This->client, DISPID_AMBIENT_USERAGENT, &res);
628 FIXME("not supported AMBIENT_USERAGENT\n");
631 case DISPID_AMBIENT_PALETTE:
632 TRACE("(%p)->(DISPID_AMBIENT_PALETTE)\n", This);
633 hres = get_property(This->client, DISPID_AMBIENT_PALETTE, &res);
637 FIXME("not supported AMBIENT_PALETTE\n");
642 FIXME("(%p) unsupported dispID=%ld\n", This, dispID);
646 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
648 HTMLDocument *This = CONTROL_THIS(iface);
649 FIXME("(%p)->(%x)\n", This, bFreeze);
655 static const IOleControlVtbl OleControlVtbl = {
656 OleControl_QueryInterface,
659 OleControl_GetControlInfo,
660 OleControl_OnMnemonic,
661 OleControl_OnAmbientPropertyChange,
662 OleControl_FreezeEvents
665 void HTMLDocument_LockContainer(HTMLDocument *This, BOOL fLock)
667 IOleContainer *container;
670 if(!This->client || This->container_locked == fLock)
673 hres = IOleClientSite_GetContainer(This->client, &container);
674 if(SUCCEEDED(hres)) {
675 IOleContainer_LockContainer(container, fLock);
676 This->container_locked = fLock;
677 IOleContainer_Release(container);
681 void HTMLDocument_OleObj_Init(HTMLDocument *This)
683 This->lpOleObjectVtbl = &OleObjectVtbl;
684 This->lpOleDocumentVtbl = &OleDocumentVtbl;
685 This->lpOleControlVtbl = &OleControlVtbl;
687 This->usermode = UNKNOWN_USERMODE;
692 This->has_key_path = FALSE;
693 This->container_locked = FALSE;