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);
87 memset(&This->hostinfo, 0, sizeof(DOCHOSTUIINFO));
92 hres = IOleObject_QueryInterface(pClientSite, &IID_IDocHostUIHandler, (void**)&pDocHostUIHandler);
94 DOCHOSTUIINFO hostinfo;
95 LPOLESTR key_path = NULL, override_key_path = NULL;
96 IDocHostUIHandler2 *pDocHostUIHandler2;
98 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
99 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
100 hres = IDocHostUIHandler_GetHostInfo(pDocHostUIHandler, &hostinfo);
101 if(SUCCEEDED(hres)) {
102 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
103 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
104 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
105 memcpy(&This->hostinfo, &hostinfo, sizeof(DOCHOSTUIINFO));
108 if(!This->has_key_path) {
109 hres = IDocHostUIHandler_GetOptionKeyPath(pDocHostUIHandler, &key_path, 0);
110 if(hres == S_OK && key_path) {
112 /* FIXME: use key_path */
113 TRACE("key_path = %s\n", debugstr_w(key_path));
115 CoTaskMemFree(key_path);
118 hres = IDocHostUIHandler_QueryInterface(pDocHostUIHandler, &IID_IDocHostUIHandler2,
119 (void**)&pDocHostUIHandler2);
120 if(SUCCEEDED(hres)) {
121 hres = IDocHostUIHandler2_GetOverrideKeyPath(pDocHostUIHandler2, &override_key_path, 0);
122 if(hres == S_OK && override_key_path && override_key_path[0]) {
123 if(override_key_path[0]) {
124 /*FIXME: use override_key_path */
125 TRACE("override_key_path = %s\n", debugstr_w(override_key_path));
127 CoTaskMemFree(override_key_path);
129 IDocHostUIHandler2_Release(pDocHostUIHandler2);
132 This->has_key_path = TRUE;
136 /* Native calls here GetWindow. What is it for?
137 * We don't have anything to do with it here (yet). */
139 IOleWindow *pOleWindow = NULL;
142 hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleWindow, (void**)&pOleWindow);
143 if(SUCCEEDED(hres)) {
144 IOleWindow_GetWindow(pOleWindow, &hwnd);
145 IOleWindow_Release(pOleWindow);
149 hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleCommandTarget, (void**)&cmdtrg);
150 if(SUCCEEDED(hres)) {
152 OLECMD cmd = {OLECMDID_SETPROGRESSTEXT, 0};
154 IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &cmd, NULL);
158 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
159 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
160 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS,
161 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
163 IOleCommandTarget_Release(cmdtrg);
166 IOleClientSite_AddRef(pClientSite);
167 This->client = pClientSite;
168 This->hostui = pDocHostUIHandler;
170 if(This->usermode == UNKNOWN_USERMODE)
171 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERMODE);
173 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
174 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_SILENT);
175 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERAGENT);
176 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_PALETTE);
181 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, IOleClientSite **ppClientSite)
183 HTMLDocument *This = OLEOBJ_THIS(iface);
185 TRACE("(%p)->(%p)\n", This, ppClientSite);
191 IOleClientSite_AddRef(This->client);
192 *ppClientSite = This->client;
197 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
199 HTMLDocument *This = OLEOBJ_THIS(iface);
200 FIXME("(%p)->(%s %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
204 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
206 HTMLDocument *This = OLEOBJ_THIS(iface);
208 TRACE("(%p)->(%08x)\n", This, dwSaveOption);
210 if(dwSaveOption == OLECLOSE_PROMPTSAVE)
211 FIXME("OLECLOSE_PROMPTSAVE not implemented\n");
213 if(This->in_place_active)
214 IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This));
216 HTMLDocument_LockContainer(This, FALSE);
221 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker *pmk)
223 HTMLDocument *This = OLEOBJ_THIS(iface);
224 FIXME("(%p %d %p)->()\n", This, dwWhichMoniker, pmk);
228 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
230 HTMLDocument *This = OLEOBJ_THIS(iface);
231 FIXME("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
235 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, IDataObject *pDataObject, BOOL fCreation,
238 HTMLDocument *This = OLEOBJ_THIS(iface);
239 FIXME("(%p)->(%p %x %d)\n", This, pDataObject, fCreation, dwReserved);
243 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved, IDataObject **ppDataObject)
245 HTMLDocument *This = OLEOBJ_THIS(iface);
246 FIXME("(%p)->(%d %p)\n", This, dwReserved, ppDataObject);
250 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite,
251 LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
253 HTMLDocument *This = OLEOBJ_THIS(iface);
254 IOleDocumentSite *pDocSite;
257 TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
259 if(iVerb != OLEIVERB_SHOW && iVerb != OLEIVERB_UIACTIVATE && iVerb != OLEIVERB_INPLACEACTIVATE) {
260 FIXME("iVerb = %d not supported\n", iVerb);
265 pActiveSite = This->client;
267 hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleDocumentSite, (void**)&pDocSite);
268 if(SUCCEEDED(hres)) {
269 HTMLDocument_LockContainer(This, TRUE);
271 /* FIXME: Create new IOleDocumentView. See CreateView for more info. */
272 hres = IOleDocumentSite_ActivateMe(pDocSite, DOCVIEW(This));
273 IOleDocumentSite_Release(pDocSite);
275 hres = IOleDocumentView_UIActivate(DOCVIEW(This), TRUE);
276 if(SUCCEEDED(hres)) {
278 RECT rect; /* We need to pass rect as not const pointer */
279 memcpy(&rect, lprcPosRect, sizeof(RECT));
280 IOleDocumentView_SetRect(DOCVIEW(This), &rect);
282 IOleDocumentView_Show(DOCVIEW(This), TRUE);
289 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
291 HTMLDocument *This = OLEOBJ_THIS(iface);
292 FIXME("(%p)->(%p)\n", This, ppEnumOleVerb);
296 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
298 HTMLDocument *This = OLEOBJ_THIS(iface);
299 FIXME("(%p)\n", This);
303 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
305 HTMLDocument *This = OLEOBJ_THIS(iface);
306 FIXME("(%p)\n", This);
310 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
312 HTMLDocument *This = OLEOBJ_THIS(iface);
314 TRACE("(%p)->(%p)\n", This, pClsid);
319 memcpy(pClsid, &CLSID_HTMLDocument, sizeof(GUID));
323 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType, LPOLESTR *pszUserType)
325 HTMLDocument *This = OLEOBJ_THIS(iface);
326 FIXME("(%p)->(%d %p)\n", This, dwFormOfType, pszUserType);
330 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
332 HTMLDocument *This = OLEOBJ_THIS(iface);
333 FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
337 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
339 HTMLDocument *This = OLEOBJ_THIS(iface);
340 FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
344 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink, DWORD *pdwConnection)
346 HTMLDocument *This = OLEOBJ_THIS(iface);
347 FIXME("(%p)->(%p %p)\n", This, pAdvSink, pdwConnection);
351 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
353 HTMLDocument *This = OLEOBJ_THIS(iface);
354 FIXME("(%p)->(%d)\n", This, dwConnection);
358 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
360 HTMLDocument *This = OLEOBJ_THIS(iface);
361 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
365 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
367 HTMLDocument *This = OLEOBJ_THIS(iface);
368 FIXME("(%p)->(%d %p)\n", This, dwAspect, pdwStatus);
372 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *pLogpal)
374 HTMLDocument *This = OLEOBJ_THIS(iface);
375 FIXME("(%p)->(%p)\n", This, pLogpal);
381 static const IOleObjectVtbl OleObjectVtbl = {
382 OleObject_QueryInterface,
385 OleObject_SetClientSite,
386 OleObject_GetClientSite,
387 OleObject_SetHostNames,
389 OleObject_SetMoniker,
390 OleObject_GetMoniker,
391 OleObject_InitFromData,
392 OleObject_GetClipboardData,
396 OleObject_IsUpToDate,
397 OleObject_GetUserClassID,
398 OleObject_GetUserType,
403 OleObject_EnumAdvise,
404 OleObject_GetMiscStatus,
405 OleObject_SetColorScheme
408 /**********************************************************
409 * IOleDocument implementation
412 #define OLEDOC_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocument, iface)
414 static HRESULT WINAPI OleDocument_QueryInterface(IOleDocument *iface, REFIID riid, void **ppvObject)
416 HTMLDocument *This = OLEDOC_THIS(iface);
417 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
420 static ULONG WINAPI OleDocument_AddRef(IOleDocument *iface)
422 HTMLDocument *This = OLEDOC_THIS(iface);
423 return IHTMLDocument2_AddRef(HTMLDOC(This));
426 static ULONG WINAPI OleDocument_Release(IOleDocument *iface)
428 HTMLDocument *This = OLEDOC_THIS(iface);
429 return IHTMLDocument2_Release(HTMLDOC(This));
432 static HRESULT WINAPI OleDocument_CreateView(IOleDocument *iface, IOleInPlaceSite *pIPSite, IStream *pstm,
433 DWORD dwReserved, IOleDocumentView **ppView)
435 HTMLDocument *This = OLEDOC_THIS(iface);
438 TRACE("(%p)->(%p %p %d %p)\n", This, pIPSite, pstm, dwReserved, ppView);
444 * Windows implementation creates new IOleDocumentView when function is called for the
445 * first time and returns E_FAIL when it is called for the second time, but it doesn't matter
446 * if the application uses returned interfaces, passed to ActivateMe or returned by
447 * QueryInterface, so there is no reason to create new interface. This needs more testing.
451 hres = IOleDocumentView_SetInPlaceSite(DOCVIEW(This), pIPSite);
457 FIXME("pstm is not supported\n");
459 IOleDocumentView_AddRef(DOCVIEW(This));
460 *ppView = DOCVIEW(This);
464 static HRESULT WINAPI OleDocument_GetDocMiscStatus(IOleDocument *iface, DWORD *pdwStatus)
466 HTMLDocument *This = OLEDOC_THIS(iface);
467 FIXME("(%p)->(%p)\n", This, pdwStatus);
471 static HRESULT WINAPI OleDocument_EnumViews(IOleDocument *iface, IEnumOleDocumentViews **ppEnum,
472 IOleDocumentView **ppView)
474 HTMLDocument *This = OLEDOC_THIS(iface);
475 FIXME("(%p)->(%p %p)\n", This, ppEnum, ppView);
481 static const IOleDocumentVtbl OleDocumentVtbl = {
482 OleDocument_QueryInterface,
485 OleDocument_CreateView,
486 OleDocument_GetDocMiscStatus,
487 OleDocument_EnumViews
490 /**********************************************************
491 * IOleControl implementation
494 #define CONTROL_THIS(iface) DEFINE_THIS(HTMLDocument, OleControl, iface)
496 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface, REFIID riid, void **ppv)
498 HTMLDocument *This = CONTROL_THIS(iface);
499 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
502 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
504 HTMLDocument *This = CONTROL_THIS(iface);
505 return IHTMLDocument2_AddRef(HTMLDOC(This));
508 static ULONG WINAPI OleControl_Release(IOleControl *iface)
510 HTMLDocument *This = CONTROL_THIS(iface);
511 return IHTMLDocument_Release(HTMLDOC(This));
514 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, CONTROLINFO *pCI)
516 HTMLDocument *This = CONTROL_THIS(iface);
517 FIXME("(%p)->(%p)\n", This, pCI);
521 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, MSG *pMsg)
523 HTMLDocument *This = CONTROL_THIS(iface);
524 FIXME("(%p)->(%p)\n", This, pMsg);
528 HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
530 IDispatch *disp = NULL;
531 DISPPARAMS dispparams = {NULL, 0};
535 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
537 TRACE("Could not get IDispatch\n");
543 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
544 DISPATCH_PROPERTYGET, &dispparams, res, NULL, &err);
546 IDispatch_Release(disp);
551 static HRESULT on_change_dlcontrol(HTMLDocument *This)
556 hres = get_client_disp_property(This->client, DISPID_AMBIENT_DLCONTROL, &res);
558 FIXME("unsupported dlcontrol %08x\n", V_I4(&res));
563 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
565 HTMLDocument *This = CONTROL_THIS(iface);
570 TRACE("This->client = NULL\n");
575 case DISPID_AMBIENT_USERMODE:
576 TRACE("(%p)->(DISPID_AMBIENT_USERMODE)\n", This);
577 hres = get_client_disp_property(This->client, DISPID_AMBIENT_USERMODE, &res);
581 if(V_VT(&res) == VT_BOOL) {
583 This->usermode = BROWSEMODE;
585 FIXME("edit mode is not supported\n");
586 This->usermode = EDITMODE;
589 FIXME("V_VT(res)=%d\n", V_VT(&res));
592 case DISPID_AMBIENT_DLCONTROL:
593 TRACE("(%p)->(DISPID_AMBIENT_DLCONTROL)\n", This);
594 return on_change_dlcontrol(This);
595 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
596 TRACE("(%p)->(DISPID_AMBIENT_OFFLINEIFNOTCONNECTED)\n", This);
597 on_change_dlcontrol(This);
598 hres = get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &res);
602 if(V_VT(&res) == VT_BOOL) {
604 FIXME("offline connection is not supported\n");
608 FIXME("V_VT(res)=%d\n", V_VT(&res));
611 case DISPID_AMBIENT_SILENT:
612 TRACE("(%p)->(DISPID_AMBIENT_SILENT)\n", This);
613 on_change_dlcontrol(This);
614 hres = get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &res);
618 if(V_VT(&res) == VT_BOOL) {
620 FIXME("silent mode is not supported\n");
624 FIXME("V_VT(res)=%d\n", V_VT(&res));
627 case DISPID_AMBIENT_USERAGENT:
628 TRACE("(%p)->(DISPID_AMBIENT_USERAGENT)\n", This);
629 hres = get_client_disp_property(This->client, DISPID_AMBIENT_USERAGENT, &res);
633 FIXME("not supported AMBIENT_USERAGENT\n");
636 case DISPID_AMBIENT_PALETTE:
637 TRACE("(%p)->(DISPID_AMBIENT_PALETTE)\n", This);
638 hres = get_client_disp_property(This->client, DISPID_AMBIENT_PALETTE, &res);
642 FIXME("not supported AMBIENT_PALETTE\n");
647 FIXME("(%p) unsupported dispID=%d\n", This, dispID);
651 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
653 HTMLDocument *This = CONTROL_THIS(iface);
654 FIXME("(%p)->(%x)\n", This, bFreeze);
660 static const IOleControlVtbl OleControlVtbl = {
661 OleControl_QueryInterface,
664 OleControl_GetControlInfo,
665 OleControl_OnMnemonic,
666 OleControl_OnAmbientPropertyChange,
667 OleControl_FreezeEvents
670 void HTMLDocument_LockContainer(HTMLDocument *This, BOOL fLock)
672 IOleContainer *container;
675 if(!This->client || This->container_locked == fLock)
678 hres = IOleClientSite_GetContainer(This->client, &container);
679 if(SUCCEEDED(hres)) {
680 IOleContainer_LockContainer(container, fLock);
681 This->container_locked = fLock;
682 IOleContainer_Release(container);
686 void HTMLDocument_OleObj_Init(HTMLDocument *This)
688 This->lpOleObjectVtbl = &OleObjectVtbl;
689 This->lpOleDocumentVtbl = &OleDocumentVtbl;
690 This->lpOleControlVtbl = &OleControlVtbl;
692 This->usermode = UNKNOWN_USERMODE;
697 This->has_key_path = FALSE;
698 This->container_locked = FALSE;
700 memset(&This->hostinfo, 0, sizeof(DOCHOSTUIINFO));