progman: Add close button and sysmenu to dialogs.
[wine/gsoc_dplay.git] / dlls / shdocvw / events.c
blobe6541f9685ace4b7db1940b86f511587efd8e202
1 /*
2 * Implementation of event-related interfaces for WebBrowser control:
4 * - IConnectionPointContainer
5 * - IConnectionPoint
7 * Copyright 2001 John R. Sheets (for CodeWeavers)
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <string.h>
25 #include "wine/debug.h"
26 #include "shdocvw.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
30 struct ConnectionPoint {
31 const IConnectionPointVtbl *lpConnectionPointVtbl;
33 DocHost *doc_host;
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(WebBrowser, ConnectionPointContainer, iface)
50 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
51 REFIID riid, LPVOID *ppobj)
53 WebBrowser *This = CONPTCONT_THIS(iface);
54 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
57 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
59 WebBrowser *This = CONPTCONT_THIS(iface);
60 return IWebBrowser_AddRef(WEBBROWSER(This));
63 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
65 WebBrowser *This = CONPTCONT_THIS(iface);
66 return IWebBrowser_Release(WEBBROWSER(This));
69 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
70 LPENUMCONNECTIONPOINTS *ppEnum)
72 WebBrowser *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 WebBrowser *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->doc_host.cp_wbe2);
92 }else if(IsEqualGUID(&DIID_DWebBrowserEvents, riid)) {
93 TRACE("(%p)->(DIID_DWebBrowserEvents %p)\n", This, ppCP);
94 *ppCP = CONPOINT(This->doc_host.cp_wbe);
95 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
96 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP);
97 *ppCP = CONPOINT(This->doc_host.cp_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 IOleClientSite_AddRef(CLIENTSITE(This->doc_host));
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 IOleClientSite_AddRef(CLIENTSITE(This->doc_host));
157 static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
159 ConnectionPoint *This = CONPOINT_THIS(iface);
160 return IOleClientSite_Release(CLIENTSITE(This->doc_host));
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));
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 = HeapReAlloc(GetProcessHeap(), 0, This->sinks,
210 (++This->sinks_size)*sizeof(*This->sinks));
211 }else {
212 This->sinks = HeapAlloc(GetProcessHeap(), 0, 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)->(%ld)\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(DocHost *doc_host, REFIID riid, ConnectionPoint **cp)
273 ConnectionPoint *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ConnectionPoint));
275 ret->lpConnectionPointVtbl = &ConnectionPointVtbl;
277 ret->doc_host = doc_host;
278 ret->sinks = NULL;
279 ret->sinks_size = 0;
280 ret->container = NULL;
282 memcpy(&ret->iid, riid, sizeof(IID));
284 *cp = ret;
287 static void ConnectionPoint_Destroy(ConnectionPoint *This)
289 int i;
291 for(i=0; i<This->sinks_size; i++) {
292 if(This->sinks[i])
293 IDispatch_Release(This->sinks[i]);
296 HeapFree(GetProcessHeap(), 0, This->sinks);
297 HeapFree(GetProcessHeap(), 0, This);
300 void DocHost_Events_Init(DocHost *This)
302 ConnectionPoint_Create(This, &DIID_DWebBrowserEvents2, &This->cp_wbe2);
303 ConnectionPoint_Create(This, &DIID_DWebBrowserEvents, &This->cp_wbe);
304 ConnectionPoint_Create(This, &IID_IPropertyNotifySink, &This->cp_pns);
307 void DocHost_Events_Release(DocHost *This)
309 ConnectionPoint_Destroy(This->cp_wbe2);
310 ConnectionPoint_Destroy(This->cp_wbe);
311 ConnectionPoint_Destroy(This->cp_pns);
314 void WebBrowser_Events_Init(WebBrowser *This)
316 This->lpConnectionPointContainerVtbl = &ConnectionPointContainerVtbl;
318 This->doc_host.cp_wbe2->container = CONPTCONT(This);
319 This->doc_host.cp_wbe->container = CONPTCONT(This);
320 This->doc_host.cp_pns->container = CONPTCONT(This);