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.

237 lines
7.1 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: ToolBarDlg.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of ToolBarDlg.cpp
  13. //----------------------------------------------------------------------------
  14. // ToolBarDlg.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "chicago.h"
  18. #include "ToolBarDlg.h"
  19. #include "..\..\LgLib\Version.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CToolBarDlg dialog
  27. static TBBUTTON stbButtons[] =
  28. {
  29. { 0, IDM_SYSTEM_RESET, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"Reset program", 0 }
  30. // ,{ 1, IDM_SYSTEM_ENABLE, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"Enable zone/devise/sensor", 1 }
  31. // ,{ 2, IDM_VIEW_MAIN, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"View main screen", 2 }
  32. // ,{ 3, IDM_VIEW_DETAIL, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"View detail screen", 3 }
  33. // ,{ 4, IDM_VIEW_OPTIONS, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"Change zoom factor", 4 }
  34. // ,{ 5, IDM_SUPPORT_DATETIME, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"Change date/time", 5 }
  35. // ,{ 6, IDM_SUPPORT_GUARD, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"Change guard", 6 }
  36. ,{ 7, IDM_SUPPORT_MUTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"Mute sound", 7 }
  37. ,{ 8, IDM_SUPPORT_REPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"History/report", 8 }
  38. // ,{ 9, IDM_SUPPORT_SOUND, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"Enable/disable zone sound", 9 }
  39. // ,{ 10, IDM_SUPPORT_STATISTIC, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"Show statistic", 10 }
  40. // ,{ 11, IDM_SYSTEM_EXIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, { 0, 0 }, (DWORD)"Exit", 11 }
  41. };
  42. CToolBarDlg::CToolBarDlg(CWnd* pParent /*=NULL*/)
  43. : CDialog(CToolBarDlg::IDD, pParent)
  44. {
  45. //{{AFX_DATA_INIT(CToolBarDlg)
  46. // NOTE: the ClassWizard will add member initialization here
  47. //}}AFX_DATA_INIT
  48. m_nButtonCount = sizeof(stbButtons)/sizeof(stbButtons[0]);
  49. m_pButton = new TBBUTTON[ m_nButtonCount ];
  50. for( int i = 0; i < m_nButtonCount; i++ )
  51. {
  52. m_pButton[i].idCommand = stbButtons[i].idCommand;
  53. m_pButton[i].iBitmap = stbButtons[i].iBitmap;
  54. m_pButton[i].iString = stbButtons[i].iString;
  55. m_pButton[i].fsState = stbButtons[i].fsState;
  56. m_pButton[i].fsStyle = stbButtons[i].fsStyle;
  57. m_pButton[i].dwData = stbButtons[i].dwData;
  58. // m_pButton[i].bReserved = tbButtons[i].bReserved;
  59. }
  60. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CToolBarDlg::CToolBarDlg") );
  61. }
  62. void CToolBarDlg::DoDataExchange(CDataExchange* pDX)
  63. {
  64. CDialog::DoDataExchange(pDX);
  65. //{{AFX_DATA_MAP(CToolBarDlg)
  66. DDX_Control(pDX, IDC_STATIC_MODE, m_StaticMode);
  67. //}}AFX_DATA_MAP
  68. }
  69. BEGIN_MESSAGE_MAP(CToolBarDlg, CDialog)
  70. //{{AFX_MSG_MAP(CToolBarDlg)
  71. ON_WM_DESTROY()
  72. ON_WM_SIZE()
  73. ON_WM_MOVE()
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. //static const int seqTableCount = sizeof(seqTable) / sizeof( seqTable[0] );
  77. BOOL CToolBarDlg::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  78. {
  79. return FALSE;
  80. TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  81. if( (pTTT->hdr.code == TTN_NEEDTEXT) )//&& ( pTTT->uFlags & 0x40 ) )
  82. {
  83. int uId = pNMHDR->idFrom;
  84. for( int i = 0; i < m_nButtonCount; i++ )
  85. if( m_pButton[i].idCommand == uId )
  86. {
  87. pTTT->lpszText = (LPSTR)m_pButton[i].dwData;//tbToolTips[i];
  88. pTTT->hinst = NULL;
  89. return TRUE;
  90. }
  91. }
  92. return FALSE;
  93. }
  94. void CToolBarDlg::CreateButtons( CMenu *pMenu )
  95. {
  96. for( unsigned int i = 0; i < pMenu->GetMenuItemCount(); i++ )
  97. {
  98. CHAR pBuffer[100];
  99. MENUITEMINFO mii;
  100. mii.cbSize = sizeof(MENUITEMINFO);
  101. mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_SUBMENU;
  102. mii.cch = 100;
  103. mii.dwTypeData = pBuffer;
  104. pMenu->GetMenuItemInfo( i, &mii, TRUE );
  105. if( mii.hSubMenu )
  106. CreateButtons( pMenu->GetSubMenu(i) );
  107. else
  108. if( mii.fType==MFT_STRING && mii.hSubMenu==NULL )
  109. {
  110. for( int j = 0; j < m_nButtonCount; j++ )
  111. {
  112. if( LOWORD(m_pButton[j].idCommand) == LOWORD(mii.wID) )
  113. {
  114. m_ToolBarCtrl.AddButtons( 1, &m_pButton[j] );
  115. break;
  116. }
  117. }
  118. }
  119. }
  120. }
  121. BOOL CToolBarDlg::Create( UINT nIDTemplate, CWnd* pParentWnd, CMenu *pMenu )
  122. {
  123. CSize size( 60, 30 );
  124. m_Size.cx = size.cx + ::GetSystemMetrics( SM_CXEDGE ) * 3 ;
  125. m_Size.cy = size.cy + ::GetSystemMetrics( SM_CYEDGE ) * 3;
  126. if( CDialog::Create(IDD, pParentWnd) )
  127. {
  128. SetWindowLong( GetSafeHwnd(), GWL_STYLE, GetWindowLong( GetSafeHwnd(), GWL_STYLE ) | WS_DLGFRAME | WS_CLIPSIBLINGS );
  129. CRect rect( 0, 0, GetSystemMetrics(SM_CXSCREEN), m_Size.cy );
  130. m_ToolBarCtrl.Create( CBRS_TOOLTIPS | TBSTYLE_TOOLTIPS | TBSTYLE_WRAPABLE /* | CCS_NORESIZE*/ | CCS_NODIVIDER | WS_CHILD | WS_VISIBLE, rect, this, 0 );
  131. m_ToolBarCtrl.SetBitmapSize( size );
  132. m_ToolBarCtrl.AddBitmap( m_nButtonCount, IDB_BITMAP_TOOLBAR );
  133. m_ToolBarCtrl.SetButtonSize( m_Size );
  134. CreateButtons( pMenu );
  135. m_ToolBarCtrl.AutoSize();
  136. CRect r( 0, 0, m_Size.cx * m_ToolBarCtrl.GetButtonCount() + ::GetSystemMetrics( SM_CXEDGE ) * 3, m_Size.cy );
  137. m_ToolBarCtrl.MoveWindow( &r );
  138. m_StaticMode.ShowWindow( SW_HIDE );
  139. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CToolBarDlg::Create"), _T("Succeeded") );
  140. return TRUE;
  141. }
  142. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CToolBarDlg::Create"), _T("CDialog::Create failed") );
  143. return FALSE;
  144. }
  145. BOOL CToolBarDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  146. {
  147. return GetParent()->SendMessage( WM_COMMAND, wParam, lParam );
  148. }
  149. void CToolBarDlg::OnDestroy()
  150. {
  151. CDialog::OnDestroy();
  152. if( m_pButton )
  153. delete [] m_pButton;
  154. }
  155. BOOL CToolBarDlg::PreTranslateMessage(MSG* pMsg)
  156. {
  157. switch( pMsg->message )
  158. {
  159. case WM_KEYDOWN:
  160. case WM_SYSKEYDOWN:
  161. return GetParent()->PreTranslateMessage( pMsg );
  162. }
  163. return CDialog::PreTranslateMessage(pMsg);
  164. }
  165. int CToolBarDlg::GetHeight()
  166. {
  167. return m_Size.cy;
  168. }
  169. void CToolBarDlg::OnSize(UINT nType, int cx, int cy)
  170. {
  171. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CToolBarDlg::OnSize"), _T("Started...") );
  172. CDialog::OnSize(nType, cx, cy);
  173. /*
  174. if( m_StaticMode.GetSafeHwnd() )
  175. {
  176. CRect r;
  177. GetClientRect( &r );
  178. r.right -= 10;
  179. r.left += m_Size.cx * m_ToolBarCtrl.GetButtonCount() + ::GetSystemMetrics( SM_CXEDGE ) * 3;
  180. m_StaticMode.MoveWindow( &r );
  181. }
  182. */
  183. if( m_ToolBarCtrl.GetSafeHwnd() )
  184. {
  185. m_ToolBarCtrl.MoveWindow( 0, 0, cx, cy );
  186. m_ToolBarCtrl.AutoSize();
  187. }
  188. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CToolBarDlg::OnSize"), _T("Done") );
  189. }
  190. void CToolBarDlg::SetModeText(LPCTSTR pStr)
  191. {
  192. m_StaticMode.SetWindowText( pStr );
  193. }
  194. BOOL CToolBarDlg::EnableButton( INT nID, BOOL bEnable )
  195. {
  196. return m_ToolBarCtrl.EnableButton( nID, bEnable );
  197. }
  198. void CToolBarDlg::OnMove(int x, int y)
  199. {
  200. CDialog::OnMove( x, y );
  201. // MoveWindow( x+1, y, 90, 30 );
  202. }