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