From 62bec5118f5e5fe750017cf2f12d4a428ab092df Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 17 九月 2025 18:06:30 +0800
Subject: [PATCH] 1.继续CControlJobManagerDlg的功能实现;
---
SourceCode/Bond/Servo/CCarrierSlotGrid.h | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 160 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/CCarrierSlotGrid.h b/SourceCode/Bond/Servo/CCarrierSlotGrid.h
new file mode 100644
index 0000000..73b1765
--- /dev/null
+++ b/SourceCode/Bond/Servo/CCarrierSlotGrid.h
@@ -0,0 +1,160 @@
+#include "stdafx.h"
+#pragma once
+
+#include <vector>
+
+#ifndef _AFX
+#include <afxwin.h>
+#endif
+
+class CCarrierSlotGrid : public CWnd
+{
+public:
+ enum MaterialType { MAT_G1 = 1, MAT_G2 = 2 };
+
+ struct SlotCell {
+ bool hasGlass = false;
+ CString coreId;
+ int material = MAT_G1;
+ bool checked = false;
+ };
+ struct PortColumn {
+ CString portName;
+ CString carrierName;
+ bool allocated = false;
+ CString allocatedBy;
+ std::vector<SlotCell> slots;
+ };
+
+public:
+ CCarrierSlotGrid();
+ virtual ~CCarrierSlotGrid();
+
+ BOOL SubclassDlgItem(UINT nID, CWnd* pParent) {
+ BOOL ok = CWnd::SubclassDlgItem(nID, pParent);
+ if (ok) {
+ if (pParent && pParent->GetFont()) SetFont(pParent->GetFont());
+ EnsureFonts();
+ Invalidate(FALSE);
+ }
+ return ok;
+ }
+ virtual void PreSubclassWindow() override;
+
+ // 初始化
+ void InitGrid(int nPorts, int nSlots);
+ void SetColumnWidths(int slotColWidth, int portColWidth);
+ void SetRowHeight(int cy);
+ void SetHeaderHeight(int cy);
+ void SetShowMaterialToggle(BOOL bShow);
+
+ // 读/写
+ int GetPortCount() const { return (int)m_ports.size(); }
+ int GetSlotCount() const { return m_nSlots; }
+
+ void SetPortInfo(int portIndex, LPCTSTR portName, LPCTSTR carrierName);
+ void SetPortAllocated(int portIndex, BOOL allocated, LPCTSTR byName = nullptr);
+ BOOL IsPortAllocated(int portIndex) const;
+
+ void SetSlotGlass(int portIndex, int slotIndex, BOOL hasGlass, LPCTSTR coreId, int material);
+ void SetSlotChecked(int portIndex, int slotIndex, BOOL checked);
+ BOOL GetSlotChecked(int portIndex, int slotIndex) const;
+
+ int GetSlotMaterialType(int portIndex, int slotIndex) const;
+ void SetSlotMaterialType(int portIndex, int slotIndex, int material, BOOL bNotify = TRUE);
+
+ CString GetDisplayId(int portIndex, int slotIndex) const;
+ void CheckAllInPort(int portIndex, BOOL checked, BOOL bNotify = TRUE);
+
+ void RebuildTexts();
+ void EnableColumnResize(BOOL enable) { m_bAllowResize = !!enable; Invalidate(FALSE); }
+
+ // 计算最佳大小:
+// - CalcBestClientSize:内容区域(不含滚动条/非客户区)刚好容纳表头+所有行、全部列
+// - CalcBestWindowSize:在当前窗口样式下,将“内容大小”转换为窗口外框大小(会考虑 WS_BORDER/CLIENTEDGE 等)
+// 默认按“隐藏滚动条”的目标来算(即不把 WS_HSCROLL/WS_VSCROLL 计入调整)
+ CSize CalcBestClientSize(int nSlotsOverride = -1) const;
+ CSize CalcBestWindowSize(BOOL includeNonClient = TRUE, int nSlotsOverride = -1) const;
+
+
+protected:
+ // 数据
+ int m_nSlots = 0;
+ std::vector<PortColumn> m_ports;
+ BOOL m_bShowMatToggle = TRUE;
+
+ // 尺寸/滚动
+ int m_rowHeight = 26;
+ int m_headerCY = 28;
+ int m_slotColCX = 100;
+ std::vector<int> m_portColCXs;
+ int m_scrollY = 0;
+ int m_scrollX = 0;
+ int m_slotColMin = 60;
+ int m_portColMin = 80;
+
+ // 颜色
+ COLORREF m_colBg = RGB(255, 255, 255);
+ COLORREF m_colAlt = RGB(240, 242, 245);
+ COLORREF m_colLock = RGB(255, 244, 214);
+ COLORREF m_gridMajor = RGB(210, 214, 220);
+ COLORREF m_gridMinor = RGB(220, 224, 230);
+ COLORREF m_text = RGB(40, 40, 40);
+ COLORREF m_textDim = RGB(150, 150, 150);
+
+ // 字体
+ CFont m_fntText;
+ CFont m_fntBold;
+ CFont m_fntSmall;
+
+ // 拖动列宽
+ bool m_bResizing = false;
+ int m_resizeEdge = -1; // 0=Slot|Port1;1..N-1=Port i|i+1
+ int m_resizeStartX = 0;
+ int m_slotColCXStart = 0;
+ std::vector<int> m_portColCXsStart;
+ int m_hitEdgeHover = -1;
+ bool m_bAllowResize = true; // ← 新增:是否允许拖动列宽
+
+ // 工具
+ void EnsureFonts();
+ void UpdateScrollRange();
+ int GetTotalContentWidth() const;
+ void NotifySelectionChanged(int port, int slot, BOOL checked);
+ void NotifyMaterialChanged(int port, int slot, int material);
+
+ // 几何
+ CRect GetClientRectNoSB() const;
+ BOOL GetCellRect(int row, int sub, CRect& rc) const; // sub: 0=Slot, 1..N=Port
+ CRect GetHeaderRect() const;
+ CRect GetHeaderItemRect(int iItem) const;
+ CRect GetHeaderCheckboxRect(int iItem) const;
+ CRect GetCheckboxRect(const CRect& cell) const;
+ CRect GetMaterialTagRect(const CRect& cell) const;
+ CRect GetStatusDotRect(const CRect& cell) const;
+ BOOL IsColumnResizeEnabled() const { return m_bAllowResize ? TRUE : FALSE; }
+
+ int HitHeaderEdge(CPoint pt) const;
+
+ // 绘制
+ void DrawFlatCheckbox(CDC* pDC, const CRect& r, bool checked, bool disabled);
+ void PaintTo(CDC* pDC);
+
+protected:
+ // 消息
+ afx_msg BOOL OnEraseBkgnd(CDC* pDC);
+ afx_msg void OnPaint();
+ afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+ afx_msg void OnSize(UINT nType, int cx, int cy);
+ afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
+ afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); // ★ 纵向滚动条
+ afx_msg void OnLButtonDown(UINT nFlags, CPoint pt);
+ afx_msg void OnLButtonUp(UINT nFlags, CPoint pt);
+ afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
+ afx_msg void OnMouseMove(UINT nFlags, CPoint pt);
+ afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
+ afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
+ afx_msg void OnWindowPosChanged(WINDOWPOS* wp);
+
+ DECLARE_MESSAGE_MAP()
+};
--
Gitblit v1.9.3