advapi32: Test and implement SystemFunction024/025.
[wine] / dlls / mshtml / conpoint.c
1 /*
2  * Copyright 2006 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30
31 #include "wine/debug.h"
32
33 #include "mshtml_private.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36
37 #define CONPOINT(x) ((IConnectionPoint*) &(x)->lpConnectionPointVtbl);
38
39 struct ConnectionPoint {
40     const IConnectionPointVtbl *lpConnectionPointVtbl;
41
42     HTMLDocument *doc;
43     IID iid;
44 };
45
46 #define CONPOINT_THIS(iface) DEFINE_THIS(ConnectionPoint, ConnectionPoint, iface)
47
48 static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface,
49                                                      REFIID riid, LPVOID *ppv)
50 {
51     ConnectionPoint *This = CONPOINT_THIS(iface);
52
53     *ppv = NULL;
54
55     if(IsEqualGUID(&IID_IUnknown, riid)) {
56         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
57         *ppv = CONPOINT(This);
58     }else if(IsEqualGUID(&IID_IConnectionPoint, riid)) {
59         TRACE("(%p)->(IID_IConnectionPoint %p)\n", This, ppv);
60         *ppv = CONPOINT(This);
61     }
62
63     if(*ppv) {
64         IUnknown_AddRef((IUnknown*)*ppv);
65         return S_OK;
66     }
67
68     WARN("Unsupported interface %s\n", debugstr_guid(riid));
69     return E_NOINTERFACE;
70 }
71
72 static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
73 {
74     ConnectionPoint *This = CONPOINT_THIS(iface);
75     return IHTMLDocument2_AddRef(HTMLDOC(This->doc));
76 }
77
78 static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
79 {
80     ConnectionPoint *This = CONPOINT_THIS(iface);
81     return IHTMLDocument2_Release(HTMLDOC(This->doc));
82 }
83
84 static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *pIID)
85 {
86     ConnectionPoint *This = CONPOINT_THIS(iface);
87
88     TRACE("(%p)->(%p)\n", This, pIID);
89
90     if(!pIID)
91         return E_POINTER;
92
93     memcpy(pIID, &This->iid, sizeof(IID));
94     return S_OK;
95 }
96
97 static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
98         IConnectionPointContainer **ppCPC)
99 {
100     ConnectionPoint *This = CONPOINT_THIS(iface);
101
102     TRACE("(%p)->(%p)\n", This, ppCPC);
103
104     if(!ppCPC)
105         return E_POINTER;
106
107     *ppCPC = CONPTCONT(This->doc);
108     IConnectionPointContainer_AddRef(*ppCPC);
109     return S_OK;
110 }
111
112 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink,
113                                              DWORD *pdwCookie)
114 {
115     ConnectionPoint *This = CONPOINT_THIS(iface);
116     FIXME("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
117     return E_NOTIMPL;
118 }
119
120 static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
121 {
122     ConnectionPoint *This = CONPOINT_THIS(iface);
123     FIXME("(%p)->(%ld)\n", This, dwCookie);
124     return E_NOTIMPL;
125 }
126
127 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
128                                                       IEnumConnections **ppEnum)
129 {
130     ConnectionPoint *This = CONPOINT_THIS(iface);
131     FIXME("(%p)->(%p)\n", This, ppEnum);
132     return E_NOTIMPL;
133 }
134
135 #undef CONPOINT_THIS
136
137 static const IConnectionPointVtbl ConnectionPointVtbl =
138 {
139     ConnectionPoint_QueryInterface,
140     ConnectionPoint_AddRef,
141     ConnectionPoint_Release,
142     ConnectionPoint_GetConnectionInterface,
143     ConnectionPoint_GetConnectionPointContainer,
144     ConnectionPoint_Advise,
145     ConnectionPoint_Unadvise,
146     ConnectionPoint_EnumConnections
147 };
148
149 static void ConnectionPoint_Create(HTMLDocument *doc, REFIID riid, ConnectionPoint **cp)
150 {
151     ConnectionPoint *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ConnectionPoint));
152
153     ret->lpConnectionPointVtbl = &ConnectionPointVtbl;
154     ret->doc = doc;
155     memcpy(&ret->iid, riid, sizeof(IID));
156
157     *cp = ret;
158 }
159
160 #define CONPTCONT_THIS(iface) DEFINE_THIS(HTMLDocument, ConnectionPointContainer, iface)
161
162 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
163                                                               REFIID riid, void **ppv)
164 {
165     HTMLDocument *This = CONPTCONT_THIS(iface);
166     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
167 }
168
169 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
170 {
171     HTMLDocument *This = CONPTCONT_THIS(iface);
172     return IHTMLDocument2_AddRef(HTMLDOC(This));
173 }
174
175 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
176 {
177     HTMLDocument *This = CONPTCONT_THIS(iface);
178     return IHTMLDocument2_Release(HTMLDOC(This));
179 }
180
181 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
182         IEnumConnectionPoints **ppEnum)
183 {
184     HTMLDocument *This = CONPTCONT_THIS(iface);
185     FIXME("(%p)->(%p)\n", This, ppEnum);
186     return E_NOTIMPL;
187 }
188
189 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
190         REFIID riid, IConnectionPoint **ppCP)
191 {
192     HTMLDocument *This = CONPTCONT_THIS(iface);
193
194     *ppCP = NULL;
195
196     if(IsEqualGUID(&DIID_HTMLDocumentEvents, riid)) {
197         TRACE("(%p)->(DIID_HTMLDocumentEvents %p)\n", This, ppCP);
198         *ppCP = CONPOINT(This->cp_htmldocevents);
199     }else if(IsEqualGUID(&DIID_HTMLDocumentEvents2, riid)) {
200         TRACE("(%p)->(DIID_HTMLDocumentEvents2 %p)\n", This, ppCP);
201         *ppCP = CONPOINT(This->cp_htmldocevents2);
202     }
203
204     if(*ppCP) {
205         IConnectionPoint_AddRef(*ppCP);
206         return S_OK;
207     }
208
209     FIXME("(%p)->(%s %p) unsupported riid\n", This, debugstr_guid(riid), ppCP);
210     return CONNECT_E_NOCONNECTION;
211 }
212
213 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl = {
214     ConnectionPointContainer_QueryInterface,
215     ConnectionPointContainer_AddRef,
216     ConnectionPointContainer_Release,
217     ConnectionPointContainer_EnumConnectionPoints,
218     ConnectionPointContainer_FindConnectionPoint
219 };
220
221 #undef CONPTCONT_THIS
222
223 void HTMLDocument_ConnectionPoints_Init(HTMLDocument *This)
224 {
225     This->lpConnectionPointContainerVtbl = &ConnectionPointContainerVtbl;
226
227     ConnectionPoint_Create(This, &DIID_HTMLDocumentEvents, &This->cp_htmldocevents);
228     ConnectionPoint_Create(This, &DIID_HTMLDocumentEvents2, &This->cp_htmldocevents2);
229 }