From e1b3d7a8705086ae67e46e872d517c13816bbfa9 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 20 八月 2025 12:27:53 +0800
Subject: [PATCH] 1.修改展开按钮为三角形;

---
 SourceCode/Bond/Servo/CExpandableListCtrl.cpp |  105 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 77 insertions(+), 28 deletions(-)

diff --git a/SourceCode/Bond/Servo/CExpandableListCtrl.cpp b/SourceCode/Bond/Servo/CExpandableListCtrl.cpp
index 276e9a0..00bdf28 100644
--- a/SourceCode/Bond/Servo/CExpandableListCtrl.cpp
+++ b/SourceCode/Bond/Servo/CExpandableListCtrl.cpp
@@ -119,20 +119,25 @@
 
 CRect CExpandableListCtrl::expanderRectForRow(int row) const
 {
-    CRect rc;
-    // 鍙栭鍒楃煩褰�
-    if (!GetSubItemRect(row, 0, LVIR_BOUNDS, rc))
+    CRect rcLabel;
+    if (!const_cast<CExpandableListCtrl*>(this)->GetSubItemRect(row, 0, LVIR_LABEL, rcLabel))
         return CRect(0, 0, 0, 0);
 
     Node* n = const_cast<CExpandableListCtrl*>(this)->GetNodeByVisibleIndex(row);
-    int indent = (n ? n->level : 0);
+    if (!n || n->children.empty())
+        return CRect(0, 0, 0, 0); // 鍙跺瓙涓嶅崰浣嶏紝鏂囨湰灏变笉浼氳澶氭帹涓�鏍�
 
-    // 缂╄繘锛氭瘡绾х粰 16px
-    int left = rc.left + m_expanderPadding + indent * 16;
-    CRect box(left, rc.CenterPoint().y - m_expanderSize / 2,
-        left + m_expanderSize, rc.CenterPoint().y + m_expanderSize / 2);
-    return box;
+    const int indent = n->level;
+    const int left = rcLabel.left + m_expanderPadding + indent * 16;
+
+    return CRect(
+        left,
+        rcLabel.CenterPoint().y - m_expanderSize / 2,
+        left + m_expanderSize,
+        rcLabel.CenterPoint().y + m_expanderSize / 2
+    );
 }
