Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
6.4 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: EventWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of EventWnd.cpp
  13. //----------------------------------------------------------------------------
  14. // EventWnd.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "chicago.h"
  18. #include "EventWnd.h"
  19. #include "..\DLIB\Socket.h"
  20. #include "..\..\LgLib\Version.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CEventWnd
  28. CEventWnd::CEventWnd()
  29. {
  30. m_nActive = -1;
  31. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CEventWnd::CEventWnd") );
  32. }
  33. CEventWnd::~CEventWnd()
  34. {
  35. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CEventWnd::~CEventWnd") );
  36. }
  37. BEGIN_MESSAGE_MAP(CEventWnd, CWnd)
  38. //{{AFX_MSG_MAP(CEventWnd)
  39. ON_WM_SIZE()
  40. ON_WM_PAINT()
  41. ON_WM_TIMER()
  42. ON_WM_LBUTTONDOWN()
  43. ON_WM_GETDLGCODE()
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CEventWnd message handlers
  48. BOOL CEventWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
  49. {
  50. m_nActive = -1;
  51. CString strClassName = AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, LoadCursor(NULL, IDC_ARROW), NULL, NULL );
  52. if( CWnd::CreateEx( WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE, strClassName, lpszWindowName, dwStyle | WS_CLIPSIBLINGS, rect, pParentWnd, nID, pContext) )
  53. {
  54. m_Font.DeleteObject();
  55. m_Font.CreateFontIndirect( &m_pSensorArray->GetProgramSettings().LogFontReport );
  56. return TRUE;
  57. }
  58. return FALSE;
  59. }
  60. void CEventWnd::OnSize(UINT nType, int cx, int cy)
  61. {
  62. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CEventWnd::OnSize"), _T("Started...") );
  63. CWnd::OnSize(nType, cx, cy);
  64. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CEventWnd::OnSize"), _T("Done") );
  65. }
  66. void CEventWnd::OnPaint()
  67. {
  68. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CEventWnd::OnPaint"), _T("Started...") );
  69. CPaintDC dc(this);
  70. OnDraw( &dc );
  71. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CEventWnd::OnPaint"), _T("Done") );
  72. }
  73. void CEventWnd::OnTimer(UINT nIDEvent)
  74. {
  75. CWnd::OnTimer(nIDEvent);
  76. }
  77. void CEventWnd::AddHead( EVENT &event )
  78. {
  79. m_EventArray.InsertAt( 0, event );
  80. if( m_EventArray.GetSize() > GetMaxLines() )
  81. {
  82. m_EventArray.RemoveAt( m_EventArray.GetSize() - 1 );
  83. }
  84. CClientDC dc( this );
  85. OnDraw( &dc );
  86. }
  87. EVENT* CEventWnd::GetAt( int nIndex )
  88. {
  89. if( nIndex < 0 || nIndex >= m_EventArray.GetSize() )
  90. return NULL;
  91. return &m_EventArray[nIndex];
  92. }
  93. void CEventWnd::AddTail(EVENT &event)
  94. {
  95. m_EventArray.Add( event );
  96. if( m_EventArray.GetSize() > GetMaxLines() )
  97. {
  98. m_EventArray.RemoveAt(0);
  99. }
  100. CClientDC dc( this );
  101. OnDraw( &dc );
  102. }
  103. void CEventWnd::SetSensorArray(CSensorArray *pSensorArray)
  104. {
  105. m_pSensorArray = pSensorArray;
  106. }
  107. void CEventWnd::RemoveAll()
  108. {
  109. m_EventArray.RemoveAll();
  110. CClientDC dc( this );
  111. OnDraw( &dc );
  112. }
  113. void CEventWnd::OnLButtonDown(UINT nFlags, CPoint point)
  114. {
  115. CWnd::OnLButtonDown(nFlags, point);
  116. SetFocus();
  117. INT nFontHeight = abs( m_pSensorArray->GetProgramSettings().LogFontReport.lfHeight );
  118. for( int j = 0; j < m_EventArray.GetSize(); j++ )
  119. {
  120. int y0 = j * ( nFontHeight + 2 ) + 1;
  121. int y1 = y0 + ( nFontHeight + 2 );
  122. if( y0 <= point.y && point.y <= y1 )
  123. {
  124. GetParent()->SendMessage( WM_EVENT_CLICK, j, (LONG)&m_EventArray[j] );
  125. break;
  126. }
  127. }
  128. }
  129. void CEventWnd::OnDraw( CDC *pDC )
  130. {
  131. CRect rect;
  132. GetClientRect( &rect );
  133. pDC->FillSolidRect( &rect, RGB(0xaf,0xaf,0xaf) );
  134. for( int i = 0; i < m_EventArray.GetSize(); i ++ )
  135. {
  136. BOOL bImage = m_EventArray[i].image.nImageCount != 0;
  137. BYTE bRed = GetRValue(m_EventArray[i].color) / 2;
  138. BYTE bBlue = GetBValue(m_EventArray[i].color) / 2;
  139. BYTE bGreen = GetGValue(m_EventArray[i].color) / 2;
  140. COLORREF nColor = pDC->SetTextColor( RGB( bRed, bGreen, bBlue ) );
  141. // COLORREF nColor = pDC->SetTextColor( m_EventArray[i].color );
  142. INT nBkMode = pDC->SetBkMode( TRANSPARENT );
  143. CFont *pFont = pDC->SelectObject( &m_Font );
  144. CString str;
  145. GetEventString( &m_EventArray[i], str );
  146. INT nFontHeight = abs( m_pSensorArray->GetProgramSettings().LogFontReport.lfHeight );
  147. if( m_nActive == i )
  148. {
  149. CRect fillRect( 0, i * (nFontHeight + 2), rect.Width() - 1, (i+1)*(nFontHeight + 2) );
  150. pDC->FillSolidRect( &fillRect, RGB(0xBF,0xBF,0xBF) );
  151. CPen pen( PS_SOLID, 1, RGB(0,0,0) );
  152. CPen *pPen = pDC->SelectObject( &pen );
  153. pDC->MoveTo( fillRect.left, fillRect.top );
  154. pDC->LineTo( fillRect.right, fillRect.top );
  155. pDC->LineTo( fillRect.right, fillRect.bottom );
  156. pDC->LineTo( fillRect.left, fillRect.bottom );
  157. pDC->LineTo( fillRect.left, fillRect.top );
  158. pDC->SelectObject( pPen );
  159. }
  160. if( bImage )
  161. pDC->TextOut( 1, 1+i * (nFontHeight + 2), _T("*")+str );
  162. else
  163. pDC->TextOut( 1, 1+i * (nFontHeight + 2), _T(" ")+str );
  164. pDC->SelectObject( pFont );
  165. pDC->SetBkMode( nBkMode );
  166. pDC->SetTextColor( nColor );
  167. }
  168. }
  169. BOOL CEventWnd::SetActive( int nActive )
  170. {
  171. if( !m_EventArray.GetSize() )
  172. {
  173. m_nActive = 0;
  174. return FALSE;
  175. }
  176. if( nActive < 0 || nActive >= m_EventArray.GetSize() )
  177. return FALSE;
  178. m_nActive = nActive;
  179. InvalidateRect( NULL );
  180. return TRUE;
  181. }
  182. int CEventWnd::GetCountLines()
  183. {
  184. if( !GetSafeHwnd() )
  185. return 0;
  186. return m_EventArray.GetSize();
  187. }
  188. int CEventWnd::GetMaxLines()
  189. {
  190. if( !GetSafeHwnd() )
  191. return 0;
  192. CRect rect;
  193. GetClientRect( &rect );
  194. INT nFontHeight = abs( m_pSensorArray->GetProgramSettings().LogFontReport.lfHeight );
  195. return rect.Height() / (nFontHeight + 2);
  196. }
  197. UINT CEventWnd::OnGetDlgCode()
  198. {
  199. // TODO: Add your message handler code here and/or call default
  200. return DLGC_BUTTON | DLGC_WANTARROWS;//CWnd::OnGetDlgCode();
  201. }
  202. void CEventWnd::OnChangeSettings()
  203. {
  204. m_Font.DeleteObject();
  205. m_Font.CreateFontIndirect( &m_pSensorArray->GetProgramSettings().LogFontReport );
  206. InvalidateRect( NULL );
  207. }