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 IConnectionPoint IConnectionPoint_iface
;
34 IConnectionPointContainer
*container
;
42 /**********************************************************************
43 * Implement the IConnectionPointContainer interface
46 static inline ConnectionPointContainer
*impl_from_IConnectionPointContainer(IConnectionPointContainer
*iface
)
48 return CONTAINING_RECORD(iface
, ConnectionPointContainer
, IConnectionPointContainer_iface
);
51 static HRESULT WINAPI
ConnectionPointContainer_QueryInterface(IConnectionPointContainer
*iface
,
52 REFIID riid
, LPVOID
*ppv
)
54 ConnectionPointContainer
*This
= impl_from_IConnectionPointContainer(iface
);
55 return IUnknown_QueryInterface(This
->impl
, riid
, ppv
);
58 static ULONG WINAPI
ConnectionPointContainer_AddRef(IConnectionPointContainer
*iface
)
60 ConnectionPointContainer
*This
= impl_from_IConnectionPointContainer(iface
);
61 return IUnknown_AddRef(This
->impl
);
64 static ULONG WINAPI
ConnectionPointContainer_Release(IConnectionPointContainer
*iface
)
66 ConnectionPointContainer
*This
= impl_from_IConnectionPointContainer(iface
);
67 return IUnknown_Release(This
->impl
);
70 static HRESULT WINAPI
ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer
*iface
,
71 LPENUMCONNECTIONPOINTS
*ppEnum
)
73 ConnectionPointContainer
*This
= impl_from_IConnectionPointContainer(iface
);
74 FIXME("(%p)->(%p)\n", This
, ppEnum
);
78 static HRESULT WINAPI
ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer
*iface
,
79 REFIID riid
, LPCONNECTIONPOINT
*ppCP
)
81 ConnectionPointContainer
*This
= impl_from_IConnectionPointContainer(iface
);
84 WARN("ppCP == NULL\n");
90 if(IsEqualGUID(&DIID_DWebBrowserEvents2
, riid
)) {
91 TRACE("(%p)->(DIID_DWebBrowserEvents2 %p)\n", This
, ppCP
);
92 *ppCP
= &This
->wbe2
->IConnectionPoint_iface
;
93 }else if(IsEqualGUID(&DIID_DWebBrowserEvents
, riid
)) {
94 TRACE("(%p)->(DIID_DWebBrowserEvents %p)\n", This
, ppCP
);
95 *ppCP
= &This
->wbe
->IConnectionPoint_iface
;
96 }else if(IsEqualGUID(&IID_IPropertyNotifySink
, riid
)) {
97 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This
, ppCP
);
98 *ppCP
= &This
->pns
->IConnectionPoint_iface
;
102 IConnectionPoint_AddRef(*ppCP
);
106 WARN("Unsupported IID %s\n", debugstr_guid(riid
));
107 return CONNECT_E_NOCONNECTION
;
110 #undef impl_from_IConnectionPointContainer
112 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl
=
114 ConnectionPointContainer_QueryInterface
,
115 ConnectionPointContainer_AddRef
,
116 ConnectionPointContainer_Release
,
117 ConnectionPointContainer_EnumConnectionPoints
,
118 ConnectionPointContainer_FindConnectionPoint
122 /**********************************************************************
123 * Implement the IConnectionPoint interface
126 static inline ConnectionPoint
*impl_from_IConnectionPoint(IConnectionPoint
*iface
)
128 return CONTAINING_RECORD(iface
, ConnectionPoint
, IConnectionPoint_iface
);
131 static HRESULT WINAPI
ConnectionPoint_QueryInterface(IConnectionPoint
*iface
,
132 REFIID riid
, LPVOID
*ppv
)
134 ConnectionPoint
*This
= impl_from_IConnectionPoint(iface
);
138 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
139 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
140 *ppv
= &This
->IConnectionPoint_iface
;
141 }else if(IsEqualGUID(&IID_IConnectionPoint
, riid
)) {
142 TRACE("(%p)->(IID_IConnectionPoint %p)\n", This
, ppv
);
143 *ppv
= &This
->IConnectionPoint_iface
;
147 IConnectionPointContainer_AddRef(This
->container
);
151 WARN("Unsupported interface %s\n", debugstr_guid(riid
));
152 return E_NOINTERFACE
;
155 static ULONG WINAPI
ConnectionPoint_AddRef(IConnectionPoint
*iface
)
157 ConnectionPoint
*This
= impl_from_IConnectionPoint(iface
);
158 return IConnectionPointContainer_AddRef(This
->container
);
161 static ULONG WINAPI
ConnectionPoint_Release(IConnectionPoint
*iface
)
163 ConnectionPoint
*This
= impl_from_IConnectionPoint(iface
);
164 return IConnectionPointContainer_Release(This
->container
);
167 static HRESULT WINAPI
ConnectionPoint_GetConnectionInterface(IConnectionPoint
*iface
, IID
*pIID
)
169 ConnectionPoint
*This
= impl_from_IConnectionPoint(iface
);
171 TRACE("(%p)->(%p)\n", This
, pIID
);
177 static HRESULT WINAPI
ConnectionPoint_GetConnectionPointContainer(IConnectionPoint
*iface
,
178 IConnectionPointContainer
**ppCPC
)
180 ConnectionPoint
*This
= impl_from_IConnectionPoint(iface
);
182 TRACE("(%p)->(%p)\n", This
, ppCPC
);
184 *ppCPC
= This
->container
;
185 IConnectionPointContainer_AddRef(This
->container
);
189 static HRESULT WINAPI
ConnectionPoint_Advise(IConnectionPoint
*iface
, IUnknown
*pUnkSink
,
192 ConnectionPoint
*This
= impl_from_IConnectionPoint(iface
);
197 TRACE("(%p)->(%p %p)\n", This
, pUnkSink
, pdwCookie
);
199 hres
= IUnknown_QueryInterface(pUnkSink
, &This
->iid
, (void**)&disp
);
201 hres
= IUnknown_QueryInterface(pUnkSink
, &IID_IDispatch
, (void**)&disp
);
203 return CONNECT_E_CANNOTCONNECT
;
207 for(i
=0; i
<This
->sinks_size
; i
++) {
212 if(i
== This
->sinks_size
)
213 This
->sinks
= heap_realloc(This
->sinks
,
214 (++This
->sinks_size
)*sizeof(*This
->sinks
));
216 This
->sinks
= heap_alloc(sizeof(*This
->sinks
));
217 This
->sinks_size
= 1;
221 This
->sinks
[i
] = disp
;
227 static HRESULT WINAPI
ConnectionPoint_Unadvise(IConnectionPoint
*iface
, DWORD dwCookie
)
229 ConnectionPoint
*This
= impl_from_IConnectionPoint(iface
);
231 TRACE("(%p)->(%d)\n", This
, dwCookie
);
233 if(!dwCookie
|| dwCookie
> This
->sinks_size
|| !This
->sinks
[dwCookie
-1])
234 return CONNECT_E_NOCONNECTION
;
236 IDispatch_Release(This
->sinks
[dwCookie
-1]);
237 This
->sinks
[dwCookie
-1] = NULL
;
242 static HRESULT WINAPI
ConnectionPoint_EnumConnections(IConnectionPoint
*iface
,
243 IEnumConnections
**ppEnum
)
245 ConnectionPoint
*This
= impl_from_IConnectionPoint(iface
);
246 FIXME("(%p)->(%p)\n", This
, ppEnum
);
250 static const IConnectionPointVtbl ConnectionPointVtbl
=
252 ConnectionPoint_QueryInterface
,
253 ConnectionPoint_AddRef
,
254 ConnectionPoint_Release
,
255 ConnectionPoint_GetConnectionInterface
,
256 ConnectionPoint_GetConnectionPointContainer
,
257 ConnectionPoint_Advise
,
258 ConnectionPoint_Unadvise
,
259 ConnectionPoint_EnumConnections
262 void call_sink(ConnectionPoint
*This
, DISPID dispid
, DISPPARAMS
*dispparams
)
266 for(i
=0; i
<This
->sinks_size
; i
++) {
268 IDispatch_Invoke(This
->sinks
[i
], dispid
, &IID_NULL
, LOCALE_SYSTEM_DEFAULT
,
269 DISPATCH_METHOD
, dispparams
, NULL
, NULL
, NULL
);
273 static void ConnectionPoint_Create(REFIID riid
, ConnectionPoint
**cp
,
274 IConnectionPointContainer
*container
)
276 ConnectionPoint
*ret
= heap_alloc(sizeof(ConnectionPoint
));
278 ret
->IConnectionPoint_iface
.lpVtbl
= &ConnectionPointVtbl
;
282 ret
->container
= container
;
289 static void ConnectionPoint_Destroy(ConnectionPoint
*This
)
293 for(i
=0; i
<This
->sinks_size
; i
++) {
295 IDispatch_Release(This
->sinks
[i
]);
298 heap_free(This
->sinks
);
302 void ConnectionPointContainer_Init(ConnectionPointContainer
*This
, IUnknown
*impl
)
304 This
->IConnectionPointContainer_iface
.lpVtbl
= &ConnectionPointContainerVtbl
;
306 ConnectionPoint_Create(&DIID_DWebBrowserEvents2
, &This
->wbe2
, &This
->IConnectionPointContainer_iface
);
307 ConnectionPoint_Create(&DIID_DWebBrowserEvents
, &This
->wbe
, &This
->IConnectionPointContainer_iface
);
308 ConnectionPoint_Create(&IID_IPropertyNotifySink
, &This
->pns
, &This
->IConnectionPointContainer_iface
);
313 void ConnectionPointContainer_Destroy(ConnectionPointContainer
*This
)
315 ConnectionPoint_Destroy(This
->wbe2
);
316 ConnectionPoint_Destroy(This
->wbe
);
317 ConnectionPoint_Destroy(This
->pns
);