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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
);
69 storage_state_uninitialised
,
70 storage_state_initialised
,
76 object_state_not_running
,
80 /****************************************************************************
86 const IOleObjectVtbl
* lpVtbl
;
87 const IUnknownVtbl
* lpvtblIUnknown
;
88 const IDataObjectVtbl
* lpvtblIDataObject
;
89 const IRunnableObjectVtbl
* lpvtblIRunnableObject
;
90 const IAdviseSinkVtbl
*lpvtblIAdviseSink
;
91 const IPersistStorageVtbl
*lpvtblIPersistStorage
;
93 /* Reference count of this object */
96 /* IUnknown implementation of the outer object. */
97 IUnknown
* outerUnknown
;
99 /* Class Id that this handler object represents. */
102 /* IUnknown implementation of the datacache. */
104 /* IPersistStorage implementation of the datacache. */
105 IPersistStorage
* dataCache_PersistStg
;
107 /* Client site for the embedded object. */
108 IOleClientSite
* clientSite
;
111 * The IOleAdviseHolder maintains the connections
112 * on behalf of the default handler.
114 IOleAdviseHolder
* oleAdviseHolder
;
117 * The IDataAdviseHolder maintains the data
118 * connections on behalf of the default handler.
120 IDataAdviseHolder
* dataAdviseHolder
;
122 /* Name of the container and object contained */
126 /* IOleObject delegate */
127 IOleObject
*pOleDelegate
;
128 /* IPersistStorage delegate */
129 IPersistStorage
*pPSDelegate
;
130 /* IDataObject delegate */
131 IDataObject
*pDataDelegate
;
132 enum object_state object_state
;
134 /* connection cookie for the advise on the delegate OLE object */
137 /* storage passed to Load or InitNew */
139 enum storage_state storage_state
;
141 /* optional class factory for object */
142 IClassFactory
*pCFObject
;
143 /* TRUE if acting as an inproc server instead of an inproc handler */
147 typedef struct DefaultHandler DefaultHandler
;
149 static inline DefaultHandler
*impl_from_IOleObject( IOleObject
*iface
)
151 return (DefaultHandler
*)((char*)iface
- FIELD_OFFSET(DefaultHandler
, lpVtbl
));
154 static inline DefaultHandler
*impl_from_NDIUnknown( IUnknown
*iface
)
156 return (DefaultHandler
*)((char*)iface
- FIELD_OFFSET(DefaultHandler
, lpvtblIUnknown
));
159 static inline DefaultHandler
*impl_from_IDataObject( IDataObject
*iface
)
161 return (DefaultHandler
*)((char*)iface
- FIELD_OFFSET(DefaultHandler
, lpvtblIDataObject
));
164 static inline DefaultHandler
*impl_from_IRunnableObject( IRunnableObject
*iface
)
166 return (DefaultHandler
*)((char*)iface
- FIELD_OFFSET(DefaultHandler
, lpvtblIRunnableObject
));
169 static inline DefaultHandler
*impl_from_IAdviseSink( IAdviseSink
*iface
)
171 return (DefaultHandler
*)((char*)iface
- FIELD_OFFSET(DefaultHandler
, lpvtblIAdviseSink
));
174 static inline DefaultHandler
*impl_from_IPersistStorage( IPersistStorage
*iface
)
176 return (DefaultHandler
*)((char*)iface
- FIELD_OFFSET(DefaultHandler
, lpvtblIPersistStorage
));
179 static void DefaultHandler_Destroy(DefaultHandler
* This
);
181 static inline BOOL
object_is_running(DefaultHandler
*This
)
183 return IRunnableObject_IsRunning((IRunnableObject
*)&This
->lpvtblIRunnableObject
);
186 /*********************************************************
187 * Method implementation for the non delegating IUnknown
188 * part of the DefaultHandler class.
191 /************************************************************************
192 * DefaultHandler_NDIUnknown_QueryInterface (IUnknown)
194 * See Windows documentation for more details on IUnknown methods.
196 * This version of QueryInterface will not delegate its implementation
197 * to the outer unknown.
199 static HRESULT WINAPI
DefaultHandler_NDIUnknown_QueryInterface(
204 DefaultHandler
*This
= impl_from_NDIUnknown(iface
);
211 if (IsEqualIID(&IID_IUnknown
, riid
))
213 else if (IsEqualIID(&IID_IOleObject
, riid
))
214 *ppvObject
= &This
->lpVtbl
;
215 else if (IsEqualIID(&IID_IDataObject
, riid
))
216 *ppvObject
= &This
->lpvtblIDataObject
;
217 else if (IsEqualIID(&IID_IRunnableObject
, riid
))
218 *ppvObject
= &This
->lpvtblIRunnableObject
;
219 else if (IsEqualIID(&IID_IPersist
, riid
) ||
220 IsEqualIID(&IID_IPersistStorage
, riid
))
221 *ppvObject
= &This
->lpvtblIPersistStorage
;
222 else if (IsEqualIID(&IID_IViewObject
, riid
) ||
223 IsEqualIID(&IID_IViewObject2
, riid
) ||
224 IsEqualIID(&IID_IOleCache
, riid
) ||
225 IsEqualIID(&IID_IOleCache2
, riid
))
227 HRESULT hr
= IUnknown_QueryInterface(This
->dataCache
, riid
, ppvObject
);
228 if (FAILED(hr
)) FIXME("interface %s not implemented by data cache\n", debugstr_guid(riid
));
231 else if (This
->inproc_server
&& This
->pOleDelegate
)
233 HRESULT hr
= IUnknown_QueryInterface(This
->pOleDelegate
, riid
, ppvObject
);
238 /* Check that we obtained an interface. */
239 if (*ppvObject
== NULL
)
241 WARN( "() : asking for un supported interface %s\n", debugstr_guid(riid
));
242 return E_NOINTERFACE
;
246 * Query Interface always increases the reference count by one when it is
249 IUnknown_AddRef((IUnknown
*)*ppvObject
);
254 /************************************************************************
255 * DefaultHandler_NDIUnknown_AddRef (IUnknown)
257 * See Windows documentation for more details on IUnknown methods.
259 * This version of QueryInterface will not delegate its implementation
260 * to the outer unknown.
262 static ULONG WINAPI
DefaultHandler_NDIUnknown_AddRef(
265 DefaultHandler
*This
= impl_from_NDIUnknown(iface
);
266 return InterlockedIncrement(&This
->ref
);
269 /************************************************************************
270 * DefaultHandler_NDIUnknown_Release (IUnknown)
272 * See Windows documentation for more details on IUnknown methods.
274 * This version of QueryInterface will not delegate its implementation
275 * to the outer unknown.
277 static ULONG WINAPI
DefaultHandler_NDIUnknown_Release(
280 DefaultHandler
*This
= impl_from_NDIUnknown(iface
);
283 ref
= InterlockedDecrement(&This
->ref
);
285 if (!ref
) DefaultHandler_Destroy(This
);
290 /*********************************************************
291 * Methods implementation for the IOleObject part of
292 * the DefaultHandler class.
295 /************************************************************************
296 * DefaultHandler_QueryInterface (IUnknown)
298 * See Windows documentation for more details on IUnknown methods.
300 static HRESULT WINAPI
DefaultHandler_QueryInterface(
305 DefaultHandler
*This
= impl_from_IOleObject(iface
);
307 return IUnknown_QueryInterface(This
->outerUnknown
, riid
, ppvObject
);
310 /************************************************************************
311 * DefaultHandler_AddRef (IUnknown)
313 * See Windows documentation for more details on IUnknown methods.
315 static ULONG WINAPI
DefaultHandler_AddRef(
318 DefaultHandler
*This
= impl_from_IOleObject(iface
);
320 return IUnknown_AddRef(This
->outerUnknown
);
323 /************************************************************************
324 * DefaultHandler_Release (IUnknown)
326 * See Windows documentation for more details on IUnknown methods.
328 static ULONG WINAPI
DefaultHandler_Release(
331 DefaultHandler
*This
= impl_from_IOleObject(iface
);
333 return IUnknown_Release(This
->outerUnknown
);
336 /************************************************************************
337 * DefaultHandler_SetClientSite (IOleObject)
339 * The default handler's implementation of this method only keeps the
340 * client site pointer for future reference.
342 * See Windows documentation for more details on IOleObject methods.
344 static HRESULT WINAPI
DefaultHandler_SetClientSite(
346 IOleClientSite
* pClientSite
)
348 DefaultHandler
*This
= impl_from_IOleObject(iface
);
351 TRACE("(%p, %p)\n", iface
, pClientSite
);
353 if (object_is_running(This
))
354 hr
= IOleObject_SetClientSite(This
->pOleDelegate
, pClientSite
);
357 * Make sure we release the previous client site if there
360 if (This
->clientSite
)
361 IOleClientSite_Release(This
->clientSite
);
363 This
->clientSite
= pClientSite
;
365 if (This
->clientSite
)
366 IOleClientSite_AddRef(This
->clientSite
);
371 /************************************************************************
372 * DefaultHandler_GetClientSite (IOleObject)
374 * The default handler's implementation of this method returns the
375 * last pointer set in IOleObject_SetClientSite.
377 * See Windows documentation for more details on IOleObject methods.
379 static HRESULT WINAPI
DefaultHandler_GetClientSite(
381 IOleClientSite
** ppClientSite
)
383 DefaultHandler
*This
= impl_from_IOleObject(iface
);
388 *ppClientSite
= This
->clientSite
;
390 if (This
->clientSite
)
391 IOleClientSite_AddRef(This
->clientSite
);
396 /************************************************************************
397 * DefaultHandler_SetHostNames (IOleObject)
399 * The default handler's implementation of this method just stores
400 * the strings and returns S_OK.
402 * See Windows documentation for more details on IOleObject methods.
404 static HRESULT WINAPI
DefaultHandler_SetHostNames(
406 LPCOLESTR szContainerApp
,
407 LPCOLESTR szContainerObj
)
409 DefaultHandler
*This
= impl_from_IOleObject(iface
);
411 TRACE("(%p, %s, %s)\n",
413 debugstr_w(szContainerApp
),
414 debugstr_w(szContainerObj
));
416 if (object_is_running(This
))
417 IOleObject_SetHostNames(This
->pOleDelegate
, szContainerApp
, szContainerObj
);
419 /* Be sure to cleanup before re-assigning the strings. */
420 HeapFree( GetProcessHeap(), 0, This
->containerApp
);
421 This
->containerApp
= NULL
;
422 HeapFree( GetProcessHeap(), 0, This
->containerObj
);
423 This
->containerObj
= NULL
;
427 if ((This
->containerApp
= HeapAlloc( GetProcessHeap(), 0,
428 (lstrlenW(szContainerApp
) + 1) * sizeof(WCHAR
) )))
429 strcpyW( This
->containerApp
, szContainerApp
);
434 if ((This
->containerObj
= HeapAlloc( GetProcessHeap(), 0,
435 (lstrlenW(szContainerObj
) + 1) * sizeof(WCHAR
) )))
436 strcpyW( This
->containerObj
, szContainerObj
);
441 static void release_delegates(DefaultHandler
*This
)
443 if (This
->pDataDelegate
)
445 IDataObject_Release(This
->pDataDelegate
);
446 This
->pDataDelegate
= NULL
;
448 if (This
->pPSDelegate
)
450 IPersistStorage_Release(This
->pPSDelegate
);
451 This
->pPSDelegate
= NULL
;
453 if (This
->pOleDelegate
)
455 IOleObject_Release(This
->pOleDelegate
);
456 This
->pOleDelegate
= NULL
;
460 /* undoes the work done by DefaultHandler_Run */
461 static void DefaultHandler_Stop(DefaultHandler
*This
)
463 if (!object_is_running(This
))
466 IOleObject_Unadvise(This
->pOleDelegate
, This
->dwAdvConn
);
468 /* FIXME: call IOleCache_OnStop */
470 if (This
->dataAdviseHolder
)
471 DataAdviseHolder_OnDisconnect(This
->dataAdviseHolder
);
473 This
->object_state
= object_state_not_running
;
476 /************************************************************************
477 * DefaultHandler_Close (IOleObject)
479 * The default handler's implementation of this method is meaningless
480 * without a running server so it does nothing.
482 * See Windows documentation for more details on IOleObject methods.
484 static HRESULT WINAPI
DefaultHandler_Close(
488 DefaultHandler
*This
= impl_from_IOleObject(iface
);
491 TRACE("(%d)\n", dwSaveOption
);
493 if (!object_is_running(This
))
496 hr
= IOleObject_Close(This
->pOleDelegate
, dwSaveOption
);
498 DefaultHandler_Stop(This
);
499 release_delegates(This
);
504 /************************************************************************
505 * DefaultHandler_SetMoniker (IOleObject)
507 * The default handler's implementation of this method does nothing.
509 * See Windows documentation for more details on IOleObject methods.
511 static HRESULT WINAPI
DefaultHandler_SetMoniker(
513 DWORD dwWhichMoniker
,
516 DefaultHandler
*This
= impl_from_IOleObject(iface
);
518 TRACE("(%p, %d, %p)\n",
523 if (object_is_running(This
))
524 return IOleObject_SetMoniker(This
->pOleDelegate
, dwWhichMoniker
, pmk
);
529 /************************************************************************
530 * DefaultHandler_GetMoniker (IOleObject)
532 * Delegate this request to the client site if we have one.
534 * See Windows documentation for more details on IOleObject methods.
536 static HRESULT WINAPI
DefaultHandler_GetMoniker(
539 DWORD dwWhichMoniker
,
542 DefaultHandler
*This
= impl_from_IOleObject(iface
);
544 TRACE("(%p, %d, %d, %p)\n",
545 iface
, dwAssign
, dwWhichMoniker
, ppmk
);
547 if (object_is_running(This
))
548 return IOleObject_GetMoniker(This
->pOleDelegate
, dwAssign
, dwWhichMoniker
,
551 /* FIXME: dwWhichMoniker == OLEWHICHMK_CONTAINER only? */
552 if (This
->clientSite
)
554 return IOleClientSite_GetMoniker(This
->clientSite
,
564 /************************************************************************
565 * DefaultHandler_InitFromData (IOleObject)
567 * This method is meaningless if the server is not running
569 * See Windows documentation for more details on IOleObject methods.
571 static HRESULT WINAPI
DefaultHandler_InitFromData(
573 IDataObject
* pDataObject
,
577 DefaultHandler
*This
= impl_from_IOleObject(iface
);
579 TRACE("(%p, %p, %d, %d)\n",
580 iface
, pDataObject
, fCreation
, dwReserved
);
582 if (object_is_running(This
))
583 return IOleObject_InitFromData(This
->pOleDelegate
, pDataObject
, fCreation
,
585 return OLE_E_NOTRUNNING
;
588 /************************************************************************
589 * DefaultHandler_GetClipboardData (IOleObject)
591 * This method is meaningless if the server is not running
593 * See Windows documentation for more details on IOleObject methods.
595 static HRESULT WINAPI
DefaultHandler_GetClipboardData(
598 IDataObject
** ppDataObject
)
600 DefaultHandler
*This
= impl_from_IOleObject(iface
);
602 TRACE("(%p, %d, %p)\n",
603 iface
, dwReserved
, ppDataObject
);
605 if (object_is_running(This
))
606 return IOleObject_GetClipboardData(This
->pOleDelegate
, dwReserved
,
609 return OLE_E_NOTRUNNING
;
612 static HRESULT WINAPI
DefaultHandler_DoVerb(
615 struct tagMSG
* lpmsg
,
616 IOleClientSite
* pActiveSite
,
621 DefaultHandler
*This
= impl_from_IOleObject(iface
);
622 IRunnableObject
*pRunnableObj
= (IRunnableObject
*)&This
->lpvtblIRunnableObject
;
625 TRACE("(%d, %p, %p, %d, %p, %s)\n", iVerb
, lpmsg
, pActiveSite
, lindex
, hwndParent
, wine_dbgstr_rect(lprcPosRect
));
627 hr
= IRunnableObject_Run(pRunnableObj
, NULL
);
628 if (FAILED(hr
)) return hr
;
630 return IOleObject_DoVerb(This
->pOleDelegate
, iVerb
, lpmsg
, pActiveSite
,
631 lindex
, hwndParent
, lprcPosRect
);
634 /************************************************************************
635 * DefaultHandler_EnumVerbs (IOleObject)
637 * The default handler implementation of this method simply delegates
640 * See Windows documentation for more details on IOleObject methods.
642 static HRESULT WINAPI
DefaultHandler_EnumVerbs(
644 IEnumOLEVERB
** ppEnumOleVerb
)
646 DefaultHandler
*This
= impl_from_IOleObject(iface
);
647 HRESULT hr
= OLE_S_USEREG
;
649 TRACE("(%p, %p)\n", iface
, ppEnumOleVerb
);
651 if (object_is_running(This
))
652 hr
= IOleObject_EnumVerbs(This
->pOleDelegate
, ppEnumOleVerb
);
654 if (hr
== OLE_S_USEREG
)
655 return OleRegEnumVerbs(&This
->clsid
, ppEnumOleVerb
);
660 static HRESULT WINAPI
DefaultHandler_Update(
663 DefaultHandler
*This
= impl_from_IOleObject(iface
);
664 TRACE("(%p)\n", iface
);
666 if (!object_is_running(This
))
668 FIXME("Should run object\n");
671 return IOleObject_Update(This
->pOleDelegate
);
674 /************************************************************************
675 * DefaultHandler_IsUpToDate (IOleObject)
677 * This method is meaningless if the server is not running
679 * See Windows documentation for more details on IOleObject methods.
681 static HRESULT WINAPI
DefaultHandler_IsUpToDate(
684 DefaultHandler
*This
= impl_from_IOleObject(iface
);
685 TRACE("(%p)\n", iface
);
687 if (object_is_running(This
))
688 return IOleObject_IsUpToDate(This
->pOleDelegate
);
690 return OLE_E_NOTRUNNING
;
693 /************************************************************************
694 * DefaultHandler_GetUserClassID (IOleObject)
696 * TODO: Map to a new class ID if emulation is active.
698 * See Windows documentation for more details on IOleObject methods.
700 static HRESULT WINAPI
DefaultHandler_GetUserClassID(
704 DefaultHandler
*This
= impl_from_IOleObject(iface
);
706 TRACE("(%p, %p)\n", iface
, pClsid
);
708 if (object_is_running(This
))
709 return IOleObject_GetUserClassID(This
->pOleDelegate
, pClsid
);
714 *pClsid
= This
->clsid
;
719 /************************************************************************
720 * DefaultHandler_GetUserType (IOleObject)
722 * The default handler implementation of this method simply delegates
723 * to OleRegGetUserType
725 * See Windows documentation for more details on IOleObject methods.
727 static HRESULT WINAPI
DefaultHandler_GetUserType(
730 LPOLESTR
* pszUserType
)
732 DefaultHandler
*This
= impl_from_IOleObject(iface
);
734 TRACE("(%p, %d, %p)\n", iface
, dwFormOfType
, pszUserType
);
735 if (object_is_running(This
))
736 return IOleObject_GetUserType(This
->pOleDelegate
, dwFormOfType
, pszUserType
);
738 return OleRegGetUserType(&This
->clsid
, dwFormOfType
, pszUserType
);
741 /************************************************************************
742 * DefaultHandler_SetExtent (IOleObject)
744 * This method is meaningless if the server is not running
746 * See Windows documentation for more details on IOleObject methods.
748 static HRESULT WINAPI
DefaultHandler_SetExtent(
753 DefaultHandler
*This
= impl_from_IOleObject(iface
);
755 TRACE("(%p, %x, (%d x %d))\n", iface
,
756 dwDrawAspect
, psizel
->cx
, psizel
->cy
);
758 if (object_is_running(This
))
759 return IOleObject_SetExtent(This
->pOleDelegate
, dwDrawAspect
, psizel
);
761 return OLE_E_NOTRUNNING
;
764 /************************************************************************
765 * DefaultHandler_GetExtent (IOleObject)
767 * The default handler's implementation of this method returns uses
768 * the cache to locate the aspect and extract the extent from it.
770 * See Windows documentation for more details on IOleObject methods.
772 static HRESULT WINAPI
DefaultHandler_GetExtent(
777 DVTARGETDEVICE
* targetDevice
;
778 IViewObject2
* cacheView
= NULL
;
781 DefaultHandler
*This
= impl_from_IOleObject(iface
);
783 TRACE("(%p, %x, %p)\n", iface
, dwDrawAspect
, psizel
);
785 if (object_is_running(This
))
786 return IOleObject_GetExtent(This
->pOleDelegate
, dwDrawAspect
, psizel
);
788 hres
= IUnknown_QueryInterface(This
->dataCache
, &IID_IViewObject2
, (void**)&cacheView
);
793 * Prepare the call to the cache's GetExtent method.
795 * Here we would build a valid DVTARGETDEVICE structure
796 * but, since we are calling into the data cache, we
797 * know its implementation and we'll skip this
798 * extra work until later.
802 hres
= IViewObject2_GetExtent(cacheView
,
808 IViewObject2_Release(cacheView
);
813 /************************************************************************
814 * DefaultHandler_Advise (IOleObject)
816 * The default handler's implementation of this method simply
817 * delegates to the OleAdviseHolder.
819 * See Windows documentation for more details on IOleObject methods.
821 static HRESULT WINAPI
DefaultHandler_Advise(
823 IAdviseSink
* pAdvSink
,
824 DWORD
* pdwConnection
)
827 DefaultHandler
*This
= impl_from_IOleObject(iface
);
829 TRACE("(%p, %p, %p)\n", iface
, pAdvSink
, pdwConnection
);
831 /* Make sure we have an advise holder before we start. */
832 if (!This
->oleAdviseHolder
)
833 hres
= CreateOleAdviseHolder(&This
->oleAdviseHolder
);
836 hres
= IOleAdviseHolder_Advise(This
->oleAdviseHolder
,
843 /************************************************************************
844 * DefaultHandler_Unadvise (IOleObject)
846 * The default handler's implementation of this method simply
847 * delegates to the OleAdviseHolder.
849 * See Windows documentation for more details on IOleObject methods.
851 static HRESULT WINAPI
DefaultHandler_Unadvise(
855 DefaultHandler
*This
= impl_from_IOleObject(iface
);
857 TRACE("(%p, %d)\n", iface
, dwConnection
);
860 * If we don't have an advise holder yet, it means we don't have
863 if (!This
->oleAdviseHolder
)
864 return OLE_E_NOCONNECTION
;
866 return IOleAdviseHolder_Unadvise(This
->oleAdviseHolder
,
870 /************************************************************************
871 * DefaultHandler_EnumAdvise (IOleObject)
873 * The default handler's implementation of this method simply
874 * delegates to the OleAdviseHolder.
876 * See Windows documentation for more details on IOleObject methods.
878 static HRESULT WINAPI
DefaultHandler_EnumAdvise(
880 IEnumSTATDATA
** ppenumAdvise
)
882 DefaultHandler
*This
= impl_from_IOleObject(iface
);
884 TRACE("(%p, %p)\n", iface
, ppenumAdvise
);
889 *ppenumAdvise
= NULL
;
891 if (!This
->oleAdviseHolder
)
894 return IOleAdviseHolder_EnumAdvise(This
->oleAdviseHolder
, ppenumAdvise
);
897 /************************************************************************
898 * DefaultHandler_GetMiscStatus (IOleObject)
900 * The default handler's implementation of this method simply delegates
901 * to OleRegGetMiscStatus.
903 * See Windows documentation for more details on IOleObject methods.
905 static HRESULT WINAPI
DefaultHandler_GetMiscStatus(
911 DefaultHandler
*This
= impl_from_IOleObject(iface
);
913 TRACE("(%p, %x, %p)\n", iface
, dwAspect
, pdwStatus
);
915 if (object_is_running(This
))
916 return IOleObject_GetMiscStatus(This
->pOleDelegate
, dwAspect
, pdwStatus
);
918 hres
= OleRegGetMiscStatus(&This
->clsid
, dwAspect
, pdwStatus
);
926 /************************************************************************
927 * DefaultHandler_SetColorScheme (IOleObject)
929 * This method is meaningless if the server is not running
931 * See Windows documentation for more details on IOleObject methods.
933 static HRESULT WINAPI
DefaultHandler_SetColorScheme(
935 struct tagLOGPALETTE
* pLogpal
)
937 DefaultHandler
*This
= impl_from_IOleObject(iface
);
939 TRACE("(%p, %p))\n", iface
, pLogpal
);
941 if (object_is_running(This
))
942 return IOleObject_SetColorScheme(This
->pOleDelegate
, pLogpal
);
944 return OLE_E_NOTRUNNING
;
947 /*********************************************************
948 * Methods implementation for the IDataObject part of
949 * the DefaultHandler class.
952 /************************************************************************
953 * DefaultHandler_IDataObject_QueryInterface (IUnknown)
955 * See Windows documentation for more details on IUnknown methods.
957 static HRESULT WINAPI
DefaultHandler_IDataObject_QueryInterface(
962 DefaultHandler
*This
= impl_from_IDataObject(iface
);
964 return IUnknown_QueryInterface(This
->outerUnknown
, riid
, ppvObject
);
967 /************************************************************************
968 * DefaultHandler_IDataObject_AddRef (IUnknown)
970 * See Windows documentation for more details on IUnknown methods.
972 static ULONG WINAPI
DefaultHandler_IDataObject_AddRef(
975 DefaultHandler
*This
= impl_from_IDataObject(iface
);
977 return IUnknown_AddRef(This
->outerUnknown
);
980 /************************************************************************
981 * DefaultHandler_IDataObject_Release (IUnknown)
983 * See Windows documentation for more details on IUnknown methods.
985 static ULONG WINAPI
DefaultHandler_IDataObject_Release(
988 DefaultHandler
*This
= impl_from_IDataObject(iface
);
990 return IUnknown_Release(This
->outerUnknown
);
993 /************************************************************************
994 * DefaultHandler_GetData
996 * Get Data from a source dataobject using format pformatetcIn->cfFormat
997 * See Windows documentation for more details on GetData.
998 * Default handler's implementation of this method delegates to the cache.
1000 static HRESULT WINAPI
DefaultHandler_GetData(
1002 LPFORMATETC pformatetcIn
,
1005 IDataObject
* cacheDataObject
= NULL
;
1008 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1010 TRACE("(%p, %p, %p)\n", iface
, pformatetcIn
, pmedium
);
1012 hres
= IUnknown_QueryInterface(This
->dataCache
,
1014 (void**)&cacheDataObject
);
1017 return E_UNEXPECTED
;
1019 hres
= IDataObject_GetData(cacheDataObject
,
1023 IDataObject_Release(cacheDataObject
);
1025 if (FAILED(hres
) && This
->pDataDelegate
)
1026 hres
= IDataObject_GetData(This
->pDataDelegate
, pformatetcIn
, pmedium
);
1031 static HRESULT WINAPI
DefaultHandler_GetDataHere(
1033 LPFORMATETC pformatetc
,
1040 /************************************************************************
1041 * DefaultHandler_QueryGetData (IDataObject)
1043 * The default handler's implementation of this method delegates to
1046 * See Windows documentation for more details on IDataObject methods.
1048 static HRESULT WINAPI
DefaultHandler_QueryGetData(
1050 LPFORMATETC pformatetc
)
1052 IDataObject
* cacheDataObject
= NULL
;
1055 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1057 TRACE("(%p, %p)\n", iface
, pformatetc
);
1059 hres
= IUnknown_QueryInterface(This
->dataCache
,
1061 (void**)&cacheDataObject
);
1064 return E_UNEXPECTED
;
1066 hres
= IDataObject_QueryGetData(cacheDataObject
,
1069 IDataObject_Release(cacheDataObject
);
1071 if (FAILED(hres
) && This
->pDataDelegate
)
1072 hres
= IDataObject_QueryGetData(This
->pDataDelegate
, pformatetc
);
1077 /************************************************************************
1078 * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
1080 * This method is meaningless if the server is not running
1082 * See Windows documentation for more details on IDataObject methods.
1084 static HRESULT WINAPI
DefaultHandler_GetCanonicalFormatEtc(
1086 LPFORMATETC pformatetcIn
,
1087 LPFORMATETC pformatetcOut
)
1089 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1091 TRACE("(%p, %p, %p)\n", iface
, pformatetcIn
, pformatetcOut
);
1093 if (!This
->pDataDelegate
)
1094 return OLE_E_NOTRUNNING
;
1096 return IDataObject_GetCanonicalFormatEtc(This
->pDataDelegate
, pformatetcIn
, pformatetcOut
);
1099 /************************************************************************
1100 * DefaultHandler_SetData (IDataObject)
1102 * The default handler's implementation of this method delegates to
1105 * See Windows documentation for more details on IDataObject methods.
1107 static HRESULT WINAPI
DefaultHandler_SetData(
1109 LPFORMATETC pformatetc
,
1113 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1114 IDataObject
* cacheDataObject
= NULL
;
1117 TRACE("(%p, %p, %p, %d)\n", iface
, pformatetc
, pmedium
, fRelease
);
1119 hres
= IUnknown_QueryInterface(This
->dataCache
,
1121 (void**)&cacheDataObject
);
1124 return E_UNEXPECTED
;
1126 hres
= IDataObject_SetData(cacheDataObject
,
1131 IDataObject_Release(cacheDataObject
);
1136 /************************************************************************
1137 * DefaultHandler_EnumFormatEtc (IDataObject)
1139 * The default handler's implementation of This method simply delegates
1140 * to OleRegEnumFormatEtc.
1142 * See Windows documentation for more details on IDataObject methods.
1144 static HRESULT WINAPI
DefaultHandler_EnumFormatEtc(
1147 IEnumFORMATETC
** ppenumFormatEtc
)
1149 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1151 TRACE("(%p, %x, %p)\n", iface
, dwDirection
, ppenumFormatEtc
);
1153 return OleRegEnumFormatEtc(&This
->clsid
, dwDirection
, ppenumFormatEtc
);
1156 /************************************************************************
1157 * DefaultHandler_DAdvise (IDataObject)
1159 * The default handler's implementation of this method simply
1160 * delegates to the DataAdviseHolder.
1162 * See Windows documentation for more details on IDataObject methods.
1164 static HRESULT WINAPI
DefaultHandler_DAdvise(
1166 FORMATETC
* pformatetc
,
1168 IAdviseSink
* pAdvSink
,
1169 DWORD
* pdwConnection
)
1171 HRESULT hres
= S_OK
;
1172 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1174 TRACE("(%p, %p, %d, %p, %p)\n",
1175 iface
, pformatetc
, advf
, pAdvSink
, pdwConnection
);
1177 /* Make sure we have a data advise holder before we start. */
1178 if (!This
->dataAdviseHolder
)
1180 hres
= CreateDataAdviseHolder(&This
->dataAdviseHolder
);
1181 if (SUCCEEDED(hres
) && This
->pDataDelegate
)
1182 DataAdviseHolder_OnConnect(This
->dataAdviseHolder
, This
->pDataDelegate
);
1185 if (SUCCEEDED(hres
))
1186 hres
= IDataAdviseHolder_Advise(This
->dataAdviseHolder
,
1196 /************************************************************************
1197 * DefaultHandler_DUnadvise (IDataObject)
1199 * The default handler's implementation of this method simply
1200 * delegates to the DataAdviseHolder.
1202 * See Windows documentation for more details on IDataObject methods.
1204 static HRESULT WINAPI
DefaultHandler_DUnadvise(
1208 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1210 TRACE("(%p, %d)\n", iface
, dwConnection
);
1213 * If we don't have a data advise holder yet, it means that
1214 * we don't have any connections..
1216 if (!This
->dataAdviseHolder
)
1217 return OLE_E_NOCONNECTION
;
1219 return IDataAdviseHolder_Unadvise(This
->dataAdviseHolder
,
1223 /************************************************************************
1224 * DefaultHandler_EnumDAdvise (IDataObject)
1226 * The default handler's implementation of this method simply
1227 * delegates to the DataAdviseHolder.
1229 * See Windows documentation for more details on IDataObject methods.
1231 static HRESULT WINAPI
DefaultHandler_EnumDAdvise(
1233 IEnumSTATDATA
** ppenumAdvise
)
1235 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1237 TRACE("(%p, %p)\n", iface
, ppenumAdvise
);
1242 *ppenumAdvise
= NULL
;
1244 /* If we have a data advise holder object, delegate. */
1245 if (This
->dataAdviseHolder
)
1246 return IDataAdviseHolder_EnumAdvise(This
->dataAdviseHolder
,
1252 /*********************************************************
1253 * Methods implementation for the IRunnableObject part
1254 * of the DefaultHandler class.
1257 /************************************************************************
1258 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1260 * See Windows documentation for more details on IUnknown methods.
1262 static HRESULT WINAPI
DefaultHandler_IRunnableObject_QueryInterface(
1263 IRunnableObject
* iface
,
1267 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1269 return IUnknown_QueryInterface(This
->outerUnknown
, riid
, ppvObject
);
1272 /************************************************************************
1273 * DefaultHandler_IRunnableObject_AddRef (IUnknown)
1275 * See Windows documentation for more details on IUnknown methods.
1277 static ULONG WINAPI
DefaultHandler_IRunnableObject_AddRef(
1278 IRunnableObject
* iface
)
1280 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1282 return IUnknown_AddRef(This
->outerUnknown
);
1285 /************************************************************************
1286 * DefaultHandler_IRunnableObject_Release (IUnknown)
1288 * See Windows documentation for more details on IUnknown methods.
1290 static ULONG WINAPI
DefaultHandler_IRunnableObject_Release(
1291 IRunnableObject
* iface
)
1293 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1295 return IUnknown_Release(This
->outerUnknown
);
1298 /************************************************************************
1299 * DefaultHandler_GetRunningClass (IRunnableObject)
1301 * See Windows documentation for more details on IRunnableObject methods.
1303 static HRESULT WINAPI
DefaultHandler_GetRunningClass(
1304 IRunnableObject
* iface
,
1311 static HRESULT WINAPI
DefaultHandler_Run(
1312 IRunnableObject
* iface
,
1315 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1318 FIXME("(%p): semi-stub\n", pbc
);
1320 /* already running? if so nothing to do */
1321 if (object_is_running(This
))
1324 release_delegates(This
);
1326 hr
= CoCreateInstance(&This
->clsid
, NULL
, CLSCTX_LOCAL_SERVER
,
1327 &IID_IOleObject
, (void **)&This
->pOleDelegate
);
1331 This
->object_state
= object_state_running
;
1333 hr
= IOleObject_Advise(This
->pOleDelegate
,
1334 (IAdviseSink
*)&This
->lpvtblIAdviseSink
,
1337 if (SUCCEEDED(hr
) && This
->clientSite
)
1338 hr
= IOleObject_SetClientSite(This
->pOleDelegate
, This
->clientSite
);
1342 IOleObject_QueryInterface(This
->pOleDelegate
, &IID_IPersistStorage
,
1343 (void **)&This
->pPSDelegate
);
1344 if (This
->pPSDelegate
)
1346 if(This
->storage_state
== storage_state_initialised
)
1347 hr
= IPersistStorage_InitNew(This
->pPSDelegate
, This
->storage
);
1348 else if(This
->storage_state
== storage_state_loaded
)
1349 hr
= IPersistStorage_Load(This
->pPSDelegate
, This
->storage
);
1353 if (SUCCEEDED(hr
) && This
->containerApp
)
1354 hr
= IOleObject_SetHostNames(This
->pOleDelegate
, This
->containerApp
,
1355 This
->containerObj
);
1357 /* FIXME: do more stuff here:
1358 * - IOleObject_GetMiscStatus
1359 * - IOleObject_GetMoniker
1364 hr
= IOleObject_QueryInterface(This
->pOleDelegate
, &IID_IDataObject
,
1365 (void **)&This
->pDataDelegate
);
1367 if (SUCCEEDED(hr
) && This
->dataAdviseHolder
)
1368 hr
= DataAdviseHolder_OnConnect(This
->dataAdviseHolder
, This
->pDataDelegate
);
1372 DefaultHandler_Stop(This
);
1373 release_delegates(This
);
1379 /************************************************************************
1380 * DefaultHandler_IsRunning (IRunnableObject)
1382 * See Windows documentation for more details on IRunnableObject methods.
1384 static BOOL WINAPI
DefaultHandler_IsRunning(
1385 IRunnableObject
* iface
)
1387 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1391 if (This
->object_state
== object_state_running
)
1397 /************************************************************************
1398 * DefaultHandler_LockRunning (IRunnableObject)
1400 * See Windows documentation for more details on IRunnableObject methods.
1402 static HRESULT WINAPI
DefaultHandler_LockRunning(
1403 IRunnableObject
* iface
,
1405 BOOL fLastUnlockCloses
)
1411 /************************************************************************
1412 * DefaultHandler_SetContainedObject (IRunnableObject)
1414 * See Windows documentation for more details on IRunnableObject methods.
1416 static HRESULT WINAPI
DefaultHandler_SetContainedObject(
1417 IRunnableObject
* iface
,
1424 static HRESULT WINAPI
DefaultHandler_IAdviseSink_QueryInterface(
1429 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1430 IsEqualIID(riid
, &IID_IAdviseSink
))
1433 IAdviseSink_AddRef(iface
);
1437 return E_NOINTERFACE
;
1440 static ULONG WINAPI
DefaultHandler_IAdviseSink_AddRef(
1443 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1445 return IUnknown_AddRef((IUnknown
*)&This
->lpvtblIUnknown
);
1448 static ULONG WINAPI
DefaultHandler_IAdviseSink_Release(
1451 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1453 return IUnknown_Release((IUnknown
*)&This
->lpvtblIUnknown
);
1456 static void WINAPI
DefaultHandler_IAdviseSink_OnDataChange(
1458 FORMATETC
*pFormatetc
,
1464 static void WINAPI
DefaultHandler_IAdviseSink_OnViewChange(
1472 static void WINAPI
DefaultHandler_IAdviseSink_OnRename(
1476 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1478 TRACE("(%p)\n", pmk
);
1480 if (This
->oleAdviseHolder
)
1481 IOleAdviseHolder_SendOnRename(This
->oleAdviseHolder
, pmk
);
1484 static void WINAPI
DefaultHandler_IAdviseSink_OnSave(
1487 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1491 if (This
->oleAdviseHolder
)
1492 IOleAdviseHolder_SendOnSave(This
->oleAdviseHolder
);
1495 static void WINAPI
DefaultHandler_IAdviseSink_OnClose(
1498 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1502 if (This
->oleAdviseHolder
)
1503 IOleAdviseHolder_SendOnClose(This
->oleAdviseHolder
);
1505 DefaultHandler_Stop(This
);
1509 /************************************************************************
1510 * DefaultHandler_IPersistStorage_QueryInterface
1513 static HRESULT WINAPI
DefaultHandler_IPersistStorage_QueryInterface(
1514 IPersistStorage
* iface
,
1518 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1520 return IUnknown_QueryInterface(This
->outerUnknown
, riid
, ppvObject
);
1523 /************************************************************************
1524 * DefaultHandler_IPersistStorage_AddRef
1527 static ULONG WINAPI
DefaultHandler_IPersistStorage_AddRef(
1528 IPersistStorage
* iface
)
1530 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1532 return IUnknown_AddRef(This
->outerUnknown
);
1535 /************************************************************************
1536 * DefaultHandler_IPersistStorage_Release
1539 static ULONG WINAPI
DefaultHandler_IPersistStorage_Release(
1540 IPersistStorage
* iface
)
1542 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1544 return IUnknown_Release(This
->outerUnknown
);
1547 /************************************************************************
1548 * DefaultHandler_IPersistStorage_GetClassID
1551 static HRESULT WINAPI
DefaultHandler_IPersistStorage_GetClassID(
1552 IPersistStorage
* iface
,
1555 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1558 TRACE("(%p)->(%p)\n", iface
, clsid
);
1560 if(object_is_running(This
))
1561 hr
= IPersistStorage_GetClassID(This
->pPSDelegate
, clsid
);
1563 hr
= IPersistStorage_GetClassID(This
->dataCache_PersistStg
, clsid
);
1568 /************************************************************************
1569 * DefaultHandler_IPersistStorage_IsDirty
1572 static HRESULT WINAPI
DefaultHandler_IPersistStorage_IsDirty(
1573 IPersistStorage
* iface
)
1575 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1578 TRACE("(%p)\n", iface
);
1580 hr
= IPersistStorage_IsDirty(This
->dataCache_PersistStg
);
1581 if(hr
!= S_FALSE
) return hr
;
1583 if(object_is_running(This
))
1584 hr
= IPersistStorage_IsDirty(This
->pPSDelegate
);
1589 /***********************************************************************
1592 * Creates the '\1Ole' stream.
1593 * The format of this stream is as follows:
1595 * DWORD Version == 0x02000001
1596 * DWORD Flags - low bit set indicates the object is a link otherwise it's embedded.
1597 * DWORD LinkupdateOption - [MS-OLEDS describes this as an implementation specific hint
1598 * supplied by the app that creates the data structure. May be
1599 * ignored on processing].
1601 * DWORD Reserved == 0
1602 * DWORD MonikerStreamSize - size of the rest of the data (ie CLSID + moniker stream data).
1603 * CLSID clsid - class id of object capable of processing the moniker
1604 * BYTE data[] - moniker data for a link
1607 static const WCHAR OleStream
[] = {1,'O','l','e',0};
1612 DWORD link_update_opt
;
1615 } ole_stream_header_t
;
1616 static const DWORD ole_stream_version
= 0x02000001;
1618 static void init_ole_stream(IStorage
*storage
)
1623 hr
= IStorage_CreateStream(storage
, OleStream
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stream
);
1627 ole_stream_header_t header
;
1629 header
.version
= ole_stream_version
;
1631 header
.link_update_opt
= 0;
1633 header
.moniker_size
= 0;
1635 IStream_Write(stream
, &header
, sizeof(header
), &written
);
1636 IStream_Release(stream
);
1641 static HRESULT
load_ole_stream(DefaultHandler
*This
, IStorage
*storage
)
1646 hr
= IStorage_OpenStream(storage
, OleStream
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stream
);
1651 ole_stream_header_t header
;
1653 hr
= IStream_Read(stream
, &header
, sizeof(header
), &read
);
1654 if(hr
== S_OK
&& read
== sizeof(header
) && header
.version
== ole_stream_version
)
1656 if(header
.flags
& 1)
1658 /* FIXME: Read the moniker and deal with the link */
1659 FIXME("Linked objects are not supported yet\n");
1664 WARN("Incorrect OleStream header\n");
1665 hr
= DV_E_CLIPFORMAT
;
1667 IStream_Release(stream
);
1671 init_ole_stream(storage
);
1677 /************************************************************************
1678 * DefaultHandler_IPersistStorage_InitNew
1681 static HRESULT WINAPI
DefaultHandler_IPersistStorage_InitNew(
1682 IPersistStorage
* iface
,
1685 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1688 TRACE("(%p)->(%p)\n", iface
, pStg
);
1689 init_ole_stream(pStg
);
1691 hr
= IPersistStorage_InitNew(This
->dataCache_PersistStg
, pStg
);
1693 if(SUCCEEDED(hr
) && object_is_running(This
))
1694 hr
= IPersistStorage_InitNew(This
->pPSDelegate
, pStg
);
1698 IStorage_AddRef(pStg
);
1699 This
->storage
= pStg
;
1700 This
->storage_state
= storage_state_initialised
;
1707 /************************************************************************
1708 * DefaultHandler_IPersistStorage_Load
1711 static HRESULT WINAPI
DefaultHandler_IPersistStorage_Load(
1712 IPersistStorage
* iface
,
1715 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1718 TRACE("(%p)->(%p)\n", iface
, pStg
);
1720 hr
= load_ole_stream(This
, pStg
);
1723 hr
= IPersistStorage_Load(This
->dataCache_PersistStg
, pStg
);
1725 if(SUCCEEDED(hr
) && object_is_running(This
))
1726 hr
= IPersistStorage_Load(This
->pPSDelegate
, pStg
);
1730 IStorage_AddRef(pStg
);
1731 This
->storage
= pStg
;
1732 This
->storage_state
= storage_state_loaded
;
1738 /************************************************************************
1739 * DefaultHandler_IPersistStorage_Save
1742 static HRESULT WINAPI
DefaultHandler_IPersistStorage_Save(
1743 IPersistStorage
* iface
,
1747 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1750 TRACE("(%p)->(%p, %d)\n", iface
, pStgSave
, fSameAsLoad
);
1752 hr
= IPersistStorage_Save(This
->dataCache_PersistStg
, pStgSave
, fSameAsLoad
);
1753 if(SUCCEEDED(hr
) && object_is_running(This
))
1754 hr
= IPersistStorage_Save(This
->pPSDelegate
, pStgSave
, fSameAsLoad
);
1760 /************************************************************************
1761 * DefaultHandler_IPersistStorage_SaveCompleted
1764 static HRESULT WINAPI
DefaultHandler_IPersistStorage_SaveCompleted(
1765 IPersistStorage
* iface
,
1768 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1771 TRACE("(%p)->(%p)\n", iface
, pStgNew
);
1773 hr
= IPersistStorage_SaveCompleted(This
->dataCache_PersistStg
, pStgNew
);
1775 if(SUCCEEDED(hr
) && object_is_running(This
))
1776 hr
= IPersistStorage_SaveCompleted(This
->pPSDelegate
, pStgNew
);
1780 IStorage_AddRef(pStgNew
);
1781 if(This
->storage
) IStorage_Release(This
->storage
);
1782 This
->storage
= pStgNew
;
1783 This
->storage_state
= storage_state_loaded
;
1790 /************************************************************************
1791 * DefaultHandler_IPersistStorage_HandsOffStorage
1794 static HRESULT WINAPI
DefaultHandler_IPersistStorage_HandsOffStorage(
1795 IPersistStorage
* iface
)
1797 DefaultHandler
*This
= impl_from_IPersistStorage(iface
);
1800 TRACE("(%p)\n", iface
);
1802 hr
= IPersistStorage_HandsOffStorage(This
->dataCache_PersistStg
);
1804 if(SUCCEEDED(hr
) && object_is_running(This
))
1805 hr
= IPersistStorage_HandsOffStorage(This
->pPSDelegate
);
1807 if(This
->storage
) IStorage_Release(This
->storage
);
1808 This
->storage
= NULL
;
1809 This
->storage_state
= storage_state_uninitialised
;
1816 * Virtual function tables for the DefaultHandler class.
1818 static const IOleObjectVtbl DefaultHandler_IOleObject_VTable
=
1820 DefaultHandler_QueryInterface
,
1821 DefaultHandler_AddRef
,
1822 DefaultHandler_Release
,
1823 DefaultHandler_SetClientSite
,
1824 DefaultHandler_GetClientSite
,
1825 DefaultHandler_SetHostNames
,
1826 DefaultHandler_Close
,
1827 DefaultHandler_SetMoniker
,
1828 DefaultHandler_GetMoniker
,
1829 DefaultHandler_InitFromData
,
1830 DefaultHandler_GetClipboardData
,
1831 DefaultHandler_DoVerb
,
1832 DefaultHandler_EnumVerbs
,
1833 DefaultHandler_Update
,
1834 DefaultHandler_IsUpToDate
,
1835 DefaultHandler_GetUserClassID
,
1836 DefaultHandler_GetUserType
,
1837 DefaultHandler_SetExtent
,
1838 DefaultHandler_GetExtent
,
1839 DefaultHandler_Advise
,
1840 DefaultHandler_Unadvise
,
1841 DefaultHandler_EnumAdvise
,
1842 DefaultHandler_GetMiscStatus
,
1843 DefaultHandler_SetColorScheme
1846 static const IUnknownVtbl DefaultHandler_NDIUnknown_VTable
=
1848 DefaultHandler_NDIUnknown_QueryInterface
,
1849 DefaultHandler_NDIUnknown_AddRef
,
1850 DefaultHandler_NDIUnknown_Release
,
1853 static const IDataObjectVtbl DefaultHandler_IDataObject_VTable
=
1855 DefaultHandler_IDataObject_QueryInterface
,
1856 DefaultHandler_IDataObject_AddRef
,
1857 DefaultHandler_IDataObject_Release
,
1858 DefaultHandler_GetData
,
1859 DefaultHandler_GetDataHere
,
1860 DefaultHandler_QueryGetData
,
1861 DefaultHandler_GetCanonicalFormatEtc
,
1862 DefaultHandler_SetData
,
1863 DefaultHandler_EnumFormatEtc
,
1864 DefaultHandler_DAdvise
,
1865 DefaultHandler_DUnadvise
,
1866 DefaultHandler_EnumDAdvise
1869 static const IRunnableObjectVtbl DefaultHandler_IRunnableObject_VTable
=
1871 DefaultHandler_IRunnableObject_QueryInterface
,
1872 DefaultHandler_IRunnableObject_AddRef
,
1873 DefaultHandler_IRunnableObject_Release
,
1874 DefaultHandler_GetRunningClass
,
1876 DefaultHandler_IsRunning
,
1877 DefaultHandler_LockRunning
,
1878 DefaultHandler_SetContainedObject
1881 static const IAdviseSinkVtbl DefaultHandler_IAdviseSink_VTable
=
1883 DefaultHandler_IAdviseSink_QueryInterface
,
1884 DefaultHandler_IAdviseSink_AddRef
,
1885 DefaultHandler_IAdviseSink_Release
,
1886 DefaultHandler_IAdviseSink_OnDataChange
,
1887 DefaultHandler_IAdviseSink_OnViewChange
,
1888 DefaultHandler_IAdviseSink_OnRename
,
1889 DefaultHandler_IAdviseSink_OnSave
,
1890 DefaultHandler_IAdviseSink_OnClose
1893 static const IPersistStorageVtbl DefaultHandler_IPersistStorage_VTable
=
1895 DefaultHandler_IPersistStorage_QueryInterface
,
1896 DefaultHandler_IPersistStorage_AddRef
,
1897 DefaultHandler_IPersistStorage_Release
,
1898 DefaultHandler_IPersistStorage_GetClassID
,
1899 DefaultHandler_IPersistStorage_IsDirty
,
1900 DefaultHandler_IPersistStorage_InitNew
,
1901 DefaultHandler_IPersistStorage_Load
,
1902 DefaultHandler_IPersistStorage_Save
,
1903 DefaultHandler_IPersistStorage_SaveCompleted
,
1904 DefaultHandler_IPersistStorage_HandsOffStorage
1907 /*********************************************************
1908 * Methods implementation for the DefaultHandler class.
1910 static DefaultHandler
* DefaultHandler_Construct(
1912 LPUNKNOWN pUnkOuter
,
1916 DefaultHandler
* This
= NULL
;
1919 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler
));
1924 This
->lpVtbl
= &DefaultHandler_IOleObject_VTable
;
1925 This
->lpvtblIUnknown
= &DefaultHandler_NDIUnknown_VTable
;
1926 This
->lpvtblIDataObject
= &DefaultHandler_IDataObject_VTable
;
1927 This
->lpvtblIRunnableObject
= &DefaultHandler_IRunnableObject_VTable
;
1928 This
->lpvtblIAdviseSink
= &DefaultHandler_IAdviseSink_VTable
;
1929 This
->lpvtblIPersistStorage
= &DefaultHandler_IPersistStorage_VTable
;
1931 This
->inproc_server
= (flags
& EMBDHLP_INPROC_SERVER
) ? TRUE
: FALSE
;
1934 * Start with one reference count. The caller of this function
1935 * must release the interface pointer when it is done.
1940 * Initialize the outer unknown
1941 * We don't keep a reference on the outer unknown since, the way
1942 * aggregation works, our lifetime is at least as large as its
1946 pUnkOuter
= (IUnknown
*)&This
->lpvtblIUnknown
;
1948 This
->outerUnknown
= pUnkOuter
;
1951 * Create a datacache object.
1952 * We aggregate with the datacache. Make sure we pass our outer
1953 * unknown as the datacache's outer unknown.
1955 hr
= CreateDataCache(This
->outerUnknown
,
1958 (void**)&This
->dataCache
);
1961 hr
= IUnknown_QueryInterface(This
->dataCache
, &IID_IPersistStorage
, (void**)&This
->dataCache_PersistStg
);
1962 /* keeping a reference to This->dataCache_PersistStg causes us to keep a
1963 * reference on the outer object */
1965 IUnknown_Release(This
->outerUnknown
);
1967 IUnknown_Release(This
->dataCache
);
1971 ERR("Unexpected error creating data cache\n");
1972 HeapFree(GetProcessHeap(), 0, This
);
1976 This
->clsid
= *clsid
;
1977 This
->clientSite
= NULL
;
1978 This
->oleAdviseHolder
= NULL
;
1979 This
->dataAdviseHolder
= NULL
;
1980 This
->containerApp
= NULL
;
1981 This
->containerObj
= NULL
;
1982 This
->pOleDelegate
= NULL
;
1983 This
->pPSDelegate
= NULL
;
1984 This
->pDataDelegate
= NULL
;
1985 This
->object_state
= object_state_not_running
;
1987 This
->dwAdvConn
= 0;
1988 This
->storage
= NULL
;
1989 This
->storage_state
= storage_state_uninitialised
;
1991 if (This
->inproc_server
&& !(flags
& EMBDHLP_DELAYCREATE
))
1994 This
->pCFObject
= NULL
;
1996 hr
= IClassFactory_CreateInstance(pCF
, NULL
, &IID_IOleObject
, (void **)&This
->pOleDelegate
);
1998 hr
= CoCreateInstance(&This
->clsid
, NULL
, CLSCTX_INPROC_SERVER
,
1999 &IID_IOleObject
, (void **)&This
->pOleDelegate
);
2001 hr
= IOleObject_QueryInterface(This
->pOleDelegate
, &IID_IPersistStorage
, (void **)&This
->pPSDelegate
);
2003 hr
= IOleObject_QueryInterface(This
->pOleDelegate
, &IID_IDataObject
, (void **)&This
->pDataDelegate
);
2005 This
->object_state
= object_state_running
;
2007 WARN("object creation failed with error %08x\n", hr
);
2011 This
->pCFObject
= pCF
;
2012 if (pCF
) IClassFactory_AddRef(pCF
);
2018 static void DefaultHandler_Destroy(
2019 DefaultHandler
* This
)
2021 TRACE("(%p)\n", This
);
2023 /* AddRef/Release may be called on this object during destruction.
2024 * Prevent the object being destroyed recursively by artificially raising
2025 * the reference count. */
2028 /* release delegates */
2029 DefaultHandler_Stop(This
);
2030 release_delegates(This
);
2032 HeapFree( GetProcessHeap(), 0, This
->containerApp
);
2033 This
->containerApp
= NULL
;
2034 HeapFree( GetProcessHeap(), 0, This
->containerObj
);
2035 This
->containerObj
= NULL
;
2037 if (This
->dataCache
)
2039 /* to balance out the release of dataCache_PersistStg which will result
2040 * in a reference being released from the outer unknown */
2041 IUnknown_AddRef(This
->outerUnknown
);
2042 IPersistStorage_Release(This
->dataCache_PersistStg
);
2043 IUnknown_Release(This
->dataCache
);
2044 This
->dataCache_PersistStg
= NULL
;
2045 This
->dataCache
= NULL
;
2048 if (This
->clientSite
)
2050 IOleClientSite_Release(This
->clientSite
);
2051 This
->clientSite
= NULL
;
2054 if (This
->oleAdviseHolder
)
2056 IOleAdviseHolder_Release(This
->oleAdviseHolder
);
2057 This
->oleAdviseHolder
= NULL
;
2060 if (This
->dataAdviseHolder
)
2062 IDataAdviseHolder_Release(This
->dataAdviseHolder
);
2063 This
->dataAdviseHolder
= NULL
;
2068 IStorage_Release(This
->storage
);
2069 This
->storage
= NULL
;
2072 if (This
->pCFObject
)
2074 IClassFactory_Release(This
->pCFObject
);
2075 This
->pCFObject
= NULL
;
2078 HeapFree(GetProcessHeap(), 0, This
);
2081 /******************************************************************************
2082 * OleCreateEmbeddingHelper [OLE32.@]
2084 HRESULT WINAPI
OleCreateEmbeddingHelper(
2086 LPUNKNOWN pUnkOuter
,
2092 DefaultHandler
* newHandler
= NULL
;
2095 TRACE("(%s, %p, %08x, %p, %s, %p)\n", debugstr_guid(clsid
), pUnkOuter
, flags
, pCF
, debugstr_guid(riid
), ppvObj
);
2103 * If This handler is constructed for aggregation, make sure
2104 * the caller is requesting the IUnknown interface.
2105 * This is necessary because it's the only time the non-delegating
2106 * IUnknown pointer can be returned to the outside.
2108 if (pUnkOuter
&& !IsEqualIID(&IID_IUnknown
, riid
))
2109 return CLASS_E_NOAGGREGATION
;
2112 * Try to construct a new instance of the class.
2114 newHandler
= DefaultHandler_Construct(clsid
, pUnkOuter
, flags
, pCF
);
2117 return E_OUTOFMEMORY
;
2120 * Make sure it supports the interface required by the caller.
2122 hr
= IUnknown_QueryInterface((IUnknown
*)&newHandler
->lpvtblIUnknown
, riid
, ppvObj
);
2125 * Release the reference obtained in the constructor. If
2126 * the QueryInterface was unsuccessful, it will free the class.
2128 IUnknown_Release((IUnknown
*)&newHandler
->lpvtblIUnknown
);
2134 /******************************************************************************
2135 * OleCreateDefaultHandler [OLE32.@]
2137 HRESULT WINAPI
OleCreateDefaultHandler(REFCLSID clsid
, LPUNKNOWN pUnkOuter
,
2138 REFIID riid
, LPVOID
* ppvObj
)
2140 TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid
), pUnkOuter
,debugstr_guid(riid
), ppvObj
);
2141 return OleCreateEmbeddingHelper(clsid
, pUnkOuter
, EMBDHLP_INPROC_HANDLER
| EMBDHLP_CREATENOW
,
2142 NULL
, riid
, ppvObj
);
2145 typedef struct HandlerCF
2147 const IClassFactoryVtbl
*lpVtbl
;
2152 static HRESULT WINAPI
2153 HandlerCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
, LPVOID
*ppv
)
2156 if (IsEqualIID(riid
,&IID_IUnknown
) ||
2157 IsEqualIID(riid
,&IID_IClassFactory
))
2160 IClassFactory_AddRef(iface
);
2163 return E_NOINTERFACE
;
2166 static ULONG WINAPI
HandlerCF_AddRef(LPCLASSFACTORY iface
)
2168 HandlerCF
*This
= (HandlerCF
*)iface
;
2169 return InterlockedIncrement(&This
->refs
);
2172 static ULONG WINAPI
HandlerCF_Release(LPCLASSFACTORY iface
)
2174 HandlerCF
*This
= (HandlerCF
*)iface
;
2175 ULONG refs
= InterlockedDecrement(&This
->refs
);
2177 HeapFree(GetProcessHeap(), 0, This
);
2181 static HRESULT WINAPI
2182 HandlerCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pUnk
,
2183 REFIID riid
, LPVOID
*ppv
)
2185 HandlerCF
*This
= (HandlerCF
*)iface
;
2186 return OleCreateDefaultHandler(&This
->clsid
, pUnk
, riid
, ppv
);
2189 static HRESULT WINAPI
HandlerCF_LockServer(LPCLASSFACTORY iface
, BOOL fLock
)
2191 FIXME("(%d), stub!\n",fLock
);
2195 static const IClassFactoryVtbl HandlerClassFactoryVtbl
= {
2196 HandlerCF_QueryInterface
,
2199 HandlerCF_CreateInstance
,
2200 HandlerCF_LockServer
2203 HRESULT
HandlerCF_Create(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
2206 HandlerCF
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
2207 if (!This
) return E_OUTOFMEMORY
;
2208 This
->lpVtbl
= &HandlerClassFactoryVtbl
;
2210 This
->clsid
= *rclsid
;
2212 hr
= IUnknown_QueryInterface((IUnknown
*)&This
->lpVtbl
, riid
, ppv
);
2214 HeapFree(GetProcessHeap(), 0, This
);