From 5652c0bf59490f923e87b63251ad3f88b541636f Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 20 八月 2025 11:48:20 +0800
Subject: [PATCH] 1.能展开的ListCtrl, +号换为三角形;
---
SourceCode/Bond/Servo/CExpandableListCtrl.cpp | 86 +++++++++++++++++++++++++++---------------
1 files changed, 55 insertions(+), 31 deletions(-)
diff --git a/SourceCode/Bond/Servo/CExpandableListCtrl.cpp b/SourceCode/Bond/Servo/CExpandableListCtrl.cpp
index c15cf59..276e9a0 100644
--- a/SourceCode/Bond/Servo/CExpandableListCtrl.cpp
+++ b/SourceCode/Bond/Servo/CExpandableListCtrl.cpp
@@ -168,50 +168,74 @@
case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
{
- int row = (int)pCD->nmcd.dwItemSpec;
- int col = pCD->iSubItem;
+ const int row = (int)pCD->nmcd.dwItemSpec;
+ const int col = pCD->iSubItem;
CDC* pDC = CDC::FromHandle(pCD->nmcd.hdc);
- // 浠呭湪棣栧垪缁樺埗灞曞紑鎸夐挳涓庣缉杩涘紩瀵�
- if (col == 0) {
- CRect rc;
- GetSubItemRect(row, 0, LVIR_BOUNDS, rc);
-
- // 榛樿鏂囨湰璁╃郴缁熺敾锛氭垜浠厛鐢绘寜閽拰缂╄繘鑳屾櫙锛屽啀杩斿洖 CDRF_DODEFAULT
+ if (col == 0)
+ {
+ CRect rc; GetSubItemRect(row, 0, LVIR_BOUNDS, rc);
Node* n = GetNodeByVisibleIndex(row);
- if (n) {
- // 缁樺埗灞曞紑涓夎/鏂瑰潡
- if (!n->children.empty()) {
- CRect box = expanderRectForRow(row);
- // 灏忔柟妗�
- pDC->Rectangle(box);
+ if (!n) { *pResult = CDRF_DODEFAULT; return; }
- // 鐢烩��+鈥濇垨鈥�-鈥�
- CPen pen(PS_SOLID, 1, RGB(0, 0, 0));
- CPen* oldPen = pDC->SelectObject(&pen);
- // 妯嚎
- pDC->MoveTo(box.left + 2, box.CenterPoint().y);
- pDC->LineTo(box.right - 2, box.CenterPoint().y);
- if (!n->expanded) {
- // 绔栫嚎锛堣〃绀� + 鍙凤級
- pDC->MoveTo(box.CenterPoint().x, box.top + 2);
- pDC->LineTo(box.CenterPoint().x, box.bottom - 2);
- }
- pDC->SelectObject(oldPen);
+ // 1) 鑳屾櫙/鍓嶆櫙棰滆壊锛氭寜鏄惁閫変腑
+ const bool selected = (GetItemState(row, LVIS_SELECTED) & LVIS_SELECTED) != 0;
+ const bool focusOnCtrl = (GetSafeHwnd() == ::GetFocus());
+ COLORREF bk = selected ? GetSysColor(focusOnCtrl ? COLOR_HIGHLIGHT : COLOR_3DFACE)
+ : ListView_GetBkColor(m_hWnd);
+ COLORREF txt = selected ? GetSysColor(focusOnCtrl ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT)
+ : ListView_GetTextColor(m_hWnd);
+
+ // 浠呭湪闇�瑕佹椂濉厖鑳屾櫙锛堥伩鍏嶁�滈粦涓�鐗団�濓級
+ CBrush bkBrush(bk);
+ pDC->FillRect(rc, &bkBrush);
+
+ // 2) 灞曞紑/鎶樺彔鎸囩ず
+ if (!n->children.empty())
+ {
+ CRect box = expanderRectForRow(row);
+ // 鐢讳笁瑙掞紙鈻�/鈻硷級锛屽苟鎭㈠鐢荤瑪/鐢诲埛
+ HGDIOBJ oldPen = pDC->SelectObject(GetStockObject(BLACK_PEN));
+ HGDIOBJ oldBrush = pDC->SelectObject(GetStockObject(BLACK_BRUSH));
+ POINT tri[3];
+ if (n->expanded) { // 鈻�
+ tri[0] = { box.left + 2, box.top + 2 };
+ tri[1] = { box.right - 2, box.top + 2 };
+ tri[2] = { box.CenterPoint().x, box.bottom - 2 };
}
-
- // 鎶婃枃鏈乏杈圭晫鍙崇Щ锛岀暀鍑虹缉杩涗笌鎸夐挳绌洪棿
- // 杩欓噷涓嶆敼绯荤粺缁樺埗鐨勬枃鏈捣鐐癸紝鑰屾槸閫氳繃鍦ㄦ枃鏈墠缃┖鏍肩殑鏂瑰紡澶勭悊鏇寸畝鍗曪細
- // 鎴戜滑鐩存帴鏀规樉绀烘枃鏈紙鎬ц兘瓒冲锛夛細鍦� RebuildVisible 鏃跺凡缁忓~浜嗙函鏂囨湰銆�
- // 濡傛灉浣犺绮惧噯鎺у埗鏂囨湰浣嶇疆锛屽彲浠ユ敼 OWNERDRAW 鎴栬嚜缁樻枃鏈��
+ else { // 鈻�
+ tri[0] = { box.left + 2, box.top + 2 };
+ tri[1] = { box.right - 2, box.CenterPoint().y };
+ tri[2] = { box.left + 2, box.bottom - 2 };
+ }
+ pDC->Polygon(tri, 3);
+ pDC->SelectObject(oldPen);
+ pDC->SelectObject(oldBrush);
}
+
+ // 3) 鏂囨湰锛氬彸绉婚伩鍏嶉伄鎸�
+ const int indentPx = n->level * 16;
+ CRect textRc = rc;
+ textRc.left = rc.left + m_expanderPadding + indentPx + m_expanderSize + m_textGap;
+
+ pDC->SetBkMode(TRANSPARENT);
+ pDC->SetTextColor(txt);
+ CString txt0 = n->cols.empty() ? _T("") : n->cols[0];
+ pDC->DrawText(txt0, textRc, DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS);
+
+ // 棣栧垪鑷粯瀹屾瘯
+ *pResult = CDRF_SKIPDEFAULT;
+ return;
}
+ // 鍏朵粬鍒楅粯璁ょ粯鍒�
*pResult = CDRF_DODEFAULT;
return;
}
+
}
*pResult = CDRF_DODEFAULT;
}
+
--
Gitblit v1.9.3