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 = {%u %08x %08x %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,
156 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
157 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS,
158 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
160 IOleCommandTarget_Release(cmdtrg);
163 IOleClientSite_AddRef(pClientSite);
164 This->client = pClientSite;
165 This->hostui = pDocHostUIHandler;
167 if(This->usermode == UNKNOWN_USERMODE)
168 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERMODE);
170 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
171 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_SILENT);
172 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_USERAGENT);
173 IOleControl_OnAmbientPropertyChange(CONTROL(This), DISPID_AMBIENT_PALETTE);
178 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, IOleClientSite **ppClientSite)
180 HTMLDocument *This = OLEOBJ_THIS(iface);
182 TRACE("(%p)->(%p)\n", This, ppClientSite);
188 IOleClientSite_AddRef(This->client);
189 *ppClientSite = This->client;
194 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
196 HTMLDocument *This = OLEOBJ_THIS(iface);
197 FIXME("(%p)->(%s %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
201 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
203 HTMLDocument *This = OLEOBJ_THIS(iface);
205 TRACE("(%p)->(%08x)\n", This, dwSaveOption);
207 if(dwSaveOption == OLECLOSE_PROMPTSAVE)
208 FIXME("OLECLOSE_PROMPTSAVE not implemented\n");
210 if(This->in_place_active)
211 IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This));
213 HTMLDocument_LockContainer(This, FALSE);
218 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker *pmk)
220 HTMLDocument *This = OLEOBJ_THIS(iface);
221 FIXME("(%p %d %p)->()\n", This, dwWhichMoniker, pmk);
225 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
227 HTMLDocument *This = OLEOBJ_THIS(iface);
228 FIXME("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
232 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, IDataObject *pDataObject, BOOL fCreation,
235 HTMLDocument *This = OLEOBJ_THIS(iface);
236 FIXME("(%p)->(%p %x %d)\n", This, pDataObject, fCreation, dwReserved);
240 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved, IDataObject **ppDataObject)
242 HTMLDocument *This = OLEOBJ_THIS(iface);
243 FIXME("(%p)->(%d %p)\n", This, dwReserved, ppDataObject);
247 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite,
248 LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
250 HTMLDocument *This = OLEOBJ_THIS(iface);
251 IOleDocumentSite *pDocSite;
254 TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
256 if(iVerb != OLEIVERB_SHOW && iVerb != OLEIVERB_UIACTIVATE && iVerb != OLEIVERB_INPLACEACTIVATE) {
257 FIXME("iVerb = %d not supported\n", iVerb);
262 pActiveSite = This->client;
264 hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleDocumentSite, (void**)&pDocSite);
265 if(SUCCEEDED(hres)) {
266 HTMLDocument_LockContainer(This, TRUE);
268 /* FIXME: Create new IOleDocumentView. See CreateView for more info. */
269 hres = IOleDocumentSite_ActivateMe(pDocSite, DOCVIEW(This));
270 IOleDocumentSite_Release(pDocSite);
272 hres = IOleDocumentView_UIActivate(DOCVIEW(This), TRUE);
273 if(SUCCEEDED(hres)) {
275 RECT rect; /* We need to pass rect as not const pointer */
276 memcpy(&rect, lprcPosRect, sizeof(RECT));
277 IOleDocumentView_SetRect(DOCVIEW(This), &rect);
279 IOleDocumentView_Show(DOCVIEW(This), TRUE);
286 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
288 HTMLDocument *This = OLEOBJ_THIS(iface);
289 FIXME("(%p)->(%p)\n", This, ppEnumOleVerb);
293 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
295 HTMLDocument *This = OLEOBJ_THIS(iface);
296 FIXME("(%p)\n", This);
300 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
302 HTMLDocument *This = OLEOBJ_THIS(iface);
303 FIXME("(%p)\n", This);
307 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
309 HTMLDocument *This = OLEOBJ_THIS(iface);
311 TRACE("(%p)->(%p)\n", This, pClsid);
316 memcpy(pClsid, &CLSID_HTMLDocument, sizeof(GUID));
320 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType, LPOLESTR *pszUserType)
322 HTMLDocument *This = OLEOBJ_THIS(iface);
323 FIXME("(%p)->(%d %p)\n", This, dwFormOfType, pszUserType);
327 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
329 HTMLDocument *This = OLEOBJ_THIS(iface);
330 FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
334 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
336 HTMLDocument *This = OLEOBJ_THIS(iface);
337 FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
341 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink, DWORD *pdwConnection)
343 HTMLDocument *This = OLEOBJ_THIS(iface);
344 FIXME("(%p)->(%p %p)\n", This, pAdvSink, pdwConnection);
348 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
350 HTMLDocument *This = OLEOBJ_THIS(iface);
351 FIXME("(%p)->(%d)\n", This, dwConnection);
355 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
357 HTMLDocument *This = OLEOBJ_THIS(iface);
358 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
362 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
364 HTMLDocument *This = OLEOBJ_THIS(iface);
365 FIXME("(%p)->(%d %p)\n", This, dwAspect, pdwStatus);
369 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *pLogpal)
371 HTMLDocument *This = OLEOBJ_THIS(iface);
372 FIXME("(%p)->(%p)\n", This, pLogpal);
378 static const IOleObjectVtbl OleObjectVtbl = {
379 OleObject_QueryInterface,
382 OleObject_SetClientSite,
383 OleObject_GetClientSite,
384 OleObject_SetHostNames,
386 OleObject_SetMoniker,
387 OleObject_GetMoniker,
388 OleObject_InitFromData,
389 OleObject_GetClipboardData,
393 OleObject_IsUpToDate,
394 OleObject_GetUserClassID,
395 OleObject_GetUserType,
400 OleObject_EnumAdvise,
401 OleObject_GetMiscStatus,
402 OleObject_SetColorScheme
405 /**********************************************************
406 * IOleDocument implementation
409 #define OLEDOC_THIS(iface) DEFINE_THIS(HTMLDocument, OleDocument, iface)
411 static HRESULT WINAPI OleDocument_QueryInterface(IOleDocument *iface, REFIID riid, void **ppvObject)
413 HTMLDocument *This = OLEDOC_THIS(iface);
414 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppvObject);
417 static ULONG WINAPI OleDocument_AddRef(IOleDocument *iface)
419 HTMLDocument *This = OLEDOC_THIS(iface);
420 return IHTMLDocument2_AddRef(HTMLDOC(This));
423 static ULONG WINAPI OleDocument_Release(IOleDocument *iface)
425 HTMLDocument *This = OLEDOC_THIS(iface);
426 return IHTMLDocument2_Release(HTMLDOC(This));
429 static HRESULT WINAPI OleDocument_CreateView(IOleDocument *iface, IOleInPlaceSite *pIPSite, IStream *pstm,
430 DWORD dwReserved, IOleDocumentView **ppView)
432 HTMLDocument *This = OLEDOC_THIS(iface);
435 TRACE("(%p)->(%p %p %d %p)\n", This, pIPSite, pstm, dwReserved, ppView);
441 * Windows implementation creates new IOleDocumentView when function is called for the
442 * first time and returns E_FAIL when it is called for the second time, but it doesn't matter
443 * if the application uses returned interfaces, passed to ActivateMe or returned by
444 * QueryInterface, so there is no reason to create new interface. This needs more testing.
448 hres = IOleDocumentView_SetInPlaceSite(DOCVIEW(This), pIPSite);
454 FIXME("pstm is not supported\n");
456 IOleDocumentView_AddRef(DOCVIEW(This));
457 *ppView = DOCVIEW(This);
461 static HRESULT WINAPI OleDocument_GetDocMiscStatus(IOleDocument *iface, DWORD *pdwStatus)
463 HTMLDocument *This = OLEDOC_THIS(iface);
464 FIXME("(%p)->(%p)\n", This, pdwStatus);
468 static HRESULT WINAPI OleDocument_EnumViews(IOleDocument *iface, IEnumOleDocumentViews **ppEnum,
469 IOleDocumentView **ppView)
471 HTMLDocument *This = OLEDOC_THIS(iface);
472 FIXME("(%p)->(%p %p)\n", This, ppEnum, ppView);
478 static const IOleDocumentVtbl OleDocumentVtbl = {
479 OleDocument_QueryInterface,
482 OleDocument_CreateView,
483 OleDocument_GetDocMiscStatus,
484 OleDocument_EnumViews
487 /**********************************************************
488 * IOleControl implementation
491 #define CONTROL_THIS(iface) DEFINE_THIS(HTMLDocument, OleControl, iface)
493 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface, REFIID riid, void **ppv)
495 HTMLDocument *This = CONTROL_THIS(iface);
496 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
499 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
501 HTMLDocument *This = CONTROL_THIS(iface);
502 return IHTMLDocument2_AddRef(HTMLDOC(This));
505 static ULONG WINAPI OleControl_Release(IOleControl *iface)
507 HTMLDocument *This = CONTROL_THIS(iface);
508 return IHTMLDocument_Release(HTMLDOC(This));
511 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, CONTROLINFO *pCI)
513 HTMLDocument *This = CONTROL_THIS(iface);
514 FIXME("(%p)->(%p)\n", This, pCI);
518 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, MSG *pMsg)
520 HTMLDocument *This = CONTROL_THIS(iface);
521 FIXME("(%p)->(%p)\n", This, pMsg);
525 HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
527 IDispatch *disp = NULL;
528 DISPPARAMS dispparams = {NULL, 0};
532 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
534 TRACE("Could not get IDispatch\n");
540 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
541 DISPATCH_PROPERTYGET, &dispparams, res, NULL, &err);
543 IDispatch_Release(disp);
548 static HRESULT on_change_dlcontrol(HTMLDocument *This)
553 hres = get_client_disp_property(This->client, DISPID_AMBIENT_DLCONTROL, &res);
555 FIXME("unsupported dlcontrol %08x\n", V_I4(&res));
560 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
562 HTMLDocument *This = CONTROL_THIS(iface);
567 TRACE("This->client = NULL\n");
572 case DISPID_AMBIENT_USERMODE:
573 TRACE("(%p)->(DISPID_AMBIENT_USERMODE)\n", This);
574 hres = get_client_disp_property(This->client, DISPID_AMBIENT_USERMODE, &res);
578 if(V_VT(&res) == VT_BOOL) {
580 This->usermode = BROWSEMODE;
582 FIXME("edit mode is not supported\n");
583 This->usermode = EDITMODE;
586 FIXME("V_VT(res)=%d\n", V_VT(&res));
589 case DISPID_AMBIENT_DLCONTROL:
590 TRACE("(%p)->(DISPID_AMBIENT_DLCONTROL)\n", This);
591 return on_change_dlcontrol(This);
592 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
593 TRACE("(%p)->(DISPID_AMBIENT_OFFLINEIFNOTCONNECTED)\n", This);
594 on_change_dlcontrol(This);
595 hres = get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &res);
599 if(V_VT(&res) == VT_BOOL) {
601 FIXME("offline connection is not supported\n");
605 FIXME("V_VT(res)=%d\n", V_VT(&res));
608 case DISPID_AMBIENT_SILENT:
609 TRACE("(%p)->(DISPID_AMBIENT_SILENT)\n", This);
610 on_change_dlcontrol(This);
611 hres = get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &res);
615 if(V_VT(&res) == VT_BOOL) {
617 FIXME("silent mode is not supported\n");
621 FIXME("V_VT(res)=%d\n", V_VT(&res));
624 case DISPID_AMBIENT_USERAGENT:
625 TRACE("(%p)->(DISPID_AMBIENT_USERAGENT)\n", This);
626 hres = get_client_disp_property(This->client, DISPID_AMBIENT_USERAGENT, &res);
630 FIXME("not supported AMBIENT_USERAGENT\n");
633 case DISPID_AMBIENT_PALETTE:
634 TRACE("(%p)->(DISPID_AMBIENT_PALETTE)\n", This);
635 hres = get_client_disp_property(This->client, DISPID_AMBIENT_PALETTE, &res);
639 FIXME("not supported AMBIENT_PALETTE\n");
644 FIXME("(%p) unsupported dispID=%d\n", This, dispID);
648 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
650 HTMLDocument *This = CONTROL_THIS(iface);
651 FIXME("(%p)->(%x)\n", This, bFreeze);
657 static const IOleControlVtbl OleControlVtbl = {
658 OleControl_QueryInterface,
661 OleControl_GetControlInfo,
662 OleControl_OnMnemonic,
663 OleControl_OnAmbientPropertyChange,
664 OleControl_FreezeEvents
667 void HTMLDocument_LockContainer(HTMLDocument *This, BOOL fLock)
669 IOleContainer *container;
672 if(!This->client || This->container_locked == fLock)
675 hres = IOleClientSite_GetContainer(This->client, &container);
676 if(SUCCEEDED(hres)) {
677 IOleContainer_LockContainer(container, fLock);
678 This->container_locked = fLock;
679 IOleContainer_Release(container);
683 void HTMLDocument_OleObj_Init(HTMLDocument *This)
685 This->lpOleObjectVtbl = &OleObjectVtbl;
686 This->lpOleDocumentVtbl = &OleDocumentVtbl;
687 This->lpOleControlVtbl = &OleControlVtbl;
689 This->usermode = UNKNOWN_USERMODE;
694 This->has_key_path = FALSE;
695 This->container_locked = FALSE;