wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / ieframe / events.c
blobeef1c17e6c0b6fe9cb4b58717be55317df00b9fe
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>
27 #include "ieframe.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
33 struct ConnectionPoint {
34 IConnectionPoint IConnectionPoint_iface;
36 IConnectionPointContainer *container;
38 IDispatch **sinks;
39 DWORD sinks_size;
41 IID iid;
44 /**********************************************************************
45 * Implement the IConnectionPointContainer interface
48 static inline ConnectionPointContainer *impl_from_IConnectionPointContainer(IConnectionPointContainer *iface)
50 return CONTAINING_RECORD(iface, ConnectionPointContainer, IConnectionPointContainer_iface);
53 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
54 REFIID riid, LPVOID *ppv)
56 ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
57 return IUnknown_QueryInterface(This->impl, riid, ppv);
60 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
62 ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
63 return IUnknown_AddRef(This->impl);
66 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
68 ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
69 return IUnknown_Release(This->impl);
72 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
73 LPENUMCONNECTIONPOINTS *ppEnum)
75 ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
76 FIXME("(%p)->(%p)\n", This, ppEnum);
77 return E_NOTIMPL;
80 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
81 REFIID riid, LPCONNECTIONPOINT *ppCP)
83 ConnectionPointContainer *This = impl_from_IConnectionPointContainer(iface);
85 if(!ppCP) {
86 WARN("ppCP == NULL\n");
87 return E_POINTER;
90 *ppCP = NULL;
92 if(IsEqualGUID(&DIID_DWebBrowserEvents2, riid)) {
93 TRACE("(%p)->(DIID_DWebBrowserEvents2 %p)\n", This, ppCP);
94 *ppCP = &This->wbe2->IConnectionPoint_iface;
95 }else if(IsEqualGUID(&DIID_DWebBrowserEvents, riid)) {
96 TRACE("(%p)->(DIID_DWebBrowserEvents %p)\n", This, ppCP);
97 *ppCP = &This->wbe->IConnectionPoint_iface;
98 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
99 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP);
100 *ppCP = &This->pns->IConnectionPoint_iface;
103 if(*ppCP) {
104 IConnectionPoint_AddRef(*ppCP);
105 return S_OK;
108 WARN("Unsupported IID %s\n", debugstr_guid(riid));
109 return CONNECT_E_NOCONNECTION;
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 typedef struct {
132 IEnumConnections IEnumConnections_iface;
134 LONG ref;
136 ConnectionPoint *cp;
137 DWORD iter;
138 } EnumConnections;
140 static inline EnumConnections *impl_from_IEnumConnections(IEnumConnections *iface)
142 return CONTAINING_RECORD(iface, EnumConnections, IEnumConnections_iface);
145 static HRESULT WINAPI EnumConnections_QueryInterface(IEnumConnections *iface, REFIID riid, void **ppv)
147 EnumConnections *This = impl_from_IEnumConnections(iface);
149 if(IsEqualGUID(&IID_IUnknown, riid)) {
150 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
151 *ppv = &This->IEnumConnections_iface;
152 }else if(IsEqualGUID(&IID_IEnumConnections, riid)) {
153 TRACE("(%p)->(IID_IEnumConnections %p)\n", This, ppv);
154 *ppv = &This->IEnumConnections_iface;
155 }else {
156 WARN("Unsupported interface %s\n", debugstr_guid(riid));
157 *ppv = NULL;
158 return E_NOINTERFACE;
161 IUnknown_AddRef((IUnknown*)*ppv);
162 return S_OK;
165 static ULONG WINAPI EnumConnections_AddRef(IEnumConnections *iface)
167 EnumConnections *This = impl_from_IEnumConnections(iface);
168 LONG ref = InterlockedIncrement(&This->ref);
170 TRACE("(%p) ref=%d\n", This, ref);
172 return ref;
175 static ULONG WINAPI EnumConnections_Release(IEnumConnections *iface)
177 EnumConnections *This = impl_from_IEnumConnections(iface);
178 LONG ref = InterlockedDecrement(&This->ref);
180 TRACE("(%p) ref=%d\n", This, ref);
182 if(!ref) {
183 IConnectionPoint_Release(&This->cp->IConnectionPoint_iface);
184 heap_free(This);
187 return ref;
190 static HRESULT WINAPI EnumConnections_Next(IEnumConnections *iface, ULONG cConnections, CONNECTDATA *pgcd, ULONG *pcFetched)
192 EnumConnections *This = impl_from_IEnumConnections(iface);
193 ULONG cnt = 0;
195 TRACE("(%p)->(%u %p %p)\n", This, cConnections, pgcd, pcFetched);
197 while(cConnections--) {
198 while(This->iter < This->cp->sinks_size && !This->cp->sinks[This->iter])
199 This->iter++;
200 if(This->iter == This->cp->sinks_size)
201 break;
203 pgcd[cnt].pUnk = (IUnknown*)This->cp->sinks[This->iter];
204 pgcd[cnt].dwCookie = cnt+1;
205 This->iter++;
206 cnt++;
209 if(pcFetched)
210 *pcFetched = cnt;
211 return cnt ? S_OK : S_FALSE;
214 static HRESULT WINAPI EnumConnections_Skip(IEnumConnections *iface, ULONG cConnections)
216 EnumConnections *This = impl_from_IEnumConnections(iface);
217 FIXME("(%p)->(%u)\n", This, cConnections);
218 return E_NOTIMPL;
221 static HRESULT WINAPI EnumConnections_Reset(IEnumConnections *iface)
223 EnumConnections *This = impl_from_IEnumConnections(iface);
224 FIXME("(%p)\n", This);
225 return E_NOTIMPL;
228 static HRESULT WINAPI EnumConnections_Clone(IEnumConnections *iface, IEnumConnections **ppEnum)
230 EnumConnections *This = impl_from_IEnumConnections(iface);
231 FIXME("(%p)->(%p)\n", This, ppEnum);
232 return E_NOTIMPL;
235 static const IEnumConnectionsVtbl EnumConnectionsVtbl = {
236 EnumConnections_QueryInterface,
237 EnumConnections_AddRef,
238 EnumConnections_Release,
239 EnumConnections_Next,
240 EnumConnections_Skip,
241 EnumConnections_Reset,
242 EnumConnections_Clone
245 static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface,
246 REFIID riid, LPVOID *ppv)
248 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
250 *ppv = NULL;
252 if(IsEqualGUID(&IID_IUnknown, riid)) {
253 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
254 *ppv = &This->IConnectionPoint_iface;
255 }else if(IsEqualGUID(&IID_IConnectionPoint, riid)) {
256 TRACE("(%p)->(IID_IConnectionPoint %p)\n", This, ppv);
257 *ppv = &This->IConnectionPoint_iface;
260 if(*ppv) {
261 IConnectionPointContainer_AddRef(This->container);
262 return S_OK;
265 WARN("Unsupported interface %s\n", debugstr_guid(riid));
266 return E_NOINTERFACE;
269 static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
271 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
272 return IConnectionPointContainer_AddRef(This->container);
275 static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
277 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
278 return IConnectionPointContainer_Release(This->container);
281 static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *pIID)
283 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
285 TRACE("(%p)->(%p)\n", This, pIID);
287 *pIID = This->iid;
288 return S_OK;
291 static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
292 IConnectionPointContainer **ppCPC)
294 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
296 TRACE("(%p)->(%p)\n", This, ppCPC);
298 *ppCPC = This->container;
299 IConnectionPointContainer_AddRef(This->container);
300 return S_OK;
303 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink,
304 DWORD *pdwCookie)
306 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
307 IDispatch *disp;
308 DWORD i;
309 HRESULT hres;
311 TRACE("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
313 hres = IUnknown_QueryInterface(pUnkSink, &This->iid, (void**)&disp);
314 if(FAILED(hres)) {
315 hres = IUnknown_QueryInterface(pUnkSink, &IID_IDispatch, (void**)&disp);
316 if(FAILED(hres))
317 return CONNECT_E_CANNOTCONNECT;
320 if(This->sinks) {
321 for(i=0; i<This->sinks_size; i++) {
322 if(!This->sinks[i])
323 break;
326 if(i == This->sinks_size)
327 This->sinks = heap_realloc(This->sinks,
328 (++This->sinks_size)*sizeof(*This->sinks));
329 }else {
330 This->sinks = heap_alloc(sizeof(*This->sinks));
331 This->sinks_size = 1;
332 i = 0;
335 This->sinks[i] = disp;
336 *pdwCookie = i+1;
338 return S_OK;
341 static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
343 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
345 TRACE("(%p)->(%d)\n", This, dwCookie);
347 if(!dwCookie || dwCookie > This->sinks_size || !This->sinks[dwCookie-1])
348 return CONNECT_E_NOCONNECTION;
350 IDispatch_Release(This->sinks[dwCookie-1]);
351 This->sinks[dwCookie-1] = NULL;
353 return S_OK;
356 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
357 IEnumConnections **ppEnum)
359 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
360 EnumConnections *ret;
362 TRACE("(%p)->(%p)\n", This, ppEnum);
364 ret = heap_alloc(sizeof(*ret));
365 if(!ret)
366 return E_OUTOFMEMORY;
368 ret->IEnumConnections_iface.lpVtbl = &EnumConnectionsVtbl;
369 ret->ref = 1;
370 ret->iter = 0;
372 IConnectionPoint_AddRef(&This->IConnectionPoint_iface);
373 ret->cp = This;
375 *ppEnum = &ret->IEnumConnections_iface;
376 return S_OK;
379 static const IConnectionPointVtbl ConnectionPointVtbl =
381 ConnectionPoint_QueryInterface,
382 ConnectionPoint_AddRef,
383 ConnectionPoint_Release,
384 ConnectionPoint_GetConnectionInterface,
385 ConnectionPoint_GetConnectionPointContainer,
386 ConnectionPoint_Advise,
387 ConnectionPoint_Unadvise,
388 ConnectionPoint_EnumConnections
391 void call_sink(ConnectionPoint *This, DISPID dispid, DISPPARAMS *dispparams)
393 DWORD i;
395 for(i=0; i<This->sinks_size; i++) {
396 if(This->sinks[i])
397 IDispatch_Invoke(This->sinks[i], dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
398 DISPATCH_METHOD, dispparams, NULL, NULL, NULL);
402 static void ConnectionPoint_Create(REFIID riid, ConnectionPoint **cp,
403 IConnectionPointContainer *container)
405 ConnectionPoint *ret = heap_alloc(sizeof(ConnectionPoint));
407 ret->IConnectionPoint_iface.lpVtbl = &ConnectionPointVtbl;
409 ret->sinks = NULL;
410 ret->sinks_size = 0;
411 ret->container = container;
413 ret->iid = *riid;
415 *cp = ret;
418 static void ConnectionPoint_Destroy(ConnectionPoint *This)
420 DWORD i;
422 for(i=0; i<This->sinks_size; i++) {
423 if(This->sinks[i])
424 IDispatch_Release(This->sinks[i]);
427 heap_free(This->sinks);
428 heap_free(This);
431 void ConnectionPointContainer_Init(ConnectionPointContainer *This, IUnknown *impl)
433 This->IConnectionPointContainer_iface.lpVtbl = &ConnectionPointContainerVtbl;
435 ConnectionPoint_Create(&DIID_DWebBrowserEvents2, &This->wbe2, &This->IConnectionPointContainer_iface);
436 ConnectionPoint_Create(&DIID_DWebBrowserEvents, &This->wbe, &This->IConnectionPointContainer_iface);
437 ConnectionPoint_Create(&IID_IPropertyNotifySink, &This->pns, &This->IConnectionPointContainer_iface);
439 This->impl = impl;
442 void ConnectionPointContainer_Destroy(ConnectionPointContainer *This)
444 ConnectionPoint_Destroy(This->wbe2);
445 ConnectionPoint_Destroy(This->wbe);
446 ConnectionPoint_Destroy(This->pns);