From d64036c0510cf06009a7252e318d828fbc2658f0 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 11 九月 2025 09:22:02 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/CExpandableListCtrl.h | 67 ++++++++++++++++++++++-----------
1 files changed, 45 insertions(+), 22 deletions(-)
diff --git a/SourceCode/Bond/Servo/CExpandableListCtrl.h b/SourceCode/Bond/Servo/CExpandableListCtrl.h
index 57d606d..95c013a 100644
--- a/SourceCode/Bond/Servo/CExpandableListCtrl.h
+++ b/SourceCode/Bond/Servo/CExpandableListCtrl.h
@@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include <memory>
+#include <unordered_map>
class CExpandableListCtrl : public CListCtrl
{
@@ -13,39 +14,50 @@
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*
+ void Expand(Node* n);
+ void Collapse(Node* n);
+ void Toggle(Node* n);
+ void RebuildVisible();
Node* GetNodeByVisibleIndex(int i) const;
+
+ // ===== 行配色 API =====
+ // A) 按 Node* 着色(用于树/可折叠场景,索引变化不受影响)
+ void SetNodeColor(Node* n, COLORREF text, COLORREF bk);
+ void ClearNodeColor(Node* n);
+ void ClearAllColors();
+
+ // B) 兼容旧接口:按“可见行号”着色(与你当前页面代码一致)
+ void SetItemColor(DWORD_PTR iItem, COLORREF TextColor, COLORREF TextBkColor); // 兼容 ListCtrlEx
+ void SetItemColorByVisibleIndex(int row, COLORREF text, COLORREF bk); // 同上别名
+
+ // 选中行是否使用系统高亮(TRUE,默认);
+ // 若为 FALSE,则选中时仍显示自定义颜色
+ void SetPreserveSelectionHighlight(BOOL b) { m_preserveSelHighlight = b; }
+
+ // 清除树
+ void ClearTree();
+
+protected:
+ virtual void PreSubclassWindow();
+ afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+ afx_msg void OnClick(NMHDR* pNMHDR, LRESULT* pResult);
+ afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
+ virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) override;
+ DECLARE_MESSAGE_MAP()
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()
+ void computeColorsForRow(int row, COLORREF& outText, COLORREF& outBk) const;
private:
std::vector<std::unique_ptr<Node>> m_roots; // 顶层节点
@@ -53,6 +65,17 @@
int m_expanderPadding = 6; // 首列内侧边距
int m_expanderSize = 10; // 小三角/方块大小
int m_textGap = 6;
+
+ struct RowColor {
+ COLORREF text = CLR_DEFAULT;
+ COLORREF bk = CLR_DEFAULT;
+ bool hasText = false;
+ bool hasBk = false;
+ };
+
+ // 颜色(两路来源,优先级:Node* > 行号)
+ std::unordered_map<Node*, RowColor> m_colorByNode; // 树节点颜色
+ std::vector<RowColor> m_rowColors; // 按当前可见行号的颜色(兼容旧代码)
+
+ BOOL m_preserveSelHighlight = TRUE; // TRUE=选中时优先系统高亮
};
-
-
--
Gitblit v1.9.3