Define __fastcall.
[wine] / dlls / ole32 / defaulthandler.c
1 /*
2  *      OLE 2 default object handler
3  *
4  *      Copyright 1999  Francis Beaudet
5  *
6  * NOTES:
7  *    The OLE2 default object handler supports a whole whack of
8  *    interfaces including:
9  *       IOleObject, IDataObject, IPersistStorage, IViewObject2,
10  *       IRunnableObject, IOleCache2, IOleCacheControl and much more.
11  *
12  *    All the implementation details are taken from: Inside OLE
13  *    second edition by Kraig Brockschmidt,
14  *
15  * TODO
16  * - This implementation of the default handler does not launch the
17  *   server in the DoVerb, Update, GetData, GetDataHere and Run
18  *   methods. When it is fixed to do so, all the methods will have
19  *   to be  revisited to allow delegating to the running object
20  *
21  * - All methods in the class that use the class ID should be
22  *   aware that it is possible for a class to be treated as
23  *   another one and go into emulation mode. Nothing has been
24  *   done in this area.
25  *
26  * - Some functions still return E_NOTIMPL they have to be 
27  *   implemented. Most of those are related to the running of the
28  *   actual server.
29  *
30  * - All the methods related to notification and advise sinks are
31  *   in place but no notifications are sent to the sinks yet.
32  */
33 #include <assert.h>
34
35 #include "winbase.h"
36 #include "winerror.h"
37 #include "ole2.h"
38 #include "wine/obj_oleview.h"
39 #include "debugtools.h"
40
41 DEFAULT_DEBUG_CHANNEL(ole)
42
43 /****************************************************************************
44  * DefaultHandler
45  *
46  */
47 struct DefaultHandler
48 {
49   /*
50    * List all interface VTables here
51    */
52   ICOM_VTABLE(IOleObject)*      lpvtbl1; 
53   ICOM_VTABLE(IUnknown)*        lpvtbl2;
54   ICOM_VTABLE(IDataObject)*     lpvtbl3;
55   ICOM_VTABLE(IRunnableObject)* lpvtbl4;
56
57   /*
58    * Reference count of this object
59    */
60   ULONG ref;
61
62   /*
63    * IUnknown implementation of the outer object.
64    */
65   IUnknown* outerUnknown;
66
67   /*
68    * Class Id that this handler object represents.
69    */
70   CLSID clsid;
71
72   /*
73    * IUnknown implementation of the datacache.
74    */
75   IUnknown* dataCache;
76
77   /*
78    * Client site for the embedded object.
79    */
80   IOleClientSite* clientSite;
81
82   /*
83    * The IOleAdviseHolder maintains the connections
84    * on behalf of the default handler.
85    */
86   IOleAdviseHolder* oleAdviseHolder;
87
88   /*
89    * The IDataAdviseHolder maintains the data 
90    * connections on behalf of the default handler.
91    */
92   IDataAdviseHolder* dataAdviseHolder;
93
94   /*
95    * Name of the container and object contained
96    */
97   LPWSTR containerApp; 
98   LPWSTR containerObj;
99
100 };
101
102 typedef struct DefaultHandler DefaultHandler;
103
104 /*
105  * Here, I define utility macros to help with the casting of the 
106  * "this" parameter.
107  * There is a version to accomodate all of the VTables implemented
108  * by this object.
109  */
110 #define _ICOM_THIS_From_IOleObject(class,name)       class* this = (class*)name;
111 #define _ICOM_THIS_From_NDIUnknown(class, name)      class* this = (class*)(((char*)name)-sizeof(void*)); 
112 #define _ICOM_THIS_From_IDataObject(class, name)     class* this = (class*)(((char*)name)-2*sizeof(void*)); 
113 #define _ICOM_THIS_From_IRunnableObject(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*)); 
114
115 /*
116  * Prototypes for the methods of the DefaultHandler class.
117  */
118 static DefaultHandler* DefaultHandler_Construct(REFCLSID  clsid,
119                                                 LPUNKNOWN pUnkOuter);
120 static void            DefaultHandler_Destroy(DefaultHandler* ptrToDestroy);
121
122 /*
123  * Prototypes for the methods of the DefaultHandler class
124  * that implement non delegating IUnknown methods.
125  */
126 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
127             IUnknown*      iface,
128             REFIID         riid,
129             void**         ppvObject);
130 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef( 
131             IUnknown*      iface);
132 static ULONG WINAPI DefaultHandler_NDIUnknown_Release( 
133             IUnknown*      iface);
134
135 /*
136  * Prototypes for the methods of the DefaultHandler class
137  * that implement IOleObject methods.
138  */
139 static HRESULT WINAPI DefaultHandler_QueryInterface(
140             IOleObject*      iface,
141             REFIID           riid,
142             void**           ppvObject);
143 static ULONG WINAPI DefaultHandler_AddRef( 
144             IOleObject*        iface);
145 static ULONG WINAPI DefaultHandler_Release( 
146             IOleObject*        iface);
147 static HRESULT WINAPI DefaultHandler_SetClientSite(
148             IOleObject*        iface,
149             IOleClientSite*    pClientSite);
150 static HRESULT WINAPI DefaultHandler_GetClientSite(
151             IOleObject*        iface,
152             IOleClientSite**   ppClientSite);
153 static HRESULT WINAPI DefaultHandler_SetHostNames(
154             IOleObject*        iface,
155             LPCOLESTR          szContainerApp, 
156             LPCOLESTR          szContainerObj);
157 static HRESULT WINAPI DefaultHandler_Close(
158             IOleObject*        iface, 
159             DWORD              dwSaveOption);
160 static HRESULT WINAPI DefaultHandler_SetMoniker(
161             IOleObject*        iface, 
162             DWORD              dwWhichMoniker,
163             IMoniker*          pmk);
164 static HRESULT WINAPI DefaultHandler_GetMoniker(
165             IOleObject*        iface,
166             DWORD              dwAssign,
167             DWORD              dwWhichMoniker,
168             IMoniker**         ppmk);
169 static HRESULT WINAPI DefaultHandler_InitFromData(
170             IOleObject*        iface, 
171             IDataObject*       pDataObject, 
172             BOOL               fCreation,
173             DWORD              dwReserved);
174 static HRESULT WINAPI DefaultHandler_GetClipboardData(
175             IOleObject*        iface, 
176             DWORD              dwReserved, 
177             IDataObject**      ppDataObject);
178 static HRESULT WINAPI DefaultHandler_DoVerb(
179             IOleObject*        iface, 
180             LONG               iVerb, 
181             struct tagMSG*     lpmsg, 
182             IOleClientSite*    pActiveSite, 
183             LONG               lindex, 
184             HWND               hwndParent, 
185             LPCRECT            lprcPosRect);
186 static HRESULT WINAPI DefaultHandler_EnumVerbs(
187             IOleObject*        iface, 
188             IEnumOLEVERB**     ppEnumOleVerb);
189 static HRESULT WINAPI DefaultHandler_Update(
190             IOleObject*        iface);
191 static HRESULT WINAPI DefaultHandler_IsUpToDate(
192             IOleObject*        iface);
193 static HRESULT WINAPI DefaultHandler_GetUserClassID(
194             IOleObject*        iface, 
195             CLSID*             pClsid);
196 static HRESULT WINAPI DefaultHandler_GetUserType(
197             IOleObject*        iface, 
198             DWORD              dwFormOfType, 
199             LPOLESTR*          pszUserType);
200 static HRESULT WINAPI DefaultHandler_SetExtent(
201             IOleObject*        iface, 
202             DWORD              dwDrawAspect, 
203             SIZEL*             psizel);
204 static HRESULT WINAPI DefaultHandler_GetExtent(
205             IOleObject*        iface, 
206             DWORD              dwDrawAspect, 
207             SIZEL*             psizel);
208 static HRESULT WINAPI DefaultHandler_Advise(
209             IOleObject*        iface, 
210             IAdviseSink*       pAdvSink, 
211             DWORD*             pdwConnection);
212 static HRESULT WINAPI DefaultHandler_Unadvise(
213             IOleObject*        iface, 
214             DWORD              dwConnection);
215 static HRESULT WINAPI DefaultHandler_EnumAdvise(
216             IOleObject*        iface, 
217             IEnumSTATDATA**    ppenumAdvise);
218 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
219             IOleObject*        iface, 
220             DWORD              dwAspect, 
221             DWORD*             pdwStatus);
222 static HRESULT WINAPI DefaultHandler_SetColorScheme(
223             IOleObject*           iface,
224             struct tagLOGPALETTE* pLogpal);
225
226 /*
227  * Prototypes for the methods of the DefaultHandler class
228  * that implement IDataObject methods.
229  */
230 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
231             IDataObject*     iface,
232             REFIID           riid,
233             void**           ppvObject);
234 static ULONG WINAPI DefaultHandler_IDataObject_AddRef( 
235             IDataObject*     iface);
236 static ULONG WINAPI DefaultHandler_IDataObject_Release( 
237             IDataObject*     iface);
238 static HRESULT WINAPI DefaultHandler_GetData(
239             IDataObject*     iface,
240             LPFORMATETC      pformatetcIn, 
241             STGMEDIUM*       pmedium);
242 static HRESULT WINAPI DefaultHandler_GetDataHere(
243             IDataObject*     iface, 
244             LPFORMATETC      pformatetc,
245             STGMEDIUM*       pmedium);
246 static HRESULT WINAPI DefaultHandler_QueryGetData(
247             IDataObject*     iface,
248             LPFORMATETC      pformatetc);
249 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
250             IDataObject*     iface, 
251             LPFORMATETC      pformatectIn, 
252             LPFORMATETC      pformatetcOut);
253 static HRESULT WINAPI DefaultHandler_SetData(
254             IDataObject*     iface,
255             LPFORMATETC      pformatetc, 
256             STGMEDIUM*       pmedium, 
257             BOOL             fRelease);
258 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
259             IDataObject*     iface,       
260             DWORD            dwDirection,
261             IEnumFORMATETC** ppenumFormatEtc);
262 static HRESULT WINAPI DefaultHandler_DAdvise(
263             IDataObject*     iface, 
264             FORMATETC*       pformatetc, 
265             DWORD            advf, 
266             IAdviseSink*     pAdvSink, 
267             DWORD*           pdwConnection);
268 static HRESULT WINAPI DefaultHandler_DUnadvise(
269             IDataObject*     iface,
270             DWORD            dwConnection);
271 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
272             IDataObject*     iface,
273             IEnumSTATDATA**  ppenumAdvise);
274
275 /*
276  * Prototypes for the methods of the DefaultHandler class
277  * that implement IRunnableObject methods.
278  */
279 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
280             IRunnableObject*     iface,
281             REFIID               riid,
282             void**               ppvObject);
283 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef( 
284             IRunnableObject*     iface);
285 static ULONG WINAPI DefaultHandler_IRunnableObject_Release( 
286             IRunnableObject*     iface);
287 static HRESULT WINAPI DefaultHandler_GetRunningClass( 
288             IRunnableObject*     iface,   
289             LPCLSID              lpClsid);
290 static HRESULT WINAPI DefaultHandler_Run( 
291             IRunnableObject*     iface,
292             IBindCtx*            pbc);
293 static BOOL    WINAPI DefaultHandler_IsRunning( 
294             IRunnableObject*     iface);
295 static HRESULT WINAPI DefaultHandler_LockRunning( 
296             IRunnableObject*     iface, 
297             BOOL                 fLock, 
298             BOOL                 fLastUnlockCloses);
299 static HRESULT WINAPI DefaultHandler_SetContainedObject( 
300             IRunnableObject*     iface, 
301             BOOL                 fContained);
302
303
304 /*
305  * Virtual function tables for the DefaultHandler class.
306  */
307 static ICOM_VTABLE(IOleObject) DefaultHandler_IOleObject_VTable =
308 {
309   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
310   DefaultHandler_QueryInterface,
311   DefaultHandler_AddRef,
312   DefaultHandler_Release,
313   DefaultHandler_SetClientSite,
314   DefaultHandler_GetClientSite,
315   DefaultHandler_SetHostNames,
316   DefaultHandler_Close,
317   DefaultHandler_SetMoniker,
318   DefaultHandler_GetMoniker,
319   DefaultHandler_InitFromData,
320   DefaultHandler_GetClipboardData,
321   DefaultHandler_DoVerb,
322   DefaultHandler_EnumVerbs,
323   DefaultHandler_Update,
324   DefaultHandler_IsUpToDate,
325   DefaultHandler_GetUserClassID,
326   DefaultHandler_GetUserType,
327   DefaultHandler_SetExtent,
328   DefaultHandler_GetExtent,
329   DefaultHandler_Advise,
330   DefaultHandler_Unadvise,
331   DefaultHandler_EnumAdvise,
332   DefaultHandler_GetMiscStatus,
333   DefaultHandler_SetColorScheme
334 };
335
336 static ICOM_VTABLE(IUnknown) DefaultHandler_NDIUnknown_VTable =
337 {
338   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
339   DefaultHandler_NDIUnknown_QueryInterface,
340   DefaultHandler_NDIUnknown_AddRef,
341   DefaultHandler_NDIUnknown_Release,
342 };
343
344 static ICOM_VTABLE(IDataObject) DefaultHandler_IDataObject_VTable =
345 {
346   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
347   DefaultHandler_IDataObject_QueryInterface,
348   DefaultHandler_IDataObject_AddRef,
349   DefaultHandler_IDataObject_Release,
350   DefaultHandler_GetData,
351   DefaultHandler_GetDataHere,
352   DefaultHandler_QueryGetData,
353   DefaultHandler_GetCanonicalFormatEtc,
354   DefaultHandler_SetData,
355   DefaultHandler_EnumFormatEtc,
356   DefaultHandler_DAdvise,
357   DefaultHandler_DUnadvise,
358   DefaultHandler_EnumDAdvise
359 };
360
361 static ICOM_VTABLE(IRunnableObject) DefaultHandler_IRunnableObject_VTable =
362 {
363   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
364   DefaultHandler_IRunnableObject_QueryInterface,
365   DefaultHandler_IRunnableObject_AddRef,
366   DefaultHandler_IRunnableObject_Release,
367   DefaultHandler_GetRunningClass,
368   DefaultHandler_Run,
369   DefaultHandler_IsRunning,
370   DefaultHandler_LockRunning,
371   DefaultHandler_SetContainedObject
372 };
373
374 /******************************************************************************
375  * OleCreateDefaultHandler [OLE32.90]
376  */
377 HRESULT WINAPI OleCreateDefaultHandler(
378   REFCLSID  clsid,
379   LPUNKNOWN pUnkOuter,
380   REFIID    riid,
381   LPVOID*   ppvObj)
382 {
383   DefaultHandler* newHandler = NULL;
384   HRESULT         hr         = S_OK;
385
386   TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid), pUnkOuter, debugstr_guid(riid), ppvObj);
387
388   /*
389    * Sanity check
390    */
391   if (ppvObj==0)
392     return E_POINTER;
393
394   *ppvObj = 0;
395
396   /*
397    * If this handler is constructed for aggregation, make sure
398    * the caller is requesting the IUnknown interface.
399    * This is necessary because it's the only time the non-delegating
400    * IUnknown pointer can be returned to the outside.
401    */
402   if ( (pUnkOuter!=NULL) && 
403        (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) != 0) )
404     return CLASS_E_NOAGGREGATION;
405
406   /*
407    * Try to construct a new instance of the class.
408    */
409   newHandler = DefaultHandler_Construct(clsid, 
410                                         pUnkOuter);
411
412   if (newHandler == 0)
413     return E_OUTOFMEMORY;
414
415   /*
416    * Make sure it supports the interface required by the caller.
417    */
418   hr = IUnknown_QueryInterface((IUnknown*)&(newHandler->lpvtbl2), riid, ppvObj);
419
420   /*
421    * Release the reference obtained in the constructor. If
422    * the QueryInterface was unsuccessful, it will free the class.
423    */
424   IUnknown_Release((IUnknown*)&(newHandler->lpvtbl2));
425
426   return hr;
427 }
428
429 /*********************************************************
430  * Methods implementation for the DefaultHandler class.
431  */
432 static DefaultHandler* DefaultHandler_Construct(
433   REFCLSID  clsid,
434   LPUNKNOWN pUnkOuter)
435 {
436   DefaultHandler* newObject = 0;
437
438   /*
439    * Allocate space for the object.
440    */
441   newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler));
442
443   if (newObject==0)
444     return newObject;
445   
446   /*
447    * Initialize the virtual function table.
448    */
449   newObject->lpvtbl1 = &DefaultHandler_IOleObject_VTable;
450   newObject->lpvtbl2 = &DefaultHandler_NDIUnknown_VTable;
451   newObject->lpvtbl3 = &DefaultHandler_IDataObject_VTable;
452   newObject->lpvtbl4 = &DefaultHandler_IRunnableObject_VTable;
453
454   /*
455    * Start with one reference count. The caller of this function 
456    * must release the interface pointer when it is done.
457    */
458   newObject->ref = 1;
459
460   /*
461    * Initialize the outer unknown
462    * We don't keep a reference on the outer unknown since, the way 
463    * aggregation works, our lifetime is at least as large as it's
464    * lifetime.
465    */
466   if (pUnkOuter==NULL)
467     pUnkOuter = (IUnknown*)&(newObject->lpvtbl2);
468
469   newObject->outerUnknown = pUnkOuter;
470
471   /*
472    * Create a datacache object.
473    * We aggregate with the datacache. Make sure we pass our outer
474    * unknown as the datacache's outer unknown. 
475    */
476   CreateDataCache(newObject->outerUnknown,
477                   clsid,
478                   &IID_IUnknown,
479                   (void**)&newObject->dataCache);
480
481   /*
482    * Initialize the other data members of the class.
483    */
484   memcpy(&(newObject->clsid), clsid, sizeof(CLSID));
485   newObject->clientSite = NULL;
486   newObject->oleAdviseHolder = NULL;
487   newObject->dataAdviseHolder = NULL;
488   newObject->containerApp = NULL;
489   newObject->containerObj = NULL;
490
491   return newObject;
492 }
493
494 static void DefaultHandler_Destroy(
495   DefaultHandler* ptrToDestroy)
496 {
497   /*
498    * Free the strings idenfitying the object
499    */
500   if (ptrToDestroy->containerApp!=NULL)
501   {
502     HeapFree( GetProcessHeap(), 0, ptrToDestroy->containerApp );
503     ptrToDestroy->containerApp = NULL;
504   }
505
506   if (ptrToDestroy->containerObj!=NULL)
507   {
508     HeapFree( GetProcessHeap(), 0, ptrToDestroy->containerObj );
509     ptrToDestroy->containerObj = NULL;
510   }
511   
512   /*
513    * Release our reference to the data cache.
514    */
515   if (ptrToDestroy->dataCache!=NULL)
516   {
517     IUnknown_Release(ptrToDestroy->dataCache);
518     ptrToDestroy->dataCache = NULL;
519   }
520
521   /*
522    * Same thing for the client site.
523    */
524   if (ptrToDestroy->clientSite!=NULL)
525   {
526     IOleClientSite_Release(ptrToDestroy->clientSite);
527     ptrToDestroy->clientSite = NULL;
528   }
529
530   /*
531    * And the advise holder.
532    */
533   if (ptrToDestroy->oleAdviseHolder!=NULL)
534   {
535     IOleAdviseHolder_Release(ptrToDestroy->oleAdviseHolder);
536     ptrToDestroy->oleAdviseHolder = NULL;
537   }
538
539   /*
540    * And the data advise holder.
541    */
542   if (ptrToDestroy->dataAdviseHolder!=NULL)
543   {
544     IDataAdviseHolder_Release(ptrToDestroy->dataAdviseHolder);
545     ptrToDestroy->dataAdviseHolder = NULL;
546   }
547
548
549   /*
550    * Free the actual default handler structure.
551    */
552   HeapFree(GetProcessHeap(), 0, ptrToDestroy);
553 }
554
555 /*********************************************************
556  * Method implementation for the  non delegating IUnknown
557  * part of the DefaultHandler class.
558  */
559
560 /************************************************************************
561  * DefaultHandler_NDIUnknown_QueryInterface (IUnknown)
562  *
563  * See Windows documentation for more details on IUnknown methods.
564  *
565  * This version of QueryInterface will not delegate it's implementation
566  * to the outer unknown.
567  */
568 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
569             IUnknown*      iface,
570             REFIID         riid,
571             void**         ppvObject)
572 {
573   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
574
575   /*
576    * Perform a sanity check on the parameters.
577    */
578   if ( (this==0) || (ppvObject==0) )
579     return E_INVALIDARG;
580   
581   /*
582    * Initialize the return parameter.
583    */
584   *ppvObject = 0;
585
586   /*
587    * Compare the riid with the interface IDs implemented by this object.
588    */
589   if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) 
590   {
591     *ppvObject = iface;
592   }
593   else if (memcmp(&IID_IOleObject, riid, sizeof(IID_IOleObject)) == 0) 
594   {
595     *ppvObject = (IOleObject*)&(this->lpvtbl1);
596   }
597   else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0) 
598   {
599     *ppvObject = (IDataObject*)&(this->lpvtbl3);
600   }
601   else if (memcmp(&IID_IRunnableObject, riid, sizeof(IID_IRunnableObject)) == 0) 
602   {
603     *ppvObject = (IRunnableObject*)&(this->lpvtbl4);
604   }
605   else
606   {
607     /*
608      * Blind aggregate the data cache to "inherit" it's interfaces.
609      */
610     if (IUnknown_QueryInterface(this->dataCache, riid, ppvObject) == S_OK)
611         return S_OK;
612   }
613   
614   /*
615    * Check that we obtained an interface.
616    */
617   if ((*ppvObject)==0)
618   {
619     WARN( "() : asking for un supported interface %s\n", debugstr_guid(riid));
620     return E_NOINTERFACE;
621   }
622   
623   /*
624    * Query Interface always increases the reference count by one when it is
625    * successful. 
626    */
627   IUnknown_AddRef((IUnknown*)*ppvObject);
628
629   return S_OK;;  
630 }
631
632 /************************************************************************
633  * DefaultHandler_NDIUnknown_AddRef (IUnknown)
634  *
635  * See Windows documentation for more details on IUnknown methods.
636  *
637  * This version of QueryInterface will not delegate it's implementation
638  * to the outer unknown.
639  */
640 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef( 
641             IUnknown*      iface)
642 {
643   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
644
645   this->ref++;
646
647   return this->ref;
648 }
649
650 /************************************************************************
651  * DefaultHandler_NDIUnknown_Release (IUnknown)
652  *
653  * See Windows documentation for more details on IUnknown methods.
654  *
655  * This version of QueryInterface will not delegate it's implementation
656  * to the outer unknown.
657  */
658 static ULONG WINAPI DefaultHandler_NDIUnknown_Release( 
659             IUnknown*      iface)
660 {
661   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
662
663   /*
664    * Decrease the reference count on this object.
665    */
666   this->ref--;
667
668   /*
669    * If the reference count goes down to 0, perform suicide.
670    */
671   if (this->ref==0)
672   {
673     DefaultHandler_Destroy(this);
674
675     return 0;
676   }
677   
678   return this->ref;
679 }
680
681 /*********************************************************
682  * Methods implementation for the IOleObject part of
683  * the DefaultHandler class.
684  */
685
686 /************************************************************************
687  * DefaultHandler_QueryInterface (IUnknown)
688  *
689  * See Windows documentation for more details on IUnknown methods.
690  */
691 static HRESULT WINAPI DefaultHandler_QueryInterface(
692             IOleObject*      iface,
693             REFIID           riid,
694             void**           ppvObject)
695 {
696   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
697
698   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);  
699 }
700
701 /************************************************************************
702  * DefaultHandler_AddRef (IUnknown)
703  *
704  * See Windows documentation for more details on IUnknown methods.
705  */
706 static ULONG WINAPI DefaultHandler_AddRef( 
707             IOleObject*        iface)
708 {
709   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
710
711   return IUnknown_AddRef(this->outerUnknown);
712 }
713
714 /************************************************************************
715  * DefaultHandler_Release (IUnknown)
716  *
717  * See Windows documentation for more details on IUnknown methods.
718  */
719 static ULONG WINAPI DefaultHandler_Release( 
720             IOleObject*        iface)
721 {
722   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
723
724   return IUnknown_Release(this->outerUnknown);
725 }
726
727 /************************************************************************
728  * DefaultHandler_SetClientSite (IOleObject)
729  *
730  * The default handler's implementation of this method only keeps the
731  * client site pointer for future reference.
732  *
733  * See Windows documentation for more details on IOleObject methods.
734  */
735 static HRESULT WINAPI DefaultHandler_SetClientSite(
736             IOleObject*        iface,
737             IOleClientSite*    pClientSite)
738 {
739   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
740
741   TRACE("(%p, %p)\n", iface, pClientSite);
742
743   /*
744    * Make sure we release the previous client site if there
745    * was one.
746    */
747   if (this->clientSite!=NULL)
748   {
749     IOleClientSite_Release(this->clientSite);
750   }
751
752   this->clientSite = pClientSite;
753
754   if (this->clientSite!=NULL)
755   {
756     IOleClientSite_AddRef(this->clientSite);
757   }
758
759   return S_OK;
760 }
761
762 /************************************************************************
763  * DefaultHandler_GetClientSite (IOleObject)
764  *
765  * The default handler's implementation of this method returns the
766  * last pointer set in IOleObject_SetClientSite.
767  *
768  * See Windows documentation for more details on IOleObject methods.
769  */
770 static HRESULT WINAPI DefaultHandler_GetClientSite(
771             IOleObject*        iface,
772             IOleClientSite**   ppClientSite)
773 {
774   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
775
776   /*
777    * Sanity check.
778    */
779   if (ppClientSite == NULL)
780     return E_POINTER;
781
782   *ppClientSite = this->clientSite;
783
784   if (this->clientSite != NULL)
785   {
786     IOleClientSite_AddRef(this->clientSite);
787   }
788
789   return S_OK;
790 }
791
792 /************************************************************************
793  * DefaultHandler_SetHostNames (IOleObject)
794  *
795  * The default handler's implementation of this method just stores
796  * the strings and returns S_OK.
797  *
798  * See Windows documentation for more details on IOleObject methods.
799  */
800 static HRESULT WINAPI DefaultHandler_SetHostNames(
801             IOleObject*        iface,
802             LPCOLESTR          szContainerApp, 
803             LPCOLESTR          szContainerObj)
804 {
805   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
806
807   TRACE("(%p, %s, %s)\n",
808         iface,
809         debugstr_w(szContainerApp), 
810         debugstr_w(szContainerObj));
811
812   /*
813    * Be sure to cleanup before re-assinging the strings.
814    */ 
815   if (this->containerApp!=NULL)
816   {
817     HeapFree( GetProcessHeap(), 0, this->containerApp );
818     this->containerApp = NULL;
819   }
820
821   if (this->containerObj!=NULL)
822   {
823     HeapFree( GetProcessHeap(), 0, this->containerObj );
824     this->containerObj = NULL;
825   }
826
827   /*
828    * Copy the string supplied.
829    */
830   if (szContainerApp != NULL)
831   {
832       if ((this->containerApp = HeapAlloc( GetProcessHeap(), 0,
833                                            (lstrlenW(szContainerApp) + 1) * sizeof(WCHAR) )))
834           lstrcpyW( this->containerApp, szContainerApp );
835   }
836
837   if (szContainerObj != NULL)
838   {
839       if ((this->containerObj = HeapAlloc( GetProcessHeap(), 0,
840                                            (lstrlenW(szContainerObj) + 1) * sizeof(WCHAR) )))
841           lstrcpyW( this->containerObj, szContainerObj );
842   }
843   return S_OK;
844 }
845
846 /************************************************************************
847  * DefaultHandler_Close (IOleObject)
848  *
849  * The default handler's implementation of this method is meaningless
850  * without a running server so it does nothing.
851  *
852  * See Windows documentation for more details on IOleObject methods.
853  */
854 static HRESULT WINAPI DefaultHandler_Close(
855             IOleObject*        iface, 
856             DWORD              dwSaveOption)
857 {
858   TRACE("()\n");
859   return S_OK;
860 }
861
862 /************************************************************************
863  * DefaultHandler_SetMoniker (IOleObject)
864  *
865  * The default handler's implementation of this method does nothing.
866  *
867  * See Windows documentation for more details on IOleObject methods.
868  */
869 static HRESULT WINAPI DefaultHandler_SetMoniker(
870             IOleObject*        iface, 
871             DWORD              dwWhichMoniker,
872             IMoniker*          pmk)
873 {
874   TRACE("(%p, %ld, %p)\n",
875         iface, 
876         dwWhichMoniker, 
877         pmk);
878
879   return S_OK;
880 }
881
882 /************************************************************************
883  * DefaultHandler_GetMoniker (IOleObject)
884  *
885  * Delegate this request to the client site if we have one.
886  *
887  * See Windows documentation for more details on IOleObject methods.
888  */
889 static HRESULT WINAPI DefaultHandler_GetMoniker(
890             IOleObject*        iface,
891             DWORD              dwAssign,
892             DWORD              dwWhichMoniker,
893             IMoniker**         ppmk)
894 {
895   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
896
897   TRACE("(%p, %ld, %ld, %p)\n",
898         iface, dwAssign, dwWhichMoniker, ppmk);
899
900   if (this->clientSite)
901   {
902     return IOleClientSite_GetMoniker(this->clientSite,
903                                      dwAssign,
904                                      dwWhichMoniker,
905                                      ppmk);
906                               
907   }
908
909   return E_UNSPEC;
910 }
911
912 /************************************************************************
913  * DefaultHandler_InitFromData (IOleObject)
914  *
915  * This method is meaningless if the server is not running
916  * 
917  * See Windows documentation for more details on IOleObject methods.
918  */
919 static HRESULT WINAPI DefaultHandler_InitFromData(
920             IOleObject*        iface, 
921             IDataObject*       pDataObject, 
922             BOOL               fCreation,
923             DWORD              dwReserved)
924 {
925   TRACE("(%p, %p, %d, %ld)\n",
926         iface, pDataObject, fCreation, dwReserved);
927
928   return OLE_E_NOTRUNNING;
929 }
930
931 /************************************************************************
932  * DefaultHandler_GetClipboardData (IOleObject)
933  *
934  * This method is meaningless if the server is not running
935  * 
936  * See Windows documentation for more details on IOleObject methods.
937  */
938 static HRESULT WINAPI DefaultHandler_GetClipboardData(
939             IOleObject*        iface, 
940             DWORD              dwReserved, 
941             IDataObject**      ppDataObject)
942 {
943   TRACE("(%p, %ld, %p)\n",
944         iface, dwReserved, ppDataObject);
945
946   return OLE_E_NOTRUNNING;
947 }
948
949 static HRESULT WINAPI DefaultHandler_DoVerb(
950             IOleObject*        iface, 
951             LONG               iVerb, 
952             struct tagMSG*     lpmsg, 
953             IOleClientSite*    pActiveSite, 
954             LONG               lindex, 
955             HWND               hwndParent, 
956             LPCRECT            lprcPosRect)
957 {
958   FIXME(": Stub\n");
959   return E_NOTIMPL;
960 }
961
962 /************************************************************************
963  * DefaultHandler_EnumVerbs (IOleObject)
964  *
965  * The default handler implementation of this method simply delegates
966  * to OleRegEnumVerbs
967  * 
968  * See Windows documentation for more details on IOleObject methods.
969  */
970 static HRESULT WINAPI DefaultHandler_EnumVerbs(
971             IOleObject*        iface, 
972             IEnumOLEVERB**     ppEnumOleVerb)
973 {
974   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
975
976   TRACE("(%p, %p)\n", iface, ppEnumOleVerb);
977
978   return OleRegEnumVerbs(&this->clsid, ppEnumOleVerb);
979 }
980
981 static HRESULT WINAPI DefaultHandler_Update(
982             IOleObject*        iface)
983 {
984   FIXME(": Stub\n");
985   return E_NOTIMPL;
986 }
987
988 /************************************************************************
989  * DefaultHandler_IsUpToDate (IOleObject)
990  *
991  * This method is meaningless if the server is not running
992  * 
993  * See Windows documentation for more details on IOleObject methods.
994  */
995 static HRESULT WINAPI DefaultHandler_IsUpToDate(
996             IOleObject*        iface)
997 {
998   TRACE("(%p)\n", iface);
999
1000   return OLE_E_NOTRUNNING;
1001 }
1002
1003 /************************************************************************
1004  * DefaultHandler_GetUserClassID (IOleObject)
1005  *
1006  * TODO: Map to a new class ID if emulation is active.
1007  * 
1008  * See Windows documentation for more details on IOleObject methods.
1009  */
1010 static HRESULT WINAPI DefaultHandler_GetUserClassID(
1011             IOleObject*        iface, 
1012             CLSID*             pClsid)
1013 {
1014   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
1015
1016   TRACE("(%p, %p)\n", iface, pClsid);
1017
1018   /*
1019    * Sanity check.
1020    */
1021   if (pClsid==NULL)
1022     return E_POINTER;
1023
1024   memcpy(pClsid, &this->clsid, sizeof(CLSID));
1025
1026   return S_OK;
1027 }
1028
1029 /************************************************************************
1030  * DefaultHandler_GetUserType (IOleObject)
1031  *
1032  * The default handler implementation of this method simply delegates
1033  * to OleRegGetUserType
1034  * 
1035  * See Windows documentation for more details on IOleObject methods.
1036  */
1037 static HRESULT WINAPI DefaultHandler_GetUserType(
1038             IOleObject*        iface, 
1039             DWORD              dwFormOfType, 
1040             LPOLESTR*          pszUserType)
1041 {
1042   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
1043
1044   TRACE("(%p, %ld, %p)\n", iface, dwFormOfType, pszUserType);
1045
1046   return OleRegGetUserType(&this->clsid, dwFormOfType, pszUserType);
1047 }
1048
1049 /************************************************************************
1050  * DefaultHandler_SetExtent (IOleObject)
1051  *
1052  * This method is meaningless if the server is not running
1053  *
1054  * See Windows documentation for more details on IOleObject methods.
1055  */
1056 static HRESULT WINAPI DefaultHandler_SetExtent(
1057             IOleObject*        iface, 
1058             DWORD              dwDrawAspect, 
1059             SIZEL*             psizel)
1060 {
1061   TRACE("(%p, %lx, (%d,%d))\n", iface, dwDrawAspect, psizel->cx, psizel->cy);
1062   return OLE_E_NOTRUNNING;
1063 }
1064
1065 /************************************************************************
1066  * DefaultHandler_GetExtent (IOleObject)
1067  *
1068  * The default handler's implementation of this method returns uses
1069  * the cache to locate the aspect and extract the extent from it.
1070  *
1071  * See Windows documentation for more details on IOleObject methods.
1072  */
1073 static HRESULT WINAPI DefaultHandler_GetExtent(
1074             IOleObject*        iface, 
1075             DWORD              dwDrawAspect, 
1076             SIZEL*             psizel)
1077 {
1078   DVTARGETDEVICE* targetDevice;
1079   IViewObject2*   cacheView = NULL;
1080   HRESULT         hres;
1081
1082   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1083
1084   TRACE("(%p, %lx, %p)\n", iface, dwDrawAspect, psizel);
1085
1086   hres = IUnknown_QueryInterface(this->dataCache, &IID_IViewObject2, (void**)&cacheView);
1087
1088   if (FAILED(hres))
1089     return E_UNEXPECTED;
1090
1091   /*
1092    * Prepare the call to the cache's GetExtent method.
1093    *
1094    * Here we would build a valid DVTARGETDEVICE structure
1095    * but, since we are calling into the data cache, we 
1096    * know it's implementation and we'll skip this 
1097    * extra work until later.
1098    */
1099   targetDevice = NULL;
1100
1101   hres = IViewObject2_GetExtent(cacheView,
1102                                 dwDrawAspect,
1103                                 -1,
1104                                 targetDevice,
1105                                 psizel);
1106
1107   /*
1108    * Cleanup
1109    */
1110   IViewObject2_Release(cacheView);
1111
1112   return hres;
1113 }
1114
1115 /************************************************************************
1116  * DefaultHandler_Advise (IOleObject)
1117  *
1118  * The default handler's implementation of this method simply
1119  * delegates to the OleAdviseHolder.
1120  *
1121  * See Windows documentation for more details on IOleObject methods.
1122  */
1123 static HRESULT WINAPI DefaultHandler_Advise(
1124             IOleObject*        iface, 
1125             IAdviseSink*       pAdvSink, 
1126             DWORD*             pdwConnection)
1127 {
1128   HRESULT hres = S_OK;
1129   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1130
1131   TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection);
1132
1133   /*
1134    * Make sure we have an advise holder before we start.
1135    */
1136   if (this->oleAdviseHolder==NULL)
1137   {
1138     hres = CreateOleAdviseHolder(&this->oleAdviseHolder);
1139   }
1140
1141   if (SUCCEEDED(hres))
1142   {
1143     hres = IOleAdviseHolder_Advise(this->oleAdviseHolder, 
1144                                    pAdvSink, 
1145                                    pdwConnection);
1146   }
1147
1148   return hres;
1149 }
1150
1151 /************************************************************************
1152  * DefaultHandler_Unadvise (IOleObject)
1153  *
1154  * The default handler's implementation of this method simply
1155  * delegates to the OleAdviseHolder.
1156  *
1157  * See Windows documentation for more details on IOleObject methods.
1158  */
1159 static HRESULT WINAPI DefaultHandler_Unadvise(
1160             IOleObject*        iface, 
1161             DWORD              dwConnection)
1162 {
1163   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1164
1165   TRACE("(%p, %ld)\n", iface, dwConnection);
1166
1167   /*
1168    * If we don't have an advise holder yet, it means we don't have
1169    * a connection.
1170    */
1171   if (this->oleAdviseHolder==NULL)
1172     return OLE_E_NOCONNECTION;
1173
1174   return IOleAdviseHolder_Unadvise(this->oleAdviseHolder,
1175                                    dwConnection);
1176 }
1177
1178 /************************************************************************
1179  * DefaultHandler_EnumAdvise (IOleObject)
1180  *
1181  * The default handler's implementation of this method simply
1182  * delegates to the OleAdviseHolder.
1183  *
1184  * See Windows documentation for more details on IOleObject methods.
1185  */
1186 static HRESULT WINAPI DefaultHandler_EnumAdvise(
1187             IOleObject*        iface, 
1188             IEnumSTATDATA**    ppenumAdvise)
1189 {
1190   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1191
1192   TRACE("(%p, %p)\n", iface, ppenumAdvise);
1193
1194   /*
1195    * Sanity check
1196    */
1197   if (ppenumAdvise==NULL)
1198     return E_POINTER;
1199
1200   /*
1201    * Initialize the out parameter.
1202    */
1203   *ppenumAdvise = NULL;
1204
1205   if (this->oleAdviseHolder==NULL)
1206     return IOleAdviseHolder_EnumAdvise(this->oleAdviseHolder,
1207                                        ppenumAdvise);
1208
1209   return S_OK;
1210 }
1211
1212 /************************************************************************
1213  * DefaultHandler_GetMiscStatus (IOleObject)
1214  *
1215  * The default handler's implementation of this method simply delegates
1216  * to OleRegGetMiscStatus.
1217  *
1218  * See Windows documentation for more details on IOleObject methods.
1219  */
1220 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
1221             IOleObject*        iface, 
1222             DWORD              dwAspect, 
1223             DWORD*             pdwStatus)
1224 {
1225   HRESULT hres;
1226   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
1227
1228   TRACE("(%p, %lx, %p)\n", iface, dwAspect, pdwStatus);
1229
1230   hres = OleRegGetMiscStatus(&(this->clsid), dwAspect, pdwStatus);
1231
1232   if (FAILED(hres))
1233     *pdwStatus = 0;
1234
1235   return S_OK;
1236 }
1237
1238 /************************************************************************
1239  * DefaultHandler_SetExtent (IOleObject)
1240  *
1241  * This method is meaningless if the server is not running
1242  *
1243  * See Windows documentation for more details on IOleObject methods.
1244  */
1245 static HRESULT WINAPI DefaultHandler_SetColorScheme(
1246             IOleObject*           iface,
1247             struct tagLOGPALETTE* pLogpal)
1248 {
1249   TRACE("(%p, %p))\n", iface, pLogpal);
1250   return OLE_E_NOTRUNNING;
1251 }
1252
1253 /*********************************************************
1254  * Methods implementation for the IDataObject part of
1255  * the DefaultHandler class.
1256  */
1257
1258 /************************************************************************
1259  * DefaultHandler_IDataObject_QueryInterface (IUnknown)
1260  *
1261  * See Windows documentation for more details on IUnknown methods.
1262  */
1263 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
1264             IDataObject*     iface, 
1265            REFIID           riid,
1266             void**           ppvObject)
1267 {
1268   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1269
1270   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);  
1271 }
1272
1273 /************************************************************************
1274  * DefaultHandler_IDataObject_AddRef (IUnknown)
1275  *
1276  * See Windows documentation for more details on IUnknown methods.
1277  */
1278 static ULONG WINAPI DefaultHandler_IDataObject_AddRef( 
1279             IDataObject*     iface)
1280 {
1281   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1282
1283   return IUnknown_AddRef(this->outerUnknown);  
1284 }
1285
1286 /************************************************************************
1287  * DefaultHandler_IDataObject_Release (IUnknown)
1288  *
1289  * See Windows documentation for more details on IUnknown methods.
1290  */
1291 static ULONG WINAPI DefaultHandler_IDataObject_Release( 
1292             IDataObject*     iface)
1293 {
1294   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1295
1296   return IUnknown_Release(this->outerUnknown);  
1297 }
1298
1299 static HRESULT WINAPI DefaultHandler_GetData(
1300             IDataObject*     iface,
1301             LPFORMATETC      pformatetcIn, 
1302             STGMEDIUM*       pmedium)
1303 {
1304   FIXME(": Stub\n");
1305   return E_NOTIMPL;
1306 }
1307
1308 static HRESULT WINAPI DefaultHandler_GetDataHere(
1309             IDataObject*     iface, 
1310             LPFORMATETC      pformatetc,
1311             STGMEDIUM*       pmedium)
1312 {
1313   FIXME(": Stub\n");
1314   return E_NOTIMPL;
1315 }
1316
1317 /************************************************************************
1318  * DefaultHandler_QueryGetData (IDataObject)
1319  *
1320  * The default handler's implementation of this method delegates to 
1321  * the cache.
1322  *
1323  * See Windows documentation for more details on IDataObject methods.
1324  */
1325 static HRESULT WINAPI DefaultHandler_QueryGetData(
1326             IDataObject*     iface,
1327             LPFORMATETC      pformatetc)
1328 {
1329   IDataObject* cacheDataObject = NULL;
1330   HRESULT      hres;
1331
1332   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1333
1334   TRACE("(%p, %p)\n", iface, pformatetc);
1335
1336   hres = IUnknown_QueryInterface(this->dataCache, 
1337                                  &IID_IDataObject,
1338                                  (void**)&cacheDataObject);
1339
1340   if (FAILED(hres))
1341     return E_UNEXPECTED;
1342
1343   hres = IDataObject_QueryGetData(cacheDataObject,
1344                                   pformatetc);
1345
1346   IDataObject_Release(cacheDataObject);
1347   
1348   return hres;
1349 }
1350
1351 /************************************************************************
1352  * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
1353  *
1354  * This method is meaningless if the server is not running
1355  *
1356  * See Windows documentation for more details on IDataObject methods.
1357  */
1358 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
1359             IDataObject*     iface, 
1360             LPFORMATETC      pformatectIn, 
1361             LPFORMATETC      pformatetcOut)
1362 {
1363   FIXME("(%p, %p, %p)\n", iface, pformatectIn, pformatetcOut);
1364
1365   return OLE_E_NOTRUNNING;
1366 }
1367
1368 /************************************************************************
1369  * DefaultHandler_SetData (IDataObject)
1370  *
1371  * The default handler's implementation of this method delegates to 
1372  * the cache.
1373  *
1374  * See Windows documentation for more details on IDataObject methods.
1375  */
1376 static HRESULT WINAPI DefaultHandler_SetData(
1377             IDataObject*     iface,
1378             LPFORMATETC      pformatetc, 
1379             STGMEDIUM*       pmedium, 
1380             BOOL             fRelease)
1381 {
1382   IDataObject* cacheDataObject = NULL;
1383   HRESULT      hres;
1384
1385   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1386
1387   TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
1388
1389   hres = IUnknown_QueryInterface(this->dataCache, 
1390                                  &IID_IDataObject,
1391                                  (void**)&cacheDataObject);
1392
1393   if (FAILED(hres))
1394     return E_UNEXPECTED;
1395
1396   hres = IDataObject_SetData(cacheDataObject,
1397                              pformatetc,
1398                              pmedium,
1399                              fRelease);
1400   
1401   IDataObject_Release(cacheDataObject);
1402   
1403   return hres;
1404 }
1405
1406 /************************************************************************
1407  * DefaultHandler_EnumFormatEtc (IDataObject)
1408  *
1409  * The default handler's implementation of this method simply delegates
1410  * to OleRegEnumFormatEtc.
1411  *
1412  * See Windows documentation for more details on IDataObject methods.
1413  */
1414 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
1415             IDataObject*     iface,       
1416             DWORD            dwDirection,
1417             IEnumFORMATETC** ppenumFormatEtc)
1418 {
1419   HRESULT hres;
1420   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1421
1422   TRACE("(%p, %lx, %p)\n", iface, dwDirection, ppenumFormatEtc);
1423
1424   hres = OleRegEnumFormatEtc(&(this->clsid), dwDirection, ppenumFormatEtc);
1425
1426   return hres;
1427 }
1428
1429 /************************************************************************
1430  * DefaultHandler_DAdvise (IDataObject)
1431  *
1432  * The default handler's implementation of this method simply
1433  * delegates to the DataAdviseHolder.
1434  *
1435  * See Windows documentation for more details on IDataObject methods.
1436  */
1437 static HRESULT WINAPI DefaultHandler_DAdvise(
1438             IDataObject*     iface, 
1439             FORMATETC*       pformatetc, 
1440             DWORD            advf, 
1441             IAdviseSink*     pAdvSink, 
1442             DWORD*           pdwConnection)
1443 {
1444   HRESULT hres = S_OK;
1445   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);  
1446
1447   TRACE("(%p, %p, %ld, %p, %p)\n", 
1448         iface, pformatetc, advf, pAdvSink, pdwConnection);
1449
1450   /*
1451    * Make sure we have a data advise holder before we start.
1452    */
1453   if (this->dataAdviseHolder==NULL)
1454   {
1455     hres = CreateDataAdviseHolder(&this->dataAdviseHolder);
1456   }
1457
1458   if (SUCCEEDED(hres))
1459   {
1460     hres = IDataAdviseHolder_Advise(this->dataAdviseHolder, 
1461                                     iface,
1462                                     pformatetc, 
1463                                     advf, 
1464                                     pAdvSink, 
1465                                     pdwConnection);
1466   }
1467
1468   return hres;
1469 }
1470
1471 /************************************************************************
1472  * DefaultHandler_DUnadvise (IDataObject)
1473  *
1474  * The default handler's implementation of this method simply
1475  * delegates to the DataAdviseHolder.
1476  *
1477  * See Windows documentation for more details on IDataObject methods.
1478  */
1479 static HRESULT WINAPI DefaultHandler_DUnadvise(
1480             IDataObject*     iface,
1481             DWORD            dwConnection)
1482 {
1483   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);  
1484
1485   TRACE("(%p, %ld)\n", iface, dwConnection);
1486
1487   /*
1488    * If we don't have a data advise holder yet, it means that
1489    * we don't have any connections..
1490    */
1491   if (this->dataAdviseHolder==NULL)
1492   {
1493     return OLE_E_NOCONNECTION;
1494   }
1495
1496   return IDataAdviseHolder_Unadvise(this->dataAdviseHolder, 
1497                                     dwConnection);
1498 }
1499
1500 /************************************************************************
1501  * DefaultHandler_EnumDAdvise (IDataObject)
1502  *
1503  * The default handler's implementation of this method simply
1504  * delegates to the DataAdviseHolder.
1505  *
1506  * See Windows documentation for more details on IDataObject methods.
1507  */
1508 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
1509             IDataObject*     iface,
1510             IEnumSTATDATA**  ppenumAdvise)
1511 {
1512   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);  
1513
1514   TRACE("(%p, %p)\n", iface, ppenumAdvise);
1515
1516   /*
1517    * Sanity check
1518    */
1519   if (ppenumAdvise == NULL)
1520     return E_POINTER;
1521
1522   /*
1523    * Initialize the out parameter.
1524    */
1525   *ppenumAdvise = NULL;
1526
1527   /*
1528    * If we have a data advise holder object, delegate.
1529    */
1530   if (this->dataAdviseHolder!=NULL)
1531   {
1532     return IDataAdviseHolder_EnumAdvise(this->dataAdviseHolder, 
1533                                         ppenumAdvise);
1534   }
1535
1536   return S_OK;
1537 }
1538
1539 /*********************************************************
1540  * Methods implementation for the IRunnableObject part 
1541  * of the DefaultHandler class.
1542  */
1543
1544 /************************************************************************
1545  * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1546  *
1547  * See Windows documentation for more details on IUnknown methods.
1548  */
1549 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
1550             IRunnableObject*     iface,
1551             REFIID               riid,
1552             void**               ppvObject)
1553 {
1554   _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface);
1555
1556   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);  
1557 }
1558
1559 /************************************************************************
1560  * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1561  *
1562  * See Windows documentation for more details on IUnknown methods.
1563  */
1564 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef( 
1565             IRunnableObject*     iface)
1566 {
1567   _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface);
1568
1569   return IUnknown_AddRef(this->outerUnknown);
1570 }
1571
1572 /************************************************************************
1573  * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1574  *
1575  * See Windows documentation for more details on IUnknown methods.
1576  */
1577 static ULONG WINAPI DefaultHandler_IRunnableObject_Release( 
1578             IRunnableObject*     iface)
1579 {
1580   _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface);
1581
1582   return IUnknown_Release(this->outerUnknown);
1583 }
1584
1585 /************************************************************************
1586  * DefaultHandler_GetRunningClass (IRunnableObject)
1587  *
1588  * According to Brockscmidt, Chapter 19, the default handler's 
1589  * implementation of IRunnableobject does nothing until the object
1590  * is actually running.
1591  *
1592  * See Windows documentation for more details on IRunnableObject methods.
1593  */
1594 static HRESULT WINAPI DefaultHandler_GetRunningClass( 
1595             IRunnableObject*     iface,   
1596             LPCLSID              lpClsid)
1597 {
1598   TRACE("()\n");
1599   return S_OK;
1600 }
1601
1602 static HRESULT WINAPI DefaultHandler_Run( 
1603             IRunnableObject*     iface,
1604             IBindCtx*            pbc)
1605 {
1606   FIXME(": Stub\n");
1607   return E_NOTIMPL;
1608 }
1609
1610 /************************************************************************
1611  * DefaultHandler_IsRunning (IRunnableObject)
1612  *
1613  * According to Brockscmidt, Chapter 19, the default handler's 
1614  * implementation of IRunnableobject does nothing until the object
1615  * is actually running.
1616  *
1617  * See Windows documentation for more details on IRunnableObject methods.
1618  */
1619 static BOOL    WINAPI DefaultHandler_IsRunning( 
1620             IRunnableObject*     iface)
1621 {
1622   TRACE("()\n");
1623   return S_FALSE;
1624 }
1625
1626 /************************************************************************
1627  * DefaultHandler_LockRunning (IRunnableObject)
1628  *
1629  * According to Brockscmidt, Chapter 19, the default handler's 
1630  * implementation of IRunnableobject does nothing until the object
1631  * is actually running.
1632  *
1633  * See Windows documentation for more details on IRunnableObject methods.
1634  */
1635 static HRESULT WINAPI DefaultHandler_LockRunning( 
1636             IRunnableObject*     iface, 
1637             BOOL                 fLock, 
1638             BOOL                 fLastUnlockCloses)
1639 {
1640   TRACE("()\n");
1641   return S_OK;
1642 }
1643
1644 /************************************************************************
1645  * DefaultHandler_SetContainedObject (IRunnableObject)
1646  *
1647  * According to Brockscmidt, Chapter 19, the default handler's 
1648  * implementation of IRunnableobject does nothing until the object
1649  * is actually running.
1650  *
1651  * See Windows documentation for more details on IRunnableObject methods.
1652  */
1653 static HRESULT WINAPI DefaultHandler_SetContainedObject( 
1654             IRunnableObject*     iface, 
1655             BOOL                 fContained)
1656 {
1657   TRACE("()\n");
1658   return S_OK;
1659 }
1660