//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: EventWnd.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of EventWnd.cpp //---------------------------------------------------------------------------- // EventWnd.cpp : implementation file // #include "stdafx.h" #include "chicago.h" #include "EventWnd.h" #include "..\DLIB\Socket.h" #include "..\..\LgLib\Version.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CEventWnd CEventWnd::CEventWnd() { m_nActive = -1; LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CEventWnd::CEventWnd") ); } CEventWnd::~CEventWnd() { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CEventWnd::~CEventWnd") ); } BEGIN_MESSAGE_MAP(CEventWnd, CWnd) //{{AFX_MSG_MAP(CEventWnd) ON_WM_SIZE() ON_WM_PAINT() ON_WM_TIMER() ON_WM_LBUTTONDOWN() ON_WM_GETDLGCODE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEventWnd message handlers BOOL CEventWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { m_nActive = -1; CString strClassName = AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, LoadCursor(NULL, IDC_ARROW), NULL, NULL ); if( CWnd::CreateEx( WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE, strClassName, lpszWindowName, dwStyle | WS_CLIPSIBLINGS, rect, pParentWnd, nID, pContext) ) { m_Font.DeleteObject(); m_Font.CreateFontIndirect( &m_pSensorArray->GetProgramSettings().LogFontReport ); return TRUE; } return FALSE; } void CEventWnd::OnSize(UINT nType, int cx, int cy) { LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CEventWnd::OnSize"), _T("Started...") ); CWnd::OnSize(nType, cx, cy); LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CEventWnd::OnSize"), _T("Done") ); } void CEventWnd::OnPaint() { LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CEventWnd::OnPaint"), _T("Started...") ); CPaintDC dc(this); OnDraw( &dc ); LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CEventWnd::OnPaint"), _T("Done") ); } void CEventWnd::OnTimer(UINT nIDEvent) { CWnd::OnTimer(nIDEvent); } void CEventWnd::AddHead( EVENT &event ) { m_EventArray.InsertAt( 0, event ); if( m_EventArray.GetSize() > GetMaxLines() ) { m_EventArray.RemoveAt( m_EventArray.GetSize() - 1 ); } CClientDC dc( this ); OnDraw( &dc ); } EVENT* CEventWnd::GetAt( int nIndex ) { if( nIndex < 0 || nIndex >= m_EventArray.GetSize() ) return NULL; return &m_EventArray[nIndex]; } void CEventWnd::AddTail(EVENT &event) { m_EventArray.Add( event ); if( m_EventArray.GetSize() > GetMaxLines() ) { m_EventArray.RemoveAt(0); } CClientDC dc( this ); OnDraw( &dc ); } void CEventWnd::SetSensorArray(CSensorArray *pSensorArray) { m_pSensorArray = pSensorArray; } void CEventWnd::RemoveAll() { m_EventArray.RemoveAll(); CClientDC dc( this ); OnDraw( &dc ); } void CEventWnd::OnLButtonDown(UINT nFlags, CPoint point) { CWnd::OnLButtonDown(nFlags, point); SetFocus(); INT nFontHeight = abs( m_pSensorArray->GetProgramSettings().LogFontReport.lfHeight ); for( int j = 0; j < m_EventArray.GetSize(); j++ ) { int y0 = j * ( nFontHeight + 2 ) + 1; int y1 = y0 + ( nFontHeight + 2 ); if( y0 <= point.y && point.y <= y1 ) { GetParent()->SendMessage( WM_EVENT_CLICK, j, (LONG)&m_EventArray[j] ); break; } } } void CEventWnd::OnDraw( CDC *pDC ) { CRect rect; GetClientRect( &rect ); pDC->FillSolidRect( &rect, RGB(0xaf,0xaf,0xaf) ); for( int i = 0; i < m_EventArray.GetSize(); i ++ ) { BOOL bImage = m_EventArray[i].image.nImageCount != 0; BYTE bRed = GetRValue(m_EventArray[i].color) / 2; BYTE bBlue = GetBValue(m_EventArray[i].color) / 2; BYTE bGreen = GetGValue(m_EventArray[i].color) / 2; COLORREF nColor = pDC->SetTextColor( RGB( bRed, bGreen, bBlue ) ); // COLORREF nColor = pDC->SetTextColor( m_EventArray[i].color ); INT nBkMode = pDC->SetBkMode( TRANSPARENT ); CFont *pFont = pDC->SelectObject( &m_Font ); CString str; GetEventString( &m_EventArray[i], str ); INT nFontHeight = abs( m_pSensorArray->GetProgramSettings().LogFontReport.lfHeight ); if( m_nActive == i ) { CRect fillRect( 0, i * (nFontHeight + 2), rect.Width() - 1, (i+1)*(nFontHeight + 2) ); pDC->FillSolidRect( &fillRect, RGB(0xBF,0xBF,0xBF) ); CPen pen( PS_SOLID, 1, RGB(0,0,0) ); CPen *pPen = pDC->SelectObject( &pen ); pDC->MoveTo( fillRect.left, fillRect.top ); pDC->LineTo( fillRect.right, fillRect.top ); pDC->LineTo( fillRect.right, fillRect.bottom ); pDC->LineTo( fillRect.left, fillRect.bottom ); pDC->LineTo( fillRect.left, fillRect.top ); pDC->SelectObject( pPen ); } if( bImage ) pDC->TextOut( 1, 1+i * (nFontHeight + 2), _T("*")+str ); else pDC->TextOut( 1, 1+i * (nFontHeight + 2), _T(" ")+str ); pDC->SelectObject( pFont ); pDC->SetBkMode( nBkMode ); pDC->SetTextColor( nColor ); } } BOOL CEventWnd::SetActive( int nActive ) { if( !m_EventArray.GetSize() ) { m_nActive = 0; return FALSE; } if( nActive < 0 || nActive >= m_EventArray.GetSize() ) return FALSE; m_nActive = nActive; InvalidateRect( NULL ); return TRUE; } int CEventWnd::GetCountLines() { if( !GetSafeHwnd() ) return 0; return m_EventArray.GetSize(); } int CEventWnd::GetMaxLines() { if( !GetSafeHwnd() ) return 0; CRect rect; GetClientRect( &rect ); INT nFontHeight = abs( m_pSensorArray->GetProgramSettings().LogFontReport.lfHeight ); return rect.Height() / (nFontHeight + 2); } UINT CEventWnd::OnGetDlgCode() { // TODO: Add your message handler code here and/or call default return DLGC_BUTTON | DLGC_WANTARROWS;//CWnd::OnGetDlgCode(); } void CEventWnd::OnChangeSettings() { m_Font.DeleteObject(); m_Font.CreateFontIndirect( &m_pSensorArray->GetProgramSettings().LogFontReport ); InvalidateRect( NULL ); }