| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #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; |
| | | }; |
| | | |
| | | |