winhelp: Display keywords index dialog box.
[wine.git] / dlls / ole32 / defaulthandler.c
blob33e80cee80d6cdf04f1a042187a982139a25dab8
1 /*
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
21 * NOTES:
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,
30 * TODO
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
39 * done in this area.
41 * - Some functions still return E_NOTIMPL they have to be
42 * implemented. Most of those are related to the running of the
43 * actual server.
45 * - All the methods related to notification and advise sinks are
46 * in place but no notifications are sent to the sinks yet.
48 #include <assert.h>
49 #include <stdarg.h>
50 #include <string.h>
52 #define COBJMACROS
54 #include "windef.h"
55 #include "winbase.h"
56 #include "winuser.h"
57 #include "winerror.h"
58 #include "ole2.h"
60 #include "compobj_private.h"
62 #include "wine/unicode.h"
63 #include "wine/debug.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(ole);
67 /****************************************************************************
68 * DefaultHandler
71 struct DefaultHandler
73 const IOleObjectVtbl* lpVtbl;
74 const IUnknownVtbl* lpvtblIUnknown;
75 const IDataObjectVtbl* lpvtblIDataObject;
76 const IRunnableObjectVtbl* lpvtblIRunnableObject;
77 const IAdviseSinkVtbl *lpvtblIAdviseSink;
78 const IPersistStorageVtbl *lpvtblIPersistStorage;
80 /* Reference count of this object */
81 LONG ref;
83 /* IUnknown implementation of the outer object. */
84 IUnknown* outerUnknown;
86 /* Class Id that this handler object represents. */
87 CLSID clsid;
89 /* IUnknown implementation of the datacache. */
90 IUnknown* dataCache;
91 /* IPersistStorage implementation of the datacache. */
92 IPersistStorage* dataCache_PersistStg;
94 /* Client site for the embedded object. */
95 IOleClientSite* clientSite;
98 * The IOleAdviseHolder maintains the connections
99 * on behalf of the default handler.
101 IOleAdviseHolder* oleAdviseHolder;
104 * The IDataAdviseHolder maintains the data
105 * connections on behalf of the default handler.
107 IDataAdviseHolder* dataAdviseHolder;
109 /* Name of the container and object contained */
110 LPWSTR containerApp;
111 LPWSTR containerObj;
113 /* IOleObject delegate */
114 IOleObject *pOleDelegate;
115 /* IPersistStorage delegate */
116 IPersistStorage *pPSDelegate;
117 /* IDataObject delegate */
118 IDataObject *pDataDelegate;
120 /* connection cookie for the advise on the delegate OLE object */
121 DWORD dwAdvConn;
124 typedef struct DefaultHandler DefaultHandler;
127 * Here, I define utility functions to help with the casting of the
128 * "This" parameter.
129 * There is a version to accommodate all of the VTables implemented
130 * by this object.
132 static inline DefaultHandler *impl_from_IOleObject( IOleObject *iface )
134 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpVtbl));
137 static inline DefaultHandler *impl_from_NDIUnknown( IUnknown *iface )
139 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIUnknown));
142 static inline DefaultHandler *impl_from_IDataObject( IDataObject *iface )
144 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIDataObject));
147 static inline DefaultHandler *impl_from_IRunnableObject( IRunnableObject *iface )
149 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIRunnableObject));
152 static inline DefaultHandler *impl_from_IAdviseSink( IAdviseSink *iface )
154 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIAdviseSink));
157 static inline DefaultHandler *impl_from_IPersistStorage( IPersistStorage *iface )
159 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIPersistStorage));
162 static void DefaultHandler_Destroy(DefaultHandler* This);
164 static inline BOOL object_is_running(DefaultHandler *This)
166 return IRunnableObject_IsRunning((IRunnableObject*)&This->lpvtblIRunnableObject);
169 /*********************************************************
170 * Method implementation for the non delegating IUnknown
171 * part of the DefaultHandler class.
174 /************************************************************************
175 * DefaultHandler_NDIUnknown_QueryInterface (IUnknown)
177 * See Windows documentation for more details on IUnknown methods.
179 * This version of QueryInterface will not delegate its implementation
180 * to the outer unknown.
182 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
183 IUnknown* iface,
184 REFIID riid,
185 void** ppvObject)
187 DefaultHandler *This = impl_from_NDIUnknown(iface);
189 /* Perform a sanity check on the parameters. */
190 if (!ppvObject)
191 return E_INVALIDARG;
193 *ppvObject = NULL;
195 if (IsEqualIID(&IID_IUnknown, riid))
196 *ppvObject = iface;
197 else if (IsEqualIID(&IID_IOleObject, riid))
198 *ppvObject = (IOleObject*)&This->lpVtbl;
199 else if (IsEqualIID(&IID_IDataObject, riid))
200 *ppvObject = (IDataObject*)&This->lpvtblIDataObject;
201 else if (IsEqualIID(&IID_IRunnableObject, riid))
202 *ppvObject = (IRunnableObject*)&This->lpvtblIRunnableObject;
203 else if (IsEqualIID(&IID_IPersist, riid) ||
204 IsEqualIID(&IID_IPersistStorage, riid))
205 *ppvObject = &This->lpvtblIPersistStorage;
206 else if (IsEqualIID(&IID_IViewObject, riid) ||
207 IsEqualIID(&IID_IViewObject2, riid) ||
208 IsEqualIID(&IID_IOleCache, riid) ||
209 IsEqualIID(&IID_IOleCache2, riid))
211 HRESULT hr = IUnknown_QueryInterface(This->dataCache, riid, ppvObject);
212 if (FAILED(hr)) FIXME("interface %s not implemented by data cache\n", debugstr_guid(riid));
213 return hr;
216 /* Check that we obtained an interface. */
217 if (*ppvObject == NULL)
219 WARN( "() : asking for un supported interface %s\n", debugstr_guid(riid));
220 return E_NOINTERFACE;
224 * Query Interface always increases the reference count by one when it is
225 * successful.
227 IUnknown_AddRef((IUnknown*)*ppvObject);
229 return S_OK;
232 /************************************************************************
233 * DefaultHandler_NDIUnknown_AddRef (IUnknown)
235 * See Windows documentation for more details on IUnknown methods.
237 * This version of QueryInterface will not delegate its implementation
238 * to the outer unknown.
240 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef(
241 IUnknown* iface)
243 DefaultHandler *This = impl_from_NDIUnknown(iface);
244 return InterlockedIncrement(&This->ref);
247 /************************************************************************
248 * DefaultHandler_NDIUnknown_Release (IUnknown)
250 * See Windows documentation for more details on IUnknown methods.
252 * This version of QueryInterface will not delegate its implementation
253 * to the outer unknown.
255 static ULONG WINAPI DefaultHandler_NDIUnknown_Release(
256 IUnknown* iface)
258 DefaultHandler *This = impl_from_NDIUnknown(iface);
259 ULONG ref;
261 /* Decrease the reference count on this object. */
262 ref = InterlockedDecrement(&This->ref);
264 if (!ref) DefaultHandler_Destroy(This);
266 return ref;
269 /*********************************************************
270 * Methods implementation for the IOleObject part of
271 * the DefaultHandler class.
274 /************************************************************************
275 * DefaultHandler_QueryInterface (IUnknown)
277 * See Windows documentation for more details on IUnknown methods.
279 static HRESULT WINAPI DefaultHandler_QueryInterface(
280 IOleObject* iface,
281 REFIID riid,
282 void** ppvObject)
284 DefaultHandler *This = impl_from_IOleObject(iface);
286 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
289 /************************************************************************
290 * DefaultHandler_AddRef (IUnknown)
292 * See Windows documentation for more details on IUnknown methods.
294 static ULONG WINAPI DefaultHandler_AddRef(
295 IOleObject* iface)
297 DefaultHandler *This = impl_from_IOleObject(iface);
299 return IUnknown_AddRef(This->outerUnknown);
302 /************************************************************************
303 * DefaultHandler_Release (IUnknown)
305 * See Windows documentation for more details on IUnknown methods.
307 static ULONG WINAPI DefaultHandler_Release(
308 IOleObject* iface)
310 DefaultHandler *This = impl_from_IOleObject(iface);
312 return IUnknown_Release(This->outerUnknown);
315 /************************************************************************
316 * DefaultHandler_SetClientSite (IOleObject)
318 * The default handler's implementation of this method only keeps the
319 * client site pointer for future reference.
321 * See Windows documentation for more details on IOleObject methods.
323 static HRESULT WINAPI DefaultHandler_SetClientSite(
324 IOleObject* iface,
325 IOleClientSite* pClientSite)
327 DefaultHandler *This = impl_from_IOleObject(iface);
328 HRESULT hr = S_OK;
330 TRACE("(%p, %p)\n", iface, pClientSite);
332 if (object_is_running(This))
333 hr = IOleObject_SetClientSite(This->pOleDelegate, pClientSite);
336 * Make sure we release the previous client site if there
337 * was one.
339 if (This->clientSite)
340 IOleClientSite_Release(This->clientSite);
342 This->clientSite = pClientSite;
344 if (This->clientSite)
345 IOleClientSite_AddRef(This->clientSite);
347 return S_OK;
350 /************************************************************************
351 * DefaultHandler_GetClientSite (IOleObject)
353 * The default handler's implementation of this method returns the
354 * last pointer set in IOleObject_SetClientSite.
356 * See Windows documentation for more details on IOleObject methods.
358 static HRESULT WINAPI DefaultHandler_GetClientSite(
359 IOleObject* iface,
360 IOleClientSite** ppClientSite)
362 DefaultHandler *This = impl_from_IOleObject(iface);
364 /* Sanity check. */
365 if (!ppClientSite)
366 return E_POINTER;
368 *ppClientSite = This->clientSite;
370 if (This->clientSite)
371 IOleClientSite_AddRef(This->clientSite);
373 return S_OK;
376 /************************************************************************
377 * DefaultHandler_SetHostNames (IOleObject)
379 * The default handler's implementation of this method just stores
380 * the strings and returns S_OK.
382 * See Windows documentation for more details on IOleObject methods.
384 static HRESULT WINAPI DefaultHandler_SetHostNames(
385 IOleObject* iface,
386 LPCOLESTR szContainerApp,
387 LPCOLESTR szContainerObj)
389 DefaultHandler *This = impl_from_IOleObject(iface);
391 TRACE("(%p, %s, %s)\n",
392 iface,
393 debugstr_w(szContainerApp),
394 debugstr_w(szContainerObj));
396 if (object_is_running(This))
397 IOleObject_SetHostNames(This->pOleDelegate, szContainerApp, szContainerObj);
399 /* Be sure to cleanup before re-assinging the strings. */
400 HeapFree( GetProcessHeap(), 0, This->containerApp );
401 This->containerApp = NULL;
402 HeapFree( GetProcessHeap(), 0, This->containerObj );
403 This->containerObj = NULL;
405 /* Copy the string supplied. */
406 if (szContainerApp)
408 if ((This->containerApp = HeapAlloc( GetProcessHeap(), 0,
409 (lstrlenW(szContainerApp) + 1) * sizeof(WCHAR) )))
410 strcpyW( This->containerApp, szContainerApp );
413 if (szContainerObj)
415 if ((This->containerObj = HeapAlloc( GetProcessHeap(), 0,
416 (lstrlenW(szContainerObj) + 1) * sizeof(WCHAR) )))
417 strcpyW( This->containerObj, szContainerObj );
419 return S_OK;
422 /* undos the work done by DefaultHandler_Run */
423 static void WINAPI DefaultHandler_Stop(DefaultHandler *This)
425 if (!object_is_running(This))
426 return;
428 IOleObject_Unadvise(This->pOleDelegate, This->dwAdvConn);
430 /* FIXME: call IOleCache_OnStop */
432 if (This->dataAdviseHolder)
433 DataAdviseHolder_OnDisconnect(This->dataAdviseHolder);
434 if (This->pDataDelegate)
436 IDataObject_Release(This->pDataDelegate);
437 This->pDataDelegate = NULL;
439 if (This->pPSDelegate)
441 IPersistStorage_Release(This->pPSDelegate);
442 This->pPSDelegate = NULL;
444 IOleObject_Release(This->pOleDelegate);
445 This->pOleDelegate = NULL;
448 /************************************************************************
449 * DefaultHandler_Close (IOleObject)
451 * The default handler's implementation of this method is meaningless
452 * without a running server so it does nothing.
454 * See Windows documentation for more details on IOleObject methods.
456 static HRESULT WINAPI DefaultHandler_Close(
457 IOleObject* iface,
458 DWORD dwSaveOption)
460 DefaultHandler *This = impl_from_IOleObject(iface);
461 HRESULT hr;
463 TRACE("(%d)\n", dwSaveOption);
465 if (!object_is_running(This))
466 return S_OK;
468 hr = IOleObject_Close(This->pOleDelegate, dwSaveOption);
470 DefaultHandler_Stop(This);
472 return hr;
475 /************************************************************************
476 * DefaultHandler_SetMoniker (IOleObject)
478 * The default handler's implementation of this method does nothing.
480 * See Windows documentation for more details on IOleObject methods.
482 static HRESULT WINAPI DefaultHandler_SetMoniker(
483 IOleObject* iface,
484 DWORD dwWhichMoniker,
485 IMoniker* pmk)
487 DefaultHandler *This = impl_from_IOleObject(iface);
489 TRACE("(%p, %d, %p)\n",
490 iface,
491 dwWhichMoniker,
492 pmk);
494 if (object_is_running(This))
495 return IOleObject_SetMoniker(This->pOleDelegate, dwWhichMoniker, pmk);
497 return S_OK;
500 /************************************************************************
501 * DefaultHandler_GetMoniker (IOleObject)
503 * Delegate this request to the client site if we have one.
505 * See Windows documentation for more details on IOleObject methods.
507 static HRESULT WINAPI DefaultHandler_GetMoniker(
508 IOleObject* iface,
509 DWORD dwAssign,
510 DWORD dwWhichMoniker,
511 IMoniker** ppmk)
513 DefaultHandler *This = impl_from_IOleObject(iface);
515 TRACE("(%p, %d, %d, %p)\n",
516 iface, dwAssign, dwWhichMoniker, ppmk);
518 if (object_is_running(This))
519 return IOleObject_GetMoniker(This->pOleDelegate, dwAssign, dwWhichMoniker,
520 ppmk);
522 /* FIXME: dwWhichMoniker == OLEWHICHMK_CONTAINER only? */
523 if (This->clientSite)
525 return IOleClientSite_GetMoniker(This->clientSite,
526 dwAssign,
527 dwWhichMoniker,
528 ppmk);
532 return E_FAIL;
535 /************************************************************************
536 * DefaultHandler_InitFromData (IOleObject)
538 * This method is meaningless if the server is not running
540 * See Windows documentation for more details on IOleObject methods.
542 static HRESULT WINAPI DefaultHandler_InitFromData(
543 IOleObject* iface,
544 IDataObject* pDataObject,
545 BOOL fCreation,
546 DWORD dwReserved)
548 DefaultHandler *This = impl_from_IOleObject(iface);
550 TRACE("(%p, %p, %d, %d)\n",
551 iface, pDataObject, fCreation, dwReserved);
553 if (object_is_running(This))
554 return IOleObject_InitFromData(This->pOleDelegate, pDataObject, fCreation,
555 dwReserved);
556 return OLE_E_NOTRUNNING;
559 /************************************************************************
560 * DefaultHandler_GetClipboardData (IOleObject)
562 * This method is meaningless if the server is not running
564 * See Windows documentation for more details on IOleObject methods.
566 static HRESULT WINAPI DefaultHandler_GetClipboardData(
567 IOleObject* iface,
568 DWORD dwReserved,
569 IDataObject** ppDataObject)
571 DefaultHandler *This = impl_from_IOleObject(iface);
573 TRACE("(%p, %d, %p)\n",
574 iface, dwReserved, ppDataObject);
576 if (object_is_running(This))
577 return IOleObject_GetClipboardData(This->pOleDelegate, dwReserved,
578 ppDataObject);
580 return OLE_E_NOTRUNNING;
583 static HRESULT WINAPI DefaultHandler_DoVerb(
584 IOleObject* iface,
585 LONG iVerb,
586 struct tagMSG* lpmsg,
587 IOleClientSite* pActiveSite,
588 LONG lindex,
589 HWND hwndParent,
590 LPCRECT lprcPosRect)
592 DefaultHandler *This = impl_from_IOleObject(iface);
593 IRunnableObject *pRunnableObj = (IRunnableObject *)&This->lpvtblIRunnableObject;
594 HRESULT hr;
596 TRACE("(%d, %p, %p, %d, %p, %s)\n", iVerb, lpmsg, pActiveSite, lindex, hwndParent, wine_dbgstr_rect(lprcPosRect));
598 hr = IRunnableObject_Run(pRunnableObj, NULL);
599 if (FAILED(hr)) return hr;
601 return IOleObject_DoVerb(This->pOleDelegate, iVerb, lpmsg, pActiveSite,
602 lindex, hwndParent, lprcPosRect);
605 /************************************************************************
606 * DefaultHandler_EnumVerbs (IOleObject)
608 * The default handler implementation of this method simply delegates
609 * to OleRegEnumVerbs
611 * See Windows documentation for more details on IOleObject methods.
613 static HRESULT WINAPI DefaultHandler_EnumVerbs(
614 IOleObject* iface,
615 IEnumOLEVERB** ppEnumOleVerb)
617 DefaultHandler *This = impl_from_IOleObject(iface);
618 HRESULT hr = OLE_S_USEREG;
620 TRACE("(%p, %p)\n", iface, ppEnumOleVerb);
622 if (object_is_running(This))
623 hr = IOleObject_EnumVerbs(This->pOleDelegate, ppEnumOleVerb);
625 if (hr == OLE_S_USEREG)
626 return OleRegEnumVerbs(&This->clsid, ppEnumOleVerb);
627 else
628 return hr;
631 static HRESULT WINAPI DefaultHandler_Update(
632 IOleObject* iface)
634 FIXME(": Stub\n");
635 return E_NOTIMPL;
638 /************************************************************************
639 * DefaultHandler_IsUpToDate (IOleObject)
641 * This method is meaningless if the server is not running
643 * See Windows documentation for more details on IOleObject methods.
645 static HRESULT WINAPI DefaultHandler_IsUpToDate(
646 IOleObject* iface)
648 TRACE("(%p)\n", iface);
650 return OLE_E_NOTRUNNING;
653 /************************************************************************
654 * DefaultHandler_GetUserClassID (IOleObject)
656 * TODO: Map to a new class ID if emulation is active.
658 * See Windows documentation for more details on IOleObject methods.
660 static HRESULT WINAPI DefaultHandler_GetUserClassID(
661 IOleObject* iface,
662 CLSID* pClsid)
664 DefaultHandler *This = impl_from_IOleObject(iface);
666 TRACE("(%p, %p)\n", iface, pClsid);
668 if (object_is_running(This))
669 return IOleObject_GetUserClassID(This->pOleDelegate, pClsid);
671 /* Sanity check. */
672 if (!pClsid)
673 return E_POINTER;
675 memcpy(pClsid, &This->clsid, sizeof(CLSID));
677 return S_OK;
680 /************************************************************************
681 * DefaultHandler_GetUserType (IOleObject)
683 * The default handler implementation of this method simply delegates
684 * to OleRegGetUserType
686 * See Windows documentation for more details on IOleObject methods.
688 static HRESULT WINAPI DefaultHandler_GetUserType(
689 IOleObject* iface,
690 DWORD dwFormOfType,
691 LPOLESTR* pszUserType)
693 DefaultHandler *This = impl_from_IOleObject(iface);
695 TRACE("(%p, %d, %p)\n", iface, dwFormOfType, pszUserType);
697 return OleRegGetUserType(&This->clsid, dwFormOfType, pszUserType);
700 /************************************************************************
701 * DefaultHandler_SetExtent (IOleObject)
703 * This method is meaningless if the server is not running
705 * See Windows documentation for more details on IOleObject methods.
707 static HRESULT WINAPI DefaultHandler_SetExtent(
708 IOleObject* iface,
709 DWORD dwDrawAspect,
710 SIZEL* psizel)
712 DefaultHandler *This = impl_from_IOleObject(iface);
714 TRACE("(%p, %x, (%d x %d))\n", iface,
715 dwDrawAspect, psizel->cx, psizel->cy);
717 if (object_is_running(This))
718 IOleObject_SetExtent(This->pOleDelegate, dwDrawAspect, psizel);
720 return OLE_E_NOTRUNNING;
723 /************************************************************************
724 * DefaultHandler_GetExtent (IOleObject)
726 * The default handler's implementation of this method returns uses
727 * the cache to locate the aspect and extract the extent from it.
729 * See Windows documentation for more details on IOleObject methods.
731 static HRESULT WINAPI DefaultHandler_GetExtent(
732 IOleObject* iface,
733 DWORD dwDrawAspect,
734 SIZEL* psizel)
736 DVTARGETDEVICE* targetDevice;
737 IViewObject2* cacheView = NULL;
738 HRESULT hres;
740 DefaultHandler *This = impl_from_IOleObject(iface);
742 TRACE("(%p, %x, %p)\n", iface, dwDrawAspect, psizel);
744 if (object_is_running(This))
745 return IOleObject_GetExtent(This->pOleDelegate, dwDrawAspect, psizel);
747 hres = IUnknown_QueryInterface(This->dataCache, &IID_IViewObject2, (void**)&cacheView);
748 if (FAILED(hres))
749 return E_UNEXPECTED;
752 * Prepare the call to the cache's GetExtent method.
754 * Here we would build a valid DVTARGETDEVICE structure
755 * but, since we are calling into the data cache, we
756 * know its implementation and we'll skip this
757 * extra work until later.
759 targetDevice = NULL;
761 hres = IViewObject2_GetExtent(cacheView,
762 dwDrawAspect,
764 targetDevice,
765 psizel);
768 * Cleanup
770 IViewObject2_Release(cacheView);
772 return hres;
775 /************************************************************************
776 * DefaultHandler_Advise (IOleObject)
778 * The default handler's implementation of this method simply
779 * delegates to the OleAdviseHolder.
781 * See Windows documentation for more details on IOleObject methods.
783 static HRESULT WINAPI DefaultHandler_Advise(
784 IOleObject* iface,
785 IAdviseSink* pAdvSink,
786 DWORD* pdwConnection)
788 HRESULT hres = S_OK;
789 DefaultHandler *This = impl_from_IOleObject(iface);
791 TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection);
793 /* Make sure we have an advise holder before we start. */
794 if (!This->oleAdviseHolder)
795 hres = CreateOleAdviseHolder(&This->oleAdviseHolder);
797 if (SUCCEEDED(hres))
798 hres = IOleAdviseHolder_Advise(This->oleAdviseHolder,
799 pAdvSink,
800 pdwConnection);
802 return hres;
805 /************************************************************************
806 * DefaultHandler_Unadvise (IOleObject)
808 * The default handler's implementation of this method simply
809 * delegates to the OleAdviseHolder.
811 * See Windows documentation for more details on IOleObject methods.
813 static HRESULT WINAPI DefaultHandler_Unadvise(
814 IOleObject* iface,
815 DWORD dwConnection)
817 DefaultHandler *This = impl_from_IOleObject(iface);
819 TRACE("(%p, %d)\n", iface, dwConnection);
822 * If we don't have an advise holder yet, it means we don't have
823 * a connection.
825 if (!This->oleAdviseHolder)
826 return OLE_E_NOCONNECTION;
828 return IOleAdviseHolder_Unadvise(This->oleAdviseHolder,
829 dwConnection);
832 /************************************************************************
833 * DefaultHandler_EnumAdvise (IOleObject)
835 * The default handler's implementation of this method simply
836 * delegates to the OleAdviseHolder.
838 * See Windows documentation for more details on IOleObject methods.
840 static HRESULT WINAPI DefaultHandler_EnumAdvise(
841 IOleObject* iface,
842 IEnumSTATDATA** ppenumAdvise)
844 DefaultHandler *This = impl_from_IOleObject(iface);
846 TRACE("(%p, %p)\n", iface, ppenumAdvise);
848 /* Sanity check */
849 if (!ppenumAdvise)
850 return E_POINTER;
852 *ppenumAdvise = NULL;
854 if (!This->oleAdviseHolder)
855 return S_OK;
857 return IOleAdviseHolder_EnumAdvise(This->oleAdviseHolder, ppenumAdvise);
860 /************************************************************************
861 * DefaultHandler_GetMiscStatus (IOleObject)
863 * The default handler's implementation of this method simply delegates
864 * to OleRegGetMiscStatus.
866 * See Windows documentation for more details on IOleObject methods.
868 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
869 IOleObject* iface,
870 DWORD dwAspect,
871 DWORD* pdwStatus)
873 HRESULT hres;
874 DefaultHandler *This = impl_from_IOleObject(iface);
876 TRACE("(%p, %x, %p)\n", iface, dwAspect, pdwStatus);
878 if (object_is_running(This))
879 return IOleObject_GetMiscStatus(This->pOleDelegate, dwAspect, pdwStatus);
881 hres = OleRegGetMiscStatus(&This->clsid, dwAspect, pdwStatus);
883 if (FAILED(hres))
884 *pdwStatus = 0;
886 return S_OK;
889 /************************************************************************
890 * DefaultHandler_SetColorScheme (IOleObject)
892 * This method is meaningless if the server is not running
894 * See Windows documentation for more details on IOleObject methods.
896 static HRESULT WINAPI DefaultHandler_SetColorScheme(
897 IOleObject* iface,
898 struct tagLOGPALETTE* pLogpal)
900 DefaultHandler *This = impl_from_IOleObject(iface);
902 TRACE("(%p, %p))\n", iface, pLogpal);
904 if (object_is_running(This))
905 return IOleObject_SetColorScheme(This->pOleDelegate, pLogpal);
907 return OLE_E_NOTRUNNING;
910 /*********************************************************
911 * Methods implementation for the IDataObject part of
912 * the DefaultHandler class.
915 /************************************************************************
916 * DefaultHandler_IDataObject_QueryInterface (IUnknown)
918 * See Windows documentation for more details on IUnknown methods.
920 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
921 IDataObject* iface,
922 REFIID riid,
923 void** ppvObject)
925 DefaultHandler *This = impl_from_IDataObject(iface);
927 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
930 /************************************************************************
931 * DefaultHandler_IDataObject_AddRef (IUnknown)
933 * See Windows documentation for more details on IUnknown methods.
935 static ULONG WINAPI DefaultHandler_IDataObject_AddRef(
936 IDataObject* iface)
938 DefaultHandler *This = impl_from_IDataObject(iface);
940 return IUnknown_AddRef(This->outerUnknown);
943 /************************************************************************
944 * DefaultHandler_IDataObject_Release (IUnknown)
946 * See Windows documentation for more details on IUnknown methods.
948 static ULONG WINAPI DefaultHandler_IDataObject_Release(
949 IDataObject* iface)
951 DefaultHandler *This = impl_from_IDataObject(iface);
953 return IUnknown_Release(This->outerUnknown);
956 /************************************************************************
957 * DefaultHandler_GetData
959 * Get Data from a source dataobject using format pformatetcIn->cfFormat
960 * See Windows documentation for more details on GetData.
961 * Default handler's implementation of this method delegates to the cache.
963 static HRESULT WINAPI DefaultHandler_GetData(
964 IDataObject* iface,
965 LPFORMATETC pformatetcIn,
966 STGMEDIUM* pmedium)
968 IDataObject* cacheDataObject = NULL;
969 HRESULT hres;
971 DefaultHandler *This = impl_from_IDataObject(iface);
973 TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pmedium);
975 hres = IUnknown_QueryInterface(This->dataCache,
976 &IID_IDataObject,
977 (void**)&cacheDataObject);
979 if (FAILED(hres))
980 return E_UNEXPECTED;
982 hres = IDataObject_GetData(cacheDataObject,
983 pformatetcIn,
984 pmedium);
986 IDataObject_Release(cacheDataObject);
988 if (FAILED(hres) && This->pDataDelegate)
989 hres = IDataObject_GetData(This->pDataDelegate, pformatetcIn, pmedium);
991 return hres;
994 static HRESULT WINAPI DefaultHandler_GetDataHere(
995 IDataObject* iface,
996 LPFORMATETC pformatetc,
997 STGMEDIUM* pmedium)
999 FIXME(": Stub\n");
1000 return E_NOTIMPL;
1003 /************************************************************************
1004 * DefaultHandler_QueryGetData (IDataObject)
1006 * The default handler's implementation of this method delegates to
1007 * the cache.
1009 * See Windows documentation for more details on IDataObject methods.
1011 static HRESULT WINAPI DefaultHandler_QueryGetData(
1012 IDataObject* iface,
1013 LPFORMATETC pformatetc)
1015 IDataObject* cacheDataObject = NULL;
1016 HRESULT hres;
1018 DefaultHandler *This = impl_from_IDataObject(iface);
1020 TRACE("(%p, %p)\n", iface, pformatetc);
1022 hres = IUnknown_QueryInterface(This->dataCache,
1023 &IID_IDataObject,
1024 (void**)&cacheDataObject);
1026 if (FAILED(hres))
1027 return E_UNEXPECTED;
1029 hres = IDataObject_QueryGetData(cacheDataObject,
1030 pformatetc);
1032 IDataObject_Release(cacheDataObject);
1034 if (FAILED(hres) && This->pDataDelegate)
1035 hres = IDataObject_QueryGetData(This->pDataDelegate, pformatetc);
1037 return hres;
1040 /************************************************************************
1041 * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
1043 * This method is meaningless if the server is not running
1045 * See Windows documentation for more details on IDataObject methods.
1047 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
1048 IDataObject* iface,
1049 LPFORMATETC pformatetcIn,
1050 LPFORMATETC pformatetcOut)
1052 DefaultHandler *This = impl_from_IDataObject(iface);
1054 TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pformatetcOut);
1056 if (!This->pDataDelegate)
1057 return OLE_E_NOTRUNNING;
1059 return IDataObject_GetCanonicalFormatEtc(This->pDataDelegate, pformatetcIn, pformatetcOut);
1062 /************************************************************************
1063 * DefaultHandler_SetData (IDataObject)
1065 * The default handler's implementation of this method delegates to
1066 * the cache.
1068 * See Windows documentation for more details on IDataObject methods.
1070 static HRESULT WINAPI DefaultHandler_SetData(
1071 IDataObject* iface,
1072 LPFORMATETC pformatetc,
1073 STGMEDIUM* pmedium,
1074 BOOL fRelease)
1076 DefaultHandler *This = impl_from_IDataObject(iface);
1077 IDataObject* cacheDataObject = NULL;
1078 HRESULT hres;
1080 TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
1082 hres = IUnknown_QueryInterface(This->dataCache,
1083 &IID_IDataObject,
1084 (void**)&cacheDataObject);
1086 if (FAILED(hres))
1087 return E_UNEXPECTED;
1089 hres = IDataObject_SetData(cacheDataObject,
1090 pformatetc,
1091 pmedium,
1092 fRelease);
1094 IDataObject_Release(cacheDataObject);
1096 return hres;
1099 /************************************************************************
1100 * DefaultHandler_EnumFormatEtc (IDataObject)
1102 * The default handler's implementation of This method simply delegates
1103 * to OleRegEnumFormatEtc.
1105 * See Windows documentation for more details on IDataObject methods.
1107 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
1108 IDataObject* iface,
1109 DWORD dwDirection,
1110 IEnumFORMATETC** ppenumFormatEtc)
1112 HRESULT hres;
1113 DefaultHandler *This = impl_from_IDataObject(iface);
1115 TRACE("(%p, %x, %p)\n", iface, dwDirection, ppenumFormatEtc);
1117 hres = OleRegEnumFormatEtc(&This->clsid, dwDirection, ppenumFormatEtc);
1119 return hres;
1122 /************************************************************************
1123 * DefaultHandler_DAdvise (IDataObject)
1125 * The default handler's implementation of this method simply
1126 * delegates to the DataAdviseHolder.
1128 * See Windows documentation for more details on IDataObject methods.
1130 static HRESULT WINAPI DefaultHandler_DAdvise(
1131 IDataObject* iface,
1132 FORMATETC* pformatetc,
1133 DWORD advf,
1134 IAdviseSink* pAdvSink,
1135 DWORD* pdwConnection)
1137 HRESULT hres = S_OK;
1138 DefaultHandler *This = impl_from_IDataObject(iface);
1140 TRACE("(%p, %p, %d, %p, %p)\n",
1141 iface, pformatetc, advf, pAdvSink, pdwConnection);
1143 /* Make sure we have a data advise holder before we start. */
1144 if (!This->dataAdviseHolder)
1146 hres = CreateDataAdviseHolder(&This->dataAdviseHolder);
1147 if (SUCCEEDED(hres) && This->pDataDelegate)
1148 DataAdviseHolder_OnConnect(This->dataAdviseHolder, This->pDataDelegate);
1151 if (SUCCEEDED(hres))
1152 hres = IDataAdviseHolder_Advise(This->dataAdviseHolder,
1153 iface,
1154 pformatetc,
1155 advf,
1156 pAdvSink,
1157 pdwConnection);
1159 return hres;
1162 /************************************************************************
1163 * DefaultHandler_DUnadvise (IDataObject)
1165 * The default handler's implementation of this method simply
1166 * delegates to the DataAdviseHolder.
1168 * See Windows documentation for more details on IDataObject methods.
1170 static HRESULT WINAPI DefaultHandler_DUnadvise(
1171 IDataObject* iface,
1172 DWORD dwConnection)
1174 DefaultHandler *This = impl_from_IDataObject(iface);
1176 TRACE("(%p, %d)\n", iface, dwConnection);
1179 * If we don't have a data advise holder yet, it means that
1180 * we don't have any connections..
1182 if (!This->dataAdviseHolder)
1183 return OLE_E_NOCONNECTION;
1185 return IDataAdviseHolder_Unadvise(This->dataAdviseHolder,
1186 dwConnection);
1189 /************************************************************************
1190 * DefaultHandler_EnumDAdvise (IDataObject)
1192 * The default handler's implementation of this method simply
1193 * delegates to the DataAdviseHolder.
1195 * See Windows documentation for more details on IDataObject methods.
1197 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
1198 IDataObject* iface,
1199 IEnumSTATDATA** ppenumAdvise)
1201 DefaultHandler *This = impl_from_IDataObject(iface);
1203 TRACE("(%p, %p)\n", iface, ppenumAdvise);
1205 /* Sanity check */
1206 if (!ppenumAdvise)
1207 return E_POINTER;
1209 *ppenumAdvise = NULL;
1211 /* If we have a data advise holder object, delegate. */
1212 if (This->dataAdviseHolder)
1213 return IDataAdviseHolder_EnumAdvise(This->dataAdviseHolder,
1214 ppenumAdvise);
1216 return S_OK;
1219 /*********************************************************
1220 * Methods implementation for the IRunnableObject part
1221 * of the DefaultHandler class.
1224 /************************************************************************
1225 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1227 * See Windows documentation for more details on IUnknown methods.
1229 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
1230 IRunnableObject* iface,
1231 REFIID riid,
1232 void** ppvObject)
1234 DefaultHandler *This = impl_from_IRunnableObject(iface);
1236 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
1239 /************************************************************************
1240 * DefaultHandler_IRunnableObject_AddRef (IUnknown)
1242 * See Windows documentation for more details on IUnknown methods.
1244 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef(
1245 IRunnableObject* iface)
1247 DefaultHandler *This = impl_from_IRunnableObject(iface);
1249 return IUnknown_AddRef(This->outerUnknown);
1252 /************************************************************************
1253 * DefaultHandler_IRunnableObject_Release (IUnknown)
1255 * See Windows documentation for more details on IUnknown methods.
1257 static ULONG WINAPI DefaultHandler_IRunnableObject_Release(
1258 IRunnableObject* iface)
1260 DefaultHandler *This = impl_from_IRunnableObject(iface);
1262 return IUnknown_Release(This->outerUnknown);
1265 /************************************************************************
1266 * DefaultHandler_GetRunningClass (IRunnableObject)
1268 * See Windows documentation for more details on IRunnableObject methods.
1270 static HRESULT WINAPI DefaultHandler_GetRunningClass(
1271 IRunnableObject* iface,
1272 LPCLSID lpClsid)
1274 FIXME("()\n");
1275 return S_OK;
1278 static HRESULT WINAPI DefaultHandler_Run(
1279 IRunnableObject* iface,
1280 IBindCtx* pbc)
1282 DefaultHandler *This = impl_from_IRunnableObject(iface);
1283 HRESULT hr;
1285 FIXME("(%p): semi-stub\n", pbc);
1287 /* already running? if so nothing to do */
1288 if (object_is_running(This))
1289 return S_OK;
1291 hr = CoCreateInstance(&This->clsid, NULL, CLSCTX_LOCAL_SERVER,
1292 &IID_IOleObject, (void **)&This->pOleDelegate);
1293 if (FAILED(hr))
1294 return hr;
1296 hr = IOleObject_Advise(This->pOleDelegate,
1297 (IAdviseSink *)&This->lpvtblIAdviseSink,
1298 &This->dwAdvConn);
1300 if (SUCCEEDED(hr) && This->clientSite)
1301 hr = IOleObject_SetClientSite(This->pOleDelegate, This->clientSite);
1303 if (SUCCEEDED(hr))
1305 IOleObject_QueryInterface(This->pOleDelegate, &IID_IPersistStorage,
1306 (void **)&This->pPSDelegate);
1307 if (This->pPSDelegate)
1308 hr = IPersistStorage_InitNew(This->pPSDelegate, NULL);
1311 if (SUCCEEDED(hr) && This->containerApp)
1312 hr = IOleObject_SetHostNames(This->pOleDelegate, This->containerApp,
1313 This->containerObj);
1315 /* FIXME: do more stuff here:
1316 * - IOleObject_GetMiscStatus
1317 * - IOleObject_GetMoniker
1318 * - IOleCache_OnRun
1321 if (SUCCEEDED(hr))
1322 hr = IOleObject_QueryInterface(This->pOleDelegate, &IID_IDataObject,
1323 (void **)&This->pDataDelegate);
1325 if (SUCCEEDED(hr) && This->dataAdviseHolder)
1326 hr = DataAdviseHolder_OnConnect(This->dataAdviseHolder, This->pDataDelegate);
1328 if (FAILED(hr))
1329 DefaultHandler_Stop(This);
1331 return hr;
1334 /************************************************************************
1335 * DefaultHandler_IsRunning (IRunnableObject)
1337 * See Windows documentation for more details on IRunnableObject methods.
1339 static BOOL WINAPI DefaultHandler_IsRunning(
1340 IRunnableObject* iface)
1342 DefaultHandler *This = impl_from_IRunnableObject(iface);
1344 TRACE("()\n");
1346 if (This->pOleDelegate)
1347 return TRUE;
1348 else
1349 return FALSE;
1352 /************************************************************************
1353 * DefaultHandler_LockRunning (IRunnableObject)
1355 * See Windows documentation for more details on IRunnableObject methods.
1357 static HRESULT WINAPI DefaultHandler_LockRunning(
1358 IRunnableObject* iface,
1359 BOOL fLock,
1360 BOOL fLastUnlockCloses)
1362 FIXME("()\n");
1363 return S_OK;
1366 /************************************************************************
1367 * DefaultHandler_SetContainedObject (IRunnableObject)
1369 * See Windows documentation for more details on IRunnableObject methods.
1371 static HRESULT WINAPI DefaultHandler_SetContainedObject(
1372 IRunnableObject* iface,
1373 BOOL fContained)
1375 FIXME("()\n");
1376 return S_OK;
1379 static HRESULT WINAPI DefaultHandler_IAdviseSink_QueryInterface(
1380 IAdviseSink *iface,
1381 REFIID riid,
1382 void **ppvObject)
1384 if (IsEqualIID(riid, &IID_IUnknown) ||
1385 IsEqualIID(riid, &IID_IAdviseSink))
1387 *ppvObject = iface;
1388 IAdviseSink_AddRef(iface);
1389 return S_OK;
1392 return E_NOINTERFACE;
1395 static ULONG WINAPI DefaultHandler_IAdviseSink_AddRef(
1396 IAdviseSink *iface)
1398 DefaultHandler *This = impl_from_IAdviseSink(iface);
1400 return IUnknown_AddRef((IUnknown *)&This->lpvtblIUnknown);
1403 static ULONG WINAPI DefaultHandler_IAdviseSink_Release(
1404 IAdviseSink *iface)
1406 DefaultHandler *This = impl_from_IAdviseSink(iface);
1408 return IUnknown_Release((IUnknown *)&This->lpvtblIUnknown);
1411 static void WINAPI DefaultHandler_IAdviseSink_OnDataChange(
1412 IAdviseSink *iface,
1413 FORMATETC *pFormatetc,
1414 STGMEDIUM *pStgmed)
1416 FIXME(": stub\n");
1419 static void WINAPI DefaultHandler_IAdviseSink_OnViewChange(
1420 IAdviseSink *iface,
1421 DWORD dwAspect,
1422 LONG lindex)
1424 FIXME(": stub\n");
1427 static void WINAPI DefaultHandler_IAdviseSink_OnRename(
1428 IAdviseSink *iface,
1429 IMoniker *pmk)
1431 DefaultHandler *This = impl_from_IAdviseSink(iface);
1433 TRACE("(%p)\n", pmk);
1435 if (This->oleAdviseHolder)
1436 IOleAdviseHolder_SendOnRename(This->oleAdviseHolder, pmk);
1439 static void WINAPI DefaultHandler_IAdviseSink_OnSave(
1440 IAdviseSink *iface)
1442 DefaultHandler *This = impl_from_IAdviseSink(iface);
1444 TRACE("()\n");
1446 if (This->oleAdviseHolder)
1447 IOleAdviseHolder_SendOnSave(This->oleAdviseHolder);
1450 static void WINAPI DefaultHandler_IAdviseSink_OnClose(
1451 IAdviseSink *iface)
1453 DefaultHandler *This = impl_from_IAdviseSink(iface);
1455 TRACE("()\n");
1457 if (This->oleAdviseHolder)
1458 IOleAdviseHolder_SendOnClose(This->oleAdviseHolder);
1460 DefaultHandler_Stop(This);
1464 /************************************************************************
1465 * DefaultHandler_IPersistStorage_QueryInterface
1468 static HRESULT WINAPI DefaultHandler_IPersistStorage_QueryInterface(
1469 IPersistStorage* iface,
1470 REFIID riid,
1471 void** ppvObject)
1473 DefaultHandler *This = impl_from_IPersistStorage(iface);
1475 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
1478 /************************************************************************
1479 * DefaultHandler_IPersistStorage_AddRef
1482 static ULONG WINAPI DefaultHandler_IPersistStorage_AddRef(
1483 IPersistStorage* iface)
1485 DefaultHandler *This = impl_from_IPersistStorage(iface);
1487 return IUnknown_AddRef(This->outerUnknown);
1490 /************************************************************************
1491 * DefaultHandler_IPersistStorage_Release
1494 static ULONG WINAPI DefaultHandler_IPersistStorage_Release(
1495 IPersistStorage* iface)
1497 DefaultHandler *This = impl_from_IPersistStorage(iface);
1499 return IUnknown_Release(This->outerUnknown);
1502 /************************************************************************
1503 * DefaultHandler_IPersistStorage_GetClassID
1506 static HRESULT WINAPI DefaultHandler_IPersistStorage_GetClassID(
1507 IPersistStorage* iface,
1508 CLSID* clsid)
1510 DefaultHandler *This = impl_from_IPersistStorage(iface);
1512 return IPersistStorage_GetClassID(This->dataCache_PersistStg, clsid);
1515 /************************************************************************
1516 * DefaultHandler_IPersistStorage_IsDirty
1519 static HRESULT WINAPI DefaultHandler_IPersistStorage_IsDirty(
1520 IPersistStorage* iface)
1522 DefaultHandler *This = impl_from_IPersistStorage(iface);
1524 return IPersistStorage_IsDirty(This->dataCache_PersistStg);
1527 /************************************************************************
1528 * DefaultHandler_IPersistStorage_InitNew
1531 static HRESULT WINAPI DefaultHandler_IPersistStorage_InitNew(
1532 IPersistStorage* iface,
1533 IStorage* pStg)
1535 DefaultHandler *This = impl_from_IPersistStorage(iface);
1537 return IPersistStorage_InitNew(This->dataCache_PersistStg, pStg);
1541 /************************************************************************
1542 * DefaultHandler_IPersistStorage_Load
1545 static HRESULT WINAPI DefaultHandler_IPersistStorage_Load(
1546 IPersistStorage* iface,
1547 IStorage* pStg)
1549 DefaultHandler *This = impl_from_IPersistStorage(iface);
1551 return IPersistStorage_Load(This->dataCache_PersistStg, pStg);
1555 /************************************************************************
1556 * DefaultHandler_IPersistStorage_Save
1559 static HRESULT WINAPI DefaultHandler_IPersistStorage_Save(
1560 IPersistStorage* iface,
1561 IStorage* pStgSave,
1562 BOOL fSaveAsLoad)
1564 DefaultHandler *This = impl_from_IPersistStorage(iface);
1566 return IPersistStorage_Save(This->dataCache_PersistStg, pStgSave, fSaveAsLoad);
1570 /************************************************************************
1571 * DefaultHandler_IPersistStorage_SaveCompleted
1574 static HRESULT WINAPI DefaultHandler_IPersistStorage_SaveCompleted(
1575 IPersistStorage* iface,
1576 IStorage* pStgNew)
1578 DefaultHandler *This = impl_from_IPersistStorage(iface);
1580 return IPersistStorage_SaveCompleted(This->dataCache_PersistStg, pStgNew);
1584 /************************************************************************
1585 * DefaultHandler_IPersistStorage_HandsOffStorage
1588 static HRESULT WINAPI DefaultHandler_IPersistStorage_HandsOffStorage(
1589 IPersistStorage* iface)
1591 DefaultHandler *This = impl_from_IPersistStorage(iface);
1593 return IPersistStorage_HandsOffStorage(This->dataCache_PersistStg);
1598 * Virtual function tables for the DefaultHandler class.
1600 static const IOleObjectVtbl DefaultHandler_IOleObject_VTable =
1602 DefaultHandler_QueryInterface,
1603 DefaultHandler_AddRef,
1604 DefaultHandler_Release,
1605 DefaultHandler_SetClientSite,
1606 DefaultHandler_GetClientSite,
1607 DefaultHandler_SetHostNames,
1608 DefaultHandler_Close,
1609 DefaultHandler_SetMoniker,
1610 DefaultHandler_GetMoniker,
1611 DefaultHandler_InitFromData,
1612 DefaultHandler_GetClipboardData,
1613 DefaultHandler_DoVerb,
1614 DefaultHandler_EnumVerbs,
1615 DefaultHandler_Update,
1616 DefaultHandler_IsUpToDate,
1617 DefaultHandler_GetUserClassID,
1618 DefaultHandler_GetUserType,
1619 DefaultHandler_SetExtent,
1620 DefaultHandler_GetExtent,
1621 DefaultHandler_Advise,
1622 DefaultHandler_Unadvise,
1623 DefaultHandler_EnumAdvise,
1624 DefaultHandler_GetMiscStatus,
1625 DefaultHandler_SetColorScheme
1628 static const IUnknownVtbl DefaultHandler_NDIUnknown_VTable =
1630 DefaultHandler_NDIUnknown_QueryInterface,
1631 DefaultHandler_NDIUnknown_AddRef,
1632 DefaultHandler_NDIUnknown_Release,
1635 static const IDataObjectVtbl DefaultHandler_IDataObject_VTable =
1637 DefaultHandler_IDataObject_QueryInterface,
1638 DefaultHandler_IDataObject_AddRef,
1639 DefaultHandler_IDataObject_Release,
1640 DefaultHandler_GetData,
1641 DefaultHandler_GetDataHere,
1642 DefaultHandler_QueryGetData,
1643 DefaultHandler_GetCanonicalFormatEtc,
1644 DefaultHandler_SetData,
1645 DefaultHandler_EnumFormatEtc,
1646 DefaultHandler_DAdvise,
1647 DefaultHandler_DUnadvise,
1648 DefaultHandler_EnumDAdvise
1651 static const IRunnableObjectVtbl DefaultHandler_IRunnableObject_VTable =
1653 DefaultHandler_IRunnableObject_QueryInterface,
1654 DefaultHandler_IRunnableObject_AddRef,
1655 DefaultHandler_IRunnableObject_Release,
1656 DefaultHandler_GetRunningClass,
1657 DefaultHandler_Run,
1658 DefaultHandler_IsRunning,
1659 DefaultHandler_LockRunning,
1660 DefaultHandler_SetContainedObject
1663 static const IAdviseSinkVtbl DefaultHandler_IAdviseSink_VTable =
1665 DefaultHandler_IAdviseSink_QueryInterface,
1666 DefaultHandler_IAdviseSink_AddRef,
1667 DefaultHandler_IAdviseSink_Release,
1668 DefaultHandler_IAdviseSink_OnDataChange,
1669 DefaultHandler_IAdviseSink_OnViewChange,
1670 DefaultHandler_IAdviseSink_OnRename,
1671 DefaultHandler_IAdviseSink_OnSave,
1672 DefaultHandler_IAdviseSink_OnClose
1675 static const IPersistStorageVtbl DefaultHandler_IPersistStorage_VTable =
1677 DefaultHandler_IPersistStorage_QueryInterface,
1678 DefaultHandler_IPersistStorage_AddRef,
1679 DefaultHandler_IPersistStorage_Release,
1680 DefaultHandler_IPersistStorage_GetClassID,
1681 DefaultHandler_IPersistStorage_IsDirty,
1682 DefaultHandler_IPersistStorage_InitNew,
1683 DefaultHandler_IPersistStorage_Load,
1684 DefaultHandler_IPersistStorage_Save,
1685 DefaultHandler_IPersistStorage_SaveCompleted,
1686 DefaultHandler_IPersistStorage_HandsOffStorage
1689 /*********************************************************
1690 * Methods implementation for the DefaultHandler class.
1692 static DefaultHandler* DefaultHandler_Construct(
1693 REFCLSID clsid,
1694 LPUNKNOWN pUnkOuter)
1696 DefaultHandler* This = NULL;
1697 HRESULT hr;
1700 * Allocate space for the object.
1702 This = HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler));
1704 if (!This)
1705 return This;
1707 This->lpVtbl = &DefaultHandler_IOleObject_VTable;
1708 This->lpvtblIUnknown = &DefaultHandler_NDIUnknown_VTable;
1709 This->lpvtblIDataObject = &DefaultHandler_IDataObject_VTable;
1710 This->lpvtblIRunnableObject = &DefaultHandler_IRunnableObject_VTable;
1711 This->lpvtblIAdviseSink = &DefaultHandler_IAdviseSink_VTable;
1712 This->lpvtblIPersistStorage = &DefaultHandler_IPersistStorage_VTable;
1715 * Start with one reference count. The caller of this function
1716 * must release the interface pointer when it is done.
1718 This->ref = 1;
1721 * Initialize the outer unknown
1722 * We don't keep a reference on the outer unknown since, the way
1723 * aggregation works, our lifetime is at least as large as its
1724 * lifetime.
1726 if (!pUnkOuter)
1727 pUnkOuter = (IUnknown*)&This->lpvtblIUnknown;
1729 This->outerUnknown = pUnkOuter;
1732 * Create a datacache object.
1733 * We aggregate with the datacache. Make sure we pass our outer
1734 * unknown as the datacache's outer unknown.
1736 hr = CreateDataCache(This->outerUnknown,
1737 clsid,
1738 &IID_IUnknown,
1739 (void**)&This->dataCache);
1740 if(SUCCEEDED(hr))
1741 hr = IUnknown_QueryInterface(This->dataCache, &IID_IPersistStorage, (void**)&This->dataCache_PersistStg);
1742 if(FAILED(hr))
1743 ERR("Unexpected error creating data cache\n");
1745 * Initialize the other data members of the class.
1747 memcpy(&This->clsid, clsid, sizeof(CLSID));
1748 This->clientSite = NULL;
1749 This->oleAdviseHolder = NULL;
1750 This->dataAdviseHolder = NULL;
1751 This->containerApp = NULL;
1752 This->containerObj = NULL;
1753 This->pOleDelegate = NULL;
1754 This->pPSDelegate = NULL;
1755 This->pDataDelegate = NULL;
1757 This->dwAdvConn = 0;
1759 return This;
1762 static void DefaultHandler_Destroy(
1763 DefaultHandler* This)
1765 /* release delegates */
1766 DefaultHandler_Stop(This);
1768 /* Free the strings idenfitying the object */
1769 HeapFree( GetProcessHeap(), 0, This->containerApp );
1770 This->containerApp = NULL;
1771 HeapFree( GetProcessHeap(), 0, This->containerObj );
1772 This->containerObj = NULL;
1774 /* Release our reference to the data cache. */
1775 if (This->dataCache)
1777 IPersistStorage_Release(This->dataCache_PersistStg);
1778 IUnknown_Release(This->dataCache);
1779 This->dataCache_PersistStg = NULL;
1780 This->dataCache = NULL;
1783 /* Same thing for the client site. */
1784 if (This->clientSite)
1786 IOleClientSite_Release(This->clientSite);
1787 This->clientSite = NULL;
1790 /* And the advise holder. */
1791 if (This->oleAdviseHolder)
1793 IOleAdviseHolder_Release(This->oleAdviseHolder);
1794 This->oleAdviseHolder = NULL;
1797 /* And the data advise holder. */
1798 if (This->dataAdviseHolder)
1800 IDataAdviseHolder_Release(This->dataAdviseHolder);
1801 This->dataAdviseHolder = NULL;
1804 /* Free the actual default handler structure. */
1805 HeapFree(GetProcessHeap(), 0, This);
1808 /******************************************************************************
1809 * OleCreateDefaultHandler [OLE32.@]
1811 HRESULT WINAPI OleCreateDefaultHandler(
1812 REFCLSID clsid,
1813 LPUNKNOWN pUnkOuter,
1814 REFIID riid,
1815 LPVOID* ppvObj)
1817 DefaultHandler* newHandler = NULL;
1818 HRESULT hr = S_OK;
1820 TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid), pUnkOuter, debugstr_guid(riid), ppvObj);
1823 * Sanity check
1825 if (!ppvObj)
1826 return E_POINTER;
1828 *ppvObj = NULL;
1831 * If This handler is constructed for aggregation, make sure
1832 * the caller is requesting the IUnknown interface.
1833 * This is necessary because it's the only time the non-delegating
1834 * IUnknown pointer can be returned to the outside.
1836 if (pUnkOuter && !IsEqualIID(&IID_IUnknown, riid))
1837 return CLASS_E_NOAGGREGATION;
1840 * Try to construct a new instance of the class.
1842 newHandler = DefaultHandler_Construct(clsid, pUnkOuter);
1844 if (!newHandler)
1845 return E_OUTOFMEMORY;
1848 * Make sure it supports the interface required by the caller.
1850 hr = IUnknown_QueryInterface((IUnknown*)&newHandler->lpvtblIUnknown, riid, ppvObj);
1853 * Release the reference obtained in the constructor. If
1854 * the QueryInterface was unsuccessful, it will free the class.
1856 IUnknown_Release((IUnknown*)&newHandler->lpvtblIUnknown);
1858 return hr;