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_VTABLE(IOleAdviseHolder)* lpvtbl;
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 OleAdviseHolderImpl_QueryInterface,
51 OleAdviseHolderImpl_AddRef,
52 OleAdviseHolderImpl_Release,
53 OleAdviseHolderImpl_Advise,
54 OleAdviseHolderImpl_Unadvise,
55 OleAdviseHolderImpl_EnumAdvise,
56 OleAdviseHolderImpl_SendOnRename,
57 OleAdviseHolderImpl_SendOnSave,
58 OleAdviseHolderImpl_SendOnClose
61 /**************************************************************************
62 * OleAdviseHolderImpl_Constructor
65 static LPOLEADVISEHOLDER OleAdviseHolderImpl_Constructor()
67 OleAdviseHolderImpl* lpoah;
70 lpoah= (OleAdviseHolderImpl*)HeapAlloc(GetProcessHeap(),
72 sizeof(OleAdviseHolderImpl));
74 lpoah->lpvtbl = &oahvt;
77 lpoah->arrayOfSinks = HeapAlloc(GetProcessHeap(),
79 lpoah->maxSinks * sizeof(IAdviseSink*));
81 for (index = 0; index < lpoah->maxSinks; index++)
82 lpoah->arrayOfSinks[index]=0;
84 return (LPOLEADVISEHOLDER)lpoah;
87 /**************************************************************************
88 * OleAdviseHolderImpl_Destructor
90 static void OleAdviseHolderImpl_Destructor(
91 OleAdviseHolderImpl* ptrToDestroy)
95 for (index = 0; index < ptrToDestroy->maxSinks; index++)
97 if (ptrToDestroy->arrayOfSinks[index]!=0)
99 IAdviseSink_Release(ptrToDestroy->arrayOfSinks[index]);
100 ptrToDestroy->arrayOfSinks[index] = NULL;
104 HeapFree(GetProcessHeap(),
106 ptrToDestroy->arrayOfSinks);
109 HeapFree(GetProcessHeap(),
114 /**************************************************************************
115 * OleAdviseHolderImpl_QueryInterface
117 static HRESULT WINAPI OleAdviseHolderImpl_QueryInterface(
118 LPOLEADVISEHOLDER iface,
122 ICOM_THIS(OleAdviseHolderImpl, iface);
132 if (IsEqualIID(riid, &IID_IUnknown))
137 else if(IsEqualIID(riid, &IID_IOleAdviseHolder))
139 /* IOleAdviseHolder */
140 *ppvObj = (IOleAdviseHolder*) This;
144 return E_NOINTERFACE;
147 * A successful QI always increments the reference count.
149 IUnknown_AddRef((IUnknown*)*ppvObj);
154 /******************************************************************************
155 * OleAdviseHolderImpl_AddRef
157 static ULONG WINAPI OleAdviseHolderImpl_AddRef(
158 LPOLEADVISEHOLDER iface)
160 ICOM_THIS(OleAdviseHolderImpl, iface);
162 return ++(This->ref);
165 /******************************************************************************
166 * OleAdviseHolderImpl_Release
168 static ULONG WINAPI OleAdviseHolderImpl_Release(
169 LPOLEADVISEHOLDER iface)
171 ICOM_THIS(OleAdviseHolderImpl, iface);
177 OleAdviseHolderImpl_Destructor(This);
185 /******************************************************************************
186 * OleAdviseHolderImpl_Advise
188 static HRESULT WINAPI OleAdviseHolderImpl_Advise(
189 LPOLEADVISEHOLDER iface,
190 IAdviseSink* pAdvise,
191 DWORD* pdwConnection)
195 ICOM_THIS(OleAdviseHolderImpl, iface);
197 TRACE("(%p, %p, %p)\n", This, pAdvise, pdwConnection);
202 if (pdwConnection==NULL)
208 * Find a free spot in the array.
210 for (index = 0; index < This->maxSinks; index++)
212 if (This->arrayOfSinks[index]==NULL)
217 * If the array is full, we need to grow it.
219 if (index == This->maxSinks)
225 This->arrayOfSinks = HeapReAlloc(GetProcessHeap(),
228 This->maxSinks*sizeof(IAdviseSink*));
230 for (i=index;i < This->maxSinks; i++)
231 This->arrayOfSinks[i]=0;
237 This->arrayOfSinks[index] = pAdvise;
239 if (This->arrayOfSinks[index]!=NULL)
240 IAdviseSink_AddRef(This->arrayOfSinks[index]);
243 * Return the index as the cookie.
244 * Since 0 is not a valid cookie, we will increment by
245 * 1 the index in the table.
247 *pdwConnection = index+1;
252 /******************************************************************************
253 * OleAdviseHolderImpl_Unadvise
255 static HRESULT WINAPI OleAdviseHolderImpl_Unadvise(
256 LPOLEADVISEHOLDER iface,
259 ICOM_THIS(OleAdviseHolderImpl, iface);
261 TRACE("(%p, %lu)\n", This, dwConnection);
264 * So we don't return 0 as a cookie, the index was
265 * incremented by 1 in OleAdviseHolderImpl_Advise
266 * we have to compensate.
271 * Check for invalid cookies.
273 if ( (dwConnection < 0) ||
274 (dwConnection >= This->maxSinks) )
275 return OLE_E_NOCONNECTION;
277 if (This->arrayOfSinks[dwConnection] == NULL)
278 return OLE_E_NOCONNECTION;
281 * Release the sink and mark the spot in the list as free.
283 IAdviseSink_Release(This->arrayOfSinks[dwConnection]);
284 This->arrayOfSinks[dwConnection] = NULL;
289 /******************************************************************************
290 * OleAdviseHolderImpl_EnumAdvise
292 static HRESULT WINAPI
293 OleAdviseHolderImpl_EnumAdvise (LPOLEADVISEHOLDER iface, IEnumSTATDATA **ppenumAdvise)
295 ICOM_THIS(OleAdviseHolderImpl, iface);
296 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
298 *ppenumAdvise = NULL;
303 /******************************************************************************
304 * OleAdviseHolderImpl_SendOnRename
306 static HRESULT WINAPI
307 OleAdviseHolderImpl_SendOnRename (LPOLEADVISEHOLDER iface, IMoniker *pmk)
309 ICOM_THIS(OleAdviseHolderImpl, iface);
310 FIXME("(%p)->(%p)\n", This, pmk);
316 /******************************************************************************
317 * OleAdviseHolderImpl_SendOnSave
319 static HRESULT WINAPI
320 OleAdviseHolderImpl_SendOnSave (LPOLEADVISEHOLDER iface)
322 ICOM_THIS(OleAdviseHolderImpl, iface);
323 FIXME("(%p)\n", This);
329 /******************************************************************************
330 * OleAdviseHolderImpl_SendOnClose
332 static HRESULT WINAPI
333 OleAdviseHolderImpl_SendOnClose (LPOLEADVISEHOLDER iface)
335 ICOM_THIS(OleAdviseHolderImpl, iface);
336 FIXME("(%p)\n", This);
342 /**************************************************************************
343 * DataAdviseHolder Implementation
345 typedef struct DataAdviseHolder
347 ICOM_VTABLE(IDataAdviseHolder)* lpvtbl;
352 /**************************************************************************
353 * DataAdviseHolder method prototypes
355 static IDataAdviseHolder* DataAdviseHolder_Constructor();
356 static void DataAdviseHolder_Destructor(DataAdviseHolder* ptrToDestroy);
357 static HRESULT WINAPI DataAdviseHolder_QueryInterface(
358 IDataAdviseHolder* iface,
361 static ULONG WINAPI DataAdviseHolder_AddRef(
362 IDataAdviseHolder* iface);
363 static ULONG WINAPI DataAdviseHolder_Release(
364 IDataAdviseHolder* iface);
365 static HRESULT WINAPI DataAdviseHolder_Advise(
366 IDataAdviseHolder* iface,
367 IDataObject* pDataObject,
370 IAdviseSink* pAdvise,
371 DWORD* pdwConnection);
372 static HRESULT WINAPI DataAdviseHolder_Unadvise(
373 IDataAdviseHolder* iface,
375 static HRESULT WINAPI DataAdviseHolder_EnumAdvise(
376 IDataAdviseHolder* iface,
377 IEnumSTATDATA** ppenumAdvise);
378 static HRESULT WINAPI DataAdviseHolder_SendOnDataChange(
379 IDataAdviseHolder* iface,
380 IDataObject* pDataObject,
384 /**************************************************************************
385 * DataAdviseHolderImpl_VTable
387 static struct ICOM_VTABLE(IDataAdviseHolder) DataAdviseHolderImpl_VTable =
389 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
390 DataAdviseHolder_QueryInterface,
391 DataAdviseHolder_AddRef,
392 DataAdviseHolder_Release,
393 DataAdviseHolder_Advise,
394 DataAdviseHolder_Unadvise,
395 DataAdviseHolder_EnumAdvise,
396 DataAdviseHolder_SendOnDataChange
399 /******************************************************************************
400 * DataAdviseHolder_Constructor
402 static IDataAdviseHolder* DataAdviseHolder_Constructor()
404 DataAdviseHolder* newHolder;
406 newHolder = (DataAdviseHolder*)HeapAlloc(GetProcessHeap(),
408 sizeof(DataAdviseHolder));
410 newHolder->lpvtbl = &DataAdviseHolderImpl_VTable;
413 return (IDataAdviseHolder*)newHolder;
416 /******************************************************************************
417 * DataAdviseHolder_Destructor
419 static void DataAdviseHolder_Destructor(
420 DataAdviseHolder* ptrToDestroy)
422 HeapFree(GetProcessHeap(),
427 /************************************************************************
428 * DataAdviseHolder_QueryInterface (IUnknown)
430 * See Windows documentation for more details on IUnknown methods.
432 static HRESULT WINAPI DataAdviseHolder_QueryInterface(
433 IDataAdviseHolder* iface,
437 ICOM_THIS(DataAdviseHolder, iface);
440 * Perform a sanity check on the parameters.
442 if ( (This==0) || (ppvObject==0) )
446 * Initialize the return parameter.
451 * Compare the riid with the interface IDs implemented by this object.
453 if ( (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) ||
454 (memcmp(&IID_IDataAdviseHolder, riid, sizeof(IID_IDataAdviseHolder)) == 0) )
460 * Check that we obtained an interface.
464 return E_NOINTERFACE;
468 * Query Interface always increases the reference count by one when it is
471 IUnknown_AddRef((IUnknown*)*ppvObject);
476 /************************************************************************
477 * DataAdviseHolder_AddRef (IUnknown)
479 * See Windows documentation for more details on IUnknown methods.
481 static ULONG WINAPI DataAdviseHolder_AddRef(
482 IDataAdviseHolder* iface)
484 ICOM_THIS(DataAdviseHolder, iface);
491 /************************************************************************
492 * DataAdviseHolder_Release (IUnknown)
494 * See Windows documentation for more details on IUnknown methods.
496 static ULONG WINAPI DataAdviseHolder_Release(
497 IDataAdviseHolder* iface)
499 ICOM_THIS(DataAdviseHolder, iface);
502 * Decrease the reference count on this object.
507 * If the reference count goes down to 0, perform suicide.
511 DataAdviseHolder_Destructor(This);
519 static HRESULT WINAPI DataAdviseHolder_Advise(
520 IDataAdviseHolder* iface,
521 IDataObject* pDataObject,
524 IAdviseSink* pAdvise,
525 DWORD* pdwConnection)
531 static HRESULT WINAPI DataAdviseHolder_Unadvise(
532 IDataAdviseHolder* iface,
539 static HRESULT WINAPI DataAdviseHolder_EnumAdvise(
540 IDataAdviseHolder* iface,
541 IEnumSTATDATA** ppenumAdvise)
547 static HRESULT WINAPI DataAdviseHolder_SendOnDataChange(
548 IDataAdviseHolder* iface,
549 IDataObject* pDataObject,
557 /***********************************************************************
561 /***********************************************************************
562 * CreateOleAdviseHolder [OLE32.59]
564 HRESULT WINAPI CreateOleAdviseHolder(
565 LPOLEADVISEHOLDER *ppOAHolder)
567 TRACE("(%p)\n", ppOAHolder);
572 if (ppOAHolder==NULL)
575 *ppOAHolder = OleAdviseHolderImpl_Constructor ();
577 if (*ppOAHolder != NULL)
580 return E_OUTOFMEMORY;
583 /******************************************************************************
584 * CreateDataAdviseHolder [OLE32.53]
586 HRESULT WINAPI CreateDataAdviseHolder(
587 LPDATAADVISEHOLDER* ppDAHolder)
589 TRACE("(%p)\n", ppDAHolder);
594 if (ppDAHolder==NULL)
597 *ppDAHolder = DataAdviseHolder_Constructor();
599 if (*ppDAHolder != NULL)
602 return E_OUTOFMEMORY;