2 * Implementation of event-related interfaces for WebBrowser control:
4 * - IConnectionPointContainer
7 * Copyright 2001 John R. Sheets (for CodeWeavers)
8 * Copyright 2006 Jacek Caban for CodeWeavers
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
31 struct ConnectionPoint {
32 const IConnectionPointVtbl *lpConnectionPointVtbl;
34 IConnectionPointContainer *container;
42 #define CONPOINT(x) ((IConnectionPoint*) &(x)->lpConnectionPointVtbl)
44 /**********************************************************************
45 * Implement the IConnectionPointContainer interface
48 #define CONPTCONT_THIS(iface) DEFINE_THIS(ConnectionPointContainer, ConnectionPointContainer, iface)
50 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
51 REFIID riid, LPVOID *ppv)
53 ConnectionPointContainer *This = CONPTCONT_THIS(iface);
54 return IUnknown_QueryInterface(This->impl, riid, ppv);
57 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
59 ConnectionPointContainer *This = CONPTCONT_THIS(iface);
60 return IUnknown_AddRef(This->impl);
63 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
65 ConnectionPointContainer *This = CONPTCONT_THIS(iface);
66 return IUnknown_Release(This->impl);
69 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
70 LPENUMCONNECTIONPOINTS *ppEnum)
72 ConnectionPointContainer *This = CONPTCONT_THIS(iface);
73 FIXME("(%p)->(%p)\n", This, ppEnum);
77 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
78 REFIID riid, LPCONNECTIONPOINT *ppCP)
80 ConnectionPointContainer *This = CONPTCONT_THIS(iface);
83 WARN("ppCP == NULL\n");
89 if(IsEqualGUID(&DIID_DWebBrowserEvents2, riid)) {
90 TRACE("(%p)->(DIID_DWebBrowserEvents2 %p)\n", This, ppCP);
91 *ppCP = CONPOINT(This->wbe2);
92 }else if(IsEqualGUID(&DIID_DWebBrowserEvents, riid)) {
93 TRACE("(%p)->(DIID_DWebBrowserEvents %p)\n", This, ppCP);
94 *ppCP = CONPOINT(This->wbe);
95 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
96 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP);
97 *ppCP = CONPOINT(This->pns);
101 IConnectionPoint_AddRef(*ppCP);
105 WARN("Unsupported IID %s\n", debugstr_guid(riid));
106 return CONNECT_E_NOCONNECTION;
109 #undef CONPTCONT_THIS
111 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl =
113 ConnectionPointContainer_QueryInterface,
114 ConnectionPointContainer_AddRef,
115 ConnectionPointContainer_Release,
116 ConnectionPointContainer_EnumConnectionPoints,
117 ConnectionPointContainer_FindConnectionPoint
121 /**********************************************************************
122 * Implement the IConnectionPoint interface
125 #define CONPOINT_THIS(iface) DEFINE_THIS(ConnectionPoint, ConnectionPoint, iface)
127 static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface,
128 REFIID riid, LPVOID *ppv)
130 ConnectionPoint *This = CONPOINT_THIS(iface);
134 if(IsEqualGUID(&IID_IUnknown, riid)) {
135 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
136 *ppv = CONPOINT(This);
137 }else if(IsEqualGUID(&IID_IConnectionPoint, riid)) {
138 TRACE("(%p)->(IID_IConnectionPoint %p)\n", This, ppv);
139 *ppv = CONPOINT(This);
143 IConnectionPointContainer_AddRef(This->container);
147 WARN("Unsupported interface %s\n", debugstr_guid(riid));
148 return E_NOINTERFACE;
151 static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
153 ConnectionPoint *This = CONPOINT_THIS(iface);
154 return IConnectionPointContainer_AddRef(This->container);
157 static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
159 ConnectionPoint *This = CONPOINT_THIS(iface);
160 return IConnectionPointContainer_Release(This->container);
163 static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *pIID)
165 ConnectionPoint *This = CONPOINT_THIS(iface);
167 TRACE("(%p)->(%p)\n", This, pIID);
169 memcpy(pIID, &This->iid, sizeof(IID));
173 static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
174 IConnectionPointContainer **ppCPC)
176 ConnectionPoint *This = CONPOINT_THIS(iface);
178 TRACE("(%p)->(%p)\n", This, ppCPC);
180 *ppCPC = This->container;
181 IConnectionPointContainer_AddRef(This->container);
185 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink,
188 ConnectionPoint *This = CONPOINT_THIS(iface);
193 TRACE("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
195 hres = IUnknown_QueryInterface(pUnkSink, &This->iid, (void**)&disp);
197 hres = IUnknown_QueryInterface(pUnkSink, &IID_IDispatch, (void**)&disp);
199 return CONNECT_E_CANNOTCONNECT;
203 for(i=0; i<This->sinks_size; i++) {
208 if(i == This->sinks_size)
209 This->sinks = shdocvw_realloc(This->sinks,
210 (++This->sinks_size)*sizeof(*This->sinks));
212 This->sinks = shdocvw_alloc(sizeof(*This->sinks));
213 This->sinks_size = 1;
217 This->sinks[i] = disp;
223 static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
225 ConnectionPoint *This = CONPOINT_THIS(iface);
227 TRACE("(%p)->(%d)\n", This, dwCookie);
229 if(!dwCookie || dwCookie > This->sinks_size || !This->sinks[dwCookie-1])
230 return CONNECT_E_NOCONNECTION;
232 IDispatch_Release(This->sinks[dwCookie-1]);
233 This->sinks[dwCookie-1] = NULL;
238 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
239 IEnumConnections **ppEnum)
241 ConnectionPoint *This = CONPOINT_THIS(iface);
242 FIXME("(%p)->(%p)\n", This, ppEnum);
248 static const IConnectionPointVtbl ConnectionPointVtbl =
250 ConnectionPoint_QueryInterface,
251 ConnectionPoint_AddRef,
252 ConnectionPoint_Release,
253 ConnectionPoint_GetConnectionInterface,
254 ConnectionPoint_GetConnectionPointContainer,
255 ConnectionPoint_Advise,
256 ConnectionPoint_Unadvise,
257 ConnectionPoint_EnumConnections
260 void call_sink(ConnectionPoint *This, DISPID dispid, DISPPARAMS *dispparams)
264 for(i=0; i<This->sinks_size; i++) {
266 IDispatch_Invoke(This->sinks[i], dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
267 DISPATCH_METHOD, dispparams, NULL, NULL, NULL);
271 static void ConnectionPoint_Create(REFIID riid, ConnectionPoint **cp,
272 IConnectionPointContainer *container)
274 ConnectionPoint *ret = shdocvw_alloc(sizeof(ConnectionPoint));
276 ret->lpConnectionPointVtbl = &ConnectionPointVtbl;
280 ret->container = container;
282 memcpy(&ret->iid, riid, sizeof(IID));
287 static void ConnectionPoint_Destroy(ConnectionPoint *This)
291 for(i=0; i<This->sinks_size; i++) {
293 IDispatch_Release(This->sinks[i]);
296 shdocvw_free(This->sinks);
300 void ConnectionPointContainer_Init(ConnectionPointContainer *This, IUnknown *impl)
302 This->lpConnectionPointContainerVtbl = &ConnectionPointContainerVtbl;
304 ConnectionPoint_Create(&DIID_DWebBrowserEvents2, &This->wbe2, CONPTCONT(This));
305 ConnectionPoint_Create(&DIID_DWebBrowserEvents, &This->wbe, CONPTCONT(This));
306 ConnectionPoint_Create(&IID_IPropertyNotifySink, &This->pns, CONPTCONT(This));
311 void ConnectionPointContainer_Destroy(ConnectionPointContainer *This)
313 ConnectionPoint_Destroy(This->wbe2);
314 ConnectionPoint_Destroy(This->wbe);
315 ConnectionPoint_Destroy(This->pns);