2 * OLE 2 default object handler
4 * Copyright 1999 Francis Beaudet
5 * Copyright 2000 Abey George
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * The OLE2 default object handler supports a whole whack of
23 * interfaces including:
24 * IOleObject, IDataObject, IPersistStorage, IViewObject2,
25 * IRunnableObject, IOleCache2, IOleCacheControl and much more.
27 * All the implementation details are taken from: Inside OLE
28 * second edition by Kraig Brockschmidt,
31 * - This implementation of the default handler does not launch the
32 * server in the DoVerb, Update, GetData, GetDataHere and Run
33 * methods. When it is fixed to do so, all the methods will have
34 * to be revisited to allow delegating to the running object
36 * - All methods in the class that use the class ID should be
37 * aware that it is possible for a class to be treated as
38 * another one and go into emulation mode. Nothing has been
41 * - Some functions still return E_NOTIMPL they have to be
42 * implemented. Most of those are related to the running of the
45 * - All the methods related to notification and advise sinks are
46 * in place but no notifications are sent to the sinks yet.
60 #include "compobj_private.h"
62 #include "wine/unicode.h"
63 #include "wine/debug.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(ole);
67 /****************************************************************************
73 const IOleObjectVtbl* lpVtbl;
74 const IUnknownVtbl* lpvtblIUnknown;
75 const IDataObjectVtbl* lpvtblIDataObject;
76 const IRunnableObjectVtbl* lpvtblIRunnableObject;
77 const IAdviseSinkVtbl *lpvtblIAdviseSink;
79 /* Reference count of this object */
82 /* IUnknown implementation of the outer object. */
83 IUnknown* outerUnknown;
85 /* Class Id that this handler object represents. */
88 /* IUnknown implementation of the datacache. */
91 /* Client site for the embedded object. */
92 IOleClientSite* clientSite;
95 * The IOleAdviseHolder maintains the connections
96 * on behalf of the default handler.
98 IOleAdviseHolder* oleAdviseHolder;
101 * The IDataAdviseHolder maintains the data
102 * connections on behalf of the default handler.
104 IDataAdviseHolder* dataAdviseHolder;
106 /* Name of the container and object contained */
110 /* IOleObject delegate */
111 IOleObject *pOleDelegate;
112 /* IPersistStorage delegate */
113 IPersistStorage *pPSDelegate;
114 /* IDataObject delegate */
115 IDataObject *pDataDelegate;
117 /* connection cookie for the advise on the delegate OLE object */
121 typedef struct DefaultHandler DefaultHandler;
124 * Here, I define utility functions to help with the casting of the
126 * There is a version to accommodate all of the VTables implemented
129 static inline DefaultHandler *impl_from_IOleObject( IOleObject *iface )
131 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpVtbl));
134 static inline DefaultHandler *impl_from_NDIUnknown( IUnknown *iface )
136 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIUnknown));
139 static inline DefaultHandler *impl_from_IDataObject( IDataObject *iface )
141 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIDataObject));
144 static inline DefaultHandler *impl_from_IRunnableObject( IRunnableObject *iface )
146 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIRunnableObject));
149 static inline DefaultHandler *impl_from_IAdviseSink( IAdviseSink *iface )
151 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIAdviseSink));
154 static void DefaultHandler_Destroy(DefaultHandler* This);
157 /*********************************************************
158 * Method implementation for the non delegating IUnknown
159 * part of the DefaultHandler class.
162 /************************************************************************
163 * DefaultHandler_NDIUnknown_QueryInterface (IUnknown)
165 * See Windows documentation for more details on IUnknown methods.
167 * This version of QueryInterface will not delegate it's implementation
168 * to the outer unknown.
170 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
175 DefaultHandler *This = impl_from_NDIUnknown(iface);
177 /* Perform a sanity check on the parameters. */
183 if (IsEqualIID(&IID_IUnknown, riid))
185 else if (IsEqualIID(&IID_IOleObject, riid))
186 *ppvObject = (IOleObject*)&This->lpVtbl;
187 else if (IsEqualIID(&IID_IDataObject, riid))
188 *ppvObject = (IDataObject*)&This->lpvtblIDataObject;
189 else if (IsEqualIID(&IID_IRunnableObject, riid))
190 *ppvObject = (IRunnableObject*)&This->lpvtblIRunnableObject;
191 else if (IsEqualIID(&IID_IPersist, riid) ||
192 IsEqualIID(&IID_IPersistStorage, riid) ||
193 IsEqualIID(&IID_IViewObject, riid) ||
194 IsEqualIID(&IID_IViewObject2, riid) ||
195 IsEqualIID(&IID_IOleCache, riid) ||
196 IsEqualIID(&IID_IOleCache2, riid))
198 HRESULT hr = IUnknown_QueryInterface(This->dataCache, riid, ppvObject);
199 if (FAILED(hr)) FIXME("interface %s not implemented by data cache\n", debugstr_guid(riid));
203 /* Check that we obtained an interface. */
204 if (*ppvObject == NULL)
206 WARN( "() : asking for un supported interface %s\n", debugstr_guid(riid));
207 return E_NOINTERFACE;
211 * Query Interface always increases the reference count by one when it is
214 IUnknown_AddRef((IUnknown*)*ppvObject);
219 /************************************************************************
220 * DefaultHandler_NDIUnknown_AddRef (IUnknown)
222 * See Windows documentation for more details on IUnknown methods.
224 * This version of QueryInterface will not delegate it's implementation
225 * to the outer unknown.
227 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef(
230 DefaultHandler *This = impl_from_NDIUnknown(iface);
231 return InterlockedIncrement(&This->ref);
234 /************************************************************************
235 * DefaultHandler_NDIUnknown_Release (IUnknown)
237 * See Windows documentation for more details on IUnknown methods.
239 * This version of QueryInterface will not delegate it's implementation
240 * to the outer unknown.
242 static ULONG WINAPI DefaultHandler_NDIUnknown_Release(
245 DefaultHandler *This = impl_from_NDIUnknown(iface);
248 /* Decrease the reference count on this object. */
249 ref = InterlockedDecrement(&This->ref);
251 if (!ref) DefaultHandler_Destroy(This);
256 /*********************************************************
257 * Methods implementation for the IOleObject part of
258 * the DefaultHandler class.
261 /************************************************************************
262 * DefaultHandler_QueryInterface (IUnknown)
264 * See Windows documentation for more details on IUnknown methods.
266 static HRESULT WINAPI DefaultHandler_QueryInterface(
271 DefaultHandler *This = impl_from_IOleObject(iface);
273 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
276 /************************************************************************
277 * DefaultHandler_AddRef (IUnknown)
279 * See Windows documentation for more details on IUnknown methods.
281 static ULONG WINAPI DefaultHandler_AddRef(
284 DefaultHandler *This = impl_from_IOleObject(iface);
286 return IUnknown_AddRef(This->outerUnknown);
289 /************************************************************************
290 * DefaultHandler_Release (IUnknown)
292 * See Windows documentation for more details on IUnknown methods.
294 static ULONG WINAPI DefaultHandler_Release(
297 DefaultHandler *This = impl_from_IOleObject(iface);
299 return IUnknown_Release(This->outerUnknown);
302 /************************************************************************
303 * DefaultHandler_SetClientSite (IOleObject)
305 * The default handler's implementation of this method only keeps the
306 * client site pointer for future reference.
308 * See Windows documentation for more details on IOleObject methods.
310 static HRESULT WINAPI DefaultHandler_SetClientSite(
312 IOleClientSite* pClientSite)
314 DefaultHandler *This = impl_from_IOleObject(iface);
317 TRACE("(%p, %p)\n", iface, pClientSite);
319 if (This->pOleDelegate)
320 hr = IOleObject_SetClientSite(This->pOleDelegate, pClientSite);
323 * Make sure we release the previous client site if there
326 if (This->clientSite)
327 IOleClientSite_Release(This->clientSite);
329 This->clientSite = pClientSite;
331 if (This->clientSite)
332 IOleClientSite_AddRef(This->clientSite);
337 /************************************************************************
338 * DefaultHandler_GetClientSite (IOleObject)
340 * The default handler's implementation of this method returns the
341 * last pointer set in IOleObject_SetClientSite.
343 * See Windows documentation for more details on IOleObject methods.
345 static HRESULT WINAPI DefaultHandler_GetClientSite(
347 IOleClientSite** ppClientSite)
349 DefaultHandler *This = impl_from_IOleObject(iface);
355 *ppClientSite = This->clientSite;
357 if (This->clientSite)
358 IOleClientSite_AddRef(This->clientSite);
363 /************************************************************************
364 * DefaultHandler_SetHostNames (IOleObject)
366 * The default handler's implementation of this method just stores
367 * the strings and returns S_OK.
369 * See Windows documentation for more details on IOleObject methods.
371 static HRESULT WINAPI DefaultHandler_SetHostNames(
373 LPCOLESTR szContainerApp,
374 LPCOLESTR szContainerObj)
376 DefaultHandler *This = impl_from_IOleObject(iface);
378 TRACE("(%p, %s, %s)\n",
380 debugstr_w(szContainerApp),
381 debugstr_w(szContainerObj));
383 if (This->pOleDelegate)
384 IOleObject_SetHostNames(This->pOleDelegate, szContainerApp, szContainerObj);
386 /* Be sure to cleanup before re-assinging the strings. */
387 HeapFree( GetProcessHeap(), 0, This->containerApp );
388 This->containerApp = NULL;
389 HeapFree( GetProcessHeap(), 0, This->containerObj );
390 This->containerObj = NULL;
392 /* Copy the string supplied. */
395 if ((This->containerApp = HeapAlloc( GetProcessHeap(), 0,
396 (lstrlenW(szContainerApp) + 1) * sizeof(WCHAR) )))
397 strcpyW( This->containerApp, szContainerApp );
402 if ((This->containerObj = HeapAlloc( GetProcessHeap(), 0,
403 (lstrlenW(szContainerObj) + 1) * sizeof(WCHAR) )))
404 strcpyW( This->containerObj, szContainerObj );
409 /* undos the work done by DefaultHandler_Run */
410 static void WINAPI DefaultHandler_Stop(DefaultHandler *This)
412 if (!This->pOleDelegate)
415 IOleObject_Unadvise(This->pOleDelegate, This->dwAdvConn);
417 /* FIXME: call IOleCache_OnStop */
419 DataAdviseHolder_OnDisconnect(This->dataAdviseHolder);
420 if (This->pDataDelegate)
422 IDataObject_Release(This->pDataDelegate);
423 This->pDataDelegate = NULL;
425 if (This->pPSDelegate)
427 IPersistStorage_Release(This->pPSDelegate);
428 This->pPSDelegate = NULL;
430 IOleObject_Release(This->pOleDelegate);
431 This->pOleDelegate = NULL;
434 /************************************************************************
435 * DefaultHandler_Close (IOleObject)
437 * The default handler's implementation of this method is meaningless
438 * without a running server so it does nothing.
440 * See Windows documentation for more details on IOleObject methods.
442 static HRESULT WINAPI DefaultHandler_Close(
446 DefaultHandler *This = impl_from_IOleObject(iface);
449 TRACE("(%ld)\n", dwSaveOption);
451 if (!This->pOleDelegate)
454 hr = IOleObject_Close(This->pOleDelegate, dwSaveOption);
456 DefaultHandler_Stop(This);
461 /************************************************************************
462 * DefaultHandler_SetMoniker (IOleObject)
464 * The default handler's implementation of this method does nothing.
466 * See Windows documentation for more details on IOleObject methods.
468 static HRESULT WINAPI DefaultHandler_SetMoniker(
470 DWORD dwWhichMoniker,
473 DefaultHandler *This = impl_from_IOleObject(iface);
475 TRACE("(%p, %ld, %p)\n",
480 if (This->pOleDelegate)
481 return IOleObject_SetMoniker(This->pOleDelegate, dwWhichMoniker, pmk);
486 /************************************************************************
487 * DefaultHandler_GetMoniker (IOleObject)
489 * Delegate this request to the client site if we have one.
491 * See Windows documentation for more details on IOleObject methods.
493 static HRESULT WINAPI DefaultHandler_GetMoniker(
496 DWORD dwWhichMoniker,
499 DefaultHandler *This = impl_from_IOleObject(iface);
501 TRACE("(%p, %ld, %ld, %p)\n",
502 iface, dwAssign, dwWhichMoniker, ppmk);
504 if (This->pOleDelegate)
505 return IOleObject_GetMoniker(This->pOleDelegate, dwAssign, dwWhichMoniker,
508 /* FIXME: dwWhichMoniker == OLEWHICHMK_CONTAINER only? */
509 if (This->clientSite)
511 return IOleClientSite_GetMoniker(This->clientSite,
521 /************************************************************************
522 * DefaultHandler_InitFromData (IOleObject)
524 * This method is meaningless if the server is not running
526 * See Windows documentation for more details on IOleObject methods.
528 static HRESULT WINAPI DefaultHandler_InitFromData(
530 IDataObject* pDataObject,
534 DefaultHandler *This = impl_from_IOleObject(iface);
536 TRACE("(%p, %p, %d, %ld)\n",
537 iface, pDataObject, fCreation, dwReserved);
539 if (This->pOleDelegate)
540 return IOleObject_InitFromData(This->pOleDelegate, pDataObject, fCreation,
542 return OLE_E_NOTRUNNING;
545 /************************************************************************
546 * DefaultHandler_GetClipboardData (IOleObject)
548 * This method is meaningless if the server is not running
550 * See Windows documentation for more details on IOleObject methods.
552 static HRESULT WINAPI DefaultHandler_GetClipboardData(
555 IDataObject** ppDataObject)
557 DefaultHandler *This = impl_from_IOleObject(iface);
559 TRACE("(%p, %ld, %p)\n",
560 iface, dwReserved, ppDataObject);
562 if (This->pOleDelegate)
563 return IOleObject_GetClipboardData(This->pOleDelegate, dwReserved,
566 return OLE_E_NOTRUNNING;
569 static HRESULT WINAPI DefaultHandler_DoVerb(
572 struct tagMSG* lpmsg,
573 IOleClientSite* pActiveSite,
578 DefaultHandler *This = impl_from_IOleObject(iface);
579 IRunnableObject *pRunnableObj = (IRunnableObject *)&This->lpvtblIRunnableObject;
582 TRACE("(%ld, %p, %p, %ld, %p, %s)\n", iVerb, lpmsg, pActiveSite, lindex, hwndParent, wine_dbgstr_rect(lprcPosRect));
584 hr = IRunnableObject_Run(pRunnableObj, NULL);
585 if (FAILED(hr)) return hr;
587 return IOleObject_DoVerb(This->pOleDelegate, iVerb, lpmsg, pActiveSite,
588 lindex, hwndParent, lprcPosRect);
591 /************************************************************************
592 * DefaultHandler_EnumVerbs (IOleObject)
594 * The default handler implementation of this method simply delegates
597 * See Windows documentation for more details on IOleObject methods.
599 static HRESULT WINAPI DefaultHandler_EnumVerbs(
601 IEnumOLEVERB** ppEnumOleVerb)
603 DefaultHandler *This = impl_from_IOleObject(iface);
604 HRESULT hr = OLE_S_USEREG;
606 TRACE("(%p, %p)\n", iface, ppEnumOleVerb);
608 if (This->pOleDelegate)
609 hr = IOleObject_EnumVerbs(This->pOleDelegate, ppEnumOleVerb);
611 if (hr == OLE_S_USEREG)
612 return OleRegEnumVerbs(&This->clsid, ppEnumOleVerb);
617 static HRESULT WINAPI DefaultHandler_Update(
624 /************************************************************************
625 * DefaultHandler_IsUpToDate (IOleObject)
627 * This method is meaningless if the server is not running
629 * See Windows documentation for more details on IOleObject methods.
631 static HRESULT WINAPI DefaultHandler_IsUpToDate(
634 TRACE("(%p)\n", iface);
636 return OLE_E_NOTRUNNING;
639 /************************************************************************
640 * DefaultHandler_GetUserClassID (IOleObject)
642 * TODO: Map to a new class ID if emulation is active.
644 * See Windows documentation for more details on IOleObject methods.
646 static HRESULT WINAPI DefaultHandler_GetUserClassID(
650 DefaultHandler *This = impl_from_IOleObject(iface);
652 TRACE("(%p, %p)\n", iface, pClsid);
654 if (This->pOleDelegate)
655 return IOleObject_GetUserClassID(This->pOleDelegate, pClsid);
661 memcpy(pClsid, &This->clsid, sizeof(CLSID));
666 /************************************************************************
667 * DefaultHandler_GetUserType (IOleObject)
669 * The default handler implementation of this method simply delegates
670 * to OleRegGetUserType
672 * See Windows documentation for more details on IOleObject methods.
674 static HRESULT WINAPI DefaultHandler_GetUserType(
677 LPOLESTR* pszUserType)
679 DefaultHandler *This = impl_from_IOleObject(iface);
681 TRACE("(%p, %ld, %p)\n", iface, dwFormOfType, pszUserType);
683 return OleRegGetUserType(&This->clsid, dwFormOfType, pszUserType);
686 /************************************************************************
687 * DefaultHandler_SetExtent (IOleObject)
689 * This method is meaningless if the server is not running
691 * See Windows documentation for more details on IOleObject methods.
693 static HRESULT WINAPI DefaultHandler_SetExtent(
698 DefaultHandler *This = impl_from_IOleObject(iface);
700 TRACE("(%p, %lx, (%ld x %ld))\n", iface,
701 dwDrawAspect, psizel->cx, psizel->cy);
703 if (This->pOleDelegate)
704 IOleObject_SetExtent(This->pOleDelegate, dwDrawAspect, psizel);
706 return OLE_E_NOTRUNNING;
709 /************************************************************************
710 * DefaultHandler_GetExtent (IOleObject)
712 * The default handler's implementation of this method returns uses
713 * the cache to locate the aspect and extract the extent from it.
715 * See Windows documentation for more details on IOleObject methods.
717 static HRESULT WINAPI DefaultHandler_GetExtent(
722 DVTARGETDEVICE* targetDevice;
723 IViewObject2* cacheView = NULL;
726 DefaultHandler *This = impl_from_IOleObject(iface);
728 TRACE("(%p, %lx, %p)\n", iface, dwDrawAspect, psizel);
730 if (This->pOleDelegate)
731 return IOleObject_GetExtent(This->pOleDelegate, dwDrawAspect, psizel);
733 hres = IUnknown_QueryInterface(This->dataCache, &IID_IViewObject2, (void**)&cacheView);
738 * Prepare the call to the cache's GetExtent method.
740 * Here we would build a valid DVTARGETDEVICE structure
741 * but, since we are calling into the data cache, we
742 * know it's implementation and we'll skip this
743 * extra work until later.
747 hres = IViewObject2_GetExtent(cacheView,
756 IViewObject2_Release(cacheView);
761 /************************************************************************
762 * DefaultHandler_Advise (IOleObject)
764 * The default handler's implementation of this method simply
765 * delegates to the OleAdviseHolder.
767 * See Windows documentation for more details on IOleObject methods.
769 static HRESULT WINAPI DefaultHandler_Advise(
771 IAdviseSink* pAdvSink,
772 DWORD* pdwConnection)
775 DefaultHandler *This = impl_from_IOleObject(iface);
777 TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection);
779 /* Make sure we have an advise holder before we start. */
780 if (!This->oleAdviseHolder)
781 hres = CreateOleAdviseHolder(&This->oleAdviseHolder);
784 hres = IOleAdviseHolder_Advise(This->oleAdviseHolder,
791 /************************************************************************
792 * DefaultHandler_Unadvise (IOleObject)
794 * The default handler's implementation of this method simply
795 * delegates to the OleAdviseHolder.
797 * See Windows documentation for more details on IOleObject methods.
799 static HRESULT WINAPI DefaultHandler_Unadvise(
803 DefaultHandler *This = impl_from_IOleObject(iface);
805 TRACE("(%p, %ld)\n", iface, dwConnection);
808 * If we don't have an advise holder yet, it means we don't have
811 if (!This->oleAdviseHolder)
812 return OLE_E_NOCONNECTION;
814 return IOleAdviseHolder_Unadvise(This->oleAdviseHolder,
818 /************************************************************************
819 * DefaultHandler_EnumAdvise (IOleObject)
821 * The default handler's implementation of this method simply
822 * delegates to the OleAdviseHolder.
824 * See Windows documentation for more details on IOleObject methods.
826 static HRESULT WINAPI DefaultHandler_EnumAdvise(
828 IEnumSTATDATA** ppenumAdvise)
830 DefaultHandler *This = impl_from_IOleObject(iface);
832 TRACE("(%p, %p)\n", iface, ppenumAdvise);
838 *ppenumAdvise = NULL;
840 if (!This->oleAdviseHolder)
841 return IOleAdviseHolder_EnumAdvise(This->oleAdviseHolder,
847 /************************************************************************
848 * DefaultHandler_GetMiscStatus (IOleObject)
850 * The default handler's implementation of this method simply delegates
851 * to OleRegGetMiscStatus.
853 * See Windows documentation for more details on IOleObject methods.
855 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
861 DefaultHandler *This = impl_from_IOleObject(iface);
863 TRACE("(%p, %lx, %p)\n", iface, dwAspect, pdwStatus);
865 if (This->pOleDelegate)
866 return IOleObject_GetMiscStatus(This->pOleDelegate, dwAspect, pdwStatus);
868 hres = OleRegGetMiscStatus(&This->clsid, dwAspect, pdwStatus);
876 /************************************************************************
877 * DefaultHandler_SetColorScheme (IOleObject)
879 * This method is meaningless if the server is not running
881 * See Windows documentation for more details on IOleObject methods.
883 static HRESULT WINAPI DefaultHandler_SetColorScheme(
885 struct tagLOGPALETTE* pLogpal)
887 DefaultHandler *This = impl_from_IOleObject(iface);
889 TRACE("(%p, %p))\n", iface, pLogpal);
891 if (This->pOleDelegate)
892 return IOleObject_SetColorScheme(This->pOleDelegate, pLogpal);
894 return OLE_E_NOTRUNNING;
897 /*********************************************************
898 * Methods implementation for the IDataObject part of
899 * the DefaultHandler class.
902 /************************************************************************
903 * DefaultHandler_IDataObject_QueryInterface (IUnknown)
905 * See Windows documentation for more details on IUnknown methods.
907 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
912 DefaultHandler *This = impl_from_IDataObject(iface);
914 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
917 /************************************************************************
918 * DefaultHandler_IDataObject_AddRef (IUnknown)
920 * See Windows documentation for more details on IUnknown methods.
922 static ULONG WINAPI DefaultHandler_IDataObject_AddRef(
925 DefaultHandler *This = impl_from_IDataObject(iface);
927 return IUnknown_AddRef(This->outerUnknown);
930 /************************************************************************
931 * DefaultHandler_IDataObject_Release (IUnknown)
933 * See Windows documentation for more details on IUnknown methods.
935 static ULONG WINAPI DefaultHandler_IDataObject_Release(
938 DefaultHandler *This = impl_from_IDataObject(iface);
940 return IUnknown_Release(This->outerUnknown);
943 /************************************************************************
944 * DefaultHandler_GetData
946 * Get Data from a source dataobject using format pformatetcIn->cfFormat
947 * See Windows documentation for more details on GetData.
948 * Default handler's implementation of this method delegates to the cache.
950 static HRESULT WINAPI DefaultHandler_GetData(
952 LPFORMATETC pformatetcIn,
955 IDataObject* cacheDataObject = NULL;
958 DefaultHandler *This = impl_from_IDataObject(iface);
960 TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pmedium);
962 hres = IUnknown_QueryInterface(This->dataCache,
964 (void**)&cacheDataObject);
969 hres = IDataObject_GetData(cacheDataObject,
973 IDataObject_Release(cacheDataObject);
978 static HRESULT WINAPI DefaultHandler_GetDataHere(
980 LPFORMATETC pformatetc,
987 /************************************************************************
988 * DefaultHandler_QueryGetData (IDataObject)
990 * The default handler's implementation of this method delegates to
993 * See Windows documentation for more details on IDataObject methods.
995 static HRESULT WINAPI DefaultHandler_QueryGetData(
997 LPFORMATETC pformatetc)
999 IDataObject* cacheDataObject = NULL;
1002 DefaultHandler *This = impl_from_IDataObject(iface);
1004 TRACE("(%p, %p)\n", iface, pformatetc);
1006 hres = IUnknown_QueryInterface(This->dataCache,
1008 (void**)&cacheDataObject);
1011 return E_UNEXPECTED;
1013 hres = IDataObject_QueryGetData(cacheDataObject,
1016 IDataObject_Release(cacheDataObject);
1021 /************************************************************************
1022 * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
1024 * This method is meaningless if the server is not running
1026 * See Windows documentation for more details on IDataObject methods.
1028 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
1030 LPFORMATETC pformatetcIn,
1031 LPFORMATETC pformatetcOut)
1033 DefaultHandler *This = impl_from_IDataObject(iface);
1034 IDataObject *pDataObject;
1037 TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pformatetcOut);
1039 if (!This->pOleDelegate)
1040 return OLE_E_NOTRUNNING;
1042 hr = IOleObject_QueryInterface(This->pOleDelegate, &IID_IDataObject, (void **)&pDataObject);
1043 return IDataObject_GetCanonicalFormatEtc(pDataObject, pformatetcIn, pformatetcOut);
1046 /************************************************************************
1047 * DefaultHandler_SetData (IDataObject)
1049 * The default handler's implementation of this method delegates to
1052 * See Windows documentation for more details on IDataObject methods.
1054 static HRESULT WINAPI DefaultHandler_SetData(
1056 LPFORMATETC pformatetc,
1060 DefaultHandler *This = impl_from_IDataObject(iface);
1061 IDataObject* cacheDataObject = NULL;
1064 TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
1066 hres = IUnknown_QueryInterface(This->dataCache,
1068 (void**)&cacheDataObject);
1071 return E_UNEXPECTED;
1073 hres = IDataObject_SetData(cacheDataObject,
1078 IDataObject_Release(cacheDataObject);
1083 /************************************************************************
1084 * DefaultHandler_EnumFormatEtc (IDataObject)
1086 * The default handler's implementation of This method simply delegates
1087 * to OleRegEnumFormatEtc.
1089 * See Windows documentation for more details on IDataObject methods.
1091 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
1094 IEnumFORMATETC** ppenumFormatEtc)
1097 DefaultHandler *This = impl_from_IDataObject(iface);
1099 TRACE("(%p, %lx, %p)\n", iface, dwDirection, ppenumFormatEtc);
1101 hres = OleRegEnumFormatEtc(&This->clsid, dwDirection, ppenumFormatEtc);
1106 /************************************************************************
1107 * DefaultHandler_DAdvise (IDataObject)
1109 * The default handler's implementation of this method simply
1110 * delegates to the DataAdviseHolder.
1112 * See Windows documentation for more details on IDataObject methods.
1114 static HRESULT WINAPI DefaultHandler_DAdvise(
1116 FORMATETC* pformatetc,
1118 IAdviseSink* pAdvSink,
1119 DWORD* pdwConnection)
1121 HRESULT hres = S_OK;
1122 DefaultHandler *This = impl_from_IDataObject(iface);
1124 TRACE("(%p, %p, %ld, %p, %p)\n",
1125 iface, pformatetc, advf, pAdvSink, pdwConnection);
1127 /* Make sure we have a data advise holder before we start. */
1128 if (!This->dataAdviseHolder)
1129 hres = CreateDataAdviseHolder(&This->dataAdviseHolder);
1131 if (SUCCEEDED(hres))
1132 hres = IDataAdviseHolder_Advise(This->dataAdviseHolder,
1142 /************************************************************************
1143 * DefaultHandler_DUnadvise (IDataObject)
1145 * The default handler's implementation of this method simply
1146 * delegates to the DataAdviseHolder.
1148 * See Windows documentation for more details on IDataObject methods.
1150 static HRESULT WINAPI DefaultHandler_DUnadvise(
1154 DefaultHandler *This = impl_from_IDataObject(iface);
1156 TRACE("(%p, %ld)\n", iface, dwConnection);
1159 * If we don't have a data advise holder yet, it means that
1160 * we don't have any connections..
1162 if (!This->dataAdviseHolder)
1163 return OLE_E_NOCONNECTION;
1165 return IDataAdviseHolder_Unadvise(This->dataAdviseHolder,
1169 /************************************************************************
1170 * DefaultHandler_EnumDAdvise (IDataObject)
1172 * The default handler's implementation of this method simply
1173 * delegates to the DataAdviseHolder.
1175 * See Windows documentation for more details on IDataObject methods.
1177 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
1179 IEnumSTATDATA** ppenumAdvise)
1181 DefaultHandler *This = impl_from_IDataObject(iface);
1183 TRACE("(%p, %p)\n", iface, ppenumAdvise);
1189 *ppenumAdvise = NULL;
1191 /* If we have a data advise holder object, delegate. */
1192 if (This->dataAdviseHolder)
1193 return IDataAdviseHolder_EnumAdvise(This->dataAdviseHolder,
1199 /*********************************************************
1200 * Methods implementation for the IRunnableObject part
1201 * of the DefaultHandler class.
1204 /************************************************************************
1205 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1207 * See Windows documentation for more details on IUnknown methods.
1209 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
1210 IRunnableObject* iface,
1214 DefaultHandler *This = impl_from_IRunnableObject(iface);
1216 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
1219 /************************************************************************
1220 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1222 * See Windows documentation for more details on IUnknown methods.
1224 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef(
1225 IRunnableObject* iface)
1227 DefaultHandler *This = impl_from_IRunnableObject(iface);
1229 return IUnknown_AddRef(This->outerUnknown);
1232 /************************************************************************
1233 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1235 * See Windows documentation for more details on IUnknown methods.
1237 static ULONG WINAPI DefaultHandler_IRunnableObject_Release(
1238 IRunnableObject* iface)
1240 DefaultHandler *This = impl_from_IRunnableObject(iface);
1242 return IUnknown_Release(This->outerUnknown);
1245 /************************************************************************
1246 * DefaultHandler_GetRunningClass (IRunnableObject)
1248 * See Windows documentation for more details on IRunnableObject methods.
1250 static HRESULT WINAPI DefaultHandler_GetRunningClass(
1251 IRunnableObject* iface,
1258 static HRESULT WINAPI DefaultHandler_Run(
1259 IRunnableObject* iface,
1262 DefaultHandler *This = impl_from_IRunnableObject(iface);
1265 FIXME("(%p): semi-stub\n", pbc);
1267 /* already running? if so nothing to do */
1268 if (This->pOleDelegate)
1271 hr = CoCreateInstance(&This->clsid, NULL, CLSCTX_LOCAL_SERVER,
1272 &IID_IOleObject, (void **)&This->pOleDelegate);
1276 hr = IOleObject_Advise(This->pOleDelegate,
1277 (IAdviseSink *)&This->lpvtblIAdviseSink,
1280 if (SUCCEEDED(hr) && This->clientSite)
1281 hr = IOleObject_SetClientSite(This->pOleDelegate, This->clientSite);
1285 IOleObject_QueryInterface(This->pOleDelegate, &IID_IPersistStorage,
1286 (void **)&This->pPSDelegate);
1287 if (This->pPSDelegate)
1288 hr = IPersistStorage_InitNew(This->pPSDelegate, NULL);
1291 if (SUCCEEDED(hr) && This->containerApp)
1292 hr = IOleObject_SetHostNames(This->pOleDelegate, This->containerApp,
1293 This->containerObj);
1295 /* FIXME: do more stuff here:
1296 * - IOleObject_GetMiscStatus
1297 * - IOleObject_GetMoniker
1302 hr = IOleObject_QueryInterface(This->pOleDelegate, &IID_IDataObject,
1303 (void **)&This->pDataDelegate);
1305 if (SUCCEEDED(hr) && This->dataAdviseHolder)
1306 hr = DataAdviseHolder_OnConnect(This->dataAdviseHolder, This->pDataDelegate);
1309 DefaultHandler_Stop(This);
1314 /************************************************************************
1315 * DefaultHandler_IsRunning (IRunnableObject)
1317 * See Windows documentation for more details on IRunnableObject methods.
1319 static BOOL WINAPI DefaultHandler_IsRunning(
1320 IRunnableObject* iface)
1322 DefaultHandler *This = impl_from_IRunnableObject(iface);
1326 if (This->pOleDelegate)
1332 /************************************************************************
1333 * DefaultHandler_LockRunning (IRunnableObject)
1335 * See Windows documentation for more details on IRunnableObject methods.
1337 static HRESULT WINAPI DefaultHandler_LockRunning(
1338 IRunnableObject* iface,
1340 BOOL fLastUnlockCloses)
1346 /************************************************************************
1347 * DefaultHandler_SetContainedObject (IRunnableObject)
1349 * See Windows documentation for more details on IRunnableObject methods.
1351 static HRESULT WINAPI DefaultHandler_SetContainedObject(
1352 IRunnableObject* iface,
1359 static HRESULT WINAPI DefaultHandler_IAdviseSink_QueryInterface(
1364 if (IsEqualIID(riid, &IID_IUnknown) ||
1365 IsEqualIID(riid, &IID_IAdviseSink))
1368 IAdviseSink_AddRef(iface);
1372 return E_NOINTERFACE;
1375 static ULONG WINAPI DefaultHandler_IAdviseSink_AddRef(
1378 DefaultHandler *This = impl_from_IAdviseSink(iface);
1380 return IUnknown_AddRef((IUnknown *)&This->lpvtblIUnknown);
1383 static ULONG WINAPI DefaultHandler_IAdviseSink_Release(
1386 DefaultHandler *This = impl_from_IAdviseSink(iface);
1388 return IUnknown_Release((IUnknown *)&This->lpvtblIUnknown);
1391 static void WINAPI DefaultHandler_IAdviseSink_OnDataChange(
1393 FORMATETC *pFormatetc,
1399 static void WINAPI DefaultHandler_IAdviseSink_OnViewChange(
1407 static void WINAPI DefaultHandler_IAdviseSink_OnRename(
1411 DefaultHandler *This = impl_from_IAdviseSink(iface);
1413 TRACE("(%p)\n", pmk);
1415 if (This->oleAdviseHolder)
1416 IOleAdviseHolder_SendOnRename(This->oleAdviseHolder, pmk);
1419 static void WINAPI DefaultHandler_IAdviseSink_OnSave(
1422 DefaultHandler *This = impl_from_IAdviseSink(iface);
1426 if (This->oleAdviseHolder)
1427 IOleAdviseHolder_SendOnSave(This->oleAdviseHolder);
1430 static void WINAPI DefaultHandler_IAdviseSink_OnClose(
1433 DefaultHandler *This = impl_from_IAdviseSink(iface);
1437 if (This->oleAdviseHolder)
1438 IOleAdviseHolder_SendOnClose(This->oleAdviseHolder);
1440 DefaultHandler_Stop(This);
1444 * Virtual function tables for the DefaultHandler class.
1446 static const IOleObjectVtbl DefaultHandler_IOleObject_VTable =
1448 DefaultHandler_QueryInterface,
1449 DefaultHandler_AddRef,
1450 DefaultHandler_Release,
1451 DefaultHandler_SetClientSite,
1452 DefaultHandler_GetClientSite,
1453 DefaultHandler_SetHostNames,
1454 DefaultHandler_Close,
1455 DefaultHandler_SetMoniker,
1456 DefaultHandler_GetMoniker,
1457 DefaultHandler_InitFromData,
1458 DefaultHandler_GetClipboardData,
1459 DefaultHandler_DoVerb,
1460 DefaultHandler_EnumVerbs,
1461 DefaultHandler_Update,
1462 DefaultHandler_IsUpToDate,
1463 DefaultHandler_GetUserClassID,
1464 DefaultHandler_GetUserType,
1465 DefaultHandler_SetExtent,
1466 DefaultHandler_GetExtent,
1467 DefaultHandler_Advise,
1468 DefaultHandler_Unadvise,
1469 DefaultHandler_EnumAdvise,
1470 DefaultHandler_GetMiscStatus,
1471 DefaultHandler_SetColorScheme
1474 static const IUnknownVtbl DefaultHandler_NDIUnknown_VTable =
1476 DefaultHandler_NDIUnknown_QueryInterface,
1477 DefaultHandler_NDIUnknown_AddRef,
1478 DefaultHandler_NDIUnknown_Release,
1481 static const IDataObjectVtbl DefaultHandler_IDataObject_VTable =
1483 DefaultHandler_IDataObject_QueryInterface,
1484 DefaultHandler_IDataObject_AddRef,
1485 DefaultHandler_IDataObject_Release,
1486 DefaultHandler_GetData,
1487 DefaultHandler_GetDataHere,
1488 DefaultHandler_QueryGetData,
1489 DefaultHandler_GetCanonicalFormatEtc,
1490 DefaultHandler_SetData,
1491 DefaultHandler_EnumFormatEtc,
1492 DefaultHandler_DAdvise,
1493 DefaultHandler_DUnadvise,
1494 DefaultHandler_EnumDAdvise
1497 static const IRunnableObjectVtbl DefaultHandler_IRunnableObject_VTable =
1499 DefaultHandler_IRunnableObject_QueryInterface,
1500 DefaultHandler_IRunnableObject_AddRef,
1501 DefaultHandler_IRunnableObject_Release,
1502 DefaultHandler_GetRunningClass,
1504 DefaultHandler_IsRunning,
1505 DefaultHandler_LockRunning,
1506 DefaultHandler_SetContainedObject
1509 static const IAdviseSinkVtbl DefaultHandler_IAdviseSink_VTable =
1511 DefaultHandler_IAdviseSink_QueryInterface,
1512 DefaultHandler_IAdviseSink_AddRef,
1513 DefaultHandler_IAdviseSink_Release,
1514 DefaultHandler_IAdviseSink_OnDataChange,
1515 DefaultHandler_IAdviseSink_OnViewChange,
1516 DefaultHandler_IAdviseSink_OnRename,
1517 DefaultHandler_IAdviseSink_OnSave,
1518 DefaultHandler_IAdviseSink_OnClose
1521 /*********************************************************
1522 * Methods implementation for the DefaultHandler class.
1524 static DefaultHandler* DefaultHandler_Construct(
1526 LPUNKNOWN pUnkOuter)
1528 DefaultHandler* This = NULL;
1531 * Allocate space for the object.
1533 This = HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler));
1538 This->lpVtbl = &DefaultHandler_IOleObject_VTable;
1539 This->lpvtblIUnknown = &DefaultHandler_NDIUnknown_VTable;
1540 This->lpvtblIDataObject = &DefaultHandler_IDataObject_VTable;
1541 This->lpvtblIRunnableObject = &DefaultHandler_IRunnableObject_VTable;
1542 This->lpvtblIAdviseSink = &DefaultHandler_IAdviseSink_VTable;
1545 * Start with one reference count. The caller of this function
1546 * must release the interface pointer when it is done.
1551 * Initialize the outer unknown
1552 * We don't keep a reference on the outer unknown since, the way
1553 * aggregation works, our lifetime is at least as large as it's
1557 pUnkOuter = (IUnknown*)&This->lpvtblIUnknown;
1559 This->outerUnknown = pUnkOuter;
1562 * Create a datacache object.
1563 * We aggregate with the datacache. Make sure we pass our outer
1564 * unknown as the datacache's outer unknown.
1566 CreateDataCache(This->outerUnknown,
1569 (void**)&This->dataCache);
1572 * Initialize the other data members of the class.
1574 memcpy(&This->clsid, clsid, sizeof(CLSID));
1575 This->clientSite = NULL;
1576 This->oleAdviseHolder = NULL;
1577 This->dataAdviseHolder = NULL;
1578 This->containerApp = NULL;
1579 This->containerObj = NULL;
1580 This->pOleDelegate = NULL;
1581 This->pPSDelegate = NULL;
1582 This->pDataDelegate = NULL;
1584 This->dwAdvConn = 0;
1589 static void DefaultHandler_Destroy(
1590 DefaultHandler* This)
1592 /* release delegates */
1593 DefaultHandler_Stop(This);
1595 /* Free the strings idenfitying the object */
1596 HeapFree( GetProcessHeap(), 0, This->containerApp );
1597 This->containerApp = NULL;
1598 HeapFree( GetProcessHeap(), 0, This->containerObj );
1599 This->containerObj = NULL;
1601 /* Release our reference to the data cache. */
1602 if (This->dataCache)
1604 IUnknown_Release(This->dataCache);
1605 This->dataCache = NULL;
1608 /* Same thing for the client site. */
1609 if (This->clientSite)
1611 IOleClientSite_Release(This->clientSite);
1612 This->clientSite = NULL;
1615 /* And the advise holder. */
1616 if (This->oleAdviseHolder)
1618 IOleAdviseHolder_Release(This->oleAdviseHolder);
1619 This->oleAdviseHolder = NULL;
1622 /* And the data advise holder. */
1623 if (This->dataAdviseHolder)
1625 IDataAdviseHolder_Release(This->dataAdviseHolder);
1626 This->dataAdviseHolder = NULL;
1629 /* Free the actual default handler structure. */
1630 HeapFree(GetProcessHeap(), 0, This);
1633 /******************************************************************************
1634 * OleCreateDefaultHandler [OLE32.@]
1636 HRESULT WINAPI OleCreateDefaultHandler(
1638 LPUNKNOWN pUnkOuter,
1642 DefaultHandler* newHandler = NULL;
1645 TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid), pUnkOuter, debugstr_guid(riid), ppvObj);
1656 * If This handler is constructed for aggregation, make sure
1657 * the caller is requesting the IUnknown interface.
1658 * This is necessary because it's the only time the non-delegating
1659 * IUnknown pointer can be returned to the outside.
1661 if (pUnkOuter && !IsEqualIID(&IID_IUnknown, riid))
1662 return CLASS_E_NOAGGREGATION;
1665 * Try to construct a new instance of the class.
1667 newHandler = DefaultHandler_Construct(clsid, pUnkOuter);
1670 return E_OUTOFMEMORY;
1673 * Make sure it supports the interface required by the caller.
1675 hr = IUnknown_QueryInterface((IUnknown*)&newHandler->lpvtblIUnknown, riid, ppvObj);
1678 * Release the reference obtained in the constructor. If
1679 * the QueryInterface was unsuccessful, it will free the class.
1681 IUnknown_Release((IUnknown*)&newHandler->lpvtblIUnknown);