mrDarker
2025-05-29 863f21995955fb3e9aa471430218967d4e642c27
SourceCode/Bond/Servo/PortConfigurationDlg.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,146 @@
// PortConfigurationDlg.cpp: å®žçŽ°æ–‡ä»¶
//
#include "stdafx.h"
#include "Servo.h"
#include "afxdialogex.h"
#include "PortConfigurationDlg.h"
#include "NewCellTypes/GridCellCheck.h"
#include "NewCellTypes/GridCellCombo.h"
#include "NewCellTypes/GridCellNumeric.h"
// CPortConfigurationDlg å¯¹è¯æ¡†
IMPLEMENT_DYNAMIC(CPortConfigurationDlg, CDialogEx)
CPortConfigurationDlg::CPortConfigurationDlg(CWnd* pParent /*=nullptr*/)
   : CDialogEx(IDD_DIALOG_PORT_CONFIGURATION, pParent)
{
}
CPortConfigurationDlg::~CPortConfigurationDlg()
{
}
void CPortConfigurationDlg::InitGrid()
{
    if (m_wndGrid.GetSafeHwnd() == NULL) {
        return;
    }
    const int nCols = 3;
    const int nFixRows = 1;
    const int nRows = 9;
    int nColIdx = 0;
    m_wndGrid.DeleteAllItems();
    m_wndGrid.SetVirtualMode(FALSE);
    // è®¾ç½®æ ·å¼é¢œè‰²
    m_wndGrid.GetDefaultCell(TRUE, FALSE)->SetBackClr(g_nGridFixCellColor);
    m_wndGrid.GetDefaultCell(FALSE, TRUE)->SetBackClr(g_nGridFixCellColor);
    m_wndGrid.GetDefaultCell(FALSE, FALSE)->SetBackClr(g_nGridCellColor);
    m_wndGrid.SetFixedTextColor(g_nGridFixFontColor);
    // è¡Œåˆ—数量
    m_wndGrid.SetRowCount(nRows);
    m_wndGrid.SetColumnCount(nCols);
    m_wndGrid.SetFixedRowCount(nFixRows);
    m_wndGrid.SetFixedColumnCount(0);
    // è®¾ç½®åˆ—宽
    m_wndGrid.SetColumnWidth(nColIdx, 50);
    m_wndGrid.SetItemText(0, nColIdx++, _T("Slot ID"));
    m_wndGrid.SetColumnWidth(nColIdx, 150);
    m_wndGrid.SetItemText(0, nColIdx++, _T("EQ Recipe"));
    m_wndGrid.SetColumnWidth(nColIdx, 150);
    m_wndGrid.SetItemText(0, nColIdx++, _T("Panel ID"));
    m_wndGrid.SetColumnWidth(nColIdx, 60);
    m_wndGrid.SetItemText(0, nColIdx++, _T("启用"));
    // è®¾ç½®è¡Œä¸ºæ ·å¼
    m_wndGrid.SetFixedRowSelection(FALSE);
    m_wndGrid.SetFixedColumnSelection(FALSE);
    m_wndGrid.SetEditable(TRUE);
    m_wndGrid.SetRowResize(FALSE);
    m_wndGrid.SetColumnResize(TRUE);
    m_wndGrid.SetListMode(TRUE);
    m_wndGrid.EnableSelection(TRUE);
    m_wndGrid.SetSingleRowSelection(TRUE);
    m_wndGrid.ExpandColumnsToFit(TRUE);
    m_wndGrid.ExpandLastColumn();
    // è‡ªåŠ¨è®¡ç®—å¹¶è®¾ç½®æ¯è¡Œé«˜åº¦
    CRect rcClient;
    m_wndGrid.GetClientRect(&rcClient);
    int nAvailableHeight = rcClient.Height();
    int nEachRowHeight = max(24, nAvailableHeight / nRows);
    for (int i = 0; i < nRows; ++i) {
        m_wndGrid.SetRowHeight(i, nEachRowHeight);
    }
    FillGrid();
}
void CPortConfigurationDlg::FillGrid()
{
    //CStringArray recipeOptions;
    //recipeOptions.Add(_T("Recipe A"));
    //recipeOptions.Add(_T("Recipe B"));
    //recipeOptions.Add(_T("Recipe C"));
    for (int i = 1; i < 9; ++i) {
        CString strIndex;
        strIndex.Format(_T("%d"), i);
        m_wndGrid.SetItemText(i, 0, strIndex);
        m_wndGrid.SetItemState(i, 0, GVIS_READONLY);
        // EQ Recipe - ComboBox
        //if (m_wndGrid.SetCellType(i, 1, RUNTIME_CLASS(CGridCellCombo))) {
        //    CGridCellCombo* pCell = static_cast<CGridCellCombo*>(m_wndGrid.GetCell(i, 1));
        //    pCell->SetOptions(recipeOptions);
        //    pCell->SetStyle(CBS_DROPDOWNLIST);
        //}
        //m_wndGrid.SetItemText(i, 1, recipeOptions[0]);
        // Panel ID - å¯ç¼–辑
        m_wndGrid.SetItemText(i, 1, _T(""));
        // Checkbox
        m_wndGrid.SetCellType(i, 2, RUNTIME_CLASS(CGridCellCheck));
        CGridCellCheck* pCheck = static_cast<CGridCellCheck*>(m_wndGrid.GetCell(i, 2));
        if (pCheck) {
            pCheck->SetCheck(FALSE);
        }
    }
    m_wndGrid.Invalidate();
    m_wndGrid.UpdateWindow();
}
void CPortConfigurationDlg::DoDataExchange(CDataExchange* pDX)
{
    DDX_Control(pDX, IDC_GRID_PANEL_RECIPE, m_wndGrid);
   CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CPortConfigurationDlg, CDialogEx)
END_MESSAGE_MAP()
// CPortConfigurationDlg æ¶ˆæ¯å¤„理程序
BOOL CPortConfigurationDlg::OnInitDialog()
{
   CDialogEx::OnInitDialog();
   // TODO:  åœ¨æ­¤æ·»åŠ é¢å¤–çš„åˆå§‹åŒ–
    InitGrid();
   return TRUE;  // return TRUE unless you set the focus to a control
   // å¼‚常: OCX å±žæ€§é¡µåº”返回 FALSE
}