中间件标准版5.1git,去除基础模块

ViewLine.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // ViewLine.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "VoiceStation.h"
  5. #include "ViewLine.h"
  6. #include "Line.h"
  7. #include "DeviceMgr.h"
  8. #include "DisplayWnd.h"
  9. // CViewLine
  10. IMPLEMENT_DYNAMIC(CViewLine, CListCtrl)
  11. CViewLine::CViewLine(void)
  12. {
  13. }
  14. CViewLine::~CViewLine(void)
  15. {
  16. }
  17. /*****************************************************************
  18. **【函数名称】 __transType2String
  19. **【函数功能】 转换线路类型为字符串
  20. **【参数】
  21. **【返回值】
  22. ****************************************************************/
  23. LPCTSTR CViewLine::__transType2String( UINT Type )
  24. {
  25. switch(Type)
  26. {
  27. case DEV_VS_TYPE_AUDIO: return _T("模拟放音");
  28. case DEV_VS_TYPE_RECANA: return _T("模拟录音");
  29. case DEV_VS_TYPE_RECDIG: return _T("数字录音");
  30. case DEV_VS_TYPE_RECIPRR: return _T("IP录音");
  31. default: return _T("未知类型");
  32. }
  33. }
  34. /*****************************************************************
  35. **【函数名称】 __indexItem
  36. **【函数功能】 索引资源
  37. **【参数】
  38. **【返回值】
  39. ****************************************************************/
  40. int CViewLine::__indexItem( UINT ResId )
  41. {
  42. int Count = GetItemCount();
  43. for (int i=0; i < Count; ++i)
  44. {
  45. if (GetItemData(i) == ResId)
  46. return i;
  47. }
  48. return -1;
  49. }
  50. /*****************************************************************
  51. **【函数名称】 __addRes
  52. **【函数功能】 向List中添加资源
  53. **【参数】
  54. **【返回值】
  55. ****************************************************************/
  56. int CViewLine::__addRes( UINT ResId )
  57. {
  58. int Index = GetItemCount();
  59. CString strResID;
  60. strResID.Format(_T("%d"), ResId);
  61. Index = InsertItem(Index, strResID);
  62. SetItemData(Index, ResId);
  63. return Index;
  64. }
  65. /*****************************************************************
  66. **【函数名称】 __delRes
  67. **【函数功能】 删除资源
  68. **【参数】
  69. **【返回值】
  70. ****************************************************************/
  71. void CViewLine::__delRes( UINT ResId )
  72. {
  73. int Index = __indexItem(ResId);
  74. if (Index != -1)
  75. {
  76. // 界面删除行
  77. DeleteItem(Index);
  78. }
  79. }
  80. /*****************************************************************
  81. **【函数名称】 create
  82. **【函数功能】 控件初始化
  83. **【参数】
  84. **【返回值】
  85. ****************************************************************/
  86. bool CViewLine::create( CDisplayWnd* pWnd )
  87. {
  88. ASSERT(pWnd != NULL);
  89. CString Name;
  90. Name.LoadString(IDS_STR_VIEW_LINE);
  91. // 创建pane
  92. if (!m_Pane.Create(Name, pWnd, CRect(0, 0, 400, 400), TRUE, IDS_STR_VIEW_LINE,
  93. WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_TOP | CBRS_FLOAT_MULTI))
  94. {
  95. TRACE0("创建设备资源窗口失败");
  96. return false;
  97. }
  98. m_Pane.EnableDocking(CBRS_ALIGN_ANY);
  99. //创建控件
  100. if(!Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | LVS_REPORT | LVS_SORTASCENDING,
  101. CRect(0, 0, 0, 0), &m_Pane, IDC_LIST_LINE))
  102. {
  103. TRACE0("创建设备资源控件失败\n");
  104. return false;
  105. }
  106. SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  107. InsertColumn(COLUMN_RES_ID, _T("线路ID"), LVCFMT_LEFT, 140);
  108. InsertColumn(COLUMN_RES_IPO_ID, _T("匹配ID"), LVCFMT_LEFT, 140);
  109. InsertColumn(COLUMN_RES_TYPE, _T("类型"), LVCFMT_LEFT, 140);
  110. InsertColumn(COLUMN_RES_STATE, _T("状态"), LVCFMT_LEFT, 140);
  111. pWnd->OnNewPane(&m_Pane);
  112. return true;
  113. }
  114. /*****************************************************************
  115. **【函数名称】 onLineStateUpdated
  116. **【函数功能】 线路状态更新处理函数
  117. **【参数】
  118. **【返回值】
  119. ****************************************************************/
  120. void CViewLine::onLineStateUpdated( int LineId )
  121. {
  122. CLine* pLine = CDeviceMgr::GetInstance().findLineByID(LineId);
  123. ASSERT(pLine != NULL);
  124. if(pLine == NULL)
  125. return;
  126. int Index = __indexItem(LineId);
  127. if (Index == -1) // 未找到对应线路,则先创建
  128. Index = __addRes(LineId); // 创建线路
  129. ASSERT(Index != -1);
  130. CString Data;
  131. Data.Format(_T("%d"), pLine->assoIpoId());
  132. SetItemText(Index, COLUMN_RES_IPO_ID, Data);
  133. Data = __transType2String(pLine->type());
  134. SetItemText(Index, COLUMN_RES_TYPE, Data);
  135. Data = pLine->getState();
  136. SetItemText(Index, COLUMN_RES_STATE, Data);
  137. }
  138. /*****************************************************************
  139. **【函数名称】 newSize
  140. **【函数功能】 调整控件大小
  141. **【参数】
  142. **【返回值】
  143. ****************************************************************/
  144. void CViewLine::newSize( CRect& Rect )
  145. {
  146. if(IsWindow(GetSafeHwnd()))
  147. SetWindowPos(NULL, Rect.left, Rect.top, Rect.Width(), Rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
  148. }
  149. BEGIN_MESSAGE_MAP(CViewLine, CListCtrl)
  150. END_MESSAGE_MAP()
  151. // CViewLine 消息处理程序