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