Added implementation of IConnectionPoint::Advise and Unadvise.

This commit is contained in:
Jacek Caban 2005-12-02 11:26:32 +01:00 committed by Alexandre Julliard
parent 548d08884b
commit 932cf2870e
2 changed files with 90 additions and 17 deletions

View File

@ -27,13 +27,16 @@
WINE_DEFAULT_DEBUG_CHANNEL(shdocvw); WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
typedef struct { struct ConnectionPoint {
const IConnectionPointVtbl *lpConnectionPointVtbl; const IConnectionPointVtbl *lpConnectionPointVtbl;
WebBrowser *webbrowser; WebBrowser *webbrowser;
IDispatch **sinks;
DWORD sinks_size;
IID iid; IID iid;
} ConnectionPoint; };
#define CONPOINT(x) ((IConnectionPoint*) &(x)->lpConnectionPointVtbl) #define CONPOINT(x) ((IConnectionPoint*) &(x)->lpConnectionPointVtbl)
@ -84,13 +87,13 @@ static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPo
if(IsEqualGUID(&DIID_DWebBrowserEvents2, riid)) { if(IsEqualGUID(&DIID_DWebBrowserEvents2, riid)) {
TRACE("(%p)->(DIID_DWebBrowserEvents2 %p)\n", This, ppCP); TRACE("(%p)->(DIID_DWebBrowserEvents2 %p)\n", This, ppCP);
*ppCP = This->cp_wbe2; *ppCP = CONPOINT(This->cp_wbe2);
}else if(IsEqualGUID(&DIID_DWebBrowserEvents, riid)) { }else if(IsEqualGUID(&DIID_DWebBrowserEvents, riid)) {
TRACE("(%p)->(DIID_DWebBrowserEvents %p)\n", This, ppCP); TRACE("(%p)->(DIID_DWebBrowserEvents %p)\n", This, ppCP);
*ppCP = This->cp_wbe; *ppCP = CONPOINT(This->cp_wbe);
}else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) { }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP); TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP);
*ppCP = This->cp_pns; *ppCP = CONPOINT(This->cp_pns);
} }
if(*ppCP) { if(*ppCP) {
@ -181,15 +184,53 @@ static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *
DWORD *pdwCookie) DWORD *pdwCookie)
{ {
ConnectionPoint *This = CONPOINT_THIS(iface); ConnectionPoint *This = CONPOINT_THIS(iface);
FIXME("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie); IDispatch *disp;
return E_NOTIMPL; DWORD i;
HRESULT hres;
TRACE("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
hres = IUnknown_QueryInterface(pUnkSink, &This->iid, (void**)&disp);
if(FAILED(hres)) {
hres = IUnknown_QueryInterface(pUnkSink, &IID_IDispatch, (void**)&disp);
if(FAILED(hres))
return CONNECT_E_CANNOTCONNECT;
}
if(This->sinks) {
for(i=0; i<This->sinks_size; i++) {
if(!This->sinks[i])
break;
}
if(i == This->sinks_size)
This->sinks = HeapReAlloc(GetProcessHeap(), 0, This->sinks,
(++This->sinks_size)*sizeof(*This->sinks));
}else {
This->sinks = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->sinks));
This->sinks_size = 1;
i = 0;
}
This->sinks[i] = disp;
*pdwCookie = i+1;
return S_OK;
} }
static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie) static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
{ {
ConnectionPoint *This = CONPOINT_THIS(iface); ConnectionPoint *This = CONPOINT_THIS(iface);
FIXME("(%p)->(%ld)\n", This, dwCookie);
return E_NOTIMPL; TRACE("(%p)->(%ld)\n", This, dwCookie);
if(!dwCookie || dwCookie > This->sinks_size || !This->sinks[dwCookie-1])
return CONNECT_E_NOCONNECTION;
IDispatch_Release(This->sinks[dwCookie-1]);
This->sinks[dwCookie-1] = NULL;
return S_OK;
} }
static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface, static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
@ -214,15 +255,43 @@ static const IConnectionPointVtbl ConnectionPointVtbl =
ConnectionPoint_EnumConnections ConnectionPoint_EnumConnections
}; };
static void ConnectionPoint_Create(WebBrowser *wb, REFIID riid, IConnectionPoint **cp) void call_sink(ConnectionPoint *This, DISPID dispid, DISPPARAMS *dispparams)
{
DWORD i;
for(i=0; i<This->sinks_size; i++) {
if(This->sinks[i])
IDispatch_Invoke(This->sinks[i], dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, dispparams, NULL, NULL, NULL);
}
}
static void ConnectionPoint_Create(WebBrowser *wb, REFIID riid, ConnectionPoint **cp)
{ {
ConnectionPoint *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ConnectionPoint)); ConnectionPoint *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ConnectionPoint));
ret->lpConnectionPointVtbl = &ConnectionPointVtbl; ret->lpConnectionPointVtbl = &ConnectionPointVtbl;
ret->webbrowser = wb; ret->webbrowser = wb;
ret->sinks = NULL;
ret->sinks_size = 0;
memcpy(&ret->iid, riid, sizeof(IID)); memcpy(&ret->iid, riid, sizeof(IID));
*cp = CONPOINT(ret); *cp = ret;
}
static void ConnectionPoint_Destroy(ConnectionPoint *This)
{
int i;
for(i=0; i<This->sinks_size; i++) {
if(This->sinks[i])
IDispatch_Release(This->sinks[i]);
}
HeapFree(GetProcessHeap(), 0, This->sinks);
HeapFree(GetProcessHeap(), 0, This);
} }
void WebBrowser_Events_Init(WebBrowser *This) void WebBrowser_Events_Init(WebBrowser *This)
@ -236,7 +305,7 @@ void WebBrowser_Events_Init(WebBrowser *This)
void WebBrowser_Events_Destroy(WebBrowser *This) void WebBrowser_Events_Destroy(WebBrowser *This)
{ {
HeapFree(GetProcessHeap(), 0, This->cp_wbe2); ConnectionPoint_Destroy(This->cp_wbe2);
HeapFree(GetProcessHeap(), 0, This->cp_wbe); ConnectionPoint_Destroy(This->cp_wbe);
HeapFree(GetProcessHeap(), 0, This->cp_pns); ConnectionPoint_Destroy(This->cp_pns);
} }

