GLASSCTL.H

// GlassControl.h : Declaration of the CGlassControl 

#ifndef __GLASSCONTROL_H_
#define __GLASSCONTROL_H_

#include "resource.h" // main symbols
#include "CPGlass.h"
#include <mshtml.h> // for ICSSFilter
#include <ocmm.h>
#include <DDraw.H>
#include <DDrawEx.H>

typedef struct tagGLASSSTATE
{

int iWidth;
int Brightness;
DWORD DynamicFade; // 0 = no fade, otherwise, value = interval
int FadeInterval; // the change in brightness
unsigned fFreeze:1;
unsigned fEnabled:1; // CSSFilter state
unsigned fInvalid:1; // get drawn the first time around
} GLASSSTATE;

#define LEFT_BUTTON 0x01
#define RIGHT_BUTTON 0x02
#define MIDDLE_BUTTON 0x04

#define CHECK_POINTER(val) \
if (!(val) || IsBadWritePtr((void *)(val), sizeof(void *))) return E_POINTER

/////////////////////////////////////////////////////////////////////////////
// CGlassControl
class ATL_NO_VTABLE CGlassControl :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CGlassControl, &CLSID_GlassControl>,
public CComControl<CGlassControl>,
public IDispatchImpl<IGlassControl, &IID_IGlassControl, &LIBID_GLASSLib>,
public IProvideClassInfo2Impl<&CLSID_GlassControl, &DIID__GlassEvents, &LIBID_GLASSLib>,
public IPersistStreamInitImpl<CGlassControl>,
public IPersistStorageImpl<CGlassControl>,
public IPersistPropertyBagImpl<CGlassControl>,
public IQuickActivateImpl<CGlassControl>,
public IOleControlImpl<CGlassControl>,
public IOleObjectImpl<CGlassControl>,
public IOleInPlaceActiveObjectImpl<CGlassControl>,
public IViewObjectExImpl<CGlassControl>,
public IOleInPlaceObjectWindowlessImpl<CGlassControl>,
public IDataObjectImpl<CGlassControl>,
public ISpecifyPropertyPagesImpl<CGlassControl>,
public CProxy_GlassEvents<CGlassControl>,
public IConnectionPointContainerImpl<CGlassControl>,
public IObjectSafetyImpl<CGlassControl>,
public IViewFilter,
public IViewFilterSite,
public ICSSFilter
{
public:
friend class CGlassControlSink;

CGlassControl();
~CGlassControl();

DECLARE_REGISTRY_RESOURCEID(IDR_GLASSCONTROL)

BEGIN_COM_MAP(CGlassControl)
COM_INTERFACE_ENTRY(IGlassControl)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
COM_INTERFACE_ENTRY_IMPL(IOleControl)
COM_INTERFACE_ENTRY_IMPL(IOleObject)
COM_INTERFACE_ENTRY_IMPL(IQuickActivate)
COM_INTERFACE_ENTRY_IMPL(IPersistStorage)
COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit)
COM_INTERFACE_ENTRY_IMPL(IPersistPropertyBag)
COM_INTERFACE_ENTRY_IMPL(ISpecifyPropertyPages)
COM_INTERFACE_ENTRY_IMPL(IDataObject)
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
COM_INTERFACE_ENTRY_IMPL(IObjectSafety)
COM_INTERFACE_ENTRY(IViewFilter)
COM_INTERFACE_ENTRY(IViewFilterSite)
COM_INTERFACE_ENTRY(ICSSFilter)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CGlassControl)
CONNECTION_POINT_ENTRY(DIID__GlassEvents)
END_CONNECTION_POINT_MAP()

BEGIN_PROPERTY_MAP(CGlassControl)
// Example entries
// PROP_ENTRY("Property Description", dispid, clsid)
PROP_PAGE(CLSID_StockColorPage)
END_PROPERTY_MAP()


BEGIN_MSG_MAP(CGlassControl)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
MESSAGE_RANGE_HANDLER(WM_MOUSEMOVE, WM_MBUTTONUP, OnMouse)
END_MSG_MAP()


