LAPTOP-SNT8I5JK\Boounion
2025-10-13 047c7cbd047e11fba8d7872e69a11a13e463aec4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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); // ½»ÌæÁÐdz»Ò
    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()
};