4 * Copyright 1998 Eric Kohl
5 * Copyright 1999 Francis Beaudet
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(ole
)
18 /**************************************************************************
19 * OleAdviseHolderImpl Implementation
21 typedef struct OleAdviseHolderImpl
23 ICOM_VFIELD(IOleAdviseHolder
);
28 IAdviseSink
** arrayOfSinks
;
30 } OleAdviseHolderImpl
;
32 static LPOLEADVISEHOLDER
OleAdviseHolderImpl_Constructor();
33 static void OleAdviseHolderImpl_Destructor(OleAdviseHolderImpl
* ptrToDestroy
);
34 static HRESULT WINAPI
OleAdviseHolderImpl_QueryInterface(LPOLEADVISEHOLDER
,REFIID
,LPVOID
*);
35 static ULONG WINAPI
OleAdviseHolderImpl_AddRef(LPOLEADVISEHOLDER
);
36 static ULONG WINAPI
OleAdviseHolderImpl_Release(LPOLEADVISEHOLDER
);
37 static HRESULT WINAPI
OleAdviseHolderImpl_Advise(LPOLEADVISEHOLDER
, IAdviseSink
*, DWORD
*);
38 static HRESULT WINAPI
OleAdviseHolderImpl_Unadvise (LPOLEADVISEHOLDER
, DWORD
);
39 static HRESULT WINAPI
OleAdviseHolderImpl_EnumAdvise (LPOLEADVISEHOLDER
, IEnumSTATDATA
**);
40 static HRESULT WINAPI
OleAdviseHolderImpl_SendOnRename (LPOLEADVISEHOLDER
, IMoniker
*);
41 static HRESULT WINAPI
OleAdviseHolderImpl_SendOnSave (LPOLEADVISEHOLDER
);
42 static HRESULT WINAPI
OleAdviseHolderImpl_SendOnClose (LPOLEADVISEHOLDER
);
45 /**************************************************************************
46 * OleAdviseHolderImpl_VTable
48 static struct ICOM_VTABLE(IOleAdviseHolder
) oahvt
=
50 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
51 OleAdviseHolderImpl_QueryInterface
,
52 OleAdviseHolderImpl_AddRef
,
53 OleAdviseHolderImpl_Release
,
54 OleAdviseHolderImpl_Advise
,
55 OleAdviseHolderImpl_Unadvise
,
56 OleAdviseHolderImpl_EnumAdvise
,
57 OleAdviseHolderImpl_SendOnRename
,
58 OleAdviseHolderImpl_SendOnSave
,
59 OleAdviseHolderImpl_SendOnClose
62 /**************************************************************************
63 * OleAdviseHolderImpl_Constructor
66 static LPOLEADVISEHOLDER
OleAdviseHolderImpl_Constructor()
68 OleAdviseHolderImpl
* lpoah
;
71 lpoah
= (OleAdviseHolderImpl
*)HeapAlloc(GetProcessHeap(),
73 sizeof(OleAdviseHolderImpl
));
75 ICOM_VTBL(lpoah
) = &oahvt
;
78 lpoah
->arrayOfSinks
= HeapAlloc(GetProcessHeap(),
80 lpoah
->maxSinks
* sizeof(IAdviseSink
*));
82 for (index
= 0; index
< lpoah
->maxSinks
; index
++)
83 lpoah
->arrayOfSinks
[index
]=0;
85 return (LPOLEADVISEHOLDER
)lpoah
;
88 /**************************************************************************
89 * OleAdviseHolderImpl_Destructor
91 static void OleAdviseHolderImpl_Destructor(
92 OleAdviseHolderImpl
* ptrToDestroy
)
96 for (index
= 0; index
< ptrToDestroy
->maxSinks
; index
++)
98 if (ptrToDestroy
->arrayOfSinks
[index
]!=0)
100 IAdviseSink_Release(ptrToDestroy
->arrayOfSinks
[index
]);
101 ptrToDestroy
->arrayOfSinks
[index
] = NULL
;
105 HeapFree(GetProcessHeap(),
107 ptrToDestroy
->arrayOfSinks
);
110 HeapFree(GetProcessHeap(),
115 /**************************************************************************
116 * OleAdviseHolderImpl_QueryInterface
118 static HRESULT WINAPI
OleAdviseHolderImpl_QueryInterface(
119 LPOLEADVISEHOLDER iface
,
123 ICOM_THIS(OleAdviseHolderImpl
, iface
);
133 if (IsEqualIID(riid
, &IID_IUnknown
))
138 else if(IsEqualIID(riid
, &IID_IOleAdviseHolder
))
140 /* IOleAdviseHolder */
141 *ppvObj
= (IOleAdviseHolder
*) This
;
145 return E_NOINTERFACE
;
148 * A successful QI always increments the reference count.
150 IUnknown_AddRef((IUnknown
*)*ppvObj
);
155 /******************************************************************************
156 * OleAdviseHolderImpl_AddRef
158 static ULONG WINAPI
OleAdviseHolderImpl_AddRef(
159 LPOLEADVISEHOLDER iface
)
161 ICOM_THIS(OleAdviseHolderImpl
, iface
);
163 return ++(This
->ref
);
166 /******************************************************************************
167 * OleAdviseHolderImpl_Release
169 static ULONG WINAPI
OleAdviseHolderImpl_Release(
170 LPOLEADVISEHOLDER iface
)
172 ICOM_THIS(OleAdviseHolderImpl
, iface
);
178 OleAdviseHolderImpl_Destructor(This
);
186 /******************************************************************************
187 * OleAdviseHolderImpl_Advise
189 static HRESULT WINAPI
OleAdviseHolderImpl_Advise(
190 LPOLEADVISEHOLDER iface
,
191 IAdviseSink
* pAdvise
,
192 DWORD
* pdwConnection
)
196 ICOM_THIS(OleAdviseHolderImpl
, iface
);
198 TRACE("(%p, %p, %p)\n", This
, pAdvise
, pdwConnection
);
203 if (pdwConnection
==NULL
)
209 * Find a free spot in the array.
211 for (index
= 0; index
< This
->maxSinks
; index
++)
213 if (This
->arrayOfSinks
[index
]==NULL
)
218 * If the array is full, we need to grow it.
220 if (index
== This
->maxSinks
)
226 This
->arrayOfSinks
= HeapReAlloc(GetProcessHeap(),
229 This
->maxSinks
*sizeof(IAdviseSink
*));
231 for (i
=index
;i
< This
->maxSinks
; i
++)
232 This
->arrayOfSinks
[i
]=0;
238 This
->arrayOfSinks
[index
] = pAdvise
;
240 if (This
->arrayOfSinks
[index
]!=NULL
)
241 IAdviseSink_AddRef(This
->arrayOfSinks
[index
]);
244 * Return the index as the cookie.
245 * Since 0 is not a valid cookie, we will increment by
246 * 1 the index in the table.
248 *pdwConnection
= index
+1;
253 /******************************************************************************
254 * OleAdviseHolderImpl_Unadvise
256 static HRESULT WINAPI
OleAdviseHolderImpl_Unadvise(
257 LPOLEADVISEHOLDER iface
,
260 ICOM_THIS(OleAdviseHolderImpl
, iface
);
262 TRACE("(%p, %lu)\n", This
, dwConnection
);
265 * So we don't return 0 as a cookie, the index was
266 * incremented by 1 in OleAdviseHolderImpl_Advise
267 * we have to compensate.
272 * Check for invalid cookies.
274 if ( (dwConnection
< 0) ||
275 (dwConnection
>= This
->maxSinks
) )
276 return OLE_E_NOCONNECTION
;
278 if (This
->arrayOfSinks
[dwConnection
] == NULL
)
279 return OLE_E_NOCONNECTION
;
282 * Release the sink and mark the spot in the list as free.
284 IAdviseSink_Release(This
->arrayOfSinks
[dwConnection
]);
285 This
->arrayOfSinks
[dwConnection
] = NULL
;
290 /******************************************************************************
291 * OleAdviseHolderImpl_EnumAdvise
293 static HRESULT WINAPI
294 OleAdviseHolderImpl_EnumAdvise (LPOLEADVISEHOLDER iface
, IEnumSTATDATA
**ppenumAdvise
)
296 ICOM_THIS(OleAdviseHolderImpl
, iface
);
297 FIXME("(%p)->(%p)\n", This
, ppenumAdvise
);
299 *ppenumAdvise
= NULL
;
304 /******************************************************************************
305 * OleAdviseHolderImpl_SendOnRename
307 static HRESULT WINAPI
308 OleAdviseHolderImpl_SendOnRename (LPOLEADVISEHOLDER iface
, IMoniker
*pmk
)
310 ICOM_THIS(OleAdviseHolderImpl
, iface
);
311 FIXME("(%p)->(%p)\n", This
, pmk
);
317 /******************************************************************************
318 * OleAdviseHolderImpl_SendOnSave
320 static HRESULT WINAPI
321 OleAdviseHolderImpl_SendOnSave (LPOLEADVISEHOLDER iface
)
323 ICOM_THIS(OleAdviseHolderImpl
, iface
);
324 FIXME("(%p)\n", This
);
330 /******************************************************************************
331 * OleAdviseHolderImpl_SendOnClose
333 static HRESULT WINAPI
334 OleAdviseHolderImpl_SendOnClose (LPOLEADVISEHOLDER iface
)
336 ICOM_THIS(OleAdviseHolderImpl
, iface
);
337 FIXME("(%p)\n", This
);
343 /**************************************************************************
344 * DataAdviseHolder Implementation
346 typedef struct DataAdviseHolder
348 ICOM_VFIELD(IDataAdviseHolder
);
353 /**************************************************************************
354 * DataAdviseHolder method prototypes
356 static IDataAdviseHolder
* DataAdviseHolder_Constructor();
357 static void DataAdviseHolder_Destructor(DataAdviseHolder
* ptrToDestroy
);
358 static HRESULT WINAPI
DataAdviseHolder_QueryInterface(
359 IDataAdviseHolder
* iface
,
362 static ULONG WINAPI
DataAdviseHolder_AddRef(
363 IDataAdviseHolder
* iface
);
364 static ULONG WINAPI
DataAdviseHolder_Release(
365 IDataAdviseHolder
* iface
);
366 static HRESULT WINAPI
DataAdviseHolder_Advise(
367 IDataAdviseHolder
* iface
,
368 IDataObject
* pDataObject
,
371 IAdviseSink
* pAdvise
,
372 DWORD
* pdwConnection
);
373 static HRESULT WINAPI
DataAdviseHolder_Unadvise(
374 IDataAdviseHolder
* iface
,
376 static HRESULT WINAPI
DataAdviseHolder_EnumAdvise(
377 IDataAdviseHolder
* iface
,
378 IEnumSTATDATA
** ppenumAdvise
);
379 static HRESULT WINAPI
DataAdviseHolder_SendOnDataChange(
380 IDataAdviseHolder
* iface
,
381 IDataObject
* pDataObject
,
385 /**************************************************************************
386 * DataAdviseHolderImpl_VTable
388 static struct ICOM_VTABLE(IDataAdviseHolder
) DataAdviseHolderImpl_VTable
=
390 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
391 DataAdviseHolder_QueryInterface
,
392 DataAdviseHolder_AddRef
,
393 DataAdviseHolder_Release
,
394 DataAdviseHolder_Advise
,
395 DataAdviseHolder_Unadvise
,
396 DataAdviseHolder_EnumAdvise
,
397 DataAdviseHolder_SendOnDataChange
400 /******************************************************************************
401 * DataAdviseHolder_Constructor
403 static IDataAdviseHolder
* DataAdviseHolder_Constructor()
405 DataAdviseHolder
* newHolder
;
407 newHolder
= (DataAdviseHolder
*)HeapAlloc(GetProcessHeap(),
409 sizeof(DataAdviseHolder
));
411 ICOM_VTBL(newHolder
) = &DataAdviseHolderImpl_VTable
;
414 return (IDataAdviseHolder
*)newHolder
;
417 /******************************************************************************
418 * DataAdviseHolder_Destructor
420 static void DataAdviseHolder_Destructor(
421 DataAdviseHolder
* ptrToDestroy
)
423 HeapFree(GetProcessHeap(),
428 /************************************************************************
429 * DataAdviseHolder_QueryInterface (IUnknown)
431 * See Windows documentation for more details on IUnknown methods.
433 static HRESULT WINAPI
DataAdviseHolder_QueryInterface(
434 IDataAdviseHolder
* iface
,
438 ICOM_THIS(DataAdviseHolder
, iface
);
441 * Perform a sanity check on the parameters.
443 if ( (This
==0) || (ppvObject
==0) )
447 * Initialize the return parameter.
452 * Compare the riid with the interface IDs implemented by this object.
454 if ( (memcmp(&IID_IUnknown
, riid
, sizeof(IID_IUnknown
)) == 0) ||
455 (memcmp(&IID_IDataAdviseHolder
, riid
, sizeof(IID_IDataAdviseHolder
)) == 0) )
461 * Check that we obtained an interface.
465 return E_NOINTERFACE
;
469 * Query Interface always increases the reference count by one when it is
472 IUnknown_AddRef((IUnknown
*)*ppvObject
);
477 /************************************************************************
478 * DataAdviseHolder_AddRef (IUnknown)
480 * See Windows documentation for more details on IUnknown methods.
482 static ULONG WINAPI
DataAdviseHolder_AddRef(
483 IDataAdviseHolder
* iface
)
485 ICOM_THIS(DataAdviseHolder
, iface
);
492 /************************************************************************
493 * DataAdviseHolder_Release (IUnknown)
495 * See Windows documentation for more details on IUnknown methods.
497 static ULONG WINAPI
DataAdviseHolder_Release(
498 IDataAdviseHolder
* iface
)
500 ICOM_THIS(DataAdviseHolder
, iface
);
503 * Decrease the reference count on this object.
508 * If the reference count goes down to 0, perform suicide.
512 DataAdviseHolder_Destructor(This
);
520 static HRESULT WINAPI
DataAdviseHolder_Advise(
521 IDataAdviseHolder
* iface
,
522 IDataObject
* pDataObject
,
525 IAdviseSink
* pAdvise
,
526 DWORD
* pdwConnection
)
532 static HRESULT WINAPI
DataAdviseHolder_Unadvise(
533 IDataAdviseHolder
* iface
,
540 static HRESULT WINAPI
DataAdviseHolder_EnumAdvise(
541 IDataAdviseHolder
* iface
,
542 IEnumSTATDATA
** ppenumAdvise
)
548 static HRESULT WINAPI
DataAdviseHolder_SendOnDataChange(
549 IDataAdviseHolder
* iface
,
550 IDataObject
* pDataObject
,
558 /***********************************************************************
562 /***********************************************************************
563 * CreateOleAdviseHolder [OLE32.59]
565 HRESULT WINAPI
CreateOleAdviseHolder(
566 LPOLEADVISEHOLDER
*ppOAHolder
)
568 TRACE("(%p)\n", ppOAHolder
);
573 if (ppOAHolder
==NULL
)
576 *ppOAHolder
= OleAdviseHolderImpl_Constructor ();
578 if (*ppOAHolder
!= NULL
)
581 return E_OUTOFMEMORY
;
584 /******************************************************************************
585 * CreateDataAdviseHolder [OLE32.53]
587 HRESULT WINAPI
CreateDataAdviseHolder(
588 LPDATAADVISEHOLDER
* ppDAHolder
)
590 TRACE("(%p)\n", ppDAHolder
);
595 if (ppDAHolder
==NULL
)
598 *ppDAHolder
= DataAdviseHolder_Constructor();
600 if (*ppDAHolder
!= NULL
)
603 return E_OUTOFMEMORY
;