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