// LogDlg.cpp : ʵÏÖÎļþ
|
//
|
|
#include "stdafx.h"
|
#include "Servo.h"
|
#include "PageLog.h"
|
#include "afxdialogex.h"
|
#include "Common.h"
|
#include <regex>
|
|
|
// CPageLog ¶Ô»°¿ò
|
|
IMPLEMENT_DYNAMIC(CPageLog, CDialogEx)
|
|
CPageLog::CPageLog(CWnd* pParent /*=NULL*/)
|
: CDialogEx(IDD_DIALOG_LOG, pParent)
|
{
|
m_crBkgnd = LOGDLG_BACKGROUND_COLOR;
|
m_hbrBkgnd = nullptr;
|
m_pObserver = nullptr;
|
m_nLevel = 0;
|
m_strIncludeText = _T("");
|
m_bIncludeRegex = FALSE;
|
}
|
|
CPageLog::~CPageLog()
|
{
|
}
|
|
void CPageLog::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
DDX_Control(pDX, IDC_BUTTON_LEVEL, m_btnLevel);
|
DDX_Control(pDX, IDC_BUTTON_INCLUDE, m_btnInclude);
|
DDX_Control(pDX, IDC_EDIT_LOG, m_logEdit);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CPageLog, CDialogEx)
|
ON_WM_CTLCOLOR()
|
ON_WM_SIZE()
|
ON_WM_DESTROY()
|
ON_WM_CLOSE()
|
ON_NOTIFY(BLBUTTON_MENU_ITEM_CLICKED, IDC_BUTTON_LEVEL, &CPageLog::OnButtonLevelMenuClicked)
|
ON_NOTIFY(BLBUTTON_MENU_ITEM_CLICKED, IDC_BUTTON_INCLUDE, &CPageLog::OnButtonIncludeMenuClicked)
|
ON_EN_CHANGE(IDC_EDIT_INCLUDE, &CPageLog::OnEnChangeEditInclude)
|
ON_BN_CLICKED(IDC_CHECK_REGEX, &CPageLog::OnBnClickedCheckRegex)
|
END_MESSAGE_MAP()
|
|
|
// CLogDlg ÏûÏ¢´¦Àí³ÌÐò
|
|
|
void CPageLog::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_LOG == code && ::IsWindow(m_hWnd)) {
|
const char* pszLogMsg;
|
int level;
|
if (pAny->getStringValue("text", pszLogMsg)
|
&& pAny->getIntValue("exCode", level)) {
|
if (level >= m_nLevel) {
|
CString strText = pszLogMsg;
|
BOOL bInclude = TRUE;
|
if (!m_strIncludeText.IsEmpty()) {
|
if (!m_bIncludeRegex) {
|
bInclude = (strText.Find(m_strIncludeText) >= 0);
|
}
|
else {
|
bInclude = std::regex_search((LPTSTR)(LPCTSTR)strText,
|
std::regex((LPTSTR)(LPCTSTR)m_strIncludeText));
|
}
|
}
|
|
|
if (bInclude) {
|
strText.Replace("\n", "\r\n");
|
AppendLog(level, (LPTSTR)(LPCTSTR)strText);
|
}
|
}
|
}
|
}
|
|
pAny->release();
|
}, [&]() -> void {
|
// onComplete
|
}, [&](IThrowable* pThrowable) -> void {
|
// onErrorm
|
pThrowable->printf();
|
});
|
theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread())
|
->subscribe(m_pObserver);
|
}
|
}
|
|
BOOL CPageLog::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
InitRxWindow();
|
|
|
// »º´æ
|
m_nLevel = theApp.m_model.m_configuration.getLogcatLevel();
|
theApp.m_model.m_configuration.getLogcatIncludeText(m_strIncludeText);
|
m_bIncludeRegex = theApp.m_model.m_configuration.isLogcatIncludeRegex();
|
theApp.m_model.m_configuration.getCustomLogcatIncludeTexts(m_customIncludeTexts);
|
|
|
// Level
|
HMENU hMenu = LoadMenu(AfxGetInstanceHandle(), MAKEINTRESOURCEA(IDR_MENU_LOGCAT_LEVEL));
|
m_btnLevel.SetMenu(hMenu);
|
m_btnLevel.SetCurrentMenuItem(m_nLevel);
|
m_btnLevel.SetBkgndColor(BS_NORMAL, RGB(241, 242, 244));
|
m_btnLevel.SetBkgndColor(BS_HOVER, RGB(220, 223, 228));
|
m_btnLevel.SetBkgndColor(BS_PRESS, RGB(179, 185, 196));
|
m_btnLevel.SetFrameColor(BS_NORMAL, RGB(133, 144, 162));
|
m_btnLevel.SetFrameColor(BS_HOVER, RGB(56, 139, 255));
|
m_btnLevel.SetFrameColor(BS_PRESS, RGB(56, 139, 255));
|
m_btnLevel.SetFrameColor(BS_FOCUS, RGB(56, 139, 255));
|
|
|
// °üº¬×Ö·û´®
|
CString strIcon1;
|
strIcon1.Format(_T("%s\\Res\\logcat_include.ico"), theApp.m_strAppDir);
|
HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
|
strIcon1, IMAGE_ICON, 24, 24,
|
LR_LOADFROMFILE | LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
|
m_btnInclude.SetIcon(hIcon, hIcon, 24);
|
|
{
|
HMENU hMenu = LoadMenu(AfxGetInstanceHandle(), MAKEINTRESOURCEA(IDR_MENU_INCLUDE));
|
HMENU hSubMenu = GetSubMenu(hMenu, 0);
|
DeleteMenu(hSubMenu, 0, MF_BYPOSITION);
|
int i = 0;
|
for (auto& item : m_customIncludeTexts) {
|
i++;
|
InsertMenu(hSubMenu, 0, MF_BYPOSITION, 0x1998 + i, item.c_str());
|
m_btnInclude.SetMenu(hMenu);
|
}
|
}
|
|
|
SetDlgItemText(IDC_EDIT_INCLUDE, m_strIncludeText);
|
CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_REGEX);
|
pCheckBox->SetCheck(m_bIncludeRegex ? BST_CHECKED : BST_UNCHECKED);
|
|
|
// ÄÚÈÝ
|
m_logEdit.SetMaxLineCount(500);
|
m_logEdit.SetLimitText(-1);
|
Resize();
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// Òì³£: OCX ÊôÐÔÒ³Ó¦·µ»Ø FALSE
|
}
|
|
void CPageLog::OnSize(UINT nType, int cx, int cy)
|
{
|
CDialogEx::OnSize(nType, cx, cy);
|
if (GetDlgItem(IDC_EDIT_LOG) == nullptr) return;
|
Resize();
|
}
|
|
void CPageLog::Resize()
|
{
|
int x, y, y2, temp;
|
CRect rcClient, rcItem;
|
CWnd* pItem;
|
GetClientRect(&rcClient);
|
|
y = 12;
|
x = 8;
|
pItem = GetDlgItem(IDC_BUTTON_LEVEL);
|
pItem->GetWindowRect(&rcItem);
|
ScreenToClient(&rcItem);
|
pItem->MoveWindow(x, y, rcItem.Width(), rcItem.Height());
|
x += rcItem.Width();
|
x += 18;
|
y2 = rcItem.bottom;
|
y2 += 8;
|
|
pItem = GetDlgItem(IDC_BUTTON_INCLUDE);
|
pItem->GetWindowRect(&rcItem);
|
pItem->MoveWindow(x, y, rcItem.Width(), rcItem.Height());
|
x += rcItem.Width();
|
x += 2;
|
|
pItem = GetDlgItem(IDC_EDIT_INCLUDE);
|
pItem->GetWindowRect(&rcItem);
|
pItem->MoveWindow(x, y, rcItem.Width(), rcItem.Height());
|
x += rcItem.Width();
|
x += 12;
|
temp = rcItem.Height();
|
|
pItem = GetDlgItem(IDC_CHECK_REGEX);
|
pItem->GetWindowRect(&rcItem);
|
pItem->MoveWindow(x, y + (temp - rcItem.Height()) / 2, rcItem.Width(), rcItem.Height());
|
|
x = 8;
|
pItem = GetDlgItem(IDC_EDIT_LOG);
|
pItem->MoveWindow(x, y2, rcClient.Width() - 16, rcClient.Height() - 5 - y2);
|
}
|
|
void CPageLog::OnDestroy()
|
{
|
CDialogEx::OnDestroy();
|
|
{
|
HMENU hMenu = m_btnLevel.GetMenu();
|
if (hMenu != NULL) {
|
::DestroyMenu(hMenu);
|
}
|
}
|
|
{
|
HMENU hMenu = m_btnInclude.GetMenu();
|
if (hMenu != NULL) {
|
::DestroyMenu(hMenu);
|
}
|
}
|
|
if (m_hbrBkgnd != nullptr) {
|
::DeleteObject(m_hbrBkgnd);
|
}
|
|
if (m_pObserver != NULL) {
|
m_pObserver->unsubscribe();
|
m_pObserver = NULL;
|
}
|
}
|
|
HBRUSH CPageLog::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 CPageLog::OnClose()
|
{
|
ShowWindow(SW_HIDE);
|
GetParent()->PostMessage(ID_MSG_LOGDLG_HIDE, 0, 0);
|
}
|
|
BOOL CPageLog::PreTranslateMessage(MSG* pMsg)
|
{
|
if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE) {
|
return TRUE;
|
}
|
|
return CDialogEx::PreTranslateMessage(pMsg);
|
}
|
|
void CPageLog::AppendLog(int level, const char* pszText)
|
{
|
if (!::IsWindow(m_logEdit.m_hWnd)) {
|
return;
|
}
|
m_logEdit.AppendText(pszText);
|
}
|
|
void CPageLog::OnButtonLevelMenuClicked(NMHDR* pNMHDR, LRESULT* pResult)
|
{
|
BLBUTTON_NMHDR* pblbNmhdr = reinterpret_cast<BLBUTTON_NMHDR*>(pNMHDR);
|
m_nLevel = (int)pblbNmhdr->dwData;
|
theApp.m_model.m_configuration.setLogcatLevel(m_nLevel);
|
m_btnLevel.SetCurrentMenuItem(m_nLevel);
|
|
*pResult = 0;
|
}
|
|
void CPageLog::OnButtonIncludeMenuClicked(NMHDR* pNMHDR, LRESULT* pResult)
|
{
|
BLBUTTON_NMHDR* pblbNmhdr = reinterpret_cast<BLBUTTON_NMHDR*>(pNMHDR);
|
int position = (int)pblbNmhdr->dwData;
|
std::string& strInclude = m_customIncludeTexts.at(position);
|
SetDlgItemText(IDC_EDIT_INCLUDE, strInclude.c_str());
|
CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_REGEX);
|
m_bIncludeRegex = FALSE;
|
pCheckBox->SetCheck(BST_UNCHECKED);
|
|
theApp.m_model.m_configuration.setLogcatIncludeRegex(m_bIncludeRegex);
|
theApp.m_model.m_configuration.setLogcatIncludeText(m_strIncludeText);
|
|
*pResult = 0;
|
}
|
|
void CPageLog::OnEnChangeEditInclude()
|
{
|
GetDlgItemText(IDC_EDIT_INCLUDE, m_strIncludeText);
|
theApp.m_model.m_configuration.setLogcatIncludeText(m_strIncludeText);
|
}
|
|
void CPageLog::OnBnClickedCheckRegex()
|
{
|
CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_REGEX);
|
m_bIncludeRegex = pCheckBox->GetCheck();
|
theApp.m_model.m_configuration.setLogcatIncludeRegex(m_bIncludeRegex);
|
}
|