+
 
 void CExpandableListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
 {
@@ -174,7 +179,7 @@
 
         if (col == 0)
         {
-            CRect rc; GetSubItemRect(row, 0, LVIR_BOUNDS, rc);
+            CRect rc; GetSubItemRect(row, 0, LVIR_LABEL, rc);
             Node* n = GetNodeByVisibleIndex(row);
             if (!n) { *pResult = CDRF_DODEFAULT; return; }
 
@@ -190,40 +195,84 @@
             CBrush bkBrush(bk);
             pDC->FillRect(rc, &bkBrush);
 
-            // 2) 灞曞紑/鎶樺彔鎸囩ず
+            // 2) 灞曞紑/鎶樺彔鎸囩ず锛堝弬鑰冩棫椤圭洰鐨勫彸瀵归綈鍧愭爣娉曪紝鍋氬儚绱犲榻愶紝绾疓DI锛�
             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 };
+
+                // ---- 鍙皟鍙傛暟锛氫笌鏃т唬鐮佸懡鍚嶄竴鑷� ----
+                // 鍙充晶鐣欑櫧锛堜笌鏂囨湰闂撮殭/缃戞牸绾夸繚鎸佽窛绂伙級
+                const int ROFFSET = 2;
+                // 闂悎/灞曞紑鐨勨�滃搴︹�濊缃細濂囨暟鏇撮『鐪硷紙9/11 閮借锛�
+                const int WIDE = max(9, min(min(box.Width(), box.Height()), 13)); // 鈻� 鐨勮竟闀�
+                const int WIDE2 = WIDE / 2;                                        // 涓�鍗�
+                const int EXPANDED_WIDE = WIDE;                                           // 鈻� 鐨勮竟闀�
+
+                // 杞诲井鍐呯缉锛岄伩鍏嶈创杈癸紙涓庝綘鏃т唬鐮佲�滄寜閽鍒蜂竴涓嬧�濆悓鏁堬級
+                box.DeflateRect(1, 1);
+
+                // 缁熶竴鍋氬伓鏁板榻愶紝鍑忓皯鍗婂儚绱犻敮榻�
+                auto even = [](int v) { return (v & 1) ? (v - 1) : v; };
+
+                // 璁$畻鈥滆嚜涓嬪悜涓娾�濈殑鍩哄噯鍋忕Щ锛屼笌鏃� TreeCtrl 涓�鑷�
+                // 杩欓噷鐢� box 浣滀负 pRect
+                POINT pt[3];
+                if (n->expanded) {
+                    // 鈻�
+                    int nBottomOffset = (box.Height() - EXPANDED_WIDE) / 2;
+                    pt[0].x = box.right - ROFFSET - EXPANDED_WIDE;
+                    pt[0].y = box.bottom - nBottomOffset;
+                    pt[1].x = box.right - ROFFSET;
+                    pt[1].y = box.bottom - nBottomOffset;
+                    pt[2].x = box.right - ROFFSET;
+                    pt[2].y = box.bottom - nBottomOffset - EXPANDED_WIDE;
                 }
-                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 };
+                else {
+                    // 鈻�
+                    int nBottomOffset = (box.Height() - WIDE) / 2;
+
+                    pt[0].x = box.right - ROFFSET - WIDE2;
+                    pt[0].y = box.bottom - nBottomOffset - WIDE;
+                    pt[1].x = box.right - ROFFSET - WIDE2;
+                    pt[1].y = box.bottom - nBottomOffset;
+                    pt[2].x = box.right - ROFFSET;
+                    pt[2].y = box.bottom - nBottomOffset - WIDE2;
                 }
-                pDC->Polygon(tri, 3);
+
+                // 浠呭~鍏咃紝涓嶆弿杈癸紙鎻忚竟浼氬姞閲嶅彴闃舵劅锛夛紱棰滆壊鐢� txt 涓庝富棰樹竴鑷�
+                HGDIOBJ oldPen = pDC->SelectObject(GetStockObject(NULL_PEN));
+                HBRUSH   hBrush = CreateSolidBrush(txt);
+                HGDIOBJ oldBrush = pDC->SelectObject(hBrush);
+
+                pDC->Polygon(pt, 3);
+
                 pDC->SelectObject(oldPen);
                 pDC->SelectObject(oldBrush);
+                DeleteObject(hBrush);
             }
 
-            // 3) 鏂囨湰锛氬彸绉婚伩鍏嶉伄鎸�
-            const int indentPx = n->level * 16;
+
+
+            // 3) 鏂囨湰锛氬熀浜庨鍒楀尯鍩熷彸绉伙紙鍖哄垎鏄惁鏈夊瓙鑺傜偣锛�
+            const int indentPx = n->level * 14;
+            const int baseLeft = rc.left + m_expanderPadding + indentPx;
+
             CRect textRc = rc;
-            textRc.left = rc.left + m_expanderPadding + indentPx + m_expanderSize + m_textGap;
+            if (!n->children.empty()) {
+                // 鏈夊瓙椤癸細棰勭暀鎸夐挳浣� + 鏂囨湰闂撮殭
+                textRc.left = baseLeft + m_expanderSize + m_textGap;
+            }
+            else {
+                // 鍙跺瓙琛岋細涓嶉鐣欐寜閽綅锛屽彧缁欎竴鐐圭偣鍙跺瓙闂撮殭锛堣灞傜骇缂╄繘浠嶇劧鐢熸晥锛�
+                constexpr int kLeafGap = 2; // 浣犲彲璋� 0~4
+                textRc.left = baseLeft + kLeafGap;
+            }
 
             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;
         }

--
Gitblit v1.9.3