提交 | 用户 | age
|
0ed438
|
1 |
|
Q |
2 |
#include "pch.h"
|
|
3 |
#include "framework.h"
|
|
4 |
#include "mainfrm.h"
|
|
5 |
#include "FileView.h"
|
|
6 |
#include "Resource.h"
|
|
7 |
#include "MTerm1.h"
|
|
8 |
|
|
9 |
#ifdef _DEBUG
|
|
10 |
#undef THIS_FILE
|
|
11 |
static char THIS_FILE[]=__FILE__;
|
|
12 |
#define new DEBUG_NEW
|
|
13 |
#endif
|
|
14 |
|
|
15 |
/////////////////////////////////////////////////////////////////////////////
|
|
16 |
// CFileView
|
|
17 |
|
|
18 |
CFileView::CFileView() noexcept
|
|
19 |
{
|
|
20 |
}
|
|
21 |
|
|
22 |
CFileView::~CFileView()
|
|
23 |
{
|
|
24 |
}
|
|
25 |
|
|
26 |
BEGIN_MESSAGE_MAP(CFileView, CDockablePane)
|
|
27 |
ON_WM_CREATE()
|
|
28 |
ON_WM_SIZE()
|
|
29 |
ON_WM_CONTEXTMENU()
|
|
30 |
ON_COMMAND(ID_PROPERTIES, OnProperties)
|
|
31 |
ON_COMMAND(ID_OPEN, OnFileOpen)
|
|
32 |
ON_COMMAND(ID_OPEN_WITH, OnFileOpenWith)
|
|
33 |
ON_COMMAND(ID_DUMMY_COMPILE, OnDummyCompile)
|
|
34 |
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
|
|
35 |
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
|
|
36 |
ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
|
|
37 |
ON_WM_PAINT()
|
|
38 |
ON_WM_SETFOCUS()
|
|
39 |
END_MESSAGE_MAP()
|
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////
|
|
42 |
// CWorkspaceBar 消息处理程序
|
|
43 |
|
|
44 |
int CFileView::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
45 |
{
|
|
46 |
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
|
|
47 |
return -1;
|
|
48 |
|
|
49 |
CRect rectDummy;
|
|
50 |
rectDummy.SetRectEmpty();
|
|
51 |
|
|
52 |
// 创建视图:
|
|
53 |
const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
|
|
54 |
|
|
55 |
if (!m_wndFileView.Create(dwViewStyle, rectDummy, this, 4))
|
|
56 |
{
|
|
57 |
TRACE0("未能创建文件视图\n");
|
|
58 |
return -1; // 未能创建
|
|
59 |
}
|
|
60 |
|
|
61 |
// 加载视图图像:
|
|
62 |
m_FileViewImages.Create(IDB_FILE_VIEW, 16, 0, RGB(255, 0, 255));
|
|
63 |
m_wndFileView.SetImageList(&m_FileViewImages, TVSIL_NORMAL);
|
|
64 |
|
|
65 |
m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_EXPLORER);
|
|
66 |
m_wndToolBar.LoadToolBar(IDR_EXPLORER, 0, 0, TRUE /* 已锁定*/);
|
|
67 |
|
|
68 |
OnChangeVisualStyle();
|
|
69 |
|
|
70 |
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
|
|
71 |
|
|
72 |
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
|
|
73 |
|
|
74 |
m_wndToolBar.SetOwner(this);
|
|
75 |
|
|
76 |
// 所有命令将通过此控件路由,而不是通过主框架路由:
|
|
77 |
m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
|
|
78 |
|
|
79 |
// 填入一些静态树视图数据(此处只需填入虚拟代码,而不是复杂的数据)
|
|
80 |
FillFileView();
|
|
81 |
AdjustLayout();
|
|
82 |
|
|
83 |
return 0;
|
|
84 |
}
|
|
85 |
|
|
86 |
void CFileView::OnSize(UINT nType, int cx, int cy)
|
|
87 |
{
|
|
88 |
CDockablePane::OnSize(nType, cx, cy);
|
|
89 |
AdjustLayout();
|
|
90 |
}
|
|
91 |
|
|
92 |
void CFileView::FillFileView()
|
|
93 |
{
|
|
94 |
HTREEITEM hRoot = m_wndFileView.InsertItem(_T("FakeApp 文件"), 0, 0);
|
|
95 |
m_wndFileView.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);
|
|
96 |
|
|
97 |
HTREEITEM hSrc = m_wndFileView.InsertItem(_T("FakeApp 源文件"), 0, 0, hRoot);
|
|
98 |
|
|
99 |
m_wndFileView.InsertItem(_T("FakeApp.cpp"), 1, 1, hSrc);
|
|
100 |
m_wndFileView.InsertItem(_T("FakeApp.rc"), 1, 1, hSrc);
|
|
101 |
m_wndFileView.InsertItem(_T("FakeAppDoc.cpp"), 1, 1, hSrc);
|
|
102 |
m_wndFileView.InsertItem(_T("FakeAppView.cpp"), 1, 1, hSrc);
|
|
103 |
m_wndFileView.InsertItem(_T("MainFrm.cpp"), 1, 1, hSrc);
|
|
104 |
m_wndFileView.InsertItem(_T("pch.cpp"), 1, 1, hSrc);
|
|
105 |
|
|
106 |
HTREEITEM hInc = m_wndFileView.InsertItem(_T("FakeApp 头文件"), 0, 0, hRoot);
|
|
107 |
|
|
108 |
m_wndFileView.InsertItem(_T("FakeApp.h"), 2, 2, hInc);
|
|
109 |
m_wndFileView.InsertItem(_T("FakeAppDoc.h"), 2, 2, hInc);
|
|
110 |
m_wndFileView.InsertItem(_T("FakeAppView.h"), 2, 2, hInc);
|
|
111 |
m_wndFileView.InsertItem(_T("Resource.h"), 2, 2, hInc);
|
|
112 |
m_wndFileView.InsertItem(_T("MainFrm.h"), 2, 2, hInc);
|
|
113 |
m_wndFileView.InsertItem(_T("pch.h"), 2, 2, hInc);
|
|
114 |
|
|
115 |
HTREEITEM hRes = m_wndFileView.InsertItem(_T("FakeApp 资源文件"), 0, 0, hRoot);
|
|
116 |
|
|
117 |
m_wndFileView.InsertItem(_T("FakeApp.ico"), 2, 2, hRes);
|
|
118 |
m_wndFileView.InsertItem(_T("FakeApp.rc2"), 2, 2, hRes);
|
|
119 |
m_wndFileView.InsertItem(_T("FakeAppDoc.ico"), 2, 2, hRes);
|
|
120 |
m_wndFileView.InsertItem(_T("FakeToolbar.bmp"), 2, 2, hRes);
|
|
121 |
|
|
122 |
m_wndFileView.Expand(hRoot, TVE_EXPAND);
|
|
123 |
m_wndFileView.Expand(hSrc, TVE_EXPAND);
|
|
124 |
m_wndFileView.Expand(hInc, TVE_EXPAND);
|
|
125 |
}
|
|
126 |
|
|
127 |
void CFileView::OnContextMenu(CWnd* pWnd, CPoint point)
|
|
128 |
{
|
|
129 |
CTreeCtrl* pWndTree = (CTreeCtrl*) &m_wndFileView;
|
|
130 |
ASSERT_VALID(pWndTree);
|
|
131 |
|
|
132 |
if (pWnd != pWndTree)
|
|
133 |
{
|
|
134 |
CDockablePane::OnContextMenu(pWnd, point);
|
|
135 |
return;
|
|
136 |
}
|
|
137 |
|
|
138 |
if (point != CPoint(-1, -1))
|
|
139 |
{
|
|
140 |
// 选择已单击的项:
|
|
141 |
CPoint ptTree = point;
|
|
142 |
pWndTree->ScreenToClient(&ptTree);
|
|
143 |
|
|
144 |
UINT flags = 0;
|
|
145 |
HTREEITEM hTreeItem = pWndTree->HitTest(ptTree, &flags);
|
|
146 |
if (hTreeItem != nullptr)
|
|
147 |
{
|
|
148 |
pWndTree->SelectItem(hTreeItem);
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
pWndTree->SetFocus();
|
|
153 |
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EXPLORER, point.x, point.y, this, TRUE);
|
|
154 |
}
|
|
155 |
|
|
156 |
void CFileView::AdjustLayout()
|
|
157 |
{
|
|
158 |
if (GetSafeHwnd() == nullptr)
|
|
159 |
{
|
|
160 |
return;
|
|
161 |
}
|
|
162 |
|
|
163 |
CRect rectClient;
|
|
164 |
GetClientRect(rectClient);
|
|
165 |
|
|
166 |
int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;
|
|
167 |
|
|
168 |
m_wndToolBar.SetWindowPos(nullptr, rectClient.left, rectClient.top, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);
|
|
169 |
m_wndFileView.SetWindowPos(nullptr, rectClient.left + 1, rectClient.top + cyTlb + 1, rectClient.Width() - 2, rectClient.Height() - cyTlb - 2, SWP_NOACTIVATE | SWP_NOZORDER);
|
|
170 |
}
|
|
171 |
|
|
172 |
void CFileView::OnProperties()
|
|
173 |
{
|
|
174 |
AfxMessageBox(_T("属性...."));
|
|
175 |
|
|
176 |
}
|
|
177 |
|
|
178 |
void CFileView::OnFileOpen()
|
|
179 |
{
|
|
180 |
// TODO: 在此处添加命令处理程序代码
|
|
181 |
}
|
|
182 |
|
|
183 |
void CFileView::OnFileOpenWith()
|
|
184 |
{
|
|
185 |
// TODO: 在此处添加命令处理程序代码
|
|
186 |
}
|
|
187 |
|
|
188 |
void CFileView::OnDummyCompile()
|
|
189 |
{
|
|
190 |
// TODO: 在此处添加命令处理程序代码
|
|
191 |
}
|
|
192 |
|
|
193 |
void CFileView::OnEditCut()
|
|
194 |
{
|
|
195 |
// TODO: 在此处添加命令处理程序代码
|
|
196 |
}
|
|
197 |
|
|
198 |
void CFileView::OnEditCopy()
|
|
199 |
{
|
|
200 |
// TODO: 在此处添加命令处理程序代码
|
|
201 |
}
|
|
202 |
|
|
203 |
void CFileView::OnEditClear()
|
|
204 |
{
|
|
205 |
// TODO: 在此处添加命令处理程序代码
|
|
206 |
}
|
|
207 |
|
|
208 |
void CFileView::OnPaint()
|
|
209 |
{
|
|
210 |
CPaintDC dc(this); // 用于绘制的设备上下文
|
|
211 |
|
|
212 |
CRect rectTree;
|
|
213 |
m_wndFileView.GetWindowRect(rectTree);
|
|
214 |
ScreenToClient(rectTree);
|
|
215 |
|
|
216 |
rectTree.InflateRect(1, 1);
|
|
217 |
dc.Draw3dRect(rectTree, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DSHADOW));
|
|
218 |
}
|
|
219 |
|
|
220 |
void CFileView::OnSetFocus(CWnd* pOldWnd)
|
|
221 |
{
|
|
222 |
CDockablePane::OnSetFocus(pOldWnd);
|
|
223 |
|
|
224 |
m_wndFileView.SetFocus();
|
|
225 |
}
|
|
226 |
|
|
227 |
void CFileView::OnChangeVisualStyle()
|
|
228 |
{
|
|
229 |
m_wndToolBar.CleanUpLockedImages();
|
|
230 |
m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_EXPLORER_24 : IDR_EXPLORER, 0, 0, TRUE /* 锁定*/);
|
|
231 |
|
|
232 |
m_FileViewImages.DeleteImageList();
|
|
233 |
|
|
234 |
UINT uiBmpId = theApp.m_bHiColorIcons ? IDB_FILE_VIEW_24 : IDB_FILE_VIEW;
|
|
235 |
|
|
236 |
CBitmap bmp;
|
|
237 |
if (!bmp.LoadBitmap(uiBmpId))
|
|
238 |
{
|
|
239 |
TRACE(_T("无法加载位图: %x\n"), uiBmpId);
|
|
240 |
ASSERT(FALSE);
|
|
241 |
return;
|
|
242 |
}
|
|
243 |
|
|
244 |
BITMAP bmpObj;
|
|
245 |
bmp.GetBitmap(&bmpObj);
|
|
246 |
|
|
247 |
UINT nFlags = ILC_MASK;
|
|
248 |
|
|
249 |
nFlags |= (theApp.m_bHiColorIcons) ? ILC_COLOR24 : ILC_COLOR4;
|
|
250 |
|
|
251 |
m_FileViewImages.Create(16, bmpObj.bmHeight, nFlags, 0, 0);
|
|
252 |
m_FileViewImages.Add(&bmp, RGB(255, 0, 255));
|
|
253 |
|
|
254 |
m_wndFileView.SetImageList(&m_FileViewImages, TVSIL_NORMAL);
|
|
255 |
}
|
|
256 |
|
|
257 |
|