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
)
843 return IOleAdviseHolder_EnumAdvise(This
->oleAdviseHolder
, ppenumAdvise
);
846 /************************************************************************
847 * DefaultHandler_GetMiscStatus (IOleObject)
849 * The default handler's implementation of this method simply delegates
850 * to OleRegGetMiscStatus.
852 * See Windows documentation for more details on IOleObject methods.
854 static HRESULT WINAPI
DefaultHandler_GetMiscStatus(
860 DefaultHandler
*This
= impl_from_IOleObject(iface
);
862 TRACE("(%p, %lx, %p)\n", iface
, dwAspect
, pdwStatus
);
864 if (This
->pOleDelegate
)
865 return IOleObject_GetMiscStatus(This
->pOleDelegate
, dwAspect
, pdwStatus
);
867 hres
= OleRegGetMiscStatus(&This
->clsid
, dwAspect
, pdwStatus
);
875 /************************************************************************
876 * DefaultHandler_SetColorScheme (IOleObject)
878 * This method is meaningless if the server is not running
880 * See Windows documentation for more details on IOleObject methods.
882 static HRESULT WINAPI
DefaultHandler_SetColorScheme(
884 struct tagLOGPALETTE
* pLogpal
)
886 DefaultHandler
*This
= impl_from_IOleObject(iface
);
888 TRACE("(%p, %p))\n", iface
, pLogpal
);
890 if (This
->pOleDelegate
)
891 return IOleObject_SetColorScheme(This
->pOleDelegate
, pLogpal
);
893 return OLE_E_NOTRUNNING
;
896 /*********************************************************
897 * Methods implementation for the IDataObject part of
898 * the DefaultHandler class.
901 /************************************************************************
902 * DefaultHandler_IDataObject_QueryInterface (IUnknown)
904 * See Windows documentation for more details on IUnknown methods.
906 static HRESULT WINAPI
DefaultHandler_IDataObject_QueryInterface(
911 DefaultHandler
*This
= impl_from_IDataObject(iface
);
913 return IUnknown_QueryInterface(This
->outerUnknown
, riid
, ppvObject
);
916 /************************************************************************
917 * DefaultHandler_IDataObject_AddRef (IUnknown)
919 * See Windows documentation for more details on IUnknown methods.
921 static ULONG WINAPI
DefaultHandler_IDataObject_AddRef(
924 DefaultHandler
*This
= impl_from_IDataObject(iface
);
926 return IUnknown_AddRef(This
->outerUnknown
);
929 /************************************************************************
930 * DefaultHandler_IDataObject_Release (IUnknown)
932 * See Windows documentation for more details on IUnknown methods.
934 static ULONG WINAPI
DefaultHandler_IDataObject_Release(
937 DefaultHandler
*This
= impl_from_IDataObject(iface
);
939 return IUnknown_Release(This
->outerUnknown
);
942 /************************************************************************
943 * DefaultHandler_GetData
945 * Get Data from a source dataobject using format pformatetcIn->cfFormat
946 * See Windows documentation for more details on GetData.
947 * Default handler's implementation of this method delegates to the cache.
949 static HRESULT WINAPI
DefaultHandler_GetData(
951 LPFORMATETC pformatetcIn
,
954 IDataObject
* cacheDataObject
= NULL
;
957 DefaultHandler
*This
= impl_from_IDataObject(iface
);
959 TRACE("(%p, %p, %p)\n", iface
, pformatetcIn
, pmedium
);
961 hres
= IUnknown_QueryInterface(This
->dataCache
,
963 (void**)&cacheDataObject
);
968 hres
= IDataObject_GetData(cacheDataObject
,
972 IDataObject_Release(cacheDataObject
);
977 static HRESULT WINAPI
DefaultHandler_GetDataHere(
979 LPFORMATETC pformatetc
,
986 /************************************************************************
987 * DefaultHandler_QueryGetData (IDataObject)
989 * The default handler's implementation of this method delegates to
992 * See Windows documentation for more details on IDataObject methods.
994 static HRESULT WINAPI
DefaultHandler_QueryGetData(
996 LPFORMATETC pformatetc
)
998 IDataObject
* cacheDataObject
= NULL
;
1001 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1003 TRACE("(%p, %p)\n", iface
, pformatetc
);
1005 hres
= IUnknown_QueryInterface(This
->dataCache
,
1007 (void**)&cacheDataObject
);
1010 return E_UNEXPECTED
;
1012 hres
= IDataObject_QueryGetData(cacheDataObject
,
1015 IDataObject_Release(cacheDataObject
);
1020 /************************************************************************
1021 * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
1023 * This method is meaningless if the server is not running
1025 * See Windows documentation for more details on IDataObject methods.
1027 static HRESULT WINAPI
DefaultHandler_GetCanonicalFormatEtc(
1029 LPFORMATETC pformatetcIn
,
1030 LPFORMATETC pformatetcOut
)
1032 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1033 IDataObject
*pDataObject
;
1036 TRACE("(%p, %p, %p)\n", iface
, pformatetcIn
, pformatetcOut
);
1038 if (!This
->pOleDelegate
)
1039 return OLE_E_NOTRUNNING
;
1041 hr
= IOleObject_QueryInterface(This
->pOleDelegate
, &IID_IDataObject
, (void **)&pDataObject
);
1042 return IDataObject_GetCanonicalFormatEtc(pDataObject
, pformatetcIn
, pformatetcOut
);
1045 /************************************************************************
1046 * DefaultHandler_SetData (IDataObject)
1048 * The default handler's implementation of this method delegates to
1051 * See Windows documentation for more details on IDataObject methods.
1053 static HRESULT WINAPI
DefaultHandler_SetData(
1055 LPFORMATETC pformatetc
,
1059 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1060 IDataObject
* cacheDataObject
= NULL
;
1063 TRACE("(%p, %p, %p, %d)\n", iface
, pformatetc
, pmedium
, fRelease
);
1065 hres
= IUnknown_QueryInterface(This
->dataCache
,
1067 (void**)&cacheDataObject
);
1070 return E_UNEXPECTED
;
1072 hres
= IDataObject_SetData(cacheDataObject
,
1077 IDataObject_Release(cacheDataObject
);
1082 /************************************************************************
1083 * DefaultHandler_EnumFormatEtc (IDataObject)
1085 * The default handler's implementation of This method simply delegates
1086 * to OleRegEnumFormatEtc.
1088 * See Windows documentation for more details on IDataObject methods.
1090 static HRESULT WINAPI
DefaultHandler_EnumFormatEtc(
1093 IEnumFORMATETC
** ppenumFormatEtc
)
1096 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1098 TRACE("(%p, %lx, %p)\n", iface
, dwDirection
, ppenumFormatEtc
);
1100 hres
= OleRegEnumFormatEtc(&This
->clsid
, dwDirection
, ppenumFormatEtc
);
1105 /************************************************************************
1106 * DefaultHandler_DAdvise (IDataObject)
1108 * The default handler's implementation of this method simply
1109 * delegates to the DataAdviseHolder.
1111 * See Windows documentation for more details on IDataObject methods.
1113 static HRESULT WINAPI
DefaultHandler_DAdvise(
1115 FORMATETC
* pformatetc
,
1117 IAdviseSink
* pAdvSink
,
1118 DWORD
* pdwConnection
)
1120 HRESULT hres
= S_OK
;
1121 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1123 TRACE("(%p, %p, %ld, %p, %p)\n",
1124 iface
, pformatetc
, advf
, pAdvSink
, pdwConnection
);
1126 /* Make sure we have a data advise holder before we start. */
1127 if (!This
->dataAdviseHolder
)
1128 hres
= CreateDataAdviseHolder(&This
->dataAdviseHolder
);
1130 if (SUCCEEDED(hres
))
1131 hres
= IDataAdviseHolder_Advise(This
->dataAdviseHolder
,
1141 /************************************************************************
1142 * DefaultHandler_DUnadvise (IDataObject)
1144 * The default handler's implementation of this method simply
1145 * delegates to the DataAdviseHolder.
1147 * See Windows documentation for more details on IDataObject methods.
1149 static HRESULT WINAPI
DefaultHandler_DUnadvise(
1153 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1155 TRACE("(%p, %ld)\n", iface
, dwConnection
);
1158 * If we don't have a data advise holder yet, it means that
1159 * we don't have any connections..
1161 if (!This
->dataAdviseHolder
)
1162 return OLE_E_NOCONNECTION
;
1164 return IDataAdviseHolder_Unadvise(This
->dataAdviseHolder
,
1168 /************************************************************************
1169 * DefaultHandler_EnumDAdvise (IDataObject)
1171 * The default handler's implementation of this method simply
1172 * delegates to the DataAdviseHolder.
1174 * See Windows documentation for more details on IDataObject methods.
1176 static HRESULT WINAPI
DefaultHandler_EnumDAdvise(
1178 IEnumSTATDATA
** ppenumAdvise
)
1180 DefaultHandler
*This
= impl_from_IDataObject(iface
);
1182 TRACE("(%p, %p)\n", iface
, ppenumAdvise
);
1188 *ppenumAdvise
= NULL
;
1190 /* If we have a data advise holder object, delegate. */
1191 if (This
->dataAdviseHolder
)
1192 return IDataAdviseHolder_EnumAdvise(This
->dataAdviseHolder
,
1198 /*********************************************************
1199 * Methods implementation for the IRunnableObject part
1200 * of the DefaultHandler class.
1203 /************************************************************************
1204 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1206 * See Windows documentation for more details on IUnknown methods.
1208 static HRESULT WINAPI
DefaultHandler_IRunnableObject_QueryInterface(
1209 IRunnableObject
* iface
,
1213 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1215 return IUnknown_QueryInterface(This
->outerUnknown
, riid
, ppvObject
);
1218 /************************************************************************
1219 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1221 * See Windows documentation for more details on IUnknown methods.
1223 static ULONG WINAPI
DefaultHandler_IRunnableObject_AddRef(
1224 IRunnableObject
* iface
)
1226 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1228 return IUnknown_AddRef(This
->outerUnknown
);
1231 /************************************************************************
1232 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1234 * See Windows documentation for more details on IUnknown methods.
1236 static ULONG WINAPI
DefaultHandler_IRunnableObject_Release(
1237 IRunnableObject
* iface
)
1239 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1241 return IUnknown_Release(This
->outerUnknown
);
1244 /************************************************************************
1245 * DefaultHandler_GetRunningClass (IRunnableObject)
1247 * See Windows documentation for more details on IRunnableObject methods.
1249 static HRESULT WINAPI
DefaultHandler_GetRunningClass(
1250 IRunnableObject
* iface
,
1257 static HRESULT WINAPI
DefaultHandler_Run(
1258 IRunnableObject
* iface
,
1261 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1264 FIXME("(%p): semi-stub\n", pbc
);
1266 /* already running? if so nothing to do */
1267 if (This
->pOleDelegate
)
1270 hr
= CoCreateInstance(&This
->clsid
, NULL
, CLSCTX_LOCAL_SERVER
,
1271 &IID_IOleObject
, (void **)&This
->pOleDelegate
);
1275 hr
= IOleObject_Advise(This
->pOleDelegate
,
1276 (IAdviseSink
*)&This
->lpvtblIAdviseSink
,
1279 if (SUCCEEDED(hr
) && This
->clientSite
)
1280 hr
= IOleObject_SetClientSite(This
->pOleDelegate
, This
->clientSite
);
1284 IOleObject_QueryInterface(This
->pOleDelegate
, &IID_IPersistStorage
,
1285 (void **)&This
->pPSDelegate
);
1286 if (This
->pPSDelegate
)
1287 hr
= IPersistStorage_InitNew(This
->pPSDelegate
, NULL
);
1290 if (SUCCEEDED(hr
) && This
->containerApp
)
1291 hr
= IOleObject_SetHostNames(This
->pOleDelegate
, This
->containerApp
,
1292 This
->containerObj
);
1294 /* FIXME: do more stuff here:
1295 * - IOleObject_GetMiscStatus
1296 * - IOleObject_GetMoniker
1301 hr
= IOleObject_QueryInterface(This
->pOleDelegate
, &IID_IDataObject
,
1302 (void **)&This
->pDataDelegate
);
1304 if (SUCCEEDED(hr
) && This
->dataAdviseHolder
)
1305 hr
= DataAdviseHolder_OnConnect(This
->dataAdviseHolder
, This
->pDataDelegate
);
1308 DefaultHandler_Stop(This
);
1313 /************************************************************************
1314 * DefaultHandler_IsRunning (IRunnableObject)
1316 * See Windows documentation for more details on IRunnableObject methods.
1318 static BOOL WINAPI
DefaultHandler_IsRunning(
1319 IRunnableObject
* iface
)
1321 DefaultHandler
*This
= impl_from_IRunnableObject(iface
);
1325 if (This
->pOleDelegate
)
1331 /************************************************************************
1332 * DefaultHandler_LockRunning (IRunnableObject)
1334 * See Windows documentation for more details on IRunnableObject methods.
1336 static HRESULT WINAPI
DefaultHandler_LockRunning(
1337 IRunnableObject
* iface
,
1339 BOOL fLastUnlockCloses
)
1345 /************************************************************************
1346 * DefaultHandler_SetContainedObject (IRunnableObject)
1348 * See Windows documentation for more details on IRunnableObject methods.
1350 static HRESULT WINAPI
DefaultHandler_SetContainedObject(
1351 IRunnableObject
* iface
,
1358 static HRESULT WINAPI
DefaultHandler_IAdviseSink_QueryInterface(
1363 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1364 IsEqualIID(riid
, &IID_IAdviseSink
))
1367 IAdviseSink_AddRef(iface
);
1371 return E_NOINTERFACE
;
1374 static ULONG WINAPI
DefaultHandler_IAdviseSink_AddRef(
1377 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1379 return IUnknown_AddRef((IUnknown
*)&This
->lpvtblIUnknown
);
1382 static ULONG WINAPI
DefaultHandler_IAdviseSink_Release(
1385 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1387 return IUnknown_Release((IUnknown
*)&This
->lpvtblIUnknown
);
1390 static void WINAPI
DefaultHandler_IAdviseSink_OnDataChange(
1392 FORMATETC
*pFormatetc
,
1398 static void WINAPI
DefaultHandler_IAdviseSink_OnViewChange(
1406 static void WINAPI
DefaultHandler_IAdviseSink_OnRename(
1410 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1412 TRACE("(%p)\n", pmk
);
1414 if (This
->oleAdviseHolder
)
1415 IOleAdviseHolder_SendOnRename(This
->oleAdviseHolder
, pmk
);
1418 static void WINAPI
DefaultHandler_IAdviseSink_OnSave(
1421 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1425 if (This
->oleAdviseHolder
)
1426 IOleAdviseHolder_SendOnSave(This
->oleAdviseHolder
);
1429 static void WINAPI
DefaultHandler_IAdviseSink_OnClose(
1432 DefaultHandler
*This
= impl_from_IAdviseSink(iface
);
1436 if (This
->oleAdviseHolder
)
1437 IOleAdviseHolder_SendOnClose(This
->oleAdviseHolder
);
1439 DefaultHandler_Stop(This
);
1443 * Virtual function tables for the DefaultHandler class.
1445 static const IOleObjectVtbl DefaultHandler_IOleObject_VTable
=
1447 DefaultHandler_QueryInterface
,
1448 DefaultHandler_AddRef
,
1449 DefaultHandler_Release
,
1450 DefaultHandler_SetClientSite
,
1451 DefaultHandler_GetClientSite
,
1452 DefaultHandler_SetHostNames
,
1453 DefaultHandler_Close
,
1454 DefaultHandler_SetMoniker
,
1455 DefaultHandler_GetMoniker
,
1456 DefaultHandler_InitFromData
,
1457 DefaultHandler_GetClipboardData
,
1458 DefaultHandler_DoVerb
,
1459 DefaultHandler_EnumVerbs
,
1460 DefaultHandler_Update
,
1461 DefaultHandler_IsUpToDate
,
1462 DefaultHandler_GetUserClassID
,
1463 DefaultHandler_GetUserType
,
1464 DefaultHandler_SetExtent
,
1465 DefaultHandler_GetExtent
,
1466 DefaultHandler_Advise
,
1467 DefaultHandler_Unadvise
,
1468 DefaultHandler_EnumAdvise
,
1469 DefaultHandler_GetMiscStatus
,
1470 DefaultHandler_SetColorScheme
1473 static const IUnknownVtbl DefaultHandler_NDIUnknown_VTable
=
1475 DefaultHandler_NDIUnknown_QueryInterface
,
1476 DefaultHandler_NDIUnknown_AddRef
,
1477 DefaultHandler_NDIUnknown_Release
,
1480 static const IDataObjectVtbl DefaultHandler_IDataObject_VTable
=
1482 DefaultHandler_IDataObject_QueryInterface
,
1483 DefaultHandler_IDataObject_AddRef
,
1484 DefaultHandler_IDataObject_Release
,
1485 DefaultHandler_GetData
,
1486 DefaultHandler_GetDataHere
,
1487 DefaultHandler_QueryGetData
,
1488 DefaultHandler_GetCanonicalFormatEtc
,
1489 DefaultHandler_SetData
,
1490 DefaultHandler_EnumFormatEtc
,
1491 DefaultHandler_DAdvise
,
1492 DefaultHandler_DUnadvise
,
1493 DefaultHandler_EnumDAdvise
1496 static const IRunnableObjectVtbl DefaultHandler_IRunnableObject_VTable
=
1498 DefaultHandler_IRunnableObject_QueryInterface
,
1499 DefaultHandler_IRunnableObject_AddRef
,
1500 DefaultHandler_IRunnableObject_Release
,
1501 DefaultHandler_GetRunningClass
,
1503 DefaultHandler_IsRunning
,
1504 DefaultHandler_LockRunning
,
1505 DefaultHandler_SetContainedObject
1508 static const IAdviseSinkVtbl DefaultHandler_IAdviseSink_VTable
=
1510 DefaultHandler_IAdviseSink_QueryInterface
,
1511 DefaultHandler_IAdviseSink_AddRef
,
1512 DefaultHandler_IAdviseSink_Release
,
1513 DefaultHandler_IAdviseSink_OnDataChange
,
1514 DefaultHandler_IAdviseSink_OnViewChange
,
1515 DefaultHandler_IAdviseSink_OnRename
,
1516 DefaultHandler_IAdviseSink_OnSave
,
1517 DefaultHandler_IAdviseSink_OnClose
1520 /*********************************************************
1521 * Methods implementation for the DefaultHandler class.
1523 static DefaultHandler
* DefaultHandler_Construct(
1525 LPUNKNOWN pUnkOuter
)
1527 DefaultHandler
* This
= NULL
;
1530 * Allocate space for the object.
1532 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler
));
1537 This
->lpVtbl
= &DefaultHandler_IOleObject_VTable
;
1538 This
->lpvtblIUnknown
= &DefaultHandler_NDIUnknown_VTable
;
1539 This
->lpvtblIDataObject
= &DefaultHandler_IDataObject_VTable
;
1540 This
->lpvtblIRunnableObject
= &DefaultHandler_IRunnableObject_VTable
;
1541 This
->lpvtblIAdviseSink
= &DefaultHandler_IAdviseSink_VTable
;
1544 * Start with one reference count. The caller of this function
1545 * must release the interface pointer when it is done.
1550 * Initialize the outer unknown
1551 * We don't keep a reference on the outer unknown since, the way
1552 * aggregation works, our lifetime is at least as large as it's
1556 pUnkOuter
= (IUnknown
*)&This
->lpvtblIUnknown
;
1558 This
->outerUnknown
= pUnkOuter
;
1561 * Create a datacache object.
1562 * We aggregate with the datacache. Make sure we pass our outer
1563 * unknown as the datacache's outer unknown.
1565 CreateDataCache(This
->outerUnknown
,
1568 (void**)&This
->dataCache
);
1571 * Initialize the other data members of the class.
1573 memcpy(&This
->clsid
, clsid
, sizeof(CLSID
));
1574 This
->clientSite
= NULL
;
1575 This
->oleAdviseHolder
= NULL
;
1576 This
->dataAdviseHolder
= NULL
;
1577 This
->containerApp
= NULL
;
1578 This
->containerObj
= NULL
;
1579 This
->pOleDelegate
= NULL
;
1580 This
->pPSDelegate
= NULL
;
1581 This
->pDataDelegate
= NULL
;
1583 This
->dwAdvConn
= 0;
1588 static void DefaultHandler_Destroy(
1589 DefaultHandler
* This
)
1591 /* release delegates */
1592 DefaultHandler_Stop(This
);
1594 /* Free the strings idenfitying the object */
1595 HeapFree( GetProcessHeap(), 0, This
->containerApp
);
1596 This
->containerApp
= NULL
;
1597 HeapFree( GetProcessHeap(), 0, This
->containerObj
);
1598 This
->containerObj
= NULL
;
1600 /* Release our reference to the data cache. */
1601 if (This
->dataCache
)
1603 IUnknown_Release(This
->dataCache
);
1604 This
->dataCache
= NULL
;
1607 /* Same thing for the client site. */
1608 if (This
->clientSite
)
1610 IOleClientSite_Release(This
->clientSite
);
1611 This
->clientSite
= NULL
;
1614 /* And the advise holder. */
1615 if (This
->oleAdviseHolder
)
1617 IOleAdviseHolder_Release(This
->oleAdviseHolder
);
1618 This
->oleAdviseHolder
= NULL
;
1621 /* And the data advise holder. */
1622 if (This
->dataAdviseHolder
)
1624 IDataAdviseHolder_Release(This
->dataAdviseHolder
);
1625 This
->dataAdviseHolder
= NULL
;
1628 /* Free the actual default handler structure. */
1629 HeapFree(GetProcessHeap(), 0, This
);
1632 /******************************************************************************
1633 * OleCreateDefaultHandler [OLE32.@]
1635 HRESULT WINAPI
OleCreateDefaultHandler(
1637 LPUNKNOWN pUnkOuter
,
1641 DefaultHandler
* newHandler
= NULL
;
1644 TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid
), pUnkOuter
, debugstr_guid(riid
), ppvObj
);
1655 * If This handler is constructed for aggregation, make sure
1656 * the caller is requesting the IUnknown interface.
1657 * This is necessary because it's the only time the non-delegating
1658 * IUnknown pointer can be returned to the outside.
1660 if (pUnkOuter
&& !IsEqualIID(&IID_IUnknown
, riid
))
1661 return CLASS_E_NOAGGREGATION
;
1664 * Try to construct a new instance of the class.
1666 newHandler
= DefaultHandler_Construct(clsid
, pUnkOuter
);
1669 return E_OUTOFMEMORY
;
1672 * Make sure it supports the interface required by the caller.
1674 hr
= IUnknown_QueryInterface((IUnknown
*)&newHandler
->lpvtblIUnknown
, riid
, ppvObj
);
1677 * Release the reference obtained in the constructor. If
1678 * the QueryInterface was unsuccessful, it will free the class.
1680 IUnknown_Release((IUnknown
*)&newHandler
->lpvtblIUnknown
);