gdi32: Allocate smaller buffer in delete_external_font_keys helper.
[wine.git] / dlls / mshtml / oleobj.c
blob7809eb0bb6bb9a520d4f540dfad4e9deb21e3a3c
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <assert.h>
25 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "shlguid.h"
32 #include "shdeprecated.h"
33 #include "mshtmdid.h"
34 #include "idispids.h"
36 #include "wine/debug.h"
38 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 #define DOCHOST_DOCCANNAVIGATE 0
44 typedef struct {
45 IEnumUnknown IEnumUnknown_iface;
46 LONG ref;
47 } EnumUnknown;
49 static inline EnumUnknown *impl_from_IEnumUnknown(IEnumUnknown *iface)
51 return CONTAINING_RECORD(iface, EnumUnknown, IEnumUnknown_iface);
54 static HRESULT WINAPI EnumUnknown_QueryInterface(IEnumUnknown *iface, REFIID riid, void **ppv)
56 EnumUnknown *This = impl_from_IEnumUnknown(iface);
58 if(IsEqualGUID(&IID_IUnknown, riid)) {
59 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
60 *ppv = &This->IEnumUnknown_iface;
61 }else if(IsEqualGUID(&IID_IEnumUnknown, riid)) {
62 TRACE("(%p)->(IID_IEnumUnknown %p)\n", This, ppv);
63 *ppv = &This->IEnumUnknown_iface;
64 }else {
65 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
66 *ppv = NULL;
67 return E_NOINTERFACE;
70 IUnknown_AddRef((IUnknown*)*ppv);
71 return S_OK;
74 static ULONG WINAPI EnumUnknown_AddRef(IEnumUnknown *iface)
76 EnumUnknown *This = impl_from_IEnumUnknown(iface);
77 LONG ref = InterlockedIncrement(&This->ref);
79 TRACE("(%p) ref=%d\n", This, ref);
81 return ref;
84 static ULONG WINAPI EnumUnknown_Release(IEnumUnknown *iface)
86 EnumUnknown *This = impl_from_IEnumUnknown(iface);
87 LONG ref = InterlockedDecrement(&This->ref);
89 TRACE("(%p) ref=%d\n", This, ref);
91 if(!ref)
92 heap_free(This);
94 return ref;
97 static HRESULT WINAPI EnumUnknown_Next(IEnumUnknown *iface, ULONG celt, IUnknown **rgelt, ULONG *pceltFetched)
99 EnumUnknown *This = impl_from_IEnumUnknown(iface);
101 TRACE("(%p)->(%u %p %p)\n", This, celt, rgelt, pceltFetched);
103 /* FIXME: It's not clear if we should ever return something here */
104 if(pceltFetched)
105 *pceltFetched = 0;
106 return S_FALSE;
109 static HRESULT WINAPI EnumUnknown_Skip(IEnumUnknown *iface, ULONG celt)
111 EnumUnknown *This = impl_from_IEnumUnknown(iface);
112 FIXME("(%p)->(%u)\n", This, celt);
113 return E_NOTIMPL;
116 static HRESULT WINAPI EnumUnknown_Reset(IEnumUnknown *iface)
118 EnumUnknown *This = impl_from_IEnumUnknown(iface);
119 FIXME("(%p)\n", This);
120 return E_NOTIMPL;
123 static HRESULT WINAPI EnumUnknown_Clone(IEnumUnknown *iface, IEnumUnknown **ppenum)
125 EnumUnknown *This = impl_from_IEnumUnknown(iface);
126 FIXME("(%p)->(%p)\n", This, ppenum);
127 return E_NOTIMPL;
130 static const IEnumUnknownVtbl EnumUnknownVtbl = {
131 EnumUnknown_QueryInterface,
132 EnumUnknown_AddRef,
133 EnumUnknown_Release,
134 EnumUnknown_Next,
135 EnumUnknown_Skip,
136 EnumUnknown_Reset,
137 EnumUnknown_Clone
140 /**********************************************************
141 * IOleObject implementation
144 static inline HTMLDocument *impl_from_IOleObject(IOleObject *iface)
146 return CONTAINING_RECORD(iface, HTMLDocument, IOleObject_iface);
149 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
151 HTMLDocument *This = impl_from_IOleObject(iface);
152 return htmldoc_query_interface(This, riid, ppv);
155 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
157 HTMLDocument *This = impl_from_IOleObject(iface);
158 return htmldoc_addref(This);
161 static ULONG WINAPI OleObject_Release(IOleObject *iface)
163 HTMLDocument *This = impl_from_IOleObject(iface);
164 return htmldoc_release(This);
167 static void update_hostinfo(HTMLDocumentObj *This, DOCHOSTUIINFO *hostinfo)
169 nsIScrollable *scrollable;
170 nsresult nsres;
172 if(!This->nscontainer)
173 return;
175 nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
176 if(NS_SUCCEEDED(nsres)) {
177 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable, ScrollOrientation_Y,
178 (hostinfo->dwFlags & DOCHOSTUIFLAG_SCROLL_NO) ? Scrollbar_Never : Scrollbar_Always);
179 if(NS_FAILED(nsres))
180 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres);
182 nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable, ScrollOrientation_X,
183 hostinfo->dwFlags & DOCHOSTUIFLAG_SCROLL_NO ? Scrollbar_Never : Scrollbar_Auto);
184 if(NS_FAILED(nsres))
185 ERR("Could not set default X scrollbar prefs: %08x\n", nsres);
187 nsIScrollable_Release(scrollable);
188 }else {
189 ERR("Could not get nsIScrollable: %08x\n", nsres);
193 /* Calls undocumented 84 cmd of CGID_ShellDocView */
194 void call_docview_84(HTMLDocumentObj *doc)
196 IOleCommandTarget *olecmd;
197 VARIANT var;
198 HRESULT hres;
200 if(!doc->client)
201 return;
203 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
204 if(FAILED(hres))
205 return;
207 VariantInit(&var);
208 hres = IOleCommandTarget_Exec(olecmd, &CGID_ShellDocView, 84, 0, NULL, &var);
209 IOleCommandTarget_Release(olecmd);
210 if(SUCCEEDED(hres) && V_VT(&var) != VT_NULL)
211 FIXME("handle result\n");
214 void set_document_navigation(HTMLDocumentObj *doc, BOOL doc_can_navigate)
216 VARIANT var;
218 if(!doc->client_cmdtrg)
219 return;
221 if(doc_can_navigate) {
222 V_VT(&var) = VT_UNKNOWN;
223 V_UNKNOWN(&var) = (IUnknown*)&doc->basedoc.window->base.IHTMLWindow2_iface;
226 IOleCommandTarget_Exec(doc->client_cmdtrg, &CGID_DocHostCmdPriv, DOCHOST_DOCCANNAVIGATE, 0,
227 doc_can_navigate ? &var : NULL, NULL);
230 static void load_settings(HTMLDocumentObj *doc)
232 HKEY settings_key;
233 DWORD val, size;
234 LONG res;
236 static const WCHAR ie_keyW[] = {
237 'S','O','F','T','W','A','R','E','\\',
238 'M','i','c','r','o','s','o','f','t','\\',
239 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
240 static const WCHAR zoomW[] = {'Z','o','o','m',0};
241 static const WCHAR zoom_factorW[] = {'Z','o','o','m','F','a','c','t','o','r',0};
243 res = RegOpenKeyW(HKEY_CURRENT_USER, ie_keyW, &settings_key);
244 if(res != ERROR_SUCCESS)
245 return;
247 size = sizeof(val);
248 res = RegGetValueW(settings_key, zoomW, zoom_factorW, RRF_RT_REG_DWORD, NULL, &val, &size);
249 RegCloseKey(settings_key);
250 if(res == ERROR_SUCCESS)
251 set_viewer_zoom(doc->nscontainer, (float)val/100000);
254 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, IOleClientSite *pClientSite)
256 HTMLDocument *This = impl_from_IOleObject(iface);
257 IOleCommandTarget *cmdtrg = NULL;
258 IOleWindow *ole_window;
259 IBrowserService *browser_service;
260 BOOL hostui_setup;
261 VARIANT silent;
262 HWND hwnd;
263 HRESULT hres;
265 TRACE("(%p)->(%p)\n", This, pClientSite);
267 if(pClientSite == This->doc_obj->client)
268 return S_OK;
270 if(This->doc_obj->client) {
271 IOleClientSite_Release(This->doc_obj->client);
272 This->doc_obj->client = NULL;
273 This->doc_obj->usermode = UNKNOWN_USERMODE;
276 if(This->doc_obj->client_cmdtrg) {
277 IOleCommandTarget_Release(This->doc_obj->client_cmdtrg);
278 This->doc_obj->client_cmdtrg = NULL;
281 if(This->doc_obj->hostui && !This->doc_obj->custom_hostui) {
282 IDocHostUIHandler_Release(This->doc_obj->hostui);
283 This->doc_obj->hostui = NULL;
286 if(This->doc_obj->doc_object_service) {
287 IDocObjectService_Release(This->doc_obj->doc_object_service);
288 This->doc_obj->doc_object_service = NULL;
291 if(This->doc_obj->webbrowser) {
292 IUnknown_Release(This->doc_obj->webbrowser);
293 This->doc_obj->webbrowser = NULL;
296 if(This->doc_obj->browser_service) {
297 IUnknown_Release(This->doc_obj->browser_service);
298 This->doc_obj->browser_service = NULL;
301 if(This->doc_obj->travel_log) {
302 ITravelLog_Release(This->doc_obj->travel_log);
303 This->doc_obj->travel_log = NULL;
306 memset(&This->doc_obj->hostinfo, 0, sizeof(DOCHOSTUIINFO));
308 if(!pClientSite)
309 return S_OK;
311 IOleClientSite_AddRef(pClientSite);
312 This->doc_obj->client = pClientSite;
314 hostui_setup = This->doc_obj->hostui_setup;
316 if(!This->doc_obj->hostui) {
317 IDocHostUIHandler *uihandler;
319 This->doc_obj->custom_hostui = FALSE;
321 hres = IOleClientSite_QueryInterface(pClientSite, &IID_IDocHostUIHandler, (void**)&uihandler);
322 if(SUCCEEDED(hres))
323 This->doc_obj->hostui = uihandler;
326 if(This->doc_obj->hostui) {
327 DOCHOSTUIINFO hostinfo;
328 LPOLESTR key_path = NULL, override_key_path = NULL;
329 IDocHostUIHandler2 *uihandler2;
331 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
332 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
333 hres = IDocHostUIHandler_GetHostInfo(This->doc_obj->hostui, &hostinfo);
334 if(SUCCEEDED(hres)) {
335 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
336 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
337 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
338 update_hostinfo(This->doc_obj, &hostinfo);
339 This->doc_obj->hostinfo = hostinfo;
342 if(!hostui_setup) {
343 hres = IDocHostUIHandler_GetOptionKeyPath(This->doc_obj->hostui, &key_path, 0);
344 if(hres == S_OK && key_path) {
345 if(key_path[0]) {
346 /* FIXME: use key_path */
347 FIXME("key_path = %s\n", debugstr_w(key_path));
349 CoTaskMemFree(key_path);
352 hres = IDocHostUIHandler_QueryInterface(This->doc_obj->hostui, &IID_IDocHostUIHandler2,
353 (void**)&uihandler2);
354 if(SUCCEEDED(hres)) {
355 hres = IDocHostUIHandler2_GetOverrideKeyPath(uihandler2, &override_key_path, 0);
356 if(hres == S_OK && override_key_path) {
357 if(override_key_path[0]) {
358 /*FIXME: use override_key_path */
359 FIXME("override_key_path = %s\n", debugstr_w(override_key_path));
361 CoTaskMemFree(override_key_path);
363 IDocHostUIHandler2_Release(uihandler2);
366 This->doc_obj->hostui_setup = TRUE;
370 load_settings(This->doc_obj);
372 /* Native calls here GetWindow. What is it for?
373 * We don't have anything to do with it here (yet). */
374 hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleWindow, (void**)&ole_window);
375 if(SUCCEEDED(hres)) {
376 IOleWindow_GetWindow(ole_window, &hwnd);
377 IOleWindow_Release(ole_window);
380 hres = do_query_service((IUnknown*)pClientSite, &IID_IShellBrowser,
381 &IID_IBrowserService, (void**)&browser_service);
382 if(SUCCEEDED(hres)) {
383 ITravelLog *travel_log;
385 This->doc_obj->browser_service = (IUnknown*)browser_service;
387 hres = IBrowserService_GetTravelLog(browser_service, &travel_log);
388 if(SUCCEEDED(hres))
389 This->doc_obj->travel_log = travel_log;
390 }else {
391 browser_service = NULL;
394 hres = IOleClientSite_QueryInterface(pClientSite, &IID_IOleCommandTarget, (void**)&cmdtrg);
395 if(SUCCEEDED(hres)) {
396 VARIANT var;
397 OLECMD cmd = {OLECMDID_SETPROGRESSTEXT, 0};
399 This->doc_obj->client_cmdtrg = cmdtrg;
401 if(!hostui_setup) {
402 IDocObjectService *doc_object_service;
403 IWebBrowser2 *wb;
405 set_document_navigation(This->doc_obj, TRUE);
407 if(browser_service) {
408 hres = IBrowserService_QueryInterface(browser_service,
409 &IID_IDocObjectService, (void**)&doc_object_service);
410 if(SUCCEEDED(hres)) {
411 This->doc_obj->doc_object_service = doc_object_service;
414 * Some embedding routines, esp. in regards to use of IDocObjectService, differ if
415 * embedder supports IWebBrowserApp.
417 hres = do_query_service((IUnknown*)pClientSite, &IID_IWebBrowserApp, &IID_IWebBrowser2, (void**)&wb);
418 if(SUCCEEDED(hres))
419 This->doc_obj->webbrowser = (IUnknown*)wb;
424 call_docview_84(This->doc_obj);
426 IOleCommandTarget_QueryStatus(cmdtrg, NULL, 1, &cmd, NULL);
428 V_VT(&var) = VT_I4;
429 V_I4(&var) = 0;
430 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSMAX,
431 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
432 IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_SETPROGRESSPOS,
433 OLECMDEXECOPT_DONTPROMPTUSER, &var, NULL);
436 if(This->doc_obj->usermode == UNKNOWN_USERMODE)
437 IOleControl_OnAmbientPropertyChange(&This->IOleControl_iface, DISPID_AMBIENT_USERMODE);
439 IOleControl_OnAmbientPropertyChange(&This->IOleControl_iface,
440 DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
442 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_SILENT, &silent);
443 if(SUCCEEDED(hres)) {
444 if(V_VT(&silent) != VT_BOOL)
445 WARN("silent = %s\n", debugstr_variant(&silent));
446 else if(V_BOOL(&silent))
447 FIXME("silent == true\n");
450 IOleControl_OnAmbientPropertyChange(&This->IOleControl_iface, DISPID_AMBIENT_USERAGENT);
451 IOleControl_OnAmbientPropertyChange(&This->IOleControl_iface, DISPID_AMBIENT_PALETTE);
453 return S_OK;
456 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, IOleClientSite **ppClientSite)
458 HTMLDocument *This = impl_from_IOleObject(iface);
460 TRACE("(%p)->(%p)\n", This, ppClientSite);
462 if(!ppClientSite)
463 return E_INVALIDARG;
465 if(This->doc_obj->client)
466 IOleClientSite_AddRef(This->doc_obj->client);
467 *ppClientSite = This->doc_obj->client;
469 return S_OK;
472 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
474 HTMLDocument *This = impl_from_IOleObject(iface);
475 FIXME("(%p)->(%s %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
476 return E_NOTIMPL;
479 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
481 HTMLDocument *This = impl_from_IOleObject(iface);
483 TRACE("(%p)->(%08x)\n", This, dwSaveOption);
485 if(dwSaveOption == OLECLOSE_PROMPTSAVE)
486 FIXME("OLECLOSE_PROMPTSAVE not implemented\n");
488 if(This->doc_obj->in_place_active)
489 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->IOleInPlaceObjectWindowless_iface);
491 HTMLDocument_LockContainer(This->doc_obj, FALSE);
493 if(This->advise_holder)
494 IOleAdviseHolder_SendOnClose(This->advise_holder);
496 return S_OK;
499 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker *pmk)
501 HTMLDocument *This = impl_from_IOleObject(iface);
502 FIXME("(%p %d %p)->()\n", This, dwWhichMoniker, pmk);
503 return E_NOTIMPL;
506 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
508 HTMLDocument *This = impl_from_IOleObject(iface);
509 FIXME("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
510 return E_NOTIMPL;
513 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, IDataObject *pDataObject, BOOL fCreation,
514 DWORD dwReserved)
516 HTMLDocument *This = impl_from_IOleObject(iface);
517 FIXME("(%p)->(%p %x %d)\n", This, pDataObject, fCreation, dwReserved);
518 return E_NOTIMPL;
521 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved, IDataObject **ppDataObject)
523 HTMLDocument *This = impl_from_IOleObject(iface);
524 FIXME("(%p)->(%d %p)\n", This, dwReserved, ppDataObject);
525 return E_NOTIMPL;
528 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite,
529 LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
531 HTMLDocument *This = impl_from_IOleObject(iface);
532 IOleDocumentSite *pDocSite;
533 HRESULT hres;
535 TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
537 if(iVerb != OLEIVERB_SHOW && iVerb != OLEIVERB_UIACTIVATE && iVerb != OLEIVERB_INPLACEACTIVATE) {
538 FIXME("iVerb = %d not supported\n", iVerb);
539 return E_NOTIMPL;
542 if(!pActiveSite)
543 pActiveSite = This->doc_obj->client;
545 hres = IOleClientSite_QueryInterface(pActiveSite, &IID_IOleDocumentSite, (void**)&pDocSite);
546 if(SUCCEEDED(hres)) {
547 HTMLDocument_LockContainer(This->doc_obj, TRUE);
549 /* FIXME: Create new IOleDocumentView. See CreateView for more info. */
550 hres = IOleDocumentSite_ActivateMe(pDocSite, &This->IOleDocumentView_iface);
551 IOleDocumentSite_Release(pDocSite);
552 }else {
553 hres = IOleDocumentView_UIActivate(&This->IOleDocumentView_iface, TRUE);
554 if(SUCCEEDED(hres)) {
555 if(lprcPosRect) {
556 RECT rect; /* We need to pass rect as not const pointer */
557 rect = *lprcPosRect;
558 IOleDocumentView_SetRect(&This->IOleDocumentView_iface, &rect);
560 IOleDocumentView_Show(&This->IOleDocumentView_iface, TRUE);
564 return hres;
567 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
569 HTMLDocument *This = impl_from_IOleObject(iface);
570 FIXME("(%p)->(%p)\n", This, ppEnumOleVerb);
571 return E_NOTIMPL;
574 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
576 HTMLDocument *This = impl_from_IOleObject(iface);
577 FIXME("(%p)\n", This);
578 return E_NOTIMPL;
581 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
583 HTMLDocument *This = impl_from_IOleObject(iface);
584 FIXME("(%p)\n", This);
585 return E_NOTIMPL;
588 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
590 HTMLDocument *This = impl_from_IOleObject(iface);
592 TRACE("(%p)->(%p)\n", This, pClsid);
594 if(!pClsid)
595 return E_INVALIDARG;
597 *pClsid = CLSID_HTMLDocument;
598 return S_OK;
601 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType, LPOLESTR *pszUserType)
603 HTMLDocument *This = impl_from_IOleObject(iface);
604 FIXME("(%p)->(%d %p)\n", This, dwFormOfType, pszUserType);
605 return E_NOTIMPL;
608 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
610 HTMLDocument *This = impl_from_IOleObject(iface);
611 FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
612 return E_NOTIMPL;
615 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
617 HTMLDocument *This = impl_from_IOleObject(iface);
618 FIXME("(%p)->(%d %p)\n", This, dwDrawAspect, psizel);
619 return E_NOTIMPL;
622 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink, DWORD *pdwConnection)
624 HTMLDocument *This = impl_from_IOleObject(iface);
625 TRACE("(%p)->(%p %p)\n", This, pAdvSink, pdwConnection);
627 if(!pdwConnection)
628 return E_INVALIDARG;
630 if(!pAdvSink) {
631 *pdwConnection = 0;
632 return E_INVALIDARG;
635 if(!This->advise_holder) {
636 CreateOleAdviseHolder(&This->advise_holder);
637 if(!This->advise_holder)
638 return E_OUTOFMEMORY;
641 return IOleAdviseHolder_Advise(This->advise_holder, pAdvSink, pdwConnection);
644 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
646 HTMLDocument *This = impl_from_IOleObject(iface);
647 TRACE("(%p)->(%d)\n", This, dwConnection);
649 if(!This->advise_holder)
650 return OLE_E_NOCONNECTION;
652 return IOleAdviseHolder_Unadvise(This->advise_holder, dwConnection);
655 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
657 HTMLDocument *This = impl_from_IOleObject(iface);
659 if(!This->advise_holder) {
660 *ppenumAdvise = NULL;
661 return S_OK;
664 return IOleAdviseHolder_EnumAdvise(This->advise_holder, ppenumAdvise);
667 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
669 HTMLDocument *This = impl_from_IOleObject(iface);
670 FIXME("(%p)->(%d %p)\n", This, dwAspect, pdwStatus);
671 return E_NOTIMPL;
674 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *pLogpal)
676 HTMLDocument *This = impl_from_IOleObject(iface);
677 FIXME("(%p)->(%p)\n", This, pLogpal);
678 return E_NOTIMPL;
681 static const IOleObjectVtbl OleObjectVtbl = {
682 OleObject_QueryInterface,
683 OleObject_AddRef,
684 OleObject_Release,
685 OleObject_SetClientSite,
686 OleObject_GetClientSite,
687 OleObject_SetHostNames,
688 OleObject_Close,
689 OleObject_SetMoniker,
690 OleObject_GetMoniker,
691 OleObject_InitFromData,
692 OleObject_GetClipboardData,
693 OleObject_DoVerb,
694 OleObject_EnumVerbs,
695 OleObject_Update,
696 OleObject_IsUpToDate,
697 OleObject_GetUserClassID,
698 OleObject_GetUserType,
699 OleObject_SetExtent,
700 OleObject_GetExtent,
701 OleObject_Advise,
702 OleObject_Unadvise,
703 OleObject_EnumAdvise,
704 OleObject_GetMiscStatus,
705 OleObject_SetColorScheme
708 /**********************************************************
709 * IOleDocument implementation
712 static inline HTMLDocument *impl_from_IOleDocument(IOleDocument *iface)
714 return CONTAINING_RECORD(iface, HTMLDocument, IOleDocument_iface);
717 static HRESULT WINAPI OleDocument_QueryInterface(IOleDocument *iface, REFIID riid, void **ppv)
719 HTMLDocument *This = impl_from_IOleDocument(iface);
720 return htmldoc_query_interface(This, riid, ppv);
723 static ULONG WINAPI OleDocument_AddRef(IOleDocument *iface)
725 HTMLDocument *This = impl_from_IOleDocument(iface);
726 return htmldoc_addref(This);
729 static ULONG WINAPI OleDocument_Release(IOleDocument *iface)
731 HTMLDocument *This = impl_from_IOleDocument(iface);
732 return htmldoc_release(This);
735 static HRESULT WINAPI OleDocument_CreateView(IOleDocument *iface, IOleInPlaceSite *pIPSite, IStream *pstm,
736 DWORD dwReserved, IOleDocumentView **ppView)
738 HTMLDocument *This = impl_from_IOleDocument(iface);
739 HRESULT hres;
741 TRACE("(%p)->(%p %p %d %p)\n", This, pIPSite, pstm, dwReserved, ppView);
743 if(!ppView)
744 return E_INVALIDARG;
746 /* FIXME:
747 * Windows implementation creates new IOleDocumentView when function is called for the
748 * first time and returns E_FAIL when it is called for the second time, but it doesn't matter
749 * if the application uses returned interfaces, passed to ActivateMe or returned by
750 * QueryInterface, so there is no reason to create new interface. This needs more testing.
753 if(pIPSite) {
754 hres = IOleDocumentView_SetInPlaceSite(&This->IOleDocumentView_iface, pIPSite);
755 if(FAILED(hres))
756 return hres;
759 if(pstm)
760 FIXME("pstm is not supported\n");
762 IOleDocumentView_AddRef(&This->IOleDocumentView_iface);
763 *ppView = &This->IOleDocumentView_iface;
764 return S_OK;
767 static HRESULT WINAPI OleDocument_GetDocMiscStatus(IOleDocument *iface, DWORD *pdwStatus)
769 HTMLDocument *This = impl_from_IOleDocument(iface);
770 FIXME("(%p)->(%p)\n", This, pdwStatus);
771 return E_NOTIMPL;
774 static HRESULT WINAPI OleDocument_EnumViews(IOleDocument *iface, IEnumOleDocumentViews **ppEnum,
775 IOleDocumentView **ppView)
777 HTMLDocument *This = impl_from_IOleDocument(iface);
778 FIXME("(%p)->(%p %p)\n", This, ppEnum, ppView);
779 return E_NOTIMPL;
782 static const IOleDocumentVtbl OleDocumentVtbl = {
783 OleDocument_QueryInterface,
784 OleDocument_AddRef,
785 OleDocument_Release,
786 OleDocument_CreateView,
787 OleDocument_GetDocMiscStatus,
788 OleDocument_EnumViews
791 /**********************************************************
792 * IOleControl implementation
795 static inline HTMLDocument *impl_from_IOleControl(IOleControl *iface)
797 return CONTAINING_RECORD(iface, HTMLDocument, IOleControl_iface);
800 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface, REFIID riid, void **ppv)
802 HTMLDocument *This = impl_from_IOleControl(iface);
803 return htmldoc_query_interface(This, riid, ppv);
806 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
808 HTMLDocument *This = impl_from_IOleControl(iface);
809 return htmldoc_addref(This);
812 static ULONG WINAPI OleControl_Release(IOleControl *iface)
814 HTMLDocument *This = impl_from_IOleControl(iface);
815 return htmldoc_release(This);
818 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, CONTROLINFO *pCI)
820 HTMLDocument *This = impl_from_IOleControl(iface);
821 FIXME("(%p)->(%p)\n", This, pCI);
822 return E_NOTIMPL;
825 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, MSG *pMsg)
827 HTMLDocument *This = impl_from_IOleControl(iface);
828 FIXME("(%p)->(%p)\n", This, pMsg);
829 return E_NOTIMPL;
832 HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
834 IDispatch *disp = NULL;
835 DISPPARAMS dispparams = {NULL, 0};
836 UINT err;
837 HRESULT hres;
839 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
840 if(FAILED(hres)) {
841 TRACE("Could not get IDispatch\n");
842 return hres;
845 VariantInit(res);
847 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
848 DISPATCH_PROPERTYGET, &dispparams, res, NULL, &err);
850 IDispatch_Release(disp);
852 return hres;
855 static HRESULT on_change_dlcontrol(HTMLDocument *This)
857 VARIANT res;
858 HRESULT hres;
860 hres = get_client_disp_property(This->doc_obj->client, DISPID_AMBIENT_DLCONTROL, &res);
861 if(SUCCEEDED(hres))
862 FIXME("unsupported dlcontrol %08x\n", V_I4(&res));
864 return S_OK;
867 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
869 HTMLDocument *This = impl_from_IOleControl(iface);
870 IOleClientSite *client;
871 VARIANT res;
872 HRESULT hres;
874 client = This->doc_obj->client;
875 if(!client) {
876 TRACE("client = NULL\n");
877 return S_OK;
880 switch(dispID) {
881 case DISPID_AMBIENT_USERMODE:
882 TRACE("(%p)->(DISPID_AMBIENT_USERMODE)\n", This);
883 hres = get_client_disp_property(client, DISPID_AMBIENT_USERMODE, &res);
884 if(FAILED(hres))
885 return S_OK;
887 if(V_VT(&res) == VT_BOOL) {
888 if(V_BOOL(&res)) {
889 This->doc_obj->usermode = BROWSEMODE;
890 }else {
891 FIXME("edit mode is not supported\n");
892 This->doc_obj->usermode = EDITMODE;
894 }else {
895 FIXME("usermode=%s\n", debugstr_variant(&res));
897 return S_OK;
898 case DISPID_AMBIENT_DLCONTROL:
899 TRACE("(%p)->(DISPID_AMBIENT_DLCONTROL)\n", This);
900 return on_change_dlcontrol(This);
901 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
902 TRACE("(%p)->(DISPID_AMBIENT_OFFLINEIFNOTCONNECTED)\n", This);
903 on_change_dlcontrol(This);
904 hres = get_client_disp_property(client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &res);
905 if(FAILED(hres))
906 return S_OK;
908 if(V_VT(&res) == VT_BOOL) {
909 if(V_BOOL(&res)) {
910 FIXME("offline connection is not supported\n");
911 hres = E_FAIL;
913 }else {
914 FIXME("offlineconnected=%s\n", debugstr_variant(&res));
916 return S_OK;
917 case DISPID_AMBIENT_SILENT:
918 TRACE("(%p)->(DISPID_AMBIENT_SILENT)\n", This);
919 on_change_dlcontrol(This);
920 hres = get_client_disp_property(client, DISPID_AMBIENT_SILENT, &res);
921 if(FAILED(hres))
922 return S_OK;
924 if(V_VT(&res) == VT_BOOL) {
925 if(V_BOOL(&res)) {
926 FIXME("silent mode is not supported\n");
927 hres = E_FAIL;
929 }else {
930 FIXME("silent=%s\n", debugstr_variant(&res));
932 return S_OK;
933 case DISPID_AMBIENT_USERAGENT:
934 TRACE("(%p)->(DISPID_AMBIENT_USERAGENT)\n", This);
935 hres = get_client_disp_property(client, DISPID_AMBIENT_USERAGENT, &res);
936 if(FAILED(hres))
937 return S_OK;
939 FIXME("not supported AMBIENT_USERAGENT\n");
940 hres = E_FAIL;
941 return S_OK;
942 case DISPID_AMBIENT_PALETTE:
943 TRACE("(%p)->(DISPID_AMBIENT_PALETTE)\n", This);
944 hres = get_client_disp_property(client, DISPID_AMBIENT_PALETTE, &res);
945 if(FAILED(hres))
946 return S_OK;
948 FIXME("not supported AMBIENT_PALETTE\n");
949 hres = E_FAIL;
950 return S_OK;
953 FIXME("(%p) unsupported dispID=%d\n", This, dispID);
954 return E_FAIL;
957 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
959 HTMLDocument *This = impl_from_IOleControl(iface);
960 FIXME("(%p)->(%x)\n", This, bFreeze);
961 return E_NOTIMPL;
964 static const IOleControlVtbl OleControlVtbl = {
965 OleControl_QueryInterface,
966 OleControl_AddRef,
967 OleControl_Release,
968 OleControl_GetControlInfo,
969 OleControl_OnMnemonic,
970 OleControl_OnAmbientPropertyChange,
971 OleControl_FreezeEvents
974 /**********************************************************
975 * IObjectWithSite implementation
978 static inline HTMLDocument *impl_from_IObjectWithSite(IObjectWithSite *iface)
980 return CONTAINING_RECORD(iface, HTMLDocument, IObjectWithSite_iface);
983 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppv)
985 HTMLDocument *This = impl_from_IObjectWithSite(iface);
986 return htmldoc_query_interface(This, riid, ppv);
989 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
991 HTMLDocument *This = impl_from_IObjectWithSite(iface);
992 return htmldoc_addref(This);
995 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
997 HTMLDocument *This = impl_from_IObjectWithSite(iface);
998 return htmldoc_release(This);
1001 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
1003 HTMLDocument *This = impl_from_IObjectWithSite(iface);
1004 FIXME("(%p)->(%p)\n", This, pUnkSite);
1005 return E_NOTIMPL;
1008 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite* iface, REFIID riid, PVOID *ppvSite)
1010 HTMLDocument *This = impl_from_IObjectWithSite(iface);
1011 FIXME("(%p)->(%p)\n", This, ppvSite);
1012 return E_NOTIMPL;
1015 static const IObjectWithSiteVtbl ObjectWithSiteVtbl = {
1016 ObjectWithSite_QueryInterface,
1017 ObjectWithSite_AddRef,
1018 ObjectWithSite_Release,
1019 ObjectWithSite_SetSite,
1020 ObjectWithSite_GetSite
1023 /**********************************************************
1024 * IOleContainer implementation
1027 static inline HTMLDocument *impl_from_IOleContainer(IOleContainer *iface)
1029 return CONTAINING_RECORD(iface, HTMLDocument, IOleContainer_iface);
1032 static HRESULT WINAPI OleContainer_QueryInterface(IOleContainer *iface, REFIID riid, void **ppv)
1034 HTMLDocument *This = impl_from_IOleContainer(iface);
1035 return htmldoc_query_interface(This, riid, ppv);
1038 static ULONG WINAPI OleContainer_AddRef(IOleContainer *iface)
1040 HTMLDocument *This = impl_from_IOleContainer(iface);
1041 return htmldoc_addref(This);
1044 static ULONG WINAPI OleContainer_Release(IOleContainer *iface)
1046 HTMLDocument *This = impl_from_IOleContainer(iface);
1047 return htmldoc_release(This);
1050 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer *iface, IBindCtx *pbc, LPOLESTR pszDisplayName,
1051 ULONG *pchEaten, IMoniker **ppmkOut)
1053 HTMLDocument *This = impl_from_IOleContainer(iface);
1054 FIXME("(%p)->(%p %s %p %p)\n", This, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
1055 return E_NOTIMPL;
1058 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer *iface, DWORD grfFlags, IEnumUnknown **ppenum)
1060 HTMLDocument *This = impl_from_IOleContainer(iface);
1061 EnumUnknown *ret;
1063 TRACE("(%p)->(%x %p)\n", This, grfFlags, ppenum);
1065 ret = heap_alloc(sizeof(*ret));
1066 if(!ret)
1067 return E_OUTOFMEMORY;
1069 ret->IEnumUnknown_iface.lpVtbl = &EnumUnknownVtbl;
1070 ret->ref = 1;
1072 *ppenum = &ret->IEnumUnknown_iface;
1073 return S_OK;
1076 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer *iface, BOOL fLock)
1078 HTMLDocument *This = impl_from_IOleContainer(iface);
1079 FIXME("(%p)->(%x)\n", This, fLock);
1080 return E_NOTIMPL;
1083 static const IOleContainerVtbl OleContainerVtbl = {
1084 OleContainer_QueryInterface,
1085 OleContainer_AddRef,
1086 OleContainer_Release,
1087 OleContainer_ParseDisplayName,
1088 OleContainer_EnumObjects,
1089 OleContainer_LockContainer
1092 static inline HTMLDocumentObj *impl_from_ITargetContainer(ITargetContainer *iface)
1094 return CONTAINING_RECORD(iface, HTMLDocumentObj, ITargetContainer_iface);
1097 static HRESULT WINAPI TargetContainer_QueryInterface(ITargetContainer *iface, REFIID riid, void **ppv)
1099 HTMLDocumentObj *This = impl_from_ITargetContainer(iface);
1100 return ICustomDoc_QueryInterface(&This->ICustomDoc_iface, riid, ppv);
1103 static ULONG WINAPI TargetContainer_AddRef(ITargetContainer *iface)
1105 HTMLDocumentObj *This = impl_from_ITargetContainer(iface);
1106 return ICustomDoc_AddRef(&This->ICustomDoc_iface);
1109 static ULONG WINAPI TargetContainer_Release(ITargetContainer *iface)
1111 HTMLDocumentObj *This = impl_from_ITargetContainer(iface);
1112 return ICustomDoc_Release(&This->ICustomDoc_iface);
1115 static HRESULT WINAPI TargetContainer_GetFrameUrl(ITargetContainer *iface, LPWSTR *ppszFrameSrc)
1117 HTMLDocumentObj *This = impl_from_ITargetContainer(iface);
1118 FIXME("(%p)->(%p)\n", This, ppszFrameSrc);
1119 return E_NOTIMPL;
1122 static HRESULT WINAPI TargetContainer_GetFramesContainer(ITargetContainer *iface, IOleContainer **ppContainer)
1124 HTMLDocumentObj *This = impl_from_ITargetContainer(iface);
1126 TRACE("(%p)->(%p)\n", This, ppContainer);
1128 /* NOTE: we should return wrapped interface here */
1129 IOleContainer_AddRef(&This->basedoc.IOleContainer_iface);
1130 *ppContainer = &This->basedoc.IOleContainer_iface;
1131 return S_OK;
1134 static const ITargetContainerVtbl TargetContainerVtbl = {
1135 TargetContainer_QueryInterface,
1136 TargetContainer_AddRef,
1137 TargetContainer_Release,
1138 TargetContainer_GetFrameUrl,
1139 TargetContainer_GetFramesContainer
1142 void TargetContainer_Init(HTMLDocumentObj *This)
1144 This->ITargetContainer_iface.lpVtbl = &TargetContainerVtbl;
1147 /**********************************************************
1148 * IObjectSafety implementation
1151 static inline HTMLDocument *impl_from_IObjectSafety(IObjectSafety *iface)
1153 return CONTAINING_RECORD(iface, HTMLDocument, IObjectSafety_iface);
1156 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1158 HTMLDocument *This = impl_from_IObjectSafety(iface);
1159 return htmldoc_query_interface(This, riid, ppv);
1162 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
1164 HTMLDocument *This = impl_from_IObjectSafety(iface);
1165 return htmldoc_addref(This);
1168 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
1170 HTMLDocument *This = impl_from_IObjectSafety(iface);
1171 return htmldoc_release(This);
1174 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface,
1175 REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1177 HTMLDocument *This = impl_from_IObjectSafety(iface);
1178 FIXME("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
1179 return E_NOTIMPL;
1182 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface,
1183 REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1185 HTMLDocument *This = impl_from_IObjectSafety(iface);
1186 FIXME("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
1188 if(IsEqualGUID(&IID_IPersistMoniker, riid) &&
1189 dwOptionSetMask==INTERFACESAFE_FOR_UNTRUSTED_DATA &&
1190 dwEnabledOptions==INTERFACESAFE_FOR_UNTRUSTED_DATA)
1191 return S_OK;
1193 return E_NOTIMPL;
1196 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
1197 ObjectSafety_QueryInterface,
1198 ObjectSafety_AddRef,
1199 ObjectSafety_Release,
1200 ObjectSafety_GetInterfaceSafetyOptions,
1201 ObjectSafety_SetInterfaceSafetyOptions
1204 void HTMLDocument_LockContainer(HTMLDocumentObj *This, BOOL fLock)
1206 IOleContainer *container;
1207 HRESULT hres;
1209 if(!This->client || This->container_locked == fLock)
1210 return;
1212 hres = IOleClientSite_GetContainer(This->client, &container);
1213 if(SUCCEEDED(hres)) {
1214 IOleContainer_LockContainer(container, fLock);
1215 This->container_locked = fLock;
1216 IOleContainer_Release(container);
1220 void HTMLDocument_OleObj_Init(HTMLDocument *This)
1222 This->IOleObject_iface.lpVtbl = &OleObjectVtbl;
1223 This->IOleDocument_iface.lpVtbl = &OleDocumentVtbl;
1224 This->IOleControl_iface.lpVtbl = &OleControlVtbl;
1225 This->IObjectWithSite_iface.lpVtbl = &ObjectWithSiteVtbl;
1226 This->IOleContainer_iface.lpVtbl = &OleContainerVtbl;
1227 This->IObjectSafety_iface.lpVtbl = &ObjectSafetyVtbl;