* Implement <autoregister>
[reactos.git] / reactos / lib / shdocvw / events.c
1 /*
2 * Implementation of event-related interfaces for WebBrowser control:
3 *
4 * - IConnectionPointContainer
5 * - IConnectionPoint
6 *
7 * Copyright 2001 John R. Sheets (for CodeWeavers)
8 *
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.
13 *
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.
18 *
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
22 */
23
24 #include <string.h>
25 #include "wine/debug.h"
26 #include "shdocvw.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
29
30 typedef struct {
31 const IConnectionPointVtbl *lpConnectionPointVtbl;
32
33 WebBrowser *webbrowser;
34
35 IID iid;
36 } ConnectionPoint;
37
38 #define CONPOINT(x) ((IConnectionPoint*) &(x)->lpConnectionPointVtbl)
39
40 /**********************************************************************
41 * Implement the IConnectionPointContainer interface
42 */
43
44 #define CONPTCONT_THIS(iface) DEFINE_THIS(WebBrowser, ConnectionPointContainer, iface)
45
46 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
47 REFIID riid, LPVOID *ppobj)
48 {
49 WebBrowser *This = CONPTCONT_THIS(iface);
50 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
51 }
52
53 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
54 {
55 WebBrowser *This = CONPTCONT_THIS(iface);
56 return IWebBrowser_AddRef(WEBBROWSER(This));
57 }
58
59 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
60 {
61 WebBrowser *This = CONPTCONT_THIS(iface);
62 return IWebBrowser_Release(WEBBROWSER(This));
63 }
64
65 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
66 LPENUMCONNECTIONPOINTS *ppEnum)
67 {
68 WebBrowser *This = CONPTCONT_THIS(iface);
69 FIXME("(%p)->(%p)\n", This, ppEnum);
70 return E_NOTIMPL;
71 }
72
73 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
74 REFIID riid, LPCONNECTIONPOINT *ppCP)
75 {
76 WebBrowser *This = CONPTCONT_THIS(iface);
77
78 if(!ppCP) {
79 WARN("ppCP == NULL\n");
80 return E_POINTER;
81 }
82
83 *ppCP = NULL;
84
85 if(IsEqualGUID(&DIID_DWebBrowserEvents2, riid)) {
86 TRACE("(%p)->(DIID_DWebBrowserEvents2 %p)\n", This, ppCP);
87 *ppCP = This->cp_wbe2;
88 }else if(IsEqualGUID(&DIID_DWebBrowserEvents, riid)) {
89 TRACE("(%p)->(DIID_DWebBrowserEvents %p)\n", This, ppCP);
90 *ppCP = This->cp_wbe;
91 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
92 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP);
93 *ppCP = This->cp_pns;
94 }
95
96 if(*ppCP) {
97 IConnectionPoint_AddRef(*ppCP);
98 return S_OK;
99 }
100
101 WARN("Unsupported IID %s\n", debugstr_guid(riid));
102 return E_NOINTERFACE;
103 }
104
105 #undef CONPTCONT_THIS
106
107 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl =
108 {
109 ConnectionPointContainer_QueryInterface,
110 ConnectionPointContainer_AddRef,
111 ConnectionPointContainer_Release,
112 ConnectionPointContainer_EnumConnectionPoints,
113 ConnectionPointContainer_FindConnectionPoint
114 };
115
116
117 /**********************************************************************
118 * Implement the IConnectionPoint interface
119 */
120
121 #define CONPOINT_THIS(iface) DEFINE_THIS(ConnectionPoint, ConnectionPoint, iface)
122
123 static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface,
124 REFIID riid, LPVOID *ppv)
125 {
126 ConnectionPoint *This = CONPOINT_THIS(iface);
127
128 *ppv = NULL;
129
130 if(IsEqualGUID(&IID_IUnknown, riid)) {
131 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
132 *ppv = CONPOINT(This);
133 }else if(IsEqualGUID(&IID_IConnectionPoint, riid)) {
134 TRACE("(%p)->(IID_IConnectionPoint %p)\n", This, ppv);
135 *ppv = CONPOINT(This);
136 }
137
138 if(*ppv) {
139 IWebBrowser2_AddRef(WEBBROWSER(This->webbrowser));
140 return S_OK;
141 }
142
143 WARN("Unsupported interface %s\n", debugstr_guid(riid));
144 return E_NOINTERFACE;
145 }
146
147 static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
148 {
149 ConnectionPoint *This = CONPOINT_THIS(iface);
150 return IWebBrowser2_AddRef(WEBBROWSER(This->webbrowser));
151 }
152
153 static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
154 {
155 ConnectionPoint *This = CONPOINT_THIS(iface);
156 return IWebBrowser2_Release(WEBBROWSER(This->webbrowser));
157 }
158
159 static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *pIID)
160 {
161 ConnectionPoint *This = CONPOINT_THIS(iface);
162
163 TRACE("(%p)->(%p)\n", This, pIID);
164
165 memcpy(pIID, &This->iid, sizeof(IID));
166 return S_OK;
167 }
168
169 static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
170 IConnectionPointContainer **ppCPC)
171 {
172 ConnectionPoint *This = CONPOINT_THIS(iface);
173
174 TRACE("(%p)->(%p)\n", This, ppCPC);
175
176 *ppCPC = CONPTCONT(This->webbrowser);
177 return S_OK;
178 }
179
180 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink,
181 DWORD *pdwCookie)
182 {
183 ConnectionPoint *This = CONPOINT_THIS(iface);
184 FIXME("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
185 return E_NOTIMPL;
186 }
187
188 static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
189 {
190 ConnectionPoint *This = CONPOINT_THIS(iface);
191 FIXME("(%p)->(%ld)\n", This, dwCookie);
192 return E_NOTIMPL;
193 }
194
195 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
196 IEnumConnections **ppEnum)
197 {
198 ConnectionPoint *This = CONPOINT_THIS(iface);
199 FIXME("(%p)->(%p)\n", This, ppEnum);
200 return E_NOTIMPL;
201 }
202
203 #undef CONPOINT_THIS
204
205 static const IConnectionPointVtbl ConnectionPointVtbl =
206 {
207 ConnectionPoint_QueryInterface,
208 ConnectionPoint_AddRef,
209 ConnectionPoint_Release,
210 ConnectionPoint_GetConnectionInterface,
211 ConnectionPoint_GetConnectionPointContainer,
212 ConnectionPoint_Advise,
213 ConnectionPoint_Unadvise,
214 ConnectionPoint_EnumConnections
215 };
216
217 static void ConnectionPoint_Create(WebBrowser *wb, REFIID riid, IConnectionPoint **cp)
218 {
219 ConnectionPoint *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ConnectionPoint));
220
221 ret->lpConnectionPointVtbl = &ConnectionPointVtbl;
222 ret->webbrowser = wb;
223 memcpy(&ret->iid, riid, sizeof(IID));
224
225 *cp = CONPOINT(ret);
226 }
227
228 void WebBrowser_Events_Init(WebBrowser *This)
229 {
230 This->lpConnectionPointContainerVtbl = &ConnectionPointContainerVtbl;
231
232 ConnectionPoint_Create(This, &DIID_DWebBrowserEvents2, &This->cp_wbe2);
233 ConnectionPoint_Create(This, &DIID_DWebBrowserEvents, &This->cp_wbe);
234 ConnectionPoint_Create(This, &IID_IPropertyNotifySink, &This->cp_pns);
235 }
236
237 void WebBrowser_Events_Destroy(WebBrowser *This)
238 {
239 HeapFree(GetProcessHeap(), 0, This->cp_wbe2);
240 HeapFree(GetProcessHeap(), 0, This->cp_wbe);
241 HeapFree(GetProcessHeap(), 0, This->cp_pns);
242 }