From e8a27bb203fe2aff70390a5eca002d7438da9b0f Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期三, 22 十月 2025 14:24:34 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang

---
 SourceCode/Bond/Servo/CCarrierSlotSelector.h |  122 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/CCarrierSlotSelector.h b/SourceCode/Bond/Servo/CCarrierSlotSelector.h
new file mode 100644
index 0000000..9ecbf97
--- /dev/null
+++ b/SourceCode/Bond/Servo/CCarrierSlotSelector.h
@@ -0,0 +1,122 @@
+#include "stdafx.h"
+#pragma once
+
+#include <vector>
+#include <string>
+
+#ifndef _AFX
+#include <afxwin.h>
+#include <afxcmn.h>
+#endif
+
+class CCarrierSlotSelector : public CListCtrl
+{
+public:
+    enum MaterialType { MAT_G1 = 1, MAT_G2 = 2 };
+
+    struct SlotCell
+    {
+        bool    hasGlass = false;   // 是否有片
+        CString coreId;             // 固定核心ID(不含前缀)
+        int     material = MAT_G1;  // 仅影响展示(G1/G2)
+        bool    checked = false;   // 是否勾选加工
+    };
+
+    struct PortColumn
+    {
+        CString               portName;     // "Port 1" ...
+        CString               carrierName;  // "Carrier A" ...
+        bool                  allocated = false; // 整列锁定
+        CString               allocatedBy;       // 占用者
+        std::vector<SlotCell> slots;             // size = m_nSlots
+    };
+
+public:
+    CCarrierSlotSelector();
+    virtual ~CCarrierSlotSelector();
+
+    // 初始化 / 尺寸
+    void    InitGrid(int nPorts, int nSlots);
+    void    SetColumnWidths(int slotColWidth, int portColWidth);
+    void    SetRowHeight(int cy); // small image list 控制行高
+
+    // 外观
+    void    SetShowMaterialToggle(BOOL bShow);
+    BOOL    GetShowMaterialToggle() const { return m_bShowMatToggle; }
+
+    // Port 接口
+    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;
+
+    // Slot 接口
+    void    SetSlotGlass(int portIndex, int slotIndex, BOOL hasGlass, LPCTSTR coreId /*可空*/, int material /*1=G1,2=G2*/);
+    void    SetSlotChecked(int portIndex, int slotIndex, BOOL checked);
+    BOOL    GetSlotChecked(int portIndex, int slotIndex) const;
+
+    int     GetSlotMaterialType(int portIndex, int slotIndex) const; // 1/2
+    void    SetSlotMaterialType(int portIndex, int slotIndex, int material, BOOL bNotify = TRUE);
+
+    CString GetDisplayId(int portIndex, int slotIndex) const; // "Gx-core" 或 "—"
+    void    RebuildTexts(); // 列头计数、单元格临时文本
+
+    // 工具:整列全选/全不选(只影响 hasGlass==true 的格子)
+    void    CheckAllInPort(int portIndex, BOOL checked, BOOL bNotify = TRUE);
+
+protected:
+    // 内部数据
+    BOOL                    m_bFirstShown = FALSE; // 子页面首次显示后强制一次全量重绘
+    int                     m_nSlots = 0;
+    std::vector<PortColumn> m_ports;
+    BOOL                    m_bShowMatToggle = TRUE;
+
+    // UI metrics
+    int     m_rowHeight = 24;
+    int     m_slotColWidth = 100;
+    int     m_portColWidth = 180;
+
+    // 行高图像列表
+    CImageList m_ilRowHeight;
+
+    // 颜色
+    COLORREF m_colBgAlt = RGB(240, 242, 245); // 交替列浅灰
+    COLORREF m_colBgNorm = RGB(255, 255, 255);
+    COLORREF m_colLockBg = RGB(255, 244, 214); // 锁定列淡黄
+
+    // 字体
+    CFont   m_fntText;
+    CFont   m_fntBold;
+    CFont   m_fntSmall;
+
+    // 区域计算
+    CRect   GetCheckboxRect(const CRect& cell) const;
+    CRect   GetMaterialTagRect(const CRect& cell) const;
+    CRect   GetStatusDotRect(const CRect& cell) const;
+
+    // 工具
+    void    EnsureFonts();
+    void    UpdateRowCount();
+    void    DrawFlatCheckbox(CDC* pDC, const CRect& r, bool checked, bool disabled); // 扁平复选框
+
+    // 通知父窗口(WM_COMMAND 风格)
+    void    NotifySelectionChanged(int port, int slot, BOOL checked);
+    void    NotifyMaterialChanged(int port, int slot, int material);
+
+protected:
+    // MFC
+    virtual void PreSubclassWindow() override;
+    afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
+    afx_msg void OnWindowPosChanged(WINDOWPOS* lpwndpos);
+    afx_msg void OnSize(UINT nType, int cx, int cy);
+    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
+    afx_msg void OnPaint();                // ★ 新增:自带双缓冲绘制
+    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
+    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
+    afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
+    afx_msg BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); // 捕获 Header 通知
+    void    OnHeaderClick(int iItem);
+
+    DECLARE_MESSAGE_MAP()
+};

--
Gitblit v1.9.3