// IViewObjectEx
#define VIEWSTATUS_SURFACE 16
STDMETHOD(GetViewStatus)(DWORD* pdwStatus)
{
ATLTRACE(_T("IViewObjectExImpl::GetViewStatus\n"));
*pdwStatus = VIEWSTATUS_DVASPECTTRANSPARENT | VIEWSTATUS_SURFACE;
return S_OK;
}

// IGlassControl
public:
HRESULT OnDraw(ATL_DRAWINFO& di);

// IViewObjectEX overrides
STDMETHOD(QueryHitPoint)(DWORD dwAspect, LPCRECT pRectBounds, POINT ptlLoc, LONG lCloseHint, DWORD *pHitResult);

// Event handling methods
LRESULT OnMouse(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

// IGlass properties
//
STDMETHOD(get_LineWidth)(long FAR* plWidth);
STDMETHOD(put_LineWidth)(long lWidth);
STDMETHOD(get_Brightness)(long FAR* plBrightness);
STDMETHOD(put_Brightness)(long lBrightness);
STDMETHOD(get_DynamicFade)(long FAR* plDynamicFade);
STDMETHOD(put_DynamicFade)(long lDynamicFade);
STDMETHOD(get_FadeInterval)(long FAR* plFadeInterval);
STDMETHOD(put_FadeInterval)(long lFadeInterval);
STDMETHOD(get_Freeze)(long FAR* plFreeze);
STDMETHOD(put_Freeze)(long lFreeze);
STDMETHOD(get_Enabled)(long FAR* plEnabled);
STDMETHOD(put_Enabled)(long lEnabled);

STDMETHOD(HandleOnTimer)( DWORD timeAdvise );

// IViewFilter
public:
STDMETHOD(SetSource)(IViewFilter *pSource);
STDMETHOD(GetSource)(IViewFilter **ppSource);
STDMETHOD(SetSite)(IViewFilterSite *pSink);
STDMETHOD(GetSite)(IViewFilterSite **ppSink);
STDMETHOD(SetPosition)(LPCRECT prc);
STDMETHOD(Draw)(HDC hdc, LPCRECT prcBounds);
STDMETHOD(GetStatusBits)(DWORD *pdwFlags);

// IViewFilterSite
public:
STDMETHOD(GetDC)(LPCRECT prc, DWORD dwFlags, HDC *phdc);
STDMETHOD(ReleaseDC)(HDC hdc);
STDMETHOD(InvalidateRect)(LPCRECT prc, BOOL fErase);
STDMETHOD(InvalidateRgn)(HRGN hrgn, BOOL fErase);
STDMETHOD(OnStatusBitsChange)(DWORD dwFlags);

// ICSSFilter methods
STDMETHOD(SetSite)(ICSSFilterSite *pSite);
STDMETHOD(OnAmbientPropertyChange)(DISPID dispid);

// IPersistPropertyBag methods
STDMETHOD(Load)(IPropertyBag *pPropBag, IErrorLog *pErrorLog);

// IObjectSafety methods
STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid,
DWORD *pdwSupportedOptions,
DWORD *pdwEnabledOptions);
STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid,
DWORD dwOptionSetMask,
DWORD dwEnabledOptions);


// private state information.
//
GLASSSTATE m_state;
IDirectDraw3 *m_pDirectDraw3;
ITimer *m_pTimer;
CGlassControlSink *m_pTimerSink;
DWORD m_TimerCookie;
DWORD m_timeLastAdvise;

IViewFilter *m_pSource;
IViewFilterSite *m_pSite;
RECT m_rc;
ICSSFilterSite *m_pCSSSite;
};

class CGlassControlSink : public ITimerSink
{

friend class CGlassControl;

public:

CGlassControlSink( CGlassControl *pGC ) { m_pGC = pGC; m_cRefs = 0; }
~CGlassControlSink() { if ( m_pGC ) m_pGC->m_pTimerSink = NULL; }

// IUnknown methods
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
STDMETHODIMP QueryInterface (REFIID iid, void **ppvObj);

// ITimerSink methods
STDMETHOD(OnTimer)(VARIANT timeAdvise);

protected:
ULONG m_cRefs;
CGlassControl *m_pGC;
};

#endif //__GLASSCONTROL_H_