// PageAlarm.cpp : ʵÏÖÎļþ // #include "stdafx.h" #include "BondEq.h" #include "CPageAlarm.h" #include "afxdialogex.h" #include "Common.h" #include "ToolUnits.h" // CPageAlarm ¶Ô»°¿ò IMPLEMENT_DYNAMIC(CPageAlarm, CDialogEx) CPageAlarm::CPageAlarm(CWnd* pParent /*=NULL*/) : CDialogEx(IDD_PAGE_ALARM, pParent) { m_crBkgnd = PAGE_BACKGROUND_COLOR; m_hbrBkgnd = nullptr; m_pObserver = nullptr; } CPageAlarm::~CPageAlarm() { } void CPageAlarm::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CPageAlarm, CDialogEx) ON_WM_CTLCOLOR() ON_WM_DESTROY() ON_WM_SIZE() END_MESSAGE_MAP() // CPageAlarm ÏûÏ¢´¦Àí³ÌÐò void CPageAlarm::InitRxWindow() { /* code */ // ¶©ÔÄÊý¾Ý IRxWindows* pRxWindows = RX_GetRxWindows(); pRxWindows->enableLog(5); if (m_pObserver == NULL) { m_pObserver = pRxWindows->allocObserver([&](IAny* pAny) -> void { // onNext pAny->addRef(); int code = pAny->getCode(); if (RX_CODE_ALARM_ON == code) { CAlarm* pAlarm; if (pAny->getObject("obj", (IRxObject*&)pAlarm)) { AddAlarm(nullptr, pAlarm); } } else if (RX_CODE_ALARM_OFF == code) { CAlarm* pAlarm; if (pAny->getObject("obj", (IRxObject*&)pAlarm)) { UpdateAlarm(nullptr, pAlarm); } } pAny->release(); }, [&]() -> void { // onComplete }, [&](IThrowable* pThrowable) -> void { // onErrorm pThrowable->printf(); }); theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread()) ->subscribe(m_pObserver); } } BOOL CPageAlarm::OnInitDialog() { CDialogEx::OnInitDialog(); InitRxWindow(); // ±¨±í¿Ø¼þ CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); DWORD dwStyle = pListCtrl->GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT; dwStyle |= LVS_EX_GRIDLINES; pListCtrl->SetExtendedStyle(dwStyle); HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1); ListView_SetImageList(pListCtrl->GetSafeHwnd(), imageList, LVSIL_SMALL); pListCtrl->InsertColumn(0, _T(""), LVCFMT_RIGHT, 0); pListCtrl->InsertColumn(2, _T("¾¯¸æID"), LVCFMT_LEFT, 100); pListCtrl->InsertColumn(3, _T("ÃèÊö"), LVCFMT_LEFT, 580); pListCtrl->InsertColumn(4, _T("·¢Éúʱ¼ä"), LVCFMT_LEFT, 180); pListCtrl->InsertColumn(5, _T("½â³ýʱ¼ä"), LVCFMT_LEFT, 180); Resize(); LoadAlarms(); return TRUE; // return TRUE unless you set the focus to a control // Òì³£: OCX ÊôÐÔÒ³Ó¦·µ»Ø FALSE } HBRUSH CPageAlarm::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC) { pDC->SetBkColor(m_crBkgnd); } if (m_hbrBkgnd == nullptr) { m_hbrBkgnd = CreateSolidBrush(m_crBkgnd); } return m_hbrBkgnd; } void CPageAlarm::OnDestroy() { CDialogEx::OnDestroy(); if (m_hbrBkgnd != nullptr) { ::DeleteObject(m_hbrBkgnd); } if (m_pObserver != NULL) { m_pObserver->unsubscribe(); m_pObserver = NULL; } } void CPageAlarm::OnSize(UINT nType, int cx, int cy) { CDialogEx::OnSize(nType, cx, cy); if (GetDlgItem(IDC_LIST_ALARM) == nullptr) return; Resize(); } void CPageAlarm::Resize() { CWnd* pItem; CRect rcClient; GetClientRect(&rcClient); pItem = GetDlgItem(IDC_LIST_ALARM); pItem->MoveWindow(12, 12, rcClient.Width() - 24, rcClient.Height() - 24); } void CPageAlarm::LoadAlarms() { CAlarmMonitor* pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("¾¯¸æÐÅÏ¢"); pMonitor->Lock(); std::map& alarmings = pMonitor->getAlarmingMap(); std::list< CAlarm*>& alarms = pMonitor->getAlarmRecords(); for (auto item : alarmings) { AddAlarm(pMonitor, item.second); } for (auto item : alarms) { AddAlarm(pMonitor, item); } pMonitor->Unlock(); } void CPageAlarm::AddAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm) { if (pMonitor == nullptr) { pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("¾¯¸æÐÅÏ¢"); } CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); pListCtrl->InsertItem(0, _T("")); pListCtrl->SetItemData(0, (DWORD_PTR)pAlarm); pAlarm->addRef(); pListCtrl->SetItemText(0, 1, std::to_string(pAlarm->getId()).c_str()); pListCtrl->SetItemText(0, 2, pMonitor->getAlarmText(pAlarm->getId())); pListCtrl->SetItemText(0, 3, CToolUnits::timeToString2(pAlarm->getOnTime()).c_str()); if (pAlarm->getOffTime() > 0) { pListCtrl->SetItemText(0, 4, CToolUnits::timeToString2(pAlarm->getOffTime()).c_str()); } } void CPageAlarm::UpdateAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm) { if (pMonitor == nullptr) { pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent("¾¯¸æÐÅÏ¢"); } CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); for (int i = 0; i < pListCtrl->GetItemCount(); i++) { if (pListCtrl->GetItemData(i) == (DWORD_PTR)pAlarm) { if (pAlarm->getOffTime() > 0) { pListCtrl->SetItemText(i, 4, CToolUnits::timeToString2(pAlarm->getOffTime()).c_str()); } } } } BOOL CPageAlarm::DestroyWindow() { CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); for (int i = 0; i < pListCtrl->GetItemCount(); i++) { CAlarm* pAlarm = (CAlarm*)pListCtrl->GetItemData(i); pAlarm->release(); } return CDialogEx::DestroyWindow(); }