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