| | |
| | | #include "Servo.h" |
| | | #include "afxdialogex.h" |
| | | #include "PortConfigurationDlg.h" |
| | | #include "NewCellTypes/GridCellCheck.h" |
| | | #include "NewCellTypes/GridCellCombo.h" |
| | | #include "NewCellTypes/GridCellNumeric.h" |
| | | |
| | | |
| | | // CPortConfigurationDlg 对话框 |
| | |
| | | { |
| | | } |
| | | |
| | | void CPortConfigurationDlg::InitGrid() |
| | | { |
| | | if (m_wndGrid.GetSafeHwnd() == NULL) { |
| | | return; |
| | | } |
| | | |
| | | const int nCols = 4; |
| | | 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, 2, _T("")); |
| | | |
| | | // Checkbox |
| | | m_wndGrid.SetCellType(i, 3, RUNTIME_CLASS(CGridCellCheck)); |
| | | CGridCellCheck* pCheck = static_cast<CGridCellCheck*>(m_wndGrid.GetCell(i, 3)); |
| | | 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); |
| | | } |
| | | |
| | |
| | | CDialogEx::OnInitDialog(); |
| | | |
| | | // TODO: 在此添加额外的初始化 |
| | | // 绑定自定义控件(必须与资源中的 ID 一致) |
| | | m_wndGrid.SubclassDlgItem(IDC_GRID_PANEL_RECIPE, this); |
| | | |
| | | // 设置行列数 |
| | | m_wndGrid.SetRowCount(9); // 包括表头1行 + 数据8行 |
| | | m_wndGrid.SetColumnCount(4); |
| | | |
| | | // 设置固定的表头行 |
| | | m_wndGrid.SetFixedRowCount(1); |
| | | m_wndGrid.SetFixedColumnCount(0); |
| | | |
| | | // 设置列标题 |
| | | m_wndGrid.SetItemText(0, 0, _T("Slot ID")); |
| | | m_wndGrid.SetItemText(0, 1, _T("EQ Recipe")); |
| | | m_wndGrid.SetItemText(0, 2, _T("Panel ID")); |
| | | m_wndGrid.SetItemText(0, 3, _T("✓")); |
| | | |
| | | // 设置列宽 |
| | | m_wndGrid.SetColumnWidth(0, 60); |
| | | m_wndGrid.SetColumnWidth(1, 150); |
| | | m_wndGrid.SetColumnWidth(2, 150); |
| | | m_wndGrid.SetColumnWidth(3, 40); |
| | | |
| | | // 填充数据行 |
| | | for (int i = 1; i <= 8; ++i) |
| | | { |
| | | CString str; |
| | | str.Format(_T("%d"), i); |
| | | m_wndGrid.SetItemText(i, 0, str); |
| | | } |
| | | InitGrid(); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // 异常: OCX 属性页应返回 FALSE |