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.
58 #include "wine/unicode.h"
60 #include "wine/debug.h"
62 WINE_DEFAULT_DEBUG_CHANNEL(ole);
64 /****************************************************************************
70 const IOleObjectVtbl* lpVtbl;
71 const IUnknownVtbl* lpvtblIUnknown;
72 const IDataObjectVtbl* lpvtblIDataObject;
73 const IRunnableObjectVtbl* lpvtblIRunnableObject;
75 /* Reference count of this object */
78 /* IUnknown implementation of the outer object. */
79 IUnknown* outerUnknown;
81 /* Class Id that this handler object represents. */
84 /* IUnknown implementation of the datacache. */
87 /* Client site for the embedded object. */
88 IOleClientSite* clientSite;
91 * The IOleAdviseHolder maintains the connections
92 * on behalf of the default handler.
94 IOleAdviseHolder* oleAdviseHolder;
97 * The IDataAdviseHolder maintains the data
98 * connections on behalf of the default handler.
100 IDataAdviseHolder* dataAdviseHolder;
102 /* Name of the container and object contained */
108 typedef struct DefaultHandler DefaultHandler;
111 * Here, I define utility functions to help with the casting of the
113 * There is a version to accommodate all of the VTables implemented
116 static inline DefaultHandler *impl_from_IOleObject( IOleObject *iface )
118 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpVtbl));
121 static inline DefaultHandler *impl_from_NDIUnknown( IUnknown *iface )
123 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIUnknown));
126 static inline DefaultHandler *impl_from_IDataObject( IDataObject *iface )
128 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIDataObject));
131 static inline DefaultHandler *impl_from_IRunnableObject( IRunnableObject *iface )
133 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIRunnableObject));
136 static void DefaultHandler_Destroy(DefaultHandler* This);
139 /*********************************************************
140 * Method implementation for the non delegating IUnknown
141 * part of the DefaultHandler class.
144 /************************************************************************
145 * DefaultHandler_NDIUnknown_QueryInterface (IUnknown)
147 * See Windows documentation for more details on IUnknown methods.
149 * This version of QueryInterface will not delegate it's implementation
150 * to the outer unknown.
152 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
157 DefaultHandler *This = impl_from_NDIUnknown(iface);
159 /* Perform a sanity check on the parameters. */
165 if (IsEqualIID(&IID_IUnknown, riid))
167 else if (IsEqualIID(&IID_IOleObject, riid))
168 *ppvObject = (IOleObject*)&This->lpVtbl;
169 else if (IsEqualIID(&IID_IDataObject, riid))
170 *ppvObject = (IDataObject*)&This->lpvtblIDataObject;
171 else if (IsEqualIID(&IID_IRunnableObject, riid))
172 *ppvObject = (IRunnableObject*)&This->lpvtblIRunnableObject;
176 * Blind aggregate the data cache to "inherit" it's interfaces.
178 if (IUnknown_QueryInterface(This->dataCache, riid, ppvObject) == S_OK)
182 /* Check that we obtained an interface. */
183 if (*ppvObject == NULL)
185 WARN( "() : asking for un supported interface %s\n", debugstr_guid(riid));
186 return E_NOINTERFACE;
190 * Query Interface always increases the reference count by one when it is
193 IUnknown_AddRef((IUnknown*)*ppvObject);
198 /************************************************************************
199 * DefaultHandler_NDIUnknown_AddRef (IUnknown)
201 * See Windows documentation for more details on IUnknown methods.
203 * This version of QueryInterface will not delegate it's implementation
204 * to the outer unknown.
206 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef(
209 DefaultHandler *This = impl_from_NDIUnknown(iface);
210 return InterlockedIncrement(&This->ref);
213 /************************************************************************
214 * DefaultHandler_NDIUnknown_Release (IUnknown)
216 * See Windows documentation for more details on IUnknown methods.
218 * This version of QueryInterface will not delegate it's implementation
219 * to the outer unknown.
221 static ULONG WINAPI DefaultHandler_NDIUnknown_Release(
224 DefaultHandler *This = impl_from_NDIUnknown(iface);
227 /* Decrease the reference count on this object. */
228 ref = InterlockedDecrement(&This->ref);
230 if (!ref) DefaultHandler_Destroy(This);
235 /*********************************************************
236 * Methods implementation for the IOleObject part of
237 * the DefaultHandler class.
240 /************************************************************************
241 * DefaultHandler_QueryInterface (IUnknown)
243 * See Windows documentation for more details on IUnknown methods.
245 static HRESULT WINAPI DefaultHandler_QueryInterface(
250 DefaultHandler *This = impl_from_IOleObject(iface);
252 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
255 /************************************************************************
256 * DefaultHandler_AddRef (IUnknown)
258 * See Windows documentation for more details on IUnknown methods.
260 static ULONG WINAPI DefaultHandler_AddRef(
263 DefaultHandler *This = impl_from_IOleObject(iface);
265 return IUnknown_AddRef(This->outerUnknown);
268 /************************************************************************
269 * DefaultHandler_Release (IUnknown)
271 * See Windows documentation for more details on IUnknown methods.
273 static ULONG WINAPI DefaultHandler_Release(
276 DefaultHandler *This = impl_from_IOleObject(iface);
278 return IUnknown_Release(This->outerUnknown);
281 /************************************************************************
282 * DefaultHandler_SetClientSite (IOleObject)
284 * The default handler's implementation of this method only keeps the
285 * client site pointer for future reference.
287 * See Windows documentation for more details on IOleObject methods.
289 static HRESULT WINAPI DefaultHandler_SetClientSite(
291 IOleClientSite* pClientSite)
293 DefaultHandler *This = impl_from_IOleObject(iface);
295 TRACE("(%p, %p)\n", iface, pClientSite);
298 * Make sure we release the previous client site if there
301 if (This->clientSite)
302 IOleClientSite_Release(This->clientSite);
304 This->clientSite = pClientSite;
306 if (This->clientSite)
307 IOleClientSite_AddRef(This->clientSite);
312 /************************************************************************
313 * DefaultHandler_GetClientSite (IOleObject)
315 * The default handler's implementation of this method returns the
316 * last pointer set in IOleObject_SetClientSite.
318 * See Windows documentation for more details on IOleObject methods.
320 static HRESULT WINAPI DefaultHandler_GetClientSite(
322 IOleClientSite** ppClientSite)
324 DefaultHandler *This = impl_from_IOleObject(iface);
330 *ppClientSite = This->clientSite;
332 if (This->clientSite)
333 IOleClientSite_AddRef(This->clientSite);
338 /************************************************************************
339 * DefaultHandler_SetHostNames (IOleObject)
341 * The default handler's implementation of this method just stores
342 * the strings and returns S_OK.
344 * See Windows documentation for more details on IOleObject methods.
346 static HRESULT WINAPI DefaultHandler_SetHostNames(
348 LPCOLESTR szContainerApp,
349 LPCOLESTR szContainerObj)
351 DefaultHandler *This = impl_from_IOleObject(iface);
353 TRACE("(%p, %s, %s)\n",
355 debugstr_w(szContainerApp),
356 debugstr_w(szContainerObj));
358 /* Be sure to cleanup before re-assinging the strings. */
359 HeapFree( GetProcessHeap(), 0, This->containerApp );
360 This->containerApp = NULL;
361 HeapFree( GetProcessHeap(), 0, This->containerObj );
362 This->containerObj = NULL;
364 /* Copy the string supplied. */
367 if ((This->containerApp = HeapAlloc( GetProcessHeap(), 0,
368 (lstrlenW(szContainerApp) + 1) * sizeof(WCHAR) )))
369 strcpyW( This->containerApp, szContainerApp );
374 if ((This->containerObj = HeapAlloc( GetProcessHeap(), 0,
375 (lstrlenW(szContainerObj) + 1) * sizeof(WCHAR) )))
376 strcpyW( This->containerObj, szContainerObj );
381 /************************************************************************
382 * DefaultHandler_Close (IOleObject)
384 * The default handler's implementation of this method is meaningless
385 * without a running server so it does nothing.
387 * See Windows documentation for more details on IOleObject methods.
389 static HRESULT WINAPI DefaultHandler_Close(
397 /************************************************************************
398 * DefaultHandler_SetMoniker (IOleObject)
400 * The default handler's implementation of this method does nothing.
402 * See Windows documentation for more details on IOleObject methods.
404 static HRESULT WINAPI DefaultHandler_SetMoniker(
406 DWORD dwWhichMoniker,
409 TRACE("(%p, %ld, %p)\n",
417 /************************************************************************
418 * DefaultHandler_GetMoniker (IOleObject)
420 * Delegate this request to the client site if we have one.
422 * See Windows documentation for more details on IOleObject methods.
424 static HRESULT WINAPI DefaultHandler_GetMoniker(
427 DWORD dwWhichMoniker,
430 DefaultHandler *This = impl_from_IOleObject(iface);
432 TRACE("(%p, %ld, %ld, %p)\n",
433 iface, dwAssign, dwWhichMoniker, ppmk);
435 if (This->clientSite)
437 return IOleClientSite_GetMoniker(This->clientSite,
447 /************************************************************************
448 * DefaultHandler_InitFromData (IOleObject)
450 * This method is meaningless if the server is not running
452 * See Windows documentation for more details on IOleObject methods.
454 static HRESULT WINAPI DefaultHandler_InitFromData(
456 IDataObject* pDataObject,
460 TRACE("(%p, %p, %d, %ld)\n",
461 iface, pDataObject, fCreation, dwReserved);
463 return OLE_E_NOTRUNNING;
466 /************************************************************************
467 * DefaultHandler_GetClipboardData (IOleObject)
469 * This method is meaningless if the server is not running
471 * See Windows documentation for more details on IOleObject methods.
473 static HRESULT WINAPI DefaultHandler_GetClipboardData(
476 IDataObject** ppDataObject)
478 TRACE("(%p, %ld, %p)\n",
479 iface, dwReserved, ppDataObject);
481 return OLE_E_NOTRUNNING;
484 static HRESULT WINAPI DefaultHandler_DoVerb(
487 struct tagMSG* lpmsg,
488 IOleClientSite* pActiveSite,
497 /************************************************************************
498 * DefaultHandler_EnumVerbs (IOleObject)
500 * The default handler implementation of this method simply delegates
503 * See Windows documentation for more details on IOleObject methods.
505 static HRESULT WINAPI DefaultHandler_EnumVerbs(
507 IEnumOLEVERB** ppEnumOleVerb)
509 DefaultHandler *This = impl_from_IOleObject(iface);
511 TRACE("(%p, %p)\n", iface, ppEnumOleVerb);
513 return OleRegEnumVerbs(&This->clsid, ppEnumOleVerb);
516 static HRESULT WINAPI DefaultHandler_Update(
523 /************************************************************************
524 * DefaultHandler_IsUpToDate (IOleObject)
526 * This method is meaningless if the server is not running
528 * See Windows documentation for more details on IOleObject methods.
530 static HRESULT WINAPI DefaultHandler_IsUpToDate(
533 TRACE("(%p)\n", iface);
535 return OLE_E_NOTRUNNING;
538 /************************************************************************
539 * DefaultHandler_GetUserClassID (IOleObject)
541 * TODO: Map to a new class ID if emulation is active.
543 * See Windows documentation for more details on IOleObject methods.
545 static HRESULT WINAPI DefaultHandler_GetUserClassID(
549 DefaultHandler *This = impl_from_IOleObject(iface);
551 TRACE("(%p, %p)\n", iface, pClsid);
557 memcpy(pClsid, &This->clsid, sizeof(CLSID));
562 /************************************************************************
563 * DefaultHandler_GetUserType (IOleObject)
565 * The default handler implementation of this method simply delegates
566 * to OleRegGetUserType
568 * See Windows documentation for more details on IOleObject methods.
570 static HRESULT WINAPI DefaultHandler_GetUserType(
573 LPOLESTR* pszUserType)
575 DefaultHandler *This = impl_from_IOleObject(iface);
577 TRACE("(%p, %ld, %p)\n", iface, dwFormOfType, pszUserType);
579 return OleRegGetUserType(&This->clsid, dwFormOfType, pszUserType);
582 /************************************************************************
583 * DefaultHandler_SetExtent (IOleObject)
585 * This method is meaningless if the server is not running
587 * See Windows documentation for more details on IOleObject methods.
589 static HRESULT WINAPI DefaultHandler_SetExtent(
594 TRACE("(%p, %lx, (%ld x %ld))\n", iface,
595 dwDrawAspect, psizel->cx, psizel->cy);
596 return OLE_E_NOTRUNNING;
599 /************************************************************************
600 * DefaultHandler_GetExtent (IOleObject)
602 * The default handler's implementation of this method returns uses
603 * the cache to locate the aspect and extract the extent from it.
605 * See Windows documentation for more details on IOleObject methods.
607 static HRESULT WINAPI DefaultHandler_GetExtent(
612 DVTARGETDEVICE* targetDevice;
613 IViewObject2* cacheView = NULL;
616 DefaultHandler *This = impl_from_IOleObject(iface);
618 TRACE("(%p, %lx, %p)\n", iface, dwDrawAspect, psizel);
620 hres = IUnknown_QueryInterface(This->dataCache, &IID_IViewObject2, (void**)&cacheView);
626 * Prepare the call to the cache's GetExtent method.
628 * Here we would build a valid DVTARGETDEVICE structure
629 * but, since we are calling into the data cache, we
630 * know it's implementation and we'll skip this
631 * extra work until later.
635 hres = IViewObject2_GetExtent(cacheView,
644 IViewObject2_Release(cacheView);
649 /************************************************************************
650 * DefaultHandler_Advise (IOleObject)
652 * The default handler's implementation of this method simply
653 * delegates to the OleAdviseHolder.
655 * See Windows documentation for more details on IOleObject methods.
657 static HRESULT WINAPI DefaultHandler_Advise(
659 IAdviseSink* pAdvSink,
660 DWORD* pdwConnection)
663 DefaultHandler *This = impl_from_IOleObject(iface);
665 TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection);
667 /* Make sure we have an advise holder before we start. */
668 if (!This->oleAdviseHolder)
669 hres = CreateOleAdviseHolder(&This->oleAdviseHolder);
672 hres = IOleAdviseHolder_Advise(This->oleAdviseHolder,
679 /************************************************************************
680 * DefaultHandler_Unadvise (IOleObject)
682 * The default handler's implementation of this method simply
683 * delegates to the OleAdviseHolder.
685 * See Windows documentation for more details on IOleObject methods.
687 static HRESULT WINAPI DefaultHandler_Unadvise(
691 DefaultHandler *This = impl_from_IOleObject(iface);
693 TRACE("(%p, %ld)\n", iface, dwConnection);
696 * If we don't have an advise holder yet, it means we don't have
699 if (!This->oleAdviseHolder)
700 return OLE_E_NOCONNECTION;
702 return IOleAdviseHolder_Unadvise(This->oleAdviseHolder,
706 /************************************************************************
707 * DefaultHandler_EnumAdvise (IOleObject)
709 * The default handler's implementation of this method simply
710 * delegates to the OleAdviseHolder.
712 * See Windows documentation for more details on IOleObject methods.
714 static HRESULT WINAPI DefaultHandler_EnumAdvise(
716 IEnumSTATDATA** ppenumAdvise)
718 DefaultHandler *This = impl_from_IOleObject(iface);
720 TRACE("(%p, %p)\n", iface, ppenumAdvise);
726 *ppenumAdvise = NULL;
728 if (!This->oleAdviseHolder)
729 return IOleAdviseHolder_EnumAdvise(This->oleAdviseHolder,
735 /************************************************************************
736 * DefaultHandler_GetMiscStatus (IOleObject)
738 * The default handler's implementation of this method simply delegates
739 * to OleRegGetMiscStatus.
741 * See Windows documentation for more details on IOleObject methods.
743 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
749 DefaultHandler *This = impl_from_IOleObject(iface);
751 TRACE("(%p, %lx, %p)\n", iface, dwAspect, pdwStatus);
753 hres = OleRegGetMiscStatus(&This->clsid, dwAspect, pdwStatus);
761 /************************************************************************
762 * DefaultHandler_SetExtent (IOleObject)
764 * This method is meaningless if the server is not running
766 * See Windows documentation for more details on IOleObject methods.
768 static HRESULT WINAPI DefaultHandler_SetColorScheme(
770 struct tagLOGPALETTE* pLogpal)
772 TRACE("(%p, %p))\n", iface, pLogpal);
773 return OLE_E_NOTRUNNING;
776 /*********************************************************
777 * Methods implementation for the IDataObject part of
778 * the DefaultHandler class.
781 /************************************************************************
782 * DefaultHandler_IDataObject_QueryInterface (IUnknown)
784 * See Windows documentation for more details on IUnknown methods.
786 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
791 DefaultHandler *This = impl_from_IDataObject(iface);
793 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
796 /************************************************************************
797 * DefaultHandler_IDataObject_AddRef (IUnknown)
799 * See Windows documentation for more details on IUnknown methods.
801 static ULONG WINAPI DefaultHandler_IDataObject_AddRef(
804 DefaultHandler *This = impl_from_IDataObject(iface);
806 return IUnknown_AddRef(This->outerUnknown);
809 /************************************************************************
810 * DefaultHandler_IDataObject_Release (IUnknown)
812 * See Windows documentation for more details on IUnknown methods.
814 static ULONG WINAPI DefaultHandler_IDataObject_Release(
817 DefaultHandler *This = impl_from_IDataObject(iface);
819 return IUnknown_Release(This->outerUnknown);
822 /************************************************************************
823 * DefaultHandler_GetData
825 * Get Data from a source dataobject using format pformatetcIn->cfFormat
826 * See Windows documentation for more details on GetData.
827 * Default handler's implementation of this method delegates to the cache.
829 static HRESULT WINAPI DefaultHandler_GetData(
831 LPFORMATETC pformatetcIn,
834 IDataObject* cacheDataObject = NULL;
837 DefaultHandler *This = impl_from_IDataObject(iface);
839 TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pmedium);
841 hres = IUnknown_QueryInterface(This->dataCache,
843 (void**)&cacheDataObject);
848 hres = IDataObject_GetData(cacheDataObject,
852 IDataObject_Release(cacheDataObject);
857 static HRESULT WINAPI DefaultHandler_GetDataHere(
859 LPFORMATETC pformatetc,
866 /************************************************************************
867 * DefaultHandler_QueryGetData (IDataObject)
869 * The default handler's implementation of this method delegates to
872 * See Windows documentation for more details on IDataObject methods.
874 static HRESULT WINAPI DefaultHandler_QueryGetData(
876 LPFORMATETC pformatetc)
878 IDataObject* cacheDataObject = NULL;
881 DefaultHandler *This = impl_from_IDataObject(iface);
883 TRACE("(%p, %p)\n", iface, pformatetc);
885 hres = IUnknown_QueryInterface(This->dataCache,
887 (void**)&cacheDataObject);
892 hres = IDataObject_QueryGetData(cacheDataObject,
895 IDataObject_Release(cacheDataObject);
900 /************************************************************************
901 * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
903 * This method is meaningless if the server is not running
905 * See Windows documentation for more details on IDataObject methods.
907 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
909 LPFORMATETC pformatectIn,
910 LPFORMATETC pformatetcOut)
912 FIXME("(%p, %p, %p)\n", iface, pformatectIn, pformatetcOut);
914 return OLE_E_NOTRUNNING;
917 /************************************************************************
918 * DefaultHandler_SetData (IDataObject)
920 * The default handler's implementation of this method delegates to
923 * See Windows documentation for more details on IDataObject methods.
925 static HRESULT WINAPI DefaultHandler_SetData(
927 LPFORMATETC pformatetc,
931 IDataObject* cacheDataObject = NULL;
934 DefaultHandler *This = impl_from_IDataObject(iface);
936 TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
938 hres = IUnknown_QueryInterface(This->dataCache,
940 (void**)&cacheDataObject);
945 hres = IDataObject_SetData(cacheDataObject,
950 IDataObject_Release(cacheDataObject);
955 /************************************************************************
956 * DefaultHandler_EnumFormatEtc (IDataObject)
958 * The default handler's implementation of This method simply delegates
959 * to OleRegEnumFormatEtc.
961 * See Windows documentation for more details on IDataObject methods.
963 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
966 IEnumFORMATETC** ppenumFormatEtc)
969 DefaultHandler *This = impl_from_IDataObject(iface);
971 TRACE("(%p, %lx, %p)\n", iface, dwDirection, ppenumFormatEtc);
973 hres = OleRegEnumFormatEtc(&This->clsid, dwDirection, ppenumFormatEtc);
978 /************************************************************************
979 * DefaultHandler_DAdvise (IDataObject)
981 * The default handler's implementation of this method simply
982 * delegates to the DataAdviseHolder.
984 * See Windows documentation for more details on IDataObject methods.
986 static HRESULT WINAPI DefaultHandler_DAdvise(
988 FORMATETC* pformatetc,
990 IAdviseSink* pAdvSink,
991 DWORD* pdwConnection)
994 DefaultHandler *This = impl_from_IDataObject(iface);
996 TRACE("(%p, %p, %ld, %p, %p)\n",
997 iface, pformatetc, advf, pAdvSink, pdwConnection);
999 /* Make sure we have a data advise holder before we start. */
1000 if (!This->dataAdviseHolder)
1001 hres = CreateDataAdviseHolder(&This->dataAdviseHolder);
1003 if (SUCCEEDED(hres))
1004 hres = IDataAdviseHolder_Advise(This->dataAdviseHolder,
1014 /************************************************************************
1015 * DefaultHandler_DUnadvise (IDataObject)
1017 * The default handler's implementation of this method simply
1018 * delegates to the DataAdviseHolder.
1020 * See Windows documentation for more details on IDataObject methods.
1022 static HRESULT WINAPI DefaultHandler_DUnadvise(
1026 DefaultHandler *This = impl_from_IDataObject(iface);
1028 TRACE("(%p, %ld)\n", iface, dwConnection);
1031 * If we don't have a data advise holder yet, it means that
1032 * we don't have any connections..
1034 if (!This->dataAdviseHolder)
1035 return OLE_E_NOCONNECTION;
1037 return IDataAdviseHolder_Unadvise(This->dataAdviseHolder,
1041 /************************************************************************
1042 * DefaultHandler_EnumDAdvise (IDataObject)
1044 * The default handler's implementation of this method simply
1045 * delegates to the DataAdviseHolder.
1047 * See Windows documentation for more details on IDataObject methods.
1049 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
1051 IEnumSTATDATA** ppenumAdvise)
1053 DefaultHandler *This = impl_from_IDataObject(iface);
1055 TRACE("(%p, %p)\n", iface, ppenumAdvise);
1061 *ppenumAdvise = NULL;
1063 /* If we have a data advise holder object, delegate. */
1064 if (This->dataAdviseHolder)
1065 return IDataAdviseHolder_EnumAdvise(This->dataAdviseHolder,
1071 /*********************************************************
1072 * Methods implementation for the IRunnableObject part
1073 * of the DefaultHandler class.
1076 /************************************************************************
1077 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1079 * See Windows documentation for more details on IUnknown methods.
1081 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
1082 IRunnableObject* iface,
1086 DefaultHandler *This = impl_from_IRunnableObject(iface);
1088 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
1091 /************************************************************************
1092 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1094 * See Windows documentation for more details on IUnknown methods.
1096 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef(
1097 IRunnableObject* iface)
1099 DefaultHandler *This = impl_from_IRunnableObject(iface);
1101 return IUnknown_AddRef(This->outerUnknown);
1104 /************************************************************************
1105 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1107 * See Windows documentation for more details on IUnknown methods.
1109 static ULONG WINAPI DefaultHandler_IRunnableObject_Release(
1110 IRunnableObject* iface)
1112 DefaultHandler *This = impl_from_IRunnableObject(iface);
1114 return IUnknown_Release(This->outerUnknown);
1117 /************************************************************************
1118 * DefaultHandler_GetRunningClass (IRunnableObject)
1120 * According to Brockscmidt, Chapter 19, the default handler's
1121 * implementation of IRunnableobject does nothing until the object
1122 * is actually running.
1124 * See Windows documentation for more details on IRunnableObject methods.
1126 static HRESULT WINAPI DefaultHandler_GetRunningClass(
1127 IRunnableObject* iface,
1134 static HRESULT WINAPI DefaultHandler_Run(
1135 IRunnableObject* iface,
1142 /************************************************************************
1143 * DefaultHandler_IsRunning (IRunnableObject)
1145 * According to Brockscmidt, Chapter 19, the default handler's
1146 * implementation of IRunnableobject does nothing until the object
1147 * is actually running.
1149 * See Windows documentation for more details on IRunnableObject methods.
1151 static BOOL WINAPI DefaultHandler_IsRunning(
1152 IRunnableObject* iface)
1158 /************************************************************************
1159 * DefaultHandler_LockRunning (IRunnableObject)
1161 * According to Brockscmidt, Chapter 19, the default handler's
1162 * implementation of IRunnableobject does nothing until the object
1163 * is actually running.
1165 * See Windows documentation for more details on IRunnableObject methods.
1167 static HRESULT WINAPI DefaultHandler_LockRunning(
1168 IRunnableObject* iface,
1170 BOOL fLastUnlockCloses)
1176 /************************************************************************
1177 * DefaultHandler_SetContainedObject (IRunnableObject)
1179 * According to Brockscmidt, Chapter 19, the default handler's
1180 * implementation of IRunnableobject does nothing until the object
1181 * is actually running.
1183 * See Windows documentation for more details on IRunnableObject methods.
1185 static HRESULT WINAPI DefaultHandler_SetContainedObject(
1186 IRunnableObject* iface,
1194 * Virtual function tables for the DefaultHandler class.
1196 static const IOleObjectVtbl DefaultHandler_IOleObject_VTable =
1198 DefaultHandler_QueryInterface,
1199 DefaultHandler_AddRef,
1200 DefaultHandler_Release,
1201 DefaultHandler_SetClientSite,
1202 DefaultHandler_GetClientSite,
1203 DefaultHandler_SetHostNames,
1204 DefaultHandler_Close,
1205 DefaultHandler_SetMoniker,
1206 DefaultHandler_GetMoniker,
1207 DefaultHandler_InitFromData,
1208 DefaultHandler_GetClipboardData,
1209 DefaultHandler_DoVerb,
1210 DefaultHandler_EnumVerbs,
1211 DefaultHandler_Update,
1212 DefaultHandler_IsUpToDate,
1213 DefaultHandler_GetUserClassID,
1214 DefaultHandler_GetUserType,
1215 DefaultHandler_SetExtent,
1216 DefaultHandler_GetExtent,
1217 DefaultHandler_Advise,
1218 DefaultHandler_Unadvise,
1219 DefaultHandler_EnumAdvise,
1220 DefaultHandler_GetMiscStatus,
1221 DefaultHandler_SetColorScheme
1224 static const IUnknownVtbl DefaultHandler_NDIUnknown_VTable =
1226 DefaultHandler_NDIUnknown_QueryInterface,
1227 DefaultHandler_NDIUnknown_AddRef,
1228 DefaultHandler_NDIUnknown_Release,
1231 static const IDataObjectVtbl DefaultHandler_IDataObject_VTable =
1233 DefaultHandler_IDataObject_QueryInterface,
1234 DefaultHandler_IDataObject_AddRef,
1235 DefaultHandler_IDataObject_Release,
1236 DefaultHandler_GetData,
1237 DefaultHandler_GetDataHere,
1238 DefaultHandler_QueryGetData,
1239 DefaultHandler_GetCanonicalFormatEtc,
1240 DefaultHandler_SetData,
1241 DefaultHandler_EnumFormatEtc,
1242 DefaultHandler_DAdvise,
1243 DefaultHandler_DUnadvise,
1244 DefaultHandler_EnumDAdvise
1247 static const IRunnableObjectVtbl DefaultHandler_IRunnableObject_VTable =
1249 DefaultHandler_IRunnableObject_QueryInterface,
1250 DefaultHandler_IRunnableObject_AddRef,
1251 DefaultHandler_IRunnableObject_Release,
1252 DefaultHandler_GetRunningClass,
1254 DefaultHandler_IsRunning,
1255 DefaultHandler_LockRunning,
1256 DefaultHandler_SetContainedObject
1259 /*********************************************************
1260 * Methods implementation for the DefaultHandler class.
1262 static DefaultHandler* DefaultHandler_Construct(
1264 LPUNKNOWN pUnkOuter)
1266 DefaultHandler* This = NULL;
1269 * Allocate space for the object.
1271 This = HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler));
1276 This->lpVtbl = &DefaultHandler_IOleObject_VTable;
1277 This->lpvtblIUnknown = &DefaultHandler_NDIUnknown_VTable;
1278 This->lpvtblIDataObject = &DefaultHandler_IDataObject_VTable;
1279 This->lpvtblIRunnableObject = &DefaultHandler_IRunnableObject_VTable;
1282 * Start with one reference count. The caller of this function
1283 * must release the interface pointer when it is done.
1288 * Initialize the outer unknown
1289 * We don't keep a reference on the outer unknown since, the way
1290 * aggregation works, our lifetime is at least as large as it's
1294 pUnkOuter = (IUnknown*)&This->lpvtblIUnknown;
1296 This->outerUnknown = pUnkOuter;
1299 * Create a datacache object.
1300 * We aggregate with the datacache. Make sure we pass our outer
1301 * unknown as the datacache's outer unknown.
1303 CreateDataCache(This->outerUnknown,
1306 (void**)&This->dataCache);
1309 * Initialize the other data members of the class.
1311 memcpy(&This->clsid, clsid, sizeof(CLSID));
1312 This->clientSite = NULL;
1313 This->oleAdviseHolder = NULL;
1314 This->dataAdviseHolder = NULL;
1315 This->containerApp = NULL;
1316 This->containerObj = NULL;
1321 static void DefaultHandler_Destroy(
1322 DefaultHandler* This)
1324 /* Free the strings idenfitying the object */
1325 HeapFree( GetProcessHeap(), 0, This->containerApp );
1326 This->containerApp = NULL;
1327 HeapFree( GetProcessHeap(), 0, This->containerObj );
1328 This->containerObj = NULL;
1330 /* Release our reference to the data cache. */
1331 if (This->dataCache)
1333 IUnknown_Release(This->dataCache);
1334 This->dataCache = NULL;
1337 /* Same thing for the client site. */
1338 if (This->clientSite)
1340 IOleClientSite_Release(This->clientSite);
1341 This->clientSite = NULL;
1344 /* And the advise holder. */
1345 if (This->oleAdviseHolder)
1347 IOleAdviseHolder_Release(This->oleAdviseHolder);
1348 This->oleAdviseHolder = NULL;
1351 /* And the data advise holder. */
1352 if (This->dataAdviseHolder)
1354 IDataAdviseHolder_Release(This->dataAdviseHolder);
1355 This->dataAdviseHolder = NULL;
1358 /* Free the actual default handler structure. */
1359 HeapFree(GetProcessHeap(), 0, This);
1362 /******************************************************************************
1363 * OleCreateDefaultHandler [OLE32.@]
1365 HRESULT WINAPI OleCreateDefaultHandler(
1367 LPUNKNOWN pUnkOuter,
1371 DefaultHandler* newHandler = NULL;
1374 TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid), pUnkOuter, debugstr_guid(riid), ppvObj);
1385 * If This handler is constructed for aggregation, make sure
1386 * the caller is requesting the IUnknown interface.
1387 * This is necessary because it's the only time the non-delegating
1388 * IUnknown pointer can be returned to the outside.
1390 if (pUnkOuter && IsEqualIID(&IID_IUnknown, riid))
1391 return CLASS_E_NOAGGREGATION;
1394 * Try to construct a new instance of the class.
1396 newHandler = DefaultHandler_Construct(clsid, pUnkOuter);
1399 return E_OUTOFMEMORY;
1402 * Make sure it supports the interface required by the caller.
1404 hr = IUnknown_QueryInterface((IUnknown*)&newHandler->lpvtblIUnknown, riid, ppvObj);
1407 * Release the reference obtained in the constructor. If
1408 * the QueryInterface was unsuccessful, it will free the class.
1410 IUnknown_Release((IUnknown*)&newHandler->lpvtblIUnknown);