提交 | 用户 | age
|
65f713
|
1 |
|
Q |
2 |
#include "pch.h"
|
|
3 |
#include "framework.h"
|
|
4 |
#include "Resource.h"
|
|
5 |
#include "MainFrm.h"
|
|
6 |
#include "NavView.h"
|
|
7 |
|
|
8 |
#include "MTerm2.h"
|
|
9 |
|
|
10 |
class CClassViewMenuButton : public CMFCToolBarMenuButton
|
|
11 |
{
|
|
12 |
friend class CNavView;
|
|
13 |
|
|
14 |
DECLARE_SERIAL(CClassViewMenuButton)
|
|
15 |
|
|
16 |
public:
|
|
17 |
CClassViewMenuButton(HMENU hMenu = nullptr) noexcept : CMFCToolBarMenuButton((UINT)-1, hMenu, -1)
|
|
18 |
{
|
|
19 |
}
|
|
20 |
|
|
21 |
virtual void OnDraw(CDC* pDC, const CRect& rect, CMFCToolBarImages* pImages, BOOL bHorz = TRUE,
|
|
22 |
BOOL bCustomizeMode = FALSE, BOOL bHighlight = FALSE, BOOL bDrawBorder = TRUE, BOOL bGrayDisabledButtons = TRUE)
|
|
23 |
{
|
|
24 |
pImages = CMFCToolBar::GetImages();
|
|
25 |
|
|
26 |
CAfxDrawState ds;
|
|
27 |
pImages->PrepareDrawImage(ds);
|
|
28 |
|
|
29 |
CMFCToolBarMenuButton::OnDraw(pDC, rect, pImages, bHorz, bCustomizeMode, bHighlight, bDrawBorder, bGrayDisabledButtons);
|
|
30 |
|
|
31 |
pImages->EndDrawImage(ds);
|
|
32 |
}
|
|
33 |
};
|
|
34 |
|
|
35 |
IMPLEMENT_SERIAL(CClassViewMenuButton, CMFCToolBarMenuButton, 1)
|
|
36 |
|
|
37 |
//////////////////////////////////////////////////////////////////////
|
|
38 |
// 构造/析构
|
|
39 |
//////////////////////////////////////////////////////////////////////
|
|
40 |
|
|
41 |
CNavView::CNavView() noexcept
|
|
42 |
{
|
|
43 |
m_nCurrSort = ID_SORTING_GROUPBYTYPE;
|
|
44 |
}
|
|
45 |
|
|
46 |
CNavView::~CNavView()
|
|
47 |
{
|
|
48 |
}
|
|
49 |
|
|
50 |
BEGIN_MESSAGE_MAP(CNavView, CDockablePane)
|
|
51 |
ON_WM_CREATE()
|
|
52 |
ON_WM_SIZE()
|
|
53 |
ON_WM_CONTEXTMENU()
|
|
54 |
// ON_COMMAND(ID_CLASS_ADD_MEMBER_FUNCTION, OnClassAddMemberFunction)
|
|
55 |
// ON_COMMAND(ID_CLASS_ADD_MEMBER_VARIABLE, OnClassAddMemberVariable)
|
|
56 |
// ON_COMMAND(ID_CLASS_DEFINITION, OnClassDefinition)
|
|
57 |
// ON_COMMAND(ID_CLASS_PROPERTIES, OnClassProperties)
|
|
58 |
ON_COMMAND(ID_NEW_FOLDER, OnNewFolder)
|
|
59 |
ON_WM_PAINT()
|
|
60 |
ON_WM_SETFOCUS()
|
|
61 |
ON_COMMAND_RANGE(ID_SORTING_GROUPBYTYPE, ID_SORTING_SORTBYACCESS, OnSort)
|
|
62 |
ON_UPDATE_COMMAND_UI_RANGE(ID_SORTING_GROUPBYTYPE, ID_SORTING_SORTBYACCESS, OnUpdateSort)
|
|
63 |
|
|
64 |
END_MESSAGE_MAP()
|
|
65 |
|
|
66 |
/////////////////////////////////////////////////////////////////////////////
|
|
67 |
// CNavView 消息处理程序
|
|
68 |
|
|
69 |
int CNavView::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
70 |
{
|
|
71 |
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
|
|
72 |
return -1;
|
|
73 |
|
|
74 |
CRect rectDummy;
|
|
75 |
rectDummy.SetRectEmpty();
|
|
76 |
|
|
77 |
// 创建视图:
|
|
78 |
const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_LINESATROOT | TVS_HASLINES | TVS_HASBUTTONS | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; //
|
|
79 |
|
|
80 |
if (!m_wndNavView.Create(dwViewStyle, rectDummy, this, 2))
|
|
81 |
{
|
|
82 |
TRACE0("未能创建导航栏视图\n");
|
|
83 |
return -1; // 未能创建
|
|
84 |
}
|
|
85 |
|
|
86 |
// 加载图像:
|
|
87 |
m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_SORT);
|
|
88 |
m_wndToolBar.LoadToolBar(IDR_SORT, 0, 0, TRUE /* 已锁定*/);
|
|
89 |
|
|
90 |
OnChangeVisualStyle();
|
|
91 |
|
|
92 |
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
|
|
93 |
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
|
|
94 |
|
|
95 |
m_wndToolBar.SetOwner(this);
|
|
96 |
|
|
97 |
// 所有命令将通过此控件路由,而不是通过主框架路由:
|
|
98 |
m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
|
|
99 |
|
|
100 |
CMenu menuSort;
|
|
101 |
menuSort.LoadMenu(IDR_POPUP_SORT);
|
|
102 |
|
|
103 |
m_wndToolBar.ReplaceButton(ID_SORT_MENU, CClassViewMenuButton(menuSort.GetSubMenu(0)->GetSafeHmenu()));
|
|
104 |
|
|
105 |
CClassViewMenuButton* pButton = DYNAMIC_DOWNCAST(CClassViewMenuButton, m_wndToolBar.GetButton(0));
|
|
106 |
|
|
107 |
if (pButton != nullptr)
|
|
108 |
{
|
|
109 |
pButton->m_bText = FALSE;
|
|
110 |
pButton->m_bImage = TRUE;
|
|
111 |
pButton->SetImage(GetCmdMgr()->GetCmdImage(m_nCurrSort));
|
|
112 |
pButton->SetMessageWnd(this);
|
|
113 |
}
|
|
114 |
|
|
115 |
// 填入一些静态树视图数据(此处只需填入虚拟代码,而不是复杂的数据)
|
61deef
|
116 |
FillDeviceView();
|
65f713
|
117 |
|
Q |
118 |
return 0;
|
|
119 |
}
|
|
120 |
|
|
121 |
void CNavView::OnSize(UINT nType, int cx, int cy)
|
|
122 |
{
|
|
123 |
CDockablePane::OnSize(nType, cx, cy);
|
|
124 |
AdjustLayout();
|
|
125 |
}
|
|
126 |
|
61deef
|
127 |
void CNavView::FillDeviceView()
|
65f713
|
128 |
{
|
Q |
129 |
HTREEITEM hRoot1 = m_wndNavView.InsertItem(_T("连接状态"), 0, 0);
|
|
130 |
m_wndNavView.SetItemState(hRoot1, TVIS_BOLD, TVIS_BOLD);
|
|
131 |
|
|
132 |
HTREEITEM hClass1 = m_wndNavView.InsertItem(_T("KL10-E16D-N1"), 1, 1, hRoot1);
|
|
133 |
m_wndNavView.InsertItem(_T("工作模式"), 3, 3, hClass1);
|
|
134 |
m_wndNavView.InsertItem(_T("状态"), 3, 3, hClass1);
|
|
135 |
m_wndNavView.InsertItem(_T("系统参数"), 3, 3, hClass1);
|
|
136 |
m_wndNavView.Expand(hRoot1, TVE_EXPAND);
|
|
137 |
|
|
138 |
HTREEITEM hClass2 = m_wndNavView.InsertItem(_T("CFakeAboutDlg"), 1, 1, hRoot1);
|
|
139 |
m_wndNavView.InsertItem(_T("CFakeAboutDlg()"), 3, 3, hClass2);
|
|
140 |
|
|
141 |
HTREEITEM hClass3 = m_wndNavView.InsertItem(_T("CFakeAppDoc"), 1, 1, hRoot1);
|
|
142 |
m_wndNavView.InsertItem(_T("CFakeAppDoc()"), 4, 4, hClass3);
|
|
143 |
m_wndNavView.InsertItem(_T("~CFakeAppDoc()"), 3, 3, hClass3);
|
|
144 |
m_wndNavView.InsertItem(_T("OnNewDocument()"), 3, 3, hClass3);
|
|
145 |
|
|
146 |
HTREEITEM hClass4 = m_wndNavView.InsertItem(_T("CFakeAppView"), 1, 1, hRoot1);
|
|
147 |
m_wndNavView.InsertItem(_T("CFakeAppView()"), 4, 4, hClass4);
|
|
148 |
m_wndNavView.InsertItem(_T("~CFakeAppView()"), 3, 3, hClass4);
|
|
149 |
m_wndNavView.InsertItem(_T("GetDocument()"), 3, 3, hClass4);
|
|
150 |
m_wndNavView.Expand(hClass4, TVE_EXPAND);
|
|
151 |
|
|
152 |
HTREEITEM hClass5 = m_wndNavView.InsertItem(_T("Globals"), 2, 2, hRoot1);
|
|
153 |
m_wndNavView.InsertItem(_T("theFakeApp"), 5, 5, hClass5);
|
|
154 |
m_wndNavView.Expand(hClass5, TVE_EXPAND);
|
|
155 |
|
|
156 |
HTREEITEM hRoot2 = m_wndNavView.InsertItem(_T("连接状态2"), 0, 0);
|
|
157 |
m_wndNavView.SetItemState(hRoot2, TVIS_BOLD, TVIS_BOLD);
|
|
158 |
|
|
159 |
|
|
160 |
}
|
|
161 |
|
|
162 |
void CNavView::OnContextMenu(CWnd* pWnd, CPoint point)
|
|
163 |
{
|
|
164 |
CTreeCtrl* pWndTree = (CTreeCtrl*)&m_wndNavView;
|
|
165 |
ASSERT_VALID(pWndTree);
|
|
166 |
|
|
167 |
if (pWnd != pWndTree)
|
|
168 |
{
|
|
169 |
CDockablePane::OnContextMenu(pWnd, point);
|
|
170 |
return;
|
|
171 |
}
|
|
172 |
|
|
173 |
if (point != CPoint(-1, -1))
|
|
174 |
{
|
|
175 |
// 选择已单击的项:
|
|
176 |
CPoint ptTree = point;
|
|
177 |
pWndTree->ScreenToClient(&ptTree);
|
|
178 |
|
|
179 |
UINT flags = 0;
|
|
180 |
HTREEITEM hTreeItem = pWndTree->HitTest(ptTree, &flags);
|
|
181 |
if (hTreeItem != nullptr)
|
|
182 |
{
|
|
183 |
pWndTree->SelectItem(hTreeItem);
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
pWndTree->SetFocus();
|
|
188 |
CMenu menu;
|
|
189 |
menu.LoadMenu(IDR_POPUP_SORT);
|
|
190 |
|
|
191 |
CMenu* pSumMenu = menu.GetSubMenu(0);
|
|
192 |
|
|
193 |
if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
|
|
194 |
{
|
|
195 |
CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
|
|
196 |
|
|
197 |
if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
|
|
198 |
return;
|
|
199 |
|
|
200 |
((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
|
|
201 |
UpdateDialogControls(this, FALSE);
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
void CNavView::AdjustLayout()
|
|
206 |
{
|
|
207 |
if (GetSafeHwnd() == nullptr)
|
|
208 |
{
|
|
209 |
return;
|
|
210 |
}
|
|
211 |
|
|
212 |
CRect rectClient;
|
|
213 |
GetClientRect(rectClient);
|
|
214 |
|
|
215 |
int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;
|
|
216 |
|
|
217 |
m_wndToolBar.SetWindowPos(nullptr, rectClient.left, rectClient.top, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);
|
|
218 |
m_wndNavView.SetWindowPos(nullptr, rectClient.left + 1, rectClient.top + cyTlb + 1, rectClient.Width() - 2, rectClient.Height() - cyTlb - 2, SWP_NOACTIVATE | SWP_NOZORDER);
|
|
219 |
}
|
|
220 |
|
|
221 |
BOOL CNavView::PreTranslateMessage(MSG* pMsg)
|
|
222 |
{
|
|
223 |
return CDockablePane::PreTranslateMessage(pMsg);
|
|
224 |
}
|
|
225 |
|
|
226 |
void CNavView::OnSort(UINT id)
|
|
227 |
{
|
|
228 |
if (m_nCurrSort == id)
|
|
229 |
{
|
|
230 |
return;
|
|
231 |
}
|
|
232 |
|
|
233 |
m_nCurrSort = id;
|
|
234 |
|
|
235 |
CClassViewMenuButton* pButton = DYNAMIC_DOWNCAST(CClassViewMenuButton, m_wndToolBar.GetButton(0));
|
|
236 |
|
|
237 |
if (pButton != nullptr)
|
|
238 |
{
|
|
239 |
pButton->SetImage(GetCmdMgr()->GetCmdImage(id));
|
|
240 |
m_wndToolBar.Invalidate();
|
|
241 |
m_wndToolBar.UpdateWindow();
|
|
242 |
}
|
|
243 |
}
|
|
244 |
|
|
245 |
void CNavView::OnUpdateSort(CCmdUI* pCmdUI)
|
|
246 |
{
|
|
247 |
pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrSort);
|
|
248 |
}
|
|
249 |
|
|
250 |
void CNavView::OnClassAddMemberFunction()
|
|
251 |
{
|
|
252 |
AfxMessageBox(_T("添加成员函数..."));
|
|
253 |
}
|
|
254 |
|
|
255 |
void CNavView::OnClassAddMemberVariable()
|
|
256 |
{
|
|
257 |
// TODO: 在此处添加命令处理程序代码
|
|
258 |
}
|
|
259 |
|
|
260 |
void CNavView::OnClassDefinition()
|
|
261 |
{
|
|
262 |
// TODO: 在此处添加命令处理程序代码
|
|
263 |
}
|
|
264 |
|
|
265 |
void CNavView::OnClassProperties()
|
|
266 |
{
|
|
267 |
// TODO: 在此处添加命令处理程序代码
|
|
268 |
}
|
|
269 |
|
|
270 |
void CNavView::OnNewFolder()
|
|
271 |
{
|
|
272 |
AfxMessageBox(_T("新建文件夹..."));
|
|
273 |
}
|
|
274 |
|
|
275 |
void CNavView::OnPaint()
|
|
276 |
{
|
|
277 |
CPaintDC dc(this); // 用于绘制的设备上下文
|
|
278 |
|
|
279 |
CRect rectTree;
|
|
280 |
m_wndNavView.GetWindowRect(rectTree);
|
|
281 |
ScreenToClient(rectTree);
|
|
282 |
|
|
283 |
rectTree.InflateRect(1, 1);
|
|
284 |
dc.Draw3dRect(rectTree, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DSHADOW));
|
|
285 |
}
|
|
286 |
|
|
287 |
void CNavView::OnSetFocus(CWnd* pOldWnd)
|
|
288 |
{
|
|
289 |
CDockablePane::OnSetFocus(pOldWnd);
|
|
290 |
|
|
291 |
m_wndNavView.SetFocus();
|
|
292 |
}
|
|
293 |
|
|
294 |
void CNavView::OnChangeVisualStyle()
|
|
295 |
{
|
|
296 |
m_NavViewImages.DeleteImageList();
|
|
297 |
|
|
298 |
UINT uiBmpId = theApp.m_bHiColorIcons ? IDB_CLASS_VIEW_24 : IDB_CLASS_VIEW;
|
|
299 |
// uiBmpId = IDB_NAV_VIEW1;
|
|
300 |
CBitmap bmp;
|
|
301 |
if (!bmp.LoadBitmap(uiBmpId))
|
|
302 |
{
|
|
303 |
TRACE(_T("无法加载位图: %x\n"), uiBmpId);
|
|
304 |
ASSERT(FALSE);
|
|
305 |
return;
|
|
306 |
}
|
|
307 |
|
|
308 |
BITMAP bmpObj;
|
|
309 |
bmp.GetBitmap(&bmpObj);
|
|
310 |
|
|
311 |
UINT nFlags = ILC_MASK;
|
|
312 |
|
|
313 |
nFlags |= (theApp.m_bHiColorIcons) ? ILC_COLOR24 : ILC_COLOR4;
|
|
314 |
|
|
315 |
m_NavViewImages.Create(16, bmpObj.bmHeight, nFlags, 0, 0);
|
|
316 |
m_NavViewImages.Add(&bmp, RGB(255, 0, 0));
|
|
317 |
|
|
318 |
m_wndNavView.SetImageList(&m_NavViewImages, TVSIL_NORMAL);
|
|
319 |
|
|
320 |
m_wndToolBar.CleanUpLockedImages();
|
|
321 |
m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_SORT_24 : IDR_SORT, 0, 0, TRUE /* 锁定*/);
|
|
322 |
}
|