Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions
CControlEventSink Class Reference

#include <ControlEventSink.h>

Inheritance diagram for CControlEventSink:
Inheritance graph
[legend]
Collaboration diagram for CControlEventSink:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CControlEventSink ()
virtual HRESULT SubscribeToEvents (IUnknown *pControl)
virtual void UnsubscribeFromEvents ()
virtual BOOL GetEventSinkIID (IUnknown *pControl, IID &iid, ITypeInfo **typeInfo)
virtual HRESULT InternalInvoke (DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount (UINT __RPC_FAR *pctinfo)
virtual HRESULT STDMETHODCALLTYPE GetTypeInfo (UINT iTInfo, LCID lcid, ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames (REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames, LCID lcid, DISPID __RPC_FAR *rgDispId)
virtual HRESULT STDMETHODCALLTYPE Invoke (DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr)

Public Attributes

CComPtr< IConnectionPoint > m_spEventCP
CComPtr< ITypeInfo > m_spEventSinkTypeInfo
DWORD m_dwEventCookie
IID m_EventIID

Protected Member Functions

virtual ~CControlEventSink ()

Static Protected Member Functions

static HRESULT WINAPI SinkQI (void *pv, REFIID riid, LPVOID *ppv, DWORD dw)

Detailed Description

Definition at line 44 of file ControlEventSink.h.


Constructor & Destructor Documentation

Definition at line 43 of file ControlEventSink.cpp.

                                     :
    m_dwEventCookie(0),
    m_EventIID(GUID_NULL)
{
}
CControlEventSink::~CControlEventSink ( ) [protected, virtual]

Definition at line 49 of file ControlEventSink.cpp.

Here is the call graph for this function:


Member Function Documentation

BOOL CControlEventSink::GetEventSinkIID ( IUnknown pControl,
IID &  iid,
ITypeInfo **  typeInfo 
) [virtual]

Definition at line 55 of file ControlEventSink.cpp.

{
       iid = GUID_NULL;
    if (!pControl)
    {
        return E_INVALIDARG;
    }

       // IProvideClassInfo2 way is easiest
//    CComQIPtr<IProvideClassInfo2> classInfo2 = pControl;
//    if (classInfo2)
//    {
//        classInfo2->GetGUID(GUIDKIND_DEFAULT_SOURCE_DISP_IID, &iid);
//        if (!::IsEqualIID(iid, GUID_NULL))
//        {
//            return TRUE;
//        }
//    }

    // Yuck, the hard way
    CComQIPtr<IProvideClassInfo> classInfo = pControl;
    if (!classInfo)
    {
        return FALSE;
    }

    // Search the class type information for the default source interface
    // which is the outgoing event sink.

    CComPtr<ITypeInfo> classTypeInfo;
    classInfo->GetClassInfo(&classTypeInfo);
    if (!classTypeInfo)
    {
        return FALSE;
    }
    TYPEATTR *classAttr = NULL;
    if (FAILED(classTypeInfo->GetTypeAttr(&classAttr)))
    {
        return FALSE;
    }
    INT implFlags = 0;
    for (UINT i = 0; i < classAttr->cImplTypes; i++)
    {
        // Search for the interface with the [default, source] attr
        if (SUCCEEDED(classTypeInfo->GetImplTypeFlags(i, &implFlags)) &&
            implFlags == (IMPLTYPEFLAG_FDEFAULT | IMPLTYPEFLAG_FSOURCE))
        {
            CComPtr<ITypeInfo> eventSinkTypeInfo;
            HREFTYPE hRefType;
            if (SUCCEEDED(classTypeInfo->GetRefTypeOfImplType(i, &hRefType)) &&
                SUCCEEDED(classTypeInfo->GetRefTypeInfo(hRefType, &eventSinkTypeInfo)))
            {
                TYPEATTR *eventSinkAttr = NULL;
                if (SUCCEEDED(eventSinkTypeInfo->GetTypeAttr(&eventSinkAttr)))
                {
                    iid = eventSinkAttr->guid;
                    if (typeInfo)
                    {
                        *typeInfo = eventSinkTypeInfo.p;
                        (*typeInfo)->AddRef();
                    }
                    eventSinkTypeInfo->ReleaseTypeAttr(eventSinkAttr);
                }
            }
            break;
        }
    }
    classTypeInfo->ReleaseTypeAttr(classAttr);

    return (!::IsEqualIID(iid, GUID_NULL));
}

Here is the caller graph for this function:

HRESULT STDMETHODCALLTYPE CControlEventSink::GetIDsOfNames ( REFIID  riid,
LPOLESTR __RPC_FAR *  rgszNames,
UINT  cNames,
LCID  lcid,
DISPID __RPC_FAR *  rgDispId 
) [virtual]

Definition at line 205 of file ControlEventSink.cpp.

{
    return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE CControlEventSink::GetTypeInfo ( UINT  iTInfo,
LCID  lcid,
ITypeInfo __RPC_FAR *__RPC_FAR *  ppTInfo 
) [virtual]

Definition at line 199 of file ControlEventSink.cpp.

{
    return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE CControlEventSink::GetTypeInfoCount ( UINT __RPC_FAR *  pctinfo) [virtual]

Definition at line 193 of file ControlEventSink.cpp.

{
    return E_NOTIMPL;
}
HRESULT CControlEventSink::InternalInvoke ( DISPID  dispIdMember,
REFIID  riid,
LCID  lcid,
WORD  wFlags,
DISPPARAMS *  pDispParams,
VARIANT *  pVarResult,
EXCEPINFO *  pExcepInfo,
UINT puArgErr 
) [virtual]

Definition at line 183 of file ControlEventSink.cpp.

{
    // Override me!
    return E_NOTIMPL;
}

Here is the caller graph for this function:

HRESULT STDMETHODCALLTYPE CControlEventSink::Invoke ( DISPID  dispIdMember,
REFIID  riid,
LCID  lcid,
WORD  wFlags,
DISPPARAMS __RPC_FAR *  pDispParams,
VARIANT __RPC_FAR *  pVarResult,
EXCEPINFO __RPC_FAR *  pExcepInfo,
UINT __RPC_FAR *  puArgErr 
) [virtual]

Definition at line 211 of file ControlEventSink.cpp.

{
    return InternalInvoke(dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
}

Here is the call graph for this function:

static HRESULT WINAPI CControlEventSink::SinkQI ( void pv,
REFIID  riid,
LPVOID ppv,
DWORD  dw 
) [inline, static, protected]

Definition at line 60 of file ControlEventSink.h.

    {
        CControlEventSink *pThis = (CControlEventSink *) pv;
        if (!IsEqualIID(pThis->m_EventIID, GUID_NULL) && 
             IsEqualIID(pThis->m_EventIID, riid))
        {
            return pThis->QueryInterface(__uuidof(IDispatch), ppv);
        }
        return E_NOINTERFACE;
    }

Definition at line 138 of file ControlEventSink.cpp.

{
    if (!pControl)
    {
        return E_INVALIDARG;
    }

    // Throw away any existing connections
    UnsubscribeFromEvents();

    // Grab the outgoing event sink IID which will be used to subscribe
    // to events via the connection point container.

    IID iidEventSink;
    CComPtr<ITypeInfo> typeInfo;
    if (!GetEventSinkIID(pControl, iidEventSink, &typeInfo))
    {
        return E_FAIL;
    }

    // Get the connection point
    CComQIPtr<IConnectionPointContainer> ccp = pControl;
    CComPtr<IConnectionPoint> cp;
    if (!ccp)
    {
        return E_FAIL;
    }

    // Custom IID
    m_EventIID = iidEventSink;
    DWORD dwCookie = 0;
    if (!ccp ||
        FAILED(ccp->FindConnectionPoint(m_EventIID, &cp)) ||
        FAILED(cp->Advise(this, &m_dwEventCookie)))
    {
        return E_FAIL;
    }

    m_spEventCP = cp;
    m_dwEventCookie = dwCookie;
    m_spEventSinkTypeInfo = typeInfo;
    return S_OK;
}

Here is the call graph for this function:

Definition at line 127 of file ControlEventSink.cpp.

{
    if (m_spEventCP)
    {
        // Unsubscribe and reset
        m_spEventCP->Unadvise(m_dwEventCookie);
        m_dwEventCookie = 0;
        m_spEventCP.Release();
    }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 54 of file ControlEventSink.h.

Definition at line 55 of file ControlEventSink.h.

CComPtr<IConnectionPoint> CControlEventSink::m_spEventCP

Definition at line 52 of file ControlEventSink.h.

Definition at line 53 of file ControlEventSink.h.


The documentation for this class was generated from the following files: