2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37 #define CONPOINT(x) ((IConnectionPoint*) &(x)->lpConnectionPointVtbl);
39 struct ConnectionPoint {
40 const IConnectionPointVtbl *lpConnectionPointVtbl;
47 IPropertyNotifySink *propnotif;
54 #define CONPOINT_THIS(iface) DEFINE_THIS(ConnectionPoint, ConnectionPoint, iface)
56 static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface,
57 REFIID riid, LPVOID *ppv)
59 ConnectionPoint *This = CONPOINT_THIS(iface);
63 if(IsEqualGUID(&IID_IUnknown, riid)) {
64 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
65 *ppv = CONPOINT(This);
66 }else if(IsEqualGUID(&IID_IConnectionPoint, riid)) {
67 TRACE("(%p)->(IID_IConnectionPoint %p)\n", This, ppv);
68 *ppv = CONPOINT(This);
72 IUnknown_AddRef((IUnknown*)*ppv);
76 WARN("Unsupported interface %s\n", debugstr_guid(riid));
80 static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
82 ConnectionPoint *This = CONPOINT_THIS(iface);
83 return IHTMLDocument2_AddRef(HTMLDOC(This->doc));
86 static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
88 ConnectionPoint *This = CONPOINT_THIS(iface);
89 return IHTMLDocument2_Release(HTMLDOC(This->doc));
92 static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *pIID)
94 ConnectionPoint *This = CONPOINT_THIS(iface);
96 TRACE("(%p)->(%p)\n", This, pIID);
101 memcpy(pIID, &This->iid, sizeof(IID));
105 static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
106 IConnectionPointContainer **ppCPC)
108 ConnectionPoint *This = CONPOINT_THIS(iface);
110 TRACE("(%p)->(%p)\n", This, ppCPC);
115 *ppCPC = CONPTCONT(This->doc);
116 IConnectionPointContainer_AddRef(*ppCPC);
120 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink,
123 ConnectionPoint *This = CONPOINT_THIS(iface);
128 TRACE("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
130 hres = IUnknown_QueryInterface(pUnkSink, &This->iid, (void**)&sink);
131 if(FAILED(hres) && !IsEqualGUID(&IID_IPropertyNotifySink, &This->iid)) {
132 hres = IUnknown_QueryInterface(pUnkSink, &IID_IDispatch, (void**)&sink);
134 return CONNECT_E_CANNOTCONNECT;
138 for(i=0; i<This->sinks_size; i++) {
139 if(!This->sinks[i].unk)
143 if(i == This->sinks_size)
144 This->sinks = mshtml_realloc(This->sinks,(++This->sinks_size)*sizeof(*This->sinks));
146 This->sinks = mshtml_alloc(sizeof(*This->sinks));
147 This->sinks_size = 1;
151 This->sinks[i].unk = sink;
157 static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
159 ConnectionPoint *This = CONPOINT_THIS(iface);
160 TRACE("(%p)->(%ld)\n", This, dwCookie);
162 if(!dwCookie || dwCookie > This->sinks_size || !This->sinks[dwCookie-1].unk)
163 return CONNECT_E_NOCONNECTION;
165 IUnknown_Release(This->sinks[dwCookie-1].unk);
166 This->sinks[dwCookie-1].unk = NULL;
171 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
172 IEnumConnections **ppEnum)
174 ConnectionPoint *This = CONPOINT_THIS(iface);
175 FIXME("(%p)->(%p)\n", This, ppEnum);
181 static const IConnectionPointVtbl ConnectionPointVtbl =
183 ConnectionPoint_QueryInterface,
184 ConnectionPoint_AddRef,
185 ConnectionPoint_Release,
186 ConnectionPoint_GetConnectionInterface,
187 ConnectionPoint_GetConnectionPointContainer,
188 ConnectionPoint_Advise,
189 ConnectionPoint_Unadvise,
190 ConnectionPoint_EnumConnections
193 static void ConnectionPoint_Create(HTMLDocument *doc, REFIID riid, ConnectionPoint **cp)
195 ConnectionPoint *ret = mshtml_alloc(sizeof(ConnectionPoint));
197 ret->lpConnectionPointVtbl = &ConnectionPointVtbl;
201 memcpy(&ret->iid, riid, sizeof(IID));
206 static void ConnectionPoint_Destroy(ConnectionPoint *This)
210 for(i=0; i<This->sinks_size; i++) {
211 if(This->sinks[i].unk)
212 IUnknown_Release(This->sinks[i].unk);
215 mshtml_free(This->sinks);
219 #define CONPTCONT_THIS(iface) DEFINE_THIS(HTMLDocument, ConnectionPointContainer, iface)
221 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
222 REFIID riid, void **ppv)
224 HTMLDocument *This = CONPTCONT_THIS(iface);
225 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
228 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
230 HTMLDocument *This = CONPTCONT_THIS(iface);
231 return IHTMLDocument2_AddRef(HTMLDOC(This));
234 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
236 HTMLDocument *This = CONPTCONT_THIS(iface);
237 return IHTMLDocument2_Release(HTMLDOC(This));
240 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
241 IEnumConnectionPoints **ppEnum)
243 HTMLDocument *This = CONPTCONT_THIS(iface);
244 FIXME("(%p)->(%p)\n", This, ppEnum);
248 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
249 REFIID riid, IConnectionPoint **ppCP)
251 HTMLDocument *This = CONPTCONT_THIS(iface);
255 if(IsEqualGUID(&DIID_HTMLDocumentEvents, riid)) {
256 TRACE("(%p)->(DIID_HTMLDocumentEvents %p)\n", This, ppCP);
257 *ppCP = CONPOINT(This->cp_htmldocevents);
258 }else if(IsEqualGUID(&DIID_HTMLDocumentEvents2, riid)) {
259 TRACE("(%p)->(DIID_HTMLDocumentEvents2 %p)\n", This, ppCP);
260 *ppCP = CONPOINT(This->cp_htmldocevents2);
261 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
262 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP);
263 *ppCP = CONPOINT(This->cp_propnotif);
267 IConnectionPoint_AddRef(*ppCP);
271 FIXME("(%p)->(%s %p) unsupported riid\n", This, debugstr_guid(riid), ppCP);
272 return CONNECT_E_NOCONNECTION;
275 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl = {
276 ConnectionPointContainer_QueryInterface,
277 ConnectionPointContainer_AddRef,
278 ConnectionPointContainer_Release,
279 ConnectionPointContainer_EnumConnectionPoints,
280 ConnectionPointContainer_FindConnectionPoint
283 #undef CONPTCONT_THIS
285 void HTMLDocument_ConnectionPoints_Init(HTMLDocument *This)
287 This->lpConnectionPointContainerVtbl = &ConnectionPointContainerVtbl;
289 ConnectionPoint_Create(This, &IID_IPropertyNotifySink, &This->cp_propnotif);
290 ConnectionPoint_Create(This, &DIID_HTMLDocumentEvents, &This->cp_htmldocevents);
291 ConnectionPoint_Create(This, &DIID_HTMLDocumentEvents2, &This->cp_htmldocevents2);
294 void HTMLDocument_ConnectionPoints_Destroy(HTMLDocument *This)
296 ConnectionPoint_Destroy(This->cp_propnotif);
297 ConnectionPoint_Destroy(This->cp_htmldocevents);
298 ConnectionPoint_Destroy(This->cp_htmldocevents2);