-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFileView.cpp
348 lines (278 loc) · 8.59 KB
/
FileView.cpp
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#include "stdafx.h"
#include "mainfrm.h"
#include "FileView.h"
#include "Resource.h"
#include "SceneEditor.h"
#include "BaseApplication.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileView
CFileView::CFileView()
{
}
CFileView::~CFileView()
{
}
BEGIN_MESSAGE_MAP(CFileView, CDockablePane)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_PROPERTIES, OnProperties)
ON_COMMAND(ID_OPEN, OnFileOpen)
ON_COMMAND(ID_OPEN_WITH, OnFileOpenWith)
ON_COMMAND(ID_DUMMY_COMPILE, OnDummyCompile)
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
ON_NOTIFY(TVN_SELCHANGED, 4, OnSelChanged)
ON_WM_PAINT()
ON_WM_SETFOCUS()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWorkspaceBar 消息处理程序
int CFileView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rectDummy;
rectDummy.SetRectEmpty();
// 创建视图:
const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS |TVS_SHOWSELALWAYS;
if (!m_wndFileView.Create(dwViewStyle, rectDummy, this, 4))
{
TRACE0("未能创建文件视图\n");
return -1; // 未能创建
}
// 加载视图图像:
m_FileViewImages.Create(IDB_FILE_VIEW, 16, 0, RGB(255, 0, 255));
m_wndFileView.SetImageList(&m_FileViewImages, TVSIL_NORMAL);
m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_EXPLORER);
m_wndToolBar.LoadToolBar(IDR_EXPLORER, 0, 0, TRUE /* 已锁定*/);
OnChangeVisualStyle();
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
m_wndToolBar.SetOwner(this);
// 所有命令将通过此控件路由,而不是通过主框架路由:
m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
tempGroup=0;
AdjustLayout();
return 0;
}
void CFileView::OnSize(UINT nType, int cx, int cy)
{
CDockablePane::OnSize(nType, cx, cy);
AdjustLayout();
}
void CFileView::FillFileView()
{
hRoot = m_wndFileView.InsertItem(_T("资源文件"), 0, 0);
m_wndFileView.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);
hMesh = m_wndFileView.InsertItem(_T("模型"), 0, 0, hRoot);
hMeshSystem=m_wndFileView.InsertItem(_T("系统"), 0, 0, hMesh);
hPhysicsBox=m_wndFileView.InsertItem(_T("碰撞体"), 0, 0, hRoot);
hLight=m_wndFileView.InsertItem(_T("光源"),0,0,hRoot);
hSound = m_wndFileView.InsertItem(_T("声音"), 0, 0, hRoot);
hSoundSystem=m_wndFileView.InsertItem(_T("系统"), 0, 0, hSound);
hParticle = m_wndFileView.InsertItem(_T("粒子"), 0, 0, hRoot);
hParticleSystem=m_wndFileView.InsertItem(_T("系统"), 0, 0, hParticle);
m_wndFileView.InsertItem(_T("立方体.Phy"), 5, 5, hPhysicsBox);
m_wndFileView.InsertItem(_T("球体.Phy"), 5, 5, hPhysicsBox);
m_wndFileView.InsertItem(_T("圆柱体.Phy"), 5, 5, hPhysicsBox);
m_wndFileView.InsertItem(_T("胶囊.Phy"), 5, 5, hPhysicsBox);
m_wndFileView.InsertItem(_T("平面.Phy"), 5, 5, hPhysicsBox);
m_wndFileView.InsertItem(_T("点光源.Light"), 7, 7, hLight);
m_wndFileView.InsertItem(_T("聚光灯.Light"), 7, 7, hLight);
m_wndFileView.InsertItem(_T("平行光.Light"), 7, 7, hLight);
std::list<CString> listFile;
TraverseFolder(CString(_T("../media/sound")), listFile);
TraverseFolder(CString(_T("../media/models")), listFile);
CString temp;
for (std::list<CString>::iterator i=listFile.begin(); i!=listFile.end(); ++i)
{
temp=*i;
int nPos = temp.Find('.');
CString fileextion;
fileextion = temp.Right(temp.GetLength()-nPos-1);
if (fileextion=="ogg"||fileextion=="mid"||fileextion=="mp3")
{
m_wndFileView.InsertItem(temp, 6, 6, hSoundSystem);
}
if (fileextion=="mesh")
{
m_wndFileView.InsertItem(temp, 3, 3, hMeshSystem);
}
}
ParticleUniverse::ParticleSystemManager* pManager = ParticleUniverse::ParticleSystemManager::getSingletonPtr();
if (pManager!=NULL)
{
ParticleUniverse::vector<ParticleUniverse::String> ParticleNameList;
pManager->particleSystemTemplateNames(ParticleNameList);
ParticleUniverse::vector<ParticleUniverse::String>::iterator i=ParticleNameList.begin();
while(i!=ParticleNameList.end())
{
Ogre::String particleName=*i;
particleName.append(".particle");
m_wndFileView.InsertItem(CString(particleName.c_str()), 4, 4,hParticle);
i++;
}
}
m_wndFileView.Expand(hRoot, TVE_EXPAND);
m_wndFileView.Expand(hMeshSystem, TVE_EXPAND);
m_wndFileView.Expand(hSoundSystem, TVE_EXPAND);
m_wndFileView.Expand(hParticleSystem,TVE_EXPAND);
}
void CFileView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CTreeCtrl* pWndTree = (CTreeCtrl*) &m_wndFileView;
ASSERT_VALID(pWndTree);
if (pWnd != pWndTree)
{
CDockablePane::OnContextMenu(pWnd, point);
return;
}
if (point != CPoint(-1, -1))
{
// 选择已单击的项:
CPoint ptTree = point;
pWndTree->ScreenToClient(&ptTree);
UINT flags = 0;
HTREEITEM hTreeItem = pWndTree->HitTest(ptTree, &flags);
if (hTreeItem != NULL)
{
pWndTree->SelectItem(hTreeItem);
}
}
pWndTree->SetFocus();
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EXPLORER, point.x, point.y, this, TRUE);
}
void CFileView::AdjustLayout()
{
if (GetSafeHwnd() == NULL)
{
return;
}
CRect rectClient;
GetClientRect(rectClient);
int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;
m_wndToolBar.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);
m_wndFileView.SetWindowPos(NULL, rectClient.left + 1, rectClient.top + cyTlb + 1, rectClient.Width() - 2, rectClient.Height() - cyTlb - 2, SWP_NOACTIVATE | SWP_NOZORDER);
}
void CFileView::OnProperties()
{
AfxMessageBox(_T("属性...."));
}
void CFileView::OnFileOpen()
{
// TODO: 在此处添加命令处理程序代码
}
void CFileView::OnFileOpenWith()
{
// TODO: 在此处添加命令处理程序代码
}
void CFileView::OnDummyCompile()
{
// TODO: 在此处添加命令处理程序代码
}
void CFileView::OnEditCut()
{
// TODO: 在此处添加命令处理程序代码
}
void CFileView::OnEditCopy()
{
// TODO: 在此处添加命令处理程序代码
}
void CFileView::OnEditClear()
{
// TODO: 在此处添加命令处理程序代码
}
void CFileView::OnPaint()
{
CPaintDC dc(this); // 用于绘制的设备上下文
CRect rectTree;
m_wndFileView.GetWindowRect(rectTree);
ScreenToClient(rectTree);
rectTree.InflateRect(1, 1);
dc.Draw3dRect(rectTree, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DSHADOW));
}
void CFileView::OnSetFocus(CWnd* pOldWnd)
{
CDockablePane::OnSetFocus(pOldWnd);
m_wndFileView.SetFocus();
}
void CFileView::OnChangeVisualStyle()
{
m_wndToolBar.CleanUpLockedImages();
m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_EXPLORER_24 : IDR_EXPLORER, 0, 0, TRUE /* 锁定*/);
m_FileViewImages.DeleteImageList();
UINT uiBmpId = theApp.m_bHiColorIcons ? IDB_FILE_VIEW_24 : IDB_FILE_VIEW;
CBitmap bmp;
if (!bmp.LoadBitmap(uiBmpId))
{
TRACE(_T("无法加载位图: %x\n"), uiBmpId);
ASSERT(FALSE);
return;
}
BITMAP bmpObj;
bmp.GetBitmap(&bmpObj);
UINT nFlags = ILC_MASK;
nFlags |= (theApp.m_bHiColorIcons) ? ILC_COLOR24 : ILC_COLOR4;
m_FileViewImages.Create(16, bmpObj.bmHeight, nFlags, 0, 0);
m_FileViewImages.Add(&bmp, RGB(255, 0, 255));
m_wndFileView.SetImageList(&m_FileViewImages, TVSIL_NORMAL);
}
void CFileView::TraverseFolder( const CString& strDir,std::list<CString>& listFile )
{
WIN32_FIND_DATA FindFileData;
CString strDirTmp;
strDirTmp = strDir;
strDirTmp += "/*.*";
HANDLE hFind=::FindFirstFile(strDirTmp,&FindFileData);
if(INVALID_HANDLE_VALUE == hFind)
{
return;
}
while(true)
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
/*if(FindFileData.cFileName[0]!= _T('.'))
{
strDirTmp = strDir;
strDirTmp += FindFileData.cFileName;
strDirTmp+="\\";
TraverseFolder(strDirTmp,listFile) ;
}*/
}
else
{
/*strDirTmp = strDir;
strDirTmp += FindFileData.cFileName;
listFile.push_back(strDirTmp);*/
listFile.push_back(FindFileData.cFileName);
}
if(!FindNextFile(hFind,&FindFileData)) break;
}
FindClose(hFind);
}
void CFileView::OnSelChanged( NMHDR* pNMHDR, LRESULT* pResult )
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
*pResult = 0;
CString strText;
HTREEITEM hItem = m_wndFileView.GetSelectedItem();
strText = m_wndFileView.GetItemText(hItem);
BaseApplication *appMgr;
appMgr=BaseApplication::getInstance();
if (appMgr->mscene!=NULL)
{
USES_CONVERSION;
std::string str1 = W2A(strText.GetBuffer());
Ogre::String resName(str1);
appMgr->mscene->createSceneObj(resName);
}
//MessageBox(strText);
}