ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

events.c
Go to the documentation of this file.
00001 /*
00002  * Implementation of event-related interfaces for WebBrowser control:
00003  *
00004  *  - IConnectionPointContainer
00005  *  - IConnectionPoint
00006  *
00007  * Copyright 2001 John R. Sheets (for CodeWeavers)
00008  * Copyright 2006 Jacek Caban for CodeWeavers
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00023  */
00024 
00025 #include <string.h>
00026 #include "wine/debug.h"
00027 #include "shdocvw.h"
00028 
00029 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
00030 
00031 struct ConnectionPoint {
00032     const IConnectionPointVtbl *lpConnectionPointVtbl;
00033 
00034     IConnectionPointContainer *container;
00035 
00036     IDispatch **sinks;
00037     DWORD sinks_size;
00038 
00039     IID iid;
00040 };
00041 
00042 #define CONPOINT(x)  ((IConnectionPoint*) &(x)->lpConnectionPointVtbl)
00043 
00044 /**********************************************************************
00045  * Implement the IConnectionPointContainer interface
00046  */
00047 
00048 #define CONPTCONT_THIS(iface) DEFINE_THIS(ConnectionPointContainer, ConnectionPointContainer, iface)
00049 
00050 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
00051         REFIID riid, LPVOID *ppv)
00052 {
00053     ConnectionPointContainer *This = CONPTCONT_THIS(iface);
00054     return IUnknown_QueryInterface(This->impl, riid, ppv);
00055 }
00056 
00057 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
00058 {
00059     ConnectionPointContainer *This = CONPTCONT_THIS(iface);
00060     return IUnknown_AddRef(This->impl);
00061 }
00062 
00063 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
00064 {
00065     ConnectionPointContainer *This = CONPTCONT_THIS(iface);
00066     return IUnknown_Release(This->impl);
00067 }
00068 
00069 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
00070         LPENUMCONNECTIONPOINTS *ppEnum)
00071 {
00072     ConnectionPointContainer *This = CONPTCONT_THIS(iface);
00073     FIXME("(%p)->(%p)\n", This, ppEnum);
00074     return E_NOTIMPL;
00075 }
00076 
00077 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
00078         REFIID riid, LPCONNECTIONPOINT *ppCP)
00079 {
00080     ConnectionPointContainer *This = CONPTCONT_THIS(iface);
00081 
00082     if(!ppCP) {
00083         WARN("ppCP == NULL\n");
00084         return E_POINTER;
00085     }
00086 
00087     *ppCP = NULL;
00088 
00089     if(IsEqualGUID(&DIID_DWebBrowserEvents2, riid)) {
00090         TRACE("(%p)->(DIID_DWebBrowserEvents2 %p)\n", This, ppCP);
00091         *ppCP = CONPOINT(This->wbe2);
00092     }else if(IsEqualGUID(&DIID_DWebBrowserEvents, riid)) {
00093         TRACE("(%p)->(DIID_DWebBrowserEvents %p)\n", This, ppCP);
00094         *ppCP = CONPOINT(This->wbe);
00095     }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
00096         TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppCP);
00097         *ppCP = CONPOINT(This->pns);
00098     }
00099 
00100     if(*ppCP) {
00101         IConnectionPoint_AddRef(*ppCP);
00102         return S_OK;
00103     }
00104 
00105     WARN("Unsupported IID %s\n", debugstr_guid(riid));
00106     return CONNECT_E_NOCONNECTION;
00107 }
00108 
00109 #undef CONPTCONT_THIS
00110 
00111 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl =
00112 {
00113     ConnectionPointContainer_QueryInterface,
00114     ConnectionPointContainer_AddRef,
00115     ConnectionPointContainer_Release,
00116     ConnectionPointContainer_EnumConnectionPoints,
00117     ConnectionPointContainer_FindConnectionPoint
00118 };
00119 
00120 
00121 /**********************************************************************
00122  * Implement the IConnectionPoint interface
00123  */
00124 
00125 #define CONPOINT_THIS(iface) DEFINE_THIS(ConnectionPoint, ConnectionPoint, iface)
00126 
00127 static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface,
00128                                                      REFIID riid, LPVOID *ppv)
00129 {
00130     ConnectionPoint *This = CONPOINT_THIS(iface);
00131 
00132     *ppv = NULL;
00133 
00134     if(IsEqualGUID(&IID_IUnknown, riid)) {
00135         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
00136         *ppv = CONPOINT(This);
00137     }else if(IsEqualGUID(&IID_IConnectionPoint, riid)) {
00138         TRACE("(%p)->(IID_IConnectionPoint %p)\n", This, ppv);
00139         *ppv = CONPOINT(This);
00140     }
00141 
00142     if(*ppv) {
00143         IConnectionPointContainer_AddRef(This->container);
00144         return S_OK;
00145     }
00146 
00147     WARN("Unsupported interface %s\n", debugstr_guid(riid));
00148     return E_NOINTERFACE;
00149 }
00150 
00151 static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
00152 {
00153     ConnectionPoint *This = CONPOINT_THIS(iface);
00154     return IConnectionPointContainer_AddRef(This->container);
00155 }
00156 
00157 static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
00158 {
00159     ConnectionPoint *This = CONPOINT_THIS(iface);
00160     return IConnectionPointContainer_Release(This->container);
00161 }
00162 
00163 static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *pIID)
00164 {
00165     ConnectionPoint *This = CONPOINT_THIS(iface);
00166 
00167     TRACE("(%p)->(%p)\n", This, pIID);
00168 
00169     *pIID = This->iid;
00170     return S_OK;
00171 }
00172 
00173 static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
00174         IConnectionPointContainer **ppCPC)
00175 {
00176     ConnectionPoint *This = CONPOINT_THIS(iface);
00177 
00178     TRACE("(%p)->(%p)\n", This, ppCPC);
00179 
00180     *ppCPC = This->container;
00181     IConnectionPointContainer_AddRef(This->container);
00182     return S_OK;
00183 }
00184 
00185 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink,
00186                                              DWORD *pdwCookie)
00187 {
00188     ConnectionPoint *This = CONPOINT_THIS(iface);
00189     IDispatch *disp;
00190     DWORD i;
00191     HRESULT hres;
00192 
00193     TRACE("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
00194 
00195     hres = IUnknown_QueryInterface(pUnkSink, &This->iid, (void**)&disp);
00196     if(FAILED(hres)) {
00197         hres = IUnknown_QueryInterface(pUnkSink, &IID_IDispatch, (void**)&disp);
00198         if(FAILED(hres))
00199             return CONNECT_E_CANNOTCONNECT;
00200     }
00201 
00202     if(This->sinks) {
00203         for(i=0; i<This->sinks_size; i++) {
00204             if(!This->sinks[i])
00205                 break;
00206         }
00207 
00208         if(i == This->sinks_size)
00209             This->sinks = heap_realloc(This->sinks,
00210                                           (++This->sinks_size)*sizeof(*This->sinks));
00211     }else {
00212         This->sinks = heap_alloc(sizeof(*This->sinks));
00213         This->sinks_size = 1;
00214         i = 0;
00215     }
00216 
00217     This->sinks[i] = disp;
00218     *pdwCookie = i+1;
00219 
00220     return S_OK;
00221 }
00222 
00223 static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
00224 {
00225     ConnectionPoint *This = CONPOINT_THIS(iface);
00226 
00227     TRACE("(%p)->(%d)\n", This, dwCookie);
00228 
00229     if(!dwCookie || dwCookie > This->sinks_size || !This->sinks[dwCookie-1])
00230         return CONNECT_E_NOCONNECTION;
00231 
00232     IDispatch_Release(This->sinks[dwCookie-1]);
00233     This->sinks[dwCookie-1] = NULL;
00234 
00235     return S_OK;
00236 }
00237 
00238 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
00239                                                       IEnumConnections **ppEnum)
00240 {
00241     ConnectionPoint *This = CONPOINT_THIS(iface);
00242     FIXME("(%p)->(%p)\n", This, ppEnum);
00243     return E_NOTIMPL;
00244 }
00245 
00246 #undef CONPOINT_THIS
00247 
00248 static const IConnectionPointVtbl ConnectionPointVtbl =
00249 {
00250     ConnectionPoint_QueryInterface,
00251     ConnectionPoint_AddRef,
00252     ConnectionPoint_Release,
00253     ConnectionPoint_GetConnectionInterface,
00254     ConnectionPoint_GetConnectionPointContainer,
00255     ConnectionPoint_Advise,
00256     ConnectionPoint_Unadvise,
00257     ConnectionPoint_EnumConnections
00258 };
00259 
00260 void call_sink(ConnectionPoint *This, DISPID dispid, DISPPARAMS *dispparams)
00261 {
00262     DWORD i;
00263 
00264     for(i=0; i<This->sinks_size; i++) {
00265         if(This->sinks[i])
00266             IDispatch_Invoke(This->sinks[i], dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
00267                              DISPATCH_METHOD, dispparams, NULL, NULL, NULL);
00268     }
00269 }
00270 
00271 static void ConnectionPoint_Create(REFIID riid, ConnectionPoint **cp,
00272                                    IConnectionPointContainer *container)
00273 {
00274     ConnectionPoint *ret = heap_alloc(sizeof(ConnectionPoint));
00275 
00276     ret->lpConnectionPointVtbl = &ConnectionPointVtbl;
00277 
00278     ret->sinks = NULL;
00279     ret->sinks_size = 0;
00280     ret->container = container;
00281 
00282     ret->iid = *riid;
00283 
00284     *cp = ret;
00285 }
00286 
00287 static void ConnectionPoint_Destroy(ConnectionPoint *This)
00288 {
00289     DWORD i;
00290 
00291     for(i=0; i<This->sinks_size; i++) {
00292         if(This->sinks[i])
00293             IDispatch_Release(This->sinks[i]);
00294     }
00295 
00296     heap_free(This->sinks);
00297     heap_free(This);
00298 }
00299 
00300 void ConnectionPointContainer_Init(ConnectionPointContainer *This, IUnknown *impl)
00301 {
00302     This->lpConnectionPointContainerVtbl = &ConnectionPointContainerVtbl;
00303 
00304     ConnectionPoint_Create(&DIID_DWebBrowserEvents2, &This->wbe2, CONPTCONT(This));
00305     ConnectionPoint_Create(&DIID_DWebBrowserEvents,  &This->wbe,  CONPTCONT(This));
00306     ConnectionPoint_Create(&IID_IPropertyNotifySink, &This->pns,  CONPTCONT(This));
00307 
00308     This->impl = impl;
00309 }
00310 
00311 void ConnectionPointContainer_Destroy(ConnectionPointContainer *This)
00312 {
00313     ConnectionPoint_Destroy(This->wbe2);
00314     ConnectionPoint_Destroy(This->wbe);
00315     ConnectionPoint_Destroy(This->pns);
00316 }

Generated on Sun May 27 2012 04:25:16 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.