View File

@ -58,6 +58,9 @@ extern HRESULT SHDOCVW_GetShellInstanceObjectClassObject(REFCLSID rclsid,
/********************************************************************** /**********************************************************************
* WebBrowser declaration for SHDOCVW.DLL * WebBrowser declaration for SHDOCVW.DLL
*/ */
typedef struct ConnectionPoint ConnectionPoint;
typedef struct { typedef struct {
/* Interfaces available via WebBrowser object */ /* Interfaces available via WebBrowser object */
@ -109,9 +112,9 @@ typedef struct {
/* Connection points */ /* Connection points */
IConnectionPoint *cp_wbe2; ConnectionPoint *cp_wbe2;
IConnectionPoint *cp_wbe; ConnectionPoint *cp_wbe;
IConnectionPoint *cp_pns; ConnectionPoint *cp_pns;
} WebBrowser; } WebBrowser;
#define WEBBROWSER(x) ((IWebBrowser*) &(x)->lpWebBrowser2Vtbl) #define WEBBROWSER(x) ((IWebBrowser*) &(x)->lpWebBrowser2Vtbl)
@ -155,6 +158,7 @@ void WebBrowser_ClientSite_Destroy(WebBrowser*);
HRESULT WebBrowser_Create(IUnknown*,REFIID,void**); HRESULT WebBrowser_Create(IUnknown*,REFIID,void**);
void create_doc_view_hwnd(WebBrowser *This); void create_doc_view_hwnd(WebBrowser *This);
void call_sink(ConnectionPoint*,DISPID,DISPPARAMS*);
#define WB_WM_NAVIGATE2 (WM_USER+100) #define WB_WM_NAVIGATE2 (WM_USER+100)