secur32: Gracefully handle ntlm_auth versions that don't support the new commands.
[wine/winequartzdrv.git] / dlls / mshtml / conpoint.c
blobdb66160cf19c389b053742b2851d99e6803183e7
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
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;
42 HTMLDocument *doc;
44 union {
45 IUnknown *unk;
46 IDispatch *disp;
47 IPropertyNotifySink *propnotif;
48 } *sinks;
49 DWORD sinks_size;
51 IID iid;
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);
61 *ppv = NULL;
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);
71 if(*ppv) {
72 IUnknown_AddRef((IUnknown*)*ppv);
73 return S_OK;
76 WARN("Unsupported interface %s\n", debugstr_guid(riid));
77 return E_NOINTERFACE;
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);
98 if(!pIID)
99 return E_POINTER;
101 memcpy(pIID, &This->iid, sizeof(IID));
102 return S_OK;
105 static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
106 IConnectionPointContainer **ppCPC)
108 ConnectionPoint *This = CONPOINT_THIS(iface);
110 TRACE("(%p)->(%p)\n", This, ppCPC);
112 if(!ppCPC)
113 return E_POINTER;
115 *ppCPC = CONPTCONT(This->doc);
116 IConnectionPointContainer_AddRef(*ppCPC);
117 return S_OK;
120 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink,
121 DWORD *pdwCookie)
123 ConnectionPoint *This = CONPOINT_THIS(iface);
124 IUnknown *sink;
125 DWORD i;
126 HRESULT hres;
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);
133 if(FAILED(hres))
134 return CONNECT_E_CANNOTCONNECT;
136 if(This->sinks) {
137 for(i=0; i<This->sinks_size; i++) {
138 if(!This->sinks[i].unk)
139 break;
142 if(i == This->sinks_size)
143 This->sinks = mshtml_realloc(This->sinks,(++This->sinks_size)*sizeof(*This->sinks));
144 }else {
145 This->sinks = mshtml_alloc(sizeof(*This->sinks));
146 This->sinks_size = 1;
147 i = 0;
150 This->sinks[i].unk = sink;
151 *pdwCookie = i+1;
153 return S_OK;
156 static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
158 ConnectionPoint *This = CONPOINT_THIS(iface);
159 TRACE("(%p)->(%ld)\n", This, dwCookie);
161 if(!dwCookie || dwCookie > This->sinks_size || !This->sinks[dwCookie-1].unk)
162 return CONNECT_E_NOCONNECTION;
164 IUnknown_Release(This->sinks[dwCookie-1].unk);
165 This->sinks[dwCookie-1].unk = NULL;
167 return S_OK;
170 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
171 IEnumConnections **ppEnum)
173 ConnectionPoint *This = CONPOINT_THIS(iface);
174 FIXME("(%p)->(%p)\n", This, ppEnum);
175 return E_NOTIMPL;
178 #undef CONPOINT_THIS
180 static const IConnectionPointVtbl ConnectionPointVtbl =
182 ConnectionPoint_QueryInterface,
183 ConnectionPoint_AddRef,
184 ConnectionPoint_Release,
185 ConnectionPoint_GetConnectionInterface,
186 ConnectionPoint_GetConnectionPointContainer,
187 ConnectionPoint_Advise,
188 ConnectionPoint_Unadvise,
189 ConnectionPoint_EnumConnections
192 static void ConnectionPoint_Create(HTMLDocument *doc, REFIID riid, ConnectionPoint **cp)
194 ConnectionPoint *ret = mshtml_alloc(sizeof(ConnectionPoint));
196 ret->lpConnectionPointVtbl = &ConnectionPointVtbl;
197 ret->doc = doc;
198 ret->sinks = NULL;
199 ret->sinks_size = 0;
200 memcpy(&ret->iid, riid, sizeof(IID));
202 *cp = ret;
205 static void ConnectionPoint_Destroy(ConnectionPoint *This)
207 int i;
209 for(i=0; i<This->sinks_size; i++) {
210 if(This->sinks[i].unk)
211 IUnknown_Release(This->sinks[i].unk);
214 mshtml_free(This->sinks);
215 mshtml_free(This);
218 #define CONPTCONT_THIS(iface) DEFINE_THIS(HTMLDocument, ConnectionPointContainer, iface)
220 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
221 REFIID riid, void **ppv)
223 HTMLDocument *This = CONPTCONT_THIS(iface);
224 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
227 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
229 HTMLDocument *This = CONPTCONT_THIS(iface);
230 return IHTMLDocument2_AddRef(HTMLDOC(This));
233 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
235 HTMLDocument *This = CONPTCONT_THIS(iface);
236 return IHTMLDocument2_Release(HTMLDOC(This));
239 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
240 IEnumConnectionPoints **ppEnum)
242 HTMLDocument *This = CONPTCONT_THIS(iface);
243 FIXME("(%p)->(%p)\n", This, ppEnum);
244 return E_NOTIMPL;
247 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
248 REFIID riid, IConnectionPoint **ppCP)
250 HTMLDocument *This = CONPTCONT_THIS(iface);
252 *ppCP = NULL;
254 if(IsEqualGUID(&DIID_HTMLDocumentEvents, riid)) {
255 TRACE("(%p)->(DIID_HTMLDocumentEvents %p)\n", This, ppCP);
256 *ppCP = CONPOINT(This->cp_htmldocevents);
257 }else if(IsEqualGUID(&DIID_HTMLDocumentEvents2, riid)) {
258 TRACE("(%p)->(DIID_HTMLDocumentEvents2 %p)\n", This, ppCP);
259 *ppCP = CONPOINT(This->cp_htmldocevents2);
260 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
261 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP);
262 *ppCP = CONPOINT(This->cp_propnotif);
265 if(*ppCP) {
266 IConnectionPoint_AddRef(*ppCP);
267 return S_OK;
270 FIXME("(%p)->(%s %p) unsupported riid\n", This, debugstr_guid(riid), ppCP);
271 return CONNECT_E_NOCONNECTION;
274 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl = {
275 ConnectionPointContainer_QueryInterface,
276 ConnectionPointContainer_AddRef,
277 ConnectionPointContainer_Release,
278 ConnectionPointContainer_EnumConnectionPoints,
279 ConnectionPointContainer_FindConnectionPoint
282 #undef CONPTCONT_THIS
284 void HTMLDocument_ConnectionPoints_Init(HTMLDocument *This)
286 This->lpConnectionPointContainerVtbl = &ConnectionPointContainerVtbl;
288 ConnectionPoint_Create(This, &IID_IPropertyNotifySink, &This->cp_propnotif);
289 ConnectionPoint_Create(This, &DIID_HTMLDocumentEvents, &This->cp_htmldocevents);
290 ConnectionPoint_Create(This, &DIID_HTMLDocumentEvents2, &This->cp_htmldocevents2);
293 void HTMLDocument_ConnectionPoints_Destroy(HTMLDocument *This)
295 ConnectionPoint_Destroy(This->cp_propnotif);
296 ConnectionPoint_Destroy(This->cp_htmldocevents);
297 ConnectionPoint_Destroy(This->cp_htmldocevents2);