From ba50ece48a4b95563031f1dacffd3e04f89d952f Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 21 八月 2025 05:25:41 +0800
Subject: [PATCH] 1.完善可折叠列表;

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

diff --git a/SourceCode/Bond/Servo/CExpandableListCtrl.h b/SourceCode/Bond/Servo/CExpandableListCtrl.h
new file mode 100644
index 0000000..57d606d
--- /dev/null
+++ b/SourceCode/Bond/Servo/CExpandableListCtrl.h
@@ -0,0 +1,58 @@
+#pragma once
+#include <vector>
+#include <memory>
+
+class CExpandableListCtrl : public CListCtrl
+{
+    DECLARE_DYNAMIC(CExpandableListCtrl)
+
+public:
+    struct Node {
+        Node* parent = nullptr;
+        std::vector<std::unique_ptr<Node>> children;
+        std::vector<CString> cols; // 各列文本
+        bool expanded = false;
+        int level = 0; // 缩进层级
+
+        Node(int nCols = 1) : cols(nCols) {}
+    };
+
+    CExpandableListCtrl();
+    virtual ~CExpandableListCtrl();
+
+    // 数据构建
+    Node* InsertRoot(const std::vector<CString>& cols);
+    Node* InsertChild(Node* parent, const std::vector<CString>& cols);
+
+    // 展开/折叠
+    void Expand(Node* n);
+    void Collapse(Node* n);
+    void Toggle(Node* n);
+
+    // 刷新可见列表
+    void RebuildVisible();
+
+    // 便捷:通过可见行号取 Node*
+    Node* GetNodeByVisibleIndex(int i) const;
+
+private:
+    void appendVisible(Node* n);
+    CRect expanderRectForRow(int row) const;        // 首列展开按钮区域
+    virtual void PreSubclassWindow();
+
+protected:
+    // 消息
+    afx_msg int  OnCreate(LPCREATESTRUCT lpCreateStruct);
+    afx_msg void OnClick(NMHDR* pNMHDR, LRESULT* pResult);
+    afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
+    DECLARE_MESSAGE_MAP()
+
+private:
+    std::vector<std::unique_ptr<Node>> m_roots;     // 顶层节点
+    std::vector<Node*>                 m_visible;   // 展开后的可见节点顺序
+    int  m_expanderPadding = 6;                     // 首列内侧边距
+    int  m_expanderSize = 10;                       // 小三角/方块大小
+    int  m_textGap = 6;
+};
+
+

--
Gitblit v1.9.3