1998-11-22 19:06:33 +01:00
|
|
|
/*
|
|
|
|
* OLE2 COM objects
|
|
|
|
*
|
|
|
|
* Copyright 1998 Eric Kohl
|
1999-05-02 11:27:08 +02:00
|
|
|
* Copyright 1999 Francis Beaudet
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-02-28 13:27:56 +01:00
|
|
|
#include <string.h>
|
2004-10-07 05:06:48 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
2011-01-05 11:13:38 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
1999-02-28 20:14:33 +01:00
|
|
|
#include "winbase.h"
|
2003-09-09 21:39:31 +02:00
|
|
|
#include "winuser.h"
|
1998-11-22 19:06:33 +01:00
|
|
|
#include "winerror.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2002-12-05 21:33:07 +01:00
|
|
|
#include "ole2.h"
|
2000-08-03 06:22:35 +02:00
|
|
|
|
2008-06-22 10:41:19 +02:00
|
|
|
#include "compobj_private.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2000-07-08 13:46:54 +02:00
|
|
|
#define INITIAL_SINKS 10
|
1998-11-22 19:06:33 +01:00
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static void release_statdata(STATDATA *data)
|
|
|
|
{
|
|
|
|
if(data->formatetc.ptd)
|
|
|
|
{
|
|
|
|
CoTaskMemFree(data->formatetc.ptd);
|
|
|
|
data->formatetc.ptd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data->pAdvSink)
|
|
|
|
{
|
|
|
|
IAdviseSink_Release(data->pAdvSink);
|
|
|
|
data->pAdvSink = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT copy_statdata(STATDATA *dst, const STATDATA *src)
|
|
|
|
{
|
|
|
|
*dst = *src;
|
|
|
|
if(src->formatetc.ptd)
|
|
|
|
{
|
|
|
|
dst->formatetc.ptd = CoTaskMemAlloc(src->formatetc.ptd->tdSize);
|
|
|
|
if(!dst->formatetc.ptd) return E_OUTOFMEMORY;
|
|
|
|
memcpy(dst->formatetc.ptd, src->formatetc.ptd, src->formatetc.ptd->tdSize);
|
|
|
|
}
|
|
|
|
if(dst->pAdvSink) IAdviseSink_AddRef(dst->pAdvSink);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-22 19:06:33 +01:00
|
|
|
/**************************************************************************
|
2010-12-17 15:58:32 +01:00
|
|
|
* EnumSTATDATA Implementation
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2010-12-17 15:07:19 +01:00
|
|
|
static HRESULT EnumSTATDATA_Construct(IUnknown *holder, ULONG index, DWORD array_len, STATDATA *data, IEnumSTATDATA **ppenum);
|
2006-01-11 12:09:32 +01:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-12-04 22:14:37 +01:00
|
|
|
IEnumSTATDATA IEnumSTATDATA_iface;
|
2006-01-11 12:09:32 +01:00
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
ULONG index;
|
2010-12-16 13:20:51 +01:00
|
|
|
DWORD num_of_elems;
|
|
|
|
STATDATA *statdata;
|
|
|
|
IUnknown *holder;
|
|
|
|
} EnumSTATDATA;
|
2006-01-11 12:09:32 +01:00
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static inline EnumSTATDATA *impl_from_IEnumSTATDATA(IEnumSTATDATA *iface)
|
2010-12-04 22:14:37 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
return CONTAINING_RECORD(iface, EnumSTATDATA, IEnumSTATDATA_iface);
|
2010-12-04 22:14:37 +01:00
|
|
|
}
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static HRESULT WINAPI EnumSTATDATA_QueryInterface(IEnumSTATDATA *iface, REFIID riid, void **ppv)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
|
|
|
TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IEnumSTATDATA))
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*ppv = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static ULONG WINAPI EnumSTATDATA_AddRef(IEnumSTATDATA *iface)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
EnumSTATDATA *This = impl_from_IEnumSTATDATA(iface);
|
2006-01-11 12:09:32 +01:00
|
|
|
TRACE("()\n");
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static ULONG WINAPI EnumSTATDATA_Release(IEnumSTATDATA *iface)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
EnumSTATDATA *This = impl_from_IEnumSTATDATA(iface);
|
2006-01-11 12:09:32 +01:00
|
|
|
LONG refs = InterlockedDecrement(&This->ref);
|
|
|
|
TRACE("()\n");
|
|
|
|
if (!refs)
|
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
DWORD i;
|
|
|
|
for(i = 0; i < This->num_of_elems; i++)
|
|
|
|
release_statdata(This->statdata + i);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->statdata);
|
|
|
|
IUnknown_Release(This->holder);
|
2006-01-11 12:09:32 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
return refs;
|
|
|
|
}
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static HRESULT WINAPI EnumSTATDATA_Next(IEnumSTATDATA *iface, ULONG num, LPSTATDATA data,
|
|
|
|
ULONG *fetched)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
EnumSTATDATA *This = impl_from_IEnumSTATDATA(iface);
|
|
|
|
DWORD count = 0;
|
2006-01-11 12:09:32 +01:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
TRACE("(%d, %p, %p)\n", num, data, fetched);
|
2006-01-11 12:09:32 +01:00
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
while(num--)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
if (This->index >= This->num_of_elems)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
|
|
|
hr = S_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
copy_statdata(data + count, This->statdata + This->index);
|
2006-01-11 12:09:32 +01:00
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
count++;
|
2006-01-11 12:09:32 +01:00
|
|
|
This->index++;
|
|
|
|
}
|
2010-12-16 13:20:51 +01:00
|
|
|
|
|
|
|
if (fetched) *fetched = count;
|
|
|
|
|
2006-01-11 12:09:32 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static HRESULT WINAPI EnumSTATDATA_Skip(IEnumSTATDATA *iface, ULONG num)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
EnumSTATDATA *This = impl_from_IEnumSTATDATA(iface);
|
2006-01-11 12:09:32 +01:00
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
TRACE("(%d)\n", num);
|
2006-01-11 12:09:32 +01:00
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
if(This->index + num >= This->num_of_elems)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
This->index = This->num_of_elems;
|
|
|
|
return S_FALSE;
|
2006-01-11 12:09:32 +01:00
|
|
|
}
|
2010-12-16 13:20:51 +01:00
|
|
|
|
|
|
|
This->index += num;
|
2006-01-11 12:09:32 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static HRESULT WINAPI EnumSTATDATA_Reset(IEnumSTATDATA *iface)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
EnumSTATDATA *This = impl_from_IEnumSTATDATA(iface);
|
2006-01-11 12:09:32 +01:00
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
This->index = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static HRESULT WINAPI EnumSTATDATA_Clone(IEnumSTATDATA *iface, IEnumSTATDATA **ppenum)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
EnumSTATDATA *This = impl_from_IEnumSTATDATA(iface);
|
|
|
|
|
|
|
|
return EnumSTATDATA_Construct(This->holder, This->index, This->num_of_elems, This->statdata, ppenum);
|
2006-01-11 12:09:32 +01:00
|
|
|
}
|
|
|
|
|
2010-12-16 13:20:51 +01:00
|
|
|
static const IEnumSTATDATAVtbl EnumSTATDATA_VTable =
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
EnumSTATDATA_QueryInterface,
|
|
|
|
EnumSTATDATA_AddRef,
|
|
|
|
EnumSTATDATA_Release,
|
|
|
|
EnumSTATDATA_Next,
|
|
|
|
EnumSTATDATA_Skip,
|
|
|
|
EnumSTATDATA_Reset,
|
|
|
|
EnumSTATDATA_Clone
|
2006-01-11 12:09:32 +01:00
|
|
|
};
|
|
|
|
|
2010-12-17 15:07:19 +01:00
|
|
|
static HRESULT EnumSTATDATA_Construct(IUnknown *holder, ULONG index, DWORD array_len, STATDATA *data,
|
2010-12-16 13:20:51 +01:00
|
|
|
IEnumSTATDATA **ppenum)
|
2006-01-11 12:09:32 +01:00
|
|
|
{
|
2010-12-16 13:20:51 +01:00
|
|
|
EnumSTATDATA *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
|
2010-12-17 15:07:19 +01:00
|
|
|
DWORD i, count;
|
2010-12-16 13:20:51 +01:00
|
|
|
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IEnumSTATDATA_iface.lpVtbl = &EnumSTATDATA_VTable;
|
2006-01-11 12:09:32 +01:00
|
|
|
This->ref = 1;
|
|
|
|
This->index = index;
|
2010-12-16 13:20:51 +01:00
|
|
|
|
2010-12-17 15:07:19 +01:00
|
|
|
This->statdata = HeapAlloc(GetProcessHeap(), 0, array_len * sizeof(*This->statdata));
|
2010-12-16 13:20:51 +01:00
|
|
|
if(!This->statdata)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2010-12-17 15:07:19 +01:00
|
|
|
for(i = 0, count = 0; i < array_len; i++)
|
|
|
|
{
|
|
|
|
if(data[i].pAdvSink)
|
|
|
|
{
|
|
|
|
copy_statdata(This->statdata + count, data + i);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2010-12-16 13:20:51 +01:00
|
|
|
|
2010-12-17 15:07:19 +01:00
|
|
|
This->num_of_elems = count;
|
2010-12-16 13:20:51 +01:00
|
|
|
This->holder = holder;
|
|
|
|
IUnknown_AddRef(holder);
|
2010-12-04 22:14:37 +01:00
|
|
|
*ppenum = &This->IEnumSTATDATA_iface;
|
|
|
|
return S_OK;
|
2006-01-11 12:09:32 +01:00
|
|
|
}
|
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* OleAdviseHolder Implementation
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
IOleAdviseHolder IOleAdviseHolder_iface;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
DWORD max_cons;
|
|
|
|
STATDATA *connections;
|
2010-12-17 15:58:32 +01:00
|
|
|
} OleAdviseHolderImpl;
|
|
|
|
|
|
|
|
static inline OleAdviseHolderImpl *impl_from_IOleAdviseHolder(IOleAdviseHolder *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, OleAdviseHolderImpl, IOleAdviseHolder_iface);
|
|
|
|
}
|
|
|
|
|
1998-11-22 19:06:33 +01:00
|
|
|
/**************************************************************************
|
1999-05-02 11:27:08 +02:00
|
|
|
* OleAdviseHolderImpl_Destructor
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2011-01-05 12:20:11 +01:00
|
|
|
static void OleAdviseHolderImpl_Destructor(OleAdviseHolderImpl *This)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
2011-01-05 12:20:11 +01:00
|
|
|
DWORD index;
|
|
|
|
TRACE("%p\n", This);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
for (index = 0; index < This->max_cons; index++)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2011-01-05 12:20:11 +01:00
|
|
|
if (This->connections[index].pAdvSink != NULL)
|
|
|
|
release_statdata(This->connections + index);
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->connections);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
1998-11-22 19:06:33 +01:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* OleAdviseHolderImpl_QueryInterface
|
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI OleAdviseHolderImpl_QueryInterface(IOleAdviseHolder *iface,
|
|
|
|
REFIID iid, void **obj)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
|
|
|
|
TRACE("(%p)->(%s,%p)\n",This, debugstr_guid(iid), obj);
|
2010-12-17 12:51:47 +01:00
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
if (obj == NULL)
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_POINTER;
|
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
*obj = NULL;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
if (IsEqualIID(iid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(iid, &IID_IOleAdviseHolder))
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
*obj = &This->IOleAdviseHolder_iface;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
if(*obj == NULL)
|
1998-11-22 19:06:33 +01:00
|
|
|
return E_NOINTERFACE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
IUnknown_AddRef((IUnknown*)*obj);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
return S_OK;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-05-02 11:27:08 +02:00
|
|
|
* OleAdviseHolderImpl_AddRef
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static ULONG WINAPI OleAdviseHolderImpl_AddRef(IOleAdviseHolder *iface)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
|
2005-01-09 18:29:21 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p)->(ref=%d)\n", This, ref - 1);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
|
|
|
return ref;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-05-02 11:27:08 +02:00
|
|
|
* OleAdviseHolderImpl_Release
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static ULONG WINAPI OleAdviseHolderImpl_Release(IOleAdviseHolder *iface)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
|
2004-09-24 03:16:53 +02:00
|
|
|
ULONG ref;
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p)->(ref=%d)\n", This, This->ref);
|
2004-09-24 03:16:53 +02:00
|
|
|
ref = InterlockedDecrement(&This->ref);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
if (ref == 0) OleAdviseHolderImpl_Destructor(This);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
return ref;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-05-02 11:27:08 +02:00
|
|
|
* OleAdviseHolderImpl_Advise
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI OleAdviseHolderImpl_Advise(IOleAdviseHolder *iface,
|
|
|
|
IAdviseSink *pAdvise,
|
|
|
|
DWORD *pdwConnection)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
1999-05-02 11:27:08 +02:00
|
|
|
DWORD index;
|
2010-12-17 15:58:32 +01:00
|
|
|
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
|
2011-01-05 12:20:11 +01:00
|
|
|
STATDATA new_conn;
|
|
|
|
static const FORMATETC empty_fmtetc = {0, NULL, 0, -1, 0};
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2000-07-08 13:46:54 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", This, pAdvise, pdwConnection);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
if (pdwConnection==NULL)
|
|
|
|
return E_POINTER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
*pdwConnection = 0;
|
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
for (index = 0; index < This->max_cons; index++)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2011-01-05 12:20:11 +01:00
|
|
|
if (This->connections[index].pAdvSink == NULL)
|
1999-05-02 11:27:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
if (index == This->max_cons)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2011-01-05 12:20:11 +01:00
|
|
|
This->max_cons += INITIAL_SINKS;
|
|
|
|
This->connections = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->connections,
|
|
|
|
This->max_cons * sizeof(*This->connections));
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
new_conn.pAdvSink = pAdvise;
|
|
|
|
new_conn.advf = 0;
|
|
|
|
new_conn.formatetc = empty_fmtetc;
|
|
|
|
new_conn.dwConnection = index + 1; /* 0 is not a valid cookie, so increment the index */
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
copy_statdata(This->connections + index, &new_conn);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
*pdwConnection = new_conn.dwConnection;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
return S_OK;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-05-02 11:27:08 +02:00
|
|
|
* OleAdviseHolderImpl_Unadvise
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI OleAdviseHolderImpl_Unadvise(IOleAdviseHolder *iface,
|
|
|
|
DWORD dwConnection)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
|
2011-01-05 12:20:11 +01:00
|
|
|
DWORD index;
|
1998-11-22 19:06:33 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p)->(%u)\n", This, dwConnection);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
/* The connection number is 1 more than the index, see OleAdviseHolder_Advise */
|
|
|
|
index = dwConnection - 1;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
if (index >= This->max_cons || This->connections[index].pAdvSink == NULL)
|
|
|
|
return OLE_E_NOCONNECTION;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
release_statdata(This->connections + index);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
return S_OK;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-05-02 11:27:08 +02:00
|
|
|
* OleAdviseHolderImpl_EnumAdvise
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2011-01-05 12:20:11 +01:00
|
|
|
static HRESULT WINAPI OleAdviseHolderImpl_EnumAdvise(IOleAdviseHolder *iface, IEnumSTATDATA **enum_advise)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
|
2010-12-16 13:20:51 +01:00
|
|
|
IUnknown *unk;
|
|
|
|
HRESULT hr;
|
2006-01-11 12:09:32 +01:00
|
|
|
|
2011-01-05 12:20:11 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, enum_advise);
|
2010-12-16 13:20:51 +01:00
|
|
|
|
|
|
|
IOleAdviseHolder_QueryInterface(iface, &IID_IUnknown, (void**)&unk);
|
2011-01-05 12:20:11 +01:00
|
|
|
hr = EnumSTATDATA_Construct(unk, 0, This->max_cons, This->connections, enum_advise);
|
2010-12-16 13:20:51 +01:00
|
|
|
IUnknown_Release(unk);
|
|
|
|
return hr;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-05-02 11:27:08 +02:00
|
|
|
* OleAdviseHolderImpl_SendOnRename
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI OleAdviseHolderImpl_SendOnRename(IOleAdviseHolder *iface, IMoniker *pmk)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
2006-01-11 12:09:32 +01:00
|
|
|
IEnumSTATDATA *pEnum;
|
|
|
|
HRESULT hr;
|
1998-11-22 19:06:33 +01:00
|
|
|
|
2006-01-11 12:09:32 +01:00
|
|
|
TRACE("(%p)->(%p)\n", iface, pmk);
|
1998-11-22 19:06:33 +01:00
|
|
|
|
2006-01-11 12:09:32 +01:00
|
|
|
hr = IOleAdviseHolder_EnumAdvise(iface, &pEnum);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
STATDATA statdata;
|
|
|
|
while (IEnumSTATDATA_Next(pEnum, 1, &statdata, NULL) == S_OK)
|
|
|
|
{
|
|
|
|
IAdviseSink_OnRename(statdata.pAdvSink, pmk);
|
|
|
|
|
|
|
|
IAdviseSink_Release(statdata.pAdvSink);
|
|
|
|
}
|
|
|
|
IEnumSTATDATA_Release(pEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-05-02 11:27:08 +02:00
|
|
|
* OleAdviseHolderImpl_SendOnSave
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI OleAdviseHolderImpl_SendOnSave(IOleAdviseHolder *iface)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
2006-01-11 12:09:32 +01:00
|
|
|
IEnumSTATDATA *pEnum;
|
|
|
|
HRESULT hr;
|
1998-11-22 19:06:33 +01:00
|
|
|
|
2006-01-11 12:09:32 +01:00
|
|
|
TRACE("(%p)->()\n", iface);
|
|
|
|
|
|
|
|
hr = IOleAdviseHolder_EnumAdvise(iface, &pEnum);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
STATDATA statdata;
|
|
|
|
while (IEnumSTATDATA_Next(pEnum, 1, &statdata, NULL) == S_OK)
|
|
|
|
{
|
|
|
|
IAdviseSink_OnSave(statdata.pAdvSink);
|
|
|
|
|
|
|
|
IAdviseSink_Release(statdata.pAdvSink);
|
|
|
|
}
|
|
|
|
IEnumSTATDATA_Release(pEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-05-02 11:27:08 +02:00
|
|
|
* OleAdviseHolderImpl_SendOnClose
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI OleAdviseHolderImpl_SendOnClose(IOleAdviseHolder *iface)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
2006-01-11 12:09:32 +01:00
|
|
|
IEnumSTATDATA *pEnum;
|
|
|
|
HRESULT hr;
|
1998-11-22 19:06:33 +01:00
|
|
|
|
2006-01-11 12:09:32 +01:00
|
|
|
TRACE("(%p)->()\n", iface);
|
1998-11-22 19:06:33 +01:00
|
|
|
|
2006-01-11 12:09:32 +01:00
|
|
|
hr = IOleAdviseHolder_EnumAdvise(iface, &pEnum);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
STATDATA statdata;
|
|
|
|
while (IEnumSTATDATA_Next(pEnum, 1, &statdata, NULL) == S_OK)
|
|
|
|
{
|
|
|
|
IAdviseSink_OnClose(statdata.pAdvSink);
|
|
|
|
|
|
|
|
IAdviseSink_Release(statdata.pAdvSink);
|
|
|
|
}
|
|
|
|
IEnumSTATDATA_Release(pEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|
|
|
|
|
2005-05-23 18:31:13 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* OleAdviseHolderImpl_VTable
|
|
|
|
*/
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IOleAdviseHolderVtbl oahvt =
|
2005-05-23 18:31:13 +02:00
|
|
|
{
|
|
|
|
OleAdviseHolderImpl_QueryInterface,
|
|
|
|
OleAdviseHolderImpl_AddRef,
|
|
|
|
OleAdviseHolderImpl_Release,
|
|
|
|
OleAdviseHolderImpl_Advise,
|
|
|
|
OleAdviseHolderImpl_Unadvise,
|
|
|
|
OleAdviseHolderImpl_EnumAdvise,
|
|
|
|
OleAdviseHolderImpl_SendOnRename,
|
|
|
|
OleAdviseHolderImpl_SendOnSave,
|
|
|
|
OleAdviseHolderImpl_SendOnClose
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* OleAdviseHolderImpl_Constructor
|
|
|
|
*/
|
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
static IOleAdviseHolder *OleAdviseHolderImpl_Constructor(void)
|
2005-05-23 18:31:13 +02:00
|
|
|
{
|
|
|
|
OleAdviseHolderImpl* lpoah;
|
|
|
|
|
|
|
|
lpoah = HeapAlloc(GetProcessHeap(), 0, sizeof(OleAdviseHolderImpl));
|
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
lpoah->IOleAdviseHolder_iface.lpVtbl = &oahvt;
|
2005-05-23 18:31:13 +02:00
|
|
|
lpoah->ref = 1;
|
2011-01-05 12:20:11 +01:00
|
|
|
lpoah->max_cons = INITIAL_SINKS;
|
|
|
|
lpoah->connections = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
lpoah->max_cons * sizeof(*lpoah->connections));
|
2005-05-23 18:31:13 +02:00
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
TRACE("returning %p\n", &lpoah->IOleAdviseHolder_iface);
|
|
|
|
return &lpoah->IOleAdviseHolder_iface;
|
2005-05-23 18:31:13 +02:00
|
|
|
}
|
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* DataAdviseHolder Implementation
|
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
typedef struct
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
IDataAdviseHolder IDataAdviseHolder_iface;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2005-07-05 13:02:54 +02:00
|
|
|
LONG ref;
|
2000-07-08 13:46:54 +02:00
|
|
|
DWORD maxCons;
|
2010-12-17 14:13:17 +01:00
|
|
|
STATDATA* connections;
|
|
|
|
DWORD* remote_connections;
|
2006-08-07 13:59:04 +02:00
|
|
|
IDataObject* delegate;
|
1999-05-02 11:27:08 +02:00
|
|
|
} DataAdviseHolder;
|
|
|
|
|
2005-11-28 11:16:58 +01:00
|
|
|
/* this connection has also has been advised to the delegate data object */
|
|
|
|
#define WINE_ADVF_REMOTE 0x80000000
|
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
static inline DataAdviseHolder *impl_from_IDataAdviseHolder(IDataAdviseHolder *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, DataAdviseHolder, IDataAdviseHolder_iface);
|
|
|
|
}
|
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* DataAdviseHolder_Destructor
|
|
|
|
*/
|
2000-07-08 13:46:54 +02:00
|
|
|
static void DataAdviseHolder_Destructor(DataAdviseHolder* ptrToDestroy)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2000-07-08 13:46:54 +02:00
|
|
|
DWORD index;
|
|
|
|
TRACE("%p\n", ptrToDestroy);
|
|
|
|
|
|
|
|
for (index = 0; index < ptrToDestroy->maxCons; index++)
|
|
|
|
{
|
2010-12-17 14:13:17 +01:00
|
|
|
if (ptrToDestroy->connections[index].pAdvSink != NULL)
|
2000-07-08 13:46:54 +02:00
|
|
|
{
|
2006-08-07 13:59:04 +02:00
|
|
|
if (ptrToDestroy->delegate &&
|
2010-12-17 14:13:17 +01:00
|
|
|
(ptrToDestroy->connections[index].advf & WINE_ADVF_REMOTE))
|
2006-08-07 13:59:04 +02:00
|
|
|
IDataObject_DUnadvise(ptrToDestroy->delegate,
|
2010-12-17 14:13:17 +01:00
|
|
|
ptrToDestroy->remote_connections[index]);
|
2006-08-07 13:59:04 +02:00
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
release_statdata(ptrToDestroy->connections + index);
|
2000-07-08 13:46:54 +02:00
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, ptrToDestroy->remote_connections);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptrToDestroy->connections);
|
2000-07-08 13:46:54 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ptrToDestroy);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataAdviseHolder_QueryInterface (IUnknown)
|
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI DataAdviseHolder_QueryInterface(IDataAdviseHolder *iface,
|
|
|
|
REFIID riid, void **ppvObject)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
|
2000-07-08 13:46:54 +02:00
|
|
|
TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
|
2010-12-17 12:51:47 +01:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
if ( (This==0) || (ppvObject==0) )
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
*ppvObject = 0;
|
|
|
|
|
2010-07-23 11:30:00 +02:00
|
|
|
if ( IsEqualIID(&IID_IUnknown, riid) ||
|
|
|
|
IsEqualIID(&IID_IDataAdviseHolder, riid) )
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
if ((*ppvObject)==0)
|
|
|
|
{
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
IUnknown_AddRef((IUnknown*)*ppvObject);
|
2002-06-01 01:06:46 +02:00
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataAdviseHolder_AddRef (IUnknown)
|
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static ULONG WINAPI DataAdviseHolder_AddRef(IDataAdviseHolder *iface)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p) (ref=%d)\n", This, This->ref);
|
2004-09-24 03:16:53 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataAdviseHolder_Release (IUnknown)
|
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static ULONG WINAPI DataAdviseHolder_Release(IDataAdviseHolder *iface)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
|
2004-09-24 03:16:53 +02:00
|
|
|
ULONG ref;
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p) (ref=%d)\n", This, This->ref);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (ref==0) DataAdviseHolder_Destructor(This);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
return ref;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2000-07-08 13:46:54 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataAdviseHolder_Advise
|
|
|
|
*
|
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI DataAdviseHolder_Advise(IDataAdviseHolder *iface,
|
|
|
|
IDataObject *pDataObject, FORMATETC *pFetc,
|
|
|
|
DWORD advf, IAdviseSink *pAdvise,
|
|
|
|
DWORD *pdwConnection)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2000-07-08 13:46:54 +02:00
|
|
|
DWORD index;
|
2010-12-17 14:13:17 +01:00
|
|
|
STATDATA new_conn;
|
2010-12-17 15:58:32 +01:00
|
|
|
DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
|
2000-07-08 13:46:54 +02:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %08x, %p, %p)\n", This, pDataObject, pFetc, advf,
|
2000-07-08 13:46:54 +02:00
|
|
|
pAdvise, pdwConnection);
|
2010-12-17 12:51:47 +01:00
|
|
|
|
2000-07-08 13:46:54 +02:00
|
|
|
if (pdwConnection==NULL)
|
|
|
|
return E_POINTER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-08 13:46:54 +02:00
|
|
|
*pdwConnection = 0;
|
|
|
|
|
|
|
|
for (index = 0; index < This->maxCons; index++)
|
|
|
|
{
|
2010-12-17 14:13:17 +01:00
|
|
|
if (This->connections[index].pAdvSink == NULL)
|
2000-07-08 13:46:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index == This->maxCons)
|
|
|
|
{
|
|
|
|
This->maxCons+=INITIAL_SINKS;
|
2010-12-17 14:13:17 +01:00
|
|
|
This->connections = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
This->connections,
|
|
|
|
This->maxCons * sizeof(*This->connections));
|
|
|
|
This->remote_connections = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
This->remote_connections,
|
|
|
|
This->maxCons * sizeof(*This->remote_connections));
|
2000-07-08 13:46:54 +02:00
|
|
|
}
|
2010-12-17 12:51:47 +01:00
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
new_conn.pAdvSink = pAdvise;
|
|
|
|
new_conn.advf = advf & ~WINE_ADVF_REMOTE;
|
|
|
|
new_conn.formatetc = *pFetc;
|
|
|
|
new_conn.dwConnection = index + 1; /* 0 is not a valid cookie, so increment the index */
|
2000-07-08 13:46:54 +02:00
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
copy_statdata(This->connections + index, &new_conn);
|
2006-08-07 13:59:04 +02:00
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
if (This->connections[index].pAdvSink != NULL)
|
|
|
|
{
|
2006-08-07 13:59:04 +02:00
|
|
|
/* if we are already connected advise the remote object */
|
|
|
|
if (This->delegate)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
hr = IDataObject_DAdvise(This->delegate, &new_conn.formatetc,
|
|
|
|
new_conn.advf, new_conn.pAdvSink,
|
|
|
|
&This->remote_connections[index]);
|
2006-08-07 13:59:04 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2010-12-17 14:13:17 +01:00
|
|
|
IDataAdviseHolder_Unadvise(iface, new_conn.dwConnection);
|
2006-08-07 13:59:04 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2010-12-17 14:13:17 +01:00
|
|
|
This->connections[index].advf |= WINE_ADVF_REMOTE;
|
2006-08-07 13:59:04 +02:00
|
|
|
}
|
2006-08-31 18:20:09 +02:00
|
|
|
else if(advf & ADVF_PRIMEFIRST)
|
|
|
|
/* only do this if we have no delegate, since in the above case the
|
|
|
|
* delegate will do the priming for us */
|
|
|
|
IDataAdviseHolder_SendOnDataChange(iface, pDataObject, 0, advf);
|
2000-07-08 13:46:54 +02:00
|
|
|
}
|
2010-12-17 14:13:17 +01:00
|
|
|
|
|
|
|
*pdwConnection = new_conn.dwConnection;
|
2000-07-08 13:46:54 +02:00
|
|
|
|
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2000-07-08 13:46:54 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* DataAdviseHolder_Unadvise
|
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI DataAdviseHolder_Unadvise(IDataAdviseHolder *iface,
|
|
|
|
DWORD dwConnection)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
|
2010-12-17 14:13:17 +01:00
|
|
|
DWORD index;
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p)->(%u)\n", This, dwConnection);
|
2000-07-08 13:46:54 +02:00
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
/* The connection number is 1 more than the index, see DataAdviseHolder_Advise */
|
|
|
|
index = dwConnection - 1;
|
2000-07-08 13:46:54 +02:00
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
if (index >= This->maxCons || This->connections[index].pAdvSink == NULL)
|
|
|
|
return OLE_E_NOCONNECTION;
|
2000-07-08 13:46:54 +02:00
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
if (This->delegate && This->connections[index].advf & WINE_ADVF_REMOTE)
|
|
|
|
{
|
|
|
|
IDataObject_DUnadvise(This->delegate, This->remote_connections[index]);
|
|
|
|
This->remote_connections[index] = 0;
|
|
|
|
}
|
2006-08-07 13:59:04 +02:00
|
|
|
|
2010-12-17 14:13:17 +01:00
|
|
|
release_statdata(This->connections + index);
|
2006-08-07 13:59:04 +02:00
|
|
|
|
2000-07-08 13:46:54 +02:00
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2010-12-17 15:13:03 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* DataAdviseHolder_EnumAdvise
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataAdviseHolder_EnumAdvise(IDataAdviseHolder *iface,
|
|
|
|
IEnumSTATDATA **enum_advise)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
|
2010-12-17 15:13:03 +01:00
|
|
|
IUnknown *unk;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, enum_advise);
|
2000-07-08 13:46:54 +02:00
|
|
|
|
2010-12-17 15:13:03 +01:00
|
|
|
IDataAdviseHolder_QueryInterface(iface, &IID_IUnknown, (void**)&unk);
|
|
|
|
hr = EnumSTATDATA_Construct(unk, 0, This->maxCons, This->connections, enum_advise);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
return hr;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2000-07-08 13:46:54 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* DataAdviseHolder_SendOnDataChange
|
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static HRESULT WINAPI DataAdviseHolder_SendOnDataChange(IDataAdviseHolder *iface,
|
2011-01-05 11:13:38 +01:00
|
|
|
IDataObject *data_obj,
|
2010-12-17 15:58:32 +01:00
|
|
|
DWORD dwReserved, DWORD advf)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2011-01-05 11:13:38 +01:00
|
|
|
IEnumSTATDATA *pEnum;
|
|
|
|
HRESULT hr;
|
2000-07-08 13:46:54 +02:00
|
|
|
|
2011-01-05 11:13:38 +01:00
|
|
|
TRACE("(%p)->(%p, %08x, %08x)\n", iface, data_obj, dwReserved, advf);
|
2000-07-08 13:46:54 +02:00
|
|
|
|
2011-01-05 11:13:38 +01:00
|
|
|
hr = IDataAdviseHolder_EnumAdvise(iface, &pEnum);
|
|
|
|
if (SUCCEEDED(hr))
|
2010-12-17 14:13:17 +01:00
|
|
|
{
|
2011-01-05 11:13:38 +01:00
|
|
|
STATDATA statdata;
|
|
|
|
while (IEnumSTATDATA_Next(pEnum, 1, &statdata, NULL) == S_OK)
|
|
|
|
{
|
|
|
|
STGMEDIUM stg;
|
|
|
|
stg.tymed = TYMED_NULL;
|
|
|
|
stg.u.pstg = NULL;
|
|
|
|
stg.pUnkForRelease = NULL;
|
|
|
|
|
|
|
|
if(!(statdata.advf & ADVF_NODATA))
|
|
|
|
{
|
|
|
|
hr = IDataObject_GetData(data_obj, &statdata.formatetc, &stg);
|
|
|
|
}
|
|
|
|
|
|
|
|
IAdviseSink_OnDataChange(statdata.pAdvSink, &statdata.formatetc, &stg);
|
|
|
|
|
|
|
|
if(statdata.advf & ADVF_ONLYONCE)
|
|
|
|
{
|
|
|
|
IDataAdviseHolder_Unadvise(iface, statdata.dwConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
release_statdata(&statdata);
|
|
|
|
}
|
|
|
|
IEnumSTATDATA_Release(pEnum);
|
2000-07-08 13:46:54 +02:00
|
|
|
}
|
2011-01-05 11:13:38 +01:00
|
|
|
|
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2005-05-23 18:31:13 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* DataAdviseHolderImpl_VTable
|
|
|
|
*/
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IDataAdviseHolderVtbl DataAdviseHolderImpl_VTable =
|
2005-05-23 18:31:13 +02:00
|
|
|
{
|
|
|
|
DataAdviseHolder_QueryInterface,
|
|
|
|
DataAdviseHolder_AddRef,
|
|
|
|
DataAdviseHolder_Release,
|
|
|
|
DataAdviseHolder_Advise,
|
|
|
|
DataAdviseHolder_Unadvise,
|
|
|
|
DataAdviseHolder_EnumAdvise,
|
|
|
|
DataAdviseHolder_SendOnDataChange
|
|
|
|
};
|
|
|
|
|
2005-11-28 11:16:58 +01:00
|
|
|
HRESULT DataAdviseHolder_OnConnect(IDataAdviseHolder *iface, IDataObject *pDelegate)
|
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
|
2005-11-28 11:16:58 +01:00
|
|
|
DWORD index;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
for(index = 0; index < This->maxCons; index++)
|
|
|
|
{
|
2010-12-17 14:13:17 +01:00
|
|
|
if(This->connections[index].pAdvSink != NULL)
|
2005-11-28 11:16:58 +01:00
|
|
|
{
|
2010-12-17 14:13:17 +01:00
|
|
|
hr = IDataObject_DAdvise(pDelegate, &This->connections[index].formatetc,
|
|
|
|
This->connections[index].advf,
|
|
|
|
This->connections[index].pAdvSink,
|
|
|
|
&This->remote_connections[index]);
|
2005-11-28 11:16:58 +01:00
|
|
|
if (FAILED(hr)) break;
|
2010-12-17 14:13:17 +01:00
|
|
|
This->connections[index].advf |= WINE_ADVF_REMOTE;
|
2005-11-28 11:16:58 +01:00
|
|
|
}
|
|
|
|
}
|
2006-08-07 13:59:04 +02:00
|
|
|
This->delegate = pDelegate;
|
2005-11-28 11:16:58 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataAdviseHolder_OnDisconnect(IDataAdviseHolder *iface)
|
|
|
|
{
|
2010-12-17 15:58:32 +01:00
|
|
|
DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
|
2006-08-07 13:59:04 +02:00
|
|
|
DWORD index;
|
|
|
|
|
|
|
|
for(index = 0; index < This->maxCons; index++)
|
|
|
|
{
|
2010-12-17 14:13:17 +01:00
|
|
|
if((This->connections[index].pAdvSink != NULL) &&
|
|
|
|
(This->connections[index].advf & WINE_ADVF_REMOTE))
|
2006-08-07 13:59:04 +02:00
|
|
|
{
|
2010-12-17 14:13:17 +01:00
|
|
|
IDataObject_DUnadvise(This->delegate, This->remote_connections[index]);
|
|
|
|
This->remote_connections[index] = 0;
|
|
|
|
This->connections[index].advf &= ~WINE_ADVF_REMOTE;
|
2006-08-07 13:59:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
This->delegate = NULL;
|
2005-11-28 11:16:58 +01:00
|
|
|
}
|
|
|
|
|
2005-05-23 18:31:13 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* DataAdviseHolder_Constructor
|
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
static IDataAdviseHolder *DataAdviseHolder_Constructor(void)
|
2005-05-23 18:31:13 +02:00
|
|
|
{
|
|
|
|
DataAdviseHolder* newHolder;
|
|
|
|
|
|
|
|
newHolder = HeapAlloc(GetProcessHeap(), 0, sizeof(DataAdviseHolder));
|
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
newHolder->IDataAdviseHolder_iface.lpVtbl = &DataAdviseHolderImpl_VTable;
|
2005-05-23 18:31:13 +02:00
|
|
|
newHolder->ref = 1;
|
|
|
|
newHolder->maxCons = INITIAL_SINKS;
|
2010-12-17 14:13:17 +01:00
|
|
|
newHolder->connections = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
newHolder->maxCons * sizeof(*newHolder->connections));
|
|
|
|
newHolder->remote_connections = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
newHolder->maxCons * sizeof(*newHolder->remote_connections));
|
2006-08-07 13:59:04 +02:00
|
|
|
newHolder->delegate = NULL;
|
2005-05-23 18:31:13 +02:00
|
|
|
|
2010-12-17 15:58:32 +01:00
|
|
|
TRACE("returning %p\n", &newHolder->IDataAdviseHolder_iface);
|
|
|
|
return &newHolder->IDataAdviseHolder_iface;
|
2005-05-23 18:31:13 +02:00
|
|
|
}
|
|
|
|
|
1998-11-22 19:06:33 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* API functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CreateOleAdviseHolder [OLE32.@]
|
1998-11-22 19:06:33 +01:00
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
HRESULT WINAPI CreateOleAdviseHolder(IOleAdviseHolder **ppOAHolder)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n", ppOAHolder);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
if (ppOAHolder==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppOAHolder = OleAdviseHolderImpl_Constructor ();
|
|
|
|
|
|
|
|
if (*ppOAHolder != NULL)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CreateDataAdviseHolder [OLE32.@]
|
1999-05-02 11:27:08 +02:00
|
|
|
*/
|
2010-12-17 15:58:32 +01:00
|
|
|
HRESULT WINAPI CreateDataAdviseHolder(IDataAdviseHolder **ppDAHolder)
|
1998-11-22 19:06:33 +01:00
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n", ppDAHolder);
|
1998-11-22 19:06:33 +01:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
if (ppDAHolder==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppDAHolder = DataAdviseHolder_Constructor();
|
|
|
|
|
|
|
|
if (*ppDAHolder != NULL)
|
|
|
|
return S_OK;
|
1998-11-22 19:06:33 +01:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_OUTOFMEMORY;
|
1998-11-22 19:06:33 +01:00
|
|
|
}
|