Dlg_EditView.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. // Dlg_EditView.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "Dlg_EditView.h"
  5. #include ".\dlg_editview.h"
  6. #include <io.h>
  7. #include "shlwapi.h"
  8. #define FILE_NAME "sort.txt"
  9. // CDlg_EditView 对话框
  10. IMPLEMENT_DYNAMIC(CDlg_EditView, CDialog)
  11. CDlg_EditView::CDlg_EditView(CWnd* pParent /*=NULL*/)
  12. : CDialog(CDlg_EditView::IDD, pParent)
  13. {
  14. }
  15. CDlg_EditView::~CDlg_EditView()
  16. {
  17. }
  18. void CDlg_EditView::DoDataExchange(CDataExchange* pDX)
  19. {
  20. CDialog::DoDataExchange(pDX);
  21. DDX_Control(pDX, IDC_LIST1, m_ListView);
  22. }
  23. BEGIN_MESSAGE_MAP(CDlg_EditView, CDialog)
  24. ON_BN_CLICKED(IDC_BTN_DEL, OnBnClickedBtnDel)
  25. ON_BN_CLICKED(IDC_BTN_UP, OnBnClickedBtnUp)
  26. ON_BN_CLICKED(IDC_BTN_DOWN, OnBnClickedBtnDown)
  27. ON_BN_CLICKED(IDC_BTN_ALLSHOW, OnBnClickedBtnAllShow)
  28. ON_BN_CLICKED(IDC_BTN_ALLHIDE, OnBnClickedBtnAllHide)
  29. ON_BN_CLICKED(IDOK, OnBnClickedOk)
  30. ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
  31. ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnNMDblclkList1)
  32. END_MESSAGE_MAP()
  33. // CDlg_EditView 消息处理程序
  34. BOOL CDlg_EditView::OnInitDialog()
  35. {
  36. CDialog::OnInitDialog();
  37. // TODO: 在此添加额外的初始化
  38. m_ListView.InsertColumn(0, "画面名称");
  39. m_ListView.SetColumnWidth(0, 1000);
  40. m_ListView.SetExtendedStyle(m_ListView.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
  41. ////////////////////
  42. char szPicDir[MAX_PATH] = {0};
  43. strcpy(szPicDir, g_strDirectory);
  44. strcat(szPicDir, "\\");
  45. strcat(szPicDir, _PICTUREDIR);
  46. m_sPath.Format( "%s",szPicDir );
  47. ReadALlView();
  48. //CButtonST m_btnDel,m_btnUp,m_btnDown,m_btnShow,m_btnHide,m_btnSave,m_btnExit;
  49. m_btnShow.SubclassDlgItem(IDC_BTN_ALLSHOW, this);
  50. m_btnShow.SetBitmaps(IDB_EDIT, RGB(255, 0, 255));
  51. m_btnShow.SetFlat(FALSE);
  52. m_btnShow.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  53. m_btnHide.SubclassDlgItem(IDC_BTN_ALLHIDE, this);
  54. m_btnHide.SetBitmaps(IDB_COPY , RGB(192, 192, 192));
  55. m_btnHide.SetFlat(FALSE);
  56. m_btnHide.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  57. m_btnSave.SubclassDlgItem(IDOK, this);
  58. m_btnSave.SetBitmaps(IDB_SAVE, RGB(255,0 , 255));
  59. m_btnSave.SetFlat(FALSE);
  60. m_btnSave.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  61. m_btnDel.SubclassDlgItem(IDC_BTN_DEL, this);
  62. m_btnDel.SetBitmaps(IDB_DEL, RGB(255,0 , 255));
  63. m_btnDel.SetFlat(FALSE);
  64. m_btnDel.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  65. m_btnExit.SubclassDlgItem(IDCANCEL, this);
  66. m_btnExit.SetBitmaps(IDB_EXIT, RGB(192, 192, 192));
  67. m_btnExit.SetFlat(FALSE);
  68. m_btnExit.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  69. m_btnUp.SubclassDlgItem(IDC_BTN_UP, this);
  70. m_btnUp.SetIcon(IDI_ICON_UP);
  71. m_btnUp.SetFlat(FALSE);
  72. m_btnUp.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  73. m_btnDown.SubclassDlgItem(IDC_BTN_DOWN, this);
  74. m_btnDown.SetIcon(IDI_ICON_DOWN);
  75. m_btnDown.SetFlat(FALSE);
  76. m_btnDown.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  77. return TRUE; // return TRUE unless you set the focus to a control
  78. // 异常: OCX 属性页应返回 FALSE
  79. }
  80. void CDlg_EditView::OnBnClickedBtnDel()
  81. {
  82. m_ListView.SetFocus();
  83. int iListCount = m_ListView.GetItemCount();
  84. POSITION pos = m_ListView.GetFirstSelectedItemPosition();
  85. int nListSel = m_ListView.GetNextSelectedItem(pos);
  86. if(nListSel>=iListCount || nListSel==-1 )
  87. {
  88. return;
  89. }
  90. m_ListView.DeleteItem( nListSel );
  91. }
  92. void CDlg_EditView::OnBnClickedBtnUp()
  93. {
  94. m_ListView.SetFocus();
  95. int iListCount = m_ListView.GetItemCount();
  96. POSITION pos = m_ListView.GetFirstSelectedItemPosition();
  97. int nListSel = m_ListView.GetNextSelectedItem(pos);
  98. if(nListSel>=iListCount || nListSel==-1 || nListSel==0 )
  99. {
  100. return;
  101. }
  102. CString str1,str2,s1,s2;
  103. str1 = m_ListView.GetItemText( nListSel,0 );
  104. str2 = m_ListView.GetItemText( nListSel-1,0 );
  105. m_ListView.SetItemText( nListSel,0,str2 );
  106. m_ListView.SetItemText( nListSel-1,0,str1 );
  107. m_ListView.SetItemState( nListSel,0,LVIS_SELECTED|LVIS_FOCUSED );
  108. m_ListView.SetItemState( nListSel-1,LVIS_SELECTED, LVIS_SELECTED|LVIS_FOCUSED );
  109. }
  110. void CDlg_EditView::OnBnClickedBtnDown()
  111. {
  112. m_ListView.SetFocus();
  113. int iListCount = m_ListView.GetItemCount();
  114. POSITION pos = m_ListView.GetFirstSelectedItemPosition();
  115. int nListSel = m_ListView.GetNextSelectedItem(pos);
  116. if(nListSel>=iListCount-1 || nListSel==-1 )
  117. {
  118. return;
  119. }
  120. CString str1,str2,s;
  121. str1 = m_ListView.GetItemText( nListSel,0 );
  122. str2 = m_ListView.GetItemText( nListSel+1,0 );
  123. m_ListView.SetItemText( nListSel,0,str2 );
  124. m_ListView.SetItemText( nListSel+1,0,str1 );
  125. m_ListView.SetItemState(nListSel,0,LVIS_SELECTED|LVIS_FOCUSED);
  126. m_ListView.SetItemState( nListSel+1,LVIS_SELECTED, LVIS_SELECTED|LVIS_FOCUSED );
  127. }
  128. void CDlg_EditView::OnBnClickedBtnAllShow()
  129. {
  130. m_ListView.SetFocus();
  131. ShowAll();
  132. }
  133. void CDlg_EditView::OnBnClickedBtnAllHide()
  134. {
  135. m_ListView.SetFocus();
  136. HideAll();
  137. }
  138. void CDlg_EditView::OnBnClickedOk()
  139. {
  140. // TODO: 在此添加控件通知处理程序代码
  141. ShowAll();
  142. char szPicDir[MAX_PATH] = {0};
  143. strcpy(szPicDir, g_strDirectory);
  144. strcat(szPicDir, "\\");
  145. strcat(szPicDir, _PICTUREDIR);
  146. strcat(szPicDir, FILE_NAME);
  147. if( PathFileExists( szPicDir ) )
  148. DeleteFile( szPicDir );
  149. if( m_ListView.GetItemCount()==0 )
  150. return;
  151. CString strTemp;
  152. CStdioFile MyFile;
  153. MyFile.Open(szPicDir,CFile::modeCreate|CFile::modeWrite);
  154. for( int i=0;i<m_ListView.GetItemCount();i++ )
  155. {
  156. strTemp = m_ListView.GetItemText( i,0 );
  157. strTemp += "\n";
  158. MyFile.SeekToEnd();
  159. MyFile.WriteString(strTemp);
  160. }
  161. MyFile.Close();
  162. }
  163. void CDlg_EditView::OnBnClickedCancel()
  164. {
  165. // TODO: 在此添加控件通知处理程序代码
  166. OnCancel();
  167. }
  168. void CDlg_EditView::ReadALlView()
  169. {
  170. char szPicDir[MAX_PATH] = {0};
  171. strcpy(szPicDir, g_strDirectory);
  172. strcat(szPicDir, "\\");
  173. strcat(szPicDir, _PICTUREDIR);
  174. strcat(szPicDir, FILE_NAME);
  175. if( PathFileExists( szPicDir ) )
  176. {
  177. CString sTemp,strTemp1,strTemp2,sTemp2;
  178. CStdioFile File;
  179. if(!File.Open(szPicDir,CFile::modeRead))
  180. File.Open(szPicDir,CFile::modeCreate|CFile::modeRead);
  181. while(File.ReadString(sTemp))//定义一个CString变量sTemp作为缓冲区
  182. {
  183. m_ListView.InsertItem( m_ListView.GetItemCount(),sTemp );
  184. }
  185. File.Close();
  186. }
  187. CString strFindPicFile = "*.view";
  188. char szPicDir2[MAX_PATH] = {0};
  189. strcpy(szPicDir2, g_strDirectory);
  190. strcat(szPicDir2, "\\");
  191. strcat(szPicDir2, _PICTUREDIR);
  192. CStringArray SATemp;
  193. FileSearch( SATemp,0, szPicDir2, "*.*", 0);
  194. CString str1,str2;
  195. for( int i=m_ListView.GetItemCount()-1;i>=0;i-- )
  196. {
  197. str1 = m_ListView.GetItemText( i,0 );
  198. bool bExist = false;
  199. for( int m=0;m<SATemp.GetCount();m++ )
  200. {
  201. str2 = SATemp.GetAt( m );
  202. if( str1==str2 )
  203. {
  204. bExist = true;
  205. break;
  206. }
  207. }
  208. if( !bExist )
  209. m_ListView.DeleteItem( i );
  210. }
  211. }
  212. BOOL CDlg_EditView::DirSearch(CString strPath, CString strFileName)
  213. {
  214. BOOL bResult = FALSE;
  215. long hDir;
  216. struct _finddata_t fDir;
  217. int nDone;
  218. strPath += "*.*";
  219. hDir = _findfirst( (char *)(LPCTSTR)strPath, &fDir );
  220. if( -1L != hDir )
  221. {
  222. while( !( nDone = _findnext(hDir, &fDir) ) )
  223. {
  224. if( !strcmp(fDir.name, "..") ) continue;
  225. if( (_A_SUBDIR == fDir.attrib) )
  226. {
  227. CString str = fDir.name;
  228. if( !str.Compare(strFileName) )
  229. {
  230. bResult = TRUE;
  231. }
  232. }
  233. }
  234. }
  235. return bResult;
  236. }
  237. void CDlg_EditView::FileSearch( CStringArray &SATemp,int iInsertIndex, CString strPath, CString strFileName, int nLayer)
  238. {
  239. long hfile;
  240. struct _finddata_t fFile;
  241. CString strCurr = strPath + strFileName; // + "\\" +
  242. CString sIndex,sContent;
  243. int nDone=0;
  244. int nTime = 0;
  245. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  246. if( -1L != hfile )
  247. {
  248. while( !( nDone = _findnext(hfile, &fFile) ) )
  249. {
  250. if( !strcmp(fFile.name,"..") ) continue;
  251. if( (_A_SUBDIR == fFile.attrib) )
  252. {
  253. strCurr = strPath + "\\" + fFile.name + "\\";
  254. int nPos = strCurr.Find("\\\\");
  255. if( nPos!=-1 )
  256. {
  257. strCurr.Delete( nPos );
  258. }
  259. CString str = fFile.name;
  260. //HTREEITEM hReturn = hItem;
  261. sContent = str;
  262. InsertToList( iInsertIndex,sContent,strPath );
  263. ////////////////////////////////////////////////
  264. if( sContent.Find(".view")!=-1 )
  265. sContent = sContent.Left( sContent.GetLength()-5 );
  266. CString sParent;
  267. if( m_sPath!=strPath )
  268. sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
  269. if( sParent!="" )
  270. {
  271. sContent = sParent+sContent;
  272. }
  273. SATemp.Add( sContent );
  274. ///////////////////////////////////////////////////
  275. iInsertIndex++;
  276. FileSearch( SATemp,iInsertIndex, strCurr, "*.*", nLayer + 1);
  277. //hItem = hReturn;
  278. if( g_bStartRun )
  279. {
  280. CString sPath = strCurr;
  281. int nPos = sPath.Find("*");
  282. if( nPos!=-1 )
  283. {
  284. sPath = sPath.Left( sPath.GetLength()-3 );
  285. }
  286. sPath = sPath+".view";
  287. nPos = sPath.Find("\\.");
  288. if( nPos!=-1 )
  289. {
  290. sPath.Delete( nPos );
  291. }
  292. }
  293. }
  294. else
  295. {
  296. CString str = fFile.name;
  297. if( str.Right(4).Compare("view") ) continue;
  298. CString strTemp = str.Left(str.GetLength()-5);
  299. if( !DirSearch(strPath + "\\", strTemp ) )
  300. {
  301. //m_wndTree.InsertItem(strTemp, 1, 1, hTemp);
  302. sContent = str;
  303. InsertToList( iInsertIndex,sContent,strPath );
  304. iInsertIndex++;
  305. ////////////////////////////////////////////////
  306. if( sContent.Find(".view")!=-1 )
  307. sContent = sContent.Left( sContent.GetLength()-5 );
  308. CString sParent;
  309. if( m_sPath!=strPath )
  310. sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
  311. if( sParent!="" )
  312. {
  313. sContent = sParent+sContent;
  314. }
  315. SATemp.Add( sContent );
  316. ///////////////////////////////////////////////////
  317. }
  318. }
  319. }
  320. _findclose(hfile);
  321. }
  322. }
  323. void CDlg_EditView::InsertToList( int iInsertIndex,CString sContent,CString sPath )
  324. {
  325. CString str;
  326. if( sContent.Find(".view")!=-1 )
  327. sContent = sContent.Left( sContent.GetLength()-5 );
  328. CString sParent;
  329. if( m_sPath!=sPath )
  330. sParent = sPath.Right( sPath.GetLength()-m_sPath.GetLength() );
  331. if( sParent!="" )
  332. {
  333. sContent = sParent+sContent;
  334. }
  335. bool bExist=false;
  336. for( int i=0;i<m_ListView.GetItemCount();i++ )
  337. {
  338. str = m_ListView.GetItemText( i,0 );
  339. if( str==sContent )
  340. {
  341. bExist = true;
  342. break;
  343. }
  344. }
  345. if( !bExist )
  346. {
  347. int nInsert=m_ListView.GetItemCount();
  348. CString s1;
  349. s1 = GetPreStr( sContent );
  350. for( int i=nInsert-1;i>=0;i-- )
  351. {
  352. str = m_ListView.GetItemText( i,0 );
  353. if( str.Find( s1 )==0 )
  354. {
  355. nInsert = i+1;
  356. break;
  357. }
  358. }
  359. m_ListView.InsertItem( nInsert,sContent );
  360. }
  361. }
  362. int CDlg_EditView::GetLevel( CString sContent )
  363. {
  364. int nRet=0;
  365. for( int i=0;i<sContent.GetLength();i++ )
  366. {
  367. if( sContent[i]=='\\' )
  368. nRet++;
  369. if( sContent[i]=='[' )
  370. break;
  371. }
  372. return nRet;
  373. }
  374. CString CDlg_EditView::GetPreStr( CString sContent )
  375. {
  376. CString sRet;
  377. for( int i=sContent.GetLength()-1;i>=0;i-- )
  378. {
  379. if( sContent[i]=='\\' )
  380. {
  381. sRet = sContent.Left( i );
  382. break;
  383. }
  384. }
  385. return sRet;
  386. }
  387. void CDlg_EditView::ShowAll()
  388. {
  389. int nSize = m_ListView.GetItemCount();
  390. CString str;
  391. for( int i=0;i<nSize;i++ )
  392. {
  393. str = m_ListView.GetItemText( i,0 );
  394. ShowOne( "",str,i );
  395. nSize = m_ListView.GetItemCount();
  396. }
  397. }
  398. void CDlg_EditView::HideAll()
  399. {
  400. int nSize = m_ListView.GetItemCount();
  401. CString str;
  402. for( int i=nSize-1;i>=0;i-- )
  403. {
  404. str = m_ListView.GetItemText( i,0 );
  405. HideOne( "",str,i );
  406. }
  407. }
  408. void CDlg_EditView::ShowOne( CString sParent,CString sContent,int &iListIndex )
  409. {//A[\a[\1\2]\b[\1\2]] A[\a\b] A[\a\b[\1\2]]
  410. int nInsertLastIndex=iListIndex;
  411. bool bFirst = true;
  412. CString sData,s1,s2;
  413. int nStart=-1,nEnd=-1;
  414. nStart = sContent.Find("[");
  415. if( nStart==-1 )
  416. return;
  417. CString str;
  418. str = sContent.Left( nStart );
  419. sData = sContent.Mid( nStart+1,sContent.GetLength()-nStart-2 );
  420. //\a[\1\2]\b[\1\2] \a\b \a\b[\1\2]
  421. int nPos1=-1,nPos2=-1;
  422. nPos1 = sData.Find( "\\",0 );
  423. bool bOK=false;
  424. int nLastStatus=0;//0:\ 1:[ 2:]
  425. for( int i=1;i<sData.GetLength();i++ )
  426. {
  427. if( sData[i]=='\\' )
  428. {
  429. if( nLastStatus==0 )
  430. {
  431. nPos2 = i;
  432. bOK = true;
  433. }
  434. }
  435. else if( sData[i]=='[' )
  436. {
  437. nLastStatus = 1;
  438. }
  439. else if( sData[i]==']' )
  440. {
  441. if( nLastStatus==1 )
  442. {
  443. nLastStatus = 0;
  444. nPos2 = i;
  445. }
  446. }
  447. if( i==sData.GetLength()-1 )
  448. {
  449. nPos2 = sData.GetLength()-0;
  450. bOK = true;
  451. }
  452. if( bOK )
  453. {
  454. bOK = false;
  455. s1 = str + sData.Mid( nPos1,nPos2-nPos1 );
  456. nInsertLastIndex++;
  457. m_ListView.InsertItem( nInsertLastIndex,s1 );
  458. ShowOne( "",s1,nInsertLastIndex );
  459. i = nPos2;
  460. nPos1 = nPos2;
  461. }
  462. }
  463. if( nInsertLastIndex!=iListIndex )
  464. {
  465. m_ListView.SetItemText( iListIndex,0,str );
  466. iListIndex = nInsertLastIndex;
  467. }
  468. }
  469. void CDlg_EditView::HideOne( CString sParent,CString &sContent,int iListIndex )
  470. {
  471. int nDelLastIndex=-1;
  472. bool bFirst = true;
  473. CString sDesc=sContent,str1,str2,s1 = sContent,s2;
  474. int nCount1=0,nCount2=0;
  475. nCount1 = GetLevel( s1 );
  476. for( int i=iListIndex+1;i<m_ListView.GetItemCount();i++ )
  477. {
  478. s2 = m_ListView.GetItemText( i,0 );
  479. nCount2 = GetLevel( s2 );
  480. if( s2.Find(s1)==0 && nCount1+1==nCount2 )
  481. {
  482. HideOne( "",s2,i );
  483. nDelLastIndex = i;
  484. if( bFirst )
  485. {
  486. bFirst = false;
  487. sDesc += "[";
  488. }
  489. sDesc += s2.Right( s2.GetLength()-s1.GetLength() );
  490. }
  491. else
  492. break;
  493. }
  494. if( nDelLastIndex!=-1 )
  495. {
  496. sDesc += "]";
  497. sContent = sDesc;
  498. m_ListView.SetItemText( iListIndex,0,sDesc );
  499. }
  500. if( nDelLastIndex!=-1 )
  501. {
  502. for( int i=nDelLastIndex;i>iListIndex;i-- )
  503. {
  504. m_ListView.DeleteItem( i );
  505. }
  506. }
  507. }
  508. void CDlg_EditView::OnNMDblclkList1(NMHDR *pNMHDR, LRESULT *pResult)
  509. {
  510. int iListCount = m_ListView.GetItemCount();
  511. POSITION pos = m_ListView.GetFirstSelectedItemPosition();
  512. int nListSel = m_ListView.GetNextSelectedItem(pos);
  513. if(nListSel>=iListCount || nListSel==-1)
  514. {
  515. return;
  516. }
  517. CString sDesc;
  518. sDesc = m_ListView.GetItemText( nListSel,0 );
  519. if( sDesc.Find("[")==-1 )
  520. {
  521. HideOne( "",sDesc,nListSel );
  522. }
  523. else
  524. {
  525. ShowOne( "",sDesc,nListSel );
  526. }
  527. *pResult = 0;
  528. }