-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyTreeView.h
182 lines (153 loc) · 5.38 KB
/
MyTreeView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// WinDjView
// Copyright (C) 2004-2015 Andrew Zhezherun
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// http://www.gnu.org/copyleft/gpl.html
#pragma once
#include "MyScrollView.h"
#include "MyTheme.h"
#include "Drawing.h"
#define TVN_ITEMCLICKED (WM_USER + 30)
class CMyTreeView : public CMyScrollView
{
DECLARE_DYNAMIC(CMyTreeView)
public:
CMyTreeView();
virtual ~CMyTreeView();
// Attributes
public:
void SetItemHeight(int nHeight);
void SetImageList(CImageList* pImageList, DWORD dwStyle);
void SetWrapLabels(bool bWrapLabels);
void SetRedirectWheel(bool bRedirectWheel);
void RecalcLayout();
HTREEITEM InsertItem(LPCTSTR pszItem, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST);
HTREEITEM InsertItem(LPCTSTR pszItem, int nImage, int nSelectedImage, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST);
bool DeleteItem(HTREEITEM hItem);
void DeleteAllItems();
void SetItemData(HTREEITEM hItem, DWORD_PTR dwData);
DWORD_PTR GetItemData(HTREEITEM hItem);
HTREEITEM GetSelectedItem();
void SelectItem(HTREEITEM hItem);
bool Expand(HTREEITEM hItem, UINT nCode);
void BeginBatchUpdate();
void EndBatchUpdate();
// Overrides
public:
virtual void OnDraw(CDC* pDC);
virtual bool OnScrollBy(CSize szScrollBy, bool bDoScroll = true);
virtual bool OnStartPan();
// Implementation
protected:
class CTreeToolTip : public CWnd
{
public:
CTreeToolTip() : m_pTree(NULL), m_nNextCode(0), m_nMouseLeaveCode(0) {}
BOOL Create(CMyTreeView* pTree);
void Show(const CString& strText, bool bWrap, const CRect& rcWindow, const CRect& rcText);
void Hide();
CMyTreeView* m_pTree;
CString m_strText;
CRect m_rcText;
int m_nNextCode, m_nMouseLeaveCode;
bool m_bWrap;
virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
};
friend class CTreeToolTip;
bool m_bMouseInTooltip;
CTreeToolTip m_toolTip;
CString m_strToolTip;
struct TreeNode
{
TreeNode(LPCTSTR pszItem, int nImageIndex, int nSelectedIndex, TreeNode* pParentNode)
: strLabel(pszItem), nImage(nImageIndex), nSelectedImage(nSelectedIndex), pParent(pParentNode),
pChild(NULL), pLastChild(NULL), pNext(NULL), bCollapsed(true), dwUserData(0) {}
~TreeNode();
CString strLabel;
int nImage;
int nSelectedImage;
bool bCollapsed;
CRect rcNode, rcText, rcLabel, rcGlyph, rcImage;
int nLineX, nLineY, nLineStopX;
DWORD_PTR dwUserData;
TreeNode* pParent;
TreeNode* pChild;
TreeNode* pLastChild;
TreeNode* pNext;
int nIndex;
bool HasChildren() const { return pChild != NULL; }
bool HasSibling() const { return pNext != NULL; }
};
vector<TreeNode*> m_items;
enum HitTestArea
{
HT_LABEL,
HT_IMAGE,
HT_GLYPH,
HT_OTHER
};
HTHEME m_hTheme;
TreeNode* m_pRoot;
int m_nItemHeight;
CImageList* m_pImageList;
bool m_bWrapLabels;
bool m_bRedirectWheel;
bool m_bLinesAtRoot;
bool m_bHasLines;
bool m_bHasGlyphs;
CFont m_font, m_fontHover;
CSize m_szDisplay;
bool m_bBatchUpdate;
bool m_bInsideOnSize;
COffscreenDC m_offscreenDC;
TreeNode* m_pSelection;
TreeNode* m_pHoverNode;
void SetHoverNode(TreeNode* pNode);
void UpdateHoverNode();
void UpdateHoverNode(const CPoint& point);
void SelectNode(TreeNode* pNode, UINT nAction = TVC_UNKNOWN);
void ToggleNode(TreeNode* pNode, bool bAllChildren = false);
void ExpandNode(TreeNode* pNode, bool bExpand = true, bool bAllChildren = false);
TreeNode* FindNextNode(TreeNode* pNode);
TreeNode* FindPrevNode(TreeNode* pNode);
TreeNode* FindNextPageNode(TreeNode* pNode);
TreeNode* FindPrevPageNode(TreeNode* pNode);
int PaintNode(CDC* pDC, TreeNode* pNode, const CRect& rcClip);
TreeNode* HitTest(CPoint point, int* pnArea);
TreeNode* HitTest(TreeNode* pNode, CPoint point, int* pnArea);
void InvalidateNode(TreeNode* pNode);
void EnsureVisible(TreeNode* pNode);
bool UpdateParameters();
void InitNotification(NMTREEVIEW& nmtv, UINT nCode);
// Generated message map functions
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnThemeChanged();
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnMouseLeave();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint point);
afx_msg void OnSysColorChange();
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct);
DECLARE_MESSAGE_MAP()
};