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