| | |
| | | |
| | | IMPLEMENT_DYNAMIC(CExpandableListCtrl, CListCtrl) |
| | | |
| | | CExpandableListCtrl::CExpandableListCtrl() {} |
| | | CExpandableListCtrl::CExpandableListCtrl() |
| | | { |
| | | m_popupCols = { }; |
| | | } |
| | | |
| | | CExpandableListCtrl::~CExpandableListCtrl() {} |
| | | |
| | | BEGIN_MESSAGE_MAP(CExpandableListCtrl, CListCtrl) |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // —— 若点击到需要“全文显示”的列,则向父窗口发送自定义通知 —— // |
| | | if (!m_popupCols.empty()) { |
| | | LPNMITEMACTIVATE pia = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR); |
| | | |
| | | // 用 SubItemHitTest 更精准拿到列 |
| | | LVHITTESTINFO ht{}; |
| | | ht.pt = pia->ptAction; |
| | | int hit = SubItemHitTest(&ht); |
| | | if (hit >= 0 && ht.iItem >= 0 && ht.iSubItem >= 0) { |
| | | const int row = ht.iItem; |
| | | const int col = ht.iSubItem; |
| | | |
| | | if (m_popupCols.count(col)) { |
| | | CString full = GetItemText(row, col); |
| | | if (!full.IsEmpty() && _IsCellTruncated(row, col, full)) { |
| | | NMC_ELC_SHOWFULLTEXT nm{}; |
| | | nm.hdr.hwndFrom = m_hWnd; |
| | | nm.hdr.idFrom = GetDlgCtrlID(); |
| | | nm.hdr.code = ELCN_SHOWFULLTEXT; |
| | | nm.iItem = row; |
| | | nm.iSubItem = col; |
| | | nm.text = full; |
| | | |
| | | if (CWnd* pParent = GetParent()) { |
| | | pParent->SendMessage(WM_NOTIFY, nm.hdr.idFrom, reinterpret_cast<LPARAM>(&nm)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | *pResult = 0; |
| | | } |
| | | |
| | |
| | | Invalidate(); |
| | | } |
| | | |
| | | void CExpandableListCtrl::SetPopupFullTextColumns(const std::vector<int>& cols) |
| | | { |
| | | m_popupCols.clear(); |
| | | for (int c : cols) m_popupCols.insert(c); |
| | | } |
| | | |
| | | bool CExpandableListCtrl::_IsCellTruncated(int row, int col, const CString& text) const |
| | | { |
| | | if (text.IsEmpty()) return false; |
| | | |
| | | // 单元格显示区域宽度 |
| | | CRect rcCell; |
| | | if (!const_cast<CExpandableListCtrl*>(this)->GetSubItemRect(row, col, LVIR_BOUNDS, rcCell)) |
| | | return false; |
| | | |
| | | // 用控件字体测量文本像素宽 |
| | | CClientDC dc(const_cast<CExpandableListCtrl*>(this)); |
| | | CFont* pOld = dc.SelectObject(const_cast<CExpandableListCtrl*>(this)->GetFont()); |
| | | CSize sz = dc.GetTextExtent(text); |
| | | dc.SelectObject(pOld); |
| | | |
| | | const int kPadding = 8; // 预留一点边距/省略号余量 |
| | | return sz.cx > (rcCell.Width() - kPadding); |
| | | } |
| | | |
| | | |