Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / shdocvw / events.c
blob85903595295c58feb22ba5c4e26a7da455750f59
1 /*
2 * Implementation of event-related interfaces for WebBrowser control:
4 * - IConnectionPointContainer
5 * - IConnectionPoint
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
25 #include <string.h>
26 #include "wine/debug.h"
27 #include "shdocvw.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
31 struct ConnectionPoint {
32 const IConnectionPointVtbl *lpConnectionPointVtbl;
34 IConnectionPointContainer *container;
36 IDispatch **sinks;
37 DWORD sinks_size;
39 IID iid;
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);
74 return E_NOTIMPL;
77 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
78 REFIID riid, LPCONNECTIONPOINT *ppCP)
80 ConnectionPointContainer *This = CONPTCONT_THIS(iface);
82 if(!ppCP) {
83 WARN("ppCP == NULL\n");
84 return E_POINTER;
87 *ppCP = NULL;
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);
100 if(*ppCP) {
101 IConnectionPoint_AddRef(*ppCP);
102 return S_OK;
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);
132 *ppv = NULL;
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);
142 if(*ppv) {
143 IConnectionPointContainer_AddRef(This->container);
144 return S_OK;
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 *pIID = This->iid;
170 return S_OK;
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);
182 return S_OK;
185 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink,
186 DWORD *pdwCookie)
188 ConnectionPoint *This = CONPOINT_THIS(iface);
189 IDispatch *disp;
190 DWORD i;
191 HRESULT hres;
193 TRACE("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
195 hres = IUnknown_QueryInterface(pUnkSink, &This->iid, (void**)&disp);
196 if(FAILED(hres)) {
197 hres = IUnknown_QueryInterface(pUnkSink, &IID_IDispatch, (void**)&disp);
198 if(FAILED(hres))
199 return CONNECT_E_CANNOTCONNECT;
202 if(This->sinks) {
203 for(i=0; i<This->sinks_size; i++) {
204 if(!This->sinks[i])
205 break;
208 if(i == This->sinks_size)
209 This->sinks = heap_realloc(This->sinks,
210 (++This->sinks_size)*sizeof(*This->sinks));
211 }else {
212 This->sinks = heap_alloc(sizeof(*This->sinks));
213 This->sinks_size = 1;
214 i = 0;
217 This->sinks[i] = disp;
218 *pdwCookie = i+1;
220 return S_OK;
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;
235 return S_OK;
238 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
239 IEnumConnections **ppEnum)
241 ConnectionPoint *This = CONPOINT_THIS(iface);
242 FIXME("(%p)->(%p)\n", This, ppEnum);
243 return E_NOTIMPL;
246 #undef CONPOINT_THIS
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)
262 DWORD i;
264 for(i=0; i<This->sinks_size; i++) {
265 if(This->sinks[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 = heap_alloc(sizeof(ConnectionPoint));
276 ret->lpConnectionPointVtbl = &ConnectionPointVtbl;
278 ret->sinks = NULL;
279 ret->sinks_size = 0;
280 ret->container = container;
282 ret->iid = *riid;
284 *cp = ret;
287 static void ConnectionPoint_Destroy(ConnectionPoint *This)
289 DWORD i;
291 for(i=0; i<This->sinks_size; i++) {
292 if(This->sinks[i])
293 IDispatch_Release(This->sinks[i]);
296 heap_free(This->sinks);
297 heap_free(This);
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));
308 This->impl = impl;
311 void ConnectionPointContainer_Destroy(ConnectionPointContainer *This)
313 ConnectionPoint_Destroy(This->wbe2);
314 ConnectionPoint_Destroy(This->wbe);
315 ConnectionPoint_Destroy(This->